2 * Copyright © 2013 Intel Corporation
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:
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
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.
23 * Author: Jani Nikula <jani.nikula@intel.com>
26 #include <linux/slab.h>
28 #include <drm/drm_atomic_helper.h>
29 #include <drm/drm_crtc.h>
30 #include <drm/drm_edid.h>
31 #include <drm/drm_mipi_dsi.h>
34 #include "intel_atomic.h"
35 #include "intel_connector.h"
36 #include "intel_display_types.h"
37 #include "intel_dsi.h"
38 #include "intel_fifo_underrun.h"
39 #include "intel_panel.h"
40 #include "intel_sideband.h"
41 #include "skl_scaler.h"
43 /* return pixels in terms of txbyteclkhs */
44 static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count,
47 return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio,
48 8 * 100), lane_count);
51 /* return pixels equvalent to txbyteclkhs */
52 static u16 pixels_from_txbyteclkhs(u16 clk_hs, int bpp, int lane_count,
55 return DIV_ROUND_UP((clk_hs * lane_count * 8 * 100),
56 (bpp * burst_mode_ratio));
59 enum mipi_dsi_pixel_format pixel_format_from_register_bits(u32 fmt)
61 /* It just so happens the VBT matches register contents. */
63 case VID_MODE_FORMAT_RGB888:
64 return MIPI_DSI_FMT_RGB888;
65 case VID_MODE_FORMAT_RGB666:
66 return MIPI_DSI_FMT_RGB666;
67 case VID_MODE_FORMAT_RGB666_PACKED:
68 return MIPI_DSI_FMT_RGB666_PACKED;
69 case VID_MODE_FORMAT_RGB565:
70 return MIPI_DSI_FMT_RGB565;
73 return MIPI_DSI_FMT_RGB666;
77 void vlv_dsi_wait_for_fifo_empty(struct intel_dsi *intel_dsi, enum port port)
79 struct drm_encoder *encoder = &intel_dsi->base.base;
80 struct drm_device *dev = encoder->dev;
81 struct drm_i915_private *dev_priv = to_i915(dev);
84 mask = LP_CTRL_FIFO_EMPTY | HS_CTRL_FIFO_EMPTY |
85 LP_DATA_FIFO_EMPTY | HS_DATA_FIFO_EMPTY;
87 if (intel_de_wait_for_set(dev_priv, MIPI_GEN_FIFO_STAT(port),
89 drm_err(&dev_priv->drm, "DPI FIFOs are not empty\n");
92 static void write_data(struct drm_i915_private *dev_priv,
94 const u8 *data, u32 len)
98 for (i = 0; i < len; i += 4) {
101 for (j = 0; j < min_t(u32, len - i, 4); j++)
102 val |= *data++ << 8 * j;
104 intel_de_write(dev_priv, reg, val);
108 static void read_data(struct drm_i915_private *dev_priv,
114 for (i = 0; i < len; i += 4) {
115 u32 val = intel_de_read(dev_priv, reg);
117 for (j = 0; j < min_t(u32, len - i, 4); j++)
118 *data++ = val >> 8 * j;
122 static ssize_t intel_dsi_host_transfer(struct mipi_dsi_host *host,
123 const struct mipi_dsi_msg *msg)
125 struct intel_dsi_host *intel_dsi_host = to_intel_dsi_host(host);
126 struct drm_device *dev = intel_dsi_host->intel_dsi->base.base.dev;
127 struct drm_i915_private *dev_priv = to_i915(dev);
128 enum port port = intel_dsi_host->port;
129 struct mipi_dsi_packet packet;
131 const u8 *header, *data;
132 i915_reg_t data_reg, ctrl_reg;
133 u32 data_mask, ctrl_mask;
135 ret = mipi_dsi_create_packet(&packet, msg);
139 header = packet.header;
140 data = packet.payload;
142 if (msg->flags & MIPI_DSI_MSG_USE_LPM) {
143 data_reg = MIPI_LP_GEN_DATA(port);
144 data_mask = LP_DATA_FIFO_FULL;
145 ctrl_reg = MIPI_LP_GEN_CTRL(port);
146 ctrl_mask = LP_CTRL_FIFO_FULL;
148 data_reg = MIPI_HS_GEN_DATA(port);
149 data_mask = HS_DATA_FIFO_FULL;
150 ctrl_reg = MIPI_HS_GEN_CTRL(port);
151 ctrl_mask = HS_CTRL_FIFO_FULL;
154 /* note: this is never true for reads */
155 if (packet.payload_length) {
156 if (intel_de_wait_for_clear(dev_priv, MIPI_GEN_FIFO_STAT(port),
158 drm_err(&dev_priv->drm,
159 "Timeout waiting for HS/LP DATA FIFO !full\n");
161 write_data(dev_priv, data_reg, packet.payload,
162 packet.payload_length);
166 intel_de_write(dev_priv, MIPI_INTR_STAT(port),
167 GEN_READ_DATA_AVAIL);
170 if (intel_de_wait_for_clear(dev_priv, MIPI_GEN_FIFO_STAT(port),
172 drm_err(&dev_priv->drm,
173 "Timeout waiting for HS/LP CTRL FIFO !full\n");
176 intel_de_write(dev_priv, ctrl_reg,
177 header[2] << 16 | header[1] << 8 | header[0]);
179 /* ->rx_len is set only for reads */
181 data_mask = GEN_READ_DATA_AVAIL;
182 if (intel_de_wait_for_set(dev_priv, MIPI_INTR_STAT(port),
184 drm_err(&dev_priv->drm,
185 "Timeout waiting for read data.\n");
187 read_data(dev_priv, data_reg, msg->rx_buf, msg->rx_len);
190 /* XXX: fix for reads and writes */
191 return 4 + packet.payload_length;
194 static int intel_dsi_host_attach(struct mipi_dsi_host *host,
195 struct mipi_dsi_device *dsi)
200 static int intel_dsi_host_detach(struct mipi_dsi_host *host,
201 struct mipi_dsi_device *dsi)
206 static const struct mipi_dsi_host_ops intel_dsi_host_ops = {
207 .attach = intel_dsi_host_attach,
208 .detach = intel_dsi_host_detach,
209 .transfer = intel_dsi_host_transfer,
213 * send a video mode command
215 * XXX: commands with data in MIPI_DPI_DATA?
217 static int dpi_send_cmd(struct intel_dsi *intel_dsi, u32 cmd, bool hs,
220 struct drm_encoder *encoder = &intel_dsi->base.base;
221 struct drm_device *dev = encoder->dev;
222 struct drm_i915_private *dev_priv = to_i915(dev);
232 intel_de_write(dev_priv, MIPI_INTR_STAT(port), SPL_PKT_SENT_INTERRUPT);
234 /* XXX: old code skips write if control unchanged */
235 if (cmd == intel_de_read(dev_priv, MIPI_DPI_CONTROL(port)))
236 drm_dbg_kms(&dev_priv->drm,
237 "Same special packet %02x twice in a row.\n", cmd);
239 intel_de_write(dev_priv, MIPI_DPI_CONTROL(port), cmd);
241 mask = SPL_PKT_SENT_INTERRUPT;
242 if (intel_de_wait_for_set(dev_priv, MIPI_INTR_STAT(port), mask, 100))
243 drm_err(&dev_priv->drm,
244 "Video mode command 0x%08x send failed.\n", cmd);
249 static void band_gap_reset(struct drm_i915_private *dev_priv)
251 vlv_flisdsi_get(dev_priv);
253 vlv_flisdsi_write(dev_priv, 0x08, 0x0001);
254 vlv_flisdsi_write(dev_priv, 0x0F, 0x0005);
255 vlv_flisdsi_write(dev_priv, 0x0F, 0x0025);
257 vlv_flisdsi_write(dev_priv, 0x0F, 0x0000);
258 vlv_flisdsi_write(dev_priv, 0x08, 0x0000);
260 vlv_flisdsi_put(dev_priv);
263 static int intel_dsi_compute_config(struct intel_encoder *encoder,
264 struct intel_crtc_state *pipe_config,
265 struct drm_connector_state *conn_state)
267 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
268 struct intel_dsi *intel_dsi = container_of(encoder, struct intel_dsi,
270 struct intel_connector *intel_connector = intel_dsi->attached_connector;
271 const struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
272 struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
275 drm_dbg_kms(&dev_priv->drm, "\n");
276 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
279 intel_fixed_panel_mode(fixed_mode, adjusted_mode);
281 if (HAS_GMCH(dev_priv))
282 ret = intel_gmch_panel_fitting(pipe_config, conn_state);
284 ret = intel_pch_panel_fitting(pipe_config, conn_state);
289 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN)
292 /* DSI uses short packets for sync events, so clear mode flags for DSI */
293 adjusted_mode->flags = 0;
295 if (intel_dsi->pixel_format == MIPI_DSI_FMT_RGB888)
296 pipe_config->pipe_bpp = 24;
298 pipe_config->pipe_bpp = 18;
300 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
301 /* Enable Frame time stamp based scanline reporting */
302 pipe_config->mode_flags |=
303 I915_MODE_FLAG_GET_SCANLINE_FROM_TIMESTAMP;
305 /* Dual link goes to DSI transcoder A. */
306 if (intel_dsi->ports == BIT(PORT_C))
307 pipe_config->cpu_transcoder = TRANSCODER_DSI_C;
309 pipe_config->cpu_transcoder = TRANSCODER_DSI_A;
311 ret = bxt_dsi_pll_compute(encoder, pipe_config);
315 ret = vlv_dsi_pll_compute(encoder, pipe_config);
320 pipe_config->clock_set = true;
325 static bool glk_dsi_enable_io(struct intel_encoder *encoder)
327 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
328 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
331 bool cold_boot = false;
334 * If MIPI_Mode is off, then writing to LP_Wake bit is not reflecting.
335 * Power ON MIPI IO first and then write into IO reset and LP wake bits
337 for_each_dsi_port(port, intel_dsi->ports) {
338 tmp = intel_de_read(dev_priv, MIPI_CTRL(port));
339 intel_de_write(dev_priv, MIPI_CTRL(port),
340 tmp | GLK_MIPIIO_ENABLE);
343 /* Put the IO into reset */
344 tmp = intel_de_read(dev_priv, MIPI_CTRL(PORT_A));
345 tmp &= ~GLK_MIPIIO_RESET_RELEASED;
346 intel_de_write(dev_priv, MIPI_CTRL(PORT_A), tmp);
348 /* Program LP Wake */
349 for_each_dsi_port(port, intel_dsi->ports) {
350 tmp = intel_de_read(dev_priv, MIPI_CTRL(port));
351 if (!(intel_de_read(dev_priv, MIPI_DEVICE_READY(port)) & DEVICE_READY))
355 intel_de_write(dev_priv, MIPI_CTRL(port), tmp);
358 /* Wait for Pwr ACK */
359 for_each_dsi_port(port, intel_dsi->ports) {
360 if (intel_de_wait_for_set(dev_priv, MIPI_CTRL(port),
361 GLK_MIPIIO_PORT_POWERED, 20))
362 drm_err(&dev_priv->drm, "MIPIO port is powergated\n");
365 /* Check for cold boot scenario */
366 for_each_dsi_port(port, intel_dsi->ports) {
368 !(intel_de_read(dev_priv, MIPI_DEVICE_READY(port)) & DEVICE_READY);
374 static void glk_dsi_device_ready(struct intel_encoder *encoder)
376 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
377 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
381 /* Wait for MIPI PHY status bit to set */
382 for_each_dsi_port(port, intel_dsi->ports) {
383 if (intel_de_wait_for_set(dev_priv, MIPI_CTRL(port),
384 GLK_PHY_STATUS_PORT_READY, 20))
385 drm_err(&dev_priv->drm, "PHY is not ON\n");
388 /* Get IO out of reset */
389 val = intel_de_read(dev_priv, MIPI_CTRL(PORT_A));
390 intel_de_write(dev_priv, MIPI_CTRL(PORT_A),
391 val | GLK_MIPIIO_RESET_RELEASED);
393 /* Get IO out of Low power state*/
394 for_each_dsi_port(port, intel_dsi->ports) {
395 if (!(intel_de_read(dev_priv, MIPI_DEVICE_READY(port)) & DEVICE_READY)) {
396 val = intel_de_read(dev_priv, MIPI_DEVICE_READY(port));
397 val &= ~ULPS_STATE_MASK;
399 intel_de_write(dev_priv, MIPI_DEVICE_READY(port), val);
400 usleep_range(10, 15);
403 val = intel_de_read(dev_priv, MIPI_DEVICE_READY(port));
404 val &= ~ULPS_STATE_MASK;
405 val |= (ULPS_STATE_ENTER | DEVICE_READY);
406 intel_de_write(dev_priv, MIPI_DEVICE_READY(port), val);
408 /* Wait for ULPS active */
409 if (intel_de_wait_for_clear(dev_priv, MIPI_CTRL(port),
410 GLK_ULPS_NOT_ACTIVE, 20))
411 drm_err(&dev_priv->drm, "ULPS not active\n");
414 val = intel_de_read(dev_priv, MIPI_DEVICE_READY(port));
415 val &= ~ULPS_STATE_MASK;
416 val |= (ULPS_STATE_EXIT | DEVICE_READY);
417 intel_de_write(dev_priv, MIPI_DEVICE_READY(port), val);
419 /* Enter Normal Mode */
420 val = intel_de_read(dev_priv, MIPI_DEVICE_READY(port));
421 val &= ~ULPS_STATE_MASK;
422 val |= (ULPS_STATE_NORMAL_OPERATION | DEVICE_READY);
423 intel_de_write(dev_priv, MIPI_DEVICE_READY(port), val);
425 val = intel_de_read(dev_priv, MIPI_CTRL(port));
427 intel_de_write(dev_priv, MIPI_CTRL(port), val);
431 /* Wait for Stop state */
432 for_each_dsi_port(port, intel_dsi->ports) {
433 if (intel_de_wait_for_set(dev_priv, MIPI_CTRL(port),
434 GLK_DATA_LANE_STOP_STATE, 20))
435 drm_err(&dev_priv->drm,
436 "Date lane not in STOP state\n");
439 /* Wait for AFE LATCH */
440 for_each_dsi_port(port, intel_dsi->ports) {
441 if (intel_de_wait_for_set(dev_priv, BXT_MIPI_PORT_CTRL(port),
443 drm_err(&dev_priv->drm,
444 "D-PHY not entering LP-11 state\n");
448 static void bxt_dsi_device_ready(struct intel_encoder *encoder)
450 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
451 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
455 drm_dbg_kms(&dev_priv->drm, "\n");
457 /* Enable MIPI PHY transparent latch */
458 for_each_dsi_port(port, intel_dsi->ports) {
459 val = intel_de_read(dev_priv, BXT_MIPI_PORT_CTRL(port));
460 intel_de_write(dev_priv, BXT_MIPI_PORT_CTRL(port),
461 val | LP_OUTPUT_HOLD);
462 usleep_range(2000, 2500);
465 /* Clear ULPS and set device ready */
466 for_each_dsi_port(port, intel_dsi->ports) {
467 val = intel_de_read(dev_priv, MIPI_DEVICE_READY(port));
468 val &= ~ULPS_STATE_MASK;
469 intel_de_write(dev_priv, MIPI_DEVICE_READY(port), val);
470 usleep_range(2000, 2500);
472 intel_de_write(dev_priv, MIPI_DEVICE_READY(port), val);
476 static void vlv_dsi_device_ready(struct intel_encoder *encoder)
478 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
479 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
483 drm_dbg_kms(&dev_priv->drm, "\n");
485 vlv_flisdsi_get(dev_priv);
486 /* program rcomp for compliance, reduce from 50 ohms to 45 ohms
487 * needed everytime after power gate */
488 vlv_flisdsi_write(dev_priv, 0x04, 0x0004);
489 vlv_flisdsi_put(dev_priv);
491 /* bandgap reset is needed after everytime we do power gate */
492 band_gap_reset(dev_priv);
494 for_each_dsi_port(port, intel_dsi->ports) {
496 intel_de_write(dev_priv, MIPI_DEVICE_READY(port),
498 usleep_range(2500, 3000);
500 /* Enable MIPI PHY transparent latch
501 * Common bit for both MIPI Port A & MIPI Port C
502 * No similar bit in MIPI Port C reg
504 val = intel_de_read(dev_priv, MIPI_PORT_CTRL(PORT_A));
505 intel_de_write(dev_priv, MIPI_PORT_CTRL(PORT_A),
506 val | LP_OUTPUT_HOLD);
507 usleep_range(1000, 1500);
509 intel_de_write(dev_priv, MIPI_DEVICE_READY(port),
511 usleep_range(2500, 3000);
513 intel_de_write(dev_priv, MIPI_DEVICE_READY(port),
515 usleep_range(2500, 3000);
519 static void intel_dsi_device_ready(struct intel_encoder *encoder)
521 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
523 if (IS_GEMINILAKE(dev_priv))
524 glk_dsi_device_ready(encoder);
525 else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
526 bxt_dsi_device_ready(encoder);
528 vlv_dsi_device_ready(encoder);
531 static void glk_dsi_enter_low_power_mode(struct intel_encoder *encoder)
533 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
534 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
539 for_each_dsi_port(port, intel_dsi->ports) {
540 val = intel_de_read(dev_priv, MIPI_DEVICE_READY(port));
541 val &= ~ULPS_STATE_MASK;
542 val |= (ULPS_STATE_ENTER | DEVICE_READY);
543 intel_de_write(dev_priv, MIPI_DEVICE_READY(port), val);
546 /* Wait for MIPI PHY status bit to unset */
547 for_each_dsi_port(port, intel_dsi->ports) {
548 if (intel_de_wait_for_clear(dev_priv, MIPI_CTRL(port),
549 GLK_PHY_STATUS_PORT_READY, 20))
550 drm_err(&dev_priv->drm, "PHY is not turning OFF\n");
553 /* Wait for Pwr ACK bit to unset */
554 for_each_dsi_port(port, intel_dsi->ports) {
555 if (intel_de_wait_for_clear(dev_priv, MIPI_CTRL(port),
556 GLK_MIPIIO_PORT_POWERED, 20))
557 drm_err(&dev_priv->drm,
558 "MIPI IO Port is not powergated\n");
562 static void glk_dsi_disable_mipi_io(struct intel_encoder *encoder)
564 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
565 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
569 /* Put the IO into reset */
570 tmp = intel_de_read(dev_priv, MIPI_CTRL(PORT_A));
571 tmp &= ~GLK_MIPIIO_RESET_RELEASED;
572 intel_de_write(dev_priv, MIPI_CTRL(PORT_A), tmp);
574 /* Wait for MIPI PHY status bit to unset */
575 for_each_dsi_port(port, intel_dsi->ports) {
576 if (intel_de_wait_for_clear(dev_priv, MIPI_CTRL(port),
577 GLK_PHY_STATUS_PORT_READY, 20))
578 drm_err(&dev_priv->drm, "PHY is not turning OFF\n");
581 /* Clear MIPI mode */
582 for_each_dsi_port(port, intel_dsi->ports) {
583 tmp = intel_de_read(dev_priv, MIPI_CTRL(port));
584 tmp &= ~GLK_MIPIIO_ENABLE;
585 intel_de_write(dev_priv, MIPI_CTRL(port), tmp);
589 static void glk_dsi_clear_device_ready(struct intel_encoder *encoder)
591 glk_dsi_enter_low_power_mode(encoder);
592 glk_dsi_disable_mipi_io(encoder);
595 static void vlv_dsi_clear_device_ready(struct intel_encoder *encoder)
597 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
598 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
601 drm_dbg_kms(&dev_priv->drm, "\n");
602 for_each_dsi_port(port, intel_dsi->ports) {
603 /* Common bit for both MIPI Port A & MIPI Port C on VLV/CHV */
604 i915_reg_t port_ctrl = IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv) ?
605 BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(PORT_A);
608 intel_de_write(dev_priv, MIPI_DEVICE_READY(port),
609 DEVICE_READY | ULPS_STATE_ENTER);
610 usleep_range(2000, 2500);
612 intel_de_write(dev_priv, MIPI_DEVICE_READY(port),
613 DEVICE_READY | ULPS_STATE_EXIT);
614 usleep_range(2000, 2500);
616 intel_de_write(dev_priv, MIPI_DEVICE_READY(port),
617 DEVICE_READY | ULPS_STATE_ENTER);
618 usleep_range(2000, 2500);
621 * On VLV/CHV, wait till Clock lanes are in LP-00 state for MIPI
622 * Port A only. MIPI Port C has no similar bit for checking.
624 if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv) || port == PORT_A) &&
625 intel_de_wait_for_clear(dev_priv, port_ctrl,
627 drm_err(&dev_priv->drm, "DSI LP not going Low\n");
629 /* Disable MIPI PHY transparent latch */
630 val = intel_de_read(dev_priv, port_ctrl);
631 intel_de_write(dev_priv, port_ctrl, val & ~LP_OUTPUT_HOLD);
632 usleep_range(1000, 1500);
634 intel_de_write(dev_priv, MIPI_DEVICE_READY(port), 0x00);
635 usleep_range(2000, 2500);
639 static void intel_dsi_port_enable(struct intel_encoder *encoder,
640 const struct intel_crtc_state *crtc_state)
642 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
643 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
644 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
647 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) {
649 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
650 for_each_dsi_port(port, intel_dsi->ports) {
651 temp = intel_de_read(dev_priv,
653 temp &= ~BXT_PIXEL_OVERLAP_CNT_MASK |
654 intel_dsi->pixel_overlap <<
655 BXT_PIXEL_OVERLAP_CNT_SHIFT;
656 intel_de_write(dev_priv, MIPI_CTRL(port),
660 temp = intel_de_read(dev_priv, VLV_CHICKEN_3);
661 temp &= ~PIXEL_OVERLAP_CNT_MASK |
662 intel_dsi->pixel_overlap <<
663 PIXEL_OVERLAP_CNT_SHIFT;
664 intel_de_write(dev_priv, VLV_CHICKEN_3, temp);
668 for_each_dsi_port(port, intel_dsi->ports) {
669 i915_reg_t port_ctrl = IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv) ?
670 BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
673 temp = intel_de_read(dev_priv, port_ctrl);
675 temp &= ~LANE_CONFIGURATION_MASK;
676 temp &= ~DUAL_LINK_MODE_MASK;
678 if (intel_dsi->ports == (BIT(PORT_A) | BIT(PORT_C))) {
679 temp |= (intel_dsi->dual_link - 1)
680 << DUAL_LINK_MODE_SHIFT;
681 if (IS_BROXTON(dev_priv))
682 temp |= LANE_CONFIGURATION_DUAL_LINK_A;
685 LANE_CONFIGURATION_DUAL_LINK_B :
686 LANE_CONFIGURATION_DUAL_LINK_A;
689 if (intel_dsi->pixel_format != MIPI_DSI_FMT_RGB888)
690 temp |= DITHERING_ENABLE;
692 /* assert ip_tg_enable signal */
693 intel_de_write(dev_priv, port_ctrl, temp | DPI_ENABLE);
694 intel_de_posting_read(dev_priv, port_ctrl);
698 static void intel_dsi_port_disable(struct intel_encoder *encoder)
700 struct drm_device *dev = encoder->base.dev;
701 struct drm_i915_private *dev_priv = to_i915(dev);
702 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
705 for_each_dsi_port(port, intel_dsi->ports) {
706 i915_reg_t port_ctrl = IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv) ?
707 BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
710 /* de-assert ip_tg_enable signal */
711 temp = intel_de_read(dev_priv, port_ctrl);
712 intel_de_write(dev_priv, port_ctrl, temp & ~DPI_ENABLE);
713 intel_de_posting_read(dev_priv, port_ctrl);
717 static void intel_dsi_wait_panel_power_cycle(struct intel_dsi *intel_dsi)
719 ktime_t panel_power_on_time;
720 s64 panel_power_off_duration;
722 panel_power_on_time = ktime_get_boottime();
723 panel_power_off_duration = ktime_ms_delta(panel_power_on_time,
724 intel_dsi->panel_power_off_time);
726 if (panel_power_off_duration < (s64)intel_dsi->panel_pwr_cycle_delay)
727 msleep(intel_dsi->panel_pwr_cycle_delay - panel_power_off_duration);
730 static void intel_dsi_prepare(struct intel_encoder *intel_encoder,
731 const struct intel_crtc_state *pipe_config);
732 static void intel_dsi_unprepare(struct intel_encoder *encoder);
735 * Panel enable/disable sequences from the VBT spec.
737 * Note the spec has AssertReset / DeassertReset swapped from their
738 * usual naming. We use the normal names to avoid confusion (so below
739 * they are swapped compared to the spec).
741 * Steps starting with MIPI refer to VBT sequences, note that for v2
742 * VBTs several steps which have a VBT in v2 are expected to be handled
743 * directly by the driver, by directly driving gpios for example.
745 * v2 video mode seq v3 video mode seq command mode seq
746 * - power on - MIPIPanelPowerOn - power on
747 * - wait t1+t2 - wait t1+t2
748 * - MIPIDeassertResetPin - MIPIDeassertResetPin - MIPIDeassertResetPin
749 * - io lines to lp-11 - io lines to lp-11 - io lines to lp-11
750 * - MIPISendInitialDcsCmds - MIPISendInitialDcsCmds - MIPISendInitialDcsCmds
753 * - turn on DPI - turn on DPI - set pipe to dsr mode
754 * - MIPIDisplayOn - MIPIDisplayOn
755 * - wait t5 - wait t5
756 * - backlight on - MIPIBacklightOn - backlight on
757 * ... ... ... issue mem cmds ...
758 * - backlight off - MIPIBacklightOff - backlight off
759 * - wait t6 - wait t6
761 * - turn off DPI - turn off DPI - disable pipe dsr mode
763 * - MIPIDisplayOff - MIPIDisplayOff
764 * - io lines to lp-00 - io lines to lp-00 - io lines to lp-00
765 * - MIPIAssertResetPin - MIPIAssertResetPin - MIPIAssertResetPin
766 * - wait t3 - wait t3
767 * - power off - MIPIPanelPowerOff - power off
768 * - wait t4 - wait t4
772 * DSI port enable has to be done before pipe and plane enable, so we do it in
773 * the pre_enable hook instead of the enable hook.
775 static void intel_dsi_pre_enable(struct intel_atomic_state *state,
776 struct intel_encoder *encoder,
777 const struct intel_crtc_state *pipe_config,
778 const struct drm_connector_state *conn_state)
780 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
781 struct drm_crtc *crtc = pipe_config->uapi.crtc;
782 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
783 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
784 enum pipe pipe = intel_crtc->pipe;
787 bool glk_cold_boot = false;
789 drm_dbg_kms(&dev_priv->drm, "\n");
791 intel_dsi_wait_panel_power_cycle(intel_dsi);
793 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
796 * The BIOS may leave the PLL in a wonky state where it doesn't
797 * lock. It needs to be fully powered down to fix it.
799 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
800 bxt_dsi_pll_disable(encoder);
801 bxt_dsi_pll_enable(encoder, pipe_config);
803 vlv_dsi_pll_disable(encoder);
804 vlv_dsi_pll_enable(encoder, pipe_config);
807 if (IS_BROXTON(dev_priv)) {
808 /* Add MIPI IO reset programming for modeset */
809 val = intel_de_read(dev_priv, BXT_P_CR_GT_DISP_PWRON);
810 intel_de_write(dev_priv, BXT_P_CR_GT_DISP_PWRON,
811 val | MIPIO_RST_CTRL);
813 /* Power up DSI regulator */
814 intel_de_write(dev_priv, BXT_P_DSI_REGULATOR_CFG, STAP_SELECT);
815 intel_de_write(dev_priv, BXT_P_DSI_REGULATOR_TX_CTRL, 0);
818 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
821 /* Disable DPOunit clock gating, can stall pipe */
822 val = intel_de_read(dev_priv, DSPCLK_GATE_D);
823 val |= DPOUNIT_CLOCK_GATE_DISABLE;
824 intel_de_write(dev_priv, DSPCLK_GATE_D, val);
827 if (!IS_GEMINILAKE(dev_priv))
828 intel_dsi_prepare(encoder, pipe_config);
830 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_POWER_ON);
833 * Give the panel time to power-on and then deassert its reset.
834 * Depending on the VBT MIPI sequences version the deassert-seq
835 * may contain the necessary delay, intel_dsi_msleep() will skip
836 * the delay in that case. If there is no deassert-seq, then an
837 * unconditional msleep is used to give the panel time to power-on.
839 if (dev_priv->vbt.dsi.sequence[MIPI_SEQ_DEASSERT_RESET]) {
840 intel_dsi_msleep(intel_dsi, intel_dsi->panel_on_delay);
841 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DEASSERT_RESET);
843 msleep(intel_dsi->panel_on_delay);
846 if (IS_GEMINILAKE(dev_priv)) {
847 glk_cold_boot = glk_dsi_enable_io(encoder);
849 /* Prepare port in cold boot(s3/s4) scenario */
851 intel_dsi_prepare(encoder, pipe_config);
854 /* Put device in ready state (LP-11) */
855 intel_dsi_device_ready(encoder);
857 /* Prepare port in normal boot scenario */
858 if (IS_GEMINILAKE(dev_priv) && !glk_cold_boot)
859 intel_dsi_prepare(encoder, pipe_config);
861 /* Send initialization commands in LP mode */
862 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_INIT_OTP);
864 /* Enable port in pre-enable phase itself because as per hw team
865 * recommendation, port should be enabled befor plane & pipe */
866 if (is_cmd_mode(intel_dsi)) {
867 for_each_dsi_port(port, intel_dsi->ports)
868 intel_de_write(dev_priv,
869 MIPI_MAX_RETURN_PKT_SIZE(port), 8 * 4);
870 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_TEAR_ON);
871 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_ON);
873 msleep(20); /* XXX */
874 for_each_dsi_port(port, intel_dsi->ports)
875 dpi_send_cmd(intel_dsi, TURN_ON, false, port);
876 intel_dsi_msleep(intel_dsi, 100);
878 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_ON);
880 intel_dsi_port_enable(encoder, pipe_config);
883 intel_panel_enable_backlight(pipe_config, conn_state);
884 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_BACKLIGHT_ON);
887 static void bxt_dsi_enable(struct intel_atomic_state *state,
888 struct intel_encoder *encoder,
889 const struct intel_crtc_state *crtc_state,
890 const struct drm_connector_state *conn_state)
892 drm_WARN_ON(state->base.dev, crtc_state->has_pch_encoder);
894 intel_crtc_vblank_on(crtc_state);
898 * DSI port disable has to be done after pipe and plane disable, so we do it in
899 * the post_disable hook.
901 static void intel_dsi_disable(struct intel_atomic_state *state,
902 struct intel_encoder *encoder,
903 const struct intel_crtc_state *old_crtc_state,
904 const struct drm_connector_state *old_conn_state)
906 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
907 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
910 drm_dbg_kms(&i915->drm, "\n");
912 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_BACKLIGHT_OFF);
913 intel_panel_disable_backlight(old_conn_state);
916 * According to the spec we should send SHUTDOWN before
917 * MIPI_SEQ_DISPLAY_OFF only for v3+ VBTs, but field testing
918 * has shown that the v3 sequence works for v2 VBTs too
920 if (is_vid_mode(intel_dsi)) {
921 /* Send Shutdown command to the panel in LP mode */
922 for_each_dsi_port(port, intel_dsi->ports)
923 dpi_send_cmd(intel_dsi, SHUTDOWN, false, port);
928 static void intel_dsi_clear_device_ready(struct intel_encoder *encoder)
930 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
932 if (IS_GEMINILAKE(dev_priv))
933 glk_dsi_clear_device_ready(encoder);
935 vlv_dsi_clear_device_ready(encoder);
938 static void intel_dsi_post_disable(struct intel_atomic_state *state,
939 struct intel_encoder *encoder,
940 const struct intel_crtc_state *old_crtc_state,
941 const struct drm_connector_state *old_conn_state)
943 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
944 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
948 drm_dbg_kms(&dev_priv->drm, "\n");
950 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
951 intel_crtc_vblank_off(old_crtc_state);
953 skl_scaler_disable(old_crtc_state);
956 if (is_vid_mode(intel_dsi)) {
957 for_each_dsi_port(port, intel_dsi->ports)
958 vlv_dsi_wait_for_fifo_empty(intel_dsi, port);
960 intel_dsi_port_disable(encoder);
961 usleep_range(2000, 5000);
964 intel_dsi_unprepare(encoder);
967 * if disable packets are sent before sending shutdown packet then in
968 * some next enable sequence send turn on packet error is observed
970 if (is_cmd_mode(intel_dsi))
971 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_TEAR_OFF);
972 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_OFF);
974 /* Transition to LP-00 */
975 intel_dsi_clear_device_ready(encoder);
977 if (IS_BROXTON(dev_priv)) {
978 /* Power down DSI regulator to save power */
979 intel_de_write(dev_priv, BXT_P_DSI_REGULATOR_CFG, STAP_SELECT);
980 intel_de_write(dev_priv, BXT_P_DSI_REGULATOR_TX_CTRL,
983 /* Add MIPI IO reset programming for modeset */
984 val = intel_de_read(dev_priv, BXT_P_CR_GT_DISP_PWRON);
985 intel_de_write(dev_priv, BXT_P_CR_GT_DISP_PWRON,
986 val & ~MIPIO_RST_CTRL);
989 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
990 bxt_dsi_pll_disable(encoder);
994 vlv_dsi_pll_disable(encoder);
996 val = intel_de_read(dev_priv, DSPCLK_GATE_D);
997 val &= ~DPOUNIT_CLOCK_GATE_DISABLE;
998 intel_de_write(dev_priv, DSPCLK_GATE_D, val);
1002 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_ASSERT_RESET);
1004 intel_dsi_msleep(intel_dsi, intel_dsi->panel_off_delay);
1005 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_POWER_OFF);
1007 intel_dsi->panel_power_off_time = ktime_get_boottime();
1010 static void intel_dsi_shutdown(struct intel_encoder *encoder)
1012 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
1014 intel_dsi_wait_panel_power_cycle(intel_dsi);
1017 static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
1020 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1021 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
1022 intel_wakeref_t wakeref;
1024 bool active = false;
1026 drm_dbg_kms(&dev_priv->drm, "\n");
1028 wakeref = intel_display_power_get_if_enabled(dev_priv,
1029 encoder->power_domain);
1034 * On Broxton the PLL needs to be enabled with a valid divider
1035 * configuration, otherwise accessing DSI registers will hang the
1036 * machine. See BSpec North Display Engine registers/MIPI[BXT].
1038 if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) &&
1039 !bxt_dsi_pll_is_enabled(dev_priv))
1042 /* XXX: this only works for one DSI output */
1043 for_each_dsi_port(port, intel_dsi->ports) {
1044 i915_reg_t ctrl_reg = IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv) ?
1045 BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
1046 bool enabled = intel_de_read(dev_priv, ctrl_reg) & DPI_ENABLE;
1049 * Due to some hardware limitations on VLV/CHV, the DPI enable
1050 * bit in port C control register does not get set. As a
1051 * workaround, check pipe B conf instead.
1053 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
1055 enabled = intel_de_read(dev_priv, PIPECONF(PIPE_B)) & PIPECONF_ENABLE;
1057 /* Try command mode if video mode not enabled */
1059 u32 tmp = intel_de_read(dev_priv,
1060 MIPI_DSI_FUNC_PRG(port));
1061 enabled = tmp & CMD_MODE_DATA_WIDTH_MASK;
1067 if (!(intel_de_read(dev_priv, MIPI_DEVICE_READY(port)) & DEVICE_READY))
1070 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
1071 u32 tmp = intel_de_read(dev_priv, MIPI_CTRL(port));
1072 tmp &= BXT_PIPE_SELECT_MASK;
1073 tmp >>= BXT_PIPE_SELECT_SHIFT;
1075 if (drm_WARN_ON(&dev_priv->drm, tmp > PIPE_C))
1080 *pipe = port == PORT_A ? PIPE_A : PIPE_B;
1088 intel_display_power_put(dev_priv, encoder->power_domain, wakeref);
1093 static void bxt_dsi_get_pipe_config(struct intel_encoder *encoder,
1094 struct intel_crtc_state *pipe_config)
1096 struct drm_device *dev = encoder->base.dev;
1097 struct drm_i915_private *dev_priv = to_i915(dev);
1098 struct drm_display_mode *adjusted_mode =
1099 &pipe_config->hw.adjusted_mode;
1100 struct drm_display_mode *adjusted_mode_sw;
1101 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
1102 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
1103 unsigned int lane_count = intel_dsi->lane_count;
1104 unsigned int bpp, fmt;
1106 u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
1107 u16 hfp_sw, hsync_sw, hbp_sw;
1108 u16 crtc_htotal_sw, crtc_hsync_start_sw, crtc_hsync_end_sw,
1109 crtc_hblank_start_sw, crtc_hblank_end_sw;
1111 /* FIXME: hw readout should not depend on SW state */
1112 adjusted_mode_sw = &crtc->config->hw.adjusted_mode;
1115 * Atleast one port is active as encoder->get_config called only if
1116 * encoder->get_hw_state() returns true.
1118 for_each_dsi_port(port, intel_dsi->ports) {
1119 if (intel_de_read(dev_priv, BXT_MIPI_PORT_CTRL(port)) & DPI_ENABLE)
1123 fmt = intel_de_read(dev_priv, MIPI_DSI_FUNC_PRG(port)) & VID_MODE_FORMAT_MASK;
1124 bpp = mipi_dsi_pixel_format_to_bpp(
1125 pixel_format_from_register_bits(fmt));
1127 pipe_config->pipe_bpp = bdw_get_pipemisc_bpp(crtc);
1129 /* Enable Frame time stamo based scanline reporting */
1130 pipe_config->mode_flags |=
1131 I915_MODE_FLAG_GET_SCANLINE_FROM_TIMESTAMP;
1133 /* In terms of pixels */
1134 adjusted_mode->crtc_hdisplay =
1135 intel_de_read(dev_priv,
1136 BXT_MIPI_TRANS_HACTIVE(port));
1137 adjusted_mode->crtc_vdisplay =
1138 intel_de_read(dev_priv,
1139 BXT_MIPI_TRANS_VACTIVE(port));
1140 adjusted_mode->crtc_vtotal =
1141 intel_de_read(dev_priv,
1142 BXT_MIPI_TRANS_VTOTAL(port));
1144 hactive = adjusted_mode->crtc_hdisplay;
1145 hfp = intel_de_read(dev_priv, MIPI_HFP_COUNT(port));
1148 * Meaningful for video mode non-burst sync pulse mode only,
1149 * can be zero for non-burst sync events and burst modes
1151 hsync = intel_de_read(dev_priv, MIPI_HSYNC_PADDING_COUNT(port));
1152 hbp = intel_de_read(dev_priv, MIPI_HBP_COUNT(port));
1154 /* harizontal values are in terms of high speed byte clock */
1155 hfp = pixels_from_txbyteclkhs(hfp, bpp, lane_count,
1156 intel_dsi->burst_mode_ratio);
1157 hsync = pixels_from_txbyteclkhs(hsync, bpp, lane_count,
1158 intel_dsi->burst_mode_ratio);
1159 hbp = pixels_from_txbyteclkhs(hbp, bpp, lane_count,
1160 intel_dsi->burst_mode_ratio);
1162 if (intel_dsi->dual_link) {
1168 /* vertical values are in terms of lines */
1169 vfp = intel_de_read(dev_priv, MIPI_VFP_COUNT(port));
1170 vsync = intel_de_read(dev_priv, MIPI_VSYNC_PADDING_COUNT(port));
1171 vbp = intel_de_read(dev_priv, MIPI_VBP_COUNT(port));
1173 adjusted_mode->crtc_htotal = hactive + hfp + hsync + hbp;
1174 adjusted_mode->crtc_hsync_start = hfp + adjusted_mode->crtc_hdisplay;
1175 adjusted_mode->crtc_hsync_end = hsync + adjusted_mode->crtc_hsync_start;
1176 adjusted_mode->crtc_hblank_start = adjusted_mode->crtc_hdisplay;
1177 adjusted_mode->crtc_hblank_end = adjusted_mode->crtc_htotal;
1179 adjusted_mode->crtc_vsync_start = vfp + adjusted_mode->crtc_vdisplay;
1180 adjusted_mode->crtc_vsync_end = vsync + adjusted_mode->crtc_vsync_start;
1181 adjusted_mode->crtc_vblank_start = adjusted_mode->crtc_vdisplay;
1182 adjusted_mode->crtc_vblank_end = adjusted_mode->crtc_vtotal;
1185 * In BXT DSI there is no regs programmed with few horizontal timings
1186 * in Pixels but txbyteclkhs.. So retrieval process adds some
1187 * ROUND_UP ERRORS in the process of PIXELS<==>txbyteclkhs.
1188 * Actually here for the given adjusted_mode, we are calculating the
1189 * value programmed to the port and then back to the horizontal timing
1190 * param in pixels. This is the expected value, including roundup errors
1191 * And if that is same as retrieved value from port, then
1192 * (HW state) adjusted_mode's horizontal timings are corrected to
1193 * match with SW state to nullify the errors.
1195 /* Calculating the value programmed to the Port register */
1196 hfp_sw = adjusted_mode_sw->crtc_hsync_start -
1197 adjusted_mode_sw->crtc_hdisplay;
1198 hsync_sw = adjusted_mode_sw->crtc_hsync_end -
1199 adjusted_mode_sw->crtc_hsync_start;
1200 hbp_sw = adjusted_mode_sw->crtc_htotal -
1201 adjusted_mode_sw->crtc_hsync_end;
1203 if (intel_dsi->dual_link) {
1209 hfp_sw = txbyteclkhs(hfp_sw, bpp, lane_count,
1210 intel_dsi->burst_mode_ratio);
1211 hsync_sw = txbyteclkhs(hsync_sw, bpp, lane_count,
1212 intel_dsi->burst_mode_ratio);
1213 hbp_sw = txbyteclkhs(hbp_sw, bpp, lane_count,
1214 intel_dsi->burst_mode_ratio);
1216 /* Reverse calculating the adjusted mode parameters from port reg vals*/
1217 hfp_sw = pixels_from_txbyteclkhs(hfp_sw, bpp, lane_count,
1218 intel_dsi->burst_mode_ratio);
1219 hsync_sw = pixels_from_txbyteclkhs(hsync_sw, bpp, lane_count,
1220 intel_dsi->burst_mode_ratio);
1221 hbp_sw = pixels_from_txbyteclkhs(hbp_sw, bpp, lane_count,
1222 intel_dsi->burst_mode_ratio);
1224 if (intel_dsi->dual_link) {
1230 crtc_htotal_sw = adjusted_mode_sw->crtc_hdisplay + hfp_sw +
1232 crtc_hsync_start_sw = hfp_sw + adjusted_mode_sw->crtc_hdisplay;
1233 crtc_hsync_end_sw = hsync_sw + crtc_hsync_start_sw;
1234 crtc_hblank_start_sw = adjusted_mode_sw->crtc_hdisplay;
1235 crtc_hblank_end_sw = crtc_htotal_sw;
1237 if (adjusted_mode->crtc_htotal == crtc_htotal_sw)
1238 adjusted_mode->crtc_htotal = adjusted_mode_sw->crtc_htotal;
1240 if (adjusted_mode->crtc_hsync_start == crtc_hsync_start_sw)
1241 adjusted_mode->crtc_hsync_start =
1242 adjusted_mode_sw->crtc_hsync_start;
1244 if (adjusted_mode->crtc_hsync_end == crtc_hsync_end_sw)
1245 adjusted_mode->crtc_hsync_end =
1246 adjusted_mode_sw->crtc_hsync_end;
1248 if (adjusted_mode->crtc_hblank_start == crtc_hblank_start_sw)
1249 adjusted_mode->crtc_hblank_start =
1250 adjusted_mode_sw->crtc_hblank_start;
1252 if (adjusted_mode->crtc_hblank_end == crtc_hblank_end_sw)
1253 adjusted_mode->crtc_hblank_end =
1254 adjusted_mode_sw->crtc_hblank_end;
1257 static void intel_dsi_get_config(struct intel_encoder *encoder,
1258 struct intel_crtc_state *pipe_config)
1260 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1262 drm_dbg_kms(&dev_priv->drm, "\n");
1264 pipe_config->output_types |= BIT(INTEL_OUTPUT_DSI);
1266 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
1267 bxt_dsi_get_pipe_config(encoder, pipe_config);
1268 pclk = bxt_dsi_get_pclk(encoder, pipe_config);
1270 pclk = vlv_dsi_get_pclk(encoder, pipe_config);
1274 pipe_config->hw.adjusted_mode.crtc_clock = pclk;
1275 pipe_config->port_clock = pclk;
1279 /* return txclkesc cycles in terms of divider and duration in us */
1280 static u16 txclkesc(u32 divider, unsigned int us)
1283 case ESCAPE_CLOCK_DIVIDER_1:
1286 case ESCAPE_CLOCK_DIVIDER_2:
1288 case ESCAPE_CLOCK_DIVIDER_4:
1293 static void set_dsi_timings(struct drm_encoder *encoder,
1294 const struct drm_display_mode *adjusted_mode)
1296 struct drm_device *dev = encoder->dev;
1297 struct drm_i915_private *dev_priv = to_i915(dev);
1298 struct intel_dsi *intel_dsi = enc_to_intel_dsi(to_intel_encoder(encoder));
1300 unsigned int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
1301 unsigned int lane_count = intel_dsi->lane_count;
1303 u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
1305 hactive = adjusted_mode->crtc_hdisplay;
1306 hfp = adjusted_mode->crtc_hsync_start - adjusted_mode->crtc_hdisplay;
1307 hsync = adjusted_mode->crtc_hsync_end - adjusted_mode->crtc_hsync_start;
1308 hbp = adjusted_mode->crtc_htotal - adjusted_mode->crtc_hsync_end;
1310 if (intel_dsi->dual_link) {
1312 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
1313 hactive += intel_dsi->pixel_overlap;
1319 vfp = adjusted_mode->crtc_vsync_start - adjusted_mode->crtc_vdisplay;
1320 vsync = adjusted_mode->crtc_vsync_end - adjusted_mode->crtc_vsync_start;
1321 vbp = adjusted_mode->crtc_vtotal - adjusted_mode->crtc_vsync_end;
1323 /* horizontal values are in terms of high speed byte clock */
1324 hactive = txbyteclkhs(hactive, bpp, lane_count,
1325 intel_dsi->burst_mode_ratio);
1326 hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio);
1327 hsync = txbyteclkhs(hsync, bpp, lane_count,
1328 intel_dsi->burst_mode_ratio);
1329 hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio);
1331 for_each_dsi_port(port, intel_dsi->ports) {
1332 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
1334 * Program hdisplay and vdisplay on MIPI transcoder.
1335 * This is different from calculated hactive and
1336 * vactive, as they are calculated per channel basis,
1337 * whereas these values should be based on resolution.
1339 intel_de_write(dev_priv, BXT_MIPI_TRANS_HACTIVE(port),
1340 adjusted_mode->crtc_hdisplay);
1341 intel_de_write(dev_priv, BXT_MIPI_TRANS_VACTIVE(port),
1342 adjusted_mode->crtc_vdisplay);
1343 intel_de_write(dev_priv, BXT_MIPI_TRANS_VTOTAL(port),
1344 adjusted_mode->crtc_vtotal);
1347 intel_de_write(dev_priv, MIPI_HACTIVE_AREA_COUNT(port),
1349 intel_de_write(dev_priv, MIPI_HFP_COUNT(port), hfp);
1351 /* meaningful for video mode non-burst sync pulse mode only,
1352 * can be zero for non-burst sync events and burst modes */
1353 intel_de_write(dev_priv, MIPI_HSYNC_PADDING_COUNT(port),
1355 intel_de_write(dev_priv, MIPI_HBP_COUNT(port), hbp);
1357 /* vertical values are in terms of lines */
1358 intel_de_write(dev_priv, MIPI_VFP_COUNT(port), vfp);
1359 intel_de_write(dev_priv, MIPI_VSYNC_PADDING_COUNT(port),
1361 intel_de_write(dev_priv, MIPI_VBP_COUNT(port), vbp);
1365 static u32 pixel_format_to_reg(enum mipi_dsi_pixel_format fmt)
1368 case MIPI_DSI_FMT_RGB888:
1369 return VID_MODE_FORMAT_RGB888;
1370 case MIPI_DSI_FMT_RGB666:
1371 return VID_MODE_FORMAT_RGB666;
1372 case MIPI_DSI_FMT_RGB666_PACKED:
1373 return VID_MODE_FORMAT_RGB666_PACKED;
1374 case MIPI_DSI_FMT_RGB565:
1375 return VID_MODE_FORMAT_RGB565;
1378 return VID_MODE_FORMAT_RGB666;
1382 static void intel_dsi_prepare(struct intel_encoder *intel_encoder,
1383 const struct intel_crtc_state *pipe_config)
1385 struct drm_encoder *encoder = &intel_encoder->base;
1386 struct drm_device *dev = encoder->dev;
1387 struct drm_i915_private *dev_priv = to_i915(dev);
1388 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->uapi.crtc);
1389 struct intel_dsi *intel_dsi = enc_to_intel_dsi(to_intel_encoder(encoder));
1390 const struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
1392 unsigned int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
1396 drm_dbg_kms(&dev_priv->drm, "pipe %c\n", pipe_name(intel_crtc->pipe));
1398 mode_hdisplay = adjusted_mode->crtc_hdisplay;
1400 if (intel_dsi->dual_link) {
1402 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
1403 mode_hdisplay += intel_dsi->pixel_overlap;
1406 for_each_dsi_port(port, intel_dsi->ports) {
1407 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1409 * escape clock divider, 20MHz, shared for A and C.
1410 * device ready must be off when doing this! txclkesc?
1412 tmp = intel_de_read(dev_priv, MIPI_CTRL(PORT_A));
1413 tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
1414 intel_de_write(dev_priv, MIPI_CTRL(PORT_A),
1415 tmp | ESCAPE_CLOCK_DIVIDER_1);
1417 /* read request priority is per pipe */
1418 tmp = intel_de_read(dev_priv, MIPI_CTRL(port));
1419 tmp &= ~READ_REQUEST_PRIORITY_MASK;
1420 intel_de_write(dev_priv, MIPI_CTRL(port),
1421 tmp | READ_REQUEST_PRIORITY_HIGH);
1422 } else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
1423 enum pipe pipe = intel_crtc->pipe;
1425 tmp = intel_de_read(dev_priv, MIPI_CTRL(port));
1426 tmp &= ~BXT_PIPE_SELECT_MASK;
1428 tmp |= BXT_PIPE_SELECT(pipe);
1429 intel_de_write(dev_priv, MIPI_CTRL(port), tmp);
1432 /* XXX: why here, why like this? handling in irq handler?! */
1433 intel_de_write(dev_priv, MIPI_INTR_STAT(port), 0xffffffff);
1434 intel_de_write(dev_priv, MIPI_INTR_EN(port), 0xffffffff);
1436 intel_de_write(dev_priv, MIPI_DPHY_PARAM(port),
1437 intel_dsi->dphy_reg);
1439 intel_de_write(dev_priv, MIPI_DPI_RESOLUTION(port),
1440 adjusted_mode->crtc_vdisplay << VERTICAL_ADDRESS_SHIFT | mode_hdisplay << HORIZONTAL_ADDRESS_SHIFT);
1443 set_dsi_timings(encoder, adjusted_mode);
1445 val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
1446 if (is_cmd_mode(intel_dsi)) {
1447 val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
1448 val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
1450 val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
1451 val |= pixel_format_to_reg(intel_dsi->pixel_format);
1455 if (intel_dsi->eotp_pkt == 0)
1457 if (intel_dsi->clock_stop)
1460 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
1461 tmp |= BXT_DPHY_DEFEATURE_EN;
1462 if (!is_cmd_mode(intel_dsi))
1463 tmp |= BXT_DEFEATURE_DPI_FIFO_CTR;
1466 for_each_dsi_port(port, intel_dsi->ports) {
1467 intel_de_write(dev_priv, MIPI_DSI_FUNC_PRG(port), val);
1469 /* timeouts for recovery. one frame IIUC. if counter expires,
1470 * EOT and stop state. */
1473 * In burst mode, value greater than one DPI line Time in byte
1474 * clock (txbyteclkhs) To timeout this timer 1+ of the above
1475 * said value is recommended.
1477 * In non-burst mode, Value greater than one DPI frame time in
1478 * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
1479 * said value is recommended.
1481 * In DBI only mode, value greater than one DBI frame time in
1482 * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
1483 * said value is recommended.
1486 if (is_vid_mode(intel_dsi) &&
1487 intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
1488 intel_de_write(dev_priv, MIPI_HS_TX_TIMEOUT(port),
1489 txbyteclkhs(adjusted_mode->crtc_htotal, bpp, intel_dsi->lane_count, intel_dsi->burst_mode_ratio) + 1);
1491 intel_de_write(dev_priv, MIPI_HS_TX_TIMEOUT(port),
1492 txbyteclkhs(adjusted_mode->crtc_vtotal * adjusted_mode->crtc_htotal, bpp, intel_dsi->lane_count, intel_dsi->burst_mode_ratio) + 1);
1494 intel_de_write(dev_priv, MIPI_LP_RX_TIMEOUT(port),
1495 intel_dsi->lp_rx_timeout);
1496 intel_de_write(dev_priv, MIPI_TURN_AROUND_TIMEOUT(port),
1497 intel_dsi->turn_arnd_val);
1498 intel_de_write(dev_priv, MIPI_DEVICE_RESET_TIMER(port),
1499 intel_dsi->rst_timer_val);
1503 /* in terms of low power clock */
1504 intel_de_write(dev_priv, MIPI_INIT_COUNT(port),
1505 txclkesc(intel_dsi->escape_clk_div, 100));
1507 if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) &&
1508 !intel_dsi->dual_link) {
1510 * BXT spec says write MIPI_INIT_COUNT for
1511 * both the ports, even if only one is
1512 * getting used. So write the other port
1513 * if not in dual link mode.
1515 intel_de_write(dev_priv,
1516 MIPI_INIT_COUNT(port == PORT_A ? PORT_C : PORT_A),
1517 intel_dsi->init_count);
1520 /* recovery disables */
1521 intel_de_write(dev_priv, MIPI_EOT_DISABLE(port), tmp);
1523 /* in terms of low power clock */
1524 intel_de_write(dev_priv, MIPI_INIT_COUNT(port),
1525 intel_dsi->init_count);
1527 /* in terms of txbyteclkhs. actual high to low switch +
1528 * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
1530 * XXX: write MIPI_STOP_STATE_STALL?
1532 intel_de_write(dev_priv, MIPI_HIGH_LOW_SWITCH_COUNT(port),
1533 intel_dsi->hs_to_lp_count);
1535 /* XXX: low power clock equivalence in terms of byte clock.
1536 * the number of byte clocks occupied in one low power clock.
1537 * based on txbyteclkhs and txclkesc.
1538 * txclkesc time / txbyteclk time * (105 + MIPI_STOP_STATE_STALL
1541 intel_de_write(dev_priv, MIPI_LP_BYTECLK(port),
1542 intel_dsi->lp_byte_clk);
1544 if (IS_GEMINILAKE(dev_priv)) {
1545 intel_de_write(dev_priv, MIPI_TLPX_TIME_COUNT(port),
1546 intel_dsi->lp_byte_clk);
1547 /* Shadow of DPHY reg */
1548 intel_de_write(dev_priv, MIPI_CLK_LANE_TIMING(port),
1549 intel_dsi->dphy_reg);
1552 /* the bw essential for transmitting 16 long packets containing
1553 * 252 bytes meant for dcs write memory command is programmed in
1554 * this register in terms of byte clocks. based on dsi transfer
1555 * rate and the number of lanes configured the time taken to
1556 * transmit 16 long packets in a dsi stream varies. */
1557 intel_de_write(dev_priv, MIPI_DBI_BW_CTRL(port),
1558 intel_dsi->bw_timer);
1560 intel_de_write(dev_priv, MIPI_CLK_LANE_SWITCH_TIME_CNT(port),
1561 intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT | intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT);
1563 if (is_vid_mode(intel_dsi))
1564 /* Some panels might have resolution which is not a
1565 * multiple of 64 like 1366 x 768. Enable RANDOM
1566 * resolution support for such panels by default */
1567 intel_de_write(dev_priv, MIPI_VIDEO_MODE_FORMAT(port),
1568 intel_dsi->video_frmt_cfg_bits | intel_dsi->video_mode_format | IP_TG_CONFIG | RANDOM_DPI_DISPLAY_RESOLUTION);
1572 static void intel_dsi_unprepare(struct intel_encoder *encoder)
1574 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1575 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
1579 if (IS_GEMINILAKE(dev_priv))
1582 for_each_dsi_port(port, intel_dsi->ports) {
1583 /* Panel commands can be sent when clock is in LP11 */
1584 intel_de_write(dev_priv, MIPI_DEVICE_READY(port), 0x0);
1586 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
1587 bxt_dsi_reset_clocks(encoder, port);
1589 vlv_dsi_reset_clocks(encoder, port);
1590 intel_de_write(dev_priv, MIPI_EOT_DISABLE(port), CLOCKSTOP);
1592 val = intel_de_read(dev_priv, MIPI_DSI_FUNC_PRG(port));
1593 val &= ~VID_MODE_FORMAT_MASK;
1594 intel_de_write(dev_priv, MIPI_DSI_FUNC_PRG(port), val);
1596 intel_de_write(dev_priv, MIPI_DEVICE_READY(port), 0x1);
1600 static void intel_dsi_encoder_destroy(struct drm_encoder *encoder)
1602 struct intel_dsi *intel_dsi = enc_to_intel_dsi(to_intel_encoder(encoder));
1604 intel_dsi_vbt_gpio_cleanup(intel_dsi);
1605 intel_encoder_destroy(encoder);
1608 static const struct drm_encoder_funcs intel_dsi_funcs = {
1609 .destroy = intel_dsi_encoder_destroy,
1612 static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
1613 .get_modes = intel_dsi_get_modes,
1614 .mode_valid = intel_dsi_mode_valid,
1615 .atomic_check = intel_digital_connector_atomic_check,
1618 static const struct drm_connector_funcs intel_dsi_connector_funcs = {
1619 .detect = intel_panel_detect,
1620 .late_register = intel_connector_register,
1621 .early_unregister = intel_connector_unregister,
1622 .destroy = intel_connector_destroy,
1623 .fill_modes = drm_helper_probe_single_connector_modes,
1624 .atomic_get_property = intel_digital_connector_atomic_get_property,
1625 .atomic_set_property = intel_digital_connector_atomic_set_property,
1626 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
1627 .atomic_duplicate_state = intel_digital_connector_duplicate_state,
1630 static void vlv_dsi_add_properties(struct intel_connector *connector)
1632 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
1634 if (connector->panel.fixed_mode) {
1635 u32 allowed_scalers;
1637 allowed_scalers = BIT(DRM_MODE_SCALE_ASPECT) | BIT(DRM_MODE_SCALE_FULLSCREEN);
1638 if (!HAS_GMCH(dev_priv))
1639 allowed_scalers |= BIT(DRM_MODE_SCALE_CENTER);
1641 drm_connector_attach_scaling_mode_property(&connector->base,
1644 connector->base.state->scaling_mode = DRM_MODE_SCALE_ASPECT;
1646 drm_connector_set_panel_orientation_with_quirk(
1648 intel_dsi_get_panel_orientation(connector),
1649 connector->panel.fixed_mode->hdisplay,
1650 connector->panel.fixed_mode->vdisplay);
1654 #define NS_KHZ_RATIO 1000000
1656 #define PREPARE_CNT_MAX 0x3F
1657 #define EXIT_ZERO_CNT_MAX 0x3F
1658 #define CLK_ZERO_CNT_MAX 0xFF
1659 #define TRAIL_CNT_MAX 0x1F
1661 static void vlv_dphy_param_init(struct intel_dsi *intel_dsi)
1663 struct drm_device *dev = intel_dsi->base.base.dev;
1664 struct drm_i915_private *dev_priv = to_i915(dev);
1665 struct mipi_config *mipi_config = dev_priv->vbt.dsi.config;
1666 u32 tlpx_ns, extra_byte_count, tlpx_ui;
1668 u32 prepare_cnt, exit_zero_cnt, clk_zero_cnt, trail_cnt;
1669 u32 ths_prepare_ns, tclk_trail_ns;
1670 u32 tclk_prepare_clkzero, ths_prepare_hszero;
1671 u32 lp_to_hs_switch, hs_to_lp_switch;
1674 tlpx_ns = intel_dsi_tlpx_ns(intel_dsi);
1676 switch (intel_dsi->lane_count) {
1679 extra_byte_count = 2;
1682 extra_byte_count = 4;
1686 extra_byte_count = 3;
1691 ui_num = NS_KHZ_RATIO;
1692 ui_den = intel_dsi_bitrate(intel_dsi);
1694 tclk_prepare_clkzero = mipi_config->tclk_prepare_clkzero;
1695 ths_prepare_hszero = mipi_config->ths_prepare_hszero;
1699 * LP byte clock = TLPX/ (8UI)
1701 intel_dsi->lp_byte_clk = DIV_ROUND_UP(tlpx_ns * ui_den, 8 * ui_num);
1703 /* DDR clock period = 2 * UI
1704 * UI(sec) = 1/(bitrate * 10^3) (bitrate is in KHZ)
1705 * UI(nsec) = 10^6 / bitrate
1706 * DDR clock period (nsec) = 2 * UI = (2 * 10^6)/ bitrate
1707 * DDR clock count = ns_value / DDR clock period
1709 * For GEMINILAKE dphy_param_reg will be programmed in terms of
1710 * HS byte clock count for other platform in HS ddr clock count
1712 mul = IS_GEMINILAKE(dev_priv) ? 8 : 2;
1713 ths_prepare_ns = max(mipi_config->ths_prepare,
1714 mipi_config->tclk_prepare);
1717 prepare_cnt = DIV_ROUND_UP(ths_prepare_ns * ui_den, ui_num * mul);
1719 if (prepare_cnt > PREPARE_CNT_MAX) {
1720 drm_dbg_kms(&dev_priv->drm, "prepare count too high %u\n",
1722 prepare_cnt = PREPARE_CNT_MAX;
1725 /* exit zero count */
1726 exit_zero_cnt = DIV_ROUND_UP(
1727 (ths_prepare_hszero - ths_prepare_ns) * ui_den,
1732 * Exit zero is unified val ths_zero and ths_exit
1733 * minimum value for ths_exit = 110ns
1734 * min (exit_zero_cnt * 2) = 110/UI
1735 * exit_zero_cnt = 55/UI
1737 if (exit_zero_cnt < (55 * ui_den / ui_num) && (55 * ui_den) % ui_num)
1740 if (exit_zero_cnt > EXIT_ZERO_CNT_MAX) {
1741 drm_dbg_kms(&dev_priv->drm, "exit zero count too high %u\n",
1743 exit_zero_cnt = EXIT_ZERO_CNT_MAX;
1746 /* clk zero count */
1747 clk_zero_cnt = DIV_ROUND_UP(
1748 (tclk_prepare_clkzero - ths_prepare_ns)
1749 * ui_den, ui_num * mul);
1751 if (clk_zero_cnt > CLK_ZERO_CNT_MAX) {
1752 drm_dbg_kms(&dev_priv->drm, "clock zero count too high %u\n",
1754 clk_zero_cnt = CLK_ZERO_CNT_MAX;
1758 tclk_trail_ns = max(mipi_config->tclk_trail, mipi_config->ths_trail);
1759 trail_cnt = DIV_ROUND_UP(tclk_trail_ns * ui_den, ui_num * mul);
1761 if (trail_cnt > TRAIL_CNT_MAX) {
1762 drm_dbg_kms(&dev_priv->drm, "trail count too high %u\n",
1764 trail_cnt = TRAIL_CNT_MAX;
1768 intel_dsi->dphy_reg = exit_zero_cnt << 24 | trail_cnt << 16 |
1769 clk_zero_cnt << 8 | prepare_cnt;
1772 * LP to HS switch count = 4TLPX + PREP_COUNT * mul + EXIT_ZERO_COUNT *
1773 * mul + 10UI + Extra Byte Count
1775 * HS to LP switch count = THS-TRAIL + 2TLPX + Extra Byte Count
1776 * Extra Byte Count is calculated according to number of lanes.
1777 * High Low Switch Count is the Max of LP to HS and
1778 * HS to LP switch count
1781 tlpx_ui = DIV_ROUND_UP(tlpx_ns * ui_den, ui_num);
1785 * The comment above does not match with the code */
1786 lp_to_hs_switch = DIV_ROUND_UP(4 * tlpx_ui + prepare_cnt * mul +
1787 exit_zero_cnt * mul + 10, 8);
1789 hs_to_lp_switch = DIV_ROUND_UP(mipi_config->ths_trail + 2 * tlpx_ui, 8);
1791 intel_dsi->hs_to_lp_count = max(lp_to_hs_switch, hs_to_lp_switch);
1792 intel_dsi->hs_to_lp_count += extra_byte_count;
1795 /* LP -> HS for clock lanes
1796 * LP clk sync + LP11 + LP01 + tclk_prepare + tclk_zero +
1798 * 2TPLX + 1TLPX + 1 TPLX(in ns) + prepare_cnt * 2 + clk_zero_cnt *
1799 * 2(in UI) + extra byte count
1800 * In byteclks = (4TLPX + prepare_cnt * 2 + clk_zero_cnt *2 (in UI)) /
1801 * 8 + extra byte count
1803 intel_dsi->clk_lp_to_hs_count =
1805 4 * tlpx_ui + prepare_cnt * 2 +
1809 intel_dsi->clk_lp_to_hs_count += extra_byte_count;
1811 /* HS->LP for Clock Lanes
1812 * Low Power clock synchronisations + 1Tx byteclk + tclk_trail +
1814 * 2TLPX + 8UI + (trail_count*2)(in UI) + Extra byte count
1815 * In byteclks = (2*TLpx(in UI) + trail_count*2 +8)(in UI)/8 +
1818 intel_dsi->clk_hs_to_lp_count =
1819 DIV_ROUND_UP(2 * tlpx_ui + trail_cnt * 2 + 8,
1821 intel_dsi->clk_hs_to_lp_count += extra_byte_count;
1823 intel_dsi_log_params(intel_dsi);
1826 void vlv_dsi_init(struct drm_i915_private *dev_priv)
1828 struct drm_device *dev = &dev_priv->drm;
1829 struct intel_dsi *intel_dsi;
1830 struct intel_encoder *intel_encoder;
1831 struct drm_encoder *encoder;
1832 struct intel_connector *intel_connector;
1833 struct drm_connector *connector;
1834 struct drm_display_mode *current_mode, *fixed_mode;
1838 drm_dbg_kms(&dev_priv->drm, "\n");
1840 /* There is no detection method for MIPI so rely on VBT */
1841 if (!intel_bios_is_dsi_present(dev_priv, &port))
1844 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
1845 dev_priv->mipi_mmio_base = BXT_MIPI_BASE;
1847 dev_priv->mipi_mmio_base = VLV_MIPI_BASE;
1849 intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
1853 intel_connector = intel_connector_alloc();
1854 if (!intel_connector) {
1859 intel_encoder = &intel_dsi->base;
1860 encoder = &intel_encoder->base;
1861 intel_dsi->attached_connector = intel_connector;
1863 connector = &intel_connector->base;
1865 drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI,
1866 "DSI %c", port_name(port));
1868 intel_encoder->compute_config = intel_dsi_compute_config;
1869 intel_encoder->pre_enable = intel_dsi_pre_enable;
1870 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
1871 intel_encoder->enable = bxt_dsi_enable;
1872 intel_encoder->disable = intel_dsi_disable;
1873 intel_encoder->post_disable = intel_dsi_post_disable;
1874 intel_encoder->get_hw_state = intel_dsi_get_hw_state;
1875 intel_encoder->get_config = intel_dsi_get_config;
1876 intel_encoder->update_pipe = intel_panel_update_backlight;
1877 intel_encoder->shutdown = intel_dsi_shutdown;
1879 intel_connector->get_hw_state = intel_connector_get_hw_state;
1881 intel_encoder->port = port;
1882 intel_encoder->type = INTEL_OUTPUT_DSI;
1883 intel_encoder->power_domain = POWER_DOMAIN_PORT_DSI;
1884 intel_encoder->cloneable = 0;
1887 * On BYT/CHV, pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI
1888 * port C. BXT isn't limited like this.
1890 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
1891 intel_encoder->pipe_mask = ~0;
1892 else if (port == PORT_A)
1893 intel_encoder->pipe_mask = BIT(PIPE_A);
1895 intel_encoder->pipe_mask = BIT(PIPE_B);
1897 intel_dsi->panel_power_off_time = ktime_get_boottime();
1899 if (dev_priv->vbt.dsi.config->dual_link)
1900 intel_dsi->ports = BIT(PORT_A) | BIT(PORT_C);
1902 intel_dsi->ports = BIT(port);
1904 intel_dsi->dcs_backlight_ports = dev_priv->vbt.dsi.bl_ports;
1905 intel_dsi->dcs_cabc_ports = dev_priv->vbt.dsi.cabc_ports;
1907 /* Create a DSI host (and a device) for each port. */
1908 for_each_dsi_port(port, intel_dsi->ports) {
1909 struct intel_dsi_host *host;
1911 host = intel_dsi_host_init(intel_dsi, &intel_dsi_host_ops,
1916 intel_dsi->dsi_hosts[port] = host;
1919 if (!intel_dsi_vbt_init(intel_dsi, MIPI_DSI_GENERIC_PANEL_ID)) {
1920 drm_dbg_kms(&dev_priv->drm, "no device found\n");
1924 /* Use clock read-back from current hw-state for fastboot */
1925 current_mode = intel_encoder_current_mode(intel_encoder);
1927 drm_dbg_kms(&dev_priv->drm, "Calculated pclk %d GOP %d\n",
1928 intel_dsi->pclk, current_mode->clock);
1929 if (intel_fuzzy_clock_check(intel_dsi->pclk,
1930 current_mode->clock)) {
1931 drm_dbg_kms(&dev_priv->drm, "Using GOP pclk\n");
1932 intel_dsi->pclk = current_mode->clock;
1935 kfree(current_mode);
1938 vlv_dphy_param_init(intel_dsi);
1940 intel_dsi_vbt_gpio_init(intel_dsi,
1941 intel_dsi_get_hw_state(intel_encoder, &pipe));
1943 drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
1944 DRM_MODE_CONNECTOR_DSI);
1946 drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
1948 connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
1949 connector->interlace_allowed = false;
1950 connector->doublescan_allowed = false;
1952 intel_connector_attach_encoder(intel_connector, intel_encoder);
1954 mutex_lock(&dev->mode_config.mutex);
1955 fixed_mode = intel_panel_vbt_fixed_mode(intel_connector);
1956 mutex_unlock(&dev->mode_config.mutex);
1959 drm_dbg_kms(&dev_priv->drm, "no fixed mode\n");
1960 goto err_cleanup_connector;
1963 intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
1964 intel_panel_setup_backlight(connector, INVALID_PIPE);
1966 vlv_dsi_add_properties(intel_connector);
1970 err_cleanup_connector:
1971 drm_connector_cleanup(&intel_connector->base);
1973 drm_encoder_cleanup(&intel_encoder->base);
1975 kfree(intel_connector);