dsi.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
  4. * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
  5. */
  6. #ifndef __OMAP_DRM_DSS_DSI_H
  7. #define __OMAP_DRM_DSS_DSI_H
  8. #include <drm/drm_mipi_dsi.h>
  9. struct dsi_reg {
  10. u16 module;
  11. u16 idx;
  12. };
  13. #define DSI_REG(mod, idx) ((const struct dsi_reg) { mod, idx })
  14. /* DSI Protocol Engine */
  15. #define DSI_PROTO 0
  16. #define DSI_PROTO_SZ 0x200
  17. #define DSI_REVISION DSI_REG(DSI_PROTO, 0x0000)
  18. #define DSI_SYSCONFIG DSI_REG(DSI_PROTO, 0x0010)
  19. #define DSI_SYSSTATUS DSI_REG(DSI_PROTO, 0x0014)
  20. #define DSI_IRQSTATUS DSI_REG(DSI_PROTO, 0x0018)
  21. #define DSI_IRQENABLE DSI_REG(DSI_PROTO, 0x001C)
  22. #define DSI_CTRL DSI_REG(DSI_PROTO, 0x0040)
  23. #define DSI_GNQ DSI_REG(DSI_PROTO, 0x0044)
  24. #define DSI_COMPLEXIO_CFG1 DSI_REG(DSI_PROTO, 0x0048)
  25. #define DSI_COMPLEXIO_IRQ_STATUS DSI_REG(DSI_PROTO, 0x004C)
  26. #define DSI_COMPLEXIO_IRQ_ENABLE DSI_REG(DSI_PROTO, 0x0050)
  27. #define DSI_CLK_CTRL DSI_REG(DSI_PROTO, 0x0054)
  28. #define DSI_TIMING1 DSI_REG(DSI_PROTO, 0x0058)
  29. #define DSI_TIMING2 DSI_REG(DSI_PROTO, 0x005C)
  30. #define DSI_VM_TIMING1 DSI_REG(DSI_PROTO, 0x0060)
  31. #define DSI_VM_TIMING2 DSI_REG(DSI_PROTO, 0x0064)
  32. #define DSI_VM_TIMING3 DSI_REG(DSI_PROTO, 0x0068)
  33. #define DSI_CLK_TIMING DSI_REG(DSI_PROTO, 0x006C)
  34. #define DSI_TX_FIFO_VC_SIZE DSI_REG(DSI_PROTO, 0x0070)
  35. #define DSI_RX_FIFO_VC_SIZE DSI_REG(DSI_PROTO, 0x0074)
  36. #define DSI_COMPLEXIO_CFG2 DSI_REG(DSI_PROTO, 0x0078)
  37. #define DSI_RX_FIFO_VC_FULLNESS DSI_REG(DSI_PROTO, 0x007C)
  38. #define DSI_VM_TIMING4 DSI_REG(DSI_PROTO, 0x0080)
  39. #define DSI_TX_FIFO_VC_EMPTINESS DSI_REG(DSI_PROTO, 0x0084)
  40. #define DSI_VM_TIMING5 DSI_REG(DSI_PROTO, 0x0088)
  41. #define DSI_VM_TIMING6 DSI_REG(DSI_PROTO, 0x008C)
  42. #define DSI_VM_TIMING7 DSI_REG(DSI_PROTO, 0x0090)
  43. #define DSI_STOPCLK_TIMING DSI_REG(DSI_PROTO, 0x0094)
  44. #define DSI_VC_CTRL(n) DSI_REG(DSI_PROTO, 0x0100 + (n * 0x20))
  45. #define DSI_VC_TE(n) DSI_REG(DSI_PROTO, 0x0104 + (n * 0x20))
  46. #define DSI_VC_LONG_PACKET_HEADER(n) DSI_REG(DSI_PROTO, 0x0108 + (n * 0x20))
  47. #define DSI_VC_LONG_PACKET_PAYLOAD(n) DSI_REG(DSI_PROTO, 0x010C + (n * 0x20))
  48. #define DSI_VC_SHORT_PACKET_HEADER(n) DSI_REG(DSI_PROTO, 0x0110 + (n * 0x20))
  49. #define DSI_VC_IRQSTATUS(n) DSI_REG(DSI_PROTO, 0x0118 + (n * 0x20))
  50. #define DSI_VC_IRQENABLE(n) DSI_REG(DSI_PROTO, 0x011C + (n * 0x20))
  51. /* DSIPHY_SCP */
  52. #define DSI_PHY 1
  53. #define DSI_PHY_OFFSET 0x200
  54. #define DSI_PHY_SZ 0x40
  55. #define DSI_DSIPHY_CFG0 DSI_REG(DSI_PHY, 0x0000)
  56. #define DSI_DSIPHY_CFG1 DSI_REG(DSI_PHY, 0x0004)
  57. #define DSI_DSIPHY_CFG2 DSI_REG(DSI_PHY, 0x0008)
  58. #define DSI_DSIPHY_CFG5 DSI_REG(DSI_PHY, 0x0014)
  59. #define DSI_DSIPHY_CFG10 DSI_REG(DSI_PHY, 0x0028)
  60. /* DSI_PLL_CTRL_SCP */
  61. #define DSI_PLL 2
  62. #define DSI_PLL_OFFSET 0x300
  63. #define DSI_PLL_SZ 0x20
  64. #define DSI_PLL_CONTROL DSI_REG(DSI_PLL, 0x0000)
  65. #define DSI_PLL_STATUS DSI_REG(DSI_PLL, 0x0004)
  66. #define DSI_PLL_GO DSI_REG(DSI_PLL, 0x0008)
  67. #define DSI_PLL_CONFIGURATION1 DSI_REG(DSI_PLL, 0x000C)
  68. #define DSI_PLL_CONFIGURATION2 DSI_REG(DSI_PLL, 0x0010)
  69. /* Global interrupts */
  70. #define DSI_IRQ_VC0 (1 << 0)
  71. #define DSI_IRQ_VC1 (1 << 1)
  72. #define DSI_IRQ_VC2 (1 << 2)
  73. #define DSI_IRQ_VC3 (1 << 3)
  74. #define DSI_IRQ_WAKEUP (1 << 4)
  75. #define DSI_IRQ_RESYNC (1 << 5)
  76. #define DSI_IRQ_PLL_LOCK (1 << 7)
  77. #define DSI_IRQ_PLL_UNLOCK (1 << 8)
  78. #define DSI_IRQ_PLL_RECALL (1 << 9)
  79. #define DSI_IRQ_COMPLEXIO_ERR (1 << 10)
  80. #define DSI_IRQ_HS_TX_TIMEOUT (1 << 14)
  81. #define DSI_IRQ_LP_RX_TIMEOUT (1 << 15)
  82. #define DSI_IRQ_TE_TRIGGER (1 << 16)
  83. #define DSI_IRQ_ACK_TRIGGER (1 << 17)
  84. #define DSI_IRQ_SYNC_LOST (1 << 18)
  85. #define DSI_IRQ_LDO_POWER_GOOD (1 << 19)
  86. #define DSI_IRQ_TA_TIMEOUT (1 << 20)
  87. #define DSI_IRQ_ERROR_MASK \
  88. (DSI_IRQ_HS_TX_TIMEOUT | DSI_IRQ_LP_RX_TIMEOUT | DSI_IRQ_SYNC_LOST | \
  89. DSI_IRQ_TA_TIMEOUT)
  90. #define DSI_IRQ_CHANNEL_MASK 0xf
  91. /* Virtual channel interrupts */
  92. #define DSI_VC_IRQ_CS (1 << 0)
  93. #define DSI_VC_IRQ_ECC_CORR (1 << 1)
  94. #define DSI_VC_IRQ_PACKET_SENT (1 << 2)
  95. #define DSI_VC_IRQ_FIFO_TX_OVF (1 << 3)
  96. #define DSI_VC_IRQ_FIFO_RX_OVF (1 << 4)
  97. #define DSI_VC_IRQ_BTA (1 << 5)
  98. #define DSI_VC_IRQ_ECC_NO_CORR (1 << 6)
  99. #define DSI_VC_IRQ_FIFO_TX_UDF (1 << 7)
  100. #define DSI_VC_IRQ_PP_BUSY_CHANGE (1 << 8)
  101. #define DSI_VC_IRQ_ERROR_MASK \
  102. (DSI_VC_IRQ_CS | DSI_VC_IRQ_ECC_CORR | DSI_VC_IRQ_FIFO_TX_OVF | \
  103. DSI_VC_IRQ_FIFO_RX_OVF | DSI_VC_IRQ_ECC_NO_CORR | \
  104. DSI_VC_IRQ_FIFO_TX_UDF)
  105. /* ComplexIO interrupts */
  106. #define DSI_CIO_IRQ_ERRSYNCESC1 (1 << 0)
  107. #define DSI_CIO_IRQ_ERRSYNCESC2 (1 << 1)
  108. #define DSI_CIO_IRQ_ERRSYNCESC3 (1 << 2)
  109. #define DSI_CIO_IRQ_ERRSYNCESC4 (1 << 3)
  110. #define DSI_CIO_IRQ_ERRSYNCESC5 (1 << 4)
  111. #define DSI_CIO_IRQ_ERRESC1 (1 << 5)
  112. #define DSI_CIO_IRQ_ERRESC2 (1 << 6)
  113. #define DSI_CIO_IRQ_ERRESC3 (1 << 7)
  114. #define DSI_CIO_IRQ_ERRESC4 (1 << 8)
  115. #define DSI_CIO_IRQ_ERRESC5 (1 << 9)
  116. #define DSI_CIO_IRQ_ERRCONTROL1 (1 << 10)
  117. #define DSI_CIO_IRQ_ERRCONTROL2 (1 << 11)
  118. #define DSI_CIO_IRQ_ERRCONTROL3 (1 << 12)
  119. #define DSI_CIO_IRQ_ERRCONTROL4 (1 << 13)
  120. #define DSI_CIO_IRQ_ERRCONTROL5 (1 << 14)
  121. #define DSI_CIO_IRQ_STATEULPS1 (1 << 15)
  122. #define DSI_CIO_IRQ_STATEULPS2 (1 << 16)
  123. #define DSI_CIO_IRQ_STATEULPS3 (1 << 17)
  124. #define DSI_CIO_IRQ_STATEULPS4 (1 << 18)
  125. #define DSI_CIO_IRQ_STATEULPS5 (1 << 19)
  126. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_1 (1 << 20)
  127. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_1 (1 << 21)
  128. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_2 (1 << 22)
  129. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_2 (1 << 23)
  130. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_3 (1 << 24)
  131. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_3 (1 << 25)
  132. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_4 (1 << 26)
  133. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_4 (1 << 27)
  134. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_5 (1 << 28)
  135. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_5 (1 << 29)
  136. #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL0 (1 << 30)
  137. #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL1 (1 << 31)
  138. #define DSI_CIO_IRQ_ERROR_MASK \
  139. (DSI_CIO_IRQ_ERRSYNCESC1 | DSI_CIO_IRQ_ERRSYNCESC2 | \
  140. DSI_CIO_IRQ_ERRSYNCESC3 | DSI_CIO_IRQ_ERRSYNCESC4 | \
  141. DSI_CIO_IRQ_ERRSYNCESC5 | \
  142. DSI_CIO_IRQ_ERRESC1 | DSI_CIO_IRQ_ERRESC2 | \
  143. DSI_CIO_IRQ_ERRESC3 | DSI_CIO_IRQ_ERRESC4 | \
  144. DSI_CIO_IRQ_ERRESC5 | \
  145. DSI_CIO_IRQ_ERRCONTROL1 | DSI_CIO_IRQ_ERRCONTROL2 | \
  146. DSI_CIO_IRQ_ERRCONTROL3 | DSI_CIO_IRQ_ERRCONTROL4 | \
  147. DSI_CIO_IRQ_ERRCONTROL5 | \
  148. DSI_CIO_IRQ_ERRCONTENTIONLP0_1 | DSI_CIO_IRQ_ERRCONTENTIONLP1_1 | \
  149. DSI_CIO_IRQ_ERRCONTENTIONLP0_2 | DSI_CIO_IRQ_ERRCONTENTIONLP1_2 | \
  150. DSI_CIO_IRQ_ERRCONTENTIONLP0_3 | DSI_CIO_IRQ_ERRCONTENTIONLP1_3 | \
  151. DSI_CIO_IRQ_ERRCONTENTIONLP0_4 | DSI_CIO_IRQ_ERRCONTENTIONLP1_4 | \
  152. DSI_CIO_IRQ_ERRCONTENTIONLP0_5 | DSI_CIO_IRQ_ERRCONTENTIONLP1_5)
  153. enum omap_dss_dsi_mode {
  154. OMAP_DSS_DSI_CMD_MODE = 0,
  155. OMAP_DSS_DSI_VIDEO_MODE,
  156. };
  157. enum omap_dss_dsi_trans_mode {
  158. /* Sync Pulses: both sync start and end packets sent */
  159. OMAP_DSS_DSI_PULSE_MODE,
  160. /* Sync Events: only sync start packets sent */
  161. OMAP_DSS_DSI_EVENT_MODE,
  162. /* Burst: only sync start packets sent, pixels are time compressed */
  163. OMAP_DSS_DSI_BURST_MODE,
  164. };
  165. struct omap_dss_dsi_videomode_timings {
  166. unsigned long hsclk;
  167. unsigned int ndl;
  168. unsigned int bitspp;
  169. /* pixels */
  170. u16 hact;
  171. /* lines */
  172. u16 vact;
  173. /* DSI video mode blanking data */
  174. /* Unit: byte clock cycles */
  175. u16 hss;
  176. u16 hsa;
  177. u16 hse;
  178. u16 hfp;
  179. u16 hbp;
  180. /* Unit: line clocks */
  181. u16 vsa;
  182. u16 vfp;
  183. u16 vbp;
  184. /* DSI blanking modes */
  185. int blanking_mode;
  186. int hsa_blanking_mode;
  187. int hbp_blanking_mode;
  188. int hfp_blanking_mode;
  189. enum omap_dss_dsi_trans_mode trans_mode;
  190. int window_sync;
  191. };
  192. struct omap_dss_dsi_config {
  193. enum omap_dss_dsi_mode mode;
  194. enum mipi_dsi_pixel_format pixel_format;
  195. const struct videomode *vm;
  196. unsigned long hs_clk_min, hs_clk_max;
  197. unsigned long lp_clk_min, lp_clk_max;
  198. enum omap_dss_dsi_trans_mode trans_mode;
  199. };
  200. /* DSI PLL HSDIV indices */
  201. #define HSDIV_DISPC 0
  202. #define HSDIV_DSI 1
  203. #define DSI_MAX_NR_ISRS 2
  204. #define DSI_MAX_NR_LANES 5
  205. enum dsi_model {
  206. DSI_MODEL_OMAP3,
  207. DSI_MODEL_OMAP4,
  208. DSI_MODEL_OMAP5,
  209. };
  210. enum dsi_lane_function {
  211. DSI_LANE_UNUSED = 0,
  212. DSI_LANE_CLK,
  213. DSI_LANE_DATA1,
  214. DSI_LANE_DATA2,
  215. DSI_LANE_DATA3,
  216. DSI_LANE_DATA4,
  217. };
  218. struct dsi_lane_config {
  219. enum dsi_lane_function function;
  220. u8 polarity;
  221. };
  222. typedef void (*omap_dsi_isr_t) (void *arg, u32 mask);
  223. struct dsi_isr_data {
  224. omap_dsi_isr_t isr;
  225. void *arg;
  226. u32 mask;
  227. };
  228. enum fifo_size {
  229. DSI_FIFO_SIZE_0 = 0,
  230. DSI_FIFO_SIZE_32 = 1,
  231. DSI_FIFO_SIZE_64 = 2,
  232. DSI_FIFO_SIZE_96 = 3,
  233. DSI_FIFO_SIZE_128 = 4,
  234. };
  235. enum dsi_vc_source {
  236. DSI_VC_SOURCE_L4 = 0,
  237. DSI_VC_SOURCE_VP,
  238. };
  239. struct dsi_irq_stats {
  240. unsigned long last_reset;
  241. unsigned int irq_count;
  242. unsigned int dsi_irqs[32];
  243. unsigned int vc_irqs[4][32];
  244. unsigned int cio_irqs[32];
  245. };
  246. struct dsi_isr_tables {
  247. struct dsi_isr_data isr_table[DSI_MAX_NR_ISRS];
  248. struct dsi_isr_data isr_table_vc[4][DSI_MAX_NR_ISRS];
  249. struct dsi_isr_data isr_table_cio[DSI_MAX_NR_ISRS];
  250. };
  251. struct dsi_lp_clock_info {
  252. unsigned long lp_clk;
  253. u16 lp_clk_div;
  254. };
  255. struct dsi_clk_calc_ctx {
  256. struct dsi_data *dsi;
  257. struct dss_pll *pll;
  258. /* inputs */
  259. const struct omap_dss_dsi_config *config;
  260. unsigned long req_pck_min, req_pck_nom, req_pck_max;
  261. /* outputs */
  262. struct dss_pll_clock_info dsi_cinfo;
  263. struct dispc_clock_info dispc_cinfo;
  264. struct dsi_lp_clock_info lp_cinfo;
  265. struct videomode vm;
  266. struct omap_dss_dsi_videomode_timings dsi_vm;
  267. };
  268. struct dsi_module_id_data {
  269. u32 address;
  270. int id;
  271. };
  272. enum dsi_quirks {
  273. DSI_QUIRK_PLL_PWR_BUG = (1 << 0), /* DSI-PLL power command 0x3 is not working */
  274. DSI_QUIRK_DCS_CMD_CONFIG_VC = (1 << 1),
  275. DSI_QUIRK_VC_OCP_WIDTH = (1 << 2),
  276. DSI_QUIRK_REVERSE_TXCLKESC = (1 << 3),
  277. DSI_QUIRK_GNQ = (1 << 4),
  278. DSI_QUIRK_PHY_DCC = (1 << 5),
  279. };
  280. struct dsi_of_data {
  281. enum dsi_model model;
  282. const struct dss_pll_hw *pll_hw;
  283. const struct dsi_module_id_data *modules;
  284. unsigned int max_fck_freq;
  285. unsigned int max_pll_lpdiv;
  286. enum dsi_quirks quirks;
  287. };
  288. struct dsi_data {
  289. struct device *dev;
  290. void __iomem *proto_base;
  291. void __iomem *phy_base;
  292. void __iomem *pll_base;
  293. const struct dsi_of_data *data;
  294. int module_id;
  295. int irq;
  296. bool is_enabled;
  297. struct clk *dss_clk;
  298. struct regmap *syscon;
  299. struct dss_device *dss;
  300. struct mipi_dsi_host host;
  301. struct dispc_clock_info user_dispc_cinfo;
  302. struct dss_pll_clock_info user_dsi_cinfo;
  303. struct dsi_lp_clock_info user_lp_cinfo;
  304. struct dsi_lp_clock_info current_lp_cinfo;
  305. struct dss_pll pll;
  306. bool vdds_dsi_enabled;
  307. struct regulator *vdds_dsi_reg;
  308. struct mipi_dsi_device *dsidev;
  309. struct {
  310. enum dsi_vc_source source;
  311. enum fifo_size tx_fifo_size;
  312. enum fifo_size rx_fifo_size;
  313. } vc[4];
  314. struct mutex lock;
  315. struct semaphore bus_lock;
  316. spinlock_t irq_lock;
  317. struct dsi_isr_tables isr_tables;
  318. /* space for a copy used by the interrupt handler */
  319. struct dsi_isr_tables isr_tables_copy;
  320. int update_vc;
  321. #ifdef DSI_PERF_MEASURE
  322. unsigned int update_bytes;
  323. #endif
  324. /* external TE GPIO */
  325. struct gpio_desc *te_gpio;
  326. int te_irq;
  327. struct delayed_work te_timeout_work;
  328. atomic_t do_ext_te_update;
  329. bool te_enabled;
  330. bool iface_enabled;
  331. bool video_enabled;
  332. struct delayed_work framedone_timeout_work;
  333. #ifdef DSI_CATCH_MISSING_TE
  334. struct timer_list te_timer;
  335. #endif
  336. unsigned long cache_req_pck;
  337. unsigned long cache_clk_freq;
  338. struct dss_pll_clock_info cache_cinfo;
  339. u32 errors;
  340. spinlock_t errors_lock;
  341. #ifdef DSI_PERF_MEASURE
  342. ktime_t perf_setup_time;
  343. ktime_t perf_start_time;
  344. #endif
  345. int debug_read;
  346. int debug_write;
  347. struct {
  348. struct dss_debugfs_entry *irqs;
  349. struct dss_debugfs_entry *regs;
  350. struct dss_debugfs_entry *clks;
  351. } debugfs;
  352. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  353. spinlock_t irq_stats_lock;
  354. struct dsi_irq_stats irq_stats;
  355. #endif
  356. unsigned int num_lanes_supported;
  357. unsigned int line_buffer_size;
  358. struct dsi_lane_config lanes[DSI_MAX_NR_LANES];
  359. unsigned int num_lanes_used;
  360. unsigned int scp_clk_refcount;
  361. struct omap_dss_dsi_config config;
  362. struct dss_lcd_mgr_config mgr_config;
  363. struct videomode vm;
  364. enum mipi_dsi_pixel_format pix_fmt;
  365. enum omap_dss_dsi_mode mode;
  366. struct omap_dss_dsi_videomode_timings vm_timings;
  367. struct omap_dss_device output;
  368. struct drm_bridge bridge;
  369. struct delayed_work dsi_disable_work;
  370. };
  371. struct dsi_packet_sent_handler_data {
  372. struct dsi_data *dsi;
  373. struct completion *completion;
  374. };
  375. #endif /* __OMAP_DRM_DSS_DSI_H */