intel_dsi.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  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->operation_mode == INTEL_DSI_VIDEO_MODE;
  56. }
  57. static inline bool is_cmd_mode(struct intel_dsi *intel_dsi)
  58. {
  59. return intel_dsi->operation_mode == 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, DPI_LP_MODE_EN);
  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. msleep(intel_dsi->panel_on_delay);
  157. if (intel_dsi->dev.dev_ops->panel_reset)
  158. intel_dsi->dev.dev_ops->panel_reset(&intel_dsi->dev);
  159. if (intel_dsi->dev.dev_ops->send_otp_cmds)
  160. intel_dsi->dev.dev_ops->send_otp_cmds(&intel_dsi->dev);
  161. /* Enable port in pre-enable phase itself because as per hw team
  162. * recommendation, port should be enabled befor plane & pipe */
  163. intel_dsi_enable(encoder);
  164. }
  165. static void intel_dsi_enable_nop(struct intel_encoder *encoder)
  166. {
  167. DRM_DEBUG_KMS("\n");
  168. /* for DSI port enable has to be done before pipe
  169. * and plane enable, so port enable is done in
  170. * pre_enable phase itself unlike other encoders
  171. */
  172. }
  173. static void intel_dsi_disable(struct intel_encoder *encoder)
  174. {
  175. struct drm_device *dev = encoder->base.dev;
  176. struct drm_i915_private *dev_priv = dev->dev_private;
  177. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  178. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  179. int pipe = intel_crtc->pipe;
  180. u32 temp;
  181. DRM_DEBUG_KMS("\n");
  182. if (is_vid_mode(intel_dsi)) {
  183. /* Send Shutdown command to the panel in LP mode */
  184. dpi_send_cmd(intel_dsi, SHUTDOWN, DPI_LP_MODE_EN);
  185. msleep(10);
  186. /* de-assert ip_tg_enable signal */
  187. temp = I915_READ(MIPI_PORT_CTRL(pipe));
  188. I915_WRITE(MIPI_PORT_CTRL(pipe), temp & ~DPI_ENABLE);
  189. POSTING_READ(MIPI_PORT_CTRL(pipe));
  190. msleep(2);
  191. }
  192. /* Panel commands can be sent when clock is in LP11 */
  193. I915_WRITE(MIPI_DEVICE_READY(pipe), 0x0);
  194. temp = I915_READ(MIPI_CTRL(pipe));
  195. temp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
  196. I915_WRITE(MIPI_CTRL(pipe), temp |
  197. intel_dsi->escape_clk_div <<
  198. ESCAPE_CLOCK_DIVIDER_SHIFT);
  199. I915_WRITE(MIPI_EOT_DISABLE(pipe), CLOCKSTOP);
  200. temp = I915_READ(MIPI_DSI_FUNC_PRG(pipe));
  201. temp &= ~VID_MODE_FORMAT_MASK;
  202. I915_WRITE(MIPI_DSI_FUNC_PRG(pipe), temp);
  203. I915_WRITE(MIPI_DEVICE_READY(pipe), 0x1);
  204. /* if disable packets are sent before sending shutdown packet then in
  205. * some next enable sequence send turn on packet error is observed */
  206. if (intel_dsi->dev.dev_ops->disable)
  207. intel_dsi->dev.dev_ops->disable(&intel_dsi->dev);
  208. }
  209. static void intel_dsi_clear_device_ready(struct intel_encoder *encoder)
  210. {
  211. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  212. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  213. int pipe = intel_crtc->pipe;
  214. u32 val;
  215. DRM_DEBUG_KMS("\n");
  216. I915_WRITE(MIPI_DEVICE_READY(pipe), ULPS_STATE_ENTER);
  217. usleep_range(2000, 2500);
  218. I915_WRITE(MIPI_DEVICE_READY(pipe), ULPS_STATE_EXIT);
  219. usleep_range(2000, 2500);
  220. I915_WRITE(MIPI_DEVICE_READY(pipe), ULPS_STATE_ENTER);
  221. usleep_range(2000, 2500);
  222. val = I915_READ(MIPI_PORT_CTRL(pipe));
  223. I915_WRITE(MIPI_PORT_CTRL(pipe), val & ~LP_OUTPUT_HOLD);
  224. usleep_range(1000, 1500);
  225. if (wait_for(((I915_READ(MIPI_PORT_CTRL(pipe)) & AFE_LATCHOUT)
  226. == 0x00000), 30))
  227. DRM_ERROR("DSI LP not going Low\n");
  228. I915_WRITE(MIPI_DEVICE_READY(pipe), 0x00);
  229. usleep_range(2000, 2500);
  230. vlv_disable_dsi_pll(encoder);
  231. }
  232. static void intel_dsi_post_disable(struct intel_encoder *encoder)
  233. {
  234. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  235. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  236. u32 val;
  237. DRM_DEBUG_KMS("\n");
  238. intel_dsi_clear_device_ready(encoder);
  239. val = I915_READ(DSPCLK_GATE_D);
  240. val &= ~DPOUNIT_CLOCK_GATE_DISABLE;
  241. I915_WRITE(DSPCLK_GATE_D, val);
  242. if (intel_dsi->dev.dev_ops->disable_panel_power)
  243. intel_dsi->dev.dev_ops->disable_panel_power(&intel_dsi->dev);
  244. msleep(intel_dsi->panel_off_delay);
  245. msleep(intel_dsi->panel_pwr_cycle_delay);
  246. }
  247. static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
  248. enum pipe *pipe)
  249. {
  250. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  251. enum intel_display_power_domain power_domain;
  252. u32 port, func;
  253. enum pipe p;
  254. DRM_DEBUG_KMS("\n");
  255. power_domain = intel_display_port_power_domain(encoder);
  256. if (!intel_display_power_enabled(dev_priv, power_domain))
  257. return false;
  258. /* XXX: this only works for one DSI output */
  259. for (p = PIPE_A; p <= PIPE_B; p++) {
  260. port = I915_READ(MIPI_PORT_CTRL(p));
  261. func = I915_READ(MIPI_DSI_FUNC_PRG(p));
  262. if ((port & DPI_ENABLE) || (func & CMD_MODE_DATA_WIDTH_MASK)) {
  263. if (I915_READ(MIPI_DEVICE_READY(p)) & DEVICE_READY) {
  264. *pipe = p;
  265. return true;
  266. }
  267. }
  268. }
  269. return false;
  270. }
  271. static void intel_dsi_get_config(struct intel_encoder *encoder,
  272. struct intel_crtc_config *pipe_config)
  273. {
  274. DRM_DEBUG_KMS("\n");
  275. /* XXX: read flags, set to adjusted_mode */
  276. }
  277. static enum drm_mode_status
  278. intel_dsi_mode_valid(struct drm_connector *connector,
  279. struct drm_display_mode *mode)
  280. {
  281. struct intel_connector *intel_connector = to_intel_connector(connector);
  282. struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
  283. struct intel_dsi *intel_dsi = intel_attached_dsi(connector);
  284. DRM_DEBUG_KMS("\n");
  285. if (mode->flags & DRM_MODE_FLAG_DBLSCAN) {
  286. DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n");
  287. return MODE_NO_DBLESCAN;
  288. }
  289. if (fixed_mode) {
  290. if (mode->hdisplay > fixed_mode->hdisplay)
  291. return MODE_PANEL;
  292. if (mode->vdisplay > fixed_mode->vdisplay)
  293. return MODE_PANEL;
  294. }
  295. return intel_dsi->dev.dev_ops->mode_valid(&intel_dsi->dev, mode);
  296. }
  297. /* return txclkesc cycles in terms of divider and duration in us */
  298. static u16 txclkesc(u32 divider, unsigned int us)
  299. {
  300. switch (divider) {
  301. case ESCAPE_CLOCK_DIVIDER_1:
  302. default:
  303. return 20 * us;
  304. case ESCAPE_CLOCK_DIVIDER_2:
  305. return 10 * us;
  306. case ESCAPE_CLOCK_DIVIDER_4:
  307. return 5 * us;
  308. }
  309. }
  310. /* return pixels in terms of txbyteclkhs */
  311. static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count)
  312. {
  313. return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp, 8), lane_count);
  314. }
  315. static void set_dsi_timings(struct drm_encoder *encoder,
  316. const struct drm_display_mode *mode)
  317. {
  318. struct drm_device *dev = encoder->dev;
  319. struct drm_i915_private *dev_priv = dev->dev_private;
  320. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  321. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  322. int pipe = intel_crtc->pipe;
  323. unsigned int bpp = intel_crtc->config.pipe_bpp;
  324. unsigned int lane_count = intel_dsi->lane_count;
  325. u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
  326. hactive = mode->hdisplay;
  327. hfp = mode->hsync_start - mode->hdisplay;
  328. hsync = mode->hsync_end - mode->hsync_start;
  329. hbp = mode->htotal - mode->hsync_end;
  330. vfp = mode->vsync_start - mode->vdisplay;
  331. vsync = mode->vsync_end - mode->vsync_start;
  332. vbp = mode->vtotal - mode->vsync_end;
  333. /* horizontal values are in terms of high speed byte clock */
  334. hactive = txbyteclkhs(hactive, bpp, lane_count);
  335. hfp = txbyteclkhs(hfp, bpp, lane_count);
  336. hsync = txbyteclkhs(hsync, bpp, lane_count);
  337. hbp = txbyteclkhs(hbp, bpp, lane_count);
  338. I915_WRITE(MIPI_HACTIVE_AREA_COUNT(pipe), hactive);
  339. I915_WRITE(MIPI_HFP_COUNT(pipe), hfp);
  340. /* meaningful for video mode non-burst sync pulse mode only, can be zero
  341. * for non-burst sync events and burst modes */
  342. I915_WRITE(MIPI_HSYNC_PADDING_COUNT(pipe), hsync);
  343. I915_WRITE(MIPI_HBP_COUNT(pipe), hbp);
  344. /* vertical values are in terms of lines */
  345. I915_WRITE(MIPI_VFP_COUNT(pipe), vfp);
  346. I915_WRITE(MIPI_VSYNC_PADDING_COUNT(pipe), vsync);
  347. I915_WRITE(MIPI_VBP_COUNT(pipe), vbp);
  348. }
  349. static void intel_dsi_mode_set(struct intel_encoder *intel_encoder)
  350. {
  351. struct drm_encoder *encoder = &intel_encoder->base;
  352. struct drm_device *dev = encoder->dev;
  353. struct drm_i915_private *dev_priv = dev->dev_private;
  354. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  355. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  356. struct drm_display_mode *adjusted_mode =
  357. &intel_crtc->config.adjusted_mode;
  358. int pipe = intel_crtc->pipe;
  359. unsigned int bpp = intel_crtc->config.pipe_bpp;
  360. u32 val, tmp;
  361. DRM_DEBUG_KMS("pipe %c\n", pipe_name(pipe));
  362. /* escape clock divider, 20MHz, shared for A and C. device ready must be
  363. * off when doing this! txclkesc? */
  364. tmp = I915_READ(MIPI_CTRL(0));
  365. tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
  366. I915_WRITE(MIPI_CTRL(0), tmp | ESCAPE_CLOCK_DIVIDER_1);
  367. /* read request priority is per pipe */
  368. tmp = I915_READ(MIPI_CTRL(pipe));
  369. tmp &= ~READ_REQUEST_PRIORITY_MASK;
  370. I915_WRITE(MIPI_CTRL(pipe), tmp | READ_REQUEST_PRIORITY_HIGH);
  371. /* XXX: why here, why like this? handling in irq handler?! */
  372. I915_WRITE(MIPI_INTR_STAT(pipe), 0xffffffff);
  373. I915_WRITE(MIPI_INTR_EN(pipe), 0xffffffff);
  374. I915_WRITE(MIPI_DPHY_PARAM(pipe), intel_dsi->dphy_reg);
  375. I915_WRITE(MIPI_DPI_RESOLUTION(pipe),
  376. adjusted_mode->vdisplay << VERTICAL_ADDRESS_SHIFT |
  377. adjusted_mode->hdisplay << HORIZONTAL_ADDRESS_SHIFT);
  378. set_dsi_timings(encoder, adjusted_mode);
  379. val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
  380. if (is_cmd_mode(intel_dsi)) {
  381. val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
  382. val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
  383. } else {
  384. val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
  385. /* XXX: cross-check bpp vs. pixel format? */
  386. val |= intel_dsi->pixel_format;
  387. }
  388. I915_WRITE(MIPI_DSI_FUNC_PRG(pipe), val);
  389. /* timeouts for recovery. one frame IIUC. if counter expires, EOT and
  390. * stop state. */
  391. /*
  392. * In burst mode, value greater than one DPI line Time in byte clock
  393. * (txbyteclkhs) To timeout this timer 1+ of the above said value is
  394. * recommended.
  395. *
  396. * In non-burst mode, Value greater than one DPI frame time in byte
  397. * clock(txbyteclkhs) To timeout this timer 1+ of the above said value
  398. * is recommended.
  399. *
  400. * In DBI only mode, value greater than one DBI frame time in byte
  401. * clock(txbyteclkhs) To timeout this timer 1+ of the above said value
  402. * is recommended.
  403. */
  404. if (is_vid_mode(intel_dsi) &&
  405. intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
  406. I915_WRITE(MIPI_HS_TX_TIMEOUT(pipe),
  407. txbyteclkhs(adjusted_mode->htotal, bpp,
  408. intel_dsi->lane_count) + 1);
  409. } else {
  410. I915_WRITE(MIPI_HS_TX_TIMEOUT(pipe),
  411. txbyteclkhs(adjusted_mode->vtotal *
  412. adjusted_mode->htotal,
  413. bpp, intel_dsi->lane_count) + 1);
  414. }
  415. I915_WRITE(MIPI_LP_RX_TIMEOUT(pipe), intel_dsi->lp_rx_timeout);
  416. I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(pipe), intel_dsi->turn_arnd_val);
  417. I915_WRITE(MIPI_DEVICE_RESET_TIMER(pipe), intel_dsi->rst_timer_val);
  418. /* dphy stuff */
  419. /* in terms of low power clock */
  420. I915_WRITE(MIPI_INIT_COUNT(pipe), txclkesc(intel_dsi->escape_clk_div, 100));
  421. val = 0;
  422. if (intel_dsi->eotp_pkt == 0)
  423. val |= EOT_DISABLE;
  424. if (intel_dsi->clock_stop)
  425. val |= CLOCKSTOP;
  426. /* recovery disables */
  427. I915_WRITE(MIPI_EOT_DISABLE(pipe), val);
  428. /* in terms of low power clock */
  429. I915_WRITE(MIPI_INIT_COUNT(pipe), intel_dsi->init_count);
  430. /* in terms of txbyteclkhs. actual high to low switch +
  431. * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
  432. *
  433. * XXX: write MIPI_STOP_STATE_STALL?
  434. */
  435. I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(pipe),
  436. intel_dsi->hs_to_lp_count);
  437. /* XXX: low power clock equivalence in terms of byte clock. the number
  438. * of byte clocks occupied in one low power clock. based on txbyteclkhs
  439. * and txclkesc. txclkesc time / txbyteclk time * (105 +
  440. * MIPI_STOP_STATE_STALL) / 105.???
  441. */
  442. I915_WRITE(MIPI_LP_BYTECLK(pipe), intel_dsi->lp_byte_clk);
  443. /* the bw essential for transmitting 16 long packets containing 252
  444. * bytes meant for dcs write memory command is programmed in this
  445. * register in terms of byte clocks. based on dsi transfer rate and the
  446. * number of lanes configured the time taken to transmit 16 long packets
  447. * in a dsi stream varies. */
  448. I915_WRITE(MIPI_DBI_BW_CTRL(pipe), intel_dsi->bw_timer);
  449. I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(pipe),
  450. intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT |
  451. intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT);
  452. if (is_vid_mode(intel_dsi))
  453. /* Some panels might have resolution which is not a multiple of
  454. * 64 like 1366 x 768. Enable RANDOM resolution support for such
  455. * panels by default */
  456. I915_WRITE(MIPI_VIDEO_MODE_FORMAT(pipe),
  457. intel_dsi->video_frmt_cfg_bits |
  458. intel_dsi->video_mode_format |
  459. IP_TG_CONFIG |
  460. RANDOM_DPI_DISPLAY_RESOLUTION);
  461. }
  462. static enum drm_connector_status
  463. intel_dsi_detect(struct drm_connector *connector, bool force)
  464. {
  465. struct intel_dsi *intel_dsi = intel_attached_dsi(connector);
  466. struct intel_encoder *intel_encoder = &intel_dsi->base;
  467. enum intel_display_power_domain power_domain;
  468. enum drm_connector_status connector_status;
  469. struct drm_i915_private *dev_priv = intel_encoder->base.dev->dev_private;
  470. DRM_DEBUG_KMS("\n");
  471. power_domain = intel_display_port_power_domain(intel_encoder);
  472. intel_display_power_get(dev_priv, power_domain);
  473. connector_status = intel_dsi->dev.dev_ops->detect(&intel_dsi->dev);
  474. intel_display_power_put(dev_priv, power_domain);
  475. return connector_status;
  476. }
  477. static int intel_dsi_get_modes(struct drm_connector *connector)
  478. {
  479. struct intel_connector *intel_connector = to_intel_connector(connector);
  480. struct drm_display_mode *mode;
  481. DRM_DEBUG_KMS("\n");
  482. if (!intel_connector->panel.fixed_mode) {
  483. DRM_DEBUG_KMS("no fixed mode\n");
  484. return 0;
  485. }
  486. mode = drm_mode_duplicate(connector->dev,
  487. intel_connector->panel.fixed_mode);
  488. if (!mode) {
  489. DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
  490. return 0;
  491. }
  492. drm_mode_probed_add(connector, mode);
  493. return 1;
  494. }
  495. static void intel_dsi_destroy(struct drm_connector *connector)
  496. {
  497. struct intel_connector *intel_connector = to_intel_connector(connector);
  498. DRM_DEBUG_KMS("\n");
  499. intel_panel_fini(&intel_connector->panel);
  500. drm_connector_cleanup(connector);
  501. kfree(connector);
  502. }
  503. static const struct drm_encoder_funcs intel_dsi_funcs = {
  504. .destroy = intel_encoder_destroy,
  505. };
  506. static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
  507. .get_modes = intel_dsi_get_modes,
  508. .mode_valid = intel_dsi_mode_valid,
  509. .best_encoder = intel_best_encoder,
  510. };
  511. static const struct drm_connector_funcs intel_dsi_connector_funcs = {
  512. .dpms = intel_connector_dpms,
  513. .detect = intel_dsi_detect,
  514. .destroy = intel_dsi_destroy,
  515. .fill_modes = drm_helper_probe_single_connector_modes,
  516. };
  517. bool intel_dsi_init(struct drm_device *dev)
  518. {
  519. struct intel_dsi *intel_dsi;
  520. struct intel_encoder *intel_encoder;
  521. struct drm_encoder *encoder;
  522. struct intel_connector *intel_connector;
  523. struct drm_connector *connector;
  524. struct drm_display_mode *fixed_mode = NULL;
  525. const struct intel_dsi_device *dsi;
  526. unsigned int i;
  527. DRM_DEBUG_KMS("\n");
  528. intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
  529. if (!intel_dsi)
  530. return false;
  531. intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
  532. if (!intel_connector) {
  533. kfree(intel_dsi);
  534. return false;
  535. }
  536. intel_encoder = &intel_dsi->base;
  537. encoder = &intel_encoder->base;
  538. intel_dsi->attached_connector = intel_connector;
  539. connector = &intel_connector->base;
  540. drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI);
  541. /* XXX: very likely not all of these are needed */
  542. intel_encoder->hot_plug = intel_dsi_hot_plug;
  543. intel_encoder->compute_config = intel_dsi_compute_config;
  544. intel_encoder->pre_pll_enable = intel_dsi_pre_pll_enable;
  545. intel_encoder->pre_enable = intel_dsi_pre_enable;
  546. intel_encoder->enable = intel_dsi_enable_nop;
  547. intel_encoder->mode_set = intel_dsi_mode_set;
  548. intel_encoder->disable = intel_dsi_disable;
  549. intel_encoder->post_disable = intel_dsi_post_disable;
  550. intel_encoder->get_hw_state = intel_dsi_get_hw_state;
  551. intel_encoder->get_config = intel_dsi_get_config;
  552. intel_connector->get_hw_state = intel_connector_get_hw_state;
  553. intel_connector->unregister = intel_connector_unregister;
  554. for (i = 0; i < ARRAY_SIZE(intel_dsi_devices); i++) {
  555. dsi = &intel_dsi_devices[i];
  556. intel_dsi->dev = *dsi;
  557. if (dsi->dev_ops->init(&intel_dsi->dev))
  558. break;
  559. }
  560. if (i == ARRAY_SIZE(intel_dsi_devices)) {
  561. DRM_DEBUG_KMS("no device found\n");
  562. goto err;
  563. }
  564. intel_encoder->type = INTEL_OUTPUT_DSI;
  565. intel_encoder->crtc_mask = (1 << 0); /* XXX */
  566. intel_encoder->cloneable = 0;
  567. drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
  568. DRM_MODE_CONNECTOR_DSI);
  569. drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
  570. connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
  571. connector->interlace_allowed = false;
  572. connector->doublescan_allowed = false;
  573. intel_connector_attach_encoder(intel_connector, intel_encoder);
  574. drm_sysfs_connector_add(connector);
  575. fixed_mode = dsi->dev_ops->get_modes(&intel_dsi->dev);
  576. if (!fixed_mode) {
  577. DRM_DEBUG_KMS("no fixed mode\n");
  578. goto err;
  579. }
  580. fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
  581. intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
  582. return true;
  583. err:
  584. drm_encoder_cleanup(&intel_encoder->base);
  585. kfree(intel_dsi);
  586. kfree(intel_connector);
  587. return false;
  588. }