intel_dsi.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  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_is_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. u16 burst_mode_ratio)
  338. {
  339. return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio,
  340. 8 * 100), lane_count);
  341. }
  342. static void set_dsi_timings(struct drm_encoder *encoder,
  343. const struct drm_display_mode *mode)
  344. {
  345. struct drm_device *dev = encoder->dev;
  346. struct drm_i915_private *dev_priv = dev->dev_private;
  347. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  348. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  349. int pipe = intel_crtc->pipe;
  350. unsigned int bpp = intel_crtc->config.pipe_bpp;
  351. unsigned int lane_count = intel_dsi->lane_count;
  352. u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
  353. hactive = mode->hdisplay;
  354. hfp = mode->hsync_start - mode->hdisplay;
  355. hsync = mode->hsync_end - mode->hsync_start;
  356. hbp = mode->htotal - mode->hsync_end;
  357. vfp = mode->vsync_start - mode->vdisplay;
  358. vsync = mode->vsync_end - mode->vsync_start;
  359. vbp = mode->vtotal - mode->vsync_end;
  360. /* horizontal values are in terms of high speed byte clock */
  361. hactive = txbyteclkhs(hactive, bpp, lane_count,
  362. intel_dsi->burst_mode_ratio);
  363. hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio);
  364. hsync = txbyteclkhs(hsync, bpp, lane_count,
  365. intel_dsi->burst_mode_ratio);
  366. hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio);
  367. I915_WRITE(MIPI_HACTIVE_AREA_COUNT(pipe), hactive);
  368. I915_WRITE(MIPI_HFP_COUNT(pipe), hfp);
  369. /* meaningful for video mode non-burst sync pulse mode only, can be zero
  370. * for non-burst sync events and burst modes */
  371. I915_WRITE(MIPI_HSYNC_PADDING_COUNT(pipe), hsync);
  372. I915_WRITE(MIPI_HBP_COUNT(pipe), hbp);
  373. /* vertical values are in terms of lines */
  374. I915_WRITE(MIPI_VFP_COUNT(pipe), vfp);
  375. I915_WRITE(MIPI_VSYNC_PADDING_COUNT(pipe), vsync);
  376. I915_WRITE(MIPI_VBP_COUNT(pipe), vbp);
  377. }
  378. static void intel_dsi_prepare(struct intel_encoder *intel_encoder)
  379. {
  380. struct drm_encoder *encoder = &intel_encoder->base;
  381. struct drm_device *dev = encoder->dev;
  382. struct drm_i915_private *dev_priv = dev->dev_private;
  383. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  384. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  385. struct drm_display_mode *adjusted_mode =
  386. &intel_crtc->config.adjusted_mode;
  387. int pipe = intel_crtc->pipe;
  388. unsigned int bpp = intel_crtc->config.pipe_bpp;
  389. u32 val, tmp;
  390. DRM_DEBUG_KMS("pipe %c\n", pipe_name(pipe));
  391. /* escape clock divider, 20MHz, shared for A and C. device ready must be
  392. * off when doing this! txclkesc? */
  393. tmp = I915_READ(MIPI_CTRL(0));
  394. tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
  395. I915_WRITE(MIPI_CTRL(0), tmp | ESCAPE_CLOCK_DIVIDER_1);
  396. /* read request priority is per pipe */
  397. tmp = I915_READ(MIPI_CTRL(pipe));
  398. tmp &= ~READ_REQUEST_PRIORITY_MASK;
  399. I915_WRITE(MIPI_CTRL(pipe), tmp | READ_REQUEST_PRIORITY_HIGH);
  400. /* XXX: why here, why like this? handling in irq handler?! */
  401. I915_WRITE(MIPI_INTR_STAT(pipe), 0xffffffff);
  402. I915_WRITE(MIPI_INTR_EN(pipe), 0xffffffff);
  403. I915_WRITE(MIPI_DPHY_PARAM(pipe), intel_dsi->dphy_reg);
  404. I915_WRITE(MIPI_DPI_RESOLUTION(pipe),
  405. adjusted_mode->vdisplay << VERTICAL_ADDRESS_SHIFT |
  406. adjusted_mode->hdisplay << HORIZONTAL_ADDRESS_SHIFT);
  407. set_dsi_timings(encoder, adjusted_mode);
  408. val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
  409. if (is_cmd_mode(intel_dsi)) {
  410. val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
  411. val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
  412. } else {
  413. val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
  414. /* XXX: cross-check bpp vs. pixel format? */
  415. val |= intel_dsi->pixel_format;
  416. }
  417. I915_WRITE(MIPI_DSI_FUNC_PRG(pipe), val);
  418. /* timeouts for recovery. one frame IIUC. if counter expires, EOT and
  419. * stop state. */
  420. /*
  421. * In burst mode, value greater than one DPI line Time in byte clock
  422. * (txbyteclkhs) To timeout this timer 1+ of the above said value is
  423. * recommended.
  424. *
  425. * In non-burst mode, Value greater than one DPI frame time in byte
  426. * clock(txbyteclkhs) To timeout this timer 1+ of the above said value
  427. * is recommended.
  428. *
  429. * In DBI only mode, value greater than one DBI frame time in byte
  430. * clock(txbyteclkhs) To timeout this timer 1+ of the above said value
  431. * is recommended.
  432. */
  433. if (is_vid_mode(intel_dsi) &&
  434. intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
  435. I915_WRITE(MIPI_HS_TX_TIMEOUT(pipe),
  436. txbyteclkhs(adjusted_mode->htotal, bpp,
  437. intel_dsi->lane_count,
  438. intel_dsi->burst_mode_ratio) + 1);
  439. } else {
  440. I915_WRITE(MIPI_HS_TX_TIMEOUT(pipe),
  441. txbyteclkhs(adjusted_mode->vtotal *
  442. adjusted_mode->htotal,
  443. bpp, intel_dsi->lane_count,
  444. intel_dsi->burst_mode_ratio) + 1);
  445. }
  446. I915_WRITE(MIPI_LP_RX_TIMEOUT(pipe), intel_dsi->lp_rx_timeout);
  447. I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(pipe), intel_dsi->turn_arnd_val);
  448. I915_WRITE(MIPI_DEVICE_RESET_TIMER(pipe), intel_dsi->rst_timer_val);
  449. /* dphy stuff */
  450. /* in terms of low power clock */
  451. I915_WRITE(MIPI_INIT_COUNT(pipe), txclkesc(intel_dsi->escape_clk_div, 100));
  452. val = 0;
  453. if (intel_dsi->eotp_pkt == 0)
  454. val |= EOT_DISABLE;
  455. if (intel_dsi->clock_stop)
  456. val |= CLOCKSTOP;
  457. /* recovery disables */
  458. I915_WRITE(MIPI_EOT_DISABLE(pipe), val);
  459. /* in terms of low power clock */
  460. I915_WRITE(MIPI_INIT_COUNT(pipe), intel_dsi->init_count);
  461. /* in terms of txbyteclkhs. actual high to low switch +
  462. * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
  463. *
  464. * XXX: write MIPI_STOP_STATE_STALL?
  465. */
  466. I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(pipe),
  467. intel_dsi->hs_to_lp_count);
  468. /* XXX: low power clock equivalence in terms of byte clock. the number
  469. * of byte clocks occupied in one low power clock. based on txbyteclkhs
  470. * and txclkesc. txclkesc time / txbyteclk time * (105 +
  471. * MIPI_STOP_STATE_STALL) / 105.???
  472. */
  473. I915_WRITE(MIPI_LP_BYTECLK(pipe), intel_dsi->lp_byte_clk);
  474. /* the bw essential for transmitting 16 long packets containing 252
  475. * bytes meant for dcs write memory command is programmed in this
  476. * register in terms of byte clocks. based on dsi transfer rate and the
  477. * number of lanes configured the time taken to transmit 16 long packets
  478. * in a dsi stream varies. */
  479. I915_WRITE(MIPI_DBI_BW_CTRL(pipe), intel_dsi->bw_timer);
  480. I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(pipe),
  481. intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT |
  482. intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT);
  483. if (is_vid_mode(intel_dsi))
  484. /* Some panels might have resolution which is not a multiple of
  485. * 64 like 1366 x 768. Enable RANDOM resolution support for such
  486. * panels by default */
  487. I915_WRITE(MIPI_VIDEO_MODE_FORMAT(pipe),
  488. intel_dsi->video_frmt_cfg_bits |
  489. intel_dsi->video_mode_format |
  490. IP_TG_CONFIG |
  491. RANDOM_DPI_DISPLAY_RESOLUTION);
  492. }
  493. static void intel_dsi_pre_pll_enable(struct intel_encoder *encoder)
  494. {
  495. DRM_DEBUG_KMS("\n");
  496. intel_dsi_prepare(encoder);
  497. vlv_enable_dsi_pll(encoder);
  498. }
  499. static enum drm_connector_status
  500. intel_dsi_detect(struct drm_connector *connector, bool force)
  501. {
  502. struct intel_dsi *intel_dsi = intel_attached_dsi(connector);
  503. struct intel_encoder *intel_encoder = &intel_dsi->base;
  504. enum intel_display_power_domain power_domain;
  505. enum drm_connector_status connector_status;
  506. struct drm_i915_private *dev_priv = intel_encoder->base.dev->dev_private;
  507. DRM_DEBUG_KMS("\n");
  508. power_domain = intel_display_port_power_domain(intel_encoder);
  509. intel_display_power_get(dev_priv, power_domain);
  510. connector_status = intel_dsi->dev.dev_ops->detect(&intel_dsi->dev);
  511. intel_display_power_put(dev_priv, power_domain);
  512. return connector_status;
  513. }
  514. static int intel_dsi_get_modes(struct drm_connector *connector)
  515. {
  516. struct intel_connector *intel_connector = to_intel_connector(connector);
  517. struct drm_display_mode *mode;
  518. DRM_DEBUG_KMS("\n");
  519. if (!intel_connector->panel.fixed_mode) {
  520. DRM_DEBUG_KMS("no fixed mode\n");
  521. return 0;
  522. }
  523. mode = drm_mode_duplicate(connector->dev,
  524. intel_connector->panel.fixed_mode);
  525. if (!mode) {
  526. DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
  527. return 0;
  528. }
  529. drm_mode_probed_add(connector, mode);
  530. return 1;
  531. }
  532. static void intel_dsi_destroy(struct drm_connector *connector)
  533. {
  534. struct intel_connector *intel_connector = to_intel_connector(connector);
  535. DRM_DEBUG_KMS("\n");
  536. intel_panel_fini(&intel_connector->panel);
  537. drm_connector_cleanup(connector);
  538. kfree(connector);
  539. }
  540. static const struct drm_encoder_funcs intel_dsi_funcs = {
  541. .destroy = intel_encoder_destroy,
  542. };
  543. static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
  544. .get_modes = intel_dsi_get_modes,
  545. .mode_valid = intel_dsi_mode_valid,
  546. .best_encoder = intel_best_encoder,
  547. };
  548. static const struct drm_connector_funcs intel_dsi_connector_funcs = {
  549. .dpms = intel_connector_dpms,
  550. .detect = intel_dsi_detect,
  551. .destroy = intel_dsi_destroy,
  552. .fill_modes = drm_helper_probe_single_connector_modes,
  553. };
  554. void intel_dsi_init(struct drm_device *dev)
  555. {
  556. struct intel_dsi *intel_dsi;
  557. struct intel_encoder *intel_encoder;
  558. struct drm_encoder *encoder;
  559. struct intel_connector *intel_connector;
  560. struct drm_connector *connector;
  561. struct drm_display_mode *fixed_mode = NULL;
  562. struct drm_i915_private *dev_priv = dev->dev_private;
  563. const struct intel_dsi_device *dsi;
  564. unsigned int i;
  565. DRM_DEBUG_KMS("\n");
  566. /* There is no detection method for MIPI so rely on VBT */
  567. if (!dev_priv->vbt.has_mipi)
  568. return;
  569. if (IS_VALLEYVIEW(dev)) {
  570. dev_priv->mipi_mmio_base = VLV_MIPI_BASE;
  571. } else {
  572. DRM_ERROR("Unsupported Mipi device to reg base");
  573. return;
  574. }
  575. intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
  576. if (!intel_dsi)
  577. return;
  578. intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
  579. if (!intel_connector) {
  580. kfree(intel_dsi);
  581. return;
  582. }
  583. intel_encoder = &intel_dsi->base;
  584. encoder = &intel_encoder->base;
  585. intel_dsi->attached_connector = intel_connector;
  586. connector = &intel_connector->base;
  587. drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI);
  588. /* XXX: very likely not all of these are needed */
  589. intel_encoder->hot_plug = intel_dsi_hot_plug;
  590. intel_encoder->compute_config = intel_dsi_compute_config;
  591. intel_encoder->pre_pll_enable = intel_dsi_pre_pll_enable;
  592. intel_encoder->pre_enable = intel_dsi_pre_enable;
  593. intel_encoder->enable = intel_dsi_enable_nop;
  594. intel_encoder->disable = intel_dsi_pre_disable;
  595. intel_encoder->post_disable = intel_dsi_post_disable;
  596. intel_encoder->get_hw_state = intel_dsi_get_hw_state;
  597. intel_encoder->get_config = intel_dsi_get_config;
  598. intel_connector->get_hw_state = intel_connector_get_hw_state;
  599. intel_connector->unregister = intel_connector_unregister;
  600. for (i = 0; i < ARRAY_SIZE(intel_dsi_devices); i++) {
  601. dsi = &intel_dsi_devices[i];
  602. intel_dsi->dev = *dsi;
  603. if (dsi->dev_ops->init(&intel_dsi->dev))
  604. break;
  605. }
  606. if (i == ARRAY_SIZE(intel_dsi_devices)) {
  607. DRM_DEBUG_KMS("no device found\n");
  608. goto err;
  609. }
  610. intel_encoder->type = INTEL_OUTPUT_DSI;
  611. intel_encoder->crtc_mask = (1 << 0); /* XXX */
  612. intel_encoder->cloneable = 0;
  613. drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
  614. DRM_MODE_CONNECTOR_DSI);
  615. drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
  616. connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
  617. connector->interlace_allowed = false;
  618. connector->doublescan_allowed = false;
  619. intel_connector_attach_encoder(intel_connector, intel_encoder);
  620. drm_connector_register(connector);
  621. fixed_mode = dsi->dev_ops->get_modes(&intel_dsi->dev);
  622. if (!fixed_mode) {
  623. DRM_DEBUG_KMS("no fixed mode\n");
  624. goto err;
  625. }
  626. fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
  627. intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
  628. return;
  629. err:
  630. drm_encoder_cleanup(&intel_encoder->base);
  631. kfree(intel_dsi);
  632. kfree(intel_connector);
  633. }