mdfld_dsi_output.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. /*
  2. * Copyright © 2010 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * jim liu <jim.liu@intel.com>
  25. * Jackie Li<yaodong.li@intel.com>
  26. */
  27. #ifndef __MDFLD_DSI_OUTPUT_H__
  28. #define __MDFLD_DSI_OUTPUT_H__
  29. #include <linux/backlight.h>
  30. #include <drm/drmP.h>
  31. #include <drm/drm.h>
  32. #include <drm/drm_crtc.h>
  33. #include <drm/drm_edid.h>
  34. #include "psb_drv.h"
  35. #include "psb_intel_drv.h"
  36. #include "psb_intel_reg.h"
  37. #include "mdfld_output.h"
  38. #include <asm/intel-mid.h>
  39. #define FLD_MASK(start, end) (((1 << ((start) - (end) + 1)) - 1) << (end))
  40. #define FLD_VAL(val, start, end) (((val) << (end)) & FLD_MASK(start, end))
  41. #define FLD_GET(val, start, end) (((val) & FLD_MASK(start, end)) >> (end))
  42. #define FLD_MOD(orig, val, start, end) \
  43. (((orig) & ~FLD_MASK(start, end)) | FLD_VAL(val, start, end))
  44. #define REG_FLD_MOD(reg, val, start, end) \
  45. REG_WRITE(reg, FLD_MOD(REG_READ(reg), val, start, end))
  46. static inline int REGISTER_FLD_WAIT(struct drm_device *dev, u32 reg,
  47. u32 val, int start, int end)
  48. {
  49. int t = 100000;
  50. while (FLD_GET(REG_READ(reg), start, end) != val) {
  51. if (--t == 0)
  52. return 1;
  53. }
  54. return 0;
  55. }
  56. #define REG_FLD_WAIT(reg, val, start, end) \
  57. REGISTER_FLD_WAIT(dev, reg, val, start, end)
  58. #define REG_BIT_WAIT(reg, val, bitnum) \
  59. REGISTER_FLD_WAIT(dev, reg, val, bitnum, bitnum)
  60. #define MDFLD_DSI_BRIGHTNESS_MAX_LEVEL 100
  61. #ifdef DEBUG
  62. #define CHECK_PIPE(pipe) ({ \
  63. const typeof(pipe) __pipe = (pipe); \
  64. BUG_ON(__pipe != 0 && __pipe != 2); \
  65. __pipe; })
  66. #else
  67. #define CHECK_PIPE(pipe) (pipe)
  68. #endif
  69. /*
  70. * Actual MIPIA->MIPIC reg offset is 0x800, value 0x400 is valid for 0 and 2
  71. */
  72. #define REG_OFFSET(pipe) (CHECK_PIPE(pipe) * 0x400)
  73. /* mdfld DSI controller registers */
  74. #define MIPI_DEVICE_READY_REG(pipe) (0xb000 + REG_OFFSET(pipe))
  75. #define MIPI_INTR_STAT_REG(pipe) (0xb004 + REG_OFFSET(pipe))
  76. #define MIPI_INTR_EN_REG(pipe) (0xb008 + REG_OFFSET(pipe))
  77. #define MIPI_DSI_FUNC_PRG_REG(pipe) (0xb00c + REG_OFFSET(pipe))
  78. #define MIPI_HS_TX_TIMEOUT_REG(pipe) (0xb010 + REG_OFFSET(pipe))
  79. #define MIPI_LP_RX_TIMEOUT_REG(pipe) (0xb014 + REG_OFFSET(pipe))
  80. #define MIPI_TURN_AROUND_TIMEOUT_REG(pipe) (0xb018 + REG_OFFSET(pipe))
  81. #define MIPI_DEVICE_RESET_TIMER_REG(pipe) (0xb01c + REG_OFFSET(pipe))
  82. #define MIPI_DPI_RESOLUTION_REG(pipe) (0xb020 + REG_OFFSET(pipe))
  83. #define MIPI_DBI_FIFO_THROTTLE_REG(pipe) (0xb024 + REG_OFFSET(pipe))
  84. #define MIPI_HSYNC_COUNT_REG(pipe) (0xb028 + REG_OFFSET(pipe))
  85. #define MIPI_HBP_COUNT_REG(pipe) (0xb02c + REG_OFFSET(pipe))
  86. #define MIPI_HFP_COUNT_REG(pipe) (0xb030 + REG_OFFSET(pipe))
  87. #define MIPI_HACTIVE_COUNT_REG(pipe) (0xb034 + REG_OFFSET(pipe))
  88. #define MIPI_VSYNC_COUNT_REG(pipe) (0xb038 + REG_OFFSET(pipe))
  89. #define MIPI_VBP_COUNT_REG(pipe) (0xb03c + REG_OFFSET(pipe))
  90. #define MIPI_VFP_COUNT_REG(pipe) (0xb040 + REG_OFFSET(pipe))
  91. #define MIPI_HIGH_LOW_SWITCH_COUNT_REG(pipe) (0xb044 + REG_OFFSET(pipe))
  92. #define MIPI_DPI_CONTROL_REG(pipe) (0xb048 + REG_OFFSET(pipe))
  93. #define MIPI_DPI_DATA_REG(pipe) (0xb04c + REG_OFFSET(pipe))
  94. #define MIPI_INIT_COUNT_REG(pipe) (0xb050 + REG_OFFSET(pipe))
  95. #define MIPI_MAX_RETURN_PACK_SIZE_REG(pipe) (0xb054 + REG_OFFSET(pipe))
  96. #define MIPI_VIDEO_MODE_FORMAT_REG(pipe) (0xb058 + REG_OFFSET(pipe))
  97. #define MIPI_EOT_DISABLE_REG(pipe) (0xb05c + REG_OFFSET(pipe))
  98. #define MIPI_LP_BYTECLK_REG(pipe) (0xb060 + REG_OFFSET(pipe))
  99. #define MIPI_LP_GEN_DATA_REG(pipe) (0xb064 + REG_OFFSET(pipe))
  100. #define MIPI_HS_GEN_DATA_REG(pipe) (0xb068 + REG_OFFSET(pipe))
  101. #define MIPI_LP_GEN_CTRL_REG(pipe) (0xb06c + REG_OFFSET(pipe))
  102. #define MIPI_HS_GEN_CTRL_REG(pipe) (0xb070 + REG_OFFSET(pipe))
  103. #define MIPI_GEN_FIFO_STAT_REG(pipe) (0xb074 + REG_OFFSET(pipe))
  104. #define MIPI_HS_LS_DBI_ENABLE_REG(pipe) (0xb078 + REG_OFFSET(pipe))
  105. #define MIPI_DPHY_PARAM_REG(pipe) (0xb080 + REG_OFFSET(pipe))
  106. #define MIPI_DBI_BW_CTRL_REG(pipe) (0xb084 + REG_OFFSET(pipe))
  107. #define MIPI_CLK_LANE_SWITCH_TIME_CNT_REG(pipe) (0xb088 + REG_OFFSET(pipe))
  108. #define MIPI_CTRL_REG(pipe) (0xb104 + REG_OFFSET(pipe))
  109. #define MIPI_DATA_ADD_REG(pipe) (0xb108 + REG_OFFSET(pipe))
  110. #define MIPI_DATA_LEN_REG(pipe) (0xb10c + REG_OFFSET(pipe))
  111. #define MIPI_CMD_ADD_REG(pipe) (0xb110 + REG_OFFSET(pipe))
  112. #define MIPI_CMD_LEN_REG(pipe) (0xb114 + REG_OFFSET(pipe))
  113. /* non-uniform reg offset */
  114. #define MIPI_PORT_CONTROL(pipe) (CHECK_PIPE(pipe) ? MIPI_C : MIPI)
  115. #define DSI_DEVICE_READY (0x1)
  116. #define DSI_POWER_STATE_ULPS_ENTER (0x2 << 1)
  117. #define DSI_POWER_STATE_ULPS_EXIT (0x1 << 1)
  118. #define DSI_POWER_STATE_ULPS_OFFSET (0x1)
  119. #define DSI_ONE_DATA_LANE (0x1)
  120. #define DSI_TWO_DATA_LANE (0x2)
  121. #define DSI_THREE_DATA_LANE (0X3)
  122. #define DSI_FOUR_DATA_LANE (0x4)
  123. #define DSI_DPI_VIRT_CHANNEL_OFFSET (0x3)
  124. #define DSI_DBI_VIRT_CHANNEL_OFFSET (0x5)
  125. #define DSI_DPI_COLOR_FORMAT_RGB565 (0x01 << 7)
  126. #define DSI_DPI_COLOR_FORMAT_RGB666 (0x02 << 7)
  127. #define DSI_DPI_COLOR_FORMAT_RGB666_UNPACK (0x03 << 7)
  128. #define DSI_DPI_COLOR_FORMAT_RGB888 (0x04 << 7)
  129. #define DSI_DBI_COLOR_FORMAT_OPTION2 (0x05 << 13)
  130. #define DSI_INTR_STATE_RXSOTERROR BIT(0)
  131. #define DSI_INTR_STATE_SPL_PKG_SENT BIT(30)
  132. #define DSI_INTR_STATE_TE BIT(31)
  133. #define DSI_HS_TX_TIMEOUT_MASK (0xffffff)
  134. #define DSI_LP_RX_TIMEOUT_MASK (0xffffff)
  135. #define DSI_TURN_AROUND_TIMEOUT_MASK (0x3f)
  136. #define DSI_RESET_TIMER_MASK (0xffff)
  137. #define DSI_DBI_FIFO_WM_HALF (0x0)
  138. #define DSI_DBI_FIFO_WM_QUARTER (0x1)
  139. #define DSI_DBI_FIFO_WM_LOW (0x2)
  140. #define DSI_DPI_TIMING_MASK (0xffff)
  141. #define DSI_INIT_TIMER_MASK (0xffff)
  142. #define DSI_DBI_RETURN_PACK_SIZE_MASK (0x3ff)
  143. #define DSI_LP_BYTECLK_MASK (0x0ffff)
  144. #define DSI_HS_CTRL_GEN_SHORT_W0 (0x03)
  145. #define DSI_HS_CTRL_GEN_SHORT_W1 (0x13)
  146. #define DSI_HS_CTRL_GEN_SHORT_W2 (0x23)
  147. #define DSI_HS_CTRL_GEN_R0 (0x04)
  148. #define DSI_HS_CTRL_GEN_R1 (0x14)
  149. #define DSI_HS_CTRL_GEN_R2 (0x24)
  150. #define DSI_HS_CTRL_GEN_LONG_W (0x29)
  151. #define DSI_HS_CTRL_MCS_SHORT_W0 (0x05)
  152. #define DSI_HS_CTRL_MCS_SHORT_W1 (0x15)
  153. #define DSI_HS_CTRL_MCS_R0 (0x06)
  154. #define DSI_HS_CTRL_MCS_LONG_W (0x39)
  155. #define DSI_HS_CTRL_VC_OFFSET (0x06)
  156. #define DSI_HS_CTRL_WC_OFFSET (0x08)
  157. #define DSI_FIFO_GEN_HS_DATA_FULL BIT(0)
  158. #define DSI_FIFO_GEN_HS_DATA_HALF_EMPTY BIT(1)
  159. #define DSI_FIFO_GEN_HS_DATA_EMPTY BIT(2)
  160. #define DSI_FIFO_GEN_LP_DATA_FULL BIT(8)
  161. #define DSI_FIFO_GEN_LP_DATA_HALF_EMPTY BIT(9)
  162. #define DSI_FIFO_GEN_LP_DATA_EMPTY BIT(10)
  163. #define DSI_FIFO_GEN_HS_CTRL_FULL BIT(16)
  164. #define DSI_FIFO_GEN_HS_CTRL_HALF_EMPTY BIT(17)
  165. #define DSI_FIFO_GEN_HS_CTRL_EMPTY BIT(18)
  166. #define DSI_FIFO_GEN_LP_CTRL_FULL BIT(24)
  167. #define DSI_FIFO_GEN_LP_CTRL_HALF_EMPTY BIT(25)
  168. #define DSI_FIFO_GEN_LP_CTRL_EMPTY BIT(26)
  169. #define DSI_FIFO_DBI_EMPTY BIT(27)
  170. #define DSI_FIFO_DPI_EMPTY BIT(28)
  171. #define DSI_DBI_HS_LP_SWITCH_MASK (0x1)
  172. #define DSI_HS_LP_SWITCH_COUNTER_OFFSET (0x0)
  173. #define DSI_LP_HS_SWITCH_COUNTER_OFFSET (0x16)
  174. #define DSI_DPI_CTRL_HS_SHUTDOWN (0x00000001)
  175. #define DSI_DPI_CTRL_HS_TURN_ON (0x00000002)
  176. /*dsi power modes*/
  177. #define DSI_POWER_MODE_DISPLAY_ON BIT(2)
  178. #define DSI_POWER_MODE_NORMAL_ON BIT(3)
  179. #define DSI_POWER_MODE_SLEEP_OUT BIT(4)
  180. #define DSI_POWER_MODE_PARTIAL_ON BIT(5)
  181. #define DSI_POWER_MODE_IDLE_ON BIT(6)
  182. enum {
  183. MDFLD_DSI_VIDEO_NON_BURST_MODE_SYNC_PULSE = 1,
  184. MDFLD_DSI_VIDEO_NON_BURST_MODE_SYNC_EVENTS = 2,
  185. MDFLD_DSI_VIDEO_BURST_MODE = 3,
  186. };
  187. #define DSI_DPI_COMPLETE_LAST_LINE BIT(2)
  188. #define DSI_DPI_DISABLE_BTA BIT(3)
  189. struct mdfld_dsi_connector {
  190. struct gma_connector base;
  191. int pipe;
  192. void *private;
  193. void *pkg_sender;
  194. /* Connection status */
  195. enum drm_connector_status status;
  196. };
  197. struct mdfld_dsi_encoder {
  198. struct gma_encoder base;
  199. void *private;
  200. };
  201. /*
  202. * DSI config, consists of one DSI connector, two DSI encoders.
  203. * DRM will pick up on DSI encoder basing on differents configs.
  204. */
  205. struct mdfld_dsi_config {
  206. struct drm_device *dev;
  207. struct drm_display_mode *fixed_mode;
  208. struct drm_display_mode *mode;
  209. struct mdfld_dsi_connector *connector;
  210. struct mdfld_dsi_encoder *encoder;
  211. int changed;
  212. int bpp;
  213. int lane_count;
  214. /*Virtual channel number for this encoder*/
  215. int channel_num;
  216. /*video mode configure*/
  217. int video_mode;
  218. int dvr_ic_inited;
  219. };
  220. static inline struct mdfld_dsi_connector *mdfld_dsi_connector(
  221. struct drm_connector *connector)
  222. {
  223. struct gma_connector *gma_connector;
  224. gma_connector = to_gma_connector(connector);
  225. return container_of(gma_connector, struct mdfld_dsi_connector, base);
  226. }
  227. static inline struct mdfld_dsi_encoder *mdfld_dsi_encoder(
  228. struct drm_encoder *encoder)
  229. {
  230. struct gma_encoder *gma_encoder;
  231. gma_encoder = to_gma_encoder(encoder);
  232. return container_of(gma_encoder, struct mdfld_dsi_encoder, base);
  233. }
  234. static inline struct mdfld_dsi_config *
  235. mdfld_dsi_get_config(struct mdfld_dsi_connector *connector)
  236. {
  237. if (!connector)
  238. return NULL;
  239. return (struct mdfld_dsi_config *)connector->private;
  240. }
  241. static inline void *mdfld_dsi_get_pkg_sender(struct mdfld_dsi_config *config)
  242. {
  243. struct mdfld_dsi_connector *dsi_connector;
  244. if (!config)
  245. return NULL;
  246. dsi_connector = config->connector;
  247. if (!dsi_connector)
  248. return NULL;
  249. return dsi_connector->pkg_sender;
  250. }
  251. static inline struct mdfld_dsi_config *
  252. mdfld_dsi_encoder_get_config(struct mdfld_dsi_encoder *encoder)
  253. {
  254. if (!encoder)
  255. return NULL;
  256. return (struct mdfld_dsi_config *)encoder->private;
  257. }
  258. static inline struct mdfld_dsi_connector *
  259. mdfld_dsi_encoder_get_connector(struct mdfld_dsi_encoder *encoder)
  260. {
  261. struct mdfld_dsi_config *config;
  262. if (!encoder)
  263. return NULL;
  264. config = mdfld_dsi_encoder_get_config(encoder);
  265. if (!config)
  266. return NULL;
  267. return config->connector;
  268. }
  269. static inline void *mdfld_dsi_encoder_get_pkg_sender(
  270. struct mdfld_dsi_encoder *encoder)
  271. {
  272. struct mdfld_dsi_config *dsi_config;
  273. dsi_config = mdfld_dsi_encoder_get_config(encoder);
  274. if (!dsi_config)
  275. return NULL;
  276. return mdfld_dsi_get_pkg_sender(dsi_config);
  277. }
  278. static inline int mdfld_dsi_encoder_get_pipe(struct mdfld_dsi_encoder *encoder)
  279. {
  280. struct mdfld_dsi_connector *connector;
  281. if (!encoder)
  282. return -1;
  283. connector = mdfld_dsi_encoder_get_connector(encoder);
  284. if (!connector)
  285. return -1;
  286. return connector->pipe;
  287. }
  288. /* Export functions */
  289. extern void mdfld_dsi_gen_fifo_ready(struct drm_device *dev,
  290. u32 gen_fifo_stat_reg, u32 fifo_stat);
  291. extern void mdfld_dsi_brightness_init(struct mdfld_dsi_config *dsi_config,
  292. int pipe);
  293. extern void mdfld_dsi_brightness_control(struct drm_device *dev, int pipe,
  294. int level);
  295. extern void mdfld_dsi_output_init(struct drm_device *dev,
  296. int pipe,
  297. const struct panel_funcs *p_vid_funcs);
  298. extern void mdfld_dsi_controller_init(struct mdfld_dsi_config *dsi_config,
  299. int pipe);
  300. extern int mdfld_dsi_get_power_mode(struct mdfld_dsi_config *dsi_config,
  301. u32 *mode, bool hs);
  302. extern int mdfld_dsi_panel_reset(int pipe);
  303. #endif /*__MDFLD_DSI_OUTPUT_H__*/