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>
27 #include <drm/drm_atomic_helper.h>
28 #include <drm/drm_crtc.h>
29 #include <drm/drm_edid.h>
30 #include <drm/i915_drm.h>
31 #include <drm/drm_panel.h>
32 #include <drm/drm_mipi_dsi.h>
33 #include <linux/slab.h>
34 #include <linux/gpio/consumer.h>
36 #include "intel_drv.h"
37 #include "intel_dsi.h"
41 struct drm_panel
* (*init
)(struct intel_dsi
*intel_dsi
, u16 panel_id
);
42 } intel_dsi_drivers
[] = {
44 .panel_id
= MIPI_DSI_GENERIC_PANEL_ID
,
45 .init
= vbt_panel_init
,
49 enum mipi_dsi_pixel_format
pixel_format_from_register_bits(u32 fmt
)
51 /* It just so happens the VBT matches register contents. */
53 case VID_MODE_FORMAT_RGB888
:
54 return MIPI_DSI_FMT_RGB888
;
55 case VID_MODE_FORMAT_RGB666
:
56 return MIPI_DSI_FMT_RGB666
;
57 case VID_MODE_FORMAT_RGB666_PACKED
:
58 return MIPI_DSI_FMT_RGB666_PACKED
;
59 case VID_MODE_FORMAT_RGB565
:
60 return MIPI_DSI_FMT_RGB565
;
63 return MIPI_DSI_FMT_RGB666
;
67 static void wait_for_dsi_fifo_empty(struct intel_dsi
*intel_dsi
, enum port port
)
69 struct drm_encoder
*encoder
= &intel_dsi
->base
.base
;
70 struct drm_device
*dev
= encoder
->dev
;
71 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
74 mask
= LP_CTRL_FIFO_EMPTY
| HS_CTRL_FIFO_EMPTY
|
75 LP_DATA_FIFO_EMPTY
| HS_DATA_FIFO_EMPTY
;
77 if (wait_for((I915_READ(MIPI_GEN_FIFO_STAT(port
)) & mask
) == mask
, 100))
78 DRM_ERROR("DPI FIFOs are not empty\n");
81 static void write_data(struct drm_i915_private
*dev_priv
,
83 const u8
*data
, u32 len
)
87 for (i
= 0; i
< len
; i
+= 4) {
90 for (j
= 0; j
< min_t(u32
, len
- i
, 4); j
++)
91 val
|= *data
++ << 8 * j
;
97 static void read_data(struct drm_i915_private
*dev_priv
,
103 for (i
= 0; i
< len
; i
+= 4) {
104 u32 val
= I915_READ(reg
);
106 for (j
= 0; j
< min_t(u32
, len
- i
, 4); j
++)
107 *data
++ = val
>> 8 * j
;
111 static ssize_t
intel_dsi_host_transfer(struct mipi_dsi_host
*host
,
112 const struct mipi_dsi_msg
*msg
)
114 struct intel_dsi_host
*intel_dsi_host
= to_intel_dsi_host(host
);
115 struct drm_device
*dev
= intel_dsi_host
->intel_dsi
->base
.base
.dev
;
116 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
117 enum port port
= intel_dsi_host
->port
;
118 struct mipi_dsi_packet packet
;
120 const u8
*header
, *data
;
121 i915_reg_t data_reg
, ctrl_reg
;
122 u32 data_mask
, ctrl_mask
;
124 ret
= mipi_dsi_create_packet(&packet
, msg
);
128 header
= packet
.header
;
129 data
= packet
.payload
;
131 if (msg
->flags
& MIPI_DSI_MSG_USE_LPM
) {
132 data_reg
= MIPI_LP_GEN_DATA(port
);
133 data_mask
= LP_DATA_FIFO_FULL
;
134 ctrl_reg
= MIPI_LP_GEN_CTRL(port
);
135 ctrl_mask
= LP_CTRL_FIFO_FULL
;
137 data_reg
= MIPI_HS_GEN_DATA(port
);
138 data_mask
= HS_DATA_FIFO_FULL
;
139 ctrl_reg
= MIPI_HS_GEN_CTRL(port
);
140 ctrl_mask
= HS_CTRL_FIFO_FULL
;
143 /* note: this is never true for reads */
144 if (packet
.payload_length
) {
146 if (wait_for((I915_READ(MIPI_GEN_FIFO_STAT(port
)) & data_mask
) == 0, 50))
147 DRM_ERROR("Timeout waiting for HS/LP DATA FIFO !full\n");
149 write_data(dev_priv
, data_reg
, packet
.payload
,
150 packet
.payload_length
);
154 I915_WRITE(MIPI_INTR_STAT(port
), GEN_READ_DATA_AVAIL
);
157 if (wait_for((I915_READ(MIPI_GEN_FIFO_STAT(port
)) & ctrl_mask
) == 0, 50)) {
158 DRM_ERROR("Timeout waiting for HS/LP CTRL FIFO !full\n");
161 I915_WRITE(ctrl_reg
, header
[2] << 16 | header
[1] << 8 | header
[0]);
163 /* ->rx_len is set only for reads */
165 data_mask
= GEN_READ_DATA_AVAIL
;
166 if (wait_for((I915_READ(MIPI_INTR_STAT(port
)) & data_mask
) == data_mask
, 50))
167 DRM_ERROR("Timeout waiting for read data.\n");
169 read_data(dev_priv
, data_reg
, msg
->rx_buf
, msg
->rx_len
);
172 /* XXX: fix for reads and writes */
173 return 4 + packet
.payload_length
;
176 static int intel_dsi_host_attach(struct mipi_dsi_host
*host
,
177 struct mipi_dsi_device
*dsi
)
182 static int intel_dsi_host_detach(struct mipi_dsi_host
*host
,
183 struct mipi_dsi_device
*dsi
)
188 static const struct mipi_dsi_host_ops intel_dsi_host_ops
= {
189 .attach
= intel_dsi_host_attach
,
190 .detach
= intel_dsi_host_detach
,
191 .transfer
= intel_dsi_host_transfer
,
194 static struct intel_dsi_host
*intel_dsi_host_init(struct intel_dsi
*intel_dsi
,
197 struct intel_dsi_host
*host
;
198 struct mipi_dsi_device
*device
;
200 host
= kzalloc(sizeof(*host
), GFP_KERNEL
);
204 host
->base
.ops
= &intel_dsi_host_ops
;
205 host
->intel_dsi
= intel_dsi
;
209 * We should call mipi_dsi_host_register(&host->base) here, but we don't
210 * have a host->dev, and we don't have OF stuff either. So just use the
211 * dsi framework as a library and hope for the best. Create the dsi
212 * devices by ourselves here too. Need to be careful though, because we
213 * don't initialize any of the driver model devices here.
215 device
= kzalloc(sizeof(*device
), GFP_KERNEL
);
221 device
->host
= &host
->base
;
222 host
->device
= device
;
228 * send a video mode command
230 * XXX: commands with data in MIPI_DPI_DATA?
232 static int dpi_send_cmd(struct intel_dsi
*intel_dsi
, u32 cmd
, bool hs
,
235 struct drm_encoder
*encoder
= &intel_dsi
->base
.base
;
236 struct drm_device
*dev
= encoder
->dev
;
237 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
247 I915_WRITE(MIPI_INTR_STAT(port
), SPL_PKT_SENT_INTERRUPT
);
249 /* XXX: old code skips write if control unchanged */
250 if (cmd
== I915_READ(MIPI_DPI_CONTROL(port
)))
251 DRM_ERROR("Same special packet %02x twice in a row.\n", cmd
);
253 I915_WRITE(MIPI_DPI_CONTROL(port
), cmd
);
255 mask
= SPL_PKT_SENT_INTERRUPT
;
256 if (wait_for((I915_READ(MIPI_INTR_STAT(port
)) & mask
) == mask
, 100))
257 DRM_ERROR("Video mode command 0x%08x send failed.\n", cmd
);
262 static void band_gap_reset(struct drm_i915_private
*dev_priv
)
264 mutex_lock(&dev_priv
->sb_lock
);
266 vlv_flisdsi_write(dev_priv
, 0x08, 0x0001);
267 vlv_flisdsi_write(dev_priv
, 0x0F, 0x0005);
268 vlv_flisdsi_write(dev_priv
, 0x0F, 0x0025);
270 vlv_flisdsi_write(dev_priv
, 0x0F, 0x0000);
271 vlv_flisdsi_write(dev_priv
, 0x08, 0x0000);
273 mutex_unlock(&dev_priv
->sb_lock
);
276 static inline bool is_vid_mode(struct intel_dsi
*intel_dsi
)
278 return intel_dsi
->operation_mode
== INTEL_DSI_VIDEO_MODE
;
281 static inline bool is_cmd_mode(struct intel_dsi
*intel_dsi
)
283 return intel_dsi
->operation_mode
== INTEL_DSI_COMMAND_MODE
;
286 static bool intel_dsi_compute_config(struct intel_encoder
*encoder
,
287 struct intel_crtc_state
*pipe_config
)
289 struct drm_i915_private
*dev_priv
= encoder
->base
.dev
->dev_private
;
290 struct intel_dsi
*intel_dsi
= container_of(encoder
, struct intel_dsi
,
292 struct intel_connector
*intel_connector
= intel_dsi
->attached_connector
;
293 struct drm_display_mode
*fixed_mode
= intel_connector
->panel
.fixed_mode
;
294 struct drm_display_mode
*adjusted_mode
= &pipe_config
->base
.adjusted_mode
;
298 pipe_config
->has_dsi_encoder
= true;
301 intel_fixed_panel_mode(fixed_mode
, adjusted_mode
);
303 /* DSI uses short packets for sync events, so clear mode flags for DSI */
304 adjusted_mode
->flags
= 0;
306 if (IS_BROXTON(dev_priv
)) {
307 /* Dual link goes to DSI transcoder A. */
308 if (intel_dsi
->ports
== BIT(PORT_C
))
309 pipe_config
->cpu_transcoder
= TRANSCODER_DSI_C
;
311 pipe_config
->cpu_transcoder
= TRANSCODER_DSI_A
;
317 static void bxt_dsi_device_ready(struct intel_encoder
*encoder
)
319 struct drm_i915_private
*dev_priv
= encoder
->base
.dev
->dev_private
;
320 struct intel_dsi
*intel_dsi
= enc_to_intel_dsi(&encoder
->base
);
326 /* Exit Low power state in 4 steps*/
327 for_each_dsi_port(port
, intel_dsi
->ports
) {
329 /* 1. Enable MIPI PHY transparent latch */
330 val
= I915_READ(BXT_MIPI_PORT_CTRL(port
));
331 I915_WRITE(BXT_MIPI_PORT_CTRL(port
), val
| LP_OUTPUT_HOLD
);
332 usleep_range(2000, 2500);
335 val
= I915_READ(MIPI_DEVICE_READY(port
));
336 val
&= ~ULPS_STATE_MASK
;
337 val
|= (ULPS_STATE_ENTER
| DEVICE_READY
);
338 I915_WRITE(MIPI_DEVICE_READY(port
), val
);
342 val
= I915_READ(MIPI_DEVICE_READY(port
));
343 val
&= ~ULPS_STATE_MASK
;
344 val
|= (ULPS_STATE_EXIT
| DEVICE_READY
);
345 I915_WRITE(MIPI_DEVICE_READY(port
), val
);
346 usleep_range(1000, 1500);
348 /* Clear ULPS and set device ready */
349 val
= I915_READ(MIPI_DEVICE_READY(port
));
350 val
&= ~ULPS_STATE_MASK
;
352 I915_WRITE(MIPI_DEVICE_READY(port
), val
);
356 static void vlv_dsi_device_ready(struct intel_encoder
*encoder
)
358 struct drm_i915_private
*dev_priv
= encoder
->base
.dev
->dev_private
;
359 struct intel_dsi
*intel_dsi
= enc_to_intel_dsi(&encoder
->base
);
365 mutex_lock(&dev_priv
->sb_lock
);
366 /* program rcomp for compliance, reduce from 50 ohms to 45 ohms
367 * needed everytime after power gate */
368 vlv_flisdsi_write(dev_priv
, 0x04, 0x0004);
369 mutex_unlock(&dev_priv
->sb_lock
);
371 /* bandgap reset is needed after everytime we do power gate */
372 band_gap_reset(dev_priv
);
374 for_each_dsi_port(port
, intel_dsi
->ports
) {
376 I915_WRITE(MIPI_DEVICE_READY(port
), ULPS_STATE_ENTER
);
377 usleep_range(2500, 3000);
379 /* Enable MIPI PHY transparent latch
380 * Common bit for both MIPI Port A & MIPI Port C
381 * No similar bit in MIPI Port C reg
383 val
= I915_READ(MIPI_PORT_CTRL(PORT_A
));
384 I915_WRITE(MIPI_PORT_CTRL(PORT_A
), val
| LP_OUTPUT_HOLD
);
385 usleep_range(1000, 1500);
387 I915_WRITE(MIPI_DEVICE_READY(port
), ULPS_STATE_EXIT
);
388 usleep_range(2500, 3000);
390 I915_WRITE(MIPI_DEVICE_READY(port
), DEVICE_READY
);
391 usleep_range(2500, 3000);
395 static void intel_dsi_device_ready(struct intel_encoder
*encoder
)
397 struct drm_device
*dev
= encoder
->base
.dev
;
399 if (IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
))
400 vlv_dsi_device_ready(encoder
);
401 else if (IS_BROXTON(dev
))
402 bxt_dsi_device_ready(encoder
);
405 static void intel_dsi_port_enable(struct intel_encoder
*encoder
)
407 struct drm_device
*dev
= encoder
->base
.dev
;
408 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
409 struct intel_crtc
*intel_crtc
= to_intel_crtc(encoder
->base
.crtc
);
410 struct intel_dsi
*intel_dsi
= enc_to_intel_dsi(&encoder
->base
);
413 if (intel_dsi
->dual_link
== DSI_DUAL_LINK_FRONT_BACK
) {
416 temp
= I915_READ(VLV_CHICKEN_3
);
417 temp
&= ~PIXEL_OVERLAP_CNT_MASK
|
418 intel_dsi
->pixel_overlap
<<
419 PIXEL_OVERLAP_CNT_SHIFT
;
420 I915_WRITE(VLV_CHICKEN_3
, temp
);
423 for_each_dsi_port(port
, intel_dsi
->ports
) {
424 i915_reg_t port_ctrl
= IS_BROXTON(dev
) ?
425 BXT_MIPI_PORT_CTRL(port
) : MIPI_PORT_CTRL(port
);
428 temp
= I915_READ(port_ctrl
);
430 temp
&= ~LANE_CONFIGURATION_MASK
;
431 temp
&= ~DUAL_LINK_MODE_MASK
;
433 if (intel_dsi
->ports
== (BIT(PORT_A
) | BIT(PORT_C
))) {
434 temp
|= (intel_dsi
->dual_link
- 1)
435 << DUAL_LINK_MODE_SHIFT
;
436 temp
|= intel_crtc
->pipe
?
437 LANE_CONFIGURATION_DUAL_LINK_B
:
438 LANE_CONFIGURATION_DUAL_LINK_A
;
440 /* assert ip_tg_enable signal */
441 I915_WRITE(port_ctrl
, temp
| DPI_ENABLE
);
442 POSTING_READ(port_ctrl
);
446 static void intel_dsi_port_disable(struct intel_encoder
*encoder
)
448 struct drm_device
*dev
= encoder
->base
.dev
;
449 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
450 struct intel_dsi
*intel_dsi
= enc_to_intel_dsi(&encoder
->base
);
453 for_each_dsi_port(port
, intel_dsi
->ports
) {
454 i915_reg_t port_ctrl
= IS_BROXTON(dev
) ?
455 BXT_MIPI_PORT_CTRL(port
) : MIPI_PORT_CTRL(port
);
458 /* de-assert ip_tg_enable signal */
459 temp
= I915_READ(port_ctrl
);
460 I915_WRITE(port_ctrl
, temp
& ~DPI_ENABLE
);
461 POSTING_READ(port_ctrl
);
465 static void intel_dsi_enable(struct intel_encoder
*encoder
)
467 struct drm_device
*dev
= encoder
->base
.dev
;
468 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
469 struct intel_dsi
*intel_dsi
= enc_to_intel_dsi(&encoder
->base
);
474 if (is_cmd_mode(intel_dsi
)) {
475 for_each_dsi_port(port
, intel_dsi
->ports
)
476 I915_WRITE(MIPI_MAX_RETURN_PKT_SIZE(port
), 8 * 4);
478 msleep(20); /* XXX */
479 for_each_dsi_port(port
, intel_dsi
->ports
)
480 dpi_send_cmd(intel_dsi
, TURN_ON
, false, port
);
483 drm_panel_enable(intel_dsi
->panel
);
485 for_each_dsi_port(port
, intel_dsi
->ports
)
486 wait_for_dsi_fifo_empty(intel_dsi
, port
);
488 intel_dsi_port_enable(encoder
);
491 intel_panel_enable_backlight(intel_dsi
->attached_connector
);
494 static void intel_dsi_prepare(struct intel_encoder
*intel_encoder
);
496 static void intel_dsi_pre_enable(struct intel_encoder
*encoder
)
498 struct drm_device
*dev
= encoder
->base
.dev
;
499 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
500 struct intel_dsi
*intel_dsi
= enc_to_intel_dsi(&encoder
->base
);
501 struct intel_crtc
*intel_crtc
= to_intel_crtc(encoder
->base
.crtc
);
502 enum pipe pipe
= intel_crtc
->pipe
;
508 intel_enable_dsi_pll(encoder
);
509 intel_dsi_prepare(encoder
);
511 /* Panel Enable over CRC PMIC */
512 if (intel_dsi
->gpio_panel
)
513 gpiod_set_value_cansleep(intel_dsi
->gpio_panel
, 1);
515 msleep(intel_dsi
->panel_on_delay
);
517 if (IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)) {
519 * Disable DPOunit clock gating, can stall pipe
520 * and we need DPLL REFA always enabled
522 tmp
= I915_READ(DPLL(pipe
));
523 tmp
|= DPLL_REF_CLK_ENABLE_VLV
;
524 I915_WRITE(DPLL(pipe
), tmp
);
526 /* update the hw state for DPLL */
527 intel_crtc
->config
->dpll_hw_state
.dpll
=
528 DPLL_INTEGRATED_REF_CLK_VLV
|
529 DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
531 tmp
= I915_READ(DSPCLK_GATE_D
);
532 tmp
|= DPOUNIT_CLOCK_GATE_DISABLE
;
533 I915_WRITE(DSPCLK_GATE_D
, tmp
);
536 /* put device in ready state */
537 intel_dsi_device_ready(encoder
);
539 drm_panel_prepare(intel_dsi
->panel
);
541 for_each_dsi_port(port
, intel_dsi
->ports
)
542 wait_for_dsi_fifo_empty(intel_dsi
, port
);
544 /* Enable port in pre-enable phase itself because as per hw team
545 * recommendation, port should be enabled befor plane & pipe */
546 intel_dsi_enable(encoder
);
549 static void intel_dsi_enable_nop(struct intel_encoder
*encoder
)
553 /* for DSI port enable has to be done before pipe
554 * and plane enable, so port enable is done in
555 * pre_enable phase itself unlike other encoders
559 static void intel_dsi_pre_disable(struct intel_encoder
*encoder
)
561 struct intel_dsi
*intel_dsi
= enc_to_intel_dsi(&encoder
->base
);
566 intel_panel_disable_backlight(intel_dsi
->attached_connector
);
568 if (is_vid_mode(intel_dsi
)) {
569 /* Send Shutdown command to the panel in LP mode */
570 for_each_dsi_port(port
, intel_dsi
->ports
)
571 dpi_send_cmd(intel_dsi
, SHUTDOWN
, false, port
);
576 static void intel_dsi_disable(struct intel_encoder
*encoder
)
578 struct drm_device
*dev
= encoder
->base
.dev
;
579 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
580 struct intel_dsi
*intel_dsi
= enc_to_intel_dsi(&encoder
->base
);
586 if (is_vid_mode(intel_dsi
)) {
587 for_each_dsi_port(port
, intel_dsi
->ports
)
588 wait_for_dsi_fifo_empty(intel_dsi
, port
);
590 intel_dsi_port_disable(encoder
);
594 for_each_dsi_port(port
, intel_dsi
->ports
) {
595 /* Panel commands can be sent when clock is in LP11 */
596 I915_WRITE(MIPI_DEVICE_READY(port
), 0x0);
598 intel_dsi_reset_clocks(encoder
, port
);
599 I915_WRITE(MIPI_EOT_DISABLE(port
), CLOCKSTOP
);
601 temp
= I915_READ(MIPI_DSI_FUNC_PRG(port
));
602 temp
&= ~VID_MODE_FORMAT_MASK
;
603 I915_WRITE(MIPI_DSI_FUNC_PRG(port
), temp
);
605 I915_WRITE(MIPI_DEVICE_READY(port
), 0x1);
607 /* if disable packets are sent before sending shutdown packet then in
608 * some next enable sequence send turn on packet error is observed */
609 drm_panel_disable(intel_dsi
->panel
);
611 for_each_dsi_port(port
, intel_dsi
->ports
)
612 wait_for_dsi_fifo_empty(intel_dsi
, port
);
615 static void intel_dsi_clear_device_ready(struct intel_encoder
*encoder
)
617 struct drm_device
*dev
= encoder
->base
.dev
;
618 struct drm_i915_private
*dev_priv
= encoder
->base
.dev
->dev_private
;
619 struct intel_dsi
*intel_dsi
= enc_to_intel_dsi(&encoder
->base
);
623 for_each_dsi_port(port
, intel_dsi
->ports
) {
624 /* Common bit for both MIPI Port A & MIPI Port C on VLV/CHV */
625 i915_reg_t port_ctrl
= IS_BROXTON(dev
) ?
626 BXT_MIPI_PORT_CTRL(port
) : MIPI_PORT_CTRL(PORT_A
);
629 I915_WRITE(MIPI_DEVICE_READY(port
), DEVICE_READY
|
631 usleep_range(2000, 2500);
633 I915_WRITE(MIPI_DEVICE_READY(port
), DEVICE_READY
|
635 usleep_range(2000, 2500);
637 I915_WRITE(MIPI_DEVICE_READY(port
), DEVICE_READY
|
639 usleep_range(2000, 2500);
641 /* Wait till Clock lanes are in LP-00 state for MIPI Port A
642 * only. MIPI Port C has no similar bit for checking
644 if (wait_for(((I915_READ(port_ctrl
) & AFE_LATCHOUT
)
646 DRM_ERROR("DSI LP not going Low\n");
648 /* Disable MIPI PHY transparent latch */
649 val
= I915_READ(port_ctrl
);
650 I915_WRITE(port_ctrl
, val
& ~LP_OUTPUT_HOLD
);
651 usleep_range(1000, 1500);
653 I915_WRITE(MIPI_DEVICE_READY(port
), 0x00);
654 usleep_range(2000, 2500);
657 intel_disable_dsi_pll(encoder
);
660 static void intel_dsi_post_disable(struct intel_encoder
*encoder
)
662 struct drm_i915_private
*dev_priv
= encoder
->base
.dev
->dev_private
;
663 struct intel_dsi
*intel_dsi
= enc_to_intel_dsi(&encoder
->base
);
667 intel_dsi_disable(encoder
);
669 intel_dsi_clear_device_ready(encoder
);
671 if (!IS_BROXTON(dev_priv
)) {
674 val
= I915_READ(DSPCLK_GATE_D
);
675 val
&= ~DPOUNIT_CLOCK_GATE_DISABLE
;
676 I915_WRITE(DSPCLK_GATE_D
, val
);
679 drm_panel_unprepare(intel_dsi
->panel
);
681 msleep(intel_dsi
->panel_off_delay
);
682 msleep(intel_dsi
->panel_pwr_cycle_delay
);
684 /* Panel Disable over CRC PMIC */
685 if (intel_dsi
->gpio_panel
)
686 gpiod_set_value_cansleep(intel_dsi
->gpio_panel
, 0);
689 static bool intel_dsi_get_hw_state(struct intel_encoder
*encoder
,
692 struct drm_i915_private
*dev_priv
= encoder
->base
.dev
->dev_private
;
693 struct intel_dsi
*intel_dsi
= enc_to_intel_dsi(&encoder
->base
);
694 struct drm_device
*dev
= encoder
->base
.dev
;
695 enum intel_display_power_domain power_domain
;
701 power_domain
= intel_display_port_power_domain(encoder
);
702 if (!intel_display_power_get_if_enabled(dev_priv
, power_domain
))
706 * On Broxton the PLL needs to be enabled with a valid divider
707 * configuration, otherwise accessing DSI registers will hang the
708 * machine. See BSpec North Display Engine registers/MIPI[BXT].
710 if (IS_BROXTON(dev_priv
) && !intel_dsi_pll_is_enabled(dev_priv
))
713 /* XXX: this only works for one DSI output */
714 for_each_dsi_port(port
, intel_dsi
->ports
) {
715 i915_reg_t ctrl_reg
= IS_BROXTON(dev
) ?
716 BXT_MIPI_PORT_CTRL(port
) : MIPI_PORT_CTRL(port
);
717 bool enabled
= I915_READ(ctrl_reg
) & DPI_ENABLE
;
719 /* Due to some hardware limitations on BYT, MIPI Port C DPI
720 * Enable bit does not get set. To check whether DSI Port C
721 * was enabled in BIOS, check the Pipe B enable bit
723 if (IS_VALLEYVIEW(dev
) && port
== PORT_C
)
724 enabled
= I915_READ(PIPECONF(PIPE_B
)) & PIPECONF_ENABLE
;
726 /* Try command mode if video mode not enabled */
728 u32 tmp
= I915_READ(MIPI_DSI_FUNC_PRG(port
));
729 enabled
= tmp
& CMD_MODE_DATA_WIDTH_MASK
;
735 if (!(I915_READ(MIPI_DEVICE_READY(port
)) & DEVICE_READY
))
738 if (IS_BROXTON(dev_priv
)) {
739 u32 tmp
= I915_READ(MIPI_CTRL(port
));
740 tmp
&= BXT_PIPE_SELECT_MASK
;
741 tmp
>>= BXT_PIPE_SELECT_SHIFT
;
743 if (WARN_ON(tmp
> PIPE_C
))
748 *pipe
= port
== PORT_A
? PIPE_A
: PIPE_B
;
756 intel_display_power_put(dev_priv
, power_domain
);
761 static void bxt_dsi_get_pipe_config(struct intel_encoder
*encoder
,
762 struct intel_crtc_state
*pipe_config
)
764 struct drm_device
*dev
= encoder
->base
.dev
;
765 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
766 struct drm_display_mode
*adjusted_mode
=
767 &pipe_config
->base
.adjusted_mode
;
768 struct intel_dsi
*intel_dsi
= enc_to_intel_dsi(&encoder
->base
);
769 unsigned int bpp
, fmt
;
774 * Atleast one port is active as encoder->get_config called only if
775 * encoder->get_hw_state() returns true.
777 for_each_dsi_port(port
, intel_dsi
->ports
) {
778 if (I915_READ(BXT_MIPI_PORT_CTRL(port
)) & DPI_ENABLE
)
782 fmt
= I915_READ(MIPI_DSI_FUNC_PRG(port
)) & VID_MODE_FORMAT_MASK
;
783 pipe_config
->pipe_bpp
=
784 mipi_dsi_pixel_format_to_bpp(
785 pixel_format_from_register_bits(fmt
));
786 bpp
= pipe_config
->pipe_bpp
;
788 /* In terms of pixels */
789 adjusted_mode
->crtc_hdisplay
=
790 I915_READ(BXT_MIPI_TRANS_HACTIVE(port
));
791 adjusted_mode
->crtc_vdisplay
=
792 I915_READ(BXT_MIPI_TRANS_VACTIVE(port
));
793 adjusted_mode
->crtc_vtotal
=
794 I915_READ(BXT_MIPI_TRANS_VTOTAL(port
));
797 * TODO: Retrieve hfp, hsync and hbp. Adjust them for dual link and
798 * calculate hsync_start, hsync_end, htotal and hblank_end
801 /* vertical values are in terms of lines */
802 vfp
= I915_READ(MIPI_VFP_COUNT(port
));
803 vsync
= I915_READ(MIPI_VSYNC_PADDING_COUNT(port
));
804 vbp
= I915_READ(MIPI_VBP_COUNT(port
));
806 adjusted_mode
->crtc_hblank_start
= adjusted_mode
->crtc_hdisplay
;
808 adjusted_mode
->crtc_vsync_start
=
809 vfp
+ adjusted_mode
->crtc_vdisplay
;
810 adjusted_mode
->crtc_vsync_end
=
811 vsync
+ adjusted_mode
->crtc_vsync_start
;
812 adjusted_mode
->crtc_vblank_start
= adjusted_mode
->crtc_vdisplay
;
813 adjusted_mode
->crtc_vblank_end
= adjusted_mode
->crtc_vtotal
;
817 static void intel_dsi_get_config(struct intel_encoder
*encoder
,
818 struct intel_crtc_state
*pipe_config
)
820 struct drm_device
*dev
= encoder
->base
.dev
;
824 pipe_config
->has_dsi_encoder
= true;
827 bxt_dsi_get_pipe_config(encoder
, pipe_config
);
830 * DPLL_MD is not used in case of DSI, reading will get some default value
833 pipe_config
->dpll_hw_state
.dpll_md
= 0;
835 pclk
= intel_dsi_get_pclk(encoder
, pipe_config
->pipe_bpp
);
839 pipe_config
->base
.adjusted_mode
.crtc_clock
= pclk
;
840 pipe_config
->port_clock
= pclk
;
843 static enum drm_mode_status
844 intel_dsi_mode_valid(struct drm_connector
*connector
,
845 struct drm_display_mode
*mode
)
847 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
848 struct drm_display_mode
*fixed_mode
= intel_connector
->panel
.fixed_mode
;
849 int max_dotclk
= to_i915(connector
->dev
)->max_dotclk_freq
;
853 if (mode
->flags
& DRM_MODE_FLAG_DBLSCAN
) {
854 DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n");
855 return MODE_NO_DBLESCAN
;
859 if (mode
->hdisplay
> fixed_mode
->hdisplay
)
861 if (mode
->vdisplay
> fixed_mode
->vdisplay
)
863 if (fixed_mode
->clock
> max_dotclk
)
864 return MODE_CLOCK_HIGH
;
870 /* return txclkesc cycles in terms of divider and duration in us */
871 static u16
txclkesc(u32 divider
, unsigned int us
)
874 case ESCAPE_CLOCK_DIVIDER_1
:
877 case ESCAPE_CLOCK_DIVIDER_2
:
879 case ESCAPE_CLOCK_DIVIDER_4
:
884 /* return pixels in terms of txbyteclkhs */
885 static u16
txbyteclkhs(u16 pixels
, int bpp
, int lane_count
,
886 u16 burst_mode_ratio
)
888 return DIV_ROUND_UP(DIV_ROUND_UP(pixels
* bpp
* burst_mode_ratio
,
889 8 * 100), lane_count
);
892 static void set_dsi_timings(struct drm_encoder
*encoder
,
893 const struct drm_display_mode
*adjusted_mode
)
895 struct drm_device
*dev
= encoder
->dev
;
896 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
897 struct intel_dsi
*intel_dsi
= enc_to_intel_dsi(encoder
);
899 unsigned int bpp
= mipi_dsi_pixel_format_to_bpp(intel_dsi
->pixel_format
);
900 unsigned int lane_count
= intel_dsi
->lane_count
;
902 u16 hactive
, hfp
, hsync
, hbp
, vfp
, vsync
, vbp
;
904 hactive
= adjusted_mode
->crtc_hdisplay
;
905 hfp
= adjusted_mode
->crtc_hsync_start
- adjusted_mode
->crtc_hdisplay
;
906 hsync
= adjusted_mode
->crtc_hsync_end
- adjusted_mode
->crtc_hsync_start
;
907 hbp
= adjusted_mode
->crtc_htotal
- adjusted_mode
->crtc_hsync_end
;
909 if (intel_dsi
->dual_link
) {
911 if (intel_dsi
->dual_link
== DSI_DUAL_LINK_FRONT_BACK
)
912 hactive
+= intel_dsi
->pixel_overlap
;
918 vfp
= adjusted_mode
->crtc_vsync_start
- adjusted_mode
->crtc_vdisplay
;
919 vsync
= adjusted_mode
->crtc_vsync_end
- adjusted_mode
->crtc_vsync_start
;
920 vbp
= adjusted_mode
->crtc_vtotal
- adjusted_mode
->crtc_vsync_end
;
922 /* horizontal values are in terms of high speed byte clock */
923 hactive
= txbyteclkhs(hactive
, bpp
, lane_count
,
924 intel_dsi
->burst_mode_ratio
);
925 hfp
= txbyteclkhs(hfp
, bpp
, lane_count
, intel_dsi
->burst_mode_ratio
);
926 hsync
= txbyteclkhs(hsync
, bpp
, lane_count
,
927 intel_dsi
->burst_mode_ratio
);
928 hbp
= txbyteclkhs(hbp
, bpp
, lane_count
, intel_dsi
->burst_mode_ratio
);
930 for_each_dsi_port(port
, intel_dsi
->ports
) {
931 if (IS_BROXTON(dev
)) {
933 * Program hdisplay and vdisplay on MIPI transcoder.
934 * This is different from calculated hactive and
935 * vactive, as they are calculated per channel basis,
936 * whereas these values should be based on resolution.
938 I915_WRITE(BXT_MIPI_TRANS_HACTIVE(port
),
939 adjusted_mode
->crtc_hdisplay
);
940 I915_WRITE(BXT_MIPI_TRANS_VACTIVE(port
),
941 adjusted_mode
->crtc_vdisplay
);
942 I915_WRITE(BXT_MIPI_TRANS_VTOTAL(port
),
943 adjusted_mode
->crtc_vtotal
);
946 I915_WRITE(MIPI_HACTIVE_AREA_COUNT(port
), hactive
);
947 I915_WRITE(MIPI_HFP_COUNT(port
), hfp
);
949 /* meaningful for video mode non-burst sync pulse mode only,
950 * can be zero for non-burst sync events and burst modes */
951 I915_WRITE(MIPI_HSYNC_PADDING_COUNT(port
), hsync
);
952 I915_WRITE(MIPI_HBP_COUNT(port
), hbp
);
954 /* vertical values are in terms of lines */
955 I915_WRITE(MIPI_VFP_COUNT(port
), vfp
);
956 I915_WRITE(MIPI_VSYNC_PADDING_COUNT(port
), vsync
);
957 I915_WRITE(MIPI_VBP_COUNT(port
), vbp
);
961 static u32
pixel_format_to_reg(enum mipi_dsi_pixel_format fmt
)
964 case MIPI_DSI_FMT_RGB888
:
965 return VID_MODE_FORMAT_RGB888
;
966 case MIPI_DSI_FMT_RGB666
:
967 return VID_MODE_FORMAT_RGB666
;
968 case MIPI_DSI_FMT_RGB666_PACKED
:
969 return VID_MODE_FORMAT_RGB666_PACKED
;
970 case MIPI_DSI_FMT_RGB565
:
971 return VID_MODE_FORMAT_RGB565
;
974 return VID_MODE_FORMAT_RGB666
;
978 static void intel_dsi_prepare(struct intel_encoder
*intel_encoder
)
980 struct drm_encoder
*encoder
= &intel_encoder
->base
;
981 struct drm_device
*dev
= encoder
->dev
;
982 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
983 struct intel_crtc
*intel_crtc
= to_intel_crtc(encoder
->crtc
);
984 struct intel_dsi
*intel_dsi
= enc_to_intel_dsi(encoder
);
985 const struct drm_display_mode
*adjusted_mode
= &intel_crtc
->config
->base
.adjusted_mode
;
987 unsigned int bpp
= mipi_dsi_pixel_format_to_bpp(intel_dsi
->pixel_format
);
991 DRM_DEBUG_KMS("pipe %c\n", pipe_name(intel_crtc
->pipe
));
993 mode_hdisplay
= adjusted_mode
->crtc_hdisplay
;
995 if (intel_dsi
->dual_link
) {
997 if (intel_dsi
->dual_link
== DSI_DUAL_LINK_FRONT_BACK
)
998 mode_hdisplay
+= intel_dsi
->pixel_overlap
;
1001 for_each_dsi_port(port
, intel_dsi
->ports
) {
1002 if (IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)) {
1004 * escape clock divider, 20MHz, shared for A and C.
1005 * device ready must be off when doing this! txclkesc?
1007 tmp
= I915_READ(MIPI_CTRL(PORT_A
));
1008 tmp
&= ~ESCAPE_CLOCK_DIVIDER_MASK
;
1009 I915_WRITE(MIPI_CTRL(PORT_A
), tmp
|
1010 ESCAPE_CLOCK_DIVIDER_1
);
1012 /* read request priority is per pipe */
1013 tmp
= I915_READ(MIPI_CTRL(port
));
1014 tmp
&= ~READ_REQUEST_PRIORITY_MASK
;
1015 I915_WRITE(MIPI_CTRL(port
), tmp
|
1016 READ_REQUEST_PRIORITY_HIGH
);
1017 } else if (IS_BROXTON(dev
)) {
1018 enum pipe pipe
= intel_crtc
->pipe
;
1020 tmp
= I915_READ(MIPI_CTRL(port
));
1021 tmp
&= ~BXT_PIPE_SELECT_MASK
;
1023 tmp
|= BXT_PIPE_SELECT(pipe
);
1024 I915_WRITE(MIPI_CTRL(port
), tmp
);
1027 /* XXX: why here, why like this? handling in irq handler?! */
1028 I915_WRITE(MIPI_INTR_STAT(port
), 0xffffffff);
1029 I915_WRITE(MIPI_INTR_EN(port
), 0xffffffff);
1031 I915_WRITE(MIPI_DPHY_PARAM(port
), intel_dsi
->dphy_reg
);
1033 I915_WRITE(MIPI_DPI_RESOLUTION(port
),
1034 adjusted_mode
->crtc_vdisplay
<< VERTICAL_ADDRESS_SHIFT
|
1035 mode_hdisplay
<< HORIZONTAL_ADDRESS_SHIFT
);
1038 set_dsi_timings(encoder
, adjusted_mode
);
1040 val
= intel_dsi
->lane_count
<< DATA_LANES_PRG_REG_SHIFT
;
1041 if (is_cmd_mode(intel_dsi
)) {
1042 val
|= intel_dsi
->channel
<< CMD_MODE_CHANNEL_NUMBER_SHIFT
;
1043 val
|= CMD_MODE_DATA_WIDTH_8_BIT
; /* XXX */
1045 val
|= intel_dsi
->channel
<< VID_MODE_CHANNEL_NUMBER_SHIFT
;
1046 val
|= pixel_format_to_reg(intel_dsi
->pixel_format
);
1050 if (intel_dsi
->eotp_pkt
== 0)
1052 if (intel_dsi
->clock_stop
)
1055 for_each_dsi_port(port
, intel_dsi
->ports
) {
1056 I915_WRITE(MIPI_DSI_FUNC_PRG(port
), val
);
1058 /* timeouts for recovery. one frame IIUC. if counter expires,
1059 * EOT and stop state. */
1062 * In burst mode, value greater than one DPI line Time in byte
1063 * clock (txbyteclkhs) To timeout this timer 1+ of the above
1064 * said value is recommended.
1066 * In non-burst mode, Value greater than one DPI frame time in
1067 * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
1068 * said value is recommended.
1070 * In DBI only mode, value greater than one DBI frame time in
1071 * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
1072 * said value is recommended.
1075 if (is_vid_mode(intel_dsi
) &&
1076 intel_dsi
->video_mode_format
== VIDEO_MODE_BURST
) {
1077 I915_WRITE(MIPI_HS_TX_TIMEOUT(port
),
1078 txbyteclkhs(adjusted_mode
->crtc_htotal
, bpp
,
1079 intel_dsi
->lane_count
,
1080 intel_dsi
->burst_mode_ratio
) + 1);
1082 I915_WRITE(MIPI_HS_TX_TIMEOUT(port
),
1083 txbyteclkhs(adjusted_mode
->crtc_vtotal
*
1084 adjusted_mode
->crtc_htotal
,
1085 bpp
, intel_dsi
->lane_count
,
1086 intel_dsi
->burst_mode_ratio
) + 1);
1088 I915_WRITE(MIPI_LP_RX_TIMEOUT(port
), intel_dsi
->lp_rx_timeout
);
1089 I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(port
),
1090 intel_dsi
->turn_arnd_val
);
1091 I915_WRITE(MIPI_DEVICE_RESET_TIMER(port
),
1092 intel_dsi
->rst_timer_val
);
1096 /* in terms of low power clock */
1097 I915_WRITE(MIPI_INIT_COUNT(port
),
1098 txclkesc(intel_dsi
->escape_clk_div
, 100));
1100 if (IS_BROXTON(dev
) && (!intel_dsi
->dual_link
)) {
1102 * BXT spec says write MIPI_INIT_COUNT for
1103 * both the ports, even if only one is
1104 * getting used. So write the other port
1105 * if not in dual link mode.
1107 I915_WRITE(MIPI_INIT_COUNT(port
==
1108 PORT_A
? PORT_C
: PORT_A
),
1109 intel_dsi
->init_count
);
1112 /* recovery disables */
1113 I915_WRITE(MIPI_EOT_DISABLE(port
), tmp
);
1115 /* in terms of low power clock */
1116 I915_WRITE(MIPI_INIT_COUNT(port
), intel_dsi
->init_count
);
1118 /* in terms of txbyteclkhs. actual high to low switch +
1119 * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
1121 * XXX: write MIPI_STOP_STATE_STALL?
1123 I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(port
),
1124 intel_dsi
->hs_to_lp_count
);
1126 /* XXX: low power clock equivalence in terms of byte clock.
1127 * the number of byte clocks occupied in one low power clock.
1128 * based on txbyteclkhs and txclkesc.
1129 * txclkesc time / txbyteclk time * (105 + MIPI_STOP_STATE_STALL
1132 I915_WRITE(MIPI_LP_BYTECLK(port
), intel_dsi
->lp_byte_clk
);
1134 /* the bw essential for transmitting 16 long packets containing
1135 * 252 bytes meant for dcs write memory command is programmed in
1136 * this register in terms of byte clocks. based on dsi transfer
1137 * rate and the number of lanes configured the time taken to
1138 * transmit 16 long packets in a dsi stream varies. */
1139 I915_WRITE(MIPI_DBI_BW_CTRL(port
), intel_dsi
->bw_timer
);
1141 I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(port
),
1142 intel_dsi
->clk_lp_to_hs_count
<< LP_HS_SSW_CNT_SHIFT
|
1143 intel_dsi
->clk_hs_to_lp_count
<< HS_LP_PWR_SW_CNT_SHIFT
);
1145 if (is_vid_mode(intel_dsi
))
1146 /* Some panels might have resolution which is not a
1147 * multiple of 64 like 1366 x 768. Enable RANDOM
1148 * resolution support for such panels by default */
1149 I915_WRITE(MIPI_VIDEO_MODE_FORMAT(port
),
1150 intel_dsi
->video_frmt_cfg_bits
|
1151 intel_dsi
->video_mode_format
|
1153 RANDOM_DPI_DISPLAY_RESOLUTION
);
1157 static enum drm_connector_status
1158 intel_dsi_detect(struct drm_connector
*connector
, bool force
)
1160 return connector_status_connected
;
1163 static int intel_dsi_get_modes(struct drm_connector
*connector
)
1165 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
1166 struct drm_display_mode
*mode
;
1168 DRM_DEBUG_KMS("\n");
1170 if (!intel_connector
->panel
.fixed_mode
) {
1171 DRM_DEBUG_KMS("no fixed mode\n");
1175 mode
= drm_mode_duplicate(connector
->dev
,
1176 intel_connector
->panel
.fixed_mode
);
1178 DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
1182 drm_mode_probed_add(connector
, mode
);
1186 static void intel_dsi_connector_destroy(struct drm_connector
*connector
)
1188 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
1190 DRM_DEBUG_KMS("\n");
1191 intel_panel_fini(&intel_connector
->panel
);
1192 drm_connector_cleanup(connector
);
1196 static void intel_dsi_encoder_destroy(struct drm_encoder
*encoder
)
1198 struct intel_dsi
*intel_dsi
= enc_to_intel_dsi(encoder
);
1200 if (intel_dsi
->panel
) {
1201 drm_panel_detach(intel_dsi
->panel
);
1202 /* XXX: Logically this call belongs in the panel driver. */
1203 drm_panel_remove(intel_dsi
->panel
);
1206 /* dispose of the gpios */
1207 if (intel_dsi
->gpio_panel
)
1208 gpiod_put(intel_dsi
->gpio_panel
);
1210 intel_encoder_destroy(encoder
);
1213 static const struct drm_encoder_funcs intel_dsi_funcs
= {
1214 .destroy
= intel_dsi_encoder_destroy
,
1217 static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs
= {
1218 .get_modes
= intel_dsi_get_modes
,
1219 .mode_valid
= intel_dsi_mode_valid
,
1220 .best_encoder
= intel_best_encoder
,
1223 static const struct drm_connector_funcs intel_dsi_connector_funcs
= {
1224 .dpms
= drm_atomic_helper_connector_dpms
,
1225 .detect
= intel_dsi_detect
,
1226 .destroy
= intel_dsi_connector_destroy
,
1227 .fill_modes
= drm_helper_probe_single_connector_modes
,
1228 .atomic_get_property
= intel_connector_atomic_get_property
,
1229 .atomic_destroy_state
= drm_atomic_helper_connector_destroy_state
,
1230 .atomic_duplicate_state
= drm_atomic_helper_connector_duplicate_state
,
1233 void intel_dsi_init(struct drm_device
*dev
)
1235 struct intel_dsi
*intel_dsi
;
1236 struct intel_encoder
*intel_encoder
;
1237 struct drm_encoder
*encoder
;
1238 struct intel_connector
*intel_connector
;
1239 struct drm_connector
*connector
;
1240 struct drm_display_mode
*scan
, *fixed_mode
= NULL
;
1241 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1245 DRM_DEBUG_KMS("\n");
1247 /* There is no detection method for MIPI so rely on VBT */
1248 if (!intel_bios_is_dsi_present(dev_priv
, &port
))
1251 if (IS_VALLEYVIEW(dev
) || IS_CHERRYVIEW(dev
)) {
1252 dev_priv
->mipi_mmio_base
= VLV_MIPI_BASE
;
1253 } else if (IS_BROXTON(dev
)) {
1254 dev_priv
->mipi_mmio_base
= BXT_MIPI_BASE
;
1256 DRM_ERROR("Unsupported Mipi device to reg base");
1260 intel_dsi
= kzalloc(sizeof(*intel_dsi
), GFP_KERNEL
);
1264 intel_connector
= intel_connector_alloc();
1265 if (!intel_connector
) {
1270 intel_encoder
= &intel_dsi
->base
;
1271 encoder
= &intel_encoder
->base
;
1272 intel_dsi
->attached_connector
= intel_connector
;
1274 connector
= &intel_connector
->base
;
1276 drm_encoder_init(dev
, encoder
, &intel_dsi_funcs
, DRM_MODE_ENCODER_DSI
,
1279 intel_encoder
->compute_config
= intel_dsi_compute_config
;
1280 intel_encoder
->pre_enable
= intel_dsi_pre_enable
;
1281 intel_encoder
->enable
= intel_dsi_enable_nop
;
1282 intel_encoder
->disable
= intel_dsi_pre_disable
;
1283 intel_encoder
->post_disable
= intel_dsi_post_disable
;
1284 intel_encoder
->get_hw_state
= intel_dsi_get_hw_state
;
1285 intel_encoder
->get_config
= intel_dsi_get_config
;
1287 intel_connector
->get_hw_state
= intel_connector_get_hw_state
;
1288 intel_connector
->unregister
= intel_connector_unregister
;
1291 * On BYT/CHV, pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI
1292 * port C. BXT isn't limited like this.
1294 if (IS_BROXTON(dev_priv
))
1295 intel_encoder
->crtc_mask
= BIT(PIPE_A
) | BIT(PIPE_B
) | BIT(PIPE_C
);
1296 else if (port
== PORT_A
)
1297 intel_encoder
->crtc_mask
= BIT(PIPE_A
);
1299 intel_encoder
->crtc_mask
= BIT(PIPE_B
);
1301 if (dev_priv
->vbt
.dsi
.config
->dual_link
)
1302 intel_dsi
->ports
= BIT(PORT_A
) | BIT(PORT_C
);
1304 intel_dsi
->ports
= BIT(port
);
1306 /* Create a DSI host (and a device) for each port. */
1307 for_each_dsi_port(port
, intel_dsi
->ports
) {
1308 struct intel_dsi_host
*host
;
1310 host
= intel_dsi_host_init(intel_dsi
, port
);
1314 intel_dsi
->dsi_hosts
[port
] = host
;
1317 for (i
= 0; i
< ARRAY_SIZE(intel_dsi_drivers
); i
++) {
1318 intel_dsi
->panel
= intel_dsi_drivers
[i
].init(intel_dsi
,
1319 intel_dsi_drivers
[i
].panel_id
);
1320 if (intel_dsi
->panel
)
1324 if (!intel_dsi
->panel
) {
1325 DRM_DEBUG_KMS("no device found\n");
1330 * In case of BYT with CRC PMIC, we need to use GPIO for
1333 if (dev_priv
->vbt
.dsi
.config
->pwm_blc
== PPS_BLC_PMIC
) {
1334 intel_dsi
->gpio_panel
=
1335 gpiod_get(dev
->dev
, "panel", GPIOD_OUT_HIGH
);
1337 if (IS_ERR(intel_dsi
->gpio_panel
)) {
1338 DRM_ERROR("Failed to own gpio for panel control\n");
1339 intel_dsi
->gpio_panel
= NULL
;
1343 intel_encoder
->type
= INTEL_OUTPUT_DSI
;
1344 intel_encoder
->cloneable
= 0;
1345 drm_connector_init(dev
, connector
, &intel_dsi_connector_funcs
,
1346 DRM_MODE_CONNECTOR_DSI
);
1348 drm_connector_helper_add(connector
, &intel_dsi_connector_helper_funcs
);
1350 connector
->display_info
.subpixel_order
= SubPixelHorizontalRGB
; /*XXX*/
1351 connector
->interlace_allowed
= false;
1352 connector
->doublescan_allowed
= false;
1354 intel_connector_attach_encoder(intel_connector
, intel_encoder
);
1356 drm_connector_register(connector
);
1358 drm_panel_attach(intel_dsi
->panel
, connector
);
1360 mutex_lock(&dev
->mode_config
.mutex
);
1361 drm_panel_get_modes(intel_dsi
->panel
);
1362 list_for_each_entry(scan
, &connector
->probed_modes
, head
) {
1363 if ((scan
->type
& DRM_MODE_TYPE_PREFERRED
)) {
1364 fixed_mode
= drm_mode_duplicate(dev
, scan
);
1368 mutex_unlock(&dev
->mode_config
.mutex
);
1371 DRM_DEBUG_KMS("no fixed mode\n");
1375 intel_panel_init(&intel_connector
->panel
, fixed_mode
, NULL
);
1376 intel_panel_setup_backlight(connector
, INVALID_PIPE
);
1381 drm_encoder_cleanup(&intel_encoder
->base
);
1383 kfree(intel_connector
);