intel_dsi.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254
  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. DRM_DEBUG_KMS("\n");
  513. intel_dsi_disable(encoder);
  514. intel_dsi_clear_device_ready(encoder);
  515. if (!IS_BROXTON(dev_priv)) {
  516. u32 val;
  517. val = I915_READ(DSPCLK_GATE_D);
  518. val &= ~DPOUNIT_CLOCK_GATE_DISABLE;
  519. I915_WRITE(DSPCLK_GATE_D, val);
  520. }
  521. drm_panel_unprepare(intel_dsi->panel);
  522. msleep(intel_dsi->panel_off_delay);
  523. msleep(intel_dsi->panel_pwr_cycle_delay);
  524. /* Panel Disable over CRC PMIC */
  525. if (intel_dsi->gpio_panel)
  526. gpiod_set_value_cansleep(intel_dsi->gpio_panel, 0);
  527. }
  528. static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
  529. enum pipe *pipe)
  530. {
  531. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  532. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  533. struct drm_device *dev = encoder->base.dev;
  534. enum intel_display_power_domain power_domain;
  535. enum port port;
  536. bool ret;
  537. DRM_DEBUG_KMS("\n");
  538. power_domain = intel_display_port_power_domain(encoder);
  539. if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
  540. return false;
  541. ret = false;
  542. /* XXX: this only works for one DSI output */
  543. for_each_dsi_port(port, intel_dsi->ports) {
  544. i915_reg_t ctrl_reg = IS_BROXTON(dev) ?
  545. BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
  546. u32 dpi_enabled, func;
  547. func = I915_READ(MIPI_DSI_FUNC_PRG(port));
  548. dpi_enabled = I915_READ(ctrl_reg) & DPI_ENABLE;
  549. /* Due to some hardware limitations on BYT, MIPI Port C DPI
  550. * Enable bit does not get set. To check whether DSI Port C
  551. * was enabled in BIOS, check the Pipe B enable bit
  552. */
  553. if (IS_VALLEYVIEW(dev) && port == PORT_C)
  554. dpi_enabled = I915_READ(PIPECONF(PIPE_B)) &
  555. PIPECONF_ENABLE;
  556. if (dpi_enabled || (func & CMD_MODE_DATA_WIDTH_MASK)) {
  557. if (I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY) {
  558. *pipe = port == PORT_A ? PIPE_A : PIPE_B;
  559. ret = true;
  560. goto out;
  561. }
  562. }
  563. }
  564. out:
  565. intel_display_power_put(dev_priv, power_domain);
  566. return ret;
  567. }
  568. static void intel_dsi_get_config(struct intel_encoder *encoder,
  569. struct intel_crtc_state *pipe_config)
  570. {
  571. u32 pclk;
  572. DRM_DEBUG_KMS("\n");
  573. pipe_config->has_dsi_encoder = true;
  574. /*
  575. * DPLL_MD is not used in case of DSI, reading will get some default value
  576. * set dpll_md = 0
  577. */
  578. pipe_config->dpll_hw_state.dpll_md = 0;
  579. pclk = intel_dsi_get_pclk(encoder, pipe_config->pipe_bpp);
  580. if (!pclk)
  581. return;
  582. pipe_config->base.adjusted_mode.crtc_clock = pclk;
  583. pipe_config->port_clock = pclk;
  584. }
  585. static enum drm_mode_status
  586. intel_dsi_mode_valid(struct drm_connector *connector,
  587. struct drm_display_mode *mode)
  588. {
  589. struct intel_connector *intel_connector = to_intel_connector(connector);
  590. struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
  591. int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
  592. DRM_DEBUG_KMS("\n");
  593. if (mode->flags & DRM_MODE_FLAG_DBLSCAN) {
  594. DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n");
  595. return MODE_NO_DBLESCAN;
  596. }
  597. if (fixed_mode) {
  598. if (mode->hdisplay > fixed_mode->hdisplay)
  599. return MODE_PANEL;
  600. if (mode->vdisplay > fixed_mode->vdisplay)
  601. return MODE_PANEL;
  602. if (fixed_mode->clock > max_dotclk)
  603. return MODE_CLOCK_HIGH;
  604. }
  605. return MODE_OK;
  606. }
  607. /* return txclkesc cycles in terms of divider and duration in us */
  608. static u16 txclkesc(u32 divider, unsigned int us)
  609. {
  610. switch (divider) {
  611. case ESCAPE_CLOCK_DIVIDER_1:
  612. default:
  613. return 20 * us;
  614. case ESCAPE_CLOCK_DIVIDER_2:
  615. return 10 * us;
  616. case ESCAPE_CLOCK_DIVIDER_4:
  617. return 5 * us;
  618. }
  619. }
  620. /* return pixels in terms of txbyteclkhs */
  621. static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count,
  622. u16 burst_mode_ratio)
  623. {
  624. return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio,
  625. 8 * 100), lane_count);
  626. }
  627. static void set_dsi_timings(struct drm_encoder *encoder,
  628. const struct drm_display_mode *adjusted_mode)
  629. {
  630. struct drm_device *dev = encoder->dev;
  631. struct drm_i915_private *dev_priv = dev->dev_private;
  632. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  633. enum port port;
  634. unsigned int bpp = dsi_pixel_format_bpp(intel_dsi->pixel_format);
  635. unsigned int lane_count = intel_dsi->lane_count;
  636. u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
  637. hactive = adjusted_mode->crtc_hdisplay;
  638. hfp = adjusted_mode->crtc_hsync_start - adjusted_mode->crtc_hdisplay;
  639. hsync = adjusted_mode->crtc_hsync_end - adjusted_mode->crtc_hsync_start;
  640. hbp = adjusted_mode->crtc_htotal - adjusted_mode->crtc_hsync_end;
  641. if (intel_dsi->dual_link) {
  642. hactive /= 2;
  643. if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
  644. hactive += intel_dsi->pixel_overlap;
  645. hfp /= 2;
  646. hsync /= 2;
  647. hbp /= 2;
  648. }
  649. vfp = adjusted_mode->crtc_vsync_start - adjusted_mode->crtc_vdisplay;
  650. vsync = adjusted_mode->crtc_vsync_end - adjusted_mode->crtc_vsync_start;
  651. vbp = adjusted_mode->crtc_vtotal - adjusted_mode->crtc_vsync_end;
  652. /* horizontal values are in terms of high speed byte clock */
  653. hactive = txbyteclkhs(hactive, bpp, lane_count,
  654. intel_dsi->burst_mode_ratio);
  655. hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio);
  656. hsync = txbyteclkhs(hsync, bpp, lane_count,
  657. intel_dsi->burst_mode_ratio);
  658. hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio);
  659. for_each_dsi_port(port, intel_dsi->ports) {
  660. if (IS_BROXTON(dev)) {
  661. /*
  662. * Program hdisplay and vdisplay on MIPI transcoder.
  663. * This is different from calculated hactive and
  664. * vactive, as they are calculated per channel basis,
  665. * whereas these values should be based on resolution.
  666. */
  667. I915_WRITE(BXT_MIPI_TRANS_HACTIVE(port),
  668. adjusted_mode->crtc_hdisplay);
  669. I915_WRITE(BXT_MIPI_TRANS_VACTIVE(port),
  670. adjusted_mode->crtc_vdisplay);
  671. I915_WRITE(BXT_MIPI_TRANS_VTOTAL(port),
  672. adjusted_mode->crtc_vtotal);
  673. }
  674. I915_WRITE(MIPI_HACTIVE_AREA_COUNT(port), hactive);
  675. I915_WRITE(MIPI_HFP_COUNT(port), hfp);
  676. /* meaningful for video mode non-burst sync pulse mode only,
  677. * can be zero for non-burst sync events and burst modes */
  678. I915_WRITE(MIPI_HSYNC_PADDING_COUNT(port), hsync);
  679. I915_WRITE(MIPI_HBP_COUNT(port), hbp);
  680. /* vertical values are in terms of lines */
  681. I915_WRITE(MIPI_VFP_COUNT(port), vfp);
  682. I915_WRITE(MIPI_VSYNC_PADDING_COUNT(port), vsync);
  683. I915_WRITE(MIPI_VBP_COUNT(port), vbp);
  684. }
  685. }
  686. static void intel_dsi_prepare(struct intel_encoder *intel_encoder)
  687. {
  688. struct drm_encoder *encoder = &intel_encoder->base;
  689. struct drm_device *dev = encoder->dev;
  690. struct drm_i915_private *dev_priv = dev->dev_private;
  691. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  692. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  693. const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode;
  694. enum port port;
  695. unsigned int bpp = dsi_pixel_format_bpp(intel_dsi->pixel_format);
  696. u32 val, tmp;
  697. u16 mode_hdisplay;
  698. DRM_DEBUG_KMS("pipe %c\n", pipe_name(intel_crtc->pipe));
  699. mode_hdisplay = adjusted_mode->crtc_hdisplay;
  700. if (intel_dsi->dual_link) {
  701. mode_hdisplay /= 2;
  702. if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
  703. mode_hdisplay += intel_dsi->pixel_overlap;
  704. }
  705. for_each_dsi_port(port, intel_dsi->ports) {
  706. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
  707. /*
  708. * escape clock divider, 20MHz, shared for A and C.
  709. * device ready must be off when doing this! txclkesc?
  710. */
  711. tmp = I915_READ(MIPI_CTRL(PORT_A));
  712. tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
  713. I915_WRITE(MIPI_CTRL(PORT_A), tmp |
  714. ESCAPE_CLOCK_DIVIDER_1);
  715. /* read request priority is per pipe */
  716. tmp = I915_READ(MIPI_CTRL(port));
  717. tmp &= ~READ_REQUEST_PRIORITY_MASK;
  718. I915_WRITE(MIPI_CTRL(port), tmp |
  719. READ_REQUEST_PRIORITY_HIGH);
  720. } else if (IS_BROXTON(dev)) {
  721. enum pipe pipe = intel_crtc->pipe;
  722. tmp = I915_READ(MIPI_CTRL(port));
  723. tmp &= ~BXT_PIPE_SELECT_MASK;
  724. tmp |= BXT_PIPE_SELECT(pipe);
  725. I915_WRITE(MIPI_CTRL(port), tmp);
  726. }
  727. /* XXX: why here, why like this? handling in irq handler?! */
  728. I915_WRITE(MIPI_INTR_STAT(port), 0xffffffff);
  729. I915_WRITE(MIPI_INTR_EN(port), 0xffffffff);
  730. I915_WRITE(MIPI_DPHY_PARAM(port), intel_dsi->dphy_reg);
  731. I915_WRITE(MIPI_DPI_RESOLUTION(port),
  732. adjusted_mode->crtc_vdisplay << VERTICAL_ADDRESS_SHIFT |
  733. mode_hdisplay << HORIZONTAL_ADDRESS_SHIFT);
  734. }
  735. set_dsi_timings(encoder, adjusted_mode);
  736. val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
  737. if (is_cmd_mode(intel_dsi)) {
  738. val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
  739. val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
  740. } else {
  741. val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
  742. /* XXX: cross-check bpp vs. pixel format? */
  743. val |= intel_dsi->pixel_format;
  744. }
  745. tmp = 0;
  746. if (intel_dsi->eotp_pkt == 0)
  747. tmp |= EOT_DISABLE;
  748. if (intel_dsi->clock_stop)
  749. tmp |= CLOCKSTOP;
  750. for_each_dsi_port(port, intel_dsi->ports) {
  751. I915_WRITE(MIPI_DSI_FUNC_PRG(port), val);
  752. /* timeouts for recovery. one frame IIUC. if counter expires,
  753. * EOT and stop state. */
  754. /*
  755. * In burst mode, value greater than one DPI line Time in byte
  756. * clock (txbyteclkhs) To timeout this timer 1+ of the above
  757. * said value is recommended.
  758. *
  759. * In non-burst mode, Value greater than one DPI frame time in
  760. * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
  761. * said value is recommended.
  762. *
  763. * In DBI only mode, value greater than one DBI frame time in
  764. * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
  765. * said value is recommended.
  766. */
  767. if (is_vid_mode(intel_dsi) &&
  768. intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
  769. I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
  770. txbyteclkhs(adjusted_mode->crtc_htotal, bpp,
  771. intel_dsi->lane_count,
  772. intel_dsi->burst_mode_ratio) + 1);
  773. } else {
  774. I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
  775. txbyteclkhs(adjusted_mode->crtc_vtotal *
  776. adjusted_mode->crtc_htotal,
  777. bpp, intel_dsi->lane_count,
  778. intel_dsi->burst_mode_ratio) + 1);
  779. }
  780. I915_WRITE(MIPI_LP_RX_TIMEOUT(port), intel_dsi->lp_rx_timeout);
  781. I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(port),
  782. intel_dsi->turn_arnd_val);
  783. I915_WRITE(MIPI_DEVICE_RESET_TIMER(port),
  784. intel_dsi->rst_timer_val);
  785. /* dphy stuff */
  786. /* in terms of low power clock */
  787. I915_WRITE(MIPI_INIT_COUNT(port),
  788. txclkesc(intel_dsi->escape_clk_div, 100));
  789. if (IS_BROXTON(dev) && (!intel_dsi->dual_link)) {
  790. /*
  791. * BXT spec says write MIPI_INIT_COUNT for
  792. * both the ports, even if only one is
  793. * getting used. So write the other port
  794. * if not in dual link mode.
  795. */
  796. I915_WRITE(MIPI_INIT_COUNT(port ==
  797. PORT_A ? PORT_C : PORT_A),
  798. intel_dsi->init_count);
  799. }
  800. /* recovery disables */
  801. I915_WRITE(MIPI_EOT_DISABLE(port), tmp);
  802. /* in terms of low power clock */
  803. I915_WRITE(MIPI_INIT_COUNT(port), intel_dsi->init_count);
  804. /* in terms of txbyteclkhs. actual high to low switch +
  805. * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
  806. *
  807. * XXX: write MIPI_STOP_STATE_STALL?
  808. */
  809. I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(port),
  810. intel_dsi->hs_to_lp_count);
  811. /* XXX: low power clock equivalence in terms of byte clock.
  812. * the number of byte clocks occupied in one low power clock.
  813. * based on txbyteclkhs and txclkesc.
  814. * txclkesc time / txbyteclk time * (105 + MIPI_STOP_STATE_STALL
  815. * ) / 105.???
  816. */
  817. I915_WRITE(MIPI_LP_BYTECLK(port), intel_dsi->lp_byte_clk);
  818. /* the bw essential for transmitting 16 long packets containing
  819. * 252 bytes meant for dcs write memory command is programmed in
  820. * this register in terms of byte clocks. based on dsi transfer
  821. * rate and the number of lanes configured the time taken to
  822. * transmit 16 long packets in a dsi stream varies. */
  823. I915_WRITE(MIPI_DBI_BW_CTRL(port), intel_dsi->bw_timer);
  824. I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(port),
  825. intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT |
  826. intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT);
  827. if (is_vid_mode(intel_dsi))
  828. /* Some panels might have resolution which is not a
  829. * multiple of 64 like 1366 x 768. Enable RANDOM
  830. * resolution support for such panels by default */
  831. I915_WRITE(MIPI_VIDEO_MODE_FORMAT(port),
  832. intel_dsi->video_frmt_cfg_bits |
  833. intel_dsi->video_mode_format |
  834. IP_TG_CONFIG |
  835. RANDOM_DPI_DISPLAY_RESOLUTION);
  836. }
  837. }
  838. static enum drm_connector_status
  839. intel_dsi_detect(struct drm_connector *connector, bool force)
  840. {
  841. return connector_status_connected;
  842. }
  843. static int intel_dsi_get_modes(struct drm_connector *connector)
  844. {
  845. struct intel_connector *intel_connector = to_intel_connector(connector);
  846. struct drm_display_mode *mode;
  847. DRM_DEBUG_KMS("\n");
  848. if (!intel_connector->panel.fixed_mode) {
  849. DRM_DEBUG_KMS("no fixed mode\n");
  850. return 0;
  851. }
  852. mode = drm_mode_duplicate(connector->dev,
  853. intel_connector->panel.fixed_mode);
  854. if (!mode) {
  855. DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
  856. return 0;
  857. }
  858. drm_mode_probed_add(connector, mode);
  859. return 1;
  860. }
  861. static void intel_dsi_connector_destroy(struct drm_connector *connector)
  862. {
  863. struct intel_connector *intel_connector = to_intel_connector(connector);
  864. DRM_DEBUG_KMS("\n");
  865. intel_panel_fini(&intel_connector->panel);
  866. drm_connector_cleanup(connector);
  867. kfree(connector);
  868. }
  869. static void intel_dsi_encoder_destroy(struct drm_encoder *encoder)
  870. {
  871. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  872. if (intel_dsi->panel) {
  873. drm_panel_detach(intel_dsi->panel);
  874. /* XXX: Logically this call belongs in the panel driver. */
  875. drm_panel_remove(intel_dsi->panel);
  876. }
  877. /* dispose of the gpios */
  878. if (intel_dsi->gpio_panel)
  879. gpiod_put(intel_dsi->gpio_panel);
  880. intel_encoder_destroy(encoder);
  881. }
  882. static const struct drm_encoder_funcs intel_dsi_funcs = {
  883. .destroy = intel_dsi_encoder_destroy,
  884. };
  885. static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
  886. .get_modes = intel_dsi_get_modes,
  887. .mode_valid = intel_dsi_mode_valid,
  888. .best_encoder = intel_best_encoder,
  889. };
  890. static const struct drm_connector_funcs intel_dsi_connector_funcs = {
  891. .dpms = drm_atomic_helper_connector_dpms,
  892. .detect = intel_dsi_detect,
  893. .destroy = intel_dsi_connector_destroy,
  894. .fill_modes = drm_helper_probe_single_connector_modes,
  895. .atomic_get_property = intel_connector_atomic_get_property,
  896. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  897. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  898. };
  899. void intel_dsi_init(struct drm_device *dev)
  900. {
  901. struct intel_dsi *intel_dsi;
  902. struct intel_encoder *intel_encoder;
  903. struct drm_encoder *encoder;
  904. struct intel_connector *intel_connector;
  905. struct drm_connector *connector;
  906. struct drm_display_mode *scan, *fixed_mode = NULL;
  907. struct drm_i915_private *dev_priv = dev->dev_private;
  908. enum port port;
  909. unsigned int i;
  910. DRM_DEBUG_KMS("\n");
  911. /* There is no detection method for MIPI so rely on VBT */
  912. if (!dev_priv->vbt.has_mipi)
  913. return;
  914. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
  915. dev_priv->mipi_mmio_base = VLV_MIPI_BASE;
  916. } else {
  917. DRM_ERROR("Unsupported Mipi device to reg base");
  918. return;
  919. }
  920. intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
  921. if (!intel_dsi)
  922. return;
  923. intel_connector = intel_connector_alloc();
  924. if (!intel_connector) {
  925. kfree(intel_dsi);
  926. return;
  927. }
  928. intel_encoder = &intel_dsi->base;
  929. encoder = &intel_encoder->base;
  930. intel_dsi->attached_connector = intel_connector;
  931. connector = &intel_connector->base;
  932. drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI,
  933. NULL);
  934. intel_encoder->compute_config = intel_dsi_compute_config;
  935. intel_encoder->pre_enable = intel_dsi_pre_enable;
  936. intel_encoder->enable = intel_dsi_enable_nop;
  937. intel_encoder->disable = intel_dsi_pre_disable;
  938. intel_encoder->post_disable = intel_dsi_post_disable;
  939. intel_encoder->get_hw_state = intel_dsi_get_hw_state;
  940. intel_encoder->get_config = intel_dsi_get_config;
  941. intel_connector->get_hw_state = intel_connector_get_hw_state;
  942. intel_connector->unregister = intel_connector_unregister;
  943. /* Pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI port C */
  944. if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIA) {
  945. intel_encoder->crtc_mask = (1 << PIPE_A);
  946. intel_dsi->ports = (1 << PORT_A);
  947. } else if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIC) {
  948. intel_encoder->crtc_mask = (1 << PIPE_B);
  949. intel_dsi->ports = (1 << PORT_C);
  950. }
  951. if (dev_priv->vbt.dsi.config->dual_link)
  952. intel_dsi->ports = ((1 << PORT_A) | (1 << PORT_C));
  953. /* Create a DSI host (and a device) for each port. */
  954. for_each_dsi_port(port, intel_dsi->ports) {
  955. struct intel_dsi_host *host;
  956. host = intel_dsi_host_init(intel_dsi, port);
  957. if (!host)
  958. goto err;
  959. intel_dsi->dsi_hosts[port] = host;
  960. }
  961. for (i = 0; i < ARRAY_SIZE(intel_dsi_drivers); i++) {
  962. intel_dsi->panel = intel_dsi_drivers[i].init(intel_dsi,
  963. intel_dsi_drivers[i].panel_id);
  964. if (intel_dsi->panel)
  965. break;
  966. }
  967. if (!intel_dsi->panel) {
  968. DRM_DEBUG_KMS("no device found\n");
  969. goto err;
  970. }
  971. /*
  972. * In case of BYT with CRC PMIC, we need to use GPIO for
  973. * Panel control.
  974. */
  975. if (dev_priv->vbt.dsi.config->pwm_blc == PPS_BLC_PMIC) {
  976. intel_dsi->gpio_panel =
  977. gpiod_get(dev->dev, "panel", GPIOD_OUT_HIGH);
  978. if (IS_ERR(intel_dsi->gpio_panel)) {
  979. DRM_ERROR("Failed to own gpio for panel control\n");
  980. intel_dsi->gpio_panel = NULL;
  981. }
  982. }
  983. intel_encoder->type = INTEL_OUTPUT_DSI;
  984. intel_encoder->cloneable = 0;
  985. drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
  986. DRM_MODE_CONNECTOR_DSI);
  987. drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
  988. connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
  989. connector->interlace_allowed = false;
  990. connector->doublescan_allowed = false;
  991. intel_connector_attach_encoder(intel_connector, intel_encoder);
  992. drm_connector_register(connector);
  993. drm_panel_attach(intel_dsi->panel, connector);
  994. mutex_lock(&dev->mode_config.mutex);
  995. drm_panel_get_modes(intel_dsi->panel);
  996. list_for_each_entry(scan, &connector->probed_modes, head) {
  997. if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
  998. fixed_mode = drm_mode_duplicate(dev, scan);
  999. break;
  1000. }
  1001. }
  1002. mutex_unlock(&dev->mode_config.mutex);
  1003. if (!fixed_mode) {
  1004. DRM_DEBUG_KMS("no fixed mode\n");
  1005. goto err;
  1006. }
  1007. intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
  1008. intel_panel_setup_backlight(connector, INVALID_PIPE);
  1009. return;
  1010. err:
  1011. drm_encoder_cleanup(&intel_encoder->base);
  1012. kfree(intel_dsi);
  1013. kfree(intel_connector);
  1014. }