intel_dsi.c 18 KB

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