intel_dsi.c 23 KB

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