intel_dsi.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  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. vlv_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. DRM_DEBUG_KMS("\n");
  529. if (mode->flags & DRM_MODE_FLAG_DBLSCAN) {
  530. DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n");
  531. return MODE_NO_DBLESCAN;
  532. }
  533. if (fixed_mode) {
  534. if (mode->hdisplay > fixed_mode->hdisplay)
  535. return MODE_PANEL;
  536. if (mode->vdisplay > fixed_mode->vdisplay)
  537. return MODE_PANEL;
  538. }
  539. return MODE_OK;
  540. }
  541. /* return txclkesc cycles in terms of divider and duration in us */
  542. static u16 txclkesc(u32 divider, unsigned int us)
  543. {
  544. switch (divider) {
  545. case ESCAPE_CLOCK_DIVIDER_1:
  546. default:
  547. return 20 * us;
  548. case ESCAPE_CLOCK_DIVIDER_2:
  549. return 10 * us;
  550. case ESCAPE_CLOCK_DIVIDER_4:
  551. return 5 * us;
  552. }
  553. }
  554. /* return pixels in terms of txbyteclkhs */
  555. static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count,
  556. u16 burst_mode_ratio)
  557. {
  558. return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio,
  559. 8 * 100), lane_count);
  560. }
  561. static void set_dsi_timings(struct drm_encoder *encoder,
  562. const struct drm_display_mode *mode)
  563. {
  564. struct drm_device *dev = encoder->dev;
  565. struct drm_i915_private *dev_priv = dev->dev_private;
  566. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  567. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  568. enum port port;
  569. unsigned int bpp = intel_crtc->config->pipe_bpp;
  570. unsigned int lane_count = intel_dsi->lane_count;
  571. u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
  572. hactive = mode->hdisplay;
  573. hfp = mode->hsync_start - mode->hdisplay;
  574. hsync = mode->hsync_end - mode->hsync_start;
  575. hbp = mode->htotal - mode->hsync_end;
  576. if (intel_dsi->dual_link) {
  577. hactive /= 2;
  578. if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
  579. hactive += intel_dsi->pixel_overlap;
  580. hfp /= 2;
  581. hsync /= 2;
  582. hbp /= 2;
  583. }
  584. vfp = mode->vsync_start - mode->vdisplay;
  585. vsync = mode->vsync_end - mode->vsync_start;
  586. vbp = mode->vtotal - mode->vsync_end;
  587. /* horizontal values are in terms of high speed byte clock */
  588. hactive = txbyteclkhs(hactive, bpp, lane_count,
  589. intel_dsi->burst_mode_ratio);
  590. hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio);
  591. hsync = txbyteclkhs(hsync, bpp, lane_count,
  592. intel_dsi->burst_mode_ratio);
  593. hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio);
  594. for_each_dsi_port(port, intel_dsi->ports) {
  595. I915_WRITE(MIPI_HACTIVE_AREA_COUNT(port), hactive);
  596. I915_WRITE(MIPI_HFP_COUNT(port), hfp);
  597. /* meaningful for video mode non-burst sync pulse mode only,
  598. * can be zero for non-burst sync events and burst modes */
  599. I915_WRITE(MIPI_HSYNC_PADDING_COUNT(port), hsync);
  600. I915_WRITE(MIPI_HBP_COUNT(port), hbp);
  601. /* vertical values are in terms of lines */
  602. I915_WRITE(MIPI_VFP_COUNT(port), vfp);
  603. I915_WRITE(MIPI_VSYNC_PADDING_COUNT(port), vsync);
  604. I915_WRITE(MIPI_VBP_COUNT(port), vbp);
  605. }
  606. }
  607. static void intel_dsi_prepare(struct intel_encoder *intel_encoder)
  608. {
  609. struct drm_encoder *encoder = &intel_encoder->base;
  610. struct drm_device *dev = encoder->dev;
  611. struct drm_i915_private *dev_priv = dev->dev_private;
  612. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  613. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  614. struct drm_display_mode *adjusted_mode =
  615. &intel_crtc->config->base.adjusted_mode;
  616. enum port port;
  617. unsigned int bpp = intel_crtc->config->pipe_bpp;
  618. u32 val, tmp;
  619. u16 mode_hdisplay;
  620. DRM_DEBUG_KMS("pipe %c\n", pipe_name(intel_crtc->pipe));
  621. mode_hdisplay = adjusted_mode->hdisplay;
  622. if (intel_dsi->dual_link) {
  623. mode_hdisplay /= 2;
  624. if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
  625. mode_hdisplay += intel_dsi->pixel_overlap;
  626. }
  627. for_each_dsi_port(port, intel_dsi->ports) {
  628. /* escape clock divider, 20MHz, shared for A and C.
  629. * device ready must be off when doing this! txclkesc? */
  630. tmp = I915_READ(MIPI_CTRL(PORT_A));
  631. tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
  632. I915_WRITE(MIPI_CTRL(PORT_A), tmp | ESCAPE_CLOCK_DIVIDER_1);
  633. /* read request priority is per pipe */
  634. tmp = I915_READ(MIPI_CTRL(port));
  635. tmp &= ~READ_REQUEST_PRIORITY_MASK;
  636. I915_WRITE(MIPI_CTRL(port), tmp | READ_REQUEST_PRIORITY_HIGH);
  637. /* XXX: why here, why like this? handling in irq handler?! */
  638. I915_WRITE(MIPI_INTR_STAT(port), 0xffffffff);
  639. I915_WRITE(MIPI_INTR_EN(port), 0xffffffff);
  640. I915_WRITE(MIPI_DPHY_PARAM(port), intel_dsi->dphy_reg);
  641. I915_WRITE(MIPI_DPI_RESOLUTION(port),
  642. adjusted_mode->vdisplay << VERTICAL_ADDRESS_SHIFT |
  643. mode_hdisplay << HORIZONTAL_ADDRESS_SHIFT);
  644. }
  645. set_dsi_timings(encoder, adjusted_mode);
  646. val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
  647. if (is_cmd_mode(intel_dsi)) {
  648. val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
  649. val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
  650. } else {
  651. val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
  652. /* XXX: cross-check bpp vs. pixel format? */
  653. val |= intel_dsi->pixel_format;
  654. }
  655. tmp = 0;
  656. if (intel_dsi->eotp_pkt == 0)
  657. tmp |= EOT_DISABLE;
  658. if (intel_dsi->clock_stop)
  659. tmp |= CLOCKSTOP;
  660. for_each_dsi_port(port, intel_dsi->ports) {
  661. I915_WRITE(MIPI_DSI_FUNC_PRG(port), val);
  662. /* timeouts for recovery. one frame IIUC. if counter expires,
  663. * EOT and stop state. */
  664. /*
  665. * In burst mode, value greater than one DPI line Time in byte
  666. * clock (txbyteclkhs) To timeout this timer 1+ of the above
  667. * said value is recommended.
  668. *
  669. * In non-burst mode, Value greater than one DPI frame time in
  670. * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
  671. * said value is recommended.
  672. *
  673. * In DBI only mode, value greater than one DBI frame time in
  674. * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
  675. * said value is recommended.
  676. */
  677. if (is_vid_mode(intel_dsi) &&
  678. intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
  679. I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
  680. txbyteclkhs(adjusted_mode->htotal, bpp,
  681. intel_dsi->lane_count,
  682. intel_dsi->burst_mode_ratio) + 1);
  683. } else {
  684. I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
  685. txbyteclkhs(adjusted_mode->vtotal *
  686. adjusted_mode->htotal,
  687. bpp, intel_dsi->lane_count,
  688. intel_dsi->burst_mode_ratio) + 1);
  689. }
  690. I915_WRITE(MIPI_LP_RX_TIMEOUT(port), intel_dsi->lp_rx_timeout);
  691. I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(port),
  692. intel_dsi->turn_arnd_val);
  693. I915_WRITE(MIPI_DEVICE_RESET_TIMER(port),
  694. intel_dsi->rst_timer_val);
  695. /* dphy stuff */
  696. /* in terms of low power clock */
  697. I915_WRITE(MIPI_INIT_COUNT(port),
  698. txclkesc(intel_dsi->escape_clk_div, 100));
  699. /* recovery disables */
  700. I915_WRITE(MIPI_EOT_DISABLE(port), tmp);
  701. /* in terms of low power clock */
  702. I915_WRITE(MIPI_INIT_COUNT(port), intel_dsi->init_count);
  703. /* in terms of txbyteclkhs. actual high to low switch +
  704. * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
  705. *
  706. * XXX: write MIPI_STOP_STATE_STALL?
  707. */
  708. I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(port),
  709. intel_dsi->hs_to_lp_count);
  710. /* XXX: low power clock equivalence in terms of byte clock.
  711. * the number of byte clocks occupied in one low power clock.
  712. * based on txbyteclkhs and txclkesc.
  713. * txclkesc time / txbyteclk time * (105 + MIPI_STOP_STATE_STALL
  714. * ) / 105.???
  715. */
  716. I915_WRITE(MIPI_LP_BYTECLK(port), intel_dsi->lp_byte_clk);
  717. /* the bw essential for transmitting 16 long packets containing
  718. * 252 bytes meant for dcs write memory command is programmed in
  719. * this register in terms of byte clocks. based on dsi transfer
  720. * rate and the number of lanes configured the time taken to
  721. * transmit 16 long packets in a dsi stream varies. */
  722. I915_WRITE(MIPI_DBI_BW_CTRL(port), intel_dsi->bw_timer);
  723. I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(port),
  724. intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT |
  725. intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT);
  726. if (is_vid_mode(intel_dsi))
  727. /* Some panels might have resolution which is not a
  728. * multiple of 64 like 1366 x 768. Enable RANDOM
  729. * resolution support for such panels by default */
  730. I915_WRITE(MIPI_VIDEO_MODE_FORMAT(port),
  731. intel_dsi->video_frmt_cfg_bits |
  732. intel_dsi->video_mode_format |
  733. IP_TG_CONFIG |
  734. RANDOM_DPI_DISPLAY_RESOLUTION);
  735. }
  736. }
  737. static void intel_dsi_pre_pll_enable(struct intel_encoder *encoder)
  738. {
  739. DRM_DEBUG_KMS("\n");
  740. intel_dsi_prepare(encoder);
  741. vlv_enable_dsi_pll(encoder);
  742. }
  743. static enum drm_connector_status
  744. intel_dsi_detect(struct drm_connector *connector, bool force)
  745. {
  746. return connector_status_connected;
  747. }
  748. static int intel_dsi_get_modes(struct drm_connector *connector)
  749. {
  750. struct intel_connector *intel_connector = to_intel_connector(connector);
  751. struct drm_display_mode *mode;
  752. DRM_DEBUG_KMS("\n");
  753. if (!intel_connector->panel.fixed_mode) {
  754. DRM_DEBUG_KMS("no fixed mode\n");
  755. return 0;
  756. }
  757. mode = drm_mode_duplicate(connector->dev,
  758. intel_connector->panel.fixed_mode);
  759. if (!mode) {
  760. DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
  761. return 0;
  762. }
  763. drm_mode_probed_add(connector, mode);
  764. return 1;
  765. }
  766. static void intel_dsi_connector_destroy(struct drm_connector *connector)
  767. {
  768. struct intel_connector *intel_connector = to_intel_connector(connector);
  769. DRM_DEBUG_KMS("\n");
  770. intel_panel_fini(&intel_connector->panel);
  771. drm_connector_cleanup(connector);
  772. kfree(connector);
  773. }
  774. static void intel_dsi_encoder_destroy(struct drm_encoder *encoder)
  775. {
  776. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  777. if (intel_dsi->panel) {
  778. drm_panel_detach(intel_dsi->panel);
  779. /* XXX: Logically this call belongs in the panel driver. */
  780. drm_panel_remove(intel_dsi->panel);
  781. }
  782. /* dispose of the gpios */
  783. if (intel_dsi->gpio_panel)
  784. gpiod_put(intel_dsi->gpio_panel);
  785. intel_encoder_destroy(encoder);
  786. }
  787. static const struct drm_encoder_funcs intel_dsi_funcs = {
  788. .destroy = intel_dsi_encoder_destroy,
  789. };
  790. static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
  791. .get_modes = intel_dsi_get_modes,
  792. .mode_valid = intel_dsi_mode_valid,
  793. .best_encoder = intel_best_encoder,
  794. };
  795. static const struct drm_connector_funcs intel_dsi_connector_funcs = {
  796. .dpms = drm_atomic_helper_connector_dpms,
  797. .detect = intel_dsi_detect,
  798. .destroy = intel_dsi_connector_destroy,
  799. .fill_modes = drm_helper_probe_single_connector_modes,
  800. .atomic_get_property = intel_connector_atomic_get_property,
  801. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  802. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  803. };
  804. void intel_dsi_init(struct drm_device *dev)
  805. {
  806. struct intel_dsi *intel_dsi;
  807. struct intel_encoder *intel_encoder;
  808. struct drm_encoder *encoder;
  809. struct intel_connector *intel_connector;
  810. struct drm_connector *connector;
  811. struct drm_display_mode *scan, *fixed_mode = NULL;
  812. struct drm_i915_private *dev_priv = dev->dev_private;
  813. enum port port;
  814. unsigned int i;
  815. DRM_DEBUG_KMS("\n");
  816. /* There is no detection method for MIPI so rely on VBT */
  817. if (!dev_priv->vbt.has_mipi)
  818. return;
  819. if (IS_VALLEYVIEW(dev)) {
  820. dev_priv->mipi_mmio_base = VLV_MIPI_BASE;
  821. } else {
  822. DRM_ERROR("Unsupported Mipi device to reg base");
  823. return;
  824. }
  825. intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
  826. if (!intel_dsi)
  827. return;
  828. intel_connector = intel_connector_alloc();
  829. if (!intel_connector) {
  830. kfree(intel_dsi);
  831. return;
  832. }
  833. intel_encoder = &intel_dsi->base;
  834. encoder = &intel_encoder->base;
  835. intel_dsi->attached_connector = intel_connector;
  836. connector = &intel_connector->base;
  837. drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI);
  838. /* XXX: very likely not all of these are needed */
  839. intel_encoder->compute_config = intel_dsi_compute_config;
  840. intel_encoder->pre_pll_enable = intel_dsi_pre_pll_enable;
  841. intel_encoder->pre_enable = intel_dsi_pre_enable;
  842. intel_encoder->enable = intel_dsi_enable_nop;
  843. intel_encoder->disable = intel_dsi_pre_disable;
  844. intel_encoder->post_disable = intel_dsi_post_disable;
  845. intel_encoder->get_hw_state = intel_dsi_get_hw_state;
  846. intel_encoder->get_config = intel_dsi_get_config;
  847. intel_connector->get_hw_state = intel_connector_get_hw_state;
  848. intel_connector->unregister = intel_connector_unregister;
  849. /* Pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI port C */
  850. if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIA) {
  851. intel_encoder->crtc_mask = (1 << PIPE_A);
  852. intel_dsi->ports = (1 << PORT_A);
  853. } else if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIC) {
  854. intel_encoder->crtc_mask = (1 << PIPE_B);
  855. intel_dsi->ports = (1 << PORT_C);
  856. }
  857. if (dev_priv->vbt.dsi.config->dual_link)
  858. intel_dsi->ports = ((1 << PORT_A) | (1 << PORT_C));
  859. /* Create a DSI host (and a device) for each port. */
  860. for_each_dsi_port(port, intel_dsi->ports) {
  861. struct intel_dsi_host *host;
  862. host = intel_dsi_host_init(intel_dsi, port);
  863. if (!host)
  864. goto err;
  865. intel_dsi->dsi_hosts[port] = host;
  866. }
  867. for (i = 0; i < ARRAY_SIZE(intel_dsi_drivers); i++) {
  868. intel_dsi->panel = intel_dsi_drivers[i].init(intel_dsi,
  869. intel_dsi_drivers[i].panel_id);
  870. if (intel_dsi->panel)
  871. break;
  872. }
  873. if (!intel_dsi->panel) {
  874. DRM_DEBUG_KMS("no device found\n");
  875. goto err;
  876. }
  877. /*
  878. * In case of BYT with CRC PMIC, we need to use GPIO for
  879. * Panel control.
  880. */
  881. if (dev_priv->vbt.dsi.config->pwm_blc == PPS_BLC_PMIC) {
  882. intel_dsi->gpio_panel =
  883. gpiod_get(dev->dev, "panel", GPIOD_OUT_HIGH);
  884. if (IS_ERR(intel_dsi->gpio_panel)) {
  885. DRM_ERROR("Failed to own gpio for panel control\n");
  886. intel_dsi->gpio_panel = NULL;
  887. }
  888. }
  889. intel_encoder->type = INTEL_OUTPUT_DSI;
  890. intel_encoder->cloneable = 0;
  891. drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
  892. DRM_MODE_CONNECTOR_DSI);
  893. drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
  894. connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
  895. connector->interlace_allowed = false;
  896. connector->doublescan_allowed = false;
  897. intel_connector_attach_encoder(intel_connector, intel_encoder);
  898. drm_connector_register(connector);
  899. drm_panel_attach(intel_dsi->panel, connector);
  900. mutex_lock(&dev->mode_config.mutex);
  901. drm_panel_get_modes(intel_dsi->panel);
  902. list_for_each_entry(scan, &connector->probed_modes, head) {
  903. if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
  904. fixed_mode = drm_mode_duplicate(dev, scan);
  905. break;
  906. }
  907. }
  908. mutex_unlock(&dev->mode_config.mutex);
  909. if (!fixed_mode) {
  910. DRM_DEBUG_KMS("no fixed mode\n");
  911. goto err;
  912. }
  913. intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
  914. intel_panel_setup_backlight(connector, INVALID_PIPE);
  915. return;
  916. err:
  917. drm_encoder_cleanup(&intel_encoder->base);
  918. kfree(intel_dsi);
  919. kfree(intel_connector);
  920. }