intel_dsi.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  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 band_gap_reset(struct drm_i915_private *dev_priv)
  38. {
  39. mutex_lock(&dev_priv->dpio_lock);
  40. vlv_flisdsi_write(dev_priv, 0x08, 0x0001);
  41. vlv_flisdsi_write(dev_priv, 0x0F, 0x0005);
  42. vlv_flisdsi_write(dev_priv, 0x0F, 0x0025);
  43. udelay(150);
  44. vlv_flisdsi_write(dev_priv, 0x0F, 0x0000);
  45. vlv_flisdsi_write(dev_priv, 0x08, 0x0000);
  46. mutex_unlock(&dev_priv->dpio_lock);
  47. }
  48. static struct intel_dsi *intel_attached_dsi(struct drm_connector *connector)
  49. {
  50. return container_of(intel_attached_encoder(connector),
  51. struct intel_dsi, base);
  52. }
  53. static inline bool is_vid_mode(struct intel_dsi *intel_dsi)
  54. {
  55. return intel_dsi->dev.type == INTEL_DSI_VIDEO_MODE;
  56. }
  57. static inline bool is_cmd_mode(struct intel_dsi *intel_dsi)
  58. {
  59. return intel_dsi->dev.type == INTEL_DSI_COMMAND_MODE;
  60. }
  61. static void intel_dsi_hot_plug(struct intel_encoder *encoder)
  62. {
  63. DRM_DEBUG_KMS("\n");
  64. }
  65. static bool intel_dsi_compute_config(struct intel_encoder *encoder,
  66. struct intel_crtc_config *config)
  67. {
  68. struct intel_dsi *intel_dsi = container_of(encoder, struct intel_dsi,
  69. base);
  70. struct intel_connector *intel_connector = intel_dsi->attached_connector;
  71. struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
  72. struct drm_display_mode *adjusted_mode = &config->adjusted_mode;
  73. struct drm_display_mode *mode = &config->requested_mode;
  74. DRM_DEBUG_KMS("\n");
  75. if (fixed_mode)
  76. intel_fixed_panel_mode(fixed_mode, adjusted_mode);
  77. if (intel_dsi->dev.dev_ops->mode_fixup)
  78. return intel_dsi->dev.dev_ops->mode_fixup(&intel_dsi->dev,
  79. mode, adjusted_mode);
  80. return true;
  81. }
  82. static void intel_dsi_pre_pll_enable(struct intel_encoder *encoder)
  83. {
  84. DRM_DEBUG_KMS("\n");
  85. vlv_enable_dsi_pll(encoder);
  86. }
  87. static void intel_dsi_device_ready(struct intel_encoder *encoder)
  88. {
  89. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  90. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  91. int pipe = intel_crtc->pipe;
  92. u32 val;
  93. DRM_DEBUG_KMS("\n");
  94. mutex_lock(&dev_priv->dpio_lock);
  95. /* program rcomp for compliance, reduce from 50 ohms to 45 ohms
  96. * needed everytime after power gate */
  97. vlv_flisdsi_write(dev_priv, 0x04, 0x0004);
  98. mutex_unlock(&dev_priv->dpio_lock);
  99. /* bandgap reset is needed after everytime we do power gate */
  100. band_gap_reset(dev_priv);
  101. val = I915_READ(MIPI_PORT_CTRL(pipe));
  102. I915_WRITE(MIPI_PORT_CTRL(pipe), val | LP_OUTPUT_HOLD);
  103. usleep_range(1000, 1500);
  104. I915_WRITE(MIPI_DEVICE_READY(pipe), DEVICE_READY | ULPS_STATE_EXIT);
  105. usleep_range(2000, 2500);
  106. I915_WRITE(MIPI_DEVICE_READY(pipe), DEVICE_READY);
  107. usleep_range(2000, 2500);
  108. I915_WRITE(MIPI_DEVICE_READY(pipe), 0x00);
  109. usleep_range(2000, 2500);
  110. I915_WRITE(MIPI_DEVICE_READY(pipe), DEVICE_READY);
  111. usleep_range(2000, 2500);
  112. }
  113. static void intel_dsi_enable(struct intel_encoder *encoder)
  114. {
  115. struct drm_device *dev = encoder->base.dev;
  116. struct drm_i915_private *dev_priv = dev->dev_private;
  117. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  118. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  119. int pipe = intel_crtc->pipe;
  120. u32 temp;
  121. DRM_DEBUG_KMS("\n");
  122. if (is_cmd_mode(intel_dsi))
  123. I915_WRITE(MIPI_MAX_RETURN_PKT_SIZE(pipe), 8 * 4);
  124. else {
  125. msleep(20); /* XXX */
  126. dpi_send_cmd(intel_dsi, TURN_ON);
  127. msleep(100);
  128. if (intel_dsi->dev.dev_ops->enable)
  129. intel_dsi->dev.dev_ops->enable(&intel_dsi->dev);
  130. /* assert ip_tg_enable signal */
  131. temp = I915_READ(MIPI_PORT_CTRL(pipe)) & ~LANE_CONFIGURATION_MASK;
  132. temp = temp | intel_dsi->port_bits;
  133. I915_WRITE(MIPI_PORT_CTRL(pipe), temp | DPI_ENABLE);
  134. POSTING_READ(MIPI_PORT_CTRL(pipe));
  135. }
  136. }
  137. static void intel_dsi_pre_enable(struct intel_encoder *encoder)
  138. {
  139. struct drm_device *dev = encoder->base.dev;
  140. struct drm_i915_private *dev_priv = dev->dev_private;
  141. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  142. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  143. enum pipe pipe = intel_crtc->pipe;
  144. u32 tmp;
  145. DRM_DEBUG_KMS("\n");
  146. /* Disable DPOunit clock gating, can stall pipe
  147. * and we need DPLL REFA always enabled */
  148. tmp = I915_READ(DPLL(pipe));
  149. tmp |= DPLL_REFA_CLK_ENABLE_VLV;
  150. I915_WRITE(DPLL(pipe), tmp);
  151. tmp = I915_READ(DSPCLK_GATE_D);
  152. tmp |= DPOUNIT_CLOCK_GATE_DISABLE;
  153. I915_WRITE(DSPCLK_GATE_D, tmp);
  154. /* put device in ready state */
  155. intel_dsi_device_ready(encoder);
  156. if (intel_dsi->dev.dev_ops->panel_reset)
  157. intel_dsi->dev.dev_ops->panel_reset(&intel_dsi->dev);
  158. if (intel_dsi->dev.dev_ops->send_otp_cmds)
  159. intel_dsi->dev.dev_ops->send_otp_cmds(&intel_dsi->dev);
  160. /* Enable port in pre-enable phase itself because as per hw team
  161. * recommendation, port should be enabled befor plane & pipe */
  162. intel_dsi_enable(encoder);
  163. }
  164. static void intel_dsi_enable_nop(struct intel_encoder *encoder)
  165. {
  166. DRM_DEBUG_KMS("\n");
  167. /* for DSI port enable has to be done before pipe
  168. * and plane enable, so port enable is done in
  169. * pre_enable phase itself unlike other encoders
  170. */
  171. }
  172. static void intel_dsi_disable(struct intel_encoder *encoder)
  173. {
  174. struct drm_device *dev = encoder->base.dev;
  175. struct drm_i915_private *dev_priv = dev->dev_private;
  176. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  177. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  178. int pipe = intel_crtc->pipe;
  179. u32 temp;
  180. DRM_DEBUG_KMS("\n");
  181. if (is_vid_mode(intel_dsi)) {
  182. dpi_send_cmd(intel_dsi, SHUTDOWN);
  183. msleep(10);
  184. /* de-assert ip_tg_enable signal */
  185. temp = I915_READ(MIPI_PORT_CTRL(pipe));
  186. I915_WRITE(MIPI_PORT_CTRL(pipe), temp & ~DPI_ENABLE);
  187. POSTING_READ(MIPI_PORT_CTRL(pipe));
  188. msleep(2);
  189. }
  190. /* if disable packets are sent before sending shutdown packet then in
  191. * some next enable sequence send turn on packet error is observed */
  192. if (intel_dsi->dev.dev_ops->disable)
  193. intel_dsi->dev.dev_ops->disable(&intel_dsi->dev);
  194. }
  195. static void intel_dsi_clear_device_ready(struct intel_encoder *encoder)
  196. {
  197. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  198. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  199. int pipe = intel_crtc->pipe;
  200. u32 val;
  201. DRM_DEBUG_KMS("\n");
  202. I915_WRITE(MIPI_DEVICE_READY(pipe), ULPS_STATE_ENTER);
  203. usleep_range(2000, 2500);
  204. I915_WRITE(MIPI_DEVICE_READY(pipe), ULPS_STATE_EXIT);
  205. usleep_range(2000, 2500);
  206. I915_WRITE(MIPI_DEVICE_READY(pipe), ULPS_STATE_ENTER);
  207. usleep_range(2000, 2500);
  208. val = I915_READ(MIPI_PORT_CTRL(pipe));
  209. I915_WRITE(MIPI_PORT_CTRL(pipe), val & ~LP_OUTPUT_HOLD);
  210. usleep_range(1000, 1500);
  211. if (wait_for(((I915_READ(MIPI_PORT_CTRL(pipe)) & AFE_LATCHOUT)
  212. == 0x00000), 30))
  213. DRM_ERROR("DSI LP not going Low\n");
  214. I915_WRITE(MIPI_DEVICE_READY(pipe), 0x00);
  215. usleep_range(2000, 2500);
  216. vlv_disable_dsi_pll(encoder);
  217. }
  218. static void intel_dsi_post_disable(struct intel_encoder *encoder)
  219. {
  220. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  221. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  222. u32 val;
  223. DRM_DEBUG_KMS("\n");
  224. intel_dsi_clear_device_ready(encoder);
  225. val = I915_READ(DSPCLK_GATE_D);
  226. val &= ~DPOUNIT_CLOCK_GATE_DISABLE;
  227. I915_WRITE(DSPCLK_GATE_D, val);
  228. if (intel_dsi->dev.dev_ops->disable_panel_power)
  229. intel_dsi->dev.dev_ops->disable_panel_power(&intel_dsi->dev);
  230. }
  231. static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
  232. enum pipe *pipe)
  233. {
  234. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  235. enum intel_display_power_domain power_domain;
  236. u32 port, func;
  237. enum pipe p;
  238. DRM_DEBUG_KMS("\n");
  239. power_domain = intel_display_port_power_domain(encoder);
  240. if (!intel_display_power_enabled(dev_priv, power_domain))
  241. return false;
  242. /* XXX: this only works for one DSI output */
  243. for (p = PIPE_A; p <= PIPE_B; p++) {
  244. port = I915_READ(MIPI_PORT_CTRL(p));
  245. func = I915_READ(MIPI_DSI_FUNC_PRG(p));
  246. if ((port & DPI_ENABLE) || (func & CMD_MODE_DATA_WIDTH_MASK)) {
  247. if (I915_READ(MIPI_DEVICE_READY(p)) & DEVICE_READY) {
  248. *pipe = p;
  249. return true;
  250. }
  251. }
  252. }
  253. return false;
  254. }
  255. static void intel_dsi_get_config(struct intel_encoder *encoder,
  256. struct intel_crtc_config *pipe_config)
  257. {
  258. DRM_DEBUG_KMS("\n");
  259. /* XXX: read flags, set to adjusted_mode */
  260. }
  261. static enum drm_mode_status
  262. intel_dsi_mode_valid(struct drm_connector *connector,
  263. struct drm_display_mode *mode)
  264. {
  265. struct intel_connector *intel_connector = to_intel_connector(connector);
  266. struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
  267. struct intel_dsi *intel_dsi = intel_attached_dsi(connector);
  268. DRM_DEBUG_KMS("\n");
  269. if (mode->flags & DRM_MODE_FLAG_DBLSCAN) {
  270. DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n");
  271. return MODE_NO_DBLESCAN;
  272. }
  273. if (fixed_mode) {
  274. if (mode->hdisplay > fixed_mode->hdisplay)
  275. return MODE_PANEL;
  276. if (mode->vdisplay > fixed_mode->vdisplay)
  277. return MODE_PANEL;
  278. }
  279. return intel_dsi->dev.dev_ops->mode_valid(&intel_dsi->dev, mode);
  280. }
  281. /* return txclkesc cycles in terms of divider and duration in us */
  282. static u16 txclkesc(u32 divider, unsigned int us)
  283. {
  284. switch (divider) {
  285. case ESCAPE_CLOCK_DIVIDER_1:
  286. default:
  287. return 20 * us;
  288. case ESCAPE_CLOCK_DIVIDER_2:
  289. return 10 * us;
  290. case ESCAPE_CLOCK_DIVIDER_4:
  291. return 5 * us;
  292. }
  293. }
  294. /* return pixels in terms of txbyteclkhs */
  295. static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count)
  296. {
  297. return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp, 8), lane_count);
  298. }
  299. static void set_dsi_timings(struct drm_encoder *encoder,
  300. const struct drm_display_mode *mode)
  301. {
  302. struct drm_device *dev = encoder->dev;
  303. struct drm_i915_private *dev_priv = dev->dev_private;
  304. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  305. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  306. int pipe = intel_crtc->pipe;
  307. unsigned int bpp = intel_crtc->config.pipe_bpp;
  308. unsigned int lane_count = intel_dsi->lane_count;
  309. u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
  310. hactive = mode->hdisplay;
  311. hfp = mode->hsync_start - mode->hdisplay;
  312. hsync = mode->hsync_end - mode->hsync_start;
  313. hbp = mode->htotal - mode->hsync_end;
  314. vfp = mode->vsync_start - mode->vdisplay;
  315. vsync = mode->vsync_end - mode->vsync_start;
  316. vbp = mode->vtotal - mode->vsync_end;
  317. /* horizontal values are in terms of high speed byte clock */
  318. hactive = txbyteclkhs(hactive, bpp, lane_count);
  319. hfp = txbyteclkhs(hfp, bpp, lane_count);
  320. hsync = txbyteclkhs(hsync, bpp, lane_count);
  321. hbp = txbyteclkhs(hbp, bpp, lane_count);
  322. I915_WRITE(MIPI_HACTIVE_AREA_COUNT(pipe), hactive);
  323. I915_WRITE(MIPI_HFP_COUNT(pipe), hfp);
  324. /* meaningful for video mode non-burst sync pulse mode only, can be zero
  325. * for non-burst sync events and burst modes */
  326. I915_WRITE(MIPI_HSYNC_PADDING_COUNT(pipe), hsync);
  327. I915_WRITE(MIPI_HBP_COUNT(pipe), hbp);
  328. /* vertical values are in terms of lines */
  329. I915_WRITE(MIPI_VFP_COUNT(pipe), vfp);
  330. I915_WRITE(MIPI_VSYNC_PADDING_COUNT(pipe), vsync);
  331. I915_WRITE(MIPI_VBP_COUNT(pipe), vbp);
  332. }
  333. static void intel_dsi_mode_set(struct intel_encoder *intel_encoder)
  334. {
  335. struct drm_encoder *encoder = &intel_encoder->base;
  336. struct drm_device *dev = encoder->dev;
  337. struct drm_i915_private *dev_priv = dev->dev_private;
  338. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  339. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  340. struct drm_display_mode *adjusted_mode =
  341. &intel_crtc->config.adjusted_mode;
  342. int pipe = intel_crtc->pipe;
  343. unsigned int bpp = intel_crtc->config.pipe_bpp;
  344. u32 val, tmp;
  345. DRM_DEBUG_KMS("pipe %c\n", pipe_name(pipe));
  346. /* escape clock divider, 20MHz, shared for A and C. device ready must be
  347. * off when doing this! txclkesc? */
  348. tmp = I915_READ(MIPI_CTRL(0));
  349. tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
  350. I915_WRITE(MIPI_CTRL(0), tmp | ESCAPE_CLOCK_DIVIDER_1);
  351. /* read request priority is per pipe */
  352. tmp = I915_READ(MIPI_CTRL(pipe));
  353. tmp &= ~READ_REQUEST_PRIORITY_MASK;
  354. I915_WRITE(MIPI_CTRL(pipe), tmp | READ_REQUEST_PRIORITY_HIGH);
  355. /* XXX: why here, why like this? handling in irq handler?! */
  356. I915_WRITE(MIPI_INTR_STAT(pipe), 0xffffffff);
  357. I915_WRITE(MIPI_INTR_EN(pipe), 0xffffffff);
  358. I915_WRITE(MIPI_DPHY_PARAM(pipe), intel_dsi->dphy_reg);
  359. I915_WRITE(MIPI_DPI_RESOLUTION(pipe),
  360. adjusted_mode->vdisplay << VERTICAL_ADDRESS_SHIFT |
  361. adjusted_mode->hdisplay << HORIZONTAL_ADDRESS_SHIFT);
  362. set_dsi_timings(encoder, adjusted_mode);
  363. val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
  364. if (is_cmd_mode(intel_dsi)) {
  365. val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
  366. val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
  367. } else {
  368. val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
  369. /* XXX: cross-check bpp vs. pixel format? */
  370. val |= intel_dsi->pixel_format;
  371. }
  372. I915_WRITE(MIPI_DSI_FUNC_PRG(pipe), val);
  373. /* timeouts for recovery. one frame IIUC. if counter expires, EOT and
  374. * stop state. */
  375. /*
  376. * In burst mode, value greater than one DPI line Time in byte clock
  377. * (txbyteclkhs) To timeout this timer 1+ of the above said value is
  378. * recommended.
  379. *
  380. * In non-burst mode, Value greater than one DPI frame time in byte
  381. * clock(txbyteclkhs) To timeout this timer 1+ of the above said value
  382. * is recommended.
  383. *
  384. * In DBI only mode, value greater than one DBI frame time in byte
  385. * clock(txbyteclkhs) To timeout this timer 1+ of the above said value
  386. * is recommended.
  387. */
  388. if (is_vid_mode(intel_dsi) &&
  389. intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
  390. I915_WRITE(MIPI_HS_TX_TIMEOUT(pipe),
  391. txbyteclkhs(adjusted_mode->htotal, bpp,
  392. intel_dsi->lane_count) + 1);
  393. } else {
  394. I915_WRITE(MIPI_HS_TX_TIMEOUT(pipe),
  395. txbyteclkhs(adjusted_mode->vtotal *
  396. adjusted_mode->htotal,
  397. bpp, intel_dsi->lane_count) + 1);
  398. }
  399. I915_WRITE(MIPI_LP_RX_TIMEOUT(pipe), intel_dsi->lp_rx_timeout);
  400. I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(pipe), intel_dsi->turn_arnd_val);
  401. I915_WRITE(MIPI_DEVICE_RESET_TIMER(pipe), intel_dsi->rst_timer_val);
  402. /* dphy stuff */
  403. /* in terms of low power clock */
  404. I915_WRITE(MIPI_INIT_COUNT(pipe), txclkesc(ESCAPE_CLOCK_DIVIDER_1, 100));
  405. /* recovery disables */
  406. I915_WRITE(MIPI_EOT_DISABLE(pipe), intel_dsi->eot_disable);
  407. /* in terms of txbyteclkhs. actual high to low switch +
  408. * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
  409. *
  410. * XXX: write MIPI_STOP_STATE_STALL?
  411. */
  412. I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(pipe),
  413. intel_dsi->hs_to_lp_count);
  414. /* XXX: low power clock equivalence in terms of byte clock. the number
  415. * of byte clocks occupied in one low power clock. based on txbyteclkhs
  416. * and txclkesc. txclkesc time / txbyteclk time * (105 +
  417. * MIPI_STOP_STATE_STALL) / 105.???
  418. */
  419. I915_WRITE(MIPI_LP_BYTECLK(pipe), intel_dsi->lp_byte_clk);
  420. /* the bw essential for transmitting 16 long packets containing 252
  421. * bytes meant for dcs write memory command is programmed in this
  422. * register in terms of byte clocks. based on dsi transfer rate and the
  423. * number of lanes configured the time taken to transmit 16 long packets
  424. * in a dsi stream varies. */
  425. I915_WRITE(MIPI_DBI_BW_CTRL(pipe), intel_dsi->bw_timer);
  426. I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(pipe),
  427. intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT |
  428. intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT);
  429. if (is_vid_mode(intel_dsi))
  430. I915_WRITE(MIPI_VIDEO_MODE_FORMAT(pipe),
  431. intel_dsi->video_frmt_cfg_bits |
  432. intel_dsi->video_mode_format);
  433. }
  434. static enum drm_connector_status
  435. intel_dsi_detect(struct drm_connector *connector, bool force)
  436. {
  437. struct intel_dsi *intel_dsi = intel_attached_dsi(connector);
  438. struct intel_encoder *intel_encoder = &intel_dsi->base;
  439. enum intel_display_power_domain power_domain;
  440. enum drm_connector_status connector_status;
  441. struct drm_i915_private *dev_priv = intel_encoder->base.dev->dev_private;
  442. DRM_DEBUG_KMS("\n");
  443. power_domain = intel_display_port_power_domain(intel_encoder);
  444. intel_display_power_get(dev_priv, power_domain);
  445. connector_status = intel_dsi->dev.dev_ops->detect(&intel_dsi->dev);
  446. intel_display_power_put(dev_priv, power_domain);
  447. return connector_status;
  448. }
  449. static int intel_dsi_get_modes(struct drm_connector *connector)
  450. {
  451. struct intel_connector *intel_connector = to_intel_connector(connector);
  452. struct drm_display_mode *mode;
  453. DRM_DEBUG_KMS("\n");
  454. if (!intel_connector->panel.fixed_mode) {
  455. DRM_DEBUG_KMS("no fixed mode\n");
  456. return 0;
  457. }
  458. mode = drm_mode_duplicate(connector->dev,
  459. intel_connector->panel.fixed_mode);
  460. if (!mode) {
  461. DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
  462. return 0;
  463. }
  464. drm_mode_probed_add(connector, mode);
  465. return 1;
  466. }
  467. static void intel_dsi_destroy(struct drm_connector *connector)
  468. {
  469. struct intel_connector *intel_connector = to_intel_connector(connector);
  470. DRM_DEBUG_KMS("\n");
  471. intel_panel_fini(&intel_connector->panel);
  472. drm_connector_cleanup(connector);
  473. kfree(connector);
  474. }
  475. static const struct drm_encoder_funcs intel_dsi_funcs = {
  476. .destroy = intel_encoder_destroy,
  477. };
  478. static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
  479. .get_modes = intel_dsi_get_modes,
  480. .mode_valid = intel_dsi_mode_valid,
  481. .best_encoder = intel_best_encoder,
  482. };
  483. static const struct drm_connector_funcs intel_dsi_connector_funcs = {
  484. .dpms = intel_connector_dpms,
  485. .detect = intel_dsi_detect,
  486. .destroy = intel_dsi_destroy,
  487. .fill_modes = drm_helper_probe_single_connector_modes,
  488. };
  489. bool intel_dsi_init(struct drm_device *dev)
  490. {
  491. struct intel_dsi *intel_dsi;
  492. struct intel_encoder *intel_encoder;
  493. struct drm_encoder *encoder;
  494. struct intel_connector *intel_connector;
  495. struct drm_connector *connector;
  496. struct drm_display_mode *fixed_mode = NULL;
  497. const struct intel_dsi_device *dsi;
  498. unsigned int i;
  499. DRM_DEBUG_KMS("\n");
  500. intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
  501. if (!intel_dsi)
  502. return false;
  503. intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
  504. if (!intel_connector) {
  505. kfree(intel_dsi);
  506. return false;
  507. }
  508. intel_encoder = &intel_dsi->base;
  509. encoder = &intel_encoder->base;
  510. intel_dsi->attached_connector = intel_connector;
  511. connector = &intel_connector->base;
  512. drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI);
  513. /* XXX: very likely not all of these are needed */
  514. intel_encoder->hot_plug = intel_dsi_hot_plug;
  515. intel_encoder->compute_config = intel_dsi_compute_config;
  516. intel_encoder->pre_pll_enable = intel_dsi_pre_pll_enable;
  517. intel_encoder->pre_enable = intel_dsi_pre_enable;
  518. intel_encoder->enable = intel_dsi_enable_nop;
  519. intel_encoder->mode_set = intel_dsi_mode_set;
  520. intel_encoder->disable = intel_dsi_disable;
  521. intel_encoder->post_disable = intel_dsi_post_disable;
  522. intel_encoder->get_hw_state = intel_dsi_get_hw_state;
  523. intel_encoder->get_config = intel_dsi_get_config;
  524. intel_connector->get_hw_state = intel_connector_get_hw_state;
  525. intel_connector->unregister = intel_connector_unregister;
  526. for (i = 0; i < ARRAY_SIZE(intel_dsi_devices); i++) {
  527. dsi = &intel_dsi_devices[i];
  528. intel_dsi->dev = *dsi;
  529. if (dsi->dev_ops->init(&intel_dsi->dev))
  530. break;
  531. }
  532. if (i == ARRAY_SIZE(intel_dsi_devices)) {
  533. DRM_DEBUG_KMS("no device found\n");
  534. goto err;
  535. }
  536. intel_encoder->type = INTEL_OUTPUT_DSI;
  537. intel_encoder->crtc_mask = (1 << 0); /* XXX */
  538. intel_encoder->cloneable = 0;
  539. drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
  540. DRM_MODE_CONNECTOR_DSI);
  541. drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
  542. connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
  543. connector->interlace_allowed = false;
  544. connector->doublescan_allowed = false;
  545. intel_connector_attach_encoder(intel_connector, intel_encoder);
  546. drm_sysfs_connector_add(connector);
  547. fixed_mode = dsi->dev_ops->get_modes(&intel_dsi->dev);
  548. if (!fixed_mode) {
  549. DRM_DEBUG_KMS("no fixed mode\n");
  550. goto err;
  551. }
  552. fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
  553. intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
  554. return true;
  555. err:
  556. drm_encoder_cleanup(&intel_encoder->base);
  557. kfree(intel_dsi);
  558. kfree(intel_connector);
  559. return false;
  560. }