mipi_dsi.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. /* Copyright (c) 2009-2013, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. */
  13. #ifndef MIPI_DSI_H
  14. #define MIPI_DSI_H
  15. #include <mach/scm-io.h>
  16. #include <linux/list.h>
  17. #ifdef BIT
  18. #undef BIT
  19. #endif
  20. #define BIT(x) (1<<(x))
  21. #define MMSS_CC_BASE_PHY 0x04000000 /* mmss clcok control */
  22. #define MMSS_SFPB_BASE_PHY 0x05700000 /* mmss SFPB CFG */
  23. #define MMSS_SERDES_BASE_PHY 0x04f01000 /* mmss (De)Serializer CFG */
  24. #define MIPI_DSI_BASE mipi_dsi_base
  25. #define MIPI_OUTP(addr, data) writel((data), (addr))
  26. #define MIPI_INP(addr) readl(addr)
  27. #ifdef CONFIG_MSM_SECURE_IO
  28. #define MIPI_OUTP_SECURE(addr, data) secure_writel((data), (addr))
  29. #define MIPI_INP_SECURE(addr) secure_readl(addr)
  30. #else
  31. #define MIPI_OUTP_SECURE(addr, data) writel((data), (addr))
  32. #define MIPI_INP_SECURE(addr) readl(addr)
  33. #endif
  34. #define MIPI_DSI_PRIM 1
  35. #define MIPI_DSI_SECD 2
  36. #define MIPI_DSI_PANEL_VGA 0
  37. #define MIPI_DSI_PANEL_WVGA 1
  38. #define MIPI_DSI_PANEL_WVGA_PT 2
  39. #define MIPI_DSI_PANEL_FWVGA_PT 3
  40. #define MIPI_DSI_PANEL_WSVGA_PT 4
  41. #define MIPI_DSI_PANEL_QHD_PT 5
  42. #define MIPI_DSI_PANEL_WXGA 6
  43. #define MIPI_DSI_PANEL_WUXGA 7
  44. #define MIPI_DSI_PANEL_720P_PT 8
  45. #define DSI_PANEL_MAX 8
  46. enum { /* mipi dsi panel */
  47. DSI_VIDEO_MODE,
  48. DSI_CMD_MODE,
  49. };
  50. enum {
  51. ST_DSI_CLK_OFF,
  52. ST_DSI_SUSPEND,
  53. ST_DSI_RESUME,
  54. ST_DSI_PLAYING,
  55. ST_DSI_NUM
  56. };
  57. enum {
  58. EV_DSI_UPDATE,
  59. EV_DSI_DONE,
  60. EV_DSI_TOUT,
  61. EV_DSI_NUM
  62. };
  63. enum {
  64. LANDSCAPE = 1,
  65. PORTRAIT = 2,
  66. };
  67. enum dsi_trigger_type {
  68. DSI_CMD_MODE_DMA,
  69. DSI_CMD_MODE_MDP,
  70. };
  71. #define DSI_NON_BURST_SYNCH_PULSE 0
  72. #define DSI_NON_BURST_SYNCH_EVENT 1
  73. #define DSI_BURST_MODE 2
  74. #define DSI_RGB_SWAP_RGB 0
  75. #define DSI_RGB_SWAP_RBG 1
  76. #define DSI_RGB_SWAP_BGR 2
  77. #define DSI_RGB_SWAP_BRG 3
  78. #define DSI_RGB_SWAP_GRB 4
  79. #define DSI_RGB_SWAP_GBR 5
  80. #define DSI_VIDEO_DST_FORMAT_RGB565 0
  81. #define DSI_VIDEO_DST_FORMAT_RGB666 1
  82. #define DSI_VIDEO_DST_FORMAT_RGB666_LOOSE 2
  83. #define DSI_VIDEO_DST_FORMAT_RGB888 3
  84. #define DSI_CMD_DST_FORMAT_RGB111 0
  85. #define DSI_CMD_DST_FORMAT_RGB332 3
  86. #define DSI_CMD_DST_FORMAT_RGB444 4
  87. #define DSI_CMD_DST_FORMAT_RGB565 6
  88. #define DSI_CMD_DST_FORMAT_RGB666 7
  89. #define DSI_CMD_DST_FORMAT_RGB888 8
  90. #define DSI_INTR_ERROR_MASK BIT(25)
  91. #define DSI_INTR_ERROR BIT(24)
  92. #define DSI_INTR_VIDEO_DONE_MASK BIT(17)
  93. #define DSI_INTR_VIDEO_DONE BIT(16)
  94. #define DSI_INTR_CMD_MDP_DONE_MASK BIT(9)
  95. #define DSI_INTR_CMD_MDP_DONE BIT(8)
  96. #define DSI_INTR_CMD_DMA_DONE_MASK BIT(1)
  97. #define DSI_INTR_CMD_DMA_DONE BIT(0)
  98. #define DSI_MDP_TERM BIT(8)
  99. #define DSI_CMD_TERM BIT(0)
  100. #define DSI_CMD_TRIGGER_NONE 0x0 /* mdp trigger */
  101. #define DSI_CMD_TRIGGER_TE 0x02
  102. #define DSI_CMD_TRIGGER_SW 0x04
  103. #define DSI_CMD_TRIGGER_SW_SEOF 0x05 /* cmd dma only */
  104. #define DSI_CMD_TRIGGER_SW_TE 0x06
  105. extern struct device dsi_dev;
  106. extern int mipi_dsi_clk_on;
  107. extern u32 dsi_irq;
  108. extern u32 esc_byte_ratio;
  109. extern void __iomem *periph_base;
  110. extern char *mmss_cc_base; /* mutimedia sub system clock control */
  111. extern char *mmss_sfpb_base; /* mutimedia sub system sfpb */
  112. struct dsiphy_pll_divider_config {
  113. u32 clk_rate;
  114. u32 fb_divider;
  115. u32 ref_divider_ratio;
  116. u32 bit_clk_divider; /* oCLK1 */
  117. u32 byte_clk_divider; /* oCLK2 */
  118. u32 dsi_clk_divider; /* oCLK3 */
  119. };
  120. extern struct dsiphy_pll_divider_config pll_divider_config;
  121. struct dsi_clk_mnd_table {
  122. uint8 lanes;
  123. uint8 bpp;
  124. uint8 dsiclk_div;
  125. uint8 dsiclk_m;
  126. uint8 dsiclk_n;
  127. uint8 dsiclk_d;
  128. uint8 pclk_m;
  129. uint8 pclk_n;
  130. uint8 pclk_d;
  131. };
  132. static const struct dsi_clk_mnd_table mnd_table[] = {
  133. { 1, 2, 8, 1, 1, 0, 1, 2, 1},
  134. { 1, 3, 8, 1, 1, 0, 1, 3, 2},
  135. { 2, 2, 4, 1, 1, 0, 1, 2, 1},
  136. { 2, 3, 4, 1, 1, 0, 1, 3, 2},
  137. { 3, 2, 1, 3, 8, 4, 3, 16, 8},
  138. { 3, 3, 1, 3, 8, 4, 1, 8, 4},
  139. { 4, 2, 2, 1, 1, 0, 1, 2, 1},
  140. { 4, 3, 2, 1, 1, 0, 1, 3, 2},
  141. };
  142. struct dsi_clk_desc {
  143. uint32 src;
  144. uint32 m;
  145. uint32 n;
  146. uint32 d;
  147. uint32 mnd_mode;
  148. uint32 pre_div_func;
  149. };
  150. #define DSI_HOST_HDR_SIZE 4
  151. #define DSI_HDR_LAST BIT(31)
  152. #define DSI_HDR_LONG_PKT BIT(30)
  153. #define DSI_HDR_BTA BIT(29)
  154. #define DSI_HDR_VC(vc) (((vc) & 0x03) << 22)
  155. #define DSI_HDR_DTYPE(dtype) (((dtype) & 0x03f) << 16)
  156. #define DSI_HDR_DATA2(data) (((data) & 0x0ff) << 8)
  157. #define DSI_HDR_DATA1(data) ((data) & 0x0ff)
  158. #define DSI_HDR_WC(wc) ((wc) & 0x0ffff)
  159. #define DSI_BUF_SIZE 64
  160. #define MIPI_DSI_MRPS 0x04 /* Maximum Return Packet Size */
  161. #define MIPI_DSI_LEN 8 /* 4 x 4 - 6 - 2, bytes dcs header+crc-align */
  162. struct dsi_buf {
  163. uint32 *hdr; /* dsi host header */
  164. char *start; /* buffer start addr */
  165. char *end; /* buffer end addr */
  166. int size; /* size of buffer */
  167. char *data; /* buffer */
  168. int len; /* data length */
  169. dma_addr_t dmap; /* mapped dma addr */
  170. };
  171. /* dcs read/write */
  172. #define DTYPE_DCS_WRITE 0x05 /* short write, 0 parameter */
  173. #define DTYPE_DCS_WRITE1 0x15 /* short write, 1 parameter */
  174. #define DTYPE_DCS_READ 0x06 /* read */
  175. #define DTYPE_DCS_LWRITE 0x39 /* long write */
  176. /* generic read/write */
  177. #define DTYPE_GEN_WRITE 0x03 /* short write, 0 parameter */
  178. #define DTYPE_GEN_WRITE1 0x13 /* short write, 1 parameter */
  179. #define DTYPE_GEN_WRITE2 0x23 /* short write, 2 parameter */
  180. #define DTYPE_GEN_LWRITE 0x29 /* long write */
  181. #define DTYPE_GEN_READ 0x04 /* long read, 0 parameter */
  182. #define DTYPE_GEN_READ1 0x14 /* long read, 1 parameter */
  183. #define DTYPE_GEN_READ2 0x24 /* long read, 2 parameter */
  184. #define DTYPE_TEAR_ON 0x35 /* set tear on */
  185. #define DTYPE_MAX_PKTSIZE 0x37 /* set max packet size */
  186. #define DTYPE_NULL_PKT 0x09 /* null packet, no data */
  187. #define DTYPE_BLANK_PKT 0x19 /* blankiing packet, no data */
  188. #define DTYPE_CM_ON 0x02 /* color mode off */
  189. #define DTYPE_CM_OFF 0x12 /* color mode on */
  190. #define DTYPE_PERIPHERAL_OFF 0x22
  191. #define DTYPE_PERIPHERAL_ON 0x32
  192. /*
  193. * dcs response
  194. */
  195. #define DTYPE_ACK_ERR_RESP 0x02
  196. #define DTYPE_EOT_RESP 0x08 /* end of tx */
  197. #define DTYPE_GEN_READ1_RESP 0x11 /* 1 parameter, short */
  198. #define DTYPE_GEN_READ2_RESP 0x12 /* 2 parameter, short */
  199. #define DTYPE_GEN_LREAD_RESP 0x1a
  200. #define DTYPE_DCS_LREAD_RESP 0x1c
  201. #define DTYPE_DCS_READ1_RESP 0x21 /* 1 parameter, short */
  202. #define DTYPE_DCS_READ2_RESP 0x22 /* 2 parameter, short */
  203. struct dsi_cmd_desc {
  204. int dtype;
  205. int last;
  206. int vc;
  207. int ack; /* ask ACK from peripheral */
  208. int wait;
  209. int dlen;
  210. char *payload;
  211. };
  212. typedef void (*kickoff_act)(void *);
  213. struct dsi_kickoff_action {
  214. struct list_head act_entry;
  215. kickoff_act action;
  216. void *data;
  217. };
  218. #define CMD_REQ_MAX 4
  219. typedef void (*fxn)(u32 data);
  220. #define CMD_REQ_RX 0x0001
  221. #define CMD_REQ_COMMIT 0x0002
  222. #define CMD_CLK_CTRL 0x0004
  223. #define CMD_REQ_NO_MAX_PKT_SIZE 0x0008
  224. #define CMD_MDP3_CMD_PANEL 0x80000000 /* mdp3 only */
  225. struct dcs_cmd_req {
  226. struct dsi_cmd_desc *cmds;
  227. int cmds_cnt;
  228. u32 flags;
  229. struct dsi_buf *rbuf;
  230. int rlen; /* rx length */
  231. fxn cb;
  232. };
  233. struct dcs_cmd_list {
  234. int put;
  235. int get;
  236. int tot;
  237. struct dcs_cmd_req list[CMD_REQ_MAX];
  238. };
  239. char *mipi_dsi_buf_reserve_hdr(struct dsi_buf *dp, int hlen);
  240. char *mipi_dsi_buf_init(struct dsi_buf *dp);
  241. void mipi_dsi_init(void);
  242. void mipi_dsi_lane_cfg(void);
  243. void mipi_dsi_bist_ctrl(void);
  244. int mipi_dsi_buf_alloc(struct dsi_buf *, int size);
  245. int mipi_dsi_cmd_dma_add(struct dsi_buf *dp, struct dsi_cmd_desc *cm);
  246. int mipi_dsi_cmd_reg_tx(uint32 data);
  247. void mipi_dsi_host_init(struct mipi_panel_info *pinfo);
  248. void mipi_dsi_op_mode_config(int mode);
  249. void mipi_dsi_cmd_mode_ctrl(int enable);
  250. void mdp4_dsi_cmd_trigger(void);
  251. void mipi_dsi_cmd_mdp_start(void);
  252. int mipi_dsi_ctrl_lock(int mdp);
  253. int mipi_dsi_ctrl_lock_query(void);
  254. void mipi_dsi_cmd_bta_sw_trigger(void);
  255. void mipi_dsi_ack_err_status(void);
  256. void mipi_dsi_set_tear_on(struct msm_fb_data_type *mfd);
  257. void mipi_dsi_set_tear_off(struct msm_fb_data_type *mfd);
  258. void mipi_dsi_set_backlight(struct msm_fb_data_type *mfd, int level);
  259. void mipi_dsi_cmd_backlight_tx(struct dsi_buf *dp);
  260. void mipi_dsi_pre_kickoff_action(void);
  261. void mipi_dsi_post_kickoff_action(void);
  262. void mipi_dsi_pre_kickoff_add(struct dsi_kickoff_action *act);
  263. void mipi_dsi_post_kickoff_add(struct dsi_kickoff_action *act);
  264. void mipi_dsi_pre_kickoff_del(struct dsi_kickoff_action *act);
  265. void mipi_dsi_post_kickoff_del(struct dsi_kickoff_action *act);
  266. void mipi_dsi_controller_cfg(int enable);
  267. void mipi_dsi_sw_reset(void);
  268. void mipi_dsi_mdp_busy_wait(void);
  269. irqreturn_t mipi_dsi_isr(int irq, void *ptr);
  270. void mipi_set_tx_power_mode(int mode);
  271. void mipi_dsi_phy_init(int panel_ndx, struct msm_panel_info const *panel_info,
  272. int target_type);
  273. int mipi_dsi_clk_div_config(uint8 bpp, uint8 lanes,
  274. uint32 *expected_dsi_pclk);
  275. int mipi_dsi_clk_init(struct platform_device *pdev);
  276. void mipi_dsi_clk_deinit(struct device *dev);
  277. #ifdef CONFIG_FB_MSM_MIPI_DSI
  278. void mipi_dsi_clk_enable(void);
  279. void mipi_dsi_clk_disable(void);
  280. void mipi_dsi_prepare_clocks(void);
  281. void mipi_dsi_unprepare_clocks(void);
  282. void mipi_dsi_ahb_ctrl(u32 enable);
  283. void mipi_dsi_phy_ctrl(int on);
  284. #else
  285. static inline void mipi_dsi_clk_enable(void)
  286. {
  287. /* empty */
  288. }
  289. void mipi_dsi_clk_disable(void)
  290. {
  291. /* empty */
  292. }
  293. void mipi_dsi_prepare_clocks(void)
  294. {
  295. /* empty */
  296. }
  297. void mipi_dsi_unprepare_clocks(void)
  298. {
  299. /* empty */
  300. }
  301. void mipi_dsi_ahb_ctrl(u32 enable)
  302. {
  303. /* empty */
  304. }
  305. void mipi_dsi_phy_ctrl(int on)
  306. {
  307. /* empty */
  308. }
  309. #endif
  310. void cont_splash_clk_ctrl(int enable);
  311. void mipi_dsi_turn_on_clks(void);
  312. void mipi_dsi_turn_off_clks(void);
  313. void mipi_dsi_clk_cfg(int on);
  314. int mipi_dsi_cmdlist_put(struct dcs_cmd_req *cmdreq);
  315. struct dcs_cmd_req *mipi_dsi_cmdlist_get(void);
  316. void mipi_dsi_cmdlist_commit(int from_mdp);
  317. void mipi_dsi_cmd_mdp_busy(void);
  318. void mipi_dsi_configure_fb_divider(u32 fps_level);
  319. void mipi_dsi_wait4video_done(void);
  320. #ifdef CONFIG_FB_MSM_MDP303
  321. void update_lane_config(struct msm_panel_info *pinfo);
  322. #endif
  323. #endif /* MIPI_DSI_H */