vlv_dsi.c 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879
  1. /*
  2. * Copyright © 2013 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. * Author: Jani Nikula <jani.nikula@intel.com>
  24. */
  25. #include <drm/drmP.h>
  26. #include <drm/drm_atomic_helper.h>
  27. #include <drm/drm_crtc.h>
  28. #include <drm/drm_edid.h>
  29. #include <drm/i915_drm.h>
  30. #include <drm/drm_mipi_dsi.h>
  31. #include <linux/slab.h>
  32. #include <linux/gpio/consumer.h>
  33. #include "i915_drv.h"
  34. #include "intel_drv.h"
  35. #include "intel_dsi.h"
  36. /* return pixels in terms of txbyteclkhs */
  37. static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count,
  38. u16 burst_mode_ratio)
  39. {
  40. return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio,
  41. 8 * 100), lane_count);
  42. }
  43. /* return pixels equvalent to txbyteclkhs */
  44. static u16 pixels_from_txbyteclkhs(u16 clk_hs, int bpp, int lane_count,
  45. u16 burst_mode_ratio)
  46. {
  47. return DIV_ROUND_UP((clk_hs * lane_count * 8 * 100),
  48. (bpp * burst_mode_ratio));
  49. }
  50. enum mipi_dsi_pixel_format pixel_format_from_register_bits(u32 fmt)
  51. {
  52. /* It just so happens the VBT matches register contents. */
  53. switch (fmt) {
  54. case VID_MODE_FORMAT_RGB888:
  55. return MIPI_DSI_FMT_RGB888;
  56. case VID_MODE_FORMAT_RGB666:
  57. return MIPI_DSI_FMT_RGB666;
  58. case VID_MODE_FORMAT_RGB666_PACKED:
  59. return MIPI_DSI_FMT_RGB666_PACKED;
  60. case VID_MODE_FORMAT_RGB565:
  61. return MIPI_DSI_FMT_RGB565;
  62. default:
  63. MISSING_CASE(fmt);
  64. return MIPI_DSI_FMT_RGB666;
  65. }
  66. }
  67. void vlv_dsi_wait_for_fifo_empty(struct intel_dsi *intel_dsi, enum port port)
  68. {
  69. struct drm_encoder *encoder = &intel_dsi->base.base;
  70. struct drm_device *dev = encoder->dev;
  71. struct drm_i915_private *dev_priv = to_i915(dev);
  72. u32 mask;
  73. mask = LP_CTRL_FIFO_EMPTY | HS_CTRL_FIFO_EMPTY |
  74. LP_DATA_FIFO_EMPTY | HS_DATA_FIFO_EMPTY;
  75. if (intel_wait_for_register(dev_priv,
  76. MIPI_GEN_FIFO_STAT(port), mask, mask,
  77. 100))
  78. DRM_ERROR("DPI FIFOs are not empty\n");
  79. }
  80. static void write_data(struct drm_i915_private *dev_priv,
  81. i915_reg_t reg,
  82. const u8 *data, u32 len)
  83. {
  84. u32 i, j;
  85. for (i = 0; i < len; i += 4) {
  86. u32 val = 0;
  87. for (j = 0; j < min_t(u32, len - i, 4); j++)
  88. val |= *data++ << 8 * j;
  89. I915_WRITE(reg, val);
  90. }
  91. }
  92. static void read_data(struct drm_i915_private *dev_priv,
  93. i915_reg_t reg,
  94. u8 *data, u32 len)
  95. {
  96. u32 i, j;
  97. for (i = 0; i < len; i += 4) {
  98. u32 val = I915_READ(reg);
  99. for (j = 0; j < min_t(u32, len - i, 4); j++)
  100. *data++ = val >> 8 * j;
  101. }
  102. }
  103. static ssize_t intel_dsi_host_transfer(struct mipi_dsi_host *host,
  104. const struct mipi_dsi_msg *msg)
  105. {
  106. struct intel_dsi_host *intel_dsi_host = to_intel_dsi_host(host);
  107. struct drm_device *dev = intel_dsi_host->intel_dsi->base.base.dev;
  108. struct drm_i915_private *dev_priv = to_i915(dev);
  109. enum port port = intel_dsi_host->port;
  110. struct mipi_dsi_packet packet;
  111. ssize_t ret;
  112. const u8 *header, *data;
  113. i915_reg_t data_reg, ctrl_reg;
  114. u32 data_mask, ctrl_mask;
  115. ret = mipi_dsi_create_packet(&packet, msg);
  116. if (ret < 0)
  117. return ret;
  118. header = packet.header;
  119. data = packet.payload;
  120. if (msg->flags & MIPI_DSI_MSG_USE_LPM) {
  121. data_reg = MIPI_LP_GEN_DATA(port);
  122. data_mask = LP_DATA_FIFO_FULL;
  123. ctrl_reg = MIPI_LP_GEN_CTRL(port);
  124. ctrl_mask = LP_CTRL_FIFO_FULL;
  125. } else {
  126. data_reg = MIPI_HS_GEN_DATA(port);
  127. data_mask = HS_DATA_FIFO_FULL;
  128. ctrl_reg = MIPI_HS_GEN_CTRL(port);
  129. ctrl_mask = HS_CTRL_FIFO_FULL;
  130. }
  131. /* note: this is never true for reads */
  132. if (packet.payload_length) {
  133. if (intel_wait_for_register(dev_priv,
  134. MIPI_GEN_FIFO_STAT(port),
  135. data_mask, 0,
  136. 50))
  137. DRM_ERROR("Timeout waiting for HS/LP DATA FIFO !full\n");
  138. write_data(dev_priv, data_reg, packet.payload,
  139. packet.payload_length);
  140. }
  141. if (msg->rx_len) {
  142. I915_WRITE(MIPI_INTR_STAT(port), GEN_READ_DATA_AVAIL);
  143. }
  144. if (intel_wait_for_register(dev_priv,
  145. MIPI_GEN_FIFO_STAT(port),
  146. ctrl_mask, 0,
  147. 50)) {
  148. DRM_ERROR("Timeout waiting for HS/LP CTRL FIFO !full\n");
  149. }
  150. I915_WRITE(ctrl_reg, header[2] << 16 | header[1] << 8 | header[0]);
  151. /* ->rx_len is set only for reads */
  152. if (msg->rx_len) {
  153. data_mask = GEN_READ_DATA_AVAIL;
  154. if (intel_wait_for_register(dev_priv,
  155. MIPI_INTR_STAT(port),
  156. data_mask, data_mask,
  157. 50))
  158. DRM_ERROR("Timeout waiting for read data.\n");
  159. read_data(dev_priv, data_reg, msg->rx_buf, msg->rx_len);
  160. }
  161. /* XXX: fix for reads and writes */
  162. return 4 + packet.payload_length;
  163. }
  164. static int intel_dsi_host_attach(struct mipi_dsi_host *host,
  165. struct mipi_dsi_device *dsi)
  166. {
  167. return 0;
  168. }
  169. static int intel_dsi_host_detach(struct mipi_dsi_host *host,
  170. struct mipi_dsi_device *dsi)
  171. {
  172. return 0;
  173. }
  174. static const struct mipi_dsi_host_ops intel_dsi_host_ops = {
  175. .attach = intel_dsi_host_attach,
  176. .detach = intel_dsi_host_detach,
  177. .transfer = intel_dsi_host_transfer,
  178. };
  179. static struct intel_dsi_host *intel_dsi_host_init(struct intel_dsi *intel_dsi,
  180. enum port port)
  181. {
  182. struct intel_dsi_host *host;
  183. struct mipi_dsi_device *device;
  184. host = kzalloc(sizeof(*host), GFP_KERNEL);
  185. if (!host)
  186. return NULL;
  187. host->base.ops = &intel_dsi_host_ops;
  188. host->intel_dsi = intel_dsi;
  189. host->port = port;
  190. /*
  191. * We should call mipi_dsi_host_register(&host->base) here, but we don't
  192. * have a host->dev, and we don't have OF stuff either. So just use the
  193. * dsi framework as a library and hope for the best. Create the dsi
  194. * devices by ourselves here too. Need to be careful though, because we
  195. * don't initialize any of the driver model devices here.
  196. */
  197. device = kzalloc(sizeof(*device), GFP_KERNEL);
  198. if (!device) {
  199. kfree(host);
  200. return NULL;
  201. }
  202. device->host = &host->base;
  203. host->device = device;
  204. return host;
  205. }
  206. /*
  207. * send a video mode command
  208. *
  209. * XXX: commands with data in MIPI_DPI_DATA?
  210. */
  211. static int dpi_send_cmd(struct intel_dsi *intel_dsi, u32 cmd, bool hs,
  212. enum port port)
  213. {
  214. struct drm_encoder *encoder = &intel_dsi->base.base;
  215. struct drm_device *dev = encoder->dev;
  216. struct drm_i915_private *dev_priv = to_i915(dev);
  217. u32 mask;
  218. /* XXX: pipe, hs */
  219. if (hs)
  220. cmd &= ~DPI_LP_MODE;
  221. else
  222. cmd |= DPI_LP_MODE;
  223. /* clear bit */
  224. I915_WRITE(MIPI_INTR_STAT(port), SPL_PKT_SENT_INTERRUPT);
  225. /* XXX: old code skips write if control unchanged */
  226. if (cmd == I915_READ(MIPI_DPI_CONTROL(port)))
  227. DRM_DEBUG_KMS("Same special packet %02x twice in a row.\n", cmd);
  228. I915_WRITE(MIPI_DPI_CONTROL(port), cmd);
  229. mask = SPL_PKT_SENT_INTERRUPT;
  230. if (intel_wait_for_register(dev_priv,
  231. MIPI_INTR_STAT(port), mask, mask,
  232. 100))
  233. DRM_ERROR("Video mode command 0x%08x send failed.\n", cmd);
  234. return 0;
  235. }
  236. static void band_gap_reset(struct drm_i915_private *dev_priv)
  237. {
  238. mutex_lock(&dev_priv->sb_lock);
  239. vlv_flisdsi_write(dev_priv, 0x08, 0x0001);
  240. vlv_flisdsi_write(dev_priv, 0x0F, 0x0005);
  241. vlv_flisdsi_write(dev_priv, 0x0F, 0x0025);
  242. udelay(150);
  243. vlv_flisdsi_write(dev_priv, 0x0F, 0x0000);
  244. vlv_flisdsi_write(dev_priv, 0x08, 0x0000);
  245. mutex_unlock(&dev_priv->sb_lock);
  246. }
  247. static inline bool is_vid_mode(struct intel_dsi *intel_dsi)
  248. {
  249. return intel_dsi->operation_mode == INTEL_DSI_VIDEO_MODE;
  250. }
  251. static inline bool is_cmd_mode(struct intel_dsi *intel_dsi)
  252. {
  253. return intel_dsi->operation_mode == INTEL_DSI_COMMAND_MODE;
  254. }
  255. static bool intel_dsi_compute_config(struct intel_encoder *encoder,
  256. struct intel_crtc_state *pipe_config,
  257. struct drm_connector_state *conn_state)
  258. {
  259. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  260. struct intel_dsi *intel_dsi = container_of(encoder, struct intel_dsi,
  261. base);
  262. struct intel_connector *intel_connector = intel_dsi->attached_connector;
  263. struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
  264. const struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
  265. struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
  266. int ret;
  267. DRM_DEBUG_KMS("\n");
  268. if (fixed_mode) {
  269. intel_fixed_panel_mode(fixed_mode, adjusted_mode);
  270. if (HAS_GMCH_DISPLAY(dev_priv))
  271. intel_gmch_panel_fitting(crtc, pipe_config,
  272. conn_state->scaling_mode);
  273. else
  274. intel_pch_panel_fitting(crtc, pipe_config,
  275. conn_state->scaling_mode);
  276. }
  277. if (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN)
  278. return false;
  279. /* DSI uses short packets for sync events, so clear mode flags for DSI */
  280. adjusted_mode->flags = 0;
  281. if (IS_GEN9_LP(dev_priv)) {
  282. /* Enable Frame time stamp based scanline reporting */
  283. adjusted_mode->private_flags |=
  284. I915_MODE_FLAG_GET_SCANLINE_FROM_TIMESTAMP;
  285. /* Dual link goes to DSI transcoder A. */
  286. if (intel_dsi->ports == BIT(PORT_C))
  287. pipe_config->cpu_transcoder = TRANSCODER_DSI_C;
  288. else
  289. pipe_config->cpu_transcoder = TRANSCODER_DSI_A;
  290. ret = bxt_dsi_pll_compute(encoder, pipe_config);
  291. if (ret)
  292. return false;
  293. } else {
  294. ret = vlv_dsi_pll_compute(encoder, pipe_config);
  295. if (ret)
  296. return false;
  297. }
  298. pipe_config->clock_set = true;
  299. return true;
  300. }
  301. static bool glk_dsi_enable_io(struct intel_encoder *encoder)
  302. {
  303. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  304. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  305. enum port port;
  306. u32 tmp;
  307. bool cold_boot = false;
  308. /* Set the MIPI mode
  309. * If MIPI_Mode is off, then writing to LP_Wake bit is not reflecting.
  310. * Power ON MIPI IO first and then write into IO reset and LP wake bits
  311. */
  312. for_each_dsi_port(port, intel_dsi->ports) {
  313. tmp = I915_READ(MIPI_CTRL(port));
  314. I915_WRITE(MIPI_CTRL(port), tmp | GLK_MIPIIO_ENABLE);
  315. }
  316. /* Put the IO into reset */
  317. tmp = I915_READ(MIPI_CTRL(PORT_A));
  318. tmp &= ~GLK_MIPIIO_RESET_RELEASED;
  319. I915_WRITE(MIPI_CTRL(PORT_A), tmp);
  320. /* Program LP Wake */
  321. for_each_dsi_port(port, intel_dsi->ports) {
  322. tmp = I915_READ(MIPI_CTRL(port));
  323. if (!(I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY))
  324. tmp &= ~GLK_LP_WAKE;
  325. else
  326. tmp |= GLK_LP_WAKE;
  327. I915_WRITE(MIPI_CTRL(port), tmp);
  328. }
  329. /* Wait for Pwr ACK */
  330. for_each_dsi_port(port, intel_dsi->ports) {
  331. if (intel_wait_for_register(dev_priv,
  332. MIPI_CTRL(port), GLK_MIPIIO_PORT_POWERED,
  333. GLK_MIPIIO_PORT_POWERED, 20))
  334. DRM_ERROR("MIPIO port is powergated\n");
  335. }
  336. /* Check for cold boot scenario */
  337. for_each_dsi_port(port, intel_dsi->ports) {
  338. cold_boot |= !(I915_READ(MIPI_DEVICE_READY(port)) &
  339. DEVICE_READY);
  340. }
  341. return cold_boot;
  342. }
  343. static void glk_dsi_device_ready(struct intel_encoder *encoder)
  344. {
  345. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  346. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  347. enum port port;
  348. u32 val;
  349. /* Wait for MIPI PHY status bit to set */
  350. for_each_dsi_port(port, intel_dsi->ports) {
  351. if (intel_wait_for_register(dev_priv,
  352. MIPI_CTRL(port), GLK_PHY_STATUS_PORT_READY,
  353. GLK_PHY_STATUS_PORT_READY, 20))
  354. DRM_ERROR("PHY is not ON\n");
  355. }
  356. /* Get IO out of reset */
  357. val = I915_READ(MIPI_CTRL(PORT_A));
  358. I915_WRITE(MIPI_CTRL(PORT_A), val | GLK_MIPIIO_RESET_RELEASED);
  359. /* Get IO out of Low power state*/
  360. for_each_dsi_port(port, intel_dsi->ports) {
  361. if (!(I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY)) {
  362. val = I915_READ(MIPI_DEVICE_READY(port));
  363. val &= ~ULPS_STATE_MASK;
  364. val |= DEVICE_READY;
  365. I915_WRITE(MIPI_DEVICE_READY(port), val);
  366. usleep_range(10, 15);
  367. } else {
  368. /* Enter ULPS */
  369. val = I915_READ(MIPI_DEVICE_READY(port));
  370. val &= ~ULPS_STATE_MASK;
  371. val |= (ULPS_STATE_ENTER | DEVICE_READY);
  372. I915_WRITE(MIPI_DEVICE_READY(port), val);
  373. /* Wait for ULPS active */
  374. if (intel_wait_for_register(dev_priv,
  375. MIPI_CTRL(port), GLK_ULPS_NOT_ACTIVE, 0, 20))
  376. DRM_ERROR("ULPS not active\n");
  377. /* Exit ULPS */
  378. val = I915_READ(MIPI_DEVICE_READY(port));
  379. val &= ~ULPS_STATE_MASK;
  380. val |= (ULPS_STATE_EXIT | DEVICE_READY);
  381. I915_WRITE(MIPI_DEVICE_READY(port), val);
  382. /* Enter Normal Mode */
  383. val = I915_READ(MIPI_DEVICE_READY(port));
  384. val &= ~ULPS_STATE_MASK;
  385. val |= (ULPS_STATE_NORMAL_OPERATION | DEVICE_READY);
  386. I915_WRITE(MIPI_DEVICE_READY(port), val);
  387. val = I915_READ(MIPI_CTRL(port));
  388. val &= ~GLK_LP_WAKE;
  389. I915_WRITE(MIPI_CTRL(port), val);
  390. }
  391. }
  392. /* Wait for Stop state */
  393. for_each_dsi_port(port, intel_dsi->ports) {
  394. if (intel_wait_for_register(dev_priv,
  395. MIPI_CTRL(port), GLK_DATA_LANE_STOP_STATE,
  396. GLK_DATA_LANE_STOP_STATE, 20))
  397. DRM_ERROR("Date lane not in STOP state\n");
  398. }
  399. /* Wait for AFE LATCH */
  400. for_each_dsi_port(port, intel_dsi->ports) {
  401. if (intel_wait_for_register(dev_priv,
  402. BXT_MIPI_PORT_CTRL(port), AFE_LATCHOUT,
  403. AFE_LATCHOUT, 20))
  404. DRM_ERROR("D-PHY not entering LP-11 state\n");
  405. }
  406. }
  407. static void bxt_dsi_device_ready(struct intel_encoder *encoder)
  408. {
  409. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  410. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  411. enum port port;
  412. u32 val;
  413. DRM_DEBUG_KMS("\n");
  414. /* Enable MIPI PHY transparent latch */
  415. for_each_dsi_port(port, intel_dsi->ports) {
  416. val = I915_READ(BXT_MIPI_PORT_CTRL(port));
  417. I915_WRITE(BXT_MIPI_PORT_CTRL(port), val | LP_OUTPUT_HOLD);
  418. usleep_range(2000, 2500);
  419. }
  420. /* Clear ULPS and set device ready */
  421. for_each_dsi_port(port, intel_dsi->ports) {
  422. val = I915_READ(MIPI_DEVICE_READY(port));
  423. val &= ~ULPS_STATE_MASK;
  424. I915_WRITE(MIPI_DEVICE_READY(port), val);
  425. usleep_range(2000, 2500);
  426. val |= DEVICE_READY;
  427. I915_WRITE(MIPI_DEVICE_READY(port), val);
  428. }
  429. }
  430. static void vlv_dsi_device_ready(struct intel_encoder *encoder)
  431. {
  432. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  433. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  434. enum port port;
  435. u32 val;
  436. DRM_DEBUG_KMS("\n");
  437. mutex_lock(&dev_priv->sb_lock);
  438. /* program rcomp for compliance, reduce from 50 ohms to 45 ohms
  439. * needed everytime after power gate */
  440. vlv_flisdsi_write(dev_priv, 0x04, 0x0004);
  441. mutex_unlock(&dev_priv->sb_lock);
  442. /* bandgap reset is needed after everytime we do power gate */
  443. band_gap_reset(dev_priv);
  444. for_each_dsi_port(port, intel_dsi->ports) {
  445. I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_ENTER);
  446. usleep_range(2500, 3000);
  447. /* Enable MIPI PHY transparent latch
  448. * Common bit for both MIPI Port A & MIPI Port C
  449. * No similar bit in MIPI Port C reg
  450. */
  451. val = I915_READ(MIPI_PORT_CTRL(PORT_A));
  452. I915_WRITE(MIPI_PORT_CTRL(PORT_A), val | LP_OUTPUT_HOLD);
  453. usleep_range(1000, 1500);
  454. I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_EXIT);
  455. usleep_range(2500, 3000);
  456. I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY);
  457. usleep_range(2500, 3000);
  458. }
  459. }
  460. static void intel_dsi_device_ready(struct intel_encoder *encoder)
  461. {
  462. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  463. if (IS_GEMINILAKE(dev_priv))
  464. glk_dsi_device_ready(encoder);
  465. else if (IS_GEN9_LP(dev_priv))
  466. bxt_dsi_device_ready(encoder);
  467. else
  468. vlv_dsi_device_ready(encoder);
  469. }
  470. static void glk_dsi_enter_low_power_mode(struct intel_encoder *encoder)
  471. {
  472. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  473. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  474. enum port port;
  475. u32 val;
  476. /* Enter ULPS */
  477. for_each_dsi_port(port, intel_dsi->ports) {
  478. val = I915_READ(MIPI_DEVICE_READY(port));
  479. val &= ~ULPS_STATE_MASK;
  480. val |= (ULPS_STATE_ENTER | DEVICE_READY);
  481. I915_WRITE(MIPI_DEVICE_READY(port), val);
  482. }
  483. /* Wait for MIPI PHY status bit to unset */
  484. for_each_dsi_port(port, intel_dsi->ports) {
  485. if (intel_wait_for_register(dev_priv,
  486. MIPI_CTRL(port),
  487. GLK_PHY_STATUS_PORT_READY, 0, 20))
  488. DRM_ERROR("PHY is not turning OFF\n");
  489. }
  490. /* Wait for Pwr ACK bit to unset */
  491. for_each_dsi_port(port, intel_dsi->ports) {
  492. if (intel_wait_for_register(dev_priv,
  493. MIPI_CTRL(port),
  494. GLK_MIPIIO_PORT_POWERED, 0, 20))
  495. DRM_ERROR("MIPI IO Port is not powergated\n");
  496. }
  497. }
  498. static void glk_dsi_disable_mipi_io(struct intel_encoder *encoder)
  499. {
  500. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  501. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  502. enum port port;
  503. u32 tmp;
  504. /* Put the IO into reset */
  505. tmp = I915_READ(MIPI_CTRL(PORT_A));
  506. tmp &= ~GLK_MIPIIO_RESET_RELEASED;
  507. I915_WRITE(MIPI_CTRL(PORT_A), tmp);
  508. /* Wait for MIPI PHY status bit to unset */
  509. for_each_dsi_port(port, intel_dsi->ports) {
  510. if (intel_wait_for_register(dev_priv,
  511. MIPI_CTRL(port),
  512. GLK_PHY_STATUS_PORT_READY, 0, 20))
  513. DRM_ERROR("PHY is not turning OFF\n");
  514. }
  515. /* Clear MIPI mode */
  516. for_each_dsi_port(port, intel_dsi->ports) {
  517. tmp = I915_READ(MIPI_CTRL(port));
  518. tmp &= ~GLK_MIPIIO_ENABLE;
  519. I915_WRITE(MIPI_CTRL(port), tmp);
  520. }
  521. }
  522. static void glk_dsi_clear_device_ready(struct intel_encoder *encoder)
  523. {
  524. glk_dsi_enter_low_power_mode(encoder);
  525. glk_dsi_disable_mipi_io(encoder);
  526. }
  527. static void vlv_dsi_clear_device_ready(struct intel_encoder *encoder)
  528. {
  529. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  530. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  531. enum port port;
  532. DRM_DEBUG_KMS("\n");
  533. for_each_dsi_port(port, intel_dsi->ports) {
  534. /* Common bit for both MIPI Port A & MIPI Port C on VLV/CHV */
  535. i915_reg_t port_ctrl = IS_GEN9_LP(dev_priv) ?
  536. BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(PORT_A);
  537. u32 val;
  538. I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
  539. ULPS_STATE_ENTER);
  540. usleep_range(2000, 2500);
  541. I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
  542. ULPS_STATE_EXIT);
  543. usleep_range(2000, 2500);
  544. I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
  545. ULPS_STATE_ENTER);
  546. usleep_range(2000, 2500);
  547. /*
  548. * On VLV/CHV, wait till Clock lanes are in LP-00 state for MIPI
  549. * Port A only. MIPI Port C has no similar bit for checking.
  550. */
  551. if ((IS_GEN9_LP(dev_priv) || port == PORT_A) &&
  552. intel_wait_for_register(dev_priv,
  553. port_ctrl, AFE_LATCHOUT, 0,
  554. 30))
  555. DRM_ERROR("DSI LP not going Low\n");
  556. /* Disable MIPI PHY transparent latch */
  557. val = I915_READ(port_ctrl);
  558. I915_WRITE(port_ctrl, val & ~LP_OUTPUT_HOLD);
  559. usleep_range(1000, 1500);
  560. I915_WRITE(MIPI_DEVICE_READY(port), 0x00);
  561. usleep_range(2000, 2500);
  562. }
  563. }
  564. static void intel_dsi_port_enable(struct intel_encoder *encoder,
  565. const struct intel_crtc_state *crtc_state)
  566. {
  567. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  568. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  569. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  570. enum port port;
  571. if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) {
  572. u32 temp;
  573. if (IS_GEN9_LP(dev_priv)) {
  574. for_each_dsi_port(port, intel_dsi->ports) {
  575. temp = I915_READ(MIPI_CTRL(port));
  576. temp &= ~BXT_PIXEL_OVERLAP_CNT_MASK |
  577. intel_dsi->pixel_overlap <<
  578. BXT_PIXEL_OVERLAP_CNT_SHIFT;
  579. I915_WRITE(MIPI_CTRL(port), temp);
  580. }
  581. } else {
  582. temp = I915_READ(VLV_CHICKEN_3);
  583. temp &= ~PIXEL_OVERLAP_CNT_MASK |
  584. intel_dsi->pixel_overlap <<
  585. PIXEL_OVERLAP_CNT_SHIFT;
  586. I915_WRITE(VLV_CHICKEN_3, temp);
  587. }
  588. }
  589. for_each_dsi_port(port, intel_dsi->ports) {
  590. i915_reg_t port_ctrl = IS_GEN9_LP(dev_priv) ?
  591. BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
  592. u32 temp;
  593. temp = I915_READ(port_ctrl);
  594. temp &= ~LANE_CONFIGURATION_MASK;
  595. temp &= ~DUAL_LINK_MODE_MASK;
  596. if (intel_dsi->ports == (BIT(PORT_A) | BIT(PORT_C))) {
  597. temp |= (intel_dsi->dual_link - 1)
  598. << DUAL_LINK_MODE_SHIFT;
  599. if (IS_BROXTON(dev_priv))
  600. temp |= LANE_CONFIGURATION_DUAL_LINK_A;
  601. else
  602. temp |= crtc->pipe ?
  603. LANE_CONFIGURATION_DUAL_LINK_B :
  604. LANE_CONFIGURATION_DUAL_LINK_A;
  605. }
  606. /* assert ip_tg_enable signal */
  607. I915_WRITE(port_ctrl, temp | DPI_ENABLE);
  608. POSTING_READ(port_ctrl);
  609. }
  610. }
  611. static void intel_dsi_port_disable(struct intel_encoder *encoder)
  612. {
  613. struct drm_device *dev = encoder->base.dev;
  614. struct drm_i915_private *dev_priv = to_i915(dev);
  615. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  616. enum port port;
  617. for_each_dsi_port(port, intel_dsi->ports) {
  618. i915_reg_t port_ctrl = IS_GEN9_LP(dev_priv) ?
  619. BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
  620. u32 temp;
  621. /* de-assert ip_tg_enable signal */
  622. temp = I915_READ(port_ctrl);
  623. I915_WRITE(port_ctrl, temp & ~DPI_ENABLE);
  624. POSTING_READ(port_ctrl);
  625. }
  626. }
  627. static void intel_dsi_prepare(struct intel_encoder *intel_encoder,
  628. const struct intel_crtc_state *pipe_config);
  629. static void intel_dsi_unprepare(struct intel_encoder *encoder);
  630. static void intel_dsi_msleep(struct intel_dsi *intel_dsi, int msec)
  631. {
  632. struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev);
  633. /* For v3 VBTs in vid-mode the delays are part of the VBT sequences */
  634. if (is_vid_mode(intel_dsi) && dev_priv->vbt.dsi.seq_version >= 3)
  635. return;
  636. msleep(msec);
  637. }
  638. /*
  639. * Panel enable/disable sequences from the VBT spec.
  640. *
  641. * Note the spec has AssertReset / DeassertReset swapped from their
  642. * usual naming. We use the normal names to avoid confusion (so below
  643. * they are swapped compared to the spec).
  644. *
  645. * Steps starting with MIPI refer to VBT sequences, note that for v2
  646. * VBTs several steps which have a VBT in v2 are expected to be handled
  647. * directly by the driver, by directly driving gpios for example.
  648. *
  649. * v2 video mode seq v3 video mode seq command mode seq
  650. * - power on - MIPIPanelPowerOn - power on
  651. * - wait t1+t2 - wait t1+t2
  652. * - MIPIDeassertResetPin - MIPIDeassertResetPin - MIPIDeassertResetPin
  653. * - io lines to lp-11 - io lines to lp-11 - io lines to lp-11
  654. * - MIPISendInitialDcsCmds - MIPISendInitialDcsCmds - MIPISendInitialDcsCmds
  655. * - MIPITearOn
  656. * - MIPIDisplayOn
  657. * - turn on DPI - turn on DPI - set pipe to dsr mode
  658. * - MIPIDisplayOn - MIPIDisplayOn
  659. * - wait t5 - wait t5
  660. * - backlight on - MIPIBacklightOn - backlight on
  661. * ... ... ... issue mem cmds ...
  662. * - backlight off - MIPIBacklightOff - backlight off
  663. * - wait t6 - wait t6
  664. * - MIPIDisplayOff
  665. * - turn off DPI - turn off DPI - disable pipe dsr mode
  666. * - MIPITearOff
  667. * - MIPIDisplayOff - MIPIDisplayOff
  668. * - io lines to lp-00 - io lines to lp-00 - io lines to lp-00
  669. * - MIPIAssertResetPin - MIPIAssertResetPin - MIPIAssertResetPin
  670. * - wait t3 - wait t3
  671. * - power off - MIPIPanelPowerOff - power off
  672. * - wait t4 - wait t4
  673. */
  674. static void intel_dsi_pre_enable(struct intel_encoder *encoder,
  675. const struct intel_crtc_state *pipe_config,
  676. const struct drm_connector_state *conn_state)
  677. {
  678. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  679. struct drm_crtc *crtc = pipe_config->base.crtc;
  680. struct drm_i915_private *dev_priv = to_i915(crtc->dev);
  681. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  682. int pipe = intel_crtc->pipe;
  683. enum port port;
  684. u32 val;
  685. bool glk_cold_boot = false;
  686. DRM_DEBUG_KMS("\n");
  687. intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
  688. /*
  689. * The BIOS may leave the PLL in a wonky state where it doesn't
  690. * lock. It needs to be fully powered down to fix it.
  691. */
  692. if (IS_GEN9_LP(dev_priv)) {
  693. bxt_dsi_pll_disable(encoder);
  694. bxt_dsi_pll_enable(encoder, pipe_config);
  695. } else {
  696. vlv_dsi_pll_disable(encoder);
  697. vlv_dsi_pll_enable(encoder, pipe_config);
  698. }
  699. if (IS_BROXTON(dev_priv)) {
  700. /* Add MIPI IO reset programming for modeset */
  701. val = I915_READ(BXT_P_CR_GT_DISP_PWRON);
  702. I915_WRITE(BXT_P_CR_GT_DISP_PWRON,
  703. val | MIPIO_RST_CTRL);
  704. /* Power up DSI regulator */
  705. I915_WRITE(BXT_P_DSI_REGULATOR_CFG, STAP_SELECT);
  706. I915_WRITE(BXT_P_DSI_REGULATOR_TX_CTRL, 0);
  707. }
  708. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  709. u32 val;
  710. /* Disable DPOunit clock gating, can stall pipe */
  711. val = I915_READ(DSPCLK_GATE_D);
  712. val |= DPOUNIT_CLOCK_GATE_DISABLE;
  713. I915_WRITE(DSPCLK_GATE_D, val);
  714. }
  715. if (!IS_GEMINILAKE(dev_priv))
  716. intel_dsi_prepare(encoder, pipe_config);
  717. /* Power on, try both CRC pmic gpio and VBT */
  718. if (intel_dsi->gpio_panel)
  719. gpiod_set_value_cansleep(intel_dsi->gpio_panel, 1);
  720. intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_POWER_ON);
  721. intel_dsi_msleep(intel_dsi, intel_dsi->panel_on_delay);
  722. /* Deassert reset */
  723. intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DEASSERT_RESET);
  724. if (IS_GEMINILAKE(dev_priv)) {
  725. glk_cold_boot = glk_dsi_enable_io(encoder);
  726. /* Prepare port in cold boot(s3/s4) scenario */
  727. if (glk_cold_boot)
  728. intel_dsi_prepare(encoder, pipe_config);
  729. }
  730. /* Put device in ready state (LP-11) */
  731. intel_dsi_device_ready(encoder);
  732. /* Prepare port in normal boot scenario */
  733. if (IS_GEMINILAKE(dev_priv) && !glk_cold_boot)
  734. intel_dsi_prepare(encoder, pipe_config);
  735. /* Send initialization commands in LP mode */
  736. intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_INIT_OTP);
  737. /* Enable port in pre-enable phase itself because as per hw team
  738. * recommendation, port should be enabled befor plane & pipe */
  739. if (is_cmd_mode(intel_dsi)) {
  740. for_each_dsi_port(port, intel_dsi->ports)
  741. I915_WRITE(MIPI_MAX_RETURN_PKT_SIZE(port), 8 * 4);
  742. intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_TEAR_ON);
  743. intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_ON);
  744. } else {
  745. msleep(20); /* XXX */
  746. for_each_dsi_port(port, intel_dsi->ports)
  747. dpi_send_cmd(intel_dsi, TURN_ON, false, port);
  748. intel_dsi_msleep(intel_dsi, 100);
  749. intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_ON);
  750. intel_dsi_port_enable(encoder, pipe_config);
  751. }
  752. intel_panel_enable_backlight(pipe_config, conn_state);
  753. intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_BACKLIGHT_ON);
  754. }
  755. /*
  756. * DSI port enable has to be done before pipe and plane enable, so we do it in
  757. * the pre_enable hook.
  758. */
  759. static void intel_dsi_enable_nop(struct intel_encoder *encoder,
  760. const struct intel_crtc_state *pipe_config,
  761. const struct drm_connector_state *conn_state)
  762. {
  763. DRM_DEBUG_KMS("\n");
  764. }
  765. /*
  766. * DSI port disable has to be done after pipe and plane disable, so we do it in
  767. * the post_disable hook.
  768. */
  769. static void intel_dsi_disable(struct intel_encoder *encoder,
  770. const struct intel_crtc_state *old_crtc_state,
  771. const struct drm_connector_state *old_conn_state)
  772. {
  773. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  774. enum port port;
  775. DRM_DEBUG_KMS("\n");
  776. intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_BACKLIGHT_OFF);
  777. intel_panel_disable_backlight(old_conn_state);
  778. /*
  779. * According to the spec we should send SHUTDOWN before
  780. * MIPI_SEQ_DISPLAY_OFF only for v3+ VBTs, but field testing
  781. * has shown that the v3 sequence works for v2 VBTs too
  782. */
  783. if (is_vid_mode(intel_dsi)) {
  784. /* Send Shutdown command to the panel in LP mode */
  785. for_each_dsi_port(port, intel_dsi->ports)
  786. dpi_send_cmd(intel_dsi, SHUTDOWN, false, port);
  787. msleep(10);
  788. }
  789. }
  790. static void intel_dsi_clear_device_ready(struct intel_encoder *encoder)
  791. {
  792. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  793. if (IS_GEMINILAKE(dev_priv))
  794. glk_dsi_clear_device_ready(encoder);
  795. else
  796. vlv_dsi_clear_device_ready(encoder);
  797. }
  798. static void intel_dsi_post_disable(struct intel_encoder *encoder,
  799. const struct intel_crtc_state *pipe_config,
  800. const struct drm_connector_state *conn_state)
  801. {
  802. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  803. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  804. enum port port;
  805. u32 val;
  806. DRM_DEBUG_KMS("\n");
  807. if (is_vid_mode(intel_dsi)) {
  808. for_each_dsi_port(port, intel_dsi->ports)
  809. vlv_dsi_wait_for_fifo_empty(intel_dsi, port);
  810. intel_dsi_port_disable(encoder);
  811. usleep_range(2000, 5000);
  812. }
  813. intel_dsi_unprepare(encoder);
  814. /*
  815. * if disable packets are sent before sending shutdown packet then in
  816. * some next enable sequence send turn on packet error is observed
  817. */
  818. if (is_cmd_mode(intel_dsi))
  819. intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_TEAR_OFF);
  820. intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_OFF);
  821. /* Transition to LP-00 */
  822. intel_dsi_clear_device_ready(encoder);
  823. if (IS_BROXTON(dev_priv)) {
  824. /* Power down DSI regulator to save power */
  825. I915_WRITE(BXT_P_DSI_REGULATOR_CFG, STAP_SELECT);
  826. I915_WRITE(BXT_P_DSI_REGULATOR_TX_CTRL, HS_IO_CTRL_SELECT);
  827. /* Add MIPI IO reset programming for modeset */
  828. val = I915_READ(BXT_P_CR_GT_DISP_PWRON);
  829. I915_WRITE(BXT_P_CR_GT_DISP_PWRON,
  830. val & ~MIPIO_RST_CTRL);
  831. }
  832. if (IS_GEN9_LP(dev_priv)) {
  833. bxt_dsi_pll_disable(encoder);
  834. } else {
  835. u32 val;
  836. vlv_dsi_pll_disable(encoder);
  837. val = I915_READ(DSPCLK_GATE_D);
  838. val &= ~DPOUNIT_CLOCK_GATE_DISABLE;
  839. I915_WRITE(DSPCLK_GATE_D, val);
  840. }
  841. /* Assert reset */
  842. intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_ASSERT_RESET);
  843. /* Power off, try both CRC pmic gpio and VBT */
  844. intel_dsi_msleep(intel_dsi, intel_dsi->panel_off_delay);
  845. intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_POWER_OFF);
  846. if (intel_dsi->gpio_panel)
  847. gpiod_set_value_cansleep(intel_dsi->gpio_panel, 0);
  848. /*
  849. * FIXME As we do with eDP, just make a note of the time here
  850. * and perform the wait before the next panel power on.
  851. */
  852. intel_dsi_msleep(intel_dsi, intel_dsi->panel_pwr_cycle_delay);
  853. }
  854. static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
  855. enum pipe *pipe)
  856. {
  857. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  858. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  859. enum port port;
  860. bool active = false;
  861. DRM_DEBUG_KMS("\n");
  862. if (!intel_display_power_get_if_enabled(dev_priv,
  863. encoder->power_domain))
  864. return false;
  865. /*
  866. * On Broxton the PLL needs to be enabled with a valid divider
  867. * configuration, otherwise accessing DSI registers will hang the
  868. * machine. See BSpec North Display Engine registers/MIPI[BXT].
  869. */
  870. if (IS_GEN9_LP(dev_priv) && !bxt_dsi_pll_is_enabled(dev_priv))
  871. goto out_put_power;
  872. /* XXX: this only works for one DSI output */
  873. for_each_dsi_port(port, intel_dsi->ports) {
  874. i915_reg_t ctrl_reg = IS_GEN9_LP(dev_priv) ?
  875. BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
  876. bool enabled = I915_READ(ctrl_reg) & DPI_ENABLE;
  877. /*
  878. * Due to some hardware limitations on VLV/CHV, the DPI enable
  879. * bit in port C control register does not get set. As a
  880. * workaround, check pipe B conf instead.
  881. */
  882. if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
  883. port == PORT_C)
  884. enabled = I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE;
  885. /* Try command mode if video mode not enabled */
  886. if (!enabled) {
  887. u32 tmp = I915_READ(MIPI_DSI_FUNC_PRG(port));
  888. enabled = tmp & CMD_MODE_DATA_WIDTH_MASK;
  889. }
  890. if (!enabled)
  891. continue;
  892. if (!(I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY))
  893. continue;
  894. if (IS_GEN9_LP(dev_priv)) {
  895. u32 tmp = I915_READ(MIPI_CTRL(port));
  896. tmp &= BXT_PIPE_SELECT_MASK;
  897. tmp >>= BXT_PIPE_SELECT_SHIFT;
  898. if (WARN_ON(tmp > PIPE_C))
  899. continue;
  900. *pipe = tmp;
  901. } else {
  902. *pipe = port == PORT_A ? PIPE_A : PIPE_B;
  903. }
  904. active = true;
  905. break;
  906. }
  907. out_put_power:
  908. intel_display_power_put(dev_priv, encoder->power_domain);
  909. return active;
  910. }
  911. static void bxt_dsi_get_pipe_config(struct intel_encoder *encoder,
  912. struct intel_crtc_state *pipe_config)
  913. {
  914. struct drm_device *dev = encoder->base.dev;
  915. struct drm_i915_private *dev_priv = to_i915(dev);
  916. struct drm_display_mode *adjusted_mode =
  917. &pipe_config->base.adjusted_mode;
  918. struct drm_display_mode *adjusted_mode_sw;
  919. struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
  920. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  921. unsigned int lane_count = intel_dsi->lane_count;
  922. unsigned int bpp, fmt;
  923. enum port port;
  924. u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
  925. u16 hfp_sw, hsync_sw, hbp_sw;
  926. u16 crtc_htotal_sw, crtc_hsync_start_sw, crtc_hsync_end_sw,
  927. crtc_hblank_start_sw, crtc_hblank_end_sw;
  928. /* FIXME: hw readout should not depend on SW state */
  929. adjusted_mode_sw = &crtc->config->base.adjusted_mode;
  930. /*
  931. * Atleast one port is active as encoder->get_config called only if
  932. * encoder->get_hw_state() returns true.
  933. */
  934. for_each_dsi_port(port, intel_dsi->ports) {
  935. if (I915_READ(BXT_MIPI_PORT_CTRL(port)) & DPI_ENABLE)
  936. break;
  937. }
  938. fmt = I915_READ(MIPI_DSI_FUNC_PRG(port)) & VID_MODE_FORMAT_MASK;
  939. pipe_config->pipe_bpp =
  940. mipi_dsi_pixel_format_to_bpp(
  941. pixel_format_from_register_bits(fmt));
  942. bpp = pipe_config->pipe_bpp;
  943. /* Enable Frame time stamo based scanline reporting */
  944. adjusted_mode->private_flags |=
  945. I915_MODE_FLAG_GET_SCANLINE_FROM_TIMESTAMP;
  946. /* In terms of pixels */
  947. adjusted_mode->crtc_hdisplay =
  948. I915_READ(BXT_MIPI_TRANS_HACTIVE(port));
  949. adjusted_mode->crtc_vdisplay =
  950. I915_READ(BXT_MIPI_TRANS_VACTIVE(port));
  951. adjusted_mode->crtc_vtotal =
  952. I915_READ(BXT_MIPI_TRANS_VTOTAL(port));
  953. hactive = adjusted_mode->crtc_hdisplay;
  954. hfp = I915_READ(MIPI_HFP_COUNT(port));
  955. /*
  956. * Meaningful for video mode non-burst sync pulse mode only,
  957. * can be zero for non-burst sync events and burst modes
  958. */
  959. hsync = I915_READ(MIPI_HSYNC_PADDING_COUNT(port));
  960. hbp = I915_READ(MIPI_HBP_COUNT(port));
  961. /* harizontal values are in terms of high speed byte clock */
  962. hfp = pixels_from_txbyteclkhs(hfp, bpp, lane_count,
  963. intel_dsi->burst_mode_ratio);
  964. hsync = pixels_from_txbyteclkhs(hsync, bpp, lane_count,
  965. intel_dsi->burst_mode_ratio);
  966. hbp = pixels_from_txbyteclkhs(hbp, bpp, lane_count,
  967. intel_dsi->burst_mode_ratio);
  968. if (intel_dsi->dual_link) {
  969. hfp *= 2;
  970. hsync *= 2;
  971. hbp *= 2;
  972. }
  973. /* vertical values are in terms of lines */
  974. vfp = I915_READ(MIPI_VFP_COUNT(port));
  975. vsync = I915_READ(MIPI_VSYNC_PADDING_COUNT(port));
  976. vbp = I915_READ(MIPI_VBP_COUNT(port));
  977. adjusted_mode->crtc_htotal = hactive + hfp + hsync + hbp;
  978. adjusted_mode->crtc_hsync_start = hfp + adjusted_mode->crtc_hdisplay;
  979. adjusted_mode->crtc_hsync_end = hsync + adjusted_mode->crtc_hsync_start;
  980. adjusted_mode->crtc_hblank_start = adjusted_mode->crtc_hdisplay;
  981. adjusted_mode->crtc_hblank_end = adjusted_mode->crtc_htotal;
  982. adjusted_mode->crtc_vsync_start = vfp + adjusted_mode->crtc_vdisplay;
  983. adjusted_mode->crtc_vsync_end = vsync + adjusted_mode->crtc_vsync_start;
  984. adjusted_mode->crtc_vblank_start = adjusted_mode->crtc_vdisplay;
  985. adjusted_mode->crtc_vblank_end = adjusted_mode->crtc_vtotal;
  986. /*
  987. * In BXT DSI there is no regs programmed with few horizontal timings
  988. * in Pixels but txbyteclkhs.. So retrieval process adds some
  989. * ROUND_UP ERRORS in the process of PIXELS<==>txbyteclkhs.
  990. * Actually here for the given adjusted_mode, we are calculating the
  991. * value programmed to the port and then back to the horizontal timing
  992. * param in pixels. This is the expected value, including roundup errors
  993. * And if that is same as retrieved value from port, then
  994. * (HW state) adjusted_mode's horizontal timings are corrected to
  995. * match with SW state to nullify the errors.
  996. */
  997. /* Calculating the value programmed to the Port register */
  998. hfp_sw = adjusted_mode_sw->crtc_hsync_start -
  999. adjusted_mode_sw->crtc_hdisplay;
  1000. hsync_sw = adjusted_mode_sw->crtc_hsync_end -
  1001. adjusted_mode_sw->crtc_hsync_start;
  1002. hbp_sw = adjusted_mode_sw->crtc_htotal -
  1003. adjusted_mode_sw->crtc_hsync_end;
  1004. if (intel_dsi->dual_link) {
  1005. hfp_sw /= 2;
  1006. hsync_sw /= 2;
  1007. hbp_sw /= 2;
  1008. }
  1009. hfp_sw = txbyteclkhs(hfp_sw, bpp, lane_count,
  1010. intel_dsi->burst_mode_ratio);
  1011. hsync_sw = txbyteclkhs(hsync_sw, bpp, lane_count,
  1012. intel_dsi->burst_mode_ratio);
  1013. hbp_sw = txbyteclkhs(hbp_sw, bpp, lane_count,
  1014. intel_dsi->burst_mode_ratio);
  1015. /* Reverse calculating the adjusted mode parameters from port reg vals*/
  1016. hfp_sw = pixels_from_txbyteclkhs(hfp_sw, bpp, lane_count,
  1017. intel_dsi->burst_mode_ratio);
  1018. hsync_sw = pixels_from_txbyteclkhs(hsync_sw, bpp, lane_count,
  1019. intel_dsi->burst_mode_ratio);
  1020. hbp_sw = pixels_from_txbyteclkhs(hbp_sw, bpp, lane_count,
  1021. intel_dsi->burst_mode_ratio);
  1022. if (intel_dsi->dual_link) {
  1023. hfp_sw *= 2;
  1024. hsync_sw *= 2;
  1025. hbp_sw *= 2;
  1026. }
  1027. crtc_htotal_sw = adjusted_mode_sw->crtc_hdisplay + hfp_sw +
  1028. hsync_sw + hbp_sw;
  1029. crtc_hsync_start_sw = hfp_sw + adjusted_mode_sw->crtc_hdisplay;
  1030. crtc_hsync_end_sw = hsync_sw + crtc_hsync_start_sw;
  1031. crtc_hblank_start_sw = adjusted_mode_sw->crtc_hdisplay;
  1032. crtc_hblank_end_sw = crtc_htotal_sw;
  1033. if (adjusted_mode->crtc_htotal == crtc_htotal_sw)
  1034. adjusted_mode->crtc_htotal = adjusted_mode_sw->crtc_htotal;
  1035. if (adjusted_mode->crtc_hsync_start == crtc_hsync_start_sw)
  1036. adjusted_mode->crtc_hsync_start =
  1037. adjusted_mode_sw->crtc_hsync_start;
  1038. if (adjusted_mode->crtc_hsync_end == crtc_hsync_end_sw)
  1039. adjusted_mode->crtc_hsync_end =
  1040. adjusted_mode_sw->crtc_hsync_end;
  1041. if (adjusted_mode->crtc_hblank_start == crtc_hblank_start_sw)
  1042. adjusted_mode->crtc_hblank_start =
  1043. adjusted_mode_sw->crtc_hblank_start;
  1044. if (adjusted_mode->crtc_hblank_end == crtc_hblank_end_sw)
  1045. adjusted_mode->crtc_hblank_end =
  1046. adjusted_mode_sw->crtc_hblank_end;
  1047. }
  1048. static void intel_dsi_get_config(struct intel_encoder *encoder,
  1049. struct intel_crtc_state *pipe_config)
  1050. {
  1051. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1052. u32 pclk;
  1053. DRM_DEBUG_KMS("\n");
  1054. pipe_config->output_types |= BIT(INTEL_OUTPUT_DSI);
  1055. if (IS_GEN9_LP(dev_priv)) {
  1056. bxt_dsi_get_pipe_config(encoder, pipe_config);
  1057. pclk = bxt_dsi_get_pclk(encoder, pipe_config->pipe_bpp,
  1058. pipe_config);
  1059. } else {
  1060. pclk = vlv_dsi_get_pclk(encoder, pipe_config->pipe_bpp,
  1061. pipe_config);
  1062. }
  1063. if (pclk) {
  1064. pipe_config->base.adjusted_mode.crtc_clock = pclk;
  1065. pipe_config->port_clock = pclk;
  1066. }
  1067. }
  1068. static enum drm_mode_status
  1069. intel_dsi_mode_valid(struct drm_connector *connector,
  1070. struct drm_display_mode *mode)
  1071. {
  1072. struct intel_connector *intel_connector = to_intel_connector(connector);
  1073. const struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
  1074. int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
  1075. DRM_DEBUG_KMS("\n");
  1076. if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
  1077. return MODE_NO_DBLESCAN;
  1078. if (fixed_mode) {
  1079. if (mode->hdisplay > fixed_mode->hdisplay)
  1080. return MODE_PANEL;
  1081. if (mode->vdisplay > fixed_mode->vdisplay)
  1082. return MODE_PANEL;
  1083. if (fixed_mode->clock > max_dotclk)
  1084. return MODE_CLOCK_HIGH;
  1085. }
  1086. return MODE_OK;
  1087. }
  1088. /* return txclkesc cycles in terms of divider and duration in us */
  1089. static u16 txclkesc(u32 divider, unsigned int us)
  1090. {
  1091. switch (divider) {
  1092. case ESCAPE_CLOCK_DIVIDER_1:
  1093. default:
  1094. return 20 * us;
  1095. case ESCAPE_CLOCK_DIVIDER_2:
  1096. return 10 * us;
  1097. case ESCAPE_CLOCK_DIVIDER_4:
  1098. return 5 * us;
  1099. }
  1100. }
  1101. static void set_dsi_timings(struct drm_encoder *encoder,
  1102. const struct drm_display_mode *adjusted_mode)
  1103. {
  1104. struct drm_device *dev = encoder->dev;
  1105. struct drm_i915_private *dev_priv = to_i915(dev);
  1106. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  1107. enum port port;
  1108. unsigned int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
  1109. unsigned int lane_count = intel_dsi->lane_count;
  1110. u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
  1111. hactive = adjusted_mode->crtc_hdisplay;
  1112. hfp = adjusted_mode->crtc_hsync_start - adjusted_mode->crtc_hdisplay;
  1113. hsync = adjusted_mode->crtc_hsync_end - adjusted_mode->crtc_hsync_start;
  1114. hbp = adjusted_mode->crtc_htotal - adjusted_mode->crtc_hsync_end;
  1115. if (intel_dsi->dual_link) {
  1116. hactive /= 2;
  1117. if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
  1118. hactive += intel_dsi->pixel_overlap;
  1119. hfp /= 2;
  1120. hsync /= 2;
  1121. hbp /= 2;
  1122. }
  1123. vfp = adjusted_mode->crtc_vsync_start - adjusted_mode->crtc_vdisplay;
  1124. vsync = adjusted_mode->crtc_vsync_end - adjusted_mode->crtc_vsync_start;
  1125. vbp = adjusted_mode->crtc_vtotal - adjusted_mode->crtc_vsync_end;
  1126. /* horizontal values are in terms of high speed byte clock */
  1127. hactive = txbyteclkhs(hactive, bpp, lane_count,
  1128. intel_dsi->burst_mode_ratio);
  1129. hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio);
  1130. hsync = txbyteclkhs(hsync, bpp, lane_count,
  1131. intel_dsi->burst_mode_ratio);
  1132. hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio);
  1133. for_each_dsi_port(port, intel_dsi->ports) {
  1134. if (IS_GEN9_LP(dev_priv)) {
  1135. /*
  1136. * Program hdisplay and vdisplay on MIPI transcoder.
  1137. * This is different from calculated hactive and
  1138. * vactive, as they are calculated per channel basis,
  1139. * whereas these values should be based on resolution.
  1140. */
  1141. I915_WRITE(BXT_MIPI_TRANS_HACTIVE(port),
  1142. adjusted_mode->crtc_hdisplay);
  1143. I915_WRITE(BXT_MIPI_TRANS_VACTIVE(port),
  1144. adjusted_mode->crtc_vdisplay);
  1145. I915_WRITE(BXT_MIPI_TRANS_VTOTAL(port),
  1146. adjusted_mode->crtc_vtotal);
  1147. }
  1148. I915_WRITE(MIPI_HACTIVE_AREA_COUNT(port), hactive);
  1149. I915_WRITE(MIPI_HFP_COUNT(port), hfp);
  1150. /* meaningful for video mode non-burst sync pulse mode only,
  1151. * can be zero for non-burst sync events and burst modes */
  1152. I915_WRITE(MIPI_HSYNC_PADDING_COUNT(port), hsync);
  1153. I915_WRITE(MIPI_HBP_COUNT(port), hbp);
  1154. /* vertical values are in terms of lines */
  1155. I915_WRITE(MIPI_VFP_COUNT(port), vfp);
  1156. I915_WRITE(MIPI_VSYNC_PADDING_COUNT(port), vsync);
  1157. I915_WRITE(MIPI_VBP_COUNT(port), vbp);
  1158. }
  1159. }
  1160. static u32 pixel_format_to_reg(enum mipi_dsi_pixel_format fmt)
  1161. {
  1162. switch (fmt) {
  1163. case MIPI_DSI_FMT_RGB888:
  1164. return VID_MODE_FORMAT_RGB888;
  1165. case MIPI_DSI_FMT_RGB666:
  1166. return VID_MODE_FORMAT_RGB666;
  1167. case MIPI_DSI_FMT_RGB666_PACKED:
  1168. return VID_MODE_FORMAT_RGB666_PACKED;
  1169. case MIPI_DSI_FMT_RGB565:
  1170. return VID_MODE_FORMAT_RGB565;
  1171. default:
  1172. MISSING_CASE(fmt);
  1173. return VID_MODE_FORMAT_RGB666;
  1174. }
  1175. }
  1176. static void intel_dsi_prepare(struct intel_encoder *intel_encoder,
  1177. const struct intel_crtc_state *pipe_config)
  1178. {
  1179. struct drm_encoder *encoder = &intel_encoder->base;
  1180. struct drm_device *dev = encoder->dev;
  1181. struct drm_i915_private *dev_priv = to_i915(dev);
  1182. struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
  1183. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  1184. const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
  1185. enum port port;
  1186. unsigned int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
  1187. u32 val, tmp;
  1188. u16 mode_hdisplay;
  1189. DRM_DEBUG_KMS("pipe %c\n", pipe_name(intel_crtc->pipe));
  1190. mode_hdisplay = adjusted_mode->crtc_hdisplay;
  1191. if (intel_dsi->dual_link) {
  1192. mode_hdisplay /= 2;
  1193. if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
  1194. mode_hdisplay += intel_dsi->pixel_overlap;
  1195. }
  1196. for_each_dsi_port(port, intel_dsi->ports) {
  1197. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  1198. /*
  1199. * escape clock divider, 20MHz, shared for A and C.
  1200. * device ready must be off when doing this! txclkesc?
  1201. */
  1202. tmp = I915_READ(MIPI_CTRL(PORT_A));
  1203. tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
  1204. I915_WRITE(MIPI_CTRL(PORT_A), tmp |
  1205. ESCAPE_CLOCK_DIVIDER_1);
  1206. /* read request priority is per pipe */
  1207. tmp = I915_READ(MIPI_CTRL(port));
  1208. tmp &= ~READ_REQUEST_PRIORITY_MASK;
  1209. I915_WRITE(MIPI_CTRL(port), tmp |
  1210. READ_REQUEST_PRIORITY_HIGH);
  1211. } else if (IS_GEN9_LP(dev_priv)) {
  1212. enum pipe pipe = intel_crtc->pipe;
  1213. tmp = I915_READ(MIPI_CTRL(port));
  1214. tmp &= ~BXT_PIPE_SELECT_MASK;
  1215. tmp |= BXT_PIPE_SELECT(pipe);
  1216. I915_WRITE(MIPI_CTRL(port), tmp);
  1217. }
  1218. /* XXX: why here, why like this? handling in irq handler?! */
  1219. I915_WRITE(MIPI_INTR_STAT(port), 0xffffffff);
  1220. I915_WRITE(MIPI_INTR_EN(port), 0xffffffff);
  1221. I915_WRITE(MIPI_DPHY_PARAM(port), intel_dsi->dphy_reg);
  1222. I915_WRITE(MIPI_DPI_RESOLUTION(port),
  1223. adjusted_mode->crtc_vdisplay << VERTICAL_ADDRESS_SHIFT |
  1224. mode_hdisplay << HORIZONTAL_ADDRESS_SHIFT);
  1225. }
  1226. set_dsi_timings(encoder, adjusted_mode);
  1227. val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
  1228. if (is_cmd_mode(intel_dsi)) {
  1229. val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
  1230. val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
  1231. } else {
  1232. val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
  1233. val |= pixel_format_to_reg(intel_dsi->pixel_format);
  1234. }
  1235. tmp = 0;
  1236. if (intel_dsi->eotp_pkt == 0)
  1237. tmp |= EOT_DISABLE;
  1238. if (intel_dsi->clock_stop)
  1239. tmp |= CLOCKSTOP;
  1240. if (IS_GEN9_LP(dev_priv)) {
  1241. tmp |= BXT_DPHY_DEFEATURE_EN;
  1242. if (!is_cmd_mode(intel_dsi))
  1243. tmp |= BXT_DEFEATURE_DPI_FIFO_CTR;
  1244. }
  1245. for_each_dsi_port(port, intel_dsi->ports) {
  1246. I915_WRITE(MIPI_DSI_FUNC_PRG(port), val);
  1247. /* timeouts for recovery. one frame IIUC. if counter expires,
  1248. * EOT and stop state. */
  1249. /*
  1250. * In burst mode, value greater than one DPI line Time in byte
  1251. * clock (txbyteclkhs) To timeout this timer 1+ of the above
  1252. * said value is recommended.
  1253. *
  1254. * In non-burst mode, Value greater than one DPI frame time in
  1255. * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
  1256. * said value is recommended.
  1257. *
  1258. * In DBI only mode, value greater than one DBI frame time in
  1259. * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
  1260. * said value is recommended.
  1261. */
  1262. if (is_vid_mode(intel_dsi) &&
  1263. intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
  1264. I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
  1265. txbyteclkhs(adjusted_mode->crtc_htotal, bpp,
  1266. intel_dsi->lane_count,
  1267. intel_dsi->burst_mode_ratio) + 1);
  1268. } else {
  1269. I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
  1270. txbyteclkhs(adjusted_mode->crtc_vtotal *
  1271. adjusted_mode->crtc_htotal,
  1272. bpp, intel_dsi->lane_count,
  1273. intel_dsi->burst_mode_ratio) + 1);
  1274. }
  1275. I915_WRITE(MIPI_LP_RX_TIMEOUT(port), intel_dsi->lp_rx_timeout);
  1276. I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(port),
  1277. intel_dsi->turn_arnd_val);
  1278. I915_WRITE(MIPI_DEVICE_RESET_TIMER(port),
  1279. intel_dsi->rst_timer_val);
  1280. /* dphy stuff */
  1281. /* in terms of low power clock */
  1282. I915_WRITE(MIPI_INIT_COUNT(port),
  1283. txclkesc(intel_dsi->escape_clk_div, 100));
  1284. if (IS_GEN9_LP(dev_priv) && (!intel_dsi->dual_link)) {
  1285. /*
  1286. * BXT spec says write MIPI_INIT_COUNT for
  1287. * both the ports, even if only one is
  1288. * getting used. So write the other port
  1289. * if not in dual link mode.
  1290. */
  1291. I915_WRITE(MIPI_INIT_COUNT(port ==
  1292. PORT_A ? PORT_C : PORT_A),
  1293. intel_dsi->init_count);
  1294. }
  1295. /* recovery disables */
  1296. I915_WRITE(MIPI_EOT_DISABLE(port), tmp);
  1297. /* in terms of low power clock */
  1298. I915_WRITE(MIPI_INIT_COUNT(port), intel_dsi->init_count);
  1299. /* in terms of txbyteclkhs. actual high to low switch +
  1300. * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
  1301. *
  1302. * XXX: write MIPI_STOP_STATE_STALL?
  1303. */
  1304. I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(port),
  1305. intel_dsi->hs_to_lp_count);
  1306. /* XXX: low power clock equivalence in terms of byte clock.
  1307. * the number of byte clocks occupied in one low power clock.
  1308. * based on txbyteclkhs and txclkesc.
  1309. * txclkesc time / txbyteclk time * (105 + MIPI_STOP_STATE_STALL
  1310. * ) / 105.???
  1311. */
  1312. I915_WRITE(MIPI_LP_BYTECLK(port), intel_dsi->lp_byte_clk);
  1313. if (IS_GEMINILAKE(dev_priv)) {
  1314. I915_WRITE(MIPI_TLPX_TIME_COUNT(port),
  1315. intel_dsi->lp_byte_clk);
  1316. /* Shadow of DPHY reg */
  1317. I915_WRITE(MIPI_CLK_LANE_TIMING(port),
  1318. intel_dsi->dphy_reg);
  1319. }
  1320. /* the bw essential for transmitting 16 long packets containing
  1321. * 252 bytes meant for dcs write memory command is programmed in
  1322. * this register in terms of byte clocks. based on dsi transfer
  1323. * rate and the number of lanes configured the time taken to
  1324. * transmit 16 long packets in a dsi stream varies. */
  1325. I915_WRITE(MIPI_DBI_BW_CTRL(port), intel_dsi->bw_timer);
  1326. I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(port),
  1327. intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT |
  1328. intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT);
  1329. if (is_vid_mode(intel_dsi))
  1330. /* Some panels might have resolution which is not a
  1331. * multiple of 64 like 1366 x 768. Enable RANDOM
  1332. * resolution support for such panels by default */
  1333. I915_WRITE(MIPI_VIDEO_MODE_FORMAT(port),
  1334. intel_dsi->video_frmt_cfg_bits |
  1335. intel_dsi->video_mode_format |
  1336. IP_TG_CONFIG |
  1337. RANDOM_DPI_DISPLAY_RESOLUTION);
  1338. }
  1339. }
  1340. static void intel_dsi_unprepare(struct intel_encoder *encoder)
  1341. {
  1342. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1343. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  1344. enum port port;
  1345. u32 val;
  1346. if (IS_GEMINILAKE(dev_priv))
  1347. return;
  1348. for_each_dsi_port(port, intel_dsi->ports) {
  1349. /* Panel commands can be sent when clock is in LP11 */
  1350. I915_WRITE(MIPI_DEVICE_READY(port), 0x0);
  1351. if (IS_GEN9_LP(dev_priv))
  1352. bxt_dsi_reset_clocks(encoder, port);
  1353. else
  1354. vlv_dsi_reset_clocks(encoder, port);
  1355. I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP);
  1356. val = I915_READ(MIPI_DSI_FUNC_PRG(port));
  1357. val &= ~VID_MODE_FORMAT_MASK;
  1358. I915_WRITE(MIPI_DSI_FUNC_PRG(port), val);
  1359. I915_WRITE(MIPI_DEVICE_READY(port), 0x1);
  1360. }
  1361. }
  1362. static int intel_dsi_get_modes(struct drm_connector *connector)
  1363. {
  1364. struct intel_connector *intel_connector = to_intel_connector(connector);
  1365. struct drm_display_mode *mode;
  1366. DRM_DEBUG_KMS("\n");
  1367. if (!intel_connector->panel.fixed_mode) {
  1368. DRM_DEBUG_KMS("no fixed mode\n");
  1369. return 0;
  1370. }
  1371. mode = drm_mode_duplicate(connector->dev,
  1372. intel_connector->panel.fixed_mode);
  1373. if (!mode) {
  1374. DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
  1375. return 0;
  1376. }
  1377. drm_mode_probed_add(connector, mode);
  1378. return 1;
  1379. }
  1380. static void intel_dsi_connector_destroy(struct drm_connector *connector)
  1381. {
  1382. struct intel_connector *intel_connector = to_intel_connector(connector);
  1383. DRM_DEBUG_KMS("\n");
  1384. intel_panel_fini(&intel_connector->panel);
  1385. drm_connector_cleanup(connector);
  1386. kfree(connector);
  1387. }
  1388. static void intel_dsi_encoder_destroy(struct drm_encoder *encoder)
  1389. {
  1390. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  1391. /* dispose of the gpios */
  1392. if (intel_dsi->gpio_panel)
  1393. gpiod_put(intel_dsi->gpio_panel);
  1394. intel_encoder_destroy(encoder);
  1395. }
  1396. static const struct drm_encoder_funcs intel_dsi_funcs = {
  1397. .destroy = intel_dsi_encoder_destroy,
  1398. };
  1399. static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
  1400. .get_modes = intel_dsi_get_modes,
  1401. .mode_valid = intel_dsi_mode_valid,
  1402. .atomic_check = intel_digital_connector_atomic_check,
  1403. };
  1404. static const struct drm_connector_funcs intel_dsi_connector_funcs = {
  1405. .late_register = intel_connector_register,
  1406. .early_unregister = intel_connector_unregister,
  1407. .destroy = intel_dsi_connector_destroy,
  1408. .fill_modes = drm_helper_probe_single_connector_modes,
  1409. .atomic_get_property = intel_digital_connector_atomic_get_property,
  1410. .atomic_set_property = intel_digital_connector_atomic_set_property,
  1411. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  1412. .atomic_duplicate_state = intel_digital_connector_duplicate_state,
  1413. };
  1414. static int intel_dsi_get_panel_orientation(struct intel_connector *connector)
  1415. {
  1416. struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
  1417. int orientation = DRM_MODE_PANEL_ORIENTATION_NORMAL;
  1418. enum i9xx_plane_id i9xx_plane;
  1419. u32 val;
  1420. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  1421. if (connector->encoder->crtc_mask == BIT(PIPE_B))
  1422. i9xx_plane = PLANE_B;
  1423. else
  1424. i9xx_plane = PLANE_A;
  1425. val = I915_READ(DSPCNTR(i9xx_plane));
  1426. if (val & DISPPLANE_ROTATE_180)
  1427. orientation = DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP;
  1428. }
  1429. return orientation;
  1430. }
  1431. static void intel_dsi_add_properties(struct intel_connector *connector)
  1432. {
  1433. struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
  1434. if (connector->panel.fixed_mode) {
  1435. u32 allowed_scalers;
  1436. allowed_scalers = BIT(DRM_MODE_SCALE_ASPECT) | BIT(DRM_MODE_SCALE_FULLSCREEN);
  1437. if (!HAS_GMCH_DISPLAY(dev_priv))
  1438. allowed_scalers |= BIT(DRM_MODE_SCALE_CENTER);
  1439. drm_connector_attach_scaling_mode_property(&connector->base,
  1440. allowed_scalers);
  1441. connector->base.state->scaling_mode = DRM_MODE_SCALE_ASPECT;
  1442. connector->base.display_info.panel_orientation =
  1443. intel_dsi_get_panel_orientation(connector);
  1444. drm_connector_init_panel_orientation_property(
  1445. &connector->base,
  1446. connector->panel.fixed_mode->hdisplay,
  1447. connector->panel.fixed_mode->vdisplay);
  1448. }
  1449. }
  1450. void vlv_dsi_init(struct drm_i915_private *dev_priv)
  1451. {
  1452. struct drm_device *dev = &dev_priv->drm;
  1453. struct intel_dsi *intel_dsi;
  1454. struct intel_encoder *intel_encoder;
  1455. struct drm_encoder *encoder;
  1456. struct intel_connector *intel_connector;
  1457. struct drm_connector *connector;
  1458. struct drm_display_mode *scan, *fixed_mode = NULL;
  1459. enum port port;
  1460. DRM_DEBUG_KMS("\n");
  1461. /* There is no detection method for MIPI so rely on VBT */
  1462. if (!intel_bios_is_dsi_present(dev_priv, &port))
  1463. return;
  1464. if (IS_GEN9_LP(dev_priv))
  1465. dev_priv->mipi_mmio_base = BXT_MIPI_BASE;
  1466. else
  1467. dev_priv->mipi_mmio_base = VLV_MIPI_BASE;
  1468. intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
  1469. if (!intel_dsi)
  1470. return;
  1471. intel_connector = intel_connector_alloc();
  1472. if (!intel_connector) {
  1473. kfree(intel_dsi);
  1474. return;
  1475. }
  1476. intel_encoder = &intel_dsi->base;
  1477. encoder = &intel_encoder->base;
  1478. intel_dsi->attached_connector = intel_connector;
  1479. connector = &intel_connector->base;
  1480. drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI,
  1481. "DSI %c", port_name(port));
  1482. intel_encoder->compute_config = intel_dsi_compute_config;
  1483. intel_encoder->pre_enable = intel_dsi_pre_enable;
  1484. intel_encoder->enable = intel_dsi_enable_nop;
  1485. intel_encoder->disable = intel_dsi_disable;
  1486. intel_encoder->post_disable = intel_dsi_post_disable;
  1487. intel_encoder->get_hw_state = intel_dsi_get_hw_state;
  1488. intel_encoder->get_config = intel_dsi_get_config;
  1489. intel_connector->get_hw_state = intel_connector_get_hw_state;
  1490. intel_encoder->port = port;
  1491. /*
  1492. * On BYT/CHV, pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI
  1493. * port C. BXT isn't limited like this.
  1494. */
  1495. if (IS_GEN9_LP(dev_priv))
  1496. intel_encoder->crtc_mask = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C);
  1497. else if (port == PORT_A)
  1498. intel_encoder->crtc_mask = BIT(PIPE_A);
  1499. else
  1500. intel_encoder->crtc_mask = BIT(PIPE_B);
  1501. if (dev_priv->vbt.dsi.config->dual_link)
  1502. intel_dsi->ports = BIT(PORT_A) | BIT(PORT_C);
  1503. else
  1504. intel_dsi->ports = BIT(port);
  1505. intel_dsi->dcs_backlight_ports = dev_priv->vbt.dsi.bl_ports;
  1506. intel_dsi->dcs_cabc_ports = dev_priv->vbt.dsi.cabc_ports;
  1507. /* Create a DSI host (and a device) for each port. */
  1508. for_each_dsi_port(port, intel_dsi->ports) {
  1509. struct intel_dsi_host *host;
  1510. host = intel_dsi_host_init(intel_dsi, port);
  1511. if (!host)
  1512. goto err;
  1513. intel_dsi->dsi_hosts[port] = host;
  1514. }
  1515. if (!intel_dsi_vbt_init(intel_dsi, MIPI_DSI_GENERIC_PANEL_ID)) {
  1516. DRM_DEBUG_KMS("no device found\n");
  1517. goto err;
  1518. }
  1519. /*
  1520. * In case of BYT with CRC PMIC, we need to use GPIO for
  1521. * Panel control.
  1522. */
  1523. if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
  1524. (dev_priv->vbt.dsi.config->pwm_blc == PPS_BLC_PMIC)) {
  1525. intel_dsi->gpio_panel =
  1526. gpiod_get(dev->dev, "panel", GPIOD_OUT_HIGH);
  1527. if (IS_ERR(intel_dsi->gpio_panel)) {
  1528. DRM_ERROR("Failed to own gpio for panel control\n");
  1529. intel_dsi->gpio_panel = NULL;
  1530. }
  1531. }
  1532. intel_encoder->type = INTEL_OUTPUT_DSI;
  1533. intel_encoder->power_domain = POWER_DOMAIN_PORT_DSI;
  1534. intel_encoder->cloneable = 0;
  1535. drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
  1536. DRM_MODE_CONNECTOR_DSI);
  1537. drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
  1538. connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
  1539. connector->interlace_allowed = false;
  1540. connector->doublescan_allowed = false;
  1541. intel_connector_attach_encoder(intel_connector, intel_encoder);
  1542. mutex_lock(&dev->mode_config.mutex);
  1543. intel_dsi_vbt_get_modes(intel_dsi);
  1544. list_for_each_entry(scan, &connector->probed_modes, head) {
  1545. if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
  1546. fixed_mode = drm_mode_duplicate(dev, scan);
  1547. break;
  1548. }
  1549. }
  1550. mutex_unlock(&dev->mode_config.mutex);
  1551. if (!fixed_mode) {
  1552. DRM_DEBUG_KMS("no fixed mode\n");
  1553. goto err;
  1554. }
  1555. connector->display_info.width_mm = fixed_mode->width_mm;
  1556. connector->display_info.height_mm = fixed_mode->height_mm;
  1557. intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
  1558. intel_panel_setup_backlight(connector, INVALID_PIPE);
  1559. intel_dsi_add_properties(intel_connector);
  1560. return;
  1561. err:
  1562. drm_encoder_cleanup(&intel_encoder->base);
  1563. kfree(intel_dsi);
  1564. kfree(intel_connector);
  1565. }