mdfld_dsi_dpi.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020
  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. const 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, dspcntr;
  703. u32 mipi = MIPI_PORT_EN | PASS_FROM_SPHY_TO_AFE | SEL_FLOPPED_HSTX;
  704. if (WARN_ON(pipe < 0))
  705. return;
  706. pipeconf = dev_priv->pipeconf[pipe];
  707. dspcntr = dev_priv->dspcntr[pipe];
  708. if (pipe) {
  709. pipeconf_reg = PIPECCONF;
  710. dspcntr_reg = DSPCCNTR;
  711. } else {
  712. if (mdfld_get_panel_type(dev, pipe) == TC35876X)
  713. mipi &= (~0x03); /* Use all four lanes */
  714. else
  715. mipi |= 2;
  716. }
  717. /*start up display island if it was shutdown*/
  718. if (!gma_power_begin(dev, true))
  719. return;
  720. if (mdfld_get_panel_type(dev, pipe) == TC35876X) {
  721. /*
  722. * The following logic is required to reset the bridge and
  723. * configure. This also starts the DSI clock at 200MHz.
  724. */
  725. tc35876x_set_bridge_reset_state(dev, 0); /*Pull High Reset */
  726. tc35876x_toshiba_bridge_panel_on(dev);
  727. udelay(100);
  728. /* Now start the DSI clock */
  729. REG_WRITE(MRST_DPLL_A, 0x00);
  730. REG_WRITE(MRST_FPA0, 0xC1);
  731. REG_WRITE(MRST_DPLL_A, 0x00800000);
  732. udelay(500);
  733. REG_WRITE(MRST_DPLL_A, 0x80800000);
  734. if (REG_BIT_WAIT(pipeconf_reg, 1, 29))
  735. dev_err(&dev->pdev->dev, "%s: DSI PLL lock timeout\n",
  736. __func__);
  737. REG_WRITE(MIPI_DPHY_PARAM_REG(pipe), 0x2A0c6008);
  738. mipi_set_properties(dsi_config, pipe);
  739. mdfld_mipi_config(dsi_config, pipe);
  740. mdfld_set_pipe_timing(dsi_config, pipe);
  741. REG_WRITE(DSPABASE, 0x00);
  742. REG_WRITE(DSPASIZE,
  743. ((mode->vdisplay - 1) << 16) | (mode->hdisplay - 1));
  744. REG_WRITE(DSPACNTR, 0x98000000);
  745. REG_WRITE(DSPASURF, 0x00);
  746. REG_WRITE(VGACNTRL, 0x80000000);
  747. REG_WRITE(DEVICE_READY_REG, 0x00000001);
  748. REG_WRITE(MIPI_PORT_CONTROL(pipe), 0x80810000);
  749. } else {
  750. /*set up mipi port FIXME: do at init time */
  751. REG_WRITE(MIPI_PORT_CONTROL(pipe), mipi);
  752. }
  753. REG_READ(MIPI_PORT_CONTROL(pipe));
  754. if (mdfld_get_panel_type(dev, pipe) == TMD_VID) {
  755. /* NOP */
  756. } else if (mdfld_get_panel_type(dev, pipe) == TC35876X) {
  757. /* set up DSI controller DPI interface */
  758. mdfld_dsi_dpi_controller_init(dsi_config, pipe);
  759. /* Configure MIPI Bridge and Panel */
  760. tc35876x_configure_lvds_bridge(dev);
  761. dev_priv->dpi_panel_on[pipe] = true;
  762. } else {
  763. /*turn on DPI interface*/
  764. mdfld_dsi_dpi_turn_on(dpi_output, pipe);
  765. }
  766. /*set up pipe*/
  767. REG_WRITE(pipeconf_reg, pipeconf);
  768. REG_READ(pipeconf_reg);
  769. /*set up display plane*/
  770. REG_WRITE(dspcntr_reg, dspcntr);
  771. REG_READ(dspcntr_reg);
  772. msleep(20); /* FIXME: this should wait for vblank */
  773. if (mdfld_get_panel_type(dev, pipe) == TMD_VID) {
  774. /* NOP */
  775. } else if (mdfld_get_panel_type(dev, pipe) == TC35876X) {
  776. mdfld_dsi_dpi_turn_on(dpi_output, pipe);
  777. } else {
  778. /* init driver ic */
  779. mdfld_dsi_tpo_ic_init(dsi_config, pipe);
  780. /*init backlight*/
  781. mdfld_dsi_brightness_init(dsi_config, pipe);
  782. }
  783. gma_power_end(dev);
  784. }
  785. /*
  786. * Init DSI DPI encoder.
  787. * Allocate an mdfld_dsi_encoder and attach it to given @dsi_connector
  788. * return pointer of newly allocated DPI encoder, NULL on error
  789. */
  790. struct mdfld_dsi_encoder *mdfld_dsi_dpi_init(struct drm_device *dev,
  791. struct mdfld_dsi_connector *dsi_connector,
  792. const struct panel_funcs *p_funcs)
  793. {
  794. struct mdfld_dsi_dpi_output *dpi_output = NULL;
  795. struct mdfld_dsi_config *dsi_config;
  796. struct drm_connector *connector = NULL;
  797. struct drm_encoder *encoder = NULL;
  798. int pipe;
  799. u32 data;
  800. int ret;
  801. pipe = dsi_connector->pipe;
  802. if (mdfld_get_panel_type(dev, pipe) != TC35876X) {
  803. dsi_config = mdfld_dsi_get_config(dsi_connector);
  804. /* panel hard-reset */
  805. if (p_funcs->reset) {
  806. ret = p_funcs->reset(pipe);
  807. if (ret) {
  808. DRM_ERROR("Panel %d hard-reset failed\n", pipe);
  809. return NULL;
  810. }
  811. }
  812. /* panel drvIC init */
  813. if (p_funcs->drv_ic_init)
  814. p_funcs->drv_ic_init(dsi_config, pipe);
  815. /* panel power mode detect */
  816. ret = mdfld_dsi_get_power_mode(dsi_config, &data, false);
  817. if (ret) {
  818. DRM_ERROR("Panel %d get power mode failed\n", pipe);
  819. dsi_connector->status = connector_status_disconnected;
  820. } else {
  821. DRM_INFO("pipe %d power mode 0x%x\n", pipe, data);
  822. dsi_connector->status = connector_status_connected;
  823. }
  824. }
  825. dpi_output = kzalloc(sizeof(struct mdfld_dsi_dpi_output), GFP_KERNEL);
  826. if (!dpi_output) {
  827. DRM_ERROR("No memory\n");
  828. return NULL;
  829. }
  830. if (dsi_connector->pipe)
  831. dpi_output->panel_on = 0;
  832. else
  833. dpi_output->panel_on = 0;
  834. dpi_output->dev = dev;
  835. if (mdfld_get_panel_type(dev, pipe) != TC35876X)
  836. dpi_output->p_funcs = p_funcs;
  837. dpi_output->first_boot = 1;
  838. /*get fixed mode*/
  839. dsi_config = mdfld_dsi_get_config(dsi_connector);
  840. /*create drm encoder object*/
  841. connector = &dsi_connector->base.base;
  842. encoder = &dpi_output->base.base.base;
  843. drm_encoder_init(dev,
  844. encoder,
  845. p_funcs->encoder_funcs,
  846. DRM_MODE_ENCODER_LVDS);
  847. drm_encoder_helper_add(encoder,
  848. p_funcs->encoder_helper_funcs);
  849. /*attach to given connector*/
  850. drm_mode_connector_attach_encoder(connector, encoder);
  851. /*set possible crtcs and clones*/
  852. if (dsi_connector->pipe) {
  853. encoder->possible_crtcs = (1 << 2);
  854. encoder->possible_clones = (1 << 1);
  855. } else {
  856. encoder->possible_crtcs = (1 << 0);
  857. encoder->possible_clones = (1 << 0);
  858. }
  859. dsi_connector->base.encoder = &dpi_output->base.base;
  860. return &dpi_output->base;
  861. }