intel_dsi.c 46 KB

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