intel_dsi.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  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. static void wait_for_dsi_fifo_empty(struct intel_dsi *intel_dsi, enum port port)
  47. {
  48. struct drm_encoder *encoder = &intel_dsi->base.base;
  49. struct drm_device *dev = encoder->dev;
  50. struct drm_i915_private *dev_priv = dev->dev_private;
  51. u32 mask;
  52. mask = LP_CTRL_FIFO_EMPTY | HS_CTRL_FIFO_EMPTY |
  53. LP_DATA_FIFO_EMPTY | HS_DATA_FIFO_EMPTY;
  54. if (wait_for((I915_READ(MIPI_GEN_FIFO_STAT(port)) & mask) == mask, 100))
  55. DRM_ERROR("DPI FIFOs are not empty\n");
  56. }
  57. static void write_data(struct drm_i915_private *dev_priv,
  58. i915_reg_t reg,
  59. const u8 *data, u32 len)
  60. {
  61. u32 i, j;
  62. for (i = 0; i < len; i += 4) {
  63. u32 val = 0;
  64. for (j = 0; j < min_t(u32, len - i, 4); j++)
  65. val |= *data++ << 8 * j;
  66. I915_WRITE(reg, val);
  67. }
  68. }
  69. static void read_data(struct drm_i915_private *dev_priv,
  70. i915_reg_t reg,
  71. u8 *data, u32 len)
  72. {
  73. u32 i, j;
  74. for (i = 0; i < len; i += 4) {
  75. u32 val = I915_READ(reg);
  76. for (j = 0; j < min_t(u32, len - i, 4); j++)
  77. *data++ = val >> 8 * j;
  78. }
  79. }
  80. static ssize_t intel_dsi_host_transfer(struct mipi_dsi_host *host,
  81. const struct mipi_dsi_msg *msg)
  82. {
  83. struct intel_dsi_host *intel_dsi_host = to_intel_dsi_host(host);
  84. struct drm_device *dev = intel_dsi_host->intel_dsi->base.base.dev;
  85. struct drm_i915_private *dev_priv = dev->dev_private;
  86. enum port port = intel_dsi_host->port;
  87. struct mipi_dsi_packet packet;
  88. ssize_t ret;
  89. const u8 *header, *data;
  90. i915_reg_t data_reg, ctrl_reg;
  91. u32 data_mask, ctrl_mask;
  92. ret = mipi_dsi_create_packet(&packet, msg);
  93. if (ret < 0)
  94. return ret;
  95. header = packet.header;
  96. data = packet.payload;
  97. if (msg->flags & MIPI_DSI_MSG_USE_LPM) {
  98. data_reg = MIPI_LP_GEN_DATA(port);
  99. data_mask = LP_DATA_FIFO_FULL;
  100. ctrl_reg = MIPI_LP_GEN_CTRL(port);
  101. ctrl_mask = LP_CTRL_FIFO_FULL;
  102. } else {
  103. data_reg = MIPI_HS_GEN_DATA(port);
  104. data_mask = HS_DATA_FIFO_FULL;
  105. ctrl_reg = MIPI_HS_GEN_CTRL(port);
  106. ctrl_mask = HS_CTRL_FIFO_FULL;
  107. }
  108. /* note: this is never true for reads */
  109. if (packet.payload_length) {
  110. if (wait_for((I915_READ(MIPI_GEN_FIFO_STAT(port)) & data_mask) == 0, 50))
  111. DRM_ERROR("Timeout waiting for HS/LP DATA FIFO !full\n");
  112. write_data(dev_priv, data_reg, packet.payload,
  113. packet.payload_length);
  114. }
  115. if (msg->rx_len) {
  116. I915_WRITE(MIPI_INTR_STAT(port), GEN_READ_DATA_AVAIL);
  117. }
  118. if (wait_for((I915_READ(MIPI_GEN_FIFO_STAT(port)) & ctrl_mask) == 0, 50)) {
  119. DRM_ERROR("Timeout waiting for HS/LP CTRL FIFO !full\n");
  120. }
  121. I915_WRITE(ctrl_reg, header[2] << 16 | header[1] << 8 | header[0]);
  122. /* ->rx_len is set only for reads */
  123. if (msg->rx_len) {
  124. data_mask = GEN_READ_DATA_AVAIL;
  125. if (wait_for((I915_READ(MIPI_INTR_STAT(port)) & data_mask) == data_mask, 50))
  126. DRM_ERROR("Timeout waiting for read data.\n");
  127. read_data(dev_priv, data_reg, msg->rx_buf, msg->rx_len);
  128. }
  129. /* XXX: fix for reads and writes */
  130. return 4 + packet.payload_length;
  131. }
  132. static int intel_dsi_host_attach(struct mipi_dsi_host *host,
  133. struct mipi_dsi_device *dsi)
  134. {
  135. return 0;
  136. }
  137. static int intel_dsi_host_detach(struct mipi_dsi_host *host,
  138. struct mipi_dsi_device *dsi)
  139. {
  140. return 0;
  141. }
  142. static const struct mipi_dsi_host_ops intel_dsi_host_ops = {
  143. .attach = intel_dsi_host_attach,
  144. .detach = intel_dsi_host_detach,
  145. .transfer = intel_dsi_host_transfer,
  146. };
  147. static struct intel_dsi_host *intel_dsi_host_init(struct intel_dsi *intel_dsi,
  148. enum port port)
  149. {
  150. struct intel_dsi_host *host;
  151. struct mipi_dsi_device *device;
  152. host = kzalloc(sizeof(*host), GFP_KERNEL);
  153. if (!host)
  154. return NULL;
  155. host->base.ops = &intel_dsi_host_ops;
  156. host->intel_dsi = intel_dsi;
  157. host->port = port;
  158. /*
  159. * We should call mipi_dsi_host_register(&host->base) here, but we don't
  160. * have a host->dev, and we don't have OF stuff either. So just use the
  161. * dsi framework as a library and hope for the best. Create the dsi
  162. * devices by ourselves here too. Need to be careful though, because we
  163. * don't initialize any of the driver model devices here.
  164. */
  165. device = kzalloc(sizeof(*device), GFP_KERNEL);
  166. if (!device) {
  167. kfree(host);
  168. return NULL;
  169. }
  170. device->host = &host->base;
  171. host->device = device;
  172. return host;
  173. }
  174. /*
  175. * send a video mode command
  176. *
  177. * XXX: commands with data in MIPI_DPI_DATA?
  178. */
  179. static int dpi_send_cmd(struct intel_dsi *intel_dsi, u32 cmd, bool hs,
  180. enum port port)
  181. {
  182. struct drm_encoder *encoder = &intel_dsi->base.base;
  183. struct drm_device *dev = encoder->dev;
  184. struct drm_i915_private *dev_priv = dev->dev_private;
  185. u32 mask;
  186. /* XXX: pipe, hs */
  187. if (hs)
  188. cmd &= ~DPI_LP_MODE;
  189. else
  190. cmd |= DPI_LP_MODE;
  191. /* clear bit */
  192. I915_WRITE(MIPI_INTR_STAT(port), SPL_PKT_SENT_INTERRUPT);
  193. /* XXX: old code skips write if control unchanged */
  194. if (cmd == I915_READ(MIPI_DPI_CONTROL(port)))
  195. DRM_ERROR("Same special packet %02x twice in a row.\n", cmd);
  196. I915_WRITE(MIPI_DPI_CONTROL(port), cmd);
  197. mask = SPL_PKT_SENT_INTERRUPT;
  198. if (wait_for((I915_READ(MIPI_INTR_STAT(port)) & mask) == mask, 100))
  199. DRM_ERROR("Video mode command 0x%08x send failed.\n", cmd);
  200. return 0;
  201. }
  202. static void band_gap_reset(struct drm_i915_private *dev_priv)
  203. {
  204. mutex_lock(&dev_priv->sb_lock);
  205. vlv_flisdsi_write(dev_priv, 0x08, 0x0001);
  206. vlv_flisdsi_write(dev_priv, 0x0F, 0x0005);
  207. vlv_flisdsi_write(dev_priv, 0x0F, 0x0025);
  208. udelay(150);
  209. vlv_flisdsi_write(dev_priv, 0x0F, 0x0000);
  210. vlv_flisdsi_write(dev_priv, 0x08, 0x0000);
  211. mutex_unlock(&dev_priv->sb_lock);
  212. }
  213. static inline bool is_vid_mode(struct intel_dsi *intel_dsi)
  214. {
  215. return intel_dsi->operation_mode == INTEL_DSI_VIDEO_MODE;
  216. }
  217. static inline bool is_cmd_mode(struct intel_dsi *intel_dsi)
  218. {
  219. return intel_dsi->operation_mode == INTEL_DSI_COMMAND_MODE;
  220. }
  221. static bool intel_dsi_compute_config(struct intel_encoder *encoder,
  222. struct intel_crtc_state *pipe_config)
  223. {
  224. struct intel_dsi *intel_dsi = container_of(encoder, struct intel_dsi,
  225. base);
  226. struct intel_connector *intel_connector = intel_dsi->attached_connector;
  227. struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
  228. struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
  229. DRM_DEBUG_KMS("\n");
  230. pipe_config->has_dsi_encoder = true;
  231. if (fixed_mode)
  232. intel_fixed_panel_mode(fixed_mode, adjusted_mode);
  233. /* DSI uses short packets for sync events, so clear mode flags for DSI */
  234. adjusted_mode->flags = 0;
  235. return true;
  236. }
  237. static void bxt_dsi_device_ready(struct intel_encoder *encoder)
  238. {
  239. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  240. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  241. enum port port;
  242. u32 val;
  243. DRM_DEBUG_KMS("\n");
  244. /* Exit Low power state in 4 steps*/
  245. for_each_dsi_port(port, intel_dsi->ports) {
  246. /* 1. Enable MIPI PHY transparent latch */
  247. val = I915_READ(BXT_MIPI_PORT_CTRL(port));
  248. I915_WRITE(BXT_MIPI_PORT_CTRL(port), val | LP_OUTPUT_HOLD);
  249. usleep_range(2000, 2500);
  250. /* 2. Enter ULPS */
  251. val = I915_READ(MIPI_DEVICE_READY(port));
  252. val &= ~ULPS_STATE_MASK;
  253. val |= (ULPS_STATE_ENTER | DEVICE_READY);
  254. I915_WRITE(MIPI_DEVICE_READY(port), val);
  255. usleep_range(2, 3);
  256. /* 3. Exit ULPS */
  257. val = I915_READ(MIPI_DEVICE_READY(port));
  258. val &= ~ULPS_STATE_MASK;
  259. val |= (ULPS_STATE_EXIT | DEVICE_READY);
  260. I915_WRITE(MIPI_DEVICE_READY(port), val);
  261. usleep_range(1000, 1500);
  262. /* Clear ULPS and set device ready */
  263. val = I915_READ(MIPI_DEVICE_READY(port));
  264. val &= ~ULPS_STATE_MASK;
  265. val |= DEVICE_READY;
  266. I915_WRITE(MIPI_DEVICE_READY(port), val);
  267. }
  268. }
  269. static void vlv_dsi_device_ready(struct intel_encoder *encoder)
  270. {
  271. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  272. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  273. enum port port;
  274. u32 val;
  275. DRM_DEBUG_KMS("\n");
  276. mutex_lock(&dev_priv->sb_lock);
  277. /* program rcomp for compliance, reduce from 50 ohms to 45 ohms
  278. * needed everytime after power gate */
  279. vlv_flisdsi_write(dev_priv, 0x04, 0x0004);
  280. mutex_unlock(&dev_priv->sb_lock);
  281. /* bandgap reset is needed after everytime we do power gate */
  282. band_gap_reset(dev_priv);
  283. for_each_dsi_port(port, intel_dsi->ports) {
  284. I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_ENTER);
  285. usleep_range(2500, 3000);
  286. /* Enable MIPI PHY transparent latch
  287. * Common bit for both MIPI Port A & MIPI Port C
  288. * No similar bit in MIPI Port C reg
  289. */
  290. val = I915_READ(MIPI_PORT_CTRL(PORT_A));
  291. I915_WRITE(MIPI_PORT_CTRL(PORT_A), val | LP_OUTPUT_HOLD);
  292. usleep_range(1000, 1500);
  293. I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_EXIT);
  294. usleep_range(2500, 3000);
  295. I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY);
  296. usleep_range(2500, 3000);
  297. }
  298. }
  299. static void intel_dsi_device_ready(struct intel_encoder *encoder)
  300. {
  301. struct drm_device *dev = encoder->base.dev;
  302. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
  303. vlv_dsi_device_ready(encoder);
  304. else if (IS_BROXTON(dev))
  305. bxt_dsi_device_ready(encoder);
  306. }
  307. static void intel_dsi_port_enable(struct intel_encoder *encoder)
  308. {
  309. struct drm_device *dev = encoder->base.dev;
  310. struct drm_i915_private *dev_priv = dev->dev_private;
  311. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  312. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  313. enum port port;
  314. if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) {
  315. u32 temp;
  316. temp = I915_READ(VLV_CHICKEN_3);
  317. temp &= ~PIXEL_OVERLAP_CNT_MASK |
  318. intel_dsi->pixel_overlap <<
  319. PIXEL_OVERLAP_CNT_SHIFT;
  320. I915_WRITE(VLV_CHICKEN_3, temp);
  321. }
  322. for_each_dsi_port(port, intel_dsi->ports) {
  323. i915_reg_t port_ctrl = IS_BROXTON(dev) ?
  324. BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
  325. u32 temp;
  326. temp = I915_READ(port_ctrl);
  327. temp &= ~LANE_CONFIGURATION_MASK;
  328. temp &= ~DUAL_LINK_MODE_MASK;
  329. if (intel_dsi->ports == ((1 << PORT_A) | (1 << PORT_C))) {
  330. temp |= (intel_dsi->dual_link - 1)
  331. << DUAL_LINK_MODE_SHIFT;
  332. temp |= intel_crtc->pipe ?
  333. LANE_CONFIGURATION_DUAL_LINK_B :
  334. LANE_CONFIGURATION_DUAL_LINK_A;
  335. }
  336. /* assert ip_tg_enable signal */
  337. I915_WRITE(port_ctrl, temp | DPI_ENABLE);
  338. POSTING_READ(port_ctrl);
  339. }
  340. }
  341. static void intel_dsi_port_disable(struct intel_encoder *encoder)
  342. {
  343. struct drm_device *dev = encoder->base.dev;
  344. struct drm_i915_private *dev_priv = dev->dev_private;
  345. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  346. enum port port;
  347. for_each_dsi_port(port, intel_dsi->ports) {
  348. i915_reg_t port_ctrl = IS_BROXTON(dev) ?
  349. BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
  350. u32 temp;
  351. /* de-assert ip_tg_enable signal */
  352. temp = I915_READ(port_ctrl);
  353. I915_WRITE(port_ctrl, temp & ~DPI_ENABLE);
  354. POSTING_READ(port_ctrl);
  355. }
  356. }
  357. static void intel_dsi_enable(struct intel_encoder *encoder)
  358. {
  359. struct drm_device *dev = encoder->base.dev;
  360. struct drm_i915_private *dev_priv = dev->dev_private;
  361. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  362. enum port port;
  363. DRM_DEBUG_KMS("\n");
  364. if (is_cmd_mode(intel_dsi)) {
  365. for_each_dsi_port(port, intel_dsi->ports)
  366. I915_WRITE(MIPI_MAX_RETURN_PKT_SIZE(port), 8 * 4);
  367. } else {
  368. msleep(20); /* XXX */
  369. for_each_dsi_port(port, intel_dsi->ports)
  370. dpi_send_cmd(intel_dsi, TURN_ON, false, port);
  371. msleep(100);
  372. drm_panel_enable(intel_dsi->panel);
  373. for_each_dsi_port(port, intel_dsi->ports)
  374. wait_for_dsi_fifo_empty(intel_dsi, port);
  375. intel_dsi_port_enable(encoder);
  376. }
  377. intel_panel_enable_backlight(intel_dsi->attached_connector);
  378. }
  379. static void intel_dsi_prepare(struct intel_encoder *intel_encoder);
  380. static void intel_dsi_pre_enable(struct intel_encoder *encoder)
  381. {
  382. struct drm_device *dev = encoder->base.dev;
  383. struct drm_i915_private *dev_priv = dev->dev_private;
  384. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  385. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  386. enum pipe pipe = intel_crtc->pipe;
  387. enum port port;
  388. u32 tmp;
  389. DRM_DEBUG_KMS("\n");
  390. intel_enable_dsi_pll(encoder);
  391. intel_dsi_prepare(encoder);
  392. /* Panel Enable over CRC PMIC */
  393. if (intel_dsi->gpio_panel)
  394. gpiod_set_value_cansleep(intel_dsi->gpio_panel, 1);
  395. msleep(intel_dsi->panel_on_delay);
  396. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
  397. /*
  398. * Disable DPOunit clock gating, can stall pipe
  399. * and we need DPLL REFA always enabled
  400. */
  401. tmp = I915_READ(DPLL(pipe));
  402. tmp |= DPLL_REF_CLK_ENABLE_VLV;
  403. I915_WRITE(DPLL(pipe), tmp);
  404. /* update the hw state for DPLL */
  405. intel_crtc->config->dpll_hw_state.dpll =
  406. DPLL_INTEGRATED_REF_CLK_VLV |
  407. DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
  408. tmp = I915_READ(DSPCLK_GATE_D);
  409. tmp |= DPOUNIT_CLOCK_GATE_DISABLE;
  410. I915_WRITE(DSPCLK_GATE_D, tmp);
  411. }
  412. /* put device in ready state */
  413. intel_dsi_device_ready(encoder);
  414. drm_panel_prepare(intel_dsi->panel);
  415. for_each_dsi_port(port, intel_dsi->ports)
  416. wait_for_dsi_fifo_empty(intel_dsi, port);
  417. /* Enable port in pre-enable phase itself because as per hw team
  418. * recommendation, port should be enabled befor plane & pipe */
  419. intel_dsi_enable(encoder);
  420. }
  421. static void intel_dsi_enable_nop(struct intel_encoder *encoder)
  422. {
  423. DRM_DEBUG_KMS("\n");
  424. /* for DSI port enable has to be done before pipe
  425. * and plane enable, so port enable is done in
  426. * pre_enable phase itself unlike other encoders
  427. */
  428. }
  429. static void intel_dsi_pre_disable(struct intel_encoder *encoder)
  430. {
  431. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  432. enum port port;
  433. DRM_DEBUG_KMS("\n");
  434. intel_panel_disable_backlight(intel_dsi->attached_connector);
  435. if (is_vid_mode(intel_dsi)) {
  436. /* Send Shutdown command to the panel in LP mode */
  437. for_each_dsi_port(port, intel_dsi->ports)
  438. dpi_send_cmd(intel_dsi, SHUTDOWN, false, port);
  439. msleep(10);
  440. }
  441. }
  442. static void intel_dsi_disable(struct intel_encoder *encoder)
  443. {
  444. struct drm_device *dev = encoder->base.dev;
  445. struct drm_i915_private *dev_priv = dev->dev_private;
  446. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  447. enum port port;
  448. u32 temp;
  449. DRM_DEBUG_KMS("\n");
  450. if (is_vid_mode(intel_dsi)) {
  451. for_each_dsi_port(port, intel_dsi->ports)
  452. wait_for_dsi_fifo_empty(intel_dsi, port);
  453. intel_dsi_port_disable(encoder);
  454. msleep(2);
  455. }
  456. for_each_dsi_port(port, intel_dsi->ports) {
  457. /* Panel commands can be sent when clock is in LP11 */
  458. I915_WRITE(MIPI_DEVICE_READY(port), 0x0);
  459. intel_dsi_reset_clocks(encoder, port);
  460. I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP);
  461. temp = I915_READ(MIPI_DSI_FUNC_PRG(port));
  462. temp &= ~VID_MODE_FORMAT_MASK;
  463. I915_WRITE(MIPI_DSI_FUNC_PRG(port), temp);
  464. I915_WRITE(MIPI_DEVICE_READY(port), 0x1);
  465. }
  466. /* if disable packets are sent before sending shutdown packet then in
  467. * some next enable sequence send turn on packet error is observed */
  468. drm_panel_disable(intel_dsi->panel);
  469. for_each_dsi_port(port, intel_dsi->ports)
  470. wait_for_dsi_fifo_empty(intel_dsi, port);
  471. }
  472. static void intel_dsi_clear_device_ready(struct intel_encoder *encoder)
  473. {
  474. struct drm_device *dev = encoder->base.dev;
  475. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  476. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  477. enum port port;
  478. DRM_DEBUG_KMS("\n");
  479. for_each_dsi_port(port, intel_dsi->ports) {
  480. /* Common bit for both MIPI Port A & MIPI Port C on VLV/CHV */
  481. i915_reg_t port_ctrl = IS_BROXTON(dev) ?
  482. BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(PORT_A);
  483. u32 val;
  484. I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
  485. ULPS_STATE_ENTER);
  486. usleep_range(2000, 2500);
  487. I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
  488. ULPS_STATE_EXIT);
  489. usleep_range(2000, 2500);
  490. I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
  491. ULPS_STATE_ENTER);
  492. usleep_range(2000, 2500);
  493. /* Wait till Clock lanes are in LP-00 state for MIPI Port A
  494. * only. MIPI Port C has no similar bit for checking
  495. */
  496. if (wait_for(((I915_READ(port_ctrl) & AFE_LATCHOUT)
  497. == 0x00000), 30))
  498. DRM_ERROR("DSI LP not going Low\n");
  499. /* Disable MIPI PHY transparent latch */
  500. val = I915_READ(port_ctrl);
  501. I915_WRITE(port_ctrl, val & ~LP_OUTPUT_HOLD);
  502. usleep_range(1000, 1500);
  503. I915_WRITE(MIPI_DEVICE_READY(port), 0x00);
  504. usleep_range(2000, 2500);
  505. }
  506. intel_disable_dsi_pll(encoder);
  507. }
  508. static void intel_dsi_post_disable(struct intel_encoder *encoder)
  509. {
  510. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  511. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  512. u32 val;
  513. DRM_DEBUG_KMS("\n");
  514. intel_dsi_disable(encoder);
  515. intel_dsi_clear_device_ready(encoder);
  516. val = I915_READ(DSPCLK_GATE_D);
  517. val &= ~DPOUNIT_CLOCK_GATE_DISABLE;
  518. I915_WRITE(DSPCLK_GATE_D, val);
  519. drm_panel_unprepare(intel_dsi->panel);
  520. msleep(intel_dsi->panel_off_delay);
  521. msleep(intel_dsi->panel_pwr_cycle_delay);
  522. /* Panel Disable over CRC PMIC */
  523. if (intel_dsi->gpio_panel)
  524. gpiod_set_value_cansleep(intel_dsi->gpio_panel, 0);
  525. }
  526. static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
  527. enum pipe *pipe)
  528. {
  529. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  530. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  531. struct drm_device *dev = encoder->base.dev;
  532. enum intel_display_power_domain power_domain;
  533. enum port port;
  534. bool ret;
  535. DRM_DEBUG_KMS("\n");
  536. power_domain = intel_display_port_power_domain(encoder);
  537. if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
  538. return false;
  539. ret = false;
  540. /* XXX: this only works for one DSI output */
  541. for_each_dsi_port(port, intel_dsi->ports) {
  542. i915_reg_t ctrl_reg = IS_BROXTON(dev) ?
  543. BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
  544. u32 dpi_enabled, func;
  545. func = I915_READ(MIPI_DSI_FUNC_PRG(port));
  546. dpi_enabled = I915_READ(ctrl_reg) & DPI_ENABLE;
  547. /* Due to some hardware limitations on BYT, MIPI Port C DPI
  548. * Enable bit does not get set. To check whether DSI Port C
  549. * was enabled in BIOS, check the Pipe B enable bit
  550. */
  551. if (IS_VALLEYVIEW(dev) && port == PORT_C)
  552. dpi_enabled = I915_READ(PIPECONF(PIPE_B)) &
  553. PIPECONF_ENABLE;
  554. if (dpi_enabled || (func & CMD_MODE_DATA_WIDTH_MASK)) {
  555. if (I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY) {
  556. *pipe = port == PORT_A ? PIPE_A : PIPE_B;
  557. ret = true;
  558. goto out;
  559. }
  560. }
  561. }
  562. out:
  563. intel_display_power_put(dev_priv, power_domain);
  564. return ret;
  565. }
  566. static void intel_dsi_get_config(struct intel_encoder *encoder,
  567. struct intel_crtc_state *pipe_config)
  568. {
  569. u32 pclk;
  570. DRM_DEBUG_KMS("\n");
  571. pipe_config->has_dsi_encoder = true;
  572. /*
  573. * DPLL_MD is not used in case of DSI, reading will get some default value
  574. * set dpll_md = 0
  575. */
  576. pipe_config->dpll_hw_state.dpll_md = 0;
  577. pclk = intel_dsi_get_pclk(encoder, pipe_config->pipe_bpp);
  578. if (!pclk)
  579. return;
  580. pipe_config->base.adjusted_mode.crtc_clock = pclk;
  581. pipe_config->port_clock = pclk;
  582. }
  583. static enum drm_mode_status
  584. intel_dsi_mode_valid(struct drm_connector *connector,
  585. struct drm_display_mode *mode)
  586. {
  587. struct intel_connector *intel_connector = to_intel_connector(connector);
  588. struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
  589. int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
  590. DRM_DEBUG_KMS("\n");
  591. if (mode->flags & DRM_MODE_FLAG_DBLSCAN) {
  592. DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n");
  593. return MODE_NO_DBLESCAN;
  594. }
  595. if (fixed_mode) {
  596. if (mode->hdisplay > fixed_mode->hdisplay)
  597. return MODE_PANEL;
  598. if (mode->vdisplay > fixed_mode->vdisplay)
  599. return MODE_PANEL;
  600. if (fixed_mode->clock > max_dotclk)
  601. return MODE_CLOCK_HIGH;
  602. }
  603. return MODE_OK;
  604. }
  605. /* return txclkesc cycles in terms of divider and duration in us */
  606. static u16 txclkesc(u32 divider, unsigned int us)
  607. {
  608. switch (divider) {
  609. case ESCAPE_CLOCK_DIVIDER_1:
  610. default:
  611. return 20 * us;
  612. case ESCAPE_CLOCK_DIVIDER_2:
  613. return 10 * us;
  614. case ESCAPE_CLOCK_DIVIDER_4:
  615. return 5 * us;
  616. }
  617. }
  618. /* return pixels in terms of txbyteclkhs */
  619. static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count,
  620. u16 burst_mode_ratio)
  621. {
  622. return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio,
  623. 8 * 100), lane_count);
  624. }
  625. static void set_dsi_timings(struct drm_encoder *encoder,
  626. const struct drm_display_mode *adjusted_mode)
  627. {
  628. struct drm_device *dev = encoder->dev;
  629. struct drm_i915_private *dev_priv = dev->dev_private;
  630. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  631. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  632. enum port port;
  633. unsigned int bpp = intel_crtc->config->pipe_bpp;
  634. unsigned int lane_count = intel_dsi->lane_count;
  635. u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
  636. hactive = adjusted_mode->crtc_hdisplay;
  637. hfp = adjusted_mode->crtc_hsync_start - adjusted_mode->crtc_hdisplay;
  638. hsync = adjusted_mode->crtc_hsync_end - adjusted_mode->crtc_hsync_start;
  639. hbp = adjusted_mode->crtc_htotal - adjusted_mode->crtc_hsync_end;
  640. if (intel_dsi->dual_link) {
  641. hactive /= 2;
  642. if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
  643. hactive += intel_dsi->pixel_overlap;
  644. hfp /= 2;
  645. hsync /= 2;
  646. hbp /= 2;
  647. }
  648. vfp = adjusted_mode->crtc_vsync_start - adjusted_mode->crtc_vdisplay;
  649. vsync = adjusted_mode->crtc_vsync_end - adjusted_mode->crtc_vsync_start;
  650. vbp = adjusted_mode->crtc_vtotal - adjusted_mode->crtc_vsync_end;
  651. /* horizontal values are in terms of high speed byte clock */
  652. hactive = txbyteclkhs(hactive, bpp, lane_count,
  653. intel_dsi->burst_mode_ratio);
  654. hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio);
  655. hsync = txbyteclkhs(hsync, bpp, lane_count,
  656. intel_dsi->burst_mode_ratio);
  657. hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio);
  658. for_each_dsi_port(port, intel_dsi->ports) {
  659. if (IS_BROXTON(dev)) {
  660. /*
  661. * Program hdisplay and vdisplay on MIPI transcoder.
  662. * This is different from calculated hactive and
  663. * vactive, as they are calculated per channel basis,
  664. * whereas these values should be based on resolution.
  665. */
  666. I915_WRITE(BXT_MIPI_TRANS_HACTIVE(port),
  667. adjusted_mode->crtc_hdisplay);
  668. I915_WRITE(BXT_MIPI_TRANS_VACTIVE(port),
  669. adjusted_mode->crtc_vdisplay);
  670. I915_WRITE(BXT_MIPI_TRANS_VTOTAL(port),
  671. adjusted_mode->crtc_vtotal);
  672. }
  673. I915_WRITE(MIPI_HACTIVE_AREA_COUNT(port), hactive);
  674. I915_WRITE(MIPI_HFP_COUNT(port), hfp);
  675. /* meaningful for video mode non-burst sync pulse mode only,
  676. * can be zero for non-burst sync events and burst modes */
  677. I915_WRITE(MIPI_HSYNC_PADDING_COUNT(port), hsync);
  678. I915_WRITE(MIPI_HBP_COUNT(port), hbp);
  679. /* vertical values are in terms of lines */
  680. I915_WRITE(MIPI_VFP_COUNT(port), vfp);
  681. I915_WRITE(MIPI_VSYNC_PADDING_COUNT(port), vsync);
  682. I915_WRITE(MIPI_VBP_COUNT(port), vbp);
  683. }
  684. }
  685. static void intel_dsi_prepare(struct intel_encoder *intel_encoder)
  686. {
  687. struct drm_encoder *encoder = &intel_encoder->base;
  688. struct drm_device *dev = encoder->dev;
  689. struct drm_i915_private *dev_priv = dev->dev_private;
  690. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  691. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  692. const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode;
  693. enum port port;
  694. unsigned int bpp = intel_crtc->config->pipe_bpp;
  695. u32 val, tmp;
  696. u16 mode_hdisplay;
  697. DRM_DEBUG_KMS("pipe %c\n", pipe_name(intel_crtc->pipe));
  698. mode_hdisplay = adjusted_mode->crtc_hdisplay;
  699. if (intel_dsi->dual_link) {
  700. mode_hdisplay /= 2;
  701. if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
  702. mode_hdisplay += intel_dsi->pixel_overlap;
  703. }
  704. for_each_dsi_port(port, intel_dsi->ports) {
  705. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
  706. /*
  707. * escape clock divider, 20MHz, shared for A and C.
  708. * device ready must be off when doing this! txclkesc?
  709. */
  710. tmp = I915_READ(MIPI_CTRL(PORT_A));
  711. tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
  712. I915_WRITE(MIPI_CTRL(PORT_A), tmp |
  713. ESCAPE_CLOCK_DIVIDER_1);
  714. /* read request priority is per pipe */
  715. tmp = I915_READ(MIPI_CTRL(port));
  716. tmp &= ~READ_REQUEST_PRIORITY_MASK;
  717. I915_WRITE(MIPI_CTRL(port), tmp |
  718. READ_REQUEST_PRIORITY_HIGH);
  719. } else if (IS_BROXTON(dev)) {
  720. enum pipe pipe = intel_crtc->pipe;
  721. tmp = I915_READ(MIPI_CTRL(port));
  722. tmp &= ~BXT_PIPE_SELECT_MASK;
  723. tmp |= BXT_PIPE_SELECT(pipe);
  724. I915_WRITE(MIPI_CTRL(port), tmp);
  725. }
  726. /* XXX: why here, why like this? handling in irq handler?! */
  727. I915_WRITE(MIPI_INTR_STAT(port), 0xffffffff);
  728. I915_WRITE(MIPI_INTR_EN(port), 0xffffffff);
  729. I915_WRITE(MIPI_DPHY_PARAM(port), intel_dsi->dphy_reg);
  730. I915_WRITE(MIPI_DPI_RESOLUTION(port),
  731. adjusted_mode->crtc_vdisplay << VERTICAL_ADDRESS_SHIFT |
  732. mode_hdisplay << HORIZONTAL_ADDRESS_SHIFT);
  733. }
  734. set_dsi_timings(encoder, adjusted_mode);
  735. val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
  736. if (is_cmd_mode(intel_dsi)) {
  737. val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
  738. val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
  739. } else {
  740. val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
  741. /* XXX: cross-check bpp vs. pixel format? */
  742. val |= intel_dsi->pixel_format;
  743. }
  744. tmp = 0;
  745. if (intel_dsi->eotp_pkt == 0)
  746. tmp |= EOT_DISABLE;
  747. if (intel_dsi->clock_stop)
  748. tmp |= CLOCKSTOP;
  749. for_each_dsi_port(port, intel_dsi->ports) {
  750. I915_WRITE(MIPI_DSI_FUNC_PRG(port), val);
  751. /* timeouts for recovery. one frame IIUC. if counter expires,
  752. * EOT and stop state. */
  753. /*
  754. * In burst mode, value greater than one DPI line Time in byte
  755. * clock (txbyteclkhs) To timeout this timer 1+ of the above
  756. * said value is recommended.
  757. *
  758. * In non-burst mode, Value greater than one DPI frame time in
  759. * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
  760. * said value is recommended.
  761. *
  762. * In DBI only mode, value greater than one DBI frame time in
  763. * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
  764. * said value is recommended.
  765. */
  766. if (is_vid_mode(intel_dsi) &&
  767. intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
  768. I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
  769. txbyteclkhs(adjusted_mode->crtc_htotal, bpp,
  770. intel_dsi->lane_count,
  771. intel_dsi->burst_mode_ratio) + 1);
  772. } else {
  773. I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
  774. txbyteclkhs(adjusted_mode->crtc_vtotal *
  775. adjusted_mode->crtc_htotal,
  776. bpp, intel_dsi->lane_count,
  777. intel_dsi->burst_mode_ratio) + 1);
  778. }
  779. I915_WRITE(MIPI_LP_RX_TIMEOUT(port), intel_dsi->lp_rx_timeout);
  780. I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(port),
  781. intel_dsi->turn_arnd_val);
  782. I915_WRITE(MIPI_DEVICE_RESET_TIMER(port),
  783. intel_dsi->rst_timer_val);
  784. /* dphy stuff */
  785. /* in terms of low power clock */
  786. I915_WRITE(MIPI_INIT_COUNT(port),
  787. txclkesc(intel_dsi->escape_clk_div, 100));
  788. if (IS_BROXTON(dev) && (!intel_dsi->dual_link)) {
  789. /*
  790. * BXT spec says write MIPI_INIT_COUNT for
  791. * both the ports, even if only one is
  792. * getting used. So write the other port
  793. * if not in dual link mode.
  794. */
  795. I915_WRITE(MIPI_INIT_COUNT(port ==
  796. PORT_A ? PORT_C : PORT_A),
  797. intel_dsi->init_count);
  798. }
  799. /* recovery disables */
  800. I915_WRITE(MIPI_EOT_DISABLE(port), tmp);
  801. /* in terms of low power clock */
  802. I915_WRITE(MIPI_INIT_COUNT(port), intel_dsi->init_count);
  803. /* in terms of txbyteclkhs. actual high to low switch +
  804. * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
  805. *
  806. * XXX: write MIPI_STOP_STATE_STALL?
  807. */
  808. I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(port),
  809. intel_dsi->hs_to_lp_count);
  810. /* XXX: low power clock equivalence in terms of byte clock.
  811. * the number of byte clocks occupied in one low power clock.
  812. * based on txbyteclkhs and txclkesc.
  813. * txclkesc time / txbyteclk time * (105 + MIPI_STOP_STATE_STALL
  814. * ) / 105.???
  815. */
  816. I915_WRITE(MIPI_LP_BYTECLK(port), intel_dsi->lp_byte_clk);
  817. /* the bw essential for transmitting 16 long packets containing
  818. * 252 bytes meant for dcs write memory command is programmed in
  819. * this register in terms of byte clocks. based on dsi transfer
  820. * rate and the number of lanes configured the time taken to
  821. * transmit 16 long packets in a dsi stream varies. */
  822. I915_WRITE(MIPI_DBI_BW_CTRL(port), intel_dsi->bw_timer);
  823. I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(port),
  824. intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT |
  825. intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT);
  826. if (is_vid_mode(intel_dsi))
  827. /* Some panels might have resolution which is not a
  828. * multiple of 64 like 1366 x 768. Enable RANDOM
  829. * resolution support for such panels by default */
  830. I915_WRITE(MIPI_VIDEO_MODE_FORMAT(port),
  831. intel_dsi->video_frmt_cfg_bits |
  832. intel_dsi->video_mode_format |
  833. IP_TG_CONFIG |
  834. RANDOM_DPI_DISPLAY_RESOLUTION);
  835. }
  836. }
  837. static enum drm_connector_status
  838. intel_dsi_detect(struct drm_connector *connector, bool force)
  839. {
  840. return connector_status_connected;
  841. }
  842. static int intel_dsi_get_modes(struct drm_connector *connector)
  843. {
  844. struct intel_connector *intel_connector = to_intel_connector(connector);
  845. struct drm_display_mode *mode;
  846. DRM_DEBUG_KMS("\n");
  847. if (!intel_connector->panel.fixed_mode) {
  848. DRM_DEBUG_KMS("no fixed mode\n");
  849. return 0;
  850. }
  851. mode = drm_mode_duplicate(connector->dev,
  852. intel_connector->panel.fixed_mode);
  853. if (!mode) {
  854. DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
  855. return 0;
  856. }
  857. drm_mode_probed_add(connector, mode);
  858. return 1;
  859. }
  860. static void intel_dsi_connector_destroy(struct drm_connector *connector)
  861. {
  862. struct intel_connector *intel_connector = to_intel_connector(connector);
  863. DRM_DEBUG_KMS("\n");
  864. intel_panel_fini(&intel_connector->panel);
  865. drm_connector_cleanup(connector);
  866. kfree(connector);
  867. }
  868. static void intel_dsi_encoder_destroy(struct drm_encoder *encoder)
  869. {
  870. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  871. if (intel_dsi->panel) {
  872. drm_panel_detach(intel_dsi->panel);
  873. /* XXX: Logically this call belongs in the panel driver. */
  874. drm_panel_remove(intel_dsi->panel);
  875. }
  876. /* dispose of the gpios */
  877. if (intel_dsi->gpio_panel)
  878. gpiod_put(intel_dsi->gpio_panel);
  879. intel_encoder_destroy(encoder);
  880. }
  881. static const struct drm_encoder_funcs intel_dsi_funcs = {
  882. .destroy = intel_dsi_encoder_destroy,
  883. };
  884. static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
  885. .get_modes = intel_dsi_get_modes,
  886. .mode_valid = intel_dsi_mode_valid,
  887. .best_encoder = intel_best_encoder,
  888. };
  889. static const struct drm_connector_funcs intel_dsi_connector_funcs = {
  890. .dpms = drm_atomic_helper_connector_dpms,
  891. .detect = intel_dsi_detect,
  892. .destroy = intel_dsi_connector_destroy,
  893. .fill_modes = drm_helper_probe_single_connector_modes,
  894. .atomic_get_property = intel_connector_atomic_get_property,
  895. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  896. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  897. };
  898. void intel_dsi_init(struct drm_device *dev)
  899. {
  900. struct intel_dsi *intel_dsi;
  901. struct intel_encoder *intel_encoder;
  902. struct drm_encoder *encoder;
  903. struct intel_connector *intel_connector;
  904. struct drm_connector *connector;
  905. struct drm_display_mode *scan, *fixed_mode = NULL;
  906. struct drm_i915_private *dev_priv = dev->dev_private;
  907. enum port port;
  908. unsigned int i;
  909. DRM_DEBUG_KMS("\n");
  910. /* There is no detection method for MIPI so rely on VBT */
  911. if (!dev_priv->vbt.has_mipi)
  912. return;
  913. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
  914. dev_priv->mipi_mmio_base = VLV_MIPI_BASE;
  915. } else {
  916. DRM_ERROR("Unsupported Mipi device to reg base");
  917. return;
  918. }
  919. intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
  920. if (!intel_dsi)
  921. return;
  922. intel_connector = intel_connector_alloc();
  923. if (!intel_connector) {
  924. kfree(intel_dsi);
  925. return;
  926. }
  927. intel_encoder = &intel_dsi->base;
  928. encoder = &intel_encoder->base;
  929. intel_dsi->attached_connector = intel_connector;
  930. connector = &intel_connector->base;
  931. drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI,
  932. NULL);
  933. intel_encoder->compute_config = intel_dsi_compute_config;
  934. intel_encoder->pre_enable = intel_dsi_pre_enable;
  935. intel_encoder->enable = intel_dsi_enable_nop;
  936. intel_encoder->disable = intel_dsi_pre_disable;
  937. intel_encoder->post_disable = intel_dsi_post_disable;
  938. intel_encoder->get_hw_state = intel_dsi_get_hw_state;
  939. intel_encoder->get_config = intel_dsi_get_config;
  940. intel_connector->get_hw_state = intel_connector_get_hw_state;
  941. intel_connector->unregister = intel_connector_unregister;
  942. /* Pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI port C */
  943. if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIA) {
  944. intel_encoder->crtc_mask = (1 << PIPE_A);
  945. intel_dsi->ports = (1 << PORT_A);
  946. } else if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIC) {
  947. intel_encoder->crtc_mask = (1 << PIPE_B);
  948. intel_dsi->ports = (1 << PORT_C);
  949. }
  950. if (dev_priv->vbt.dsi.config->dual_link)
  951. intel_dsi->ports = ((1 << PORT_A) | (1 << PORT_C));
  952. /* Create a DSI host (and a device) for each port. */
  953. for_each_dsi_port(port, intel_dsi->ports) {
  954. struct intel_dsi_host *host;
  955. host = intel_dsi_host_init(intel_dsi, port);
  956. if (!host)
  957. goto err;
  958. intel_dsi->dsi_hosts[port] = host;
  959. }
  960. for (i = 0; i < ARRAY_SIZE(intel_dsi_drivers); i++) {
  961. intel_dsi->panel = intel_dsi_drivers[i].init(intel_dsi,
  962. intel_dsi_drivers[i].panel_id);
  963. if (intel_dsi->panel)
  964. break;
  965. }
  966. if (!intel_dsi->panel) {
  967. DRM_DEBUG_KMS("no device found\n");
  968. goto err;
  969. }
  970. /*
  971. * In case of BYT with CRC PMIC, we need to use GPIO for
  972. * Panel control.
  973. */
  974. if (dev_priv->vbt.dsi.config->pwm_blc == PPS_BLC_PMIC) {
  975. intel_dsi->gpio_panel =
  976. gpiod_get(dev->dev, "panel", GPIOD_OUT_HIGH);
  977. if (IS_ERR(intel_dsi->gpio_panel)) {
  978. DRM_ERROR("Failed to own gpio for panel control\n");
  979. intel_dsi->gpio_panel = NULL;
  980. }
  981. }
  982. intel_encoder->type = INTEL_OUTPUT_DSI;
  983. intel_encoder->cloneable = 0;
  984. drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
  985. DRM_MODE_CONNECTOR_DSI);
  986. drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
  987. connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
  988. connector->interlace_allowed = false;
  989. connector->doublescan_allowed = false;
  990. intel_connector_attach_encoder(intel_connector, intel_encoder);
  991. drm_connector_register(connector);
  992. drm_panel_attach(intel_dsi->panel, connector);
  993. mutex_lock(&dev->mode_config.mutex);
  994. drm_panel_get_modes(intel_dsi->panel);
  995. list_for_each_entry(scan, &connector->probed_modes, head) {
  996. if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
  997. fixed_mode = drm_mode_duplicate(dev, scan);
  998. break;
  999. }
  1000. }
  1001. mutex_unlock(&dev->mode_config.mutex);
  1002. if (!fixed_mode) {
  1003. DRM_DEBUG_KMS("no fixed mode\n");
  1004. goto err;
  1005. }
  1006. intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
  1007. intel_panel_setup_backlight(connector, INVALID_PIPE);
  1008. return;
  1009. err:
  1010. drm_encoder_cleanup(&intel_encoder->base);
  1011. kfree(intel_dsi);
  1012. kfree(intel_connector);
  1013. }