intel_dsi.c 34 KB

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