2 * Copyright © 2008 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 DEALINGS
24 * Keith Packard <keithp@keithp.com>
28 #include <linux/i2c.h>
29 #include <linux/slab.h>
30 #include <linux/export.h>
32 #include <drm/drm_crtc.h>
33 #include <drm/drm_crtc_helper.h>
34 #include <drm/drm_edid.h>
35 #include "intel_drv.h"
36 #include <drm/i915_drm.h>
39 #define DP_LINK_CHECK_TIMEOUT (10 * 1000)
42 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
43 * @intel_dp: DP struct
45 * If a CPU or PCH DP output is attached to an eDP panel, this function
46 * will return true, and false otherwise.
48 static bool is_edp(struct intel_dp
*intel_dp
)
50 struct intel_digital_port
*intel_dig_port
= dp_to_dig_port(intel_dp
);
52 return intel_dig_port
->base
.type
== INTEL_OUTPUT_EDP
;
56 * is_pch_edp - is the port on the PCH and attached to an eDP panel?
57 * @intel_dp: DP struct
59 * Returns true if the given DP struct corresponds to a PCH DP port attached
60 * to an eDP panel, false otherwise. Helpful for determining whether we
61 * may need FDI resources for a given DP output or not.
63 static bool is_pch_edp(struct intel_dp
*intel_dp
)
65 return intel_dp
->is_pch_edp
;
69 * is_cpu_edp - is the port on the CPU and attached to an eDP panel?
70 * @intel_dp: DP struct
72 * Returns true if the given DP struct corresponds to a CPU eDP port.
74 static bool is_cpu_edp(struct intel_dp
*intel_dp
)
76 return is_edp(intel_dp
) && !is_pch_edp(intel_dp
);
79 static struct drm_device
*intel_dp_to_dev(struct intel_dp
*intel_dp
)
81 struct intel_digital_port
*intel_dig_port
= dp_to_dig_port(intel_dp
);
83 return intel_dig_port
->base
.base
.dev
;
86 static struct intel_dp
*intel_attached_dp(struct drm_connector
*connector
)
88 return enc_to_intel_dp(&intel_attached_encoder(connector
)->base
);
92 * intel_encoder_is_pch_edp - is the given encoder a PCH attached eDP?
93 * @encoder: DRM encoder
95 * Return true if @encoder corresponds to a PCH attached eDP panel. Needed
98 bool intel_encoder_is_pch_edp(struct drm_encoder
*encoder
)
100 struct intel_dp
*intel_dp
;
105 intel_dp
= enc_to_intel_dp(encoder
);
107 return is_pch_edp(intel_dp
);
110 static void intel_dp_link_down(struct intel_dp
*intel_dp
);
113 intel_edp_link_config(struct intel_encoder
*intel_encoder
,
114 int *lane_num
, int *link_bw
)
116 struct intel_dp
*intel_dp
= enc_to_intel_dp(&intel_encoder
->base
);
118 *lane_num
= intel_dp
->lane_count
;
119 *link_bw
= drm_dp_bw_code_to_link_rate(intel_dp
->link_bw
);
123 intel_edp_target_clock(struct intel_encoder
*intel_encoder
,
124 struct drm_display_mode
*mode
)
126 struct intel_dp
*intel_dp
= enc_to_intel_dp(&intel_encoder
->base
);
127 struct intel_connector
*intel_connector
= intel_dp
->attached_connector
;
129 if (intel_connector
->panel
.fixed_mode
)
130 return intel_connector
->panel
.fixed_mode
->clock
;
136 intel_dp_max_link_bw(struct intel_dp
*intel_dp
)
138 int max_link_bw
= intel_dp
->dpcd
[DP_MAX_LINK_RATE
];
140 switch (max_link_bw
) {
141 case DP_LINK_BW_1_62
:
145 max_link_bw
= DP_LINK_BW_1_62
;
152 * The units on the numbers in the next two are... bizarre. Examples will
153 * make it clearer; this one parallels an example in the eDP spec.
155 * intel_dp_max_data_rate for one lane of 2.7GHz evaluates as:
157 * 270000 * 1 * 8 / 10 == 216000
159 * The actual data capacity of that configuration is 2.16Gbit/s, so the
160 * units are decakilobits. ->clock in a drm_display_mode is in kilohertz -
161 * or equivalently, kilopixels per second - so for 1680x1050R it'd be
162 * 119000. At 18bpp that's 2142000 kilobits per second.
164 * Thus the strange-looking division by 10 in intel_dp_link_required, to
165 * get the result in decakilobits instead of kilobits.
169 intel_dp_link_required(int pixel_clock
, int bpp
)
171 return (pixel_clock
* bpp
+ 9) / 10;
175 intel_dp_max_data_rate(int max_link_clock
, int max_lanes
)
177 return (max_link_clock
* max_lanes
* 8) / 10;
181 intel_dp_mode_valid(struct drm_connector
*connector
,
182 struct drm_display_mode
*mode
)
184 struct intel_dp
*intel_dp
= intel_attached_dp(connector
);
185 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
186 struct drm_display_mode
*fixed_mode
= intel_connector
->panel
.fixed_mode
;
187 int target_clock
= mode
->clock
;
188 int max_rate
, mode_rate
, max_lanes
, max_link_clock
;
190 if (is_edp(intel_dp
) && fixed_mode
) {
191 if (mode
->hdisplay
> fixed_mode
->hdisplay
)
194 if (mode
->vdisplay
> fixed_mode
->vdisplay
)
197 target_clock
= fixed_mode
->clock
;
200 max_link_clock
= drm_dp_bw_code_to_link_rate(intel_dp_max_link_bw(intel_dp
));
201 max_lanes
= drm_dp_max_lane_count(intel_dp
->dpcd
);
203 max_rate
= intel_dp_max_data_rate(max_link_clock
, max_lanes
);
204 mode_rate
= intel_dp_link_required(target_clock
, 18);
206 if (mode_rate
> max_rate
)
207 return MODE_CLOCK_HIGH
;
209 if (mode
->clock
< 10000)
210 return MODE_CLOCK_LOW
;
212 if (mode
->flags
& DRM_MODE_FLAG_DBLCLK
)
213 return MODE_H_ILLEGAL
;
219 pack_aux(uint8_t *src
, int src_bytes
)
226 for (i
= 0; i
< src_bytes
; i
++)
227 v
|= ((uint32_t) src
[i
]) << ((3-i
) * 8);
232 unpack_aux(uint32_t src
, uint8_t *dst
, int dst_bytes
)
237 for (i
= 0; i
< dst_bytes
; i
++)
238 dst
[i
] = src
>> ((3-i
) * 8);
241 /* hrawclock is 1/4 the FSB frequency */
243 intel_hrawclk(struct drm_device
*dev
)
245 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
248 /* There is no CLKCFG reg in Valleyview. VLV hrawclk is 200 MHz */
249 if (IS_VALLEYVIEW(dev
))
252 clkcfg
= I915_READ(CLKCFG
);
253 switch (clkcfg
& CLKCFG_FSB_MASK
) {
262 case CLKCFG_FSB_1067
:
264 case CLKCFG_FSB_1333
:
266 /* these two are just a guess; one of them might be right */
267 case CLKCFG_FSB_1600
:
268 case CLKCFG_FSB_1600_ALT
:
275 static bool ironlake_edp_have_panel_power(struct intel_dp
*intel_dp
)
277 struct drm_device
*dev
= intel_dp_to_dev(intel_dp
);
278 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
281 pp_stat_reg
= IS_VALLEYVIEW(dev
) ? PIPEA_PP_STATUS
: PCH_PP_STATUS
;
282 return (I915_READ(pp_stat_reg
) & PP_ON
) != 0;
285 static bool ironlake_edp_have_panel_vdd(struct intel_dp
*intel_dp
)
287 struct drm_device
*dev
= intel_dp_to_dev(intel_dp
);
288 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
291 pp_ctrl_reg
= IS_VALLEYVIEW(dev
) ? PIPEA_PP_CONTROL
: PCH_PP_CONTROL
;
292 return (I915_READ(pp_ctrl_reg
) & EDP_FORCE_VDD
) != 0;
296 intel_dp_check_edp(struct intel_dp
*intel_dp
)
298 struct drm_device
*dev
= intel_dp_to_dev(intel_dp
);
299 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
300 u32 pp_stat_reg
, pp_ctrl_reg
;
302 if (!is_edp(intel_dp
))
305 pp_stat_reg
= IS_VALLEYVIEW(dev
) ? PIPEA_PP_STATUS
: PCH_PP_STATUS
;
306 pp_ctrl_reg
= IS_VALLEYVIEW(dev
) ? PIPEA_PP_CONTROL
: PCH_PP_CONTROL
;
308 if (!ironlake_edp_have_panel_power(intel_dp
) && !ironlake_edp_have_panel_vdd(intel_dp
)) {
309 WARN(1, "eDP powered off while attempting aux channel communication.\n");
310 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
311 I915_READ(pp_stat_reg
),
312 I915_READ(pp_ctrl_reg
));
317 intel_dp_aux_wait_done(struct intel_dp
*intel_dp
, bool has_aux_irq
)
319 struct intel_digital_port
*intel_dig_port
= dp_to_dig_port(intel_dp
);
320 struct drm_device
*dev
= intel_dig_port
->base
.base
.dev
;
321 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
322 uint32_t ch_ctl
= intel_dp
->aux_ch_ctl_reg
;
326 #define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
328 done
= wait_event_timeout(dev_priv
->gmbus_wait_queue
, C
,
329 msecs_to_jiffies(10));
331 done
= wait_for_atomic(C
, 10) == 0;
333 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
341 intel_dp_aux_ch(struct intel_dp
*intel_dp
,
342 uint8_t *send
, int send_bytes
,
343 uint8_t *recv
, int recv_size
)
345 struct intel_digital_port
*intel_dig_port
= dp_to_dig_port(intel_dp
);
346 struct drm_device
*dev
= intel_dig_port
->base
.base
.dev
;
347 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
348 uint32_t ch_ctl
= intel_dp
->aux_ch_ctl_reg
;
349 uint32_t ch_data
= ch_ctl
+ 4;
350 int i
, ret
, recv_bytes
;
352 uint32_t aux_clock_divider
;
354 bool has_aux_irq
= INTEL_INFO(dev
)->gen
>= 5 && !IS_VALLEYVIEW(dev
);
356 /* dp aux is extremely sensitive to irq latency, hence request the
357 * lowest possible wakeup latency and so prevent the cpu from going into
360 pm_qos_update_request(&dev_priv
->pm_qos
, 0);
362 intel_dp_check_edp(intel_dp
);
363 /* The clock divider is based off the hrawclk,
364 * and would like to run at 2MHz. So, take the
365 * hrawclk value and divide by 2 and use that
367 * Note that PCH attached eDP panels should use a 125MHz input
370 if (is_cpu_edp(intel_dp
)) {
372 aux_clock_divider
= intel_ddi_get_cdclk_freq(dev_priv
) >> 1;
373 else if (IS_VALLEYVIEW(dev
))
374 aux_clock_divider
= 100;
375 else if (IS_GEN6(dev
) || IS_GEN7(dev
))
376 aux_clock_divider
= 200; /* SNB & IVB eDP input clock at 400Mhz */
378 aux_clock_divider
= 225; /* eDP input clock at 450Mhz */
379 } else if (HAS_PCH_SPLIT(dev
))
380 aux_clock_divider
= DIV_ROUND_UP(intel_pch_rawclk(dev
), 2);
382 aux_clock_divider
= intel_hrawclk(dev
) / 2;
389 /* Try to wait for any previous AUX channel activity */
390 for (try = 0; try < 3; try++) {
391 status
= I915_READ_NOTRACE(ch_ctl
);
392 if ((status
& DP_AUX_CH_CTL_SEND_BUSY
) == 0)
398 WARN(1, "dp_aux_ch not started status 0x%08x\n",
404 /* Must try at least 3 times according to DP spec */
405 for (try = 0; try < 5; try++) {
406 /* Load the send data into the aux channel data registers */
407 for (i
= 0; i
< send_bytes
; i
+= 4)
408 I915_WRITE(ch_data
+ i
,
409 pack_aux(send
+ i
, send_bytes
- i
));
411 /* Send the command and wait for it to complete */
413 DP_AUX_CH_CTL_SEND_BUSY
|
414 (has_aux_irq
? DP_AUX_CH_CTL_INTERRUPT
: 0) |
415 DP_AUX_CH_CTL_TIME_OUT_400us
|
416 (send_bytes
<< DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT
) |
417 (precharge
<< DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT
) |
418 (aux_clock_divider
<< DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT
) |
420 DP_AUX_CH_CTL_TIME_OUT_ERROR
|
421 DP_AUX_CH_CTL_RECEIVE_ERROR
);
423 status
= intel_dp_aux_wait_done(intel_dp
, has_aux_irq
);
425 /* Clear done status and any errors */
429 DP_AUX_CH_CTL_TIME_OUT_ERROR
|
430 DP_AUX_CH_CTL_RECEIVE_ERROR
);
432 if (status
& (DP_AUX_CH_CTL_TIME_OUT_ERROR
|
433 DP_AUX_CH_CTL_RECEIVE_ERROR
))
435 if (status
& DP_AUX_CH_CTL_DONE
)
439 if ((status
& DP_AUX_CH_CTL_DONE
) == 0) {
440 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status
);
445 /* Check for timeout or receive error.
446 * Timeouts occur when the sink is not connected
448 if (status
& DP_AUX_CH_CTL_RECEIVE_ERROR
) {
449 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status
);
454 /* Timeouts occur when the device isn't connected, so they're
455 * "normal" -- don't fill the kernel log with these */
456 if (status
& DP_AUX_CH_CTL_TIME_OUT_ERROR
) {
457 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status
);
462 /* Unload any bytes sent back from the other side */
463 recv_bytes
= ((status
& DP_AUX_CH_CTL_MESSAGE_SIZE_MASK
) >>
464 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT
);
465 if (recv_bytes
> recv_size
)
466 recv_bytes
= recv_size
;
468 for (i
= 0; i
< recv_bytes
; i
+= 4)
469 unpack_aux(I915_READ(ch_data
+ i
),
470 recv
+ i
, recv_bytes
- i
);
474 pm_qos_update_request(&dev_priv
->pm_qos
, PM_QOS_DEFAULT_VALUE
);
479 /* Write data to the aux channel in native mode */
481 intel_dp_aux_native_write(struct intel_dp
*intel_dp
,
482 uint16_t address
, uint8_t *send
, int send_bytes
)
489 intel_dp_check_edp(intel_dp
);
492 msg
[0] = AUX_NATIVE_WRITE
<< 4;
493 msg
[1] = address
>> 8;
494 msg
[2] = address
& 0xff;
495 msg
[3] = send_bytes
- 1;
496 memcpy(&msg
[4], send
, send_bytes
);
497 msg_bytes
= send_bytes
+ 4;
499 ret
= intel_dp_aux_ch(intel_dp
, msg
, msg_bytes
, &ack
, 1);
502 if ((ack
& AUX_NATIVE_REPLY_MASK
) == AUX_NATIVE_REPLY_ACK
)
504 else if ((ack
& AUX_NATIVE_REPLY_MASK
) == AUX_NATIVE_REPLY_DEFER
)
512 /* Write a single byte to the aux channel in native mode */
514 intel_dp_aux_native_write_1(struct intel_dp
*intel_dp
,
515 uint16_t address
, uint8_t byte
)
517 return intel_dp_aux_native_write(intel_dp
, address
, &byte
, 1);
520 /* read bytes from a native aux channel */
522 intel_dp_aux_native_read(struct intel_dp
*intel_dp
,
523 uint16_t address
, uint8_t *recv
, int recv_bytes
)
532 intel_dp_check_edp(intel_dp
);
533 msg
[0] = AUX_NATIVE_READ
<< 4;
534 msg
[1] = address
>> 8;
535 msg
[2] = address
& 0xff;
536 msg
[3] = recv_bytes
- 1;
539 reply_bytes
= recv_bytes
+ 1;
542 ret
= intel_dp_aux_ch(intel_dp
, msg
, msg_bytes
,
549 if ((ack
& AUX_NATIVE_REPLY_MASK
) == AUX_NATIVE_REPLY_ACK
) {
550 memcpy(recv
, reply
+ 1, ret
- 1);
553 else if ((ack
& AUX_NATIVE_REPLY_MASK
) == AUX_NATIVE_REPLY_DEFER
)
561 intel_dp_i2c_aux_ch(struct i2c_adapter
*adapter
, int mode
,
562 uint8_t write_byte
, uint8_t *read_byte
)
564 struct i2c_algo_dp_aux_data
*algo_data
= adapter
->algo_data
;
565 struct intel_dp
*intel_dp
= container_of(adapter
,
568 uint16_t address
= algo_data
->address
;
576 intel_dp_check_edp(intel_dp
);
577 /* Set up the command byte */
578 if (mode
& MODE_I2C_READ
)
579 msg
[0] = AUX_I2C_READ
<< 4;
581 msg
[0] = AUX_I2C_WRITE
<< 4;
583 if (!(mode
& MODE_I2C_STOP
))
584 msg
[0] |= AUX_I2C_MOT
<< 4;
586 msg
[1] = address
>> 8;
607 for (retry
= 0; retry
< 5; retry
++) {
608 ret
= intel_dp_aux_ch(intel_dp
,
612 DRM_DEBUG_KMS("aux_ch failed %d\n", ret
);
616 switch (reply
[0] & AUX_NATIVE_REPLY_MASK
) {
617 case AUX_NATIVE_REPLY_ACK
:
618 /* I2C-over-AUX Reply field is only valid
619 * when paired with AUX ACK.
622 case AUX_NATIVE_REPLY_NACK
:
623 DRM_DEBUG_KMS("aux_ch native nack\n");
625 case AUX_NATIVE_REPLY_DEFER
:
629 DRM_ERROR("aux_ch invalid native reply 0x%02x\n",
634 switch (reply
[0] & AUX_I2C_REPLY_MASK
) {
635 case AUX_I2C_REPLY_ACK
:
636 if (mode
== MODE_I2C_READ
) {
637 *read_byte
= reply
[1];
639 return reply_bytes
- 1;
640 case AUX_I2C_REPLY_NACK
:
641 DRM_DEBUG_KMS("aux_i2c nack\n");
643 case AUX_I2C_REPLY_DEFER
:
644 DRM_DEBUG_KMS("aux_i2c defer\n");
648 DRM_ERROR("aux_i2c invalid reply 0x%02x\n", reply
[0]);
653 DRM_ERROR("too many retries, giving up\n");
658 intel_dp_i2c_init(struct intel_dp
*intel_dp
,
659 struct intel_connector
*intel_connector
, const char *name
)
663 DRM_DEBUG_KMS("i2c_init %s\n", name
);
664 intel_dp
->algo
.running
= false;
665 intel_dp
->algo
.address
= 0;
666 intel_dp
->algo
.aux_ch
= intel_dp_i2c_aux_ch
;
668 memset(&intel_dp
->adapter
, '\0', sizeof(intel_dp
->adapter
));
669 intel_dp
->adapter
.owner
= THIS_MODULE
;
670 intel_dp
->adapter
.class = I2C_CLASS_DDC
;
671 strncpy(intel_dp
->adapter
.name
, name
, sizeof(intel_dp
->adapter
.name
) - 1);
672 intel_dp
->adapter
.name
[sizeof(intel_dp
->adapter
.name
) - 1] = '\0';
673 intel_dp
->adapter
.algo_data
= &intel_dp
->algo
;
674 intel_dp
->adapter
.dev
.parent
= &intel_connector
->base
.kdev
;
676 ironlake_edp_panel_vdd_on(intel_dp
);
677 ret
= i2c_dp_aux_add_bus(&intel_dp
->adapter
);
678 ironlake_edp_panel_vdd_off(intel_dp
, false);
683 intel_dp_compute_config(struct intel_encoder
*encoder
,
684 struct intel_crtc_config
*pipe_config
)
686 struct drm_device
*dev
= encoder
->base
.dev
;
687 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
688 struct drm_display_mode
*adjusted_mode
= &pipe_config
->adjusted_mode
;
689 struct drm_display_mode
*mode
= &pipe_config
->requested_mode
;
690 struct intel_dp
*intel_dp
= enc_to_intel_dp(&encoder
->base
);
691 struct intel_connector
*intel_connector
= intel_dp
->attached_connector
;
692 int lane_count
, clock
;
693 int max_lane_count
= drm_dp_max_lane_count(intel_dp
->dpcd
);
694 int max_clock
= intel_dp_max_link_bw(intel_dp
) == DP_LINK_BW_2_7
? 1 : 0;
696 static int bws
[2] = { DP_LINK_BW_1_62
, DP_LINK_BW_2_7
};
697 int target_clock
, link_avail
, link_clock
;
699 if (HAS_PCH_SPLIT(dev
) && !HAS_DDI(dev
) && !is_cpu_edp(intel_dp
))
700 pipe_config
->has_pch_encoder
= true;
702 pipe_config
->has_dp_encoder
= true;
704 if (is_edp(intel_dp
) && intel_connector
->panel
.fixed_mode
) {
705 intel_fixed_panel_mode(intel_connector
->panel
.fixed_mode
,
707 intel_pch_panel_fitting(dev
,
708 intel_connector
->panel
.fitting_mode
,
709 mode
, adjusted_mode
);
711 /* We need to take the panel's fixed mode into account. */
712 target_clock
= adjusted_mode
->clock
;
714 if (adjusted_mode
->flags
& DRM_MODE_FLAG_DBLCLK
)
717 DRM_DEBUG_KMS("DP link computation with max lane count %i "
718 "max bw %02x pixel clock %iKHz\n",
719 max_lane_count
, bws
[max_clock
], adjusted_mode
->clock
);
721 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
723 bpp
= min_t(int, 8*3, pipe_config
->pipe_bpp
);
724 if (is_edp(intel_dp
) && dev_priv
->edp
.bpp
)
725 bpp
= min_t(int, bpp
, dev_priv
->edp
.bpp
);
727 for (; bpp
>= 6*3; bpp
-= 2*3) {
728 mode_rate
= intel_dp_link_required(target_clock
, bpp
);
730 for (clock
= 0; clock
<= max_clock
; clock
++) {
731 for (lane_count
= 1; lane_count
<= max_lane_count
; lane_count
<<= 1) {
732 link_clock
= drm_dp_bw_code_to_link_rate(bws
[clock
]);
733 link_avail
= intel_dp_max_data_rate(link_clock
,
736 if (mode_rate
<= link_avail
) {
746 if (intel_dp
->color_range_auto
) {
749 * CEA-861-E - 5.1 Default Encoding Parameters
750 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
752 if (bpp
!= 18 && drm_match_cea_mode(adjusted_mode
) > 1)
753 intel_dp
->color_range
= DP_COLOR_RANGE_16_235
;
755 intel_dp
->color_range
= 0;
758 if (intel_dp
->color_range
)
759 pipe_config
->limited_color_range
= true;
761 intel_dp
->link_bw
= bws
[clock
];
762 intel_dp
->lane_count
= lane_count
;
763 adjusted_mode
->clock
= drm_dp_bw_code_to_link_rate(intel_dp
->link_bw
);
764 pipe_config
->pipe_bpp
= bpp
;
765 pipe_config
->pixel_target_clock
= target_clock
;
767 DRM_DEBUG_KMS("DP link bw %02x lane count %d clock %d bpp %d\n",
768 intel_dp
->link_bw
, intel_dp
->lane_count
,
769 adjusted_mode
->clock
, bpp
);
770 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
771 mode_rate
, link_avail
);
773 intel_link_compute_m_n(bpp
, lane_count
,
774 target_clock
, adjusted_mode
->clock
,
775 &pipe_config
->dp_m_n
);
780 void intel_dp_init_link_config(struct intel_dp
*intel_dp
)
782 memset(intel_dp
->link_configuration
, 0, DP_LINK_CONFIGURATION_SIZE
);
783 intel_dp
->link_configuration
[0] = intel_dp
->link_bw
;
784 intel_dp
->link_configuration
[1] = intel_dp
->lane_count
;
785 intel_dp
->link_configuration
[8] = DP_SET_ANSI_8B10B
;
787 * Check for DPCD version > 1.1 and enhanced framing support
789 if (intel_dp
->dpcd
[DP_DPCD_REV
] >= 0x11 &&
790 (intel_dp
->dpcd
[DP_MAX_LANE_COUNT
] & DP_ENHANCED_FRAME_CAP
)) {
791 intel_dp
->link_configuration
[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN
;
795 static void ironlake_set_pll_edp(struct drm_crtc
*crtc
, int clock
)
797 struct drm_device
*dev
= crtc
->dev
;
798 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
801 DRM_DEBUG_KMS("eDP PLL enable for clock %d\n", clock
);
802 dpa_ctl
= I915_READ(DP_A
);
803 dpa_ctl
&= ~DP_PLL_FREQ_MASK
;
805 if (clock
< 200000) {
806 /* For a long time we've carried around a ILK-DevA w/a for the
807 * 160MHz clock. If we're really unlucky, it's still required.
809 DRM_DEBUG_KMS("160MHz cpu eDP clock, might need ilk devA w/a\n");
810 dpa_ctl
|= DP_PLL_FREQ_160MHZ
;
812 dpa_ctl
|= DP_PLL_FREQ_270MHZ
;
815 I915_WRITE(DP_A
, dpa_ctl
);
822 intel_dp_mode_set(struct drm_encoder
*encoder
, struct drm_display_mode
*mode
,
823 struct drm_display_mode
*adjusted_mode
)
825 struct drm_device
*dev
= encoder
->dev
;
826 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
827 struct intel_dp
*intel_dp
= enc_to_intel_dp(encoder
);
828 struct drm_crtc
*crtc
= encoder
->crtc
;
829 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
832 * There are four kinds of DP registers:
839 * IBX PCH and CPU are the same for almost everything,
840 * except that the CPU DP PLL is configured in this
843 * CPT PCH is quite different, having many bits moved
844 * to the TRANS_DP_CTL register instead. That
845 * configuration happens (oddly) in ironlake_pch_enable
848 /* Preserve the BIOS-computed detected bit. This is
849 * supposed to be read-only.
851 intel_dp
->DP
= I915_READ(intel_dp
->output_reg
) & DP_DETECTED
;
853 /* Handle DP bits in common between all three register formats */
854 intel_dp
->DP
|= DP_VOLTAGE_0_4
| DP_PRE_EMPHASIS_0
;
856 switch (intel_dp
->lane_count
) {
858 intel_dp
->DP
|= DP_PORT_WIDTH_1
;
861 intel_dp
->DP
|= DP_PORT_WIDTH_2
;
864 intel_dp
->DP
|= DP_PORT_WIDTH_4
;
867 if (intel_dp
->has_audio
) {
868 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
869 pipe_name(intel_crtc
->pipe
));
870 intel_dp
->DP
|= DP_AUDIO_OUTPUT_ENABLE
;
871 intel_write_eld(encoder
, adjusted_mode
);
874 intel_dp_init_link_config(intel_dp
);
876 /* Split out the IBX/CPU vs CPT settings */
878 if (is_cpu_edp(intel_dp
) && IS_GEN7(dev
) && !IS_VALLEYVIEW(dev
)) {
879 if (adjusted_mode
->flags
& DRM_MODE_FLAG_PHSYNC
)
880 intel_dp
->DP
|= DP_SYNC_HS_HIGH
;
881 if (adjusted_mode
->flags
& DRM_MODE_FLAG_PVSYNC
)
882 intel_dp
->DP
|= DP_SYNC_VS_HIGH
;
883 intel_dp
->DP
|= DP_LINK_TRAIN_OFF_CPT
;
885 if (intel_dp
->link_configuration
[1] & DP_LANE_COUNT_ENHANCED_FRAME_EN
)
886 intel_dp
->DP
|= DP_ENHANCED_FRAMING
;
888 intel_dp
->DP
|= intel_crtc
->pipe
<< 29;
890 /* don't miss out required setting for eDP */
891 if (adjusted_mode
->clock
< 200000)
892 intel_dp
->DP
|= DP_PLL_FREQ_160MHZ
;
894 intel_dp
->DP
|= DP_PLL_FREQ_270MHZ
;
895 } else if (!HAS_PCH_CPT(dev
) || is_cpu_edp(intel_dp
)) {
896 if (!HAS_PCH_SPLIT(dev
) && !IS_VALLEYVIEW(dev
))
897 intel_dp
->DP
|= intel_dp
->color_range
;
899 if (adjusted_mode
->flags
& DRM_MODE_FLAG_PHSYNC
)
900 intel_dp
->DP
|= DP_SYNC_HS_HIGH
;
901 if (adjusted_mode
->flags
& DRM_MODE_FLAG_PVSYNC
)
902 intel_dp
->DP
|= DP_SYNC_VS_HIGH
;
903 intel_dp
->DP
|= DP_LINK_TRAIN_OFF
;
905 if (intel_dp
->link_configuration
[1] & DP_LANE_COUNT_ENHANCED_FRAME_EN
)
906 intel_dp
->DP
|= DP_ENHANCED_FRAMING
;
908 if (intel_crtc
->pipe
== 1)
909 intel_dp
->DP
|= DP_PIPEB_SELECT
;
911 if (is_cpu_edp(intel_dp
) && !IS_VALLEYVIEW(dev
)) {
912 /* don't miss out required setting for eDP */
913 if (adjusted_mode
->clock
< 200000)
914 intel_dp
->DP
|= DP_PLL_FREQ_160MHZ
;
916 intel_dp
->DP
|= DP_PLL_FREQ_270MHZ
;
919 intel_dp
->DP
|= DP_LINK_TRAIN_OFF_CPT
;
922 if (is_cpu_edp(intel_dp
) && !IS_VALLEYVIEW(dev
))
923 ironlake_set_pll_edp(crtc
, adjusted_mode
->clock
);
926 #define IDLE_ON_MASK (PP_ON | 0 | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
927 #define IDLE_ON_VALUE (PP_ON | 0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
929 #define IDLE_OFF_MASK (PP_ON | 0 | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
930 #define IDLE_OFF_VALUE (0 | 0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
932 #define IDLE_CYCLE_MASK (PP_ON | 0 | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
933 #define IDLE_CYCLE_VALUE (0 | 0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
935 static void ironlake_wait_panel_status(struct intel_dp
*intel_dp
,
939 struct drm_device
*dev
= intel_dp_to_dev(intel_dp
);
940 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
941 u32 pp_stat_reg
, pp_ctrl_reg
;
943 pp_stat_reg
= IS_VALLEYVIEW(dev
) ? PIPEA_PP_STATUS
: PCH_PP_STATUS
;
944 pp_ctrl_reg
= IS_VALLEYVIEW(dev
) ? PIPEA_PP_CONTROL
: PCH_PP_CONTROL
;
946 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
948 I915_READ(pp_stat_reg
),
949 I915_READ(pp_ctrl_reg
));
951 if (_wait_for((I915_READ(pp_stat_reg
) & mask
) == value
, 5000, 10)) {
952 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
953 I915_READ(pp_stat_reg
),
954 I915_READ(pp_ctrl_reg
));
958 static void ironlake_wait_panel_on(struct intel_dp
*intel_dp
)
960 DRM_DEBUG_KMS("Wait for panel power on\n");
961 ironlake_wait_panel_status(intel_dp
, IDLE_ON_MASK
, IDLE_ON_VALUE
);
964 static void ironlake_wait_panel_off(struct intel_dp
*intel_dp
)
966 DRM_DEBUG_KMS("Wait for panel power off time\n");
967 ironlake_wait_panel_status(intel_dp
, IDLE_OFF_MASK
, IDLE_OFF_VALUE
);
970 static void ironlake_wait_panel_power_cycle(struct intel_dp
*intel_dp
)
972 DRM_DEBUG_KMS("Wait for panel power cycle\n");
973 ironlake_wait_panel_status(intel_dp
, IDLE_CYCLE_MASK
, IDLE_CYCLE_VALUE
);
977 /* Read the current pp_control value, unlocking the register if it
981 static u32
ironlake_get_pp_control(struct intel_dp
*intel_dp
)
983 struct drm_device
*dev
= intel_dp_to_dev(intel_dp
);
984 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
988 pp_ctrl_reg
= IS_VALLEYVIEW(dev
) ? PIPEA_PP_CONTROL
: PCH_PP_CONTROL
;
989 control
= I915_READ(pp_ctrl_reg
);
991 control
&= ~PANEL_UNLOCK_MASK
;
992 control
|= PANEL_UNLOCK_REGS
;
996 void ironlake_edp_panel_vdd_on(struct intel_dp
*intel_dp
)
998 struct drm_device
*dev
= intel_dp_to_dev(intel_dp
);
999 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1001 u32 pp_stat_reg
, pp_ctrl_reg
;
1003 if (!is_edp(intel_dp
))
1005 DRM_DEBUG_KMS("Turn eDP VDD on\n");
1007 WARN(intel_dp
->want_panel_vdd
,
1008 "eDP VDD already requested on\n");
1010 intel_dp
->want_panel_vdd
= true;
1012 if (ironlake_edp_have_panel_vdd(intel_dp
)) {
1013 DRM_DEBUG_KMS("eDP VDD already on\n");
1017 if (!ironlake_edp_have_panel_power(intel_dp
))
1018 ironlake_wait_panel_power_cycle(intel_dp
);
1020 pp
= ironlake_get_pp_control(intel_dp
);
1021 pp
|= EDP_FORCE_VDD
;
1023 pp_stat_reg
= IS_VALLEYVIEW(dev
) ? PIPEA_PP_STATUS
: PCH_PP_STATUS
;
1024 pp_ctrl_reg
= IS_VALLEYVIEW(dev
) ? PIPEA_PP_CONTROL
: PCH_PP_CONTROL
;
1026 I915_WRITE(pp_ctrl_reg
, pp
);
1027 POSTING_READ(pp_ctrl_reg
);
1028 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1029 I915_READ(pp_stat_reg
), I915_READ(pp_ctrl_reg
));
1031 * If the panel wasn't on, delay before accessing aux channel
1033 if (!ironlake_edp_have_panel_power(intel_dp
)) {
1034 DRM_DEBUG_KMS("eDP was not running\n");
1035 msleep(intel_dp
->panel_power_up_delay
);
1039 static void ironlake_panel_vdd_off_sync(struct intel_dp
*intel_dp
)
1041 struct drm_device
*dev
= intel_dp_to_dev(intel_dp
);
1042 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1044 u32 pp_stat_reg
, pp_ctrl_reg
;
1046 WARN_ON(!mutex_is_locked(&dev
->mode_config
.mutex
));
1048 if (!intel_dp
->want_panel_vdd
&& ironlake_edp_have_panel_vdd(intel_dp
)) {
1049 pp
= ironlake_get_pp_control(intel_dp
);
1050 pp
&= ~EDP_FORCE_VDD
;
1052 pp_stat_reg
= IS_VALLEYVIEW(dev
) ? PIPEA_PP_STATUS
: PCH_PP_STATUS
;
1053 pp_ctrl_reg
= IS_VALLEYVIEW(dev
) ? PIPEA_PP_CONTROL
: PCH_PP_CONTROL
;
1055 I915_WRITE(pp_ctrl_reg
, pp
);
1056 POSTING_READ(pp_ctrl_reg
);
1058 /* Make sure sequencer is idle before allowing subsequent activity */
1059 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1060 I915_READ(pp_stat_reg
), I915_READ(pp_ctrl_reg
));
1061 msleep(intel_dp
->panel_power_down_delay
);
1065 static void ironlake_panel_vdd_work(struct work_struct
*__work
)
1067 struct intel_dp
*intel_dp
= container_of(to_delayed_work(__work
),
1068 struct intel_dp
, panel_vdd_work
);
1069 struct drm_device
*dev
= intel_dp_to_dev(intel_dp
);
1071 mutex_lock(&dev
->mode_config
.mutex
);
1072 ironlake_panel_vdd_off_sync(intel_dp
);
1073 mutex_unlock(&dev
->mode_config
.mutex
);
1076 void ironlake_edp_panel_vdd_off(struct intel_dp
*intel_dp
, bool sync
)
1078 if (!is_edp(intel_dp
))
1081 DRM_DEBUG_KMS("Turn eDP VDD off %d\n", intel_dp
->want_panel_vdd
);
1082 WARN(!intel_dp
->want_panel_vdd
, "eDP VDD not forced on");
1084 intel_dp
->want_panel_vdd
= false;
1087 ironlake_panel_vdd_off_sync(intel_dp
);
1090 * Queue the timer to fire a long
1091 * time from now (relative to the power down delay)
1092 * to keep the panel power up across a sequence of operations
1094 schedule_delayed_work(&intel_dp
->panel_vdd_work
,
1095 msecs_to_jiffies(intel_dp
->panel_power_cycle_delay
* 5));
1099 void ironlake_edp_panel_on(struct intel_dp
*intel_dp
)
1101 struct drm_device
*dev
= intel_dp_to_dev(intel_dp
);
1102 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1106 if (!is_edp(intel_dp
))
1109 DRM_DEBUG_KMS("Turn eDP power on\n");
1111 if (ironlake_edp_have_panel_power(intel_dp
)) {
1112 DRM_DEBUG_KMS("eDP power already on\n");
1116 ironlake_wait_panel_power_cycle(intel_dp
);
1118 pp
= ironlake_get_pp_control(intel_dp
);
1120 /* ILK workaround: disable reset around power sequence */
1121 pp
&= ~PANEL_POWER_RESET
;
1122 I915_WRITE(PCH_PP_CONTROL
, pp
);
1123 POSTING_READ(PCH_PP_CONTROL
);
1126 pp
|= POWER_TARGET_ON
;
1128 pp
|= PANEL_POWER_RESET
;
1130 pp_ctrl_reg
= IS_VALLEYVIEW(dev
) ? PIPEA_PP_CONTROL
: PCH_PP_CONTROL
;
1132 I915_WRITE(pp_ctrl_reg
, pp
);
1133 POSTING_READ(pp_ctrl_reg
);
1135 ironlake_wait_panel_on(intel_dp
);
1138 pp
|= PANEL_POWER_RESET
; /* restore panel reset bit */
1139 I915_WRITE(PCH_PP_CONTROL
, pp
);
1140 POSTING_READ(PCH_PP_CONTROL
);
1144 void ironlake_edp_panel_off(struct intel_dp
*intel_dp
)
1146 struct drm_device
*dev
= intel_dp_to_dev(intel_dp
);
1147 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1151 if (!is_edp(intel_dp
))
1154 DRM_DEBUG_KMS("Turn eDP power off\n");
1156 WARN(!intel_dp
->want_panel_vdd
, "Need VDD to turn off panel\n");
1158 pp
= ironlake_get_pp_control(intel_dp
);
1159 /* We need to switch off panel power _and_ force vdd, for otherwise some
1160 * panels get very unhappy and cease to work. */
1161 pp
&= ~(POWER_TARGET_ON
| EDP_FORCE_VDD
| PANEL_POWER_RESET
| EDP_BLC_ENABLE
);
1163 pp_ctrl_reg
= IS_VALLEYVIEW(dev
) ? PIPEA_PP_CONTROL
: PCH_PP_CONTROL
;
1165 I915_WRITE(pp_ctrl_reg
, pp
);
1166 POSTING_READ(pp_ctrl_reg
);
1168 intel_dp
->want_panel_vdd
= false;
1170 ironlake_wait_panel_off(intel_dp
);
1173 void ironlake_edp_backlight_on(struct intel_dp
*intel_dp
)
1175 struct intel_digital_port
*intel_dig_port
= dp_to_dig_port(intel_dp
);
1176 struct drm_device
*dev
= intel_dig_port
->base
.base
.dev
;
1177 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1178 int pipe
= to_intel_crtc(intel_dig_port
->base
.base
.crtc
)->pipe
;
1182 if (!is_edp(intel_dp
))
1185 DRM_DEBUG_KMS("\n");
1187 * If we enable the backlight right away following a panel power
1188 * on, we may see slight flicker as the panel syncs with the eDP
1189 * link. So delay a bit to make sure the image is solid before
1190 * allowing it to appear.
1192 msleep(intel_dp
->backlight_on_delay
);
1193 pp
= ironlake_get_pp_control(intel_dp
);
1194 pp
|= EDP_BLC_ENABLE
;
1196 pp_ctrl_reg
= IS_VALLEYVIEW(dev
) ? PIPEA_PP_CONTROL
: PCH_PP_CONTROL
;
1198 I915_WRITE(pp_ctrl_reg
, pp
);
1199 POSTING_READ(pp_ctrl_reg
);
1201 intel_panel_enable_backlight(dev
, pipe
);
1204 void ironlake_edp_backlight_off(struct intel_dp
*intel_dp
)
1206 struct drm_device
*dev
= intel_dp_to_dev(intel_dp
);
1207 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1211 if (!is_edp(intel_dp
))
1214 intel_panel_disable_backlight(dev
);
1216 DRM_DEBUG_KMS("\n");
1217 pp
= ironlake_get_pp_control(intel_dp
);
1218 pp
&= ~EDP_BLC_ENABLE
;
1220 pp_ctrl_reg
= IS_VALLEYVIEW(dev
) ? PIPEA_PP_CONTROL
: PCH_PP_CONTROL
;
1222 I915_WRITE(pp_ctrl_reg
, pp
);
1223 POSTING_READ(pp_ctrl_reg
);
1224 msleep(intel_dp
->backlight_off_delay
);
1227 static void ironlake_edp_pll_on(struct intel_dp
*intel_dp
)
1229 struct intel_digital_port
*intel_dig_port
= dp_to_dig_port(intel_dp
);
1230 struct drm_crtc
*crtc
= intel_dig_port
->base
.base
.crtc
;
1231 struct drm_device
*dev
= crtc
->dev
;
1232 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1235 assert_pipe_disabled(dev_priv
,
1236 to_intel_crtc(crtc
)->pipe
);
1238 DRM_DEBUG_KMS("\n");
1239 dpa_ctl
= I915_READ(DP_A
);
1240 WARN(dpa_ctl
& DP_PLL_ENABLE
, "dp pll on, should be off\n");
1241 WARN(dpa_ctl
& DP_PORT_EN
, "dp port still on, should be off\n");
1243 /* We don't adjust intel_dp->DP while tearing down the link, to
1244 * facilitate link retraining (e.g. after hotplug). Hence clear all
1245 * enable bits here to ensure that we don't enable too much. */
1246 intel_dp
->DP
&= ~(DP_PORT_EN
| DP_AUDIO_OUTPUT_ENABLE
);
1247 intel_dp
->DP
|= DP_PLL_ENABLE
;
1248 I915_WRITE(DP_A
, intel_dp
->DP
);
1253 static void ironlake_edp_pll_off(struct intel_dp
*intel_dp
)
1255 struct intel_digital_port
*intel_dig_port
= dp_to_dig_port(intel_dp
);
1256 struct drm_crtc
*crtc
= intel_dig_port
->base
.base
.crtc
;
1257 struct drm_device
*dev
= crtc
->dev
;
1258 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1261 assert_pipe_disabled(dev_priv
,
1262 to_intel_crtc(crtc
)->pipe
);
1264 dpa_ctl
= I915_READ(DP_A
);
1265 WARN((dpa_ctl
& DP_PLL_ENABLE
) == 0,
1266 "dp pll off, should be on\n");
1267 WARN(dpa_ctl
& DP_PORT_EN
, "dp port still on, should be off\n");
1269 /* We can't rely on the value tracked for the DP register in
1270 * intel_dp->DP because link_down must not change that (otherwise link
1271 * re-training will fail. */
1272 dpa_ctl
&= ~DP_PLL_ENABLE
;
1273 I915_WRITE(DP_A
, dpa_ctl
);
1278 /* If the sink supports it, try to set the power state appropriately */
1279 void intel_dp_sink_dpms(struct intel_dp
*intel_dp
, int mode
)
1283 /* Should have a valid DPCD by this point */
1284 if (intel_dp
->dpcd
[DP_DPCD_REV
] < 0x11)
1287 if (mode
!= DRM_MODE_DPMS_ON
) {
1288 ret
= intel_dp_aux_native_write_1(intel_dp
, DP_SET_POWER
,
1291 DRM_DEBUG_DRIVER("failed to write sink power state\n");
1294 * When turning on, we need to retry for 1ms to give the sink
1297 for (i
= 0; i
< 3; i
++) {
1298 ret
= intel_dp_aux_native_write_1(intel_dp
,
1308 static bool intel_dp_get_hw_state(struct intel_encoder
*encoder
,
1311 struct intel_dp
*intel_dp
= enc_to_intel_dp(&encoder
->base
);
1312 struct drm_device
*dev
= encoder
->base
.dev
;
1313 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1314 u32 tmp
= I915_READ(intel_dp
->output_reg
);
1316 if (!(tmp
& DP_PORT_EN
))
1319 if (is_cpu_edp(intel_dp
) && IS_GEN7(dev
) && !IS_VALLEYVIEW(dev
)) {
1320 *pipe
= PORT_TO_PIPE_CPT(tmp
);
1321 } else if (!HAS_PCH_CPT(dev
) || is_cpu_edp(intel_dp
)) {
1322 *pipe
= PORT_TO_PIPE(tmp
);
1328 switch (intel_dp
->output_reg
) {
1330 trans_sel
= TRANS_DP_PORT_SEL_B
;
1333 trans_sel
= TRANS_DP_PORT_SEL_C
;
1336 trans_sel
= TRANS_DP_PORT_SEL_D
;
1343 trans_dp
= I915_READ(TRANS_DP_CTL(i
));
1344 if ((trans_dp
& TRANS_DP_PORT_SEL_MASK
) == trans_sel
) {
1350 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
1351 intel_dp
->output_reg
);
1357 static void intel_disable_dp(struct intel_encoder
*encoder
)
1359 struct intel_dp
*intel_dp
= enc_to_intel_dp(&encoder
->base
);
1361 /* Make sure the panel is off before trying to change the mode. But also
1362 * ensure that we have vdd while we switch off the panel. */
1363 ironlake_edp_panel_vdd_on(intel_dp
);
1364 ironlake_edp_backlight_off(intel_dp
);
1365 intel_dp_sink_dpms(intel_dp
, DRM_MODE_DPMS_ON
);
1366 ironlake_edp_panel_off(intel_dp
);
1368 /* cpu edp my only be disable _after_ the cpu pipe/plane is disabled. */
1369 if (!is_cpu_edp(intel_dp
))
1370 intel_dp_link_down(intel_dp
);
1373 static void intel_post_disable_dp(struct intel_encoder
*encoder
)
1375 struct intel_dp
*intel_dp
= enc_to_intel_dp(&encoder
->base
);
1376 struct drm_device
*dev
= encoder
->base
.dev
;
1378 if (is_cpu_edp(intel_dp
)) {
1379 intel_dp_link_down(intel_dp
);
1380 if (!IS_VALLEYVIEW(dev
))
1381 ironlake_edp_pll_off(intel_dp
);
1385 static void intel_enable_dp(struct intel_encoder
*encoder
)
1387 struct intel_dp
*intel_dp
= enc_to_intel_dp(&encoder
->base
);
1388 struct drm_device
*dev
= encoder
->base
.dev
;
1389 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1390 uint32_t dp_reg
= I915_READ(intel_dp
->output_reg
);
1392 if (WARN_ON(dp_reg
& DP_PORT_EN
))
1395 ironlake_edp_panel_vdd_on(intel_dp
);
1396 intel_dp_sink_dpms(intel_dp
, DRM_MODE_DPMS_ON
);
1397 intel_dp_start_link_train(intel_dp
);
1398 ironlake_edp_panel_on(intel_dp
);
1399 ironlake_edp_panel_vdd_off(intel_dp
, true);
1400 intel_dp_complete_link_train(intel_dp
);
1401 ironlake_edp_backlight_on(intel_dp
);
1404 static void intel_pre_enable_dp(struct intel_encoder
*encoder
)
1406 struct intel_dp
*intel_dp
= enc_to_intel_dp(&encoder
->base
);
1407 struct drm_device
*dev
= encoder
->base
.dev
;
1409 if (is_cpu_edp(intel_dp
) && !IS_VALLEYVIEW(dev
))
1410 ironlake_edp_pll_on(intel_dp
);
1414 * Native read with retry for link status and receiver capability reads for
1415 * cases where the sink may still be asleep.
1418 intel_dp_aux_native_read_retry(struct intel_dp
*intel_dp
, uint16_t address
,
1419 uint8_t *recv
, int recv_bytes
)
1424 * Sinks are *supposed* to come up within 1ms from an off state,
1425 * but we're also supposed to retry 3 times per the spec.
1427 for (i
= 0; i
< 3; i
++) {
1428 ret
= intel_dp_aux_native_read(intel_dp
, address
, recv
,
1430 if (ret
== recv_bytes
)
1439 * Fetch AUX CH registers 0x202 - 0x207 which contain
1440 * link status information
1443 intel_dp_get_link_status(struct intel_dp
*intel_dp
, uint8_t link_status
[DP_LINK_STATUS_SIZE
])
1445 return intel_dp_aux_native_read_retry(intel_dp
,
1448 DP_LINK_STATUS_SIZE
);
1452 static char *voltage_names
[] = {
1453 "0.4V", "0.6V", "0.8V", "1.2V"
1455 static char *pre_emph_names
[] = {
1456 "0dB", "3.5dB", "6dB", "9.5dB"
1458 static char *link_train_names
[] = {
1459 "pattern 1", "pattern 2", "idle", "off"
1464 * These are source-specific values; current Intel hardware supports
1465 * a maximum voltage of 800mV and a maximum pre-emphasis of 6dB
1469 intel_dp_voltage_max(struct intel_dp
*intel_dp
)
1471 struct drm_device
*dev
= intel_dp_to_dev(intel_dp
);
1473 if (IS_GEN7(dev
) && is_cpu_edp(intel_dp
))
1474 return DP_TRAIN_VOLTAGE_SWING_800
;
1475 else if (HAS_PCH_CPT(dev
) && !is_cpu_edp(intel_dp
))
1476 return DP_TRAIN_VOLTAGE_SWING_1200
;
1478 return DP_TRAIN_VOLTAGE_SWING_800
;
1482 intel_dp_pre_emphasis_max(struct intel_dp
*intel_dp
, uint8_t voltage_swing
)
1484 struct drm_device
*dev
= intel_dp_to_dev(intel_dp
);
1487 switch (voltage_swing
& DP_TRAIN_VOLTAGE_SWING_MASK
) {
1488 case DP_TRAIN_VOLTAGE_SWING_400
:
1489 return DP_TRAIN_PRE_EMPHASIS_9_5
;
1490 case DP_TRAIN_VOLTAGE_SWING_600
:
1491 return DP_TRAIN_PRE_EMPHASIS_6
;
1492 case DP_TRAIN_VOLTAGE_SWING_800
:
1493 return DP_TRAIN_PRE_EMPHASIS_3_5
;
1494 case DP_TRAIN_VOLTAGE_SWING_1200
:
1496 return DP_TRAIN_PRE_EMPHASIS_0
;
1498 } else if (IS_GEN7(dev
) && is_cpu_edp(intel_dp
) && !IS_VALLEYVIEW(dev
)) {
1499 switch (voltage_swing
& DP_TRAIN_VOLTAGE_SWING_MASK
) {
1500 case DP_TRAIN_VOLTAGE_SWING_400
:
1501 return DP_TRAIN_PRE_EMPHASIS_6
;
1502 case DP_TRAIN_VOLTAGE_SWING_600
:
1503 case DP_TRAIN_VOLTAGE_SWING_800
:
1504 return DP_TRAIN_PRE_EMPHASIS_3_5
;
1506 return DP_TRAIN_PRE_EMPHASIS_0
;
1509 switch (voltage_swing
& DP_TRAIN_VOLTAGE_SWING_MASK
) {
1510 case DP_TRAIN_VOLTAGE_SWING_400
:
1511 return DP_TRAIN_PRE_EMPHASIS_6
;
1512 case DP_TRAIN_VOLTAGE_SWING_600
:
1513 return DP_TRAIN_PRE_EMPHASIS_6
;
1514 case DP_TRAIN_VOLTAGE_SWING_800
:
1515 return DP_TRAIN_PRE_EMPHASIS_3_5
;
1516 case DP_TRAIN_VOLTAGE_SWING_1200
:
1518 return DP_TRAIN_PRE_EMPHASIS_0
;
1524 intel_get_adjust_train(struct intel_dp
*intel_dp
, uint8_t link_status
[DP_LINK_STATUS_SIZE
])
1529 uint8_t voltage_max
;
1530 uint8_t preemph_max
;
1532 for (lane
= 0; lane
< intel_dp
->lane_count
; lane
++) {
1533 uint8_t this_v
= drm_dp_get_adjust_request_voltage(link_status
, lane
);
1534 uint8_t this_p
= drm_dp_get_adjust_request_pre_emphasis(link_status
, lane
);
1542 voltage_max
= intel_dp_voltage_max(intel_dp
);
1543 if (v
>= voltage_max
)
1544 v
= voltage_max
| DP_TRAIN_MAX_SWING_REACHED
;
1546 preemph_max
= intel_dp_pre_emphasis_max(intel_dp
, v
);
1547 if (p
>= preemph_max
)
1548 p
= preemph_max
| DP_TRAIN_MAX_PRE_EMPHASIS_REACHED
;
1550 for (lane
= 0; lane
< 4; lane
++)
1551 intel_dp
->train_set
[lane
] = v
| p
;
1555 intel_gen4_signal_levels(uint8_t train_set
)
1557 uint32_t signal_levels
= 0;
1559 switch (train_set
& DP_TRAIN_VOLTAGE_SWING_MASK
) {
1560 case DP_TRAIN_VOLTAGE_SWING_400
:
1562 signal_levels
|= DP_VOLTAGE_0_4
;
1564 case DP_TRAIN_VOLTAGE_SWING_600
:
1565 signal_levels
|= DP_VOLTAGE_0_6
;
1567 case DP_TRAIN_VOLTAGE_SWING_800
:
1568 signal_levels
|= DP_VOLTAGE_0_8
;
1570 case DP_TRAIN_VOLTAGE_SWING_1200
:
1571 signal_levels
|= DP_VOLTAGE_1_2
;
1574 switch (train_set
& DP_TRAIN_PRE_EMPHASIS_MASK
) {
1575 case DP_TRAIN_PRE_EMPHASIS_0
:
1577 signal_levels
|= DP_PRE_EMPHASIS_0
;
1579 case DP_TRAIN_PRE_EMPHASIS_3_5
:
1580 signal_levels
|= DP_PRE_EMPHASIS_3_5
;
1582 case DP_TRAIN_PRE_EMPHASIS_6
:
1583 signal_levels
|= DP_PRE_EMPHASIS_6
;
1585 case DP_TRAIN_PRE_EMPHASIS_9_5
:
1586 signal_levels
|= DP_PRE_EMPHASIS_9_5
;
1589 return signal_levels
;
1592 /* Gen6's DP voltage swing and pre-emphasis control */
1594 intel_gen6_edp_signal_levels(uint8_t train_set
)
1596 int signal_levels
= train_set
& (DP_TRAIN_VOLTAGE_SWING_MASK
|
1597 DP_TRAIN_PRE_EMPHASIS_MASK
);
1598 switch (signal_levels
) {
1599 case DP_TRAIN_VOLTAGE_SWING_400
| DP_TRAIN_PRE_EMPHASIS_0
:
1600 case DP_TRAIN_VOLTAGE_SWING_600
| DP_TRAIN_PRE_EMPHASIS_0
:
1601 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B
;
1602 case DP_TRAIN_VOLTAGE_SWING_400
| DP_TRAIN_PRE_EMPHASIS_3_5
:
1603 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B
;
1604 case DP_TRAIN_VOLTAGE_SWING_400
| DP_TRAIN_PRE_EMPHASIS_6
:
1605 case DP_TRAIN_VOLTAGE_SWING_600
| DP_TRAIN_PRE_EMPHASIS_6
:
1606 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B
;
1607 case DP_TRAIN_VOLTAGE_SWING_600
| DP_TRAIN_PRE_EMPHASIS_3_5
:
1608 case DP_TRAIN_VOLTAGE_SWING_800
| DP_TRAIN_PRE_EMPHASIS_3_5
:
1609 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B
;
1610 case DP_TRAIN_VOLTAGE_SWING_800
| DP_TRAIN_PRE_EMPHASIS_0
:
1611 case DP_TRAIN_VOLTAGE_SWING_1200
| DP_TRAIN_PRE_EMPHASIS_0
:
1612 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B
;
1614 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
1615 "0x%x\n", signal_levels
);
1616 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B
;
1620 /* Gen7's DP voltage swing and pre-emphasis control */
1622 intel_gen7_edp_signal_levels(uint8_t train_set
)
1624 int signal_levels
= train_set
& (DP_TRAIN_VOLTAGE_SWING_MASK
|
1625 DP_TRAIN_PRE_EMPHASIS_MASK
);
1626 switch (signal_levels
) {
1627 case DP_TRAIN_VOLTAGE_SWING_400
| DP_TRAIN_PRE_EMPHASIS_0
:
1628 return EDP_LINK_TRAIN_400MV_0DB_IVB
;
1629 case DP_TRAIN_VOLTAGE_SWING_400
| DP_TRAIN_PRE_EMPHASIS_3_5
:
1630 return EDP_LINK_TRAIN_400MV_3_5DB_IVB
;
1631 case DP_TRAIN_VOLTAGE_SWING_400
| DP_TRAIN_PRE_EMPHASIS_6
:
1632 return EDP_LINK_TRAIN_400MV_6DB_IVB
;
1634 case DP_TRAIN_VOLTAGE_SWING_600
| DP_TRAIN_PRE_EMPHASIS_0
:
1635 return EDP_LINK_TRAIN_600MV_0DB_IVB
;
1636 case DP_TRAIN_VOLTAGE_SWING_600
| DP_TRAIN_PRE_EMPHASIS_3_5
:
1637 return EDP_LINK_TRAIN_600MV_3_5DB_IVB
;
1639 case DP_TRAIN_VOLTAGE_SWING_800
| DP_TRAIN_PRE_EMPHASIS_0
:
1640 return EDP_LINK_TRAIN_800MV_0DB_IVB
;
1641 case DP_TRAIN_VOLTAGE_SWING_800
| DP_TRAIN_PRE_EMPHASIS_3_5
:
1642 return EDP_LINK_TRAIN_800MV_3_5DB_IVB
;
1645 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
1646 "0x%x\n", signal_levels
);
1647 return EDP_LINK_TRAIN_500MV_0DB_IVB
;
1651 /* Gen7.5's (HSW) DP voltage swing and pre-emphasis control */
1653 intel_hsw_signal_levels(uint8_t train_set
)
1655 int signal_levels
= train_set
& (DP_TRAIN_VOLTAGE_SWING_MASK
|
1656 DP_TRAIN_PRE_EMPHASIS_MASK
);
1657 switch (signal_levels
) {
1658 case DP_TRAIN_VOLTAGE_SWING_400
| DP_TRAIN_PRE_EMPHASIS_0
:
1659 return DDI_BUF_EMP_400MV_0DB_HSW
;
1660 case DP_TRAIN_VOLTAGE_SWING_400
| DP_TRAIN_PRE_EMPHASIS_3_5
:
1661 return DDI_BUF_EMP_400MV_3_5DB_HSW
;
1662 case DP_TRAIN_VOLTAGE_SWING_400
| DP_TRAIN_PRE_EMPHASIS_6
:
1663 return DDI_BUF_EMP_400MV_6DB_HSW
;
1664 case DP_TRAIN_VOLTAGE_SWING_400
| DP_TRAIN_PRE_EMPHASIS_9_5
:
1665 return DDI_BUF_EMP_400MV_9_5DB_HSW
;
1667 case DP_TRAIN_VOLTAGE_SWING_600
| DP_TRAIN_PRE_EMPHASIS_0
:
1668 return DDI_BUF_EMP_600MV_0DB_HSW
;
1669 case DP_TRAIN_VOLTAGE_SWING_600
| DP_TRAIN_PRE_EMPHASIS_3_5
:
1670 return DDI_BUF_EMP_600MV_3_5DB_HSW
;
1671 case DP_TRAIN_VOLTAGE_SWING_600
| DP_TRAIN_PRE_EMPHASIS_6
:
1672 return DDI_BUF_EMP_600MV_6DB_HSW
;
1674 case DP_TRAIN_VOLTAGE_SWING_800
| DP_TRAIN_PRE_EMPHASIS_0
:
1675 return DDI_BUF_EMP_800MV_0DB_HSW
;
1676 case DP_TRAIN_VOLTAGE_SWING_800
| DP_TRAIN_PRE_EMPHASIS_3_5
:
1677 return DDI_BUF_EMP_800MV_3_5DB_HSW
;
1679 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
1680 "0x%x\n", signal_levels
);
1681 return DDI_BUF_EMP_400MV_0DB_HSW
;
1685 /* Properly updates "DP" with the correct signal levels. */
1687 intel_dp_set_signal_levels(struct intel_dp
*intel_dp
, uint32_t *DP
)
1689 struct intel_digital_port
*intel_dig_port
= dp_to_dig_port(intel_dp
);
1690 struct drm_device
*dev
= intel_dig_port
->base
.base
.dev
;
1691 uint32_t signal_levels
, mask
;
1692 uint8_t train_set
= intel_dp
->train_set
[0];
1695 signal_levels
= intel_hsw_signal_levels(train_set
);
1696 mask
= DDI_BUF_EMP_MASK
;
1697 } else if (IS_GEN7(dev
) && is_cpu_edp(intel_dp
) && !IS_VALLEYVIEW(dev
)) {
1698 signal_levels
= intel_gen7_edp_signal_levels(train_set
);
1699 mask
= EDP_LINK_TRAIN_VOL_EMP_MASK_IVB
;
1700 } else if (IS_GEN6(dev
) && is_cpu_edp(intel_dp
)) {
1701 signal_levels
= intel_gen6_edp_signal_levels(train_set
);
1702 mask
= EDP_LINK_TRAIN_VOL_EMP_MASK_SNB
;
1704 signal_levels
= intel_gen4_signal_levels(train_set
);
1705 mask
= DP_VOLTAGE_MASK
| DP_PRE_EMPHASIS_MASK
;
1708 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels
);
1710 *DP
= (*DP
& ~mask
) | signal_levels
;
1714 intel_dp_set_link_train(struct intel_dp
*intel_dp
,
1715 uint32_t dp_reg_value
,
1716 uint8_t dp_train_pat
)
1718 struct intel_digital_port
*intel_dig_port
= dp_to_dig_port(intel_dp
);
1719 struct drm_device
*dev
= intel_dig_port
->base
.base
.dev
;
1720 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1721 enum port port
= intel_dig_port
->port
;
1726 temp
= I915_READ(DP_TP_CTL(port
));
1728 if (dp_train_pat
& DP_LINK_SCRAMBLING_DISABLE
)
1729 temp
|= DP_TP_CTL_SCRAMBLE_DISABLE
;
1731 temp
&= ~DP_TP_CTL_SCRAMBLE_DISABLE
;
1733 temp
&= ~DP_TP_CTL_LINK_TRAIN_MASK
;
1734 switch (dp_train_pat
& DP_TRAINING_PATTERN_MASK
) {
1735 case DP_TRAINING_PATTERN_DISABLE
:
1737 if (port
!= PORT_A
) {
1738 temp
|= DP_TP_CTL_LINK_TRAIN_IDLE
;
1739 I915_WRITE(DP_TP_CTL(port
), temp
);
1741 if (wait_for((I915_READ(DP_TP_STATUS(port
)) &
1742 DP_TP_STATUS_IDLE_DONE
), 1))
1743 DRM_ERROR("Timed out waiting for DP idle patterns\n");
1745 temp
&= ~DP_TP_CTL_LINK_TRAIN_MASK
;
1748 temp
|= DP_TP_CTL_LINK_TRAIN_NORMAL
;
1751 case DP_TRAINING_PATTERN_1
:
1752 temp
|= DP_TP_CTL_LINK_TRAIN_PAT1
;
1754 case DP_TRAINING_PATTERN_2
:
1755 temp
|= DP_TP_CTL_LINK_TRAIN_PAT2
;
1757 case DP_TRAINING_PATTERN_3
:
1758 temp
|= DP_TP_CTL_LINK_TRAIN_PAT3
;
1761 I915_WRITE(DP_TP_CTL(port
), temp
);
1763 } else if (HAS_PCH_CPT(dev
) &&
1764 (IS_GEN7(dev
) || !is_cpu_edp(intel_dp
))) {
1765 dp_reg_value
&= ~DP_LINK_TRAIN_MASK_CPT
;
1767 switch (dp_train_pat
& DP_TRAINING_PATTERN_MASK
) {
1768 case DP_TRAINING_PATTERN_DISABLE
:
1769 dp_reg_value
|= DP_LINK_TRAIN_OFF_CPT
;
1771 case DP_TRAINING_PATTERN_1
:
1772 dp_reg_value
|= DP_LINK_TRAIN_PAT_1_CPT
;
1774 case DP_TRAINING_PATTERN_2
:
1775 dp_reg_value
|= DP_LINK_TRAIN_PAT_2_CPT
;
1777 case DP_TRAINING_PATTERN_3
:
1778 DRM_ERROR("DP training pattern 3 not supported\n");
1779 dp_reg_value
|= DP_LINK_TRAIN_PAT_2_CPT
;
1784 dp_reg_value
&= ~DP_LINK_TRAIN_MASK
;
1786 switch (dp_train_pat
& DP_TRAINING_PATTERN_MASK
) {
1787 case DP_TRAINING_PATTERN_DISABLE
:
1788 dp_reg_value
|= DP_LINK_TRAIN_OFF
;
1790 case DP_TRAINING_PATTERN_1
:
1791 dp_reg_value
|= DP_LINK_TRAIN_PAT_1
;
1793 case DP_TRAINING_PATTERN_2
:
1794 dp_reg_value
|= DP_LINK_TRAIN_PAT_2
;
1796 case DP_TRAINING_PATTERN_3
:
1797 DRM_ERROR("DP training pattern 3 not supported\n");
1798 dp_reg_value
|= DP_LINK_TRAIN_PAT_2
;
1803 I915_WRITE(intel_dp
->output_reg
, dp_reg_value
);
1804 POSTING_READ(intel_dp
->output_reg
);
1806 intel_dp_aux_native_write_1(intel_dp
,
1807 DP_TRAINING_PATTERN_SET
,
1810 if ((dp_train_pat
& DP_TRAINING_PATTERN_MASK
) !=
1811 DP_TRAINING_PATTERN_DISABLE
) {
1812 ret
= intel_dp_aux_native_write(intel_dp
,
1813 DP_TRAINING_LANE0_SET
,
1814 intel_dp
->train_set
,
1815 intel_dp
->lane_count
);
1816 if (ret
!= intel_dp
->lane_count
)
1823 /* Enable corresponding port and start training pattern 1 */
1825 intel_dp_start_link_train(struct intel_dp
*intel_dp
)
1827 struct drm_encoder
*encoder
= &dp_to_dig_port(intel_dp
)->base
.base
;
1828 struct drm_device
*dev
= encoder
->dev
;
1831 bool clock_recovery
= false;
1832 int voltage_tries
, loop_tries
;
1833 uint32_t DP
= intel_dp
->DP
;
1836 intel_ddi_prepare_link_retrain(encoder
);
1838 /* Write the link configuration data */
1839 intel_dp_aux_native_write(intel_dp
, DP_LINK_BW_SET
,
1840 intel_dp
->link_configuration
,
1841 DP_LINK_CONFIGURATION_SIZE
);
1845 memset(intel_dp
->train_set
, 0, 4);
1849 clock_recovery
= false;
1851 /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */
1852 uint8_t link_status
[DP_LINK_STATUS_SIZE
];
1854 intel_dp_set_signal_levels(intel_dp
, &DP
);
1856 /* Set training pattern 1 */
1857 if (!intel_dp_set_link_train(intel_dp
, DP
,
1858 DP_TRAINING_PATTERN_1
|
1859 DP_LINK_SCRAMBLING_DISABLE
))
1862 drm_dp_link_train_clock_recovery_delay(intel_dp
->dpcd
);
1863 if (!intel_dp_get_link_status(intel_dp
, link_status
)) {
1864 DRM_ERROR("failed to get link status\n");
1868 if (drm_dp_clock_recovery_ok(link_status
, intel_dp
->lane_count
)) {
1869 DRM_DEBUG_KMS("clock recovery OK\n");
1870 clock_recovery
= true;
1874 /* Check to see if we've tried the max voltage */
1875 for (i
= 0; i
< intel_dp
->lane_count
; i
++)
1876 if ((intel_dp
->train_set
[i
] & DP_TRAIN_MAX_SWING_REACHED
) == 0)
1878 if (i
== intel_dp
->lane_count
) {
1880 if (loop_tries
== 5) {
1881 DRM_DEBUG_KMS("too many full retries, give up\n");
1884 memset(intel_dp
->train_set
, 0, 4);
1889 /* Check to see if we've tried the same voltage 5 times */
1890 if ((intel_dp
->train_set
[0] & DP_TRAIN_VOLTAGE_SWING_MASK
) == voltage
) {
1892 if (voltage_tries
== 5) {
1893 DRM_DEBUG_KMS("too many voltage retries, give up\n");
1898 voltage
= intel_dp
->train_set
[0] & DP_TRAIN_VOLTAGE_SWING_MASK
;
1900 /* Compute new intel_dp->train_set as requested by target */
1901 intel_get_adjust_train(intel_dp
, link_status
);
1908 intel_dp_complete_link_train(struct intel_dp
*intel_dp
)
1910 bool channel_eq
= false;
1911 int tries
, cr_tries
;
1912 uint32_t DP
= intel_dp
->DP
;
1914 /* channel equalization */
1919 uint8_t link_status
[DP_LINK_STATUS_SIZE
];
1922 DRM_ERROR("failed to train DP, aborting\n");
1923 intel_dp_link_down(intel_dp
);
1927 intel_dp_set_signal_levels(intel_dp
, &DP
);
1929 /* channel eq pattern */
1930 if (!intel_dp_set_link_train(intel_dp
, DP
,
1931 DP_TRAINING_PATTERN_2
|
1932 DP_LINK_SCRAMBLING_DISABLE
))
1935 drm_dp_link_train_channel_eq_delay(intel_dp
->dpcd
);
1936 if (!intel_dp_get_link_status(intel_dp
, link_status
))
1939 /* Make sure clock is still ok */
1940 if (!drm_dp_clock_recovery_ok(link_status
, intel_dp
->lane_count
)) {
1941 intel_dp_start_link_train(intel_dp
);
1946 if (drm_dp_channel_eq_ok(link_status
, intel_dp
->lane_count
)) {
1951 /* Try 5 times, then try clock recovery if that fails */
1953 intel_dp_link_down(intel_dp
);
1954 intel_dp_start_link_train(intel_dp
);
1960 /* Compute new intel_dp->train_set as requested by target */
1961 intel_get_adjust_train(intel_dp
, link_status
);
1966 DRM_DEBUG_KMS("Channel EQ done. DP Training successfull\n");
1968 intel_dp_set_link_train(intel_dp
, DP
, DP_TRAINING_PATTERN_DISABLE
);
1972 intel_dp_link_down(struct intel_dp
*intel_dp
)
1974 struct intel_digital_port
*intel_dig_port
= dp_to_dig_port(intel_dp
);
1975 struct drm_device
*dev
= intel_dig_port
->base
.base
.dev
;
1976 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1977 struct intel_crtc
*intel_crtc
=
1978 to_intel_crtc(intel_dig_port
->base
.base
.crtc
);
1979 uint32_t DP
= intel_dp
->DP
;
1982 * DDI code has a strict mode set sequence and we should try to respect
1983 * it, otherwise we might hang the machine in many different ways. So we
1984 * really should be disabling the port only on a complete crtc_disable
1985 * sequence. This function is just called under two conditions on DDI
1987 * - Link train failed while doing crtc_enable, and on this case we
1988 * really should respect the mode set sequence and wait for a
1990 * - Someone turned the monitor off and intel_dp_check_link_status
1991 * called us. We don't need to disable the whole port on this case, so
1992 * when someone turns the monitor on again,
1993 * intel_ddi_prepare_link_retrain will take care of redoing the link
1999 if (WARN_ON((I915_READ(intel_dp
->output_reg
) & DP_PORT_EN
) == 0))
2002 DRM_DEBUG_KMS("\n");
2004 if (HAS_PCH_CPT(dev
) && (IS_GEN7(dev
) || !is_cpu_edp(intel_dp
))) {
2005 DP
&= ~DP_LINK_TRAIN_MASK_CPT
;
2006 I915_WRITE(intel_dp
->output_reg
, DP
| DP_LINK_TRAIN_PAT_IDLE_CPT
);
2008 DP
&= ~DP_LINK_TRAIN_MASK
;
2009 I915_WRITE(intel_dp
->output_reg
, DP
| DP_LINK_TRAIN_PAT_IDLE
);
2011 POSTING_READ(intel_dp
->output_reg
);
2013 /* We don't really know why we're doing this */
2014 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
2016 if (HAS_PCH_IBX(dev
) &&
2017 I915_READ(intel_dp
->output_reg
) & DP_PIPEB_SELECT
) {
2018 struct drm_crtc
*crtc
= intel_dig_port
->base
.base
.crtc
;
2020 /* Hardware workaround: leaving our transcoder select
2021 * set to transcoder B while it's off will prevent the
2022 * corresponding HDMI output on transcoder A.
2024 * Combine this with another hardware workaround:
2025 * transcoder select bit can only be cleared while the
2028 DP
&= ~DP_PIPEB_SELECT
;
2029 I915_WRITE(intel_dp
->output_reg
, DP
);
2031 /* Changes to enable or select take place the vblank
2032 * after being written.
2034 if (WARN_ON(crtc
== NULL
)) {
2035 /* We should never try to disable a port without a crtc
2036 * attached. For paranoia keep the code around for a
2038 POSTING_READ(intel_dp
->output_reg
);
2041 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
2044 DP
&= ~DP_AUDIO_OUTPUT_ENABLE
;
2045 I915_WRITE(intel_dp
->output_reg
, DP
& ~DP_PORT_EN
);
2046 POSTING_READ(intel_dp
->output_reg
);
2047 msleep(intel_dp
->panel_power_down_delay
);
2051 intel_dp_get_dpcd(struct intel_dp
*intel_dp
)
2053 char dpcd_hex_dump
[sizeof(intel_dp
->dpcd
) * 3];
2055 if (intel_dp_aux_native_read_retry(intel_dp
, 0x000, intel_dp
->dpcd
,
2056 sizeof(intel_dp
->dpcd
)) == 0)
2057 return false; /* aux transfer failed */
2059 hex_dump_to_buffer(intel_dp
->dpcd
, sizeof(intel_dp
->dpcd
),
2060 32, 1, dpcd_hex_dump
, sizeof(dpcd_hex_dump
), false);
2061 DRM_DEBUG_KMS("DPCD: %s\n", dpcd_hex_dump
);
2063 if (intel_dp
->dpcd
[DP_DPCD_REV
] == 0)
2064 return false; /* DPCD not present */
2066 if (!(intel_dp
->dpcd
[DP_DOWNSTREAMPORT_PRESENT
] &
2067 DP_DWN_STRM_PORT_PRESENT
))
2068 return true; /* native DP sink */
2070 if (intel_dp
->dpcd
[DP_DPCD_REV
] == 0x10)
2071 return true; /* no per-port downstream info */
2073 if (intel_dp_aux_native_read_retry(intel_dp
, DP_DOWNSTREAM_PORT_0
,
2074 intel_dp
->downstream_ports
,
2075 DP_MAX_DOWNSTREAM_PORTS
) == 0)
2076 return false; /* downstream port status fetch failed */
2082 intel_dp_probe_oui(struct intel_dp
*intel_dp
)
2086 if (!(intel_dp
->dpcd
[DP_DOWN_STREAM_PORT_COUNT
] & DP_OUI_SUPPORT
))
2089 ironlake_edp_panel_vdd_on(intel_dp
);
2091 if (intel_dp_aux_native_read_retry(intel_dp
, DP_SINK_OUI
, buf
, 3))
2092 DRM_DEBUG_KMS("Sink OUI: %02hx%02hx%02hx\n",
2093 buf
[0], buf
[1], buf
[2]);
2095 if (intel_dp_aux_native_read_retry(intel_dp
, DP_BRANCH_OUI
, buf
, 3))
2096 DRM_DEBUG_KMS("Branch OUI: %02hx%02hx%02hx\n",
2097 buf
[0], buf
[1], buf
[2]);
2099 ironlake_edp_panel_vdd_off(intel_dp
, false);
2103 intel_dp_get_sink_irq(struct intel_dp
*intel_dp
, u8
*sink_irq_vector
)
2107 ret
= intel_dp_aux_native_read_retry(intel_dp
,
2108 DP_DEVICE_SERVICE_IRQ_VECTOR
,
2109 sink_irq_vector
, 1);
2117 intel_dp_handle_test_request(struct intel_dp
*intel_dp
)
2119 /* NAK by default */
2120 intel_dp_aux_native_write_1(intel_dp
, DP_TEST_RESPONSE
, DP_TEST_NAK
);
2124 * According to DP spec
2127 * 2. Configure link according to Receiver Capabilities
2128 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
2129 * 4. Check link status on receipt of hot-plug interrupt
2133 intel_dp_check_link_status(struct intel_dp
*intel_dp
)
2135 struct intel_encoder
*intel_encoder
= &dp_to_dig_port(intel_dp
)->base
;
2137 u8 link_status
[DP_LINK_STATUS_SIZE
];
2139 if (!intel_encoder
->connectors_active
)
2142 if (WARN_ON(!intel_encoder
->base
.crtc
))
2145 /* Try to read receiver status if the link appears to be up */
2146 if (!intel_dp_get_link_status(intel_dp
, link_status
)) {
2147 intel_dp_link_down(intel_dp
);
2151 /* Now read the DPCD to see if it's actually running */
2152 if (!intel_dp_get_dpcd(intel_dp
)) {
2153 intel_dp_link_down(intel_dp
);
2157 /* Try to read the source of the interrupt */
2158 if (intel_dp
->dpcd
[DP_DPCD_REV
] >= 0x11 &&
2159 intel_dp_get_sink_irq(intel_dp
, &sink_irq_vector
)) {
2160 /* Clear interrupt source */
2161 intel_dp_aux_native_write_1(intel_dp
,
2162 DP_DEVICE_SERVICE_IRQ_VECTOR
,
2165 if (sink_irq_vector
& DP_AUTOMATED_TEST_REQUEST
)
2166 intel_dp_handle_test_request(intel_dp
);
2167 if (sink_irq_vector
& (DP_CP_IRQ
| DP_SINK_SPECIFIC_IRQ
))
2168 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
2171 if (!drm_dp_channel_eq_ok(link_status
, intel_dp
->lane_count
)) {
2172 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
2173 drm_get_encoder_name(&intel_encoder
->base
));
2174 intel_dp_start_link_train(intel_dp
);
2175 intel_dp_complete_link_train(intel_dp
);
2179 /* XXX this is probably wrong for multiple downstream ports */
2180 static enum drm_connector_status
2181 intel_dp_detect_dpcd(struct intel_dp
*intel_dp
)
2183 uint8_t *dpcd
= intel_dp
->dpcd
;
2187 if (!intel_dp_get_dpcd(intel_dp
))
2188 return connector_status_disconnected
;
2190 /* if there's no downstream port, we're done */
2191 if (!(dpcd
[DP_DOWNSTREAMPORT_PRESENT
] & DP_DWN_STRM_PORT_PRESENT
))
2192 return connector_status_connected
;
2194 /* If we're HPD-aware, SINK_COUNT changes dynamically */
2195 hpd
= !!(intel_dp
->downstream_ports
[0] & DP_DS_PORT_HPD
);
2198 if (!intel_dp_aux_native_read_retry(intel_dp
, DP_SINK_COUNT
,
2200 return connector_status_unknown
;
2201 return DP_GET_SINK_COUNT(reg
) ? connector_status_connected
2202 : connector_status_disconnected
;
2205 /* If no HPD, poke DDC gently */
2206 if (drm_probe_ddc(&intel_dp
->adapter
))
2207 return connector_status_connected
;
2209 /* Well we tried, say unknown for unreliable port types */
2210 type
= intel_dp
->downstream_ports
[0] & DP_DS_PORT_TYPE_MASK
;
2211 if (type
== DP_DS_PORT_TYPE_VGA
|| type
== DP_DS_PORT_TYPE_NON_EDID
)
2212 return connector_status_unknown
;
2214 /* Anything else is out of spec, warn and ignore */
2215 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
2216 return connector_status_disconnected
;
2219 static enum drm_connector_status
2220 ironlake_dp_detect(struct intel_dp
*intel_dp
)
2222 struct drm_device
*dev
= intel_dp_to_dev(intel_dp
);
2223 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2224 struct intel_digital_port
*intel_dig_port
= dp_to_dig_port(intel_dp
);
2225 enum drm_connector_status status
;
2227 /* Can't disconnect eDP, but you can close the lid... */
2228 if (is_edp(intel_dp
)) {
2229 status
= intel_panel_detect(dev
);
2230 if (status
== connector_status_unknown
)
2231 status
= connector_status_connected
;
2235 if (!ibx_digital_port_connected(dev_priv
, intel_dig_port
))
2236 return connector_status_disconnected
;
2238 return intel_dp_detect_dpcd(intel_dp
);
2241 static enum drm_connector_status
2242 g4x_dp_detect(struct intel_dp
*intel_dp
)
2244 struct drm_device
*dev
= intel_dp_to_dev(intel_dp
);
2245 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2246 struct intel_digital_port
*intel_dig_port
= dp_to_dig_port(intel_dp
);
2249 /* Can't disconnect eDP, but you can close the lid... */
2250 if (is_edp(intel_dp
)) {
2251 enum drm_connector_status status
;
2253 status
= intel_panel_detect(dev
);
2254 if (status
== connector_status_unknown
)
2255 status
= connector_status_connected
;
2259 switch (intel_dig_port
->port
) {
2261 bit
= PORTB_HOTPLUG_LIVE_STATUS
;
2264 bit
= PORTC_HOTPLUG_LIVE_STATUS
;
2267 bit
= PORTD_HOTPLUG_LIVE_STATUS
;
2270 return connector_status_unknown
;
2273 if ((I915_READ(PORT_HOTPLUG_STAT
) & bit
) == 0)
2274 return connector_status_disconnected
;
2276 return intel_dp_detect_dpcd(intel_dp
);
2279 static struct edid
*
2280 intel_dp_get_edid(struct drm_connector
*connector
, struct i2c_adapter
*adapter
)
2282 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
2284 /* use cached edid if we have one */
2285 if (intel_connector
->edid
) {
2290 if (IS_ERR(intel_connector
->edid
))
2293 size
= (intel_connector
->edid
->extensions
+ 1) * EDID_LENGTH
;
2294 edid
= kmalloc(size
, GFP_KERNEL
);
2298 memcpy(edid
, intel_connector
->edid
, size
);
2302 return drm_get_edid(connector
, adapter
);
2306 intel_dp_get_edid_modes(struct drm_connector
*connector
, struct i2c_adapter
*adapter
)
2308 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
2310 /* use cached edid if we have one */
2311 if (intel_connector
->edid
) {
2313 if (IS_ERR(intel_connector
->edid
))
2316 return intel_connector_update_modes(connector
,
2317 intel_connector
->edid
);
2320 return intel_ddc_get_modes(connector
, adapter
);
2323 static enum drm_connector_status
2324 intel_dp_detect(struct drm_connector
*connector
, bool force
)
2326 struct intel_dp
*intel_dp
= intel_attached_dp(connector
);
2327 struct intel_digital_port
*intel_dig_port
= dp_to_dig_port(intel_dp
);
2328 struct intel_encoder
*intel_encoder
= &intel_dig_port
->base
;
2329 struct drm_device
*dev
= connector
->dev
;
2330 enum drm_connector_status status
;
2331 struct edid
*edid
= NULL
;
2333 intel_dp
->has_audio
= false;
2335 if (HAS_PCH_SPLIT(dev
))
2336 status
= ironlake_dp_detect(intel_dp
);
2338 status
= g4x_dp_detect(intel_dp
);
2340 if (status
!= connector_status_connected
)
2343 intel_dp_probe_oui(intel_dp
);
2345 if (intel_dp
->force_audio
!= HDMI_AUDIO_AUTO
) {
2346 intel_dp
->has_audio
= (intel_dp
->force_audio
== HDMI_AUDIO_ON
);
2348 edid
= intel_dp_get_edid(connector
, &intel_dp
->adapter
);
2350 intel_dp
->has_audio
= drm_detect_monitor_audio(edid
);
2355 if (intel_encoder
->type
!= INTEL_OUTPUT_EDP
)
2356 intel_encoder
->type
= INTEL_OUTPUT_DISPLAYPORT
;
2357 return connector_status_connected
;
2360 static int intel_dp_get_modes(struct drm_connector
*connector
)
2362 struct intel_dp
*intel_dp
= intel_attached_dp(connector
);
2363 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
2364 struct drm_device
*dev
= connector
->dev
;
2367 /* We should parse the EDID data and find out if it has an audio sink
2370 ret
= intel_dp_get_edid_modes(connector
, &intel_dp
->adapter
);
2374 /* if eDP has no EDID, fall back to fixed mode */
2375 if (is_edp(intel_dp
) && intel_connector
->panel
.fixed_mode
) {
2376 struct drm_display_mode
*mode
;
2377 mode
= drm_mode_duplicate(dev
,
2378 intel_connector
->panel
.fixed_mode
);
2380 drm_mode_probed_add(connector
, mode
);
2388 intel_dp_detect_audio(struct drm_connector
*connector
)
2390 struct intel_dp
*intel_dp
= intel_attached_dp(connector
);
2392 bool has_audio
= false;
2394 edid
= intel_dp_get_edid(connector
, &intel_dp
->adapter
);
2396 has_audio
= drm_detect_monitor_audio(edid
);
2404 intel_dp_set_property(struct drm_connector
*connector
,
2405 struct drm_property
*property
,
2408 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
2409 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
2410 struct intel_encoder
*intel_encoder
= intel_attached_encoder(connector
);
2411 struct intel_dp
*intel_dp
= enc_to_intel_dp(&intel_encoder
->base
);
2414 ret
= drm_object_property_set_value(&connector
->base
, property
, val
);
2418 if (property
== dev_priv
->force_audio_property
) {
2422 if (i
== intel_dp
->force_audio
)
2425 intel_dp
->force_audio
= i
;
2427 if (i
== HDMI_AUDIO_AUTO
)
2428 has_audio
= intel_dp_detect_audio(connector
);
2430 has_audio
= (i
== HDMI_AUDIO_ON
);
2432 if (has_audio
== intel_dp
->has_audio
)
2435 intel_dp
->has_audio
= has_audio
;
2439 if (property
== dev_priv
->broadcast_rgb_property
) {
2441 case INTEL_BROADCAST_RGB_AUTO
:
2442 intel_dp
->color_range_auto
= true;
2444 case INTEL_BROADCAST_RGB_FULL
:
2445 intel_dp
->color_range_auto
= false;
2446 intel_dp
->color_range
= 0;
2448 case INTEL_BROADCAST_RGB_LIMITED
:
2449 intel_dp
->color_range_auto
= false;
2450 intel_dp
->color_range
= DP_COLOR_RANGE_16_235
;
2458 if (is_edp(intel_dp
) &&
2459 property
== connector
->dev
->mode_config
.scaling_mode_property
) {
2460 if (val
== DRM_MODE_SCALE_NONE
) {
2461 DRM_DEBUG_KMS("no scaling not supported\n");
2465 if (intel_connector
->panel
.fitting_mode
== val
) {
2466 /* the eDP scaling property is not changed */
2469 intel_connector
->panel
.fitting_mode
= val
;
2477 if (intel_encoder
->base
.crtc
)
2478 intel_crtc_restore_mode(intel_encoder
->base
.crtc
);
2484 intel_dp_destroy(struct drm_connector
*connector
)
2486 struct drm_device
*dev
= connector
->dev
;
2487 struct intel_dp
*intel_dp
= intel_attached_dp(connector
);
2488 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
2490 if (!IS_ERR_OR_NULL(intel_connector
->edid
))
2491 kfree(intel_connector
->edid
);
2493 if (is_edp(intel_dp
)) {
2494 intel_panel_destroy_backlight(dev
);
2495 intel_panel_fini(&intel_connector
->panel
);
2498 drm_sysfs_connector_remove(connector
);
2499 drm_connector_cleanup(connector
);
2503 void intel_dp_encoder_destroy(struct drm_encoder
*encoder
)
2505 struct intel_digital_port
*intel_dig_port
= enc_to_dig_port(encoder
);
2506 struct intel_dp
*intel_dp
= &intel_dig_port
->dp
;
2508 i2c_del_adapter(&intel_dp
->adapter
);
2509 drm_encoder_cleanup(encoder
);
2510 if (is_edp(intel_dp
)) {
2511 cancel_delayed_work_sync(&intel_dp
->panel_vdd_work
);
2512 ironlake_panel_vdd_off_sync(intel_dp
);
2514 kfree(intel_dig_port
);
2517 static const struct drm_encoder_helper_funcs intel_dp_helper_funcs
= {
2518 .mode_set
= intel_dp_mode_set
,
2521 static const struct drm_connector_funcs intel_dp_connector_funcs
= {
2522 .dpms
= intel_connector_dpms
,
2523 .detect
= intel_dp_detect
,
2524 .fill_modes
= drm_helper_probe_single_connector_modes
,
2525 .set_property
= intel_dp_set_property
,
2526 .destroy
= intel_dp_destroy
,
2529 static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs
= {
2530 .get_modes
= intel_dp_get_modes
,
2531 .mode_valid
= intel_dp_mode_valid
,
2532 .best_encoder
= intel_best_encoder
,
2535 static const struct drm_encoder_funcs intel_dp_enc_funcs
= {
2536 .destroy
= intel_dp_encoder_destroy
,
2540 intel_dp_hot_plug(struct intel_encoder
*intel_encoder
)
2542 struct intel_dp
*intel_dp
= enc_to_intel_dp(&intel_encoder
->base
);
2544 intel_dp_check_link_status(intel_dp
);
2547 /* Return which DP Port should be selected for Transcoder DP control */
2549 intel_trans_dp_port_sel(struct drm_crtc
*crtc
)
2551 struct drm_device
*dev
= crtc
->dev
;
2552 struct intel_encoder
*intel_encoder
;
2553 struct intel_dp
*intel_dp
;
2555 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
) {
2556 intel_dp
= enc_to_intel_dp(&intel_encoder
->base
);
2558 if (intel_encoder
->type
== INTEL_OUTPUT_DISPLAYPORT
||
2559 intel_encoder
->type
== INTEL_OUTPUT_EDP
)
2560 return intel_dp
->output_reg
;
2566 /* check the VBT to see whether the eDP is on DP-D port */
2567 bool intel_dpd_is_edp(struct drm_device
*dev
)
2569 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2570 struct child_device_config
*p_child
;
2573 if (!dev_priv
->child_dev_num
)
2576 for (i
= 0; i
< dev_priv
->child_dev_num
; i
++) {
2577 p_child
= dev_priv
->child_dev
+ i
;
2579 if (p_child
->dvo_port
== PORT_IDPD
&&
2580 p_child
->device_type
== DEVICE_TYPE_eDP
)
2587 intel_dp_add_properties(struct intel_dp
*intel_dp
, struct drm_connector
*connector
)
2589 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
2591 intel_attach_force_audio_property(connector
);
2592 intel_attach_broadcast_rgb_property(connector
);
2593 intel_dp
->color_range_auto
= true;
2595 if (is_edp(intel_dp
)) {
2596 drm_mode_create_scaling_mode_property(connector
->dev
);
2597 drm_object_attach_property(
2599 connector
->dev
->mode_config
.scaling_mode_property
,
2600 DRM_MODE_SCALE_ASPECT
);
2601 intel_connector
->panel
.fitting_mode
= DRM_MODE_SCALE_ASPECT
;
2606 intel_dp_init_panel_power_sequencer(struct drm_device
*dev
,
2607 struct intel_dp
*intel_dp
,
2608 struct edp_power_seq
*out
)
2610 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2611 struct edp_power_seq cur
, vbt
, spec
, final
;
2612 u32 pp_on
, pp_off
, pp_div
, pp
;
2613 int pp_control_reg
, pp_on_reg
, pp_off_reg
, pp_div_reg
;
2615 if (HAS_PCH_SPLIT(dev
)) {
2616 pp_control_reg
= PCH_PP_CONTROL
;
2617 pp_on_reg
= PCH_PP_ON_DELAYS
;
2618 pp_off_reg
= PCH_PP_OFF_DELAYS
;
2619 pp_div_reg
= PCH_PP_DIVISOR
;
2621 pp_control_reg
= PIPEA_PP_CONTROL
;
2622 pp_on_reg
= PIPEA_PP_ON_DELAYS
;
2623 pp_off_reg
= PIPEA_PP_OFF_DELAYS
;
2624 pp_div_reg
= PIPEA_PP_DIVISOR
;
2627 /* Workaround: Need to write PP_CONTROL with the unlock key as
2628 * the very first thing. */
2629 pp
= ironlake_get_pp_control(intel_dp
);
2630 I915_WRITE(pp_control_reg
, pp
);
2632 pp_on
= I915_READ(pp_on_reg
);
2633 pp_off
= I915_READ(pp_off_reg
);
2634 pp_div
= I915_READ(pp_div_reg
);
2636 /* Pull timing values out of registers */
2637 cur
.t1_t3
= (pp_on
& PANEL_POWER_UP_DELAY_MASK
) >>
2638 PANEL_POWER_UP_DELAY_SHIFT
;
2640 cur
.t8
= (pp_on
& PANEL_LIGHT_ON_DELAY_MASK
) >>
2641 PANEL_LIGHT_ON_DELAY_SHIFT
;
2643 cur
.t9
= (pp_off
& PANEL_LIGHT_OFF_DELAY_MASK
) >>
2644 PANEL_LIGHT_OFF_DELAY_SHIFT
;
2646 cur
.t10
= (pp_off
& PANEL_POWER_DOWN_DELAY_MASK
) >>
2647 PANEL_POWER_DOWN_DELAY_SHIFT
;
2649 cur
.t11_t12
= ((pp_div
& PANEL_POWER_CYCLE_DELAY_MASK
) >>
2650 PANEL_POWER_CYCLE_DELAY_SHIFT
) * 1000;
2652 DRM_DEBUG_KMS("cur t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
2653 cur
.t1_t3
, cur
.t8
, cur
.t9
, cur
.t10
, cur
.t11_t12
);
2655 vbt
= dev_priv
->edp
.pps
;
2657 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
2658 * our hw here, which are all in 100usec. */
2659 spec
.t1_t3
= 210 * 10;
2660 spec
.t8
= 50 * 10; /* no limit for t8, use t7 instead */
2661 spec
.t9
= 50 * 10; /* no limit for t9, make it symmetric with t8 */
2662 spec
.t10
= 500 * 10;
2663 /* This one is special and actually in units of 100ms, but zero
2664 * based in the hw (so we need to add 100 ms). But the sw vbt
2665 * table multiplies it with 1000 to make it in units of 100usec,
2667 spec
.t11_t12
= (510 + 100) * 10;
2669 DRM_DEBUG_KMS("vbt t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
2670 vbt
.t1_t3
, vbt
.t8
, vbt
.t9
, vbt
.t10
, vbt
.t11_t12
);
2672 /* Use the max of the register settings and vbt. If both are
2673 * unset, fall back to the spec limits. */
2674 #define assign_final(field) final.field = (max(cur.field, vbt.field) == 0 ? \
2676 max(cur.field, vbt.field))
2677 assign_final(t1_t3
);
2681 assign_final(t11_t12
);
2684 #define get_delay(field) (DIV_ROUND_UP(final.field, 10))
2685 intel_dp
->panel_power_up_delay
= get_delay(t1_t3
);
2686 intel_dp
->backlight_on_delay
= get_delay(t8
);
2687 intel_dp
->backlight_off_delay
= get_delay(t9
);
2688 intel_dp
->panel_power_down_delay
= get_delay(t10
);
2689 intel_dp
->panel_power_cycle_delay
= get_delay(t11_t12
);
2692 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
2693 intel_dp
->panel_power_up_delay
, intel_dp
->panel_power_down_delay
,
2694 intel_dp
->panel_power_cycle_delay
);
2696 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
2697 intel_dp
->backlight_on_delay
, intel_dp
->backlight_off_delay
);
2704 intel_dp_init_panel_power_sequencer_registers(struct drm_device
*dev
,
2705 struct intel_dp
*intel_dp
,
2706 struct edp_power_seq
*seq
)
2708 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2709 u32 pp_on
, pp_off
, pp_div
, port_sel
= 0;
2710 int div
= HAS_PCH_SPLIT(dev
) ? intel_pch_rawclk(dev
) : intel_hrawclk(dev
);
2711 int pp_on_reg
, pp_off_reg
, pp_div_reg
;
2713 if (HAS_PCH_SPLIT(dev
)) {
2714 pp_on_reg
= PCH_PP_ON_DELAYS
;
2715 pp_off_reg
= PCH_PP_OFF_DELAYS
;
2716 pp_div_reg
= PCH_PP_DIVISOR
;
2718 pp_on_reg
= PIPEA_PP_ON_DELAYS
;
2719 pp_off_reg
= PIPEA_PP_OFF_DELAYS
;
2720 pp_div_reg
= PIPEA_PP_DIVISOR
;
2723 if (IS_VALLEYVIEW(dev
))
2724 port_sel
= I915_READ(pp_on_reg
) & 0xc0000000;
2726 /* And finally store the new values in the power sequencer. */
2727 pp_on
= (seq
->t1_t3
<< PANEL_POWER_UP_DELAY_SHIFT
) |
2728 (seq
->t8
<< PANEL_LIGHT_ON_DELAY_SHIFT
);
2729 pp_off
= (seq
->t9
<< PANEL_LIGHT_OFF_DELAY_SHIFT
) |
2730 (seq
->t10
<< PANEL_POWER_DOWN_DELAY_SHIFT
);
2731 /* Compute the divisor for the pp clock, simply match the Bspec
2733 pp_div
= ((100 * div
)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT
;
2734 pp_div
|= (DIV_ROUND_UP(seq
->t11_t12
, 1000)
2735 << PANEL_POWER_CYCLE_DELAY_SHIFT
);
2737 /* Haswell doesn't have any port selection bits for the panel
2738 * power sequencer any more. */
2739 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
)) {
2740 if (is_cpu_edp(intel_dp
))
2741 port_sel
= PANEL_POWER_PORT_DP_A
;
2743 port_sel
= PANEL_POWER_PORT_DP_D
;
2748 I915_WRITE(pp_on_reg
, pp_on
);
2749 I915_WRITE(pp_off_reg
, pp_off
);
2750 I915_WRITE(pp_div_reg
, pp_div
);
2752 DRM_DEBUG_KMS("panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n",
2753 I915_READ(pp_on_reg
),
2754 I915_READ(pp_off_reg
),
2755 I915_READ(pp_div_reg
));
2759 intel_dp_init_connector(struct intel_digital_port
*intel_dig_port
,
2760 struct intel_connector
*intel_connector
)
2762 struct drm_connector
*connector
= &intel_connector
->base
;
2763 struct intel_dp
*intel_dp
= &intel_dig_port
->dp
;
2764 struct intel_encoder
*intel_encoder
= &intel_dig_port
->base
;
2765 struct drm_device
*dev
= intel_encoder
->base
.dev
;
2766 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2767 struct drm_display_mode
*fixed_mode
= NULL
;
2768 struct edp_power_seq power_seq
= { 0 };
2769 enum port port
= intel_dig_port
->port
;
2770 const char *name
= NULL
;
2773 /* Preserve the current hw state. */
2774 intel_dp
->DP
= I915_READ(intel_dp
->output_reg
);
2775 intel_dp
->attached_connector
= intel_connector
;
2777 if (HAS_PCH_SPLIT(dev
) && port
== PORT_D
)
2778 if (intel_dpd_is_edp(dev
))
2779 intel_dp
->is_pch_edp
= true;
2782 * FIXME : We need to initialize built-in panels before external panels.
2783 * For X0, DP_C is fixed as eDP. Revisit this as part of VLV eDP cleanup
2785 if (IS_VALLEYVIEW(dev
) && port
== PORT_C
) {
2786 type
= DRM_MODE_CONNECTOR_eDP
;
2787 intel_encoder
->type
= INTEL_OUTPUT_EDP
;
2788 } else if (port
== PORT_A
|| is_pch_edp(intel_dp
)) {
2789 type
= DRM_MODE_CONNECTOR_eDP
;
2790 intel_encoder
->type
= INTEL_OUTPUT_EDP
;
2792 /* The intel_encoder->type value may be INTEL_OUTPUT_UNKNOWN for
2793 * DDI or INTEL_OUTPUT_DISPLAYPORT for the older gens, so don't
2796 type
= DRM_MODE_CONNECTOR_DisplayPort
;
2799 drm_connector_init(dev
, connector
, &intel_dp_connector_funcs
, type
);
2800 drm_connector_helper_add(connector
, &intel_dp_connector_helper_funcs
);
2802 connector
->polled
= DRM_CONNECTOR_POLL_HPD
;
2803 connector
->interlace_allowed
= true;
2804 connector
->doublescan_allowed
= 0;
2806 INIT_DELAYED_WORK(&intel_dp
->panel_vdd_work
,
2807 ironlake_panel_vdd_work
);
2809 intel_connector_attach_encoder(intel_connector
, intel_encoder
);
2810 drm_sysfs_connector_add(connector
);
2813 intel_connector
->get_hw_state
= intel_ddi_connector_get_hw_state
;
2815 intel_connector
->get_hw_state
= intel_connector_get_hw_state
;
2817 intel_dp
->aux_ch_ctl_reg
= intel_dp
->output_reg
+ 0x10;
2819 switch (intel_dig_port
->port
) {
2821 intel_dp
->aux_ch_ctl_reg
= DPA_AUX_CH_CTL
;
2824 intel_dp
->aux_ch_ctl_reg
= PCH_DPB_AUX_CH_CTL
;
2827 intel_dp
->aux_ch_ctl_reg
= PCH_DPC_AUX_CH_CTL
;
2830 intel_dp
->aux_ch_ctl_reg
= PCH_DPD_AUX_CH_CTL
;
2837 /* Set up the DDC bus. */
2840 intel_encoder
->hpd_pin
= HPD_PORT_A
;
2844 intel_encoder
->hpd_pin
= HPD_PORT_B
;
2848 intel_encoder
->hpd_pin
= HPD_PORT_C
;
2852 intel_encoder
->hpd_pin
= HPD_PORT_D
;
2859 if (is_edp(intel_dp
))
2860 intel_dp_init_panel_power_sequencer(dev
, intel_dp
, &power_seq
);
2862 intel_dp_i2c_init(intel_dp
, intel_connector
, name
);
2864 /* Cache DPCD and EDID for edp. */
2865 if (is_edp(intel_dp
)) {
2867 struct drm_display_mode
*scan
;
2870 ironlake_edp_panel_vdd_on(intel_dp
);
2871 ret
= intel_dp_get_dpcd(intel_dp
);
2872 ironlake_edp_panel_vdd_off(intel_dp
, false);
2875 if (intel_dp
->dpcd
[DP_DPCD_REV
] >= 0x11)
2876 dev_priv
->no_aux_handshake
=
2877 intel_dp
->dpcd
[DP_MAX_DOWNSPREAD
] &
2878 DP_NO_AUX_HANDSHAKE_LINK_TRAINING
;
2880 /* if this fails, presume the device is a ghost */
2881 DRM_INFO("failed to retrieve link info, disabling eDP\n");
2882 intel_dp_encoder_destroy(&intel_encoder
->base
);
2883 intel_dp_destroy(connector
);
2887 /* We now know it's not a ghost, init power sequence regs. */
2888 intel_dp_init_panel_power_sequencer_registers(dev
, intel_dp
,
2891 ironlake_edp_panel_vdd_on(intel_dp
);
2892 edid
= drm_get_edid(connector
, &intel_dp
->adapter
);
2894 if (drm_add_edid_modes(connector
, edid
)) {
2895 drm_mode_connector_update_edid_property(connector
, edid
);
2896 drm_edid_to_eld(connector
, edid
);
2899 edid
= ERR_PTR(-EINVAL
);
2902 edid
= ERR_PTR(-ENOENT
);
2904 intel_connector
->edid
= edid
;
2906 /* prefer fixed mode from EDID if available */
2907 list_for_each_entry(scan
, &connector
->probed_modes
, head
) {
2908 if ((scan
->type
& DRM_MODE_TYPE_PREFERRED
)) {
2909 fixed_mode
= drm_mode_duplicate(dev
, scan
);
2914 /* fallback to VBT if available for eDP */
2915 if (!fixed_mode
&& dev_priv
->lfp_lvds_vbt_mode
) {
2916 fixed_mode
= drm_mode_duplicate(dev
, dev_priv
->lfp_lvds_vbt_mode
);
2918 fixed_mode
->type
|= DRM_MODE_TYPE_PREFERRED
;
2921 ironlake_edp_panel_vdd_off(intel_dp
, false);
2924 if (is_edp(intel_dp
)) {
2925 intel_panel_init(&intel_connector
->panel
, fixed_mode
);
2926 intel_panel_setup_backlight(connector
);
2929 intel_dp_add_properties(intel_dp
, connector
);
2931 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
2932 * 0xd. Failure to do so will result in spurious interrupts being
2933 * generated on the port when a cable is not attached.
2935 if (IS_G4X(dev
) && !IS_GM45(dev
)) {
2936 u32 temp
= I915_READ(PEG_BAND_GAP_DATA
);
2937 I915_WRITE(PEG_BAND_GAP_DATA
, (temp
& ~0xf) | 0xd);
2942 intel_dp_init(struct drm_device
*dev
, int output_reg
, enum port port
)
2944 struct intel_digital_port
*intel_dig_port
;
2945 struct intel_encoder
*intel_encoder
;
2946 struct drm_encoder
*encoder
;
2947 struct intel_connector
*intel_connector
;
2949 intel_dig_port
= kzalloc(sizeof(struct intel_digital_port
), GFP_KERNEL
);
2950 if (!intel_dig_port
)
2953 intel_connector
= kzalloc(sizeof(struct intel_connector
), GFP_KERNEL
);
2954 if (!intel_connector
) {
2955 kfree(intel_dig_port
);
2959 intel_encoder
= &intel_dig_port
->base
;
2960 encoder
= &intel_encoder
->base
;
2962 drm_encoder_init(dev
, &intel_encoder
->base
, &intel_dp_enc_funcs
,
2963 DRM_MODE_ENCODER_TMDS
);
2964 drm_encoder_helper_add(&intel_encoder
->base
, &intel_dp_helper_funcs
);
2966 intel_encoder
->compute_config
= intel_dp_compute_config
;
2967 intel_encoder
->enable
= intel_enable_dp
;
2968 intel_encoder
->pre_enable
= intel_pre_enable_dp
;
2969 intel_encoder
->disable
= intel_disable_dp
;
2970 intel_encoder
->post_disable
= intel_post_disable_dp
;
2971 intel_encoder
->get_hw_state
= intel_dp_get_hw_state
;
2973 intel_dig_port
->port
= port
;
2974 intel_dig_port
->dp
.output_reg
= output_reg
;
2976 intel_encoder
->type
= INTEL_OUTPUT_DISPLAYPORT
;
2977 intel_encoder
->crtc_mask
= (1 << 0) | (1 << 1) | (1 << 2);
2978 intel_encoder
->cloneable
= false;
2979 intel_encoder
->hot_plug
= intel_dp_hot_plug
;
2981 intel_dp_init_connector(intel_dig_port
, intel_connector
);