mdfld_dsi_dpi.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  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. #include "mdfld_dsi_dpi.h"
  28. #include "mdfld_output.h"
  29. #include "mdfld_dsi_pkg_sender.h"
  30. #include "psb_drv.h"
  31. #include "tc35876x-dsi-lvds.h"
  32. static void mdfld_dsi_dpi_shut_down(struct mdfld_dsi_dpi_output *output,
  33. int pipe);
  34. static void mdfld_wait_for_HS_DATA_FIFO(struct drm_device *dev, u32 pipe)
  35. {
  36. u32 gen_fifo_stat_reg = MIPI_GEN_FIFO_STAT_REG(pipe);
  37. int timeout = 0;
  38. udelay(500);
  39. /* This will time out after approximately 2+ seconds */
  40. while ((timeout < 20000) &&
  41. (REG_READ(gen_fifo_stat_reg) & DSI_FIFO_GEN_HS_DATA_FULL)) {
  42. udelay(100);
  43. timeout++;
  44. }
  45. if (timeout == 20000)
  46. DRM_INFO("MIPI: HS Data FIFO was never cleared!\n");
  47. }
  48. static void mdfld_wait_for_HS_CTRL_FIFO(struct drm_device *dev, u32 pipe)
  49. {
  50. u32 gen_fifo_stat_reg = MIPI_GEN_FIFO_STAT_REG(pipe);
  51. int timeout = 0;
  52. udelay(500);
  53. /* This will time out after approximately 2+ seconds */
  54. while ((timeout < 20000) && (REG_READ(gen_fifo_stat_reg)
  55. & DSI_FIFO_GEN_HS_CTRL_FULL)) {
  56. udelay(100);
  57. timeout++;
  58. }
  59. if (timeout == 20000)
  60. DRM_INFO("MIPI: HS CMD FIFO was never cleared!\n");
  61. }
  62. static void mdfld_wait_for_DPI_CTRL_FIFO(struct drm_device *dev, u32 pipe)
  63. {
  64. u32 gen_fifo_stat_reg = MIPI_GEN_FIFO_STAT_REG(pipe);
  65. int timeout = 0;
  66. udelay(500);
  67. /* This will time out after approximately 2+ seconds */
  68. while ((timeout < 20000) && ((REG_READ(gen_fifo_stat_reg) &
  69. DPI_FIFO_EMPTY) != DPI_FIFO_EMPTY)) {
  70. udelay(100);
  71. timeout++;
  72. }
  73. if (timeout == 20000)
  74. DRM_ERROR("MIPI: DPI FIFO was never cleared\n");
  75. }
  76. static void mdfld_wait_for_SPL_PKG_SENT(struct drm_device *dev, u32 pipe)
  77. {
  78. u32 intr_stat_reg = MIPI_INTR_STAT_REG(pipe);
  79. int timeout = 0;
  80. udelay(500);
  81. /* This will time out after approximately 2+ seconds */
  82. while ((timeout < 20000) && (!(REG_READ(intr_stat_reg)
  83. & DSI_INTR_STATE_SPL_PKG_SENT))) {
  84. udelay(100);
  85. timeout++;
  86. }
  87. if (timeout == 20000)
  88. DRM_ERROR("MIPI: SPL_PKT_SENT_INTERRUPT was not sent successfully!\n");
  89. }
  90. /* For TC35876X */
  91. static void dsi_set_device_ready_state(struct drm_device *dev, int state,
  92. int pipe)
  93. {
  94. REG_FLD_MOD(MIPI_DEVICE_READY_REG(pipe), !!state, 0, 0);
  95. }
  96. static void dsi_set_pipe_plane_enable_state(struct drm_device *dev,
  97. int state, int pipe)
  98. {
  99. struct drm_psb_private *dev_priv = dev->dev_private;
  100. u32 pipeconf_reg = PIPEACONF;
  101. u32 dspcntr_reg = DSPACNTR;
  102. u32 dspcntr = dev_priv->dspcntr[pipe];
  103. u32 mipi = MIPI_PORT_EN | PASS_FROM_SPHY_TO_AFE | SEL_FLOPPED_HSTX;
  104. if (pipe) {
  105. pipeconf_reg = PIPECCONF;
  106. dspcntr_reg = DSPCCNTR;
  107. } else
  108. mipi &= (~0x03);
  109. if (state) {
  110. /*Set up pipe */
  111. REG_WRITE(pipeconf_reg, BIT(31));
  112. if (REG_BIT_WAIT(pipeconf_reg, 1, 30))
  113. dev_err(&dev->pdev->dev, "%s: Pipe enable timeout\n",
  114. __func__);
  115. /*Set up display plane */
  116. REG_WRITE(dspcntr_reg, dspcntr);
  117. } else {
  118. u32 dspbase_reg = pipe ? MDFLD_DSPCBASE : MRST_DSPABASE;
  119. /* Put DSI lanes to ULPS to disable pipe */
  120. REG_FLD_MOD(MIPI_DEVICE_READY_REG(pipe), 2, 2, 1);
  121. REG_READ(MIPI_DEVICE_READY_REG(pipe)); /* posted write? */
  122. /* LP Hold */
  123. REG_FLD_MOD(MIPI_PORT_CONTROL(pipe), 0, 16, 16);
  124. REG_READ(MIPI_PORT_CONTROL(pipe)); /* posted write? */
  125. /* Disable display plane */
  126. REG_FLD_MOD(dspcntr_reg, 0, 31, 31);
  127. /* Flush the plane changes ??? posted write? */
  128. REG_WRITE(dspbase_reg, REG_READ(dspbase_reg));
  129. REG_READ(dspbase_reg);
  130. /* Disable PIPE */
  131. REG_FLD_MOD(pipeconf_reg, 0, 31, 31);
  132. if (REG_BIT_WAIT(pipeconf_reg, 0, 30))
  133. dev_err(&dev->pdev->dev, "%s: Pipe disable timeout\n",
  134. __func__);
  135. if (REG_BIT_WAIT(MIPI_GEN_FIFO_STAT_REG(pipe), 1, 28))
  136. dev_err(&dev->pdev->dev, "%s: FIFO not empty\n",
  137. __func__);
  138. }
  139. }
  140. static void mdfld_dsi_configure_down(struct mdfld_dsi_encoder *dsi_encoder,
  141. int pipe)
  142. {
  143. struct mdfld_dsi_dpi_output *dpi_output =
  144. MDFLD_DSI_DPI_OUTPUT(dsi_encoder);
  145. struct mdfld_dsi_config *dsi_config =
  146. mdfld_dsi_encoder_get_config(dsi_encoder);
  147. struct drm_device *dev = dsi_config->dev;
  148. struct drm_psb_private *dev_priv = dev->dev_private;
  149. if (!dev_priv->dpi_panel_on[pipe]) {
  150. dev_err(dev->dev, "DPI panel is already off\n");
  151. return;
  152. }
  153. tc35876x_toshiba_bridge_panel_off(dev);
  154. tc35876x_set_bridge_reset_state(dev, 1);
  155. dsi_set_pipe_plane_enable_state(dev, 0, pipe);
  156. mdfld_dsi_dpi_shut_down(dpi_output, pipe);
  157. dsi_set_device_ready_state(dev, 0, pipe);
  158. }
  159. static void mdfld_dsi_configure_up(struct mdfld_dsi_encoder *dsi_encoder,
  160. int pipe)
  161. {
  162. struct mdfld_dsi_dpi_output *dpi_output =
  163. MDFLD_DSI_DPI_OUTPUT(dsi_encoder);
  164. struct mdfld_dsi_config *dsi_config =
  165. mdfld_dsi_encoder_get_config(dsi_encoder);
  166. struct drm_device *dev = dsi_config->dev;
  167. struct drm_psb_private *dev_priv = dev->dev_private;
  168. if (dev_priv->dpi_panel_on[pipe]) {
  169. dev_err(dev->dev, "DPI panel is already on\n");
  170. return;
  171. }
  172. /* For resume path sequence */
  173. mdfld_dsi_dpi_shut_down(dpi_output, pipe);
  174. dsi_set_device_ready_state(dev, 0, pipe);
  175. dsi_set_device_ready_state(dev, 1, pipe);
  176. tc35876x_set_bridge_reset_state(dev, 0);
  177. tc35876x_configure_lvds_bridge(dev);
  178. mdfld_dsi_dpi_turn_on(dpi_output, pipe); /* Send turn on command */
  179. dsi_set_pipe_plane_enable_state(dev, 1, pipe);
  180. }
  181. /* End for TC35876X */
  182. /* ************************************************************************* *\
  183. * FUNCTION: mdfld_dsi_tpo_ic_init
  184. *
  185. * DESCRIPTION: This function is called only by mrst_dsi_mode_set and
  186. * restore_display_registers. since this function does not
  187. * acquire the mutex, it is important that the calling function
  188. * does!
  189. \* ************************************************************************* */
  190. static void mdfld_dsi_tpo_ic_init(struct mdfld_dsi_config *dsi_config, u32 pipe)
  191. {
  192. struct drm_device *dev = dsi_config->dev;
  193. u32 dcsChannelNumber = dsi_config->channel_num;
  194. u32 gen_data_reg = MIPI_HS_GEN_DATA_REG(pipe);
  195. u32 gen_ctrl_reg = MIPI_HS_GEN_CTRL_REG(pipe);
  196. u32 gen_ctrl_val = GEN_LONG_WRITE;
  197. DRM_INFO("Enter mrst init TPO MIPI display.\n");
  198. gen_ctrl_val |= dcsChannelNumber << DCS_CHANNEL_NUMBER_POS;
  199. /* Flip page order */
  200. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  201. REG_WRITE(gen_data_reg, 0x00008036);
  202. mdfld_wait_for_HS_CTRL_FIFO(dev, pipe);
  203. REG_WRITE(gen_ctrl_reg, gen_ctrl_val | (0x02 << WORD_COUNTS_POS));
  204. /* 0xF0 */
  205. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  206. REG_WRITE(gen_data_reg, 0x005a5af0);
  207. mdfld_wait_for_HS_CTRL_FIFO(dev, pipe);
  208. REG_WRITE(gen_ctrl_reg, gen_ctrl_val | (0x03 << WORD_COUNTS_POS));
  209. /* Write protection key */
  210. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  211. REG_WRITE(gen_data_reg, 0x005a5af1);
  212. mdfld_wait_for_HS_CTRL_FIFO(dev, pipe);
  213. REG_WRITE(gen_ctrl_reg, gen_ctrl_val | (0x03 << WORD_COUNTS_POS));
  214. /* 0xFC */
  215. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  216. REG_WRITE(gen_data_reg, 0x005a5afc);
  217. mdfld_wait_for_HS_CTRL_FIFO(dev, pipe);
  218. REG_WRITE(gen_ctrl_reg, gen_ctrl_val | (0x03 << WORD_COUNTS_POS));
  219. /* 0xB7 */
  220. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  221. REG_WRITE(gen_data_reg, 0x770000b7);
  222. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  223. REG_WRITE(gen_data_reg, 0x00000044);
  224. mdfld_wait_for_HS_CTRL_FIFO(dev, pipe);
  225. REG_WRITE(gen_ctrl_reg, gen_ctrl_val | (0x05 << WORD_COUNTS_POS));
  226. /* 0xB6 */
  227. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  228. REG_WRITE(gen_data_reg, 0x000a0ab6);
  229. mdfld_wait_for_HS_CTRL_FIFO(dev, pipe);
  230. REG_WRITE(gen_ctrl_reg, gen_ctrl_val | (0x03 << WORD_COUNTS_POS));
  231. /* 0xF2 */
  232. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  233. REG_WRITE(gen_data_reg, 0x081010f2);
  234. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  235. REG_WRITE(gen_data_reg, 0x4a070708);
  236. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  237. REG_WRITE(gen_data_reg, 0x000000c5);
  238. mdfld_wait_for_HS_CTRL_FIFO(dev, pipe);
  239. REG_WRITE(gen_ctrl_reg, gen_ctrl_val | (0x09 << WORD_COUNTS_POS));
  240. /* 0xF8 */
  241. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  242. REG_WRITE(gen_data_reg, 0x024003f8);
  243. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  244. REG_WRITE(gen_data_reg, 0x01030a04);
  245. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  246. REG_WRITE(gen_data_reg, 0x0e020220);
  247. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  248. REG_WRITE(gen_data_reg, 0x00000004);
  249. mdfld_wait_for_HS_CTRL_FIFO(dev, pipe);
  250. REG_WRITE(gen_ctrl_reg, gen_ctrl_val | (0x0d << WORD_COUNTS_POS));
  251. /* 0xE2 */
  252. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  253. REG_WRITE(gen_data_reg, 0x398fc3e2);
  254. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  255. REG_WRITE(gen_data_reg, 0x0000916f);
  256. mdfld_wait_for_HS_CTRL_FIFO(dev, pipe);
  257. REG_WRITE(gen_ctrl_reg, gen_ctrl_val | (0x06 << WORD_COUNTS_POS));
  258. /* 0xB0 */
  259. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  260. REG_WRITE(gen_data_reg, 0x000000b0);
  261. mdfld_wait_for_HS_CTRL_FIFO(dev, pipe);
  262. REG_WRITE(gen_ctrl_reg, gen_ctrl_val | (0x02 << WORD_COUNTS_POS));
  263. /* 0xF4 */
  264. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  265. REG_WRITE(gen_data_reg, 0x240242f4);
  266. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  267. REG_WRITE(gen_data_reg, 0x78ee2002);
  268. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  269. REG_WRITE(gen_data_reg, 0x2a071050);
  270. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  271. REG_WRITE(gen_data_reg, 0x507fee10);
  272. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  273. REG_WRITE(gen_data_reg, 0x10300710);
  274. mdfld_wait_for_HS_CTRL_FIFO(dev, pipe);
  275. REG_WRITE(gen_ctrl_reg, gen_ctrl_val | (0x14 << WORD_COUNTS_POS));
  276. /* 0xBA */
  277. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  278. REG_WRITE(gen_data_reg, 0x19fe07ba);
  279. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  280. REG_WRITE(gen_data_reg, 0x101c0a31);
  281. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  282. REG_WRITE(gen_data_reg, 0x00000010);
  283. mdfld_wait_for_HS_CTRL_FIFO(dev, pipe);
  284. REG_WRITE(gen_ctrl_reg, gen_ctrl_val | (0x09 << WORD_COUNTS_POS));
  285. /* 0xBB */
  286. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  287. REG_WRITE(gen_data_reg, 0x28ff07bb);
  288. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  289. REG_WRITE(gen_data_reg, 0x24280a31);
  290. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  291. REG_WRITE(gen_data_reg, 0x00000034);
  292. mdfld_wait_for_HS_CTRL_FIFO(dev, pipe);
  293. REG_WRITE(gen_ctrl_reg, gen_ctrl_val | (0x09 << WORD_COUNTS_POS));
  294. /* 0xFB */
  295. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  296. REG_WRITE(gen_data_reg, 0x535d05fb);
  297. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  298. REG_WRITE(gen_data_reg, 0x1b1a2130);
  299. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  300. REG_WRITE(gen_data_reg, 0x221e180e);
  301. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  302. REG_WRITE(gen_data_reg, 0x131d2120);
  303. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  304. REG_WRITE(gen_data_reg, 0x535d0508);
  305. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  306. REG_WRITE(gen_data_reg, 0x1c1a2131);
  307. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  308. REG_WRITE(gen_data_reg, 0x231f160d);
  309. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  310. REG_WRITE(gen_data_reg, 0x111b2220);
  311. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  312. REG_WRITE(gen_data_reg, 0x535c2008);
  313. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  314. REG_WRITE(gen_data_reg, 0x1f1d2433);
  315. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  316. REG_WRITE(gen_data_reg, 0x2c251a10);
  317. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  318. REG_WRITE(gen_data_reg, 0x2c34372d);
  319. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  320. REG_WRITE(gen_data_reg, 0x00000023);
  321. mdfld_wait_for_HS_CTRL_FIFO(dev, pipe);
  322. REG_WRITE(gen_ctrl_reg, gen_ctrl_val | (0x31 << WORD_COUNTS_POS));
  323. /* 0xFA */
  324. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  325. REG_WRITE(gen_data_reg, 0x525c0bfa);
  326. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  327. REG_WRITE(gen_data_reg, 0x1c1c232f);
  328. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  329. REG_WRITE(gen_data_reg, 0x2623190e);
  330. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  331. REG_WRITE(gen_data_reg, 0x18212625);
  332. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  333. REG_WRITE(gen_data_reg, 0x545d0d0e);
  334. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  335. REG_WRITE(gen_data_reg, 0x1e1d2333);
  336. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  337. REG_WRITE(gen_data_reg, 0x26231a10);
  338. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  339. REG_WRITE(gen_data_reg, 0x1a222725);
  340. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  341. REG_WRITE(gen_data_reg, 0x545d280f);
  342. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  343. REG_WRITE(gen_data_reg, 0x21202635);
  344. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  345. REG_WRITE(gen_data_reg, 0x31292013);
  346. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  347. REG_WRITE(gen_data_reg, 0x31393d33);
  348. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  349. REG_WRITE(gen_data_reg, 0x00000029);
  350. mdfld_wait_for_HS_CTRL_FIFO(dev, pipe);
  351. REG_WRITE(gen_ctrl_reg, gen_ctrl_val | (0x31 << WORD_COUNTS_POS));
  352. /* Set DM */
  353. mdfld_wait_for_HS_DATA_FIFO(dev, pipe);
  354. REG_WRITE(gen_data_reg, 0x000100f7);
  355. mdfld_wait_for_HS_CTRL_FIFO(dev, pipe);
  356. REG_WRITE(gen_ctrl_reg, gen_ctrl_val | (0x03 << WORD_COUNTS_POS));
  357. }
  358. static u16 mdfld_dsi_dpi_to_byte_clock_count(int pixel_clock_count,
  359. int num_lane, int bpp)
  360. {
  361. return (u16)((pixel_clock_count * bpp) / (num_lane * 8));
  362. }
  363. /*
  364. * Calculate the dpi time basing on a given drm mode @mode
  365. * return 0 on success.
  366. * FIXME: I was using proposed mode value for calculation, may need to
  367. * use crtc mode values later
  368. */
  369. int mdfld_dsi_dpi_timing_calculation(struct drm_display_mode *mode,
  370. struct mdfld_dsi_dpi_timing *dpi_timing,
  371. int num_lane, int bpp)
  372. {
  373. int pclk_hsync, pclk_hfp, pclk_hbp, pclk_hactive;
  374. int pclk_vsync, pclk_vfp, pclk_vbp;
  375. pclk_hactive = mode->hdisplay;
  376. pclk_hfp = mode->hsync_start - mode->hdisplay;
  377. pclk_hsync = mode->hsync_end - mode->hsync_start;
  378. pclk_hbp = mode->htotal - mode->hsync_end;
  379. pclk_vfp = mode->vsync_start - mode->vdisplay;
  380. pclk_vsync = mode->vsync_end - mode->vsync_start;
  381. pclk_vbp = mode->vtotal - mode->vsync_end;
  382. /*
  383. * byte clock counts were calculated by following formula
  384. * bclock_count = pclk_count * bpp / num_lane / 8
  385. */
  386. dpi_timing->hsync_count = mdfld_dsi_dpi_to_byte_clock_count(
  387. pclk_hsync, num_lane, bpp);
  388. dpi_timing->hbp_count = mdfld_dsi_dpi_to_byte_clock_count(
  389. pclk_hbp, num_lane, bpp);
  390. dpi_timing->hfp_count = mdfld_dsi_dpi_to_byte_clock_count(
  391. pclk_hfp, num_lane, bpp);
  392. dpi_timing->hactive_count = mdfld_dsi_dpi_to_byte_clock_count(
  393. pclk_hactive, num_lane, bpp);
  394. dpi_timing->vsync_count = mdfld_dsi_dpi_to_byte_clock_count(
  395. pclk_vsync, num_lane, bpp);
  396. dpi_timing->vbp_count = mdfld_dsi_dpi_to_byte_clock_count(
  397. pclk_vbp, num_lane, bpp);
  398. dpi_timing->vfp_count = mdfld_dsi_dpi_to_byte_clock_count(
  399. pclk_vfp, num_lane, bpp);
  400. return 0;
  401. }
  402. void mdfld_dsi_dpi_controller_init(struct mdfld_dsi_config *dsi_config,
  403. int pipe)
  404. {
  405. struct drm_device *dev = dsi_config->dev;
  406. int lane_count = dsi_config->lane_count;
  407. struct mdfld_dsi_dpi_timing dpi_timing;
  408. struct drm_display_mode *mode = dsi_config->mode;
  409. u32 val;
  410. /*un-ready device*/
  411. REG_FLD_MOD(MIPI_DEVICE_READY_REG(pipe), 0, 0, 0);
  412. /*init dsi adapter before kicking off*/
  413. REG_WRITE(MIPI_CTRL_REG(pipe), 0x00000018);
  414. /*enable all interrupts*/
  415. REG_WRITE(MIPI_INTR_EN_REG(pipe), 0xffffffff);
  416. /*set up func_prg*/
  417. val = lane_count;
  418. val |= dsi_config->channel_num << DSI_DPI_VIRT_CHANNEL_OFFSET;
  419. switch (dsi_config->bpp) {
  420. case 16:
  421. val |= DSI_DPI_COLOR_FORMAT_RGB565;
  422. break;
  423. case 18:
  424. val |= DSI_DPI_COLOR_FORMAT_RGB666;
  425. break;
  426. case 24:
  427. val |= DSI_DPI_COLOR_FORMAT_RGB888;
  428. break;
  429. default:
  430. DRM_ERROR("unsupported color format, bpp = %d\n",
  431. dsi_config->bpp);
  432. }
  433. REG_WRITE(MIPI_DSI_FUNC_PRG_REG(pipe), val);
  434. REG_WRITE(MIPI_HS_TX_TIMEOUT_REG(pipe),
  435. (mode->vtotal * mode->htotal * dsi_config->bpp /
  436. (8 * lane_count)) & DSI_HS_TX_TIMEOUT_MASK);
  437. REG_WRITE(MIPI_LP_RX_TIMEOUT_REG(pipe),
  438. 0xffff & DSI_LP_RX_TIMEOUT_MASK);
  439. /*max value: 20 clock cycles of txclkesc*/
  440. REG_WRITE(MIPI_TURN_AROUND_TIMEOUT_REG(pipe),
  441. 0x14 & DSI_TURN_AROUND_TIMEOUT_MASK);
  442. /*min 21 txclkesc, max: ffffh*/
  443. REG_WRITE(MIPI_DEVICE_RESET_TIMER_REG(pipe),
  444. 0xffff & DSI_RESET_TIMER_MASK);
  445. REG_WRITE(MIPI_DPI_RESOLUTION_REG(pipe),
  446. mode->vdisplay << 16 | mode->hdisplay);
  447. /*set DPI timing registers*/
  448. mdfld_dsi_dpi_timing_calculation(mode, &dpi_timing,
  449. dsi_config->lane_count, dsi_config->bpp);
  450. REG_WRITE(MIPI_HSYNC_COUNT_REG(pipe),
  451. dpi_timing.hsync_count & DSI_DPI_TIMING_MASK);
  452. REG_WRITE(MIPI_HBP_COUNT_REG(pipe),
  453. dpi_timing.hbp_count & DSI_DPI_TIMING_MASK);
  454. REG_WRITE(MIPI_HFP_COUNT_REG(pipe),
  455. dpi_timing.hfp_count & DSI_DPI_TIMING_MASK);
  456. REG_WRITE(MIPI_HACTIVE_COUNT_REG(pipe),
  457. dpi_timing.hactive_count & DSI_DPI_TIMING_MASK);
  458. REG_WRITE(MIPI_VSYNC_COUNT_REG(pipe),
  459. dpi_timing.vsync_count & DSI_DPI_TIMING_MASK);
  460. REG_WRITE(MIPI_VBP_COUNT_REG(pipe),
  461. dpi_timing.vbp_count & DSI_DPI_TIMING_MASK);
  462. REG_WRITE(MIPI_VFP_COUNT_REG(pipe),
  463. dpi_timing.vfp_count & DSI_DPI_TIMING_MASK);
  464. REG_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT_REG(pipe), 0x46);
  465. /*min: 7d0 max: 4e20*/
  466. REG_WRITE(MIPI_INIT_COUNT_REG(pipe), 0x000007d0);
  467. /*set up video mode*/
  468. val = dsi_config->video_mode | DSI_DPI_COMPLETE_LAST_LINE;
  469. REG_WRITE(MIPI_VIDEO_MODE_FORMAT_REG(pipe), val);
  470. REG_WRITE(MIPI_EOT_DISABLE_REG(pipe), 0x00000000);
  471. REG_WRITE(MIPI_LP_BYTECLK_REG(pipe), 0x00000004);
  472. /*TODO: figure out how to setup these registers*/
  473. if (mdfld_get_panel_type(dev, pipe) == TC35876X)
  474. REG_WRITE(MIPI_DPHY_PARAM_REG(pipe), 0x2A0c6008);
  475. else
  476. REG_WRITE(MIPI_DPHY_PARAM_REG(pipe), 0x150c3408);
  477. REG_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT_REG(pipe), (0xa << 16) | 0x14);
  478. if (mdfld_get_panel_type(dev, pipe) == TC35876X)
  479. tc35876x_set_bridge_reset_state(dev, 0); /*Pull High Reset */
  480. /*set device ready*/
  481. REG_FLD_MOD(MIPI_DEVICE_READY_REG(pipe), 1, 0, 0);
  482. }
  483. void mdfld_dsi_dpi_turn_on(struct mdfld_dsi_dpi_output *output, int pipe)
  484. {
  485. struct drm_device *dev = output->dev;
  486. /* clear special packet sent bit */
  487. if (REG_READ(MIPI_INTR_STAT_REG(pipe)) & DSI_INTR_STATE_SPL_PKG_SENT)
  488. REG_WRITE(MIPI_INTR_STAT_REG(pipe),
  489. DSI_INTR_STATE_SPL_PKG_SENT);
  490. /*send turn on package*/
  491. REG_WRITE(MIPI_DPI_CONTROL_REG(pipe), DSI_DPI_CTRL_HS_TURN_ON);
  492. /*wait for SPL_PKG_SENT interrupt*/
  493. mdfld_wait_for_SPL_PKG_SENT(dev, pipe);
  494. if (REG_READ(MIPI_INTR_STAT_REG(pipe)) & DSI_INTR_STATE_SPL_PKG_SENT)
  495. REG_WRITE(MIPI_INTR_STAT_REG(pipe),
  496. DSI_INTR_STATE_SPL_PKG_SENT);
  497. output->panel_on = 1;
  498. /* FIXME the following is disabled to WA the X slow start issue
  499. for TMD panel
  500. if (pipe == 2)
  501. dev_priv->dpi_panel_on2 = true;
  502. else if (pipe == 0)
  503. dev_priv->dpi_panel_on = true; */
  504. }
  505. static void mdfld_dsi_dpi_shut_down(struct mdfld_dsi_dpi_output *output,
  506. int pipe)
  507. {
  508. struct drm_device *dev = output->dev;
  509. /*if output is on, or mode setting didn't happen, ignore this*/
  510. if ((!output->panel_on) || output->first_boot) {
  511. output->first_boot = 0;
  512. return;
  513. }
  514. /* Wait for dpi fifo to empty */
  515. mdfld_wait_for_DPI_CTRL_FIFO(dev, pipe);
  516. /* Clear the special packet interrupt bit if set */
  517. if (REG_READ(MIPI_INTR_STAT_REG(pipe)) & DSI_INTR_STATE_SPL_PKG_SENT)
  518. REG_WRITE(MIPI_INTR_STAT_REG(pipe),
  519. DSI_INTR_STATE_SPL_PKG_SENT);
  520. if (REG_READ(MIPI_DPI_CONTROL_REG(pipe)) == DSI_DPI_CTRL_HS_SHUTDOWN)
  521. goto shutdown_out;
  522. REG_WRITE(MIPI_DPI_CONTROL_REG(pipe), DSI_DPI_CTRL_HS_SHUTDOWN);
  523. shutdown_out:
  524. output->panel_on = 0;
  525. output->first_boot = 0;
  526. /* FIXME the following is disabled to WA the X slow start issue
  527. for TMD panel
  528. if (pipe == 2)
  529. dev_priv->dpi_panel_on2 = false;
  530. else if (pipe == 0)
  531. dev_priv->dpi_panel_on = false; */
  532. }
  533. static void mdfld_dsi_dpi_set_power(struct drm_encoder *encoder, bool on)
  534. {
  535. struct mdfld_dsi_encoder *dsi_encoder = mdfld_dsi_encoder(encoder);
  536. struct mdfld_dsi_dpi_output *dpi_output =
  537. MDFLD_DSI_DPI_OUTPUT(dsi_encoder);
  538. struct mdfld_dsi_config *dsi_config =
  539. mdfld_dsi_encoder_get_config(dsi_encoder);
  540. int pipe = mdfld_dsi_encoder_get_pipe(dsi_encoder);
  541. struct drm_device *dev = dsi_config->dev;
  542. struct drm_psb_private *dev_priv = dev->dev_private;
  543. /*start up display island if it was shutdown*/
  544. if (!gma_power_begin(dev, true))
  545. return;
  546. if (on) {
  547. if (mdfld_get_panel_type(dev, pipe) == TMD_VID)
  548. mdfld_dsi_dpi_turn_on(dpi_output, pipe);
  549. else if (mdfld_get_panel_type(dev, pipe) == TC35876X)
  550. mdfld_dsi_configure_up(dsi_encoder, pipe);
  551. else {
  552. /*enable mipi port*/
  553. REG_WRITE(MIPI_PORT_CONTROL(pipe),
  554. REG_READ(MIPI_PORT_CONTROL(pipe)) | BIT(31));
  555. REG_READ(MIPI_PORT_CONTROL(pipe));
  556. mdfld_dsi_dpi_turn_on(dpi_output, pipe);
  557. mdfld_dsi_tpo_ic_init(dsi_config, pipe);
  558. }
  559. dev_priv->dpi_panel_on[pipe] = true;
  560. } else {
  561. if (mdfld_get_panel_type(dev, pipe) == TMD_VID)
  562. mdfld_dsi_dpi_shut_down(dpi_output, pipe);
  563. else if (mdfld_get_panel_type(dev, pipe) == TC35876X)
  564. mdfld_dsi_configure_down(dsi_encoder, pipe);
  565. else {
  566. mdfld_dsi_dpi_shut_down(dpi_output, pipe);
  567. /*disable mipi port*/
  568. REG_WRITE(MIPI_PORT_CONTROL(pipe),
  569. REG_READ(MIPI_PORT_CONTROL(pipe)) & ~BIT(31));
  570. REG_READ(MIPI_PORT_CONTROL(pipe));
  571. }
  572. dev_priv->dpi_panel_on[pipe] = false;
  573. }
  574. gma_power_end(dev);
  575. }
  576. void mdfld_dsi_dpi_dpms(struct drm_encoder *encoder, int mode)
  577. {
  578. mdfld_dsi_dpi_set_power(encoder, mode == DRM_MODE_DPMS_ON);
  579. }
  580. bool mdfld_dsi_dpi_mode_fixup(struct drm_encoder *encoder,
  581. struct drm_display_mode *mode,
  582. struct drm_display_mode *adjusted_mode)
  583. {
  584. struct mdfld_dsi_encoder *dsi_encoder = mdfld_dsi_encoder(encoder);
  585. struct mdfld_dsi_config *dsi_config =
  586. mdfld_dsi_encoder_get_config(dsi_encoder);
  587. struct drm_display_mode *fixed_mode = dsi_config->fixed_mode;
  588. if (fixed_mode) {
  589. adjusted_mode->hdisplay = fixed_mode->hdisplay;
  590. adjusted_mode->hsync_start = fixed_mode->hsync_start;
  591. adjusted_mode->hsync_end = fixed_mode->hsync_end;
  592. adjusted_mode->htotal = fixed_mode->htotal;
  593. adjusted_mode->vdisplay = fixed_mode->vdisplay;
  594. adjusted_mode->vsync_start = fixed_mode->vsync_start;
  595. adjusted_mode->vsync_end = fixed_mode->vsync_end;
  596. adjusted_mode->vtotal = fixed_mode->vtotal;
  597. adjusted_mode->clock = fixed_mode->clock;
  598. drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V);
  599. }
  600. return true;
  601. }
  602. void mdfld_dsi_dpi_prepare(struct drm_encoder *encoder)
  603. {
  604. mdfld_dsi_dpi_set_power(encoder, false);
  605. }
  606. void mdfld_dsi_dpi_commit(struct drm_encoder *encoder)
  607. {
  608. mdfld_dsi_dpi_set_power(encoder, true);
  609. }
  610. /* For TC35876X */
  611. /* This functionality was implemented in FW in iCDK */
  612. /* But removed in DV0 and later. So need to add here. */
  613. static void mipi_set_properties(struct mdfld_dsi_config *dsi_config, int pipe)
  614. {
  615. struct drm_device *dev = dsi_config->dev;
  616. REG_WRITE(MIPI_CTRL_REG(pipe), 0x00000018);
  617. REG_WRITE(MIPI_INTR_EN_REG(pipe), 0xffffffff);
  618. REG_WRITE(MIPI_HS_TX_TIMEOUT_REG(pipe), 0xffffff);
  619. REG_WRITE(MIPI_LP_RX_TIMEOUT_REG(pipe), 0xffffff);
  620. REG_WRITE(MIPI_TURN_AROUND_TIMEOUT_REG(pipe), 0x14);
  621. REG_WRITE(MIPI_DEVICE_RESET_TIMER_REG(pipe), 0xff);
  622. REG_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT_REG(pipe), 0x25);
  623. REG_WRITE(MIPI_INIT_COUNT_REG(pipe), 0xf0);
  624. REG_WRITE(MIPI_EOT_DISABLE_REG(pipe), 0x00000000);
  625. REG_WRITE(MIPI_LP_BYTECLK_REG(pipe), 0x00000004);
  626. REG_WRITE(MIPI_DBI_BW_CTRL_REG(pipe), 0x00000820);
  627. REG_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT_REG(pipe), (0xa << 16) | 0x14);
  628. }
  629. static void mdfld_mipi_set_video_timing(struct mdfld_dsi_config *dsi_config,
  630. int pipe)
  631. {
  632. struct drm_device *dev = dsi_config->dev;
  633. struct mdfld_dsi_dpi_timing dpi_timing;
  634. struct drm_display_mode *mode = dsi_config->mode;
  635. mdfld_dsi_dpi_timing_calculation(mode, &dpi_timing,
  636. dsi_config->lane_count,
  637. dsi_config->bpp);
  638. REG_WRITE(MIPI_DPI_RESOLUTION_REG(pipe),
  639. mode->vdisplay << 16 | mode->hdisplay);
  640. REG_WRITE(MIPI_HSYNC_COUNT_REG(pipe),
  641. dpi_timing.hsync_count & DSI_DPI_TIMING_MASK);
  642. REG_WRITE(MIPI_HBP_COUNT_REG(pipe),
  643. dpi_timing.hbp_count & DSI_DPI_TIMING_MASK);
  644. REG_WRITE(MIPI_HFP_COUNT_REG(pipe),
  645. dpi_timing.hfp_count & DSI_DPI_TIMING_MASK);
  646. REG_WRITE(MIPI_HACTIVE_COUNT_REG(pipe),
  647. dpi_timing.hactive_count & DSI_DPI_TIMING_MASK);
  648. REG_WRITE(MIPI_VSYNC_COUNT_REG(pipe),
  649. dpi_timing.vsync_count & DSI_DPI_TIMING_MASK);
  650. REG_WRITE(MIPI_VBP_COUNT_REG(pipe),
  651. dpi_timing.vbp_count & DSI_DPI_TIMING_MASK);
  652. REG_WRITE(MIPI_VFP_COUNT_REG(pipe),
  653. dpi_timing.vfp_count & DSI_DPI_TIMING_MASK);
  654. }
  655. static void mdfld_mipi_config(struct mdfld_dsi_config *dsi_config, int pipe)
  656. {
  657. struct drm_device *dev = dsi_config->dev;
  658. int lane_count = dsi_config->lane_count;
  659. if (pipe) {
  660. REG_WRITE(MIPI_PORT_CONTROL(0), 0x00000002);
  661. REG_WRITE(MIPI_PORT_CONTROL(2), 0x80000000);
  662. } else {
  663. REG_WRITE(MIPI_PORT_CONTROL(0), 0x80010000);
  664. REG_WRITE(MIPI_PORT_CONTROL(2), 0x00);
  665. }
  666. REG_WRITE(MIPI_DPHY_PARAM_REG(pipe), 0x150A600F);
  667. REG_WRITE(MIPI_VIDEO_MODE_FORMAT_REG(pipe), 0x0000000F);
  668. /* lane_count = 3 */
  669. REG_WRITE(MIPI_DSI_FUNC_PRG_REG(pipe), 0x00000200 | lane_count);
  670. mdfld_mipi_set_video_timing(dsi_config, pipe);
  671. }
  672. static void mdfld_set_pipe_timing(struct mdfld_dsi_config *dsi_config, int pipe)
  673. {
  674. struct drm_device *dev = dsi_config->dev;
  675. struct drm_display_mode *mode = dsi_config->mode;
  676. REG_WRITE(HTOTAL_A, ((mode->htotal - 1) << 16) | (mode->hdisplay - 1));
  677. REG_WRITE(HBLANK_A, ((mode->htotal - 1) << 16) | (mode->hdisplay - 1));
  678. REG_WRITE(HSYNC_A,
  679. ((mode->hsync_end - 1) << 16) | (mode->hsync_start - 1));
  680. REG_WRITE(VTOTAL_A, ((mode->vtotal - 1) << 16) | (mode->vdisplay - 1));
  681. REG_WRITE(VBLANK_A, ((mode->vtotal - 1) << 16) | (mode->vdisplay - 1));
  682. REG_WRITE(VSYNC_A,
  683. ((mode->vsync_end - 1) << 16) | (mode->vsync_start - 1));
  684. REG_WRITE(PIPEASRC,
  685. ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
  686. }
  687. /* End for TC35876X */
  688. void mdfld_dsi_dpi_mode_set(struct drm_encoder *encoder,
  689. struct drm_display_mode *mode,
  690. struct drm_display_mode *adjusted_mode)
  691. {
  692. struct mdfld_dsi_encoder *dsi_encoder = mdfld_dsi_encoder(encoder);
  693. struct mdfld_dsi_dpi_output *dpi_output =
  694. MDFLD_DSI_DPI_OUTPUT(dsi_encoder);
  695. struct mdfld_dsi_config *dsi_config =
  696. mdfld_dsi_encoder_get_config(dsi_encoder);
  697. struct drm_device *dev = dsi_config->dev;
  698. struct drm_psb_private *dev_priv = dev->dev_private;
  699. int pipe = mdfld_dsi_encoder_get_pipe(dsi_encoder);
  700. u32 pipeconf_reg = PIPEACONF;
  701. u32 dspcntr_reg = DSPACNTR;
  702. u32 pipeconf = dev_priv->pipeconf[pipe];
  703. u32 dspcntr = dev_priv->dspcntr[pipe];
  704. u32 mipi = MIPI_PORT_EN | PASS_FROM_SPHY_TO_AFE | SEL_FLOPPED_HSTX;
  705. if (pipe) {
  706. pipeconf_reg = PIPECCONF;
  707. dspcntr_reg = DSPCCNTR;
  708. } else {
  709. if (mdfld_get_panel_type(dev, pipe) == TC35876X)
  710. mipi &= (~0x03); /* Use all four lanes */
  711. else
  712. mipi |= 2;
  713. }
  714. /*start up display island if it was shutdown*/
  715. if (!gma_power_begin(dev, true))
  716. return;
  717. if (mdfld_get_panel_type(dev, pipe) == TC35876X) {
  718. /*
  719. * The following logic is required to reset the bridge and
  720. * configure. This also starts the DSI clock at 200MHz.
  721. */
  722. tc35876x_set_bridge_reset_state(dev, 0); /*Pull High Reset */
  723. tc35876x_toshiba_bridge_panel_on(dev);
  724. udelay(100);
  725. /* Now start the DSI clock */
  726. REG_WRITE(MRST_DPLL_A, 0x00);
  727. REG_WRITE(MRST_FPA0, 0xC1);
  728. REG_WRITE(MRST_DPLL_A, 0x00800000);
  729. udelay(500);
  730. REG_WRITE(MRST_DPLL_A, 0x80800000);
  731. if (REG_BIT_WAIT(pipeconf_reg, 1, 29))
  732. dev_err(&dev->pdev->dev, "%s: DSI PLL lock timeout\n",
  733. __func__);
  734. REG_WRITE(MIPI_DPHY_PARAM_REG(pipe), 0x2A0c6008);
  735. mipi_set_properties(dsi_config, pipe);
  736. mdfld_mipi_config(dsi_config, pipe);
  737. mdfld_set_pipe_timing(dsi_config, pipe);
  738. REG_WRITE(DSPABASE, 0x00);
  739. REG_WRITE(DSPASTRIDE, (mode->hdisplay * 4));
  740. REG_WRITE(DSPASIZE,
  741. ((mode->vdisplay - 1) << 16) | (mode->hdisplay - 1));
  742. REG_WRITE(DSPACNTR, 0x98000000);
  743. REG_WRITE(DSPASURF, 0x00);
  744. REG_WRITE(VGACNTRL, 0x80000000);
  745. REG_WRITE(DEVICE_READY_REG, 0x00000001);
  746. REG_WRITE(MIPI_PORT_CONTROL(pipe), 0x80810000);
  747. } else {
  748. /*set up mipi port FIXME: do at init time */
  749. REG_WRITE(MIPI_PORT_CONTROL(pipe), mipi);
  750. }
  751. REG_READ(MIPI_PORT_CONTROL(pipe));
  752. if (mdfld_get_panel_type(dev, pipe) == TMD_VID) {
  753. /* NOP */
  754. } else if (mdfld_get_panel_type(dev, pipe) == TC35876X) {
  755. /* set up DSI controller DPI interface */
  756. mdfld_dsi_dpi_controller_init(dsi_config, pipe);
  757. /* Configure MIPI Bridge and Panel */
  758. tc35876x_configure_lvds_bridge(dev);
  759. dev_priv->dpi_panel_on[pipe] = true;
  760. } else {
  761. /*turn on DPI interface*/
  762. mdfld_dsi_dpi_turn_on(dpi_output, pipe);
  763. }
  764. /*set up pipe*/
  765. REG_WRITE(pipeconf_reg, pipeconf);
  766. REG_READ(pipeconf_reg);
  767. /*set up display plane*/
  768. REG_WRITE(dspcntr_reg, dspcntr);
  769. REG_READ(dspcntr_reg);
  770. msleep(20); /* FIXME: this should wait for vblank */
  771. if (mdfld_get_panel_type(dev, pipe) == TMD_VID) {
  772. /* NOP */
  773. } else if (mdfld_get_panel_type(dev, pipe) == TC35876X) {
  774. mdfld_dsi_dpi_turn_on(dpi_output, pipe);
  775. } else {
  776. /* init driver ic */
  777. mdfld_dsi_tpo_ic_init(dsi_config, pipe);
  778. /*init backlight*/
  779. mdfld_dsi_brightness_init(dsi_config, pipe);
  780. }
  781. gma_power_end(dev);
  782. }
  783. /*
  784. * Init DSI DPI encoder.
  785. * Allocate an mdfld_dsi_encoder and attach it to given @dsi_connector
  786. * return pointer of newly allocated DPI encoder, NULL on error
  787. */
  788. struct mdfld_dsi_encoder *mdfld_dsi_dpi_init(struct drm_device *dev,
  789. struct mdfld_dsi_connector *dsi_connector,
  790. const struct panel_funcs *p_funcs)
  791. {
  792. struct mdfld_dsi_dpi_output *dpi_output = NULL;
  793. struct mdfld_dsi_config *dsi_config;
  794. struct drm_connector *connector = NULL;
  795. struct drm_encoder *encoder = NULL;
  796. int pipe;
  797. u32 data;
  798. int ret;
  799. pipe = dsi_connector->pipe;
  800. if (mdfld_get_panel_type(dev, pipe) != TC35876X) {
  801. dsi_config = mdfld_dsi_get_config(dsi_connector);
  802. /* panel hard-reset */
  803. if (p_funcs->reset) {
  804. ret = p_funcs->reset(pipe);
  805. if (ret) {
  806. DRM_ERROR("Panel %d hard-reset failed\n", pipe);
  807. return NULL;
  808. }
  809. }
  810. /* panel drvIC init */
  811. if (p_funcs->drv_ic_init)
  812. p_funcs->drv_ic_init(dsi_config, pipe);
  813. /* panel power mode detect */
  814. ret = mdfld_dsi_get_power_mode(dsi_config, &data, false);
  815. if (ret) {
  816. DRM_ERROR("Panel %d get power mode failed\n", pipe);
  817. dsi_connector->status = connector_status_disconnected;
  818. } else {
  819. DRM_INFO("pipe %d power mode 0x%x\n", pipe, data);
  820. dsi_connector->status = connector_status_connected;
  821. }
  822. }
  823. dpi_output = kzalloc(sizeof(struct mdfld_dsi_dpi_output), GFP_KERNEL);
  824. if (!dpi_output) {
  825. DRM_ERROR("No memory\n");
  826. return NULL;
  827. }
  828. if (dsi_connector->pipe)
  829. dpi_output->panel_on = 0;
  830. else
  831. dpi_output->panel_on = 0;
  832. dpi_output->dev = dev;
  833. if (mdfld_get_panel_type(dev, pipe) != TC35876X)
  834. dpi_output->p_funcs = p_funcs;
  835. dpi_output->first_boot = 1;
  836. /*get fixed mode*/
  837. dsi_config = mdfld_dsi_get_config(dsi_connector);
  838. /*create drm encoder object*/
  839. connector = &dsi_connector->base.base;
  840. encoder = &dpi_output->base.base.base;
  841. drm_encoder_init(dev,
  842. encoder,
  843. p_funcs->encoder_funcs,
  844. DRM_MODE_ENCODER_LVDS);
  845. drm_encoder_helper_add(encoder,
  846. p_funcs->encoder_helper_funcs);
  847. /*attach to given connector*/
  848. drm_mode_connector_attach_encoder(connector, encoder);
  849. /*set possible crtcs and clones*/
  850. if (dsi_connector->pipe) {
  851. encoder->possible_crtcs = (1 << 2);
  852. encoder->possible_clones = (1 << 1);
  853. } else {
  854. encoder->possible_crtcs = (1 << 0);
  855. encoder->possible_clones = (1 << 0);
  856. }
  857. dsi_connector->base.encoder = &dpi_output->base.base;
  858. return &dpi_output->base;
  859. }