intel_dsi.c 23 KB

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