intel_dsi.c 47 KB

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