intel_dsi.c 46 KB

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