intel_dsi.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  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_crtc.h>
  27. #include <drm/drm_edid.h>
  28. #include <drm/i915_drm.h>
  29. #include <linux/slab.h>
  30. #include "i915_drv.h"
  31. #include "intel_drv.h"
  32. #include "intel_dsi.h"
  33. #include "intel_dsi_cmd.h"
  34. /* the sub-encoders aka panel drivers */
  35. static const struct intel_dsi_device intel_dsi_devices[] = {
  36. };
  37. static void vlv_cck_modify(struct drm_i915_private *dev_priv, u32 reg, u32 val,
  38. u32 mask)
  39. {
  40. u32 tmp = vlv_cck_read(dev_priv, reg);
  41. tmp &= ~mask;
  42. tmp |= val;
  43. vlv_cck_write(dev_priv, reg, tmp);
  44. }
  45. static void band_gap_wa(struct drm_i915_private *dev_priv)
  46. {
  47. mutex_lock(&dev_priv->dpio_lock);
  48. /* Enable bandgap fix in GOP driver */
  49. vlv_cck_modify(dev_priv, 0x6D, 0x00010000, 0x00030000);
  50. msleep(20);
  51. vlv_cck_modify(dev_priv, 0x6E, 0x00010000, 0x00030000);
  52. msleep(20);
  53. vlv_cck_modify(dev_priv, 0x6F, 0x00010000, 0x00030000);
  54. msleep(20);
  55. vlv_cck_modify(dev_priv, 0x00, 0x00008000, 0x00008000);
  56. msleep(20);
  57. vlv_cck_modify(dev_priv, 0x00, 0x00000000, 0x00008000);
  58. msleep(20);
  59. /* Turn Display Trunk on */
  60. vlv_cck_modify(dev_priv, 0x6B, 0x00020000, 0x00030000);
  61. msleep(20);
  62. vlv_cck_modify(dev_priv, 0x6C, 0x00020000, 0x00030000);
  63. msleep(20);
  64. vlv_cck_modify(dev_priv, 0x6D, 0x00020000, 0x00030000);
  65. msleep(20);
  66. vlv_cck_modify(dev_priv, 0x6E, 0x00020000, 0x00030000);
  67. msleep(20);
  68. vlv_cck_modify(dev_priv, 0x6F, 0x00020000, 0x00030000);
  69. mutex_unlock(&dev_priv->dpio_lock);
  70. /* Need huge delay, otherwise clock is not stable */
  71. msleep(100);
  72. }
  73. static struct intel_dsi *intel_attached_dsi(struct drm_connector *connector)
  74. {
  75. return container_of(intel_attached_encoder(connector),
  76. struct intel_dsi, base);
  77. }
  78. static inline bool is_vid_mode(struct intel_dsi *intel_dsi)
  79. {
  80. return intel_dsi->dev.type == INTEL_DSI_VIDEO_MODE;
  81. }
  82. static inline bool is_cmd_mode(struct intel_dsi *intel_dsi)
  83. {
  84. return intel_dsi->dev.type == INTEL_DSI_COMMAND_MODE;
  85. }
  86. static void intel_dsi_hot_plug(struct intel_encoder *encoder)
  87. {
  88. DRM_DEBUG_KMS("\n");
  89. }
  90. static bool intel_dsi_compute_config(struct intel_encoder *encoder,
  91. struct intel_crtc_config *config)
  92. {
  93. struct intel_dsi *intel_dsi = container_of(encoder, struct intel_dsi,
  94. base);
  95. struct intel_connector *intel_connector = intel_dsi->attached_connector;
  96. struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
  97. struct drm_display_mode *adjusted_mode = &config->adjusted_mode;
  98. struct drm_display_mode *mode = &config->requested_mode;
  99. DRM_DEBUG_KMS("\n");
  100. if (fixed_mode)
  101. intel_fixed_panel_mode(fixed_mode, adjusted_mode);
  102. if (intel_dsi->dev.dev_ops->mode_fixup)
  103. return intel_dsi->dev.dev_ops->mode_fixup(&intel_dsi->dev,
  104. mode, adjusted_mode);
  105. return true;
  106. }
  107. static void intel_dsi_pre_pll_enable(struct intel_encoder *encoder)
  108. {
  109. DRM_DEBUG_KMS("\n");
  110. vlv_enable_dsi_pll(encoder);
  111. }
  112. static void intel_dsi_pre_enable(struct intel_encoder *encoder)
  113. {
  114. DRM_DEBUG_KMS("\n");
  115. }
  116. static void intel_dsi_enable(struct intel_encoder *encoder)
  117. {
  118. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  119. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  120. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  121. int pipe = intel_crtc->pipe;
  122. u32 temp;
  123. DRM_DEBUG_KMS("\n");
  124. temp = I915_READ(MIPI_DEVICE_READY(pipe));
  125. if ((temp & DEVICE_READY) == 0) {
  126. temp &= ~ULPS_STATE_MASK;
  127. I915_WRITE(MIPI_DEVICE_READY(pipe), temp | DEVICE_READY);
  128. } else if (temp & ULPS_STATE_MASK) {
  129. temp &= ~ULPS_STATE_MASK;
  130. I915_WRITE(MIPI_DEVICE_READY(pipe), temp | ULPS_STATE_EXIT);
  131. /*
  132. * We need to ensure that there is a minimum of 1 ms time
  133. * available before clearing the UPLS exit state.
  134. */
  135. msleep(2);
  136. I915_WRITE(MIPI_DEVICE_READY(pipe), temp);
  137. }
  138. if (is_cmd_mode(intel_dsi))
  139. I915_WRITE(MIPI_MAX_RETURN_PKT_SIZE(pipe), 8 * 4);
  140. if (is_vid_mode(intel_dsi)) {
  141. msleep(20); /* XXX */
  142. dpi_send_cmd(intel_dsi, TURN_ON);
  143. msleep(100);
  144. /* assert ip_tg_enable signal */
  145. temp = I915_READ(MIPI_PORT_CTRL(pipe));
  146. I915_WRITE(MIPI_PORT_CTRL(pipe), temp | DPI_ENABLE);
  147. POSTING_READ(MIPI_PORT_CTRL(pipe));
  148. }
  149. intel_dsi->dev.dev_ops->enable(&intel_dsi->dev);
  150. }
  151. static void intel_dsi_disable(struct intel_encoder *encoder)
  152. {
  153. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  154. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  155. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  156. int pipe = intel_crtc->pipe;
  157. u32 temp;
  158. DRM_DEBUG_KMS("\n");
  159. intel_dsi->dev.dev_ops->disable(&intel_dsi->dev);
  160. if (is_vid_mode(intel_dsi)) {
  161. dpi_send_cmd(intel_dsi, SHUTDOWN);
  162. msleep(10);
  163. /* de-assert ip_tg_enable signal */
  164. temp = I915_READ(MIPI_PORT_CTRL(pipe));
  165. I915_WRITE(MIPI_PORT_CTRL(pipe), temp & ~DPI_ENABLE);
  166. POSTING_READ(MIPI_PORT_CTRL(pipe));
  167. msleep(2);
  168. }
  169. temp = I915_READ(MIPI_DEVICE_READY(pipe));
  170. if (temp & DEVICE_READY) {
  171. temp &= ~DEVICE_READY;
  172. temp &= ~ULPS_STATE_MASK;
  173. I915_WRITE(MIPI_DEVICE_READY(pipe), temp);
  174. }
  175. }
  176. static void intel_dsi_post_disable(struct intel_encoder *encoder)
  177. {
  178. DRM_DEBUG_KMS("\n");
  179. vlv_disable_dsi_pll(encoder);
  180. }
  181. static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
  182. enum pipe *pipe)
  183. {
  184. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  185. u32 port, func;
  186. enum pipe p;
  187. DRM_DEBUG_KMS("\n");
  188. /* XXX: this only works for one DSI output */
  189. for (p = PIPE_A; p <= PIPE_B; p++) {
  190. port = I915_READ(MIPI_PORT_CTRL(p));
  191. func = I915_READ(MIPI_DSI_FUNC_PRG(p));
  192. if ((port & DPI_ENABLE) || (func & CMD_MODE_DATA_WIDTH_MASK)) {
  193. if (I915_READ(MIPI_DEVICE_READY(p)) & DEVICE_READY) {
  194. *pipe = p;
  195. return true;
  196. }
  197. }
  198. }
  199. return false;
  200. }
  201. static void intel_dsi_get_config(struct intel_encoder *encoder,
  202. struct intel_crtc_config *pipe_config)
  203. {
  204. DRM_DEBUG_KMS("\n");
  205. /* XXX: read flags, set to adjusted_mode */
  206. }
  207. static int intel_dsi_mode_valid(struct drm_connector *connector,
  208. struct drm_display_mode *mode)
  209. {
  210. struct intel_connector *intel_connector = to_intel_connector(connector);
  211. struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
  212. struct intel_dsi *intel_dsi = intel_attached_dsi(connector);
  213. DRM_DEBUG_KMS("\n");
  214. if (mode->flags & DRM_MODE_FLAG_DBLSCAN) {
  215. DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n");
  216. return MODE_NO_DBLESCAN;
  217. }
  218. if (fixed_mode) {
  219. if (mode->hdisplay > fixed_mode->hdisplay)
  220. return MODE_PANEL;
  221. if (mode->vdisplay > fixed_mode->vdisplay)
  222. return MODE_PANEL;
  223. }
  224. return intel_dsi->dev.dev_ops->mode_valid(&intel_dsi->dev, mode);
  225. }
  226. /* return txclkesc cycles in terms of divider and duration in us */
  227. static u16 txclkesc(u32 divider, unsigned int us)
  228. {
  229. switch (divider) {
  230. case ESCAPE_CLOCK_DIVIDER_1:
  231. default:
  232. return 20 * us;
  233. case ESCAPE_CLOCK_DIVIDER_2:
  234. return 10 * us;
  235. case ESCAPE_CLOCK_DIVIDER_4:
  236. return 5 * us;
  237. }
  238. }
  239. /* return pixels in terms of txbyteclkhs */
  240. static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count)
  241. {
  242. return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp, 8), lane_count);
  243. }
  244. static void set_dsi_timings(struct drm_encoder *encoder,
  245. const struct drm_display_mode *mode)
  246. {
  247. struct drm_device *dev = encoder->dev;
  248. struct drm_i915_private *dev_priv = dev->dev_private;
  249. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  250. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  251. int pipe = intel_crtc->pipe;
  252. unsigned int bpp = intel_crtc->config.pipe_bpp;
  253. unsigned int lane_count = intel_dsi->lane_count;
  254. u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
  255. hactive = mode->hdisplay;
  256. hfp = mode->hsync_start - mode->hdisplay;
  257. hsync = mode->hsync_end - mode->hsync_start;
  258. hbp = mode->htotal - mode->hsync_end;
  259. vfp = mode->vsync_start - mode->vdisplay;
  260. vsync = mode->vsync_end - mode->vsync_start;
  261. vbp = mode->vtotal - mode->vsync_end;
  262. /* horizontal values are in terms of high speed byte clock */
  263. hactive = txbyteclkhs(hactive, bpp, lane_count);
  264. hfp = txbyteclkhs(hfp, bpp, lane_count);
  265. hsync = txbyteclkhs(hsync, bpp, lane_count);
  266. hbp = txbyteclkhs(hbp, bpp, lane_count);
  267. I915_WRITE(MIPI_HACTIVE_AREA_COUNT(pipe), hactive);
  268. I915_WRITE(MIPI_HFP_COUNT(pipe), hfp);
  269. /* meaningful for video mode non-burst sync pulse mode only, can be zero
  270. * for non-burst sync events and burst modes */
  271. I915_WRITE(MIPI_HSYNC_PADDING_COUNT(pipe), hsync);
  272. I915_WRITE(MIPI_HBP_COUNT(pipe), hbp);
  273. /* vertical values are in terms of lines */
  274. I915_WRITE(MIPI_VFP_COUNT(pipe), vfp);
  275. I915_WRITE(MIPI_VSYNC_PADDING_COUNT(pipe), vsync);
  276. I915_WRITE(MIPI_VBP_COUNT(pipe), vbp);
  277. }
  278. static void intel_dsi_mode_set(struct intel_encoder *intel_encoder)
  279. {
  280. struct drm_encoder *encoder = &intel_encoder->base;
  281. struct drm_device *dev = encoder->dev;
  282. struct drm_i915_private *dev_priv = dev->dev_private;
  283. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  284. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  285. struct drm_display_mode *adjusted_mode =
  286. &intel_crtc->config.adjusted_mode;
  287. int pipe = intel_crtc->pipe;
  288. unsigned int bpp = intel_crtc->config.pipe_bpp;
  289. u32 val, tmp;
  290. DRM_DEBUG_KMS("pipe %d\n", pipe);
  291. /* Update the DSI PLL */
  292. vlv_enable_dsi_pll(intel_encoder);
  293. /* XXX: Location of the call */
  294. band_gap_wa(dev_priv);
  295. /* escape clock divider, 20MHz, shared for A and C. device ready must be
  296. * off when doing this! txclkesc? */
  297. tmp = I915_READ(MIPI_CTRL(0));
  298. tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
  299. I915_WRITE(MIPI_CTRL(0), tmp | ESCAPE_CLOCK_DIVIDER_1);
  300. /* read request priority is per pipe */
  301. tmp = I915_READ(MIPI_CTRL(pipe));
  302. tmp &= ~READ_REQUEST_PRIORITY_MASK;
  303. I915_WRITE(MIPI_CTRL(pipe), tmp | READ_REQUEST_PRIORITY_HIGH);
  304. /* XXX: why here, why like this? handling in irq handler?! */
  305. I915_WRITE(MIPI_INTR_STAT(pipe), 0xffffffff);
  306. I915_WRITE(MIPI_INTR_EN(pipe), 0xffffffff);
  307. I915_WRITE(MIPI_DPHY_PARAM(pipe),
  308. 0x3c << EXIT_ZERO_COUNT_SHIFT |
  309. 0x1f << TRAIL_COUNT_SHIFT |
  310. 0xc5 << CLK_ZERO_COUNT_SHIFT |
  311. 0x1f << PREPARE_COUNT_SHIFT);
  312. I915_WRITE(MIPI_DPI_RESOLUTION(pipe),
  313. adjusted_mode->vdisplay << VERTICAL_ADDRESS_SHIFT |
  314. adjusted_mode->hdisplay << HORIZONTAL_ADDRESS_SHIFT);
  315. set_dsi_timings(encoder, adjusted_mode);
  316. val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
  317. if (is_cmd_mode(intel_dsi)) {
  318. val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
  319. val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
  320. } else {
  321. val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
  322. /* XXX: cross-check bpp vs. pixel format? */
  323. val |= intel_dsi->pixel_format;
  324. }
  325. I915_WRITE(MIPI_DSI_FUNC_PRG(pipe), val);
  326. /* timeouts for recovery. one frame IIUC. if counter expires, EOT and
  327. * stop state. */
  328. /*
  329. * In burst mode, value greater than one DPI line Time in byte clock
  330. * (txbyteclkhs) To timeout this timer 1+ of the above said value is
  331. * recommended.
  332. *
  333. * In non-burst mode, Value greater than one DPI frame time in byte
  334. * clock(txbyteclkhs) To timeout this timer 1+ of the above said value
  335. * is recommended.
  336. *
  337. * In DBI only mode, value greater than one DBI frame time in byte
  338. * clock(txbyteclkhs) To timeout this timer 1+ of the above said value
  339. * is recommended.
  340. */
  341. if (is_vid_mode(intel_dsi) &&
  342. intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
  343. I915_WRITE(MIPI_HS_TX_TIMEOUT(pipe),
  344. txbyteclkhs(adjusted_mode->htotal, bpp,
  345. intel_dsi->lane_count) + 1);
  346. } else {
  347. I915_WRITE(MIPI_HS_TX_TIMEOUT(pipe),
  348. txbyteclkhs(adjusted_mode->vtotal *
  349. adjusted_mode->htotal,
  350. bpp, intel_dsi->lane_count) + 1);
  351. }
  352. I915_WRITE(MIPI_LP_RX_TIMEOUT(pipe), 8309); /* max */
  353. I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(pipe), 0x14); /* max */
  354. I915_WRITE(MIPI_DEVICE_RESET_TIMER(pipe), 0xffff); /* max */
  355. /* dphy stuff */
  356. /* in terms of low power clock */
  357. I915_WRITE(MIPI_INIT_COUNT(pipe), txclkesc(ESCAPE_CLOCK_DIVIDER_1, 100));
  358. /* recovery disables */
  359. I915_WRITE(MIPI_EOT_DISABLE(pipe), intel_dsi->eot_disable);
  360. /* in terms of txbyteclkhs. actual high to low switch +
  361. * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
  362. *
  363. * XXX: write MIPI_STOP_STATE_STALL?
  364. */
  365. I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(pipe), 0x46);
  366. /* XXX: low power clock equivalence in terms of byte clock. the number
  367. * of byte clocks occupied in one low power clock. based on txbyteclkhs
  368. * and txclkesc. txclkesc time / txbyteclk time * (105 +
  369. * MIPI_STOP_STATE_STALL) / 105.???
  370. */
  371. I915_WRITE(MIPI_LP_BYTECLK(pipe), 4);
  372. /* the bw essential for transmitting 16 long packets containing 252
  373. * bytes meant for dcs write memory command is programmed in this
  374. * register in terms of byte clocks. based on dsi transfer rate and the
  375. * number of lanes configured the time taken to transmit 16 long packets
  376. * in a dsi stream varies. */
  377. I915_WRITE(MIPI_DBI_BW_CTRL(pipe), 0x820);
  378. I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(pipe),
  379. 0xa << LP_HS_SSW_CNT_SHIFT |
  380. 0x14 << HS_LP_PWR_SW_CNT_SHIFT);
  381. if (is_vid_mode(intel_dsi))
  382. I915_WRITE(MIPI_VIDEO_MODE_FORMAT(pipe),
  383. intel_dsi->video_mode_format);
  384. }
  385. static enum drm_connector_status
  386. intel_dsi_detect(struct drm_connector *connector, bool force)
  387. {
  388. struct intel_dsi *intel_dsi = intel_attached_dsi(connector);
  389. DRM_DEBUG_KMS("\n");
  390. return intel_dsi->dev.dev_ops->detect(&intel_dsi->dev);
  391. }
  392. static int intel_dsi_get_modes(struct drm_connector *connector)
  393. {
  394. struct intel_connector *intel_connector = to_intel_connector(connector);
  395. struct drm_display_mode *mode;
  396. DRM_DEBUG_KMS("\n");
  397. if (!intel_connector->panel.fixed_mode) {
  398. DRM_DEBUG_KMS("no fixed mode\n");
  399. return 0;
  400. }
  401. mode = drm_mode_duplicate(connector->dev,
  402. intel_connector->panel.fixed_mode);
  403. if (!mode) {
  404. DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
  405. return 0;
  406. }
  407. drm_mode_probed_add(connector, mode);
  408. return 1;
  409. }
  410. static void intel_dsi_destroy(struct drm_connector *connector)
  411. {
  412. struct intel_connector *intel_connector = to_intel_connector(connector);
  413. DRM_DEBUG_KMS("\n");
  414. intel_panel_fini(&intel_connector->panel);
  415. drm_connector_cleanup(connector);
  416. kfree(connector);
  417. }
  418. static const struct drm_encoder_funcs intel_dsi_funcs = {
  419. .destroy = intel_encoder_destroy,
  420. };
  421. static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
  422. .get_modes = intel_dsi_get_modes,
  423. .mode_valid = intel_dsi_mode_valid,
  424. .best_encoder = intel_best_encoder,
  425. };
  426. static const struct drm_connector_funcs intel_dsi_connector_funcs = {
  427. .dpms = intel_connector_dpms,
  428. .detect = intel_dsi_detect,
  429. .destroy = intel_dsi_destroy,
  430. .fill_modes = drm_helper_probe_single_connector_modes,
  431. };
  432. bool intel_dsi_init(struct drm_device *dev)
  433. {
  434. struct intel_dsi *intel_dsi;
  435. struct intel_encoder *intel_encoder;
  436. struct drm_encoder *encoder;
  437. struct intel_connector *intel_connector;
  438. struct drm_connector *connector;
  439. struct drm_display_mode *fixed_mode = NULL;
  440. const struct intel_dsi_device *dsi;
  441. unsigned int i;
  442. DRM_DEBUG_KMS("\n");
  443. intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
  444. if (!intel_dsi)
  445. return false;
  446. intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
  447. if (!intel_connector) {
  448. kfree(intel_dsi);
  449. return false;
  450. }
  451. intel_encoder = &intel_dsi->base;
  452. encoder = &intel_encoder->base;
  453. intel_dsi->attached_connector = intel_connector;
  454. connector = &intel_connector->base;
  455. drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI);
  456. /* XXX: very likely not all of these are needed */
  457. intel_encoder->hot_plug = intel_dsi_hot_plug;
  458. intel_encoder->compute_config = intel_dsi_compute_config;
  459. intel_encoder->pre_pll_enable = intel_dsi_pre_pll_enable;
  460. intel_encoder->pre_enable = intel_dsi_pre_enable;
  461. intel_encoder->enable = intel_dsi_enable;
  462. intel_encoder->mode_set = intel_dsi_mode_set;
  463. intel_encoder->disable = intel_dsi_disable;
  464. intel_encoder->post_disable = intel_dsi_post_disable;
  465. intel_encoder->get_hw_state = intel_dsi_get_hw_state;
  466. intel_encoder->get_config = intel_dsi_get_config;
  467. intel_connector->get_hw_state = intel_connector_get_hw_state;
  468. for (i = 0; i < ARRAY_SIZE(intel_dsi_devices); i++) {
  469. dsi = &intel_dsi_devices[i];
  470. intel_dsi->dev = *dsi;
  471. if (dsi->dev_ops->init(&intel_dsi->dev))
  472. break;
  473. }
  474. if (i == ARRAY_SIZE(intel_dsi_devices)) {
  475. DRM_DEBUG_KMS("no device found\n");
  476. goto err;
  477. }
  478. intel_encoder->type = INTEL_OUTPUT_DSI;
  479. intel_encoder->crtc_mask = (1 << 0); /* XXX */
  480. intel_encoder->cloneable = false;
  481. drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
  482. DRM_MODE_CONNECTOR_DSI);
  483. drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
  484. connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
  485. connector->interlace_allowed = false;
  486. connector->doublescan_allowed = false;
  487. intel_connector_attach_encoder(intel_connector, intel_encoder);
  488. drm_sysfs_connector_add(connector);
  489. fixed_mode = dsi->dev_ops->get_modes(&intel_dsi->dev);
  490. if (!fixed_mode) {
  491. DRM_DEBUG_KMS("no fixed mode\n");
  492. goto err;
  493. }
  494. fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
  495. intel_panel_init(&intel_connector->panel, fixed_mode);
  496. return true;
  497. err:
  498. drm_encoder_cleanup(&intel_encoder->base);
  499. kfree(intel_dsi);
  500. kfree(intel_connector);
  501. return false;
  502. }