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)
46 static const struct dp_link_dpll gen4_dpll[] = {
48 { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
50 { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
53 static const struct dp_link_dpll pch_dpll[] = {
55 { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
57 { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
60 static const struct dp_link_dpll vlv_dpll[] = {
62 { .p1 = 3, .p2 = 2, .n = 5, .m1 = 5, .m2 = 3 } },
64 { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } }
68 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
69 * @intel_dp: DP struct
71 * If a CPU or PCH DP output is attached to an eDP panel, this function
72 * will return true, and false otherwise.
74 static bool is_edp(struct intel_dp *intel_dp)
76 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
78 return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
81 static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp)
83 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
85 return intel_dig_port->base.base.dev;
88 static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
90 return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
93 static void intel_dp_link_down(struct intel_dp *intel_dp);
96 intel_dp_max_link_bw(struct intel_dp *intel_dp)
98 int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
100 switch (max_link_bw) {
101 case DP_LINK_BW_1_62:
104 case DP_LINK_BW_5_4: /* 1.2 capable displays may advertise higher bw */
105 max_link_bw = DP_LINK_BW_2_7;
108 WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
110 max_link_bw = DP_LINK_BW_1_62;
117 * The units on the numbers in the next two are... bizarre. Examples will
118 * make it clearer; this one parallels an example in the eDP spec.
120 * intel_dp_max_data_rate for one lane of 2.7GHz evaluates as:
122 * 270000 * 1 * 8 / 10 == 216000
124 * The actual data capacity of that configuration is 2.16Gbit/s, so the
125 * units are decakilobits. ->clock in a drm_display_mode is in kilohertz -
126 * or equivalently, kilopixels per second - so for 1680x1050R it'd be
127 * 119000. At 18bpp that's 2142000 kilobits per second.
129 * Thus the strange-looking division by 10 in intel_dp_link_required, to
130 * get the result in decakilobits instead of kilobits.
134 intel_dp_link_required(int pixel_clock, int bpp)
136 return (pixel_clock * bpp + 9) / 10;
140 intel_dp_max_data_rate(int max_link_clock, int max_lanes)
142 return (max_link_clock * max_lanes * 8) / 10;
146 intel_dp_mode_valid(struct drm_connector *connector,
147 struct drm_display_mode *mode)
149 struct intel_dp *intel_dp = intel_attached_dp(connector);
150 struct intel_connector *intel_connector = to_intel_connector(connector);
151 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
152 int target_clock = mode->clock;
153 int max_rate, mode_rate, max_lanes, max_link_clock;
155 if (is_edp(intel_dp) && fixed_mode) {
156 if (mode->hdisplay > fixed_mode->hdisplay)
159 if (mode->vdisplay > fixed_mode->vdisplay)
162 target_clock = fixed_mode->clock;
165 max_link_clock = drm_dp_bw_code_to_link_rate(intel_dp_max_link_bw(intel_dp));
166 max_lanes = drm_dp_max_lane_count(intel_dp->dpcd);
168 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
169 mode_rate = intel_dp_link_required(target_clock, 18);
171 if (mode_rate > max_rate)
172 return MODE_CLOCK_HIGH;
174 if (mode->clock < 10000)
175 return MODE_CLOCK_LOW;
177 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
178 return MODE_H_ILLEGAL;
184 pack_aux(uint8_t *src, int src_bytes)
191 for (i = 0; i < src_bytes; i++)
192 v |= ((uint32_t) src[i]) << ((3-i) * 8);
197 unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
202 for (i = 0; i < dst_bytes; i++)
203 dst[i] = src >> ((3-i) * 8);
206 /* hrawclock is 1/4 the FSB frequency */
208 intel_hrawclk(struct drm_device *dev)
210 struct drm_i915_private *dev_priv = dev->dev_private;
213 /* There is no CLKCFG reg in Valleyview. VLV hrawclk is 200 MHz */
214 if (IS_VALLEYVIEW(dev))
217 clkcfg = I915_READ(CLKCFG);
218 switch (clkcfg & CLKCFG_FSB_MASK) {
227 case CLKCFG_FSB_1067:
229 case CLKCFG_FSB_1333:
231 /* these two are just a guess; one of them might be right */
232 case CLKCFG_FSB_1600:
233 case CLKCFG_FSB_1600_ALT:
240 static bool ironlake_edp_have_panel_power(struct intel_dp *intel_dp)
242 struct drm_device *dev = intel_dp_to_dev(intel_dp);
243 struct drm_i915_private *dev_priv = dev->dev_private;
246 pp_stat_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_STATUS : PCH_PP_STATUS;
247 return (I915_READ(pp_stat_reg) & PP_ON) != 0;
250 static bool ironlake_edp_have_panel_vdd(struct intel_dp *intel_dp)
252 struct drm_device *dev = intel_dp_to_dev(intel_dp);
253 struct drm_i915_private *dev_priv = dev->dev_private;
256 pp_ctrl_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_CONTROL : PCH_PP_CONTROL;
257 return (I915_READ(pp_ctrl_reg) & EDP_FORCE_VDD) != 0;
261 intel_dp_check_edp(struct intel_dp *intel_dp)
263 struct drm_device *dev = intel_dp_to_dev(intel_dp);
264 struct drm_i915_private *dev_priv = dev->dev_private;
265 u32 pp_stat_reg, pp_ctrl_reg;
267 if (!is_edp(intel_dp))
270 pp_stat_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_STATUS : PCH_PP_STATUS;
271 pp_ctrl_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_CONTROL : PCH_PP_CONTROL;
273 if (!ironlake_edp_have_panel_power(intel_dp) && !ironlake_edp_have_panel_vdd(intel_dp)) {
274 WARN(1, "eDP powered off while attempting aux channel communication.\n");
275 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
276 I915_READ(pp_stat_reg),
277 I915_READ(pp_ctrl_reg));
282 intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
284 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
285 struct drm_device *dev = intel_dig_port->base.base.dev;
286 struct drm_i915_private *dev_priv = dev->dev_private;
287 uint32_t ch_ctl = intel_dp->aux_ch_ctl_reg;
291 #define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
293 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
294 msecs_to_jiffies_timeout(10));
296 done = wait_for_atomic(C, 10) == 0;
298 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
305 static uint32_t get_aux_clock_divider(struct intel_dp *intel_dp,
308 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
309 struct drm_device *dev = intel_dig_port->base.base.dev;
310 struct drm_i915_private *dev_priv = dev->dev_private;
312 /* The clock divider is based off the hrawclk,
313 * and would like to run at 2MHz. So, take the
314 * hrawclk value and divide by 2 and use that
316 * Note that PCH attached eDP panels should use a 125MHz input
319 if (IS_VALLEYVIEW(dev)) {
320 return index ? 0 : 100;
321 } else if (intel_dig_port->port == PORT_A) {
325 return DIV_ROUND_CLOSEST(intel_ddi_get_cdclk_freq(dev_priv), 2000);
326 else if (IS_GEN6(dev) || IS_GEN7(dev))
327 return 200; /* SNB & IVB eDP input clock at 400Mhz */
329 return 225; /* eDP input clock at 450Mhz */
330 } else if (dev_priv->pch_id == INTEL_PCH_LPT_DEVICE_ID_TYPE) {
331 /* Workaround for non-ULT HSW */
337 } else if (HAS_PCH_SPLIT(dev)) {
338 return index ? 0 : DIV_ROUND_UP(intel_pch_rawclk(dev), 2);
340 return index ? 0 :intel_hrawclk(dev) / 2;
345 intel_dp_aux_ch(struct intel_dp *intel_dp,
346 uint8_t *send, int send_bytes,
347 uint8_t *recv, int recv_size)
349 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
350 struct drm_device *dev = intel_dig_port->base.base.dev;
351 struct drm_i915_private *dev_priv = dev->dev_private;
352 uint32_t ch_ctl = intel_dp->aux_ch_ctl_reg;
353 uint32_t ch_data = ch_ctl + 4;
354 uint32_t aux_clock_divider;
355 int i, ret, recv_bytes;
357 int try, precharge, clock = 0;
358 bool has_aux_irq = INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev);
360 /* dp aux is extremely sensitive to irq latency, hence request the
361 * lowest possible wakeup latency and so prevent the cpu from going into
364 pm_qos_update_request(&dev_priv->pm_qos, 0);
366 intel_dp_check_edp(intel_dp);
373 intel_aux_display_runtime_get(dev_priv);
375 /* Try to wait for any previous AUX channel activity */
376 for (try = 0; try < 3; try++) {
377 status = I915_READ_NOTRACE(ch_ctl);
378 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
384 WARN(1, "dp_aux_ch not started status 0x%08x\n",
390 while ((aux_clock_divider = get_aux_clock_divider(intel_dp, clock++))) {
391 /* Must try at least 3 times according to DP spec */
392 for (try = 0; try < 5; try++) {
393 /* Load the send data into the aux channel data registers */
394 for (i = 0; i < send_bytes; i += 4)
395 I915_WRITE(ch_data + i,
396 pack_aux(send + i, send_bytes - i));
398 /* Send the command and wait for it to complete */
400 DP_AUX_CH_CTL_SEND_BUSY |
401 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
402 DP_AUX_CH_CTL_TIME_OUT_400us |
403 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
404 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
405 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT) |
407 DP_AUX_CH_CTL_TIME_OUT_ERROR |
408 DP_AUX_CH_CTL_RECEIVE_ERROR);
410 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
412 /* Clear done status and any errors */
416 DP_AUX_CH_CTL_TIME_OUT_ERROR |
417 DP_AUX_CH_CTL_RECEIVE_ERROR);
419 if (status & (DP_AUX_CH_CTL_TIME_OUT_ERROR |
420 DP_AUX_CH_CTL_RECEIVE_ERROR))
422 if (status & DP_AUX_CH_CTL_DONE)
425 if (status & DP_AUX_CH_CTL_DONE)
429 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
430 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
435 /* Check for timeout or receive error.
436 * Timeouts occur when the sink is not connected
438 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
439 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
444 /* Timeouts occur when the device isn't connected, so they're
445 * "normal" -- don't fill the kernel log with these */
446 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
447 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
452 /* Unload any bytes sent back from the other side */
453 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
454 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
455 if (recv_bytes > recv_size)
456 recv_bytes = recv_size;
458 for (i = 0; i < recv_bytes; i += 4)
459 unpack_aux(I915_READ(ch_data + i),
460 recv + i, recv_bytes - i);
464 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
465 intel_aux_display_runtime_put(dev_priv);
470 /* Write data to the aux channel in native mode */
472 intel_dp_aux_native_write(struct intel_dp *intel_dp,
473 uint16_t address, uint8_t *send, int send_bytes)
480 intel_dp_check_edp(intel_dp);
483 msg[0] = AUX_NATIVE_WRITE << 4;
484 msg[1] = address >> 8;
485 msg[2] = address & 0xff;
486 msg[3] = send_bytes - 1;
487 memcpy(&msg[4], send, send_bytes);
488 msg_bytes = send_bytes + 4;
490 ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes, &ack, 1);
493 if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK)
495 else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
503 /* Write a single byte to the aux channel in native mode */
505 intel_dp_aux_native_write_1(struct intel_dp *intel_dp,
506 uint16_t address, uint8_t byte)
508 return intel_dp_aux_native_write(intel_dp, address, &byte, 1);
511 /* read bytes from a native aux channel */
513 intel_dp_aux_native_read(struct intel_dp *intel_dp,
514 uint16_t address, uint8_t *recv, int recv_bytes)
523 intel_dp_check_edp(intel_dp);
524 msg[0] = AUX_NATIVE_READ << 4;
525 msg[1] = address >> 8;
526 msg[2] = address & 0xff;
527 msg[3] = recv_bytes - 1;
530 reply_bytes = recv_bytes + 1;
533 ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes,
540 if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK) {
541 memcpy(recv, reply + 1, ret - 1);
544 else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
552 intel_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode,
553 uint8_t write_byte, uint8_t *read_byte)
555 struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data;
556 struct intel_dp *intel_dp = container_of(adapter,
559 uint16_t address = algo_data->address;
567 intel_dp_check_edp(intel_dp);
568 /* Set up the command byte */
569 if (mode & MODE_I2C_READ)
570 msg[0] = AUX_I2C_READ << 4;
572 msg[0] = AUX_I2C_WRITE << 4;
574 if (!(mode & MODE_I2C_STOP))
575 msg[0] |= AUX_I2C_MOT << 4;
577 msg[1] = address >> 8;
598 for (retry = 0; retry < 5; retry++) {
599 ret = intel_dp_aux_ch(intel_dp,
603 DRM_DEBUG_KMS("aux_ch failed %d\n", ret);
607 switch (reply[0] & AUX_NATIVE_REPLY_MASK) {
608 case AUX_NATIVE_REPLY_ACK:
609 /* I2C-over-AUX Reply field is only valid
610 * when paired with AUX ACK.
613 case AUX_NATIVE_REPLY_NACK:
614 DRM_DEBUG_KMS("aux_ch native nack\n");
616 case AUX_NATIVE_REPLY_DEFER:
620 DRM_ERROR("aux_ch invalid native reply 0x%02x\n",
625 switch (reply[0] & AUX_I2C_REPLY_MASK) {
626 case AUX_I2C_REPLY_ACK:
627 if (mode == MODE_I2C_READ) {
628 *read_byte = reply[1];
630 return reply_bytes - 1;
631 case AUX_I2C_REPLY_NACK:
632 DRM_DEBUG_KMS("aux_i2c nack\n");
634 case AUX_I2C_REPLY_DEFER:
635 DRM_DEBUG_KMS("aux_i2c defer\n");
639 DRM_ERROR("aux_i2c invalid reply 0x%02x\n", reply[0]);
644 DRM_ERROR("too many retries, giving up\n");
649 intel_dp_i2c_init(struct intel_dp *intel_dp,
650 struct intel_connector *intel_connector, const char *name)
654 DRM_DEBUG_KMS("i2c_init %s\n", name);
655 intel_dp->algo.running = false;
656 intel_dp->algo.address = 0;
657 intel_dp->algo.aux_ch = intel_dp_i2c_aux_ch;
659 memset(&intel_dp->adapter, '\0', sizeof(intel_dp->adapter));
660 intel_dp->adapter.owner = THIS_MODULE;
661 intel_dp->adapter.class = I2C_CLASS_DDC;
662 strncpy(intel_dp->adapter.name, name, sizeof(intel_dp->adapter.name) - 1);
663 intel_dp->adapter.name[sizeof(intel_dp->adapter.name) - 1] = '\0';
664 intel_dp->adapter.algo_data = &intel_dp->algo;
665 intel_dp->adapter.dev.parent = &intel_connector->base.kdev;
667 ironlake_edp_panel_vdd_on(intel_dp);
668 ret = i2c_dp_aux_add_bus(&intel_dp->adapter);
669 ironlake_edp_panel_vdd_off(intel_dp, false);
674 intel_dp_set_clock(struct intel_encoder *encoder,
675 struct intel_crtc_config *pipe_config, int link_bw)
677 struct drm_device *dev = encoder->base.dev;
678 const struct dp_link_dpll *divisor = NULL;
683 count = ARRAY_SIZE(gen4_dpll);
684 } else if (IS_HASWELL(dev)) {
685 /* Haswell has special-purpose DP DDI clocks. */
686 } else if (HAS_PCH_SPLIT(dev)) {
688 count = ARRAY_SIZE(pch_dpll);
689 } else if (IS_VALLEYVIEW(dev)) {
691 count = ARRAY_SIZE(vlv_dpll);
694 if (divisor && count) {
695 for (i = 0; i < count; i++) {
696 if (link_bw == divisor[i].link_bw) {
697 pipe_config->dpll = divisor[i].dpll;
698 pipe_config->clock_set = true;
706 intel_dp_compute_config(struct intel_encoder *encoder,
707 struct intel_crtc_config *pipe_config)
709 struct drm_device *dev = encoder->base.dev;
710 struct drm_i915_private *dev_priv = dev->dev_private;
711 struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
712 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
713 enum port port = dp_to_dig_port(intel_dp)->port;
714 struct intel_crtc *intel_crtc = encoder->new_crtc;
715 struct intel_connector *intel_connector = intel_dp->attached_connector;
716 int lane_count, clock;
717 int max_lane_count = drm_dp_max_lane_count(intel_dp->dpcd);
718 int max_clock = intel_dp_max_link_bw(intel_dp) == DP_LINK_BW_2_7 ? 1 : 0;
720 static int bws[2] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7 };
721 int link_avail, link_clock;
723 if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev) && port != PORT_A)
724 pipe_config->has_pch_encoder = true;
726 pipe_config->has_dp_encoder = true;
728 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
729 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
731 if (!HAS_PCH_SPLIT(dev))
732 intel_gmch_panel_fitting(intel_crtc, pipe_config,
733 intel_connector->panel.fitting_mode);
735 intel_pch_panel_fitting(intel_crtc, pipe_config,
736 intel_connector->panel.fitting_mode);
739 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
742 DRM_DEBUG_KMS("DP link computation with max lane count %i "
743 "max bw %02x pixel clock %iKHz\n",
744 max_lane_count, bws[max_clock], adjusted_mode->clock);
746 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
748 bpp = pipe_config->pipe_bpp;
749 if (is_edp(intel_dp) && dev_priv->vbt.edp_bpp) {
750 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
751 dev_priv->vbt.edp_bpp);
752 bpp = min_t(int, bpp, dev_priv->vbt.edp_bpp);
755 for (; bpp >= 6*3; bpp -= 2*3) {
756 mode_rate = intel_dp_link_required(adjusted_mode->clock, bpp);
758 for (clock = 0; clock <= max_clock; clock++) {
759 for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) {
760 link_clock = drm_dp_bw_code_to_link_rate(bws[clock]);
761 link_avail = intel_dp_max_data_rate(link_clock,
764 if (mode_rate <= link_avail) {
774 if (intel_dp->color_range_auto) {
777 * CEA-861-E - 5.1 Default Encoding Parameters
778 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
780 if (bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1)
781 intel_dp->color_range = DP_COLOR_RANGE_16_235;
783 intel_dp->color_range = 0;
786 if (intel_dp->color_range)
787 pipe_config->limited_color_range = true;
789 intel_dp->link_bw = bws[clock];
790 intel_dp->lane_count = lane_count;
791 pipe_config->pipe_bpp = bpp;
792 pipe_config->port_clock = drm_dp_bw_code_to_link_rate(intel_dp->link_bw);
794 DRM_DEBUG_KMS("DP link bw %02x lane count %d clock %d bpp %d\n",
795 intel_dp->link_bw, intel_dp->lane_count,
796 pipe_config->port_clock, bpp);
797 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
798 mode_rate, link_avail);
800 intel_link_compute_m_n(bpp, lane_count,
801 adjusted_mode->clock, pipe_config->port_clock,
802 &pipe_config->dp_m_n);
804 intel_dp_set_clock(encoder, pipe_config, intel_dp->link_bw);
809 void intel_dp_init_link_config(struct intel_dp *intel_dp)
811 memset(intel_dp->link_configuration, 0, DP_LINK_CONFIGURATION_SIZE);
812 intel_dp->link_configuration[0] = intel_dp->link_bw;
813 intel_dp->link_configuration[1] = intel_dp->lane_count;
814 intel_dp->link_configuration[8] = DP_SET_ANSI_8B10B;
816 * Check for DPCD version > 1.1 and enhanced framing support
818 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
819 (intel_dp->dpcd[DP_MAX_LANE_COUNT] & DP_ENHANCED_FRAME_CAP)) {
820 intel_dp->link_configuration[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
824 static void ironlake_set_pll_cpu_edp(struct intel_dp *intel_dp)
826 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
827 struct intel_crtc *crtc = to_intel_crtc(dig_port->base.base.crtc);
828 struct drm_device *dev = crtc->base.dev;
829 struct drm_i915_private *dev_priv = dev->dev_private;
832 DRM_DEBUG_KMS("eDP PLL enable for clock %d\n", crtc->config.port_clock);
833 dpa_ctl = I915_READ(DP_A);
834 dpa_ctl &= ~DP_PLL_FREQ_MASK;
836 if (crtc->config.port_clock == 162000) {
837 /* For a long time we've carried around a ILK-DevA w/a for the
838 * 160MHz clock. If we're really unlucky, it's still required.
840 DRM_DEBUG_KMS("160MHz cpu eDP clock, might need ilk devA w/a\n");
841 dpa_ctl |= DP_PLL_FREQ_160MHZ;
842 intel_dp->DP |= DP_PLL_FREQ_160MHZ;
844 dpa_ctl |= DP_PLL_FREQ_270MHZ;
845 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
848 I915_WRITE(DP_A, dpa_ctl);
854 static void intel_dp_mode_set(struct intel_encoder *encoder)
856 struct drm_device *dev = encoder->base.dev;
857 struct drm_i915_private *dev_priv = dev->dev_private;
858 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
859 enum port port = dp_to_dig_port(intel_dp)->port;
860 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
861 struct drm_display_mode *adjusted_mode = &crtc->config.adjusted_mode;
864 * There are four kinds of DP registers:
871 * IBX PCH and CPU are the same for almost everything,
872 * except that the CPU DP PLL is configured in this
875 * CPT PCH is quite different, having many bits moved
876 * to the TRANS_DP_CTL register instead. That
877 * configuration happens (oddly) in ironlake_pch_enable
880 /* Preserve the BIOS-computed detected bit. This is
881 * supposed to be read-only.
883 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
885 /* Handle DP bits in common between all three register formats */
886 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
887 intel_dp->DP |= DP_PORT_WIDTH(intel_dp->lane_count);
889 if (intel_dp->has_audio) {
890 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
891 pipe_name(crtc->pipe));
892 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
893 intel_write_eld(&encoder->base, adjusted_mode);
896 intel_dp_init_link_config(intel_dp);
898 /* Split out the IBX/CPU vs CPT settings */
900 if (port == PORT_A && IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) {
901 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
902 intel_dp->DP |= DP_SYNC_HS_HIGH;
903 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
904 intel_dp->DP |= DP_SYNC_VS_HIGH;
905 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
907 if (intel_dp->link_configuration[1] & DP_LANE_COUNT_ENHANCED_FRAME_EN)
908 intel_dp->DP |= DP_ENHANCED_FRAMING;
910 intel_dp->DP |= crtc->pipe << 29;
911 } else if (!HAS_PCH_CPT(dev) || port == PORT_A) {
912 if (!HAS_PCH_SPLIT(dev) && !IS_VALLEYVIEW(dev))
913 intel_dp->DP |= intel_dp->color_range;
915 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
916 intel_dp->DP |= DP_SYNC_HS_HIGH;
917 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
918 intel_dp->DP |= DP_SYNC_VS_HIGH;
919 intel_dp->DP |= DP_LINK_TRAIN_OFF;
921 if (intel_dp->link_configuration[1] & DP_LANE_COUNT_ENHANCED_FRAME_EN)
922 intel_dp->DP |= DP_ENHANCED_FRAMING;
925 intel_dp->DP |= DP_PIPEB_SELECT;
927 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
930 if (port == PORT_A && !IS_VALLEYVIEW(dev))
931 ironlake_set_pll_cpu_edp(intel_dp);
934 #define IDLE_ON_MASK (PP_ON | 0 | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
935 #define IDLE_ON_VALUE (PP_ON | 0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
937 #define IDLE_OFF_MASK (PP_ON | 0 | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
938 #define IDLE_OFF_VALUE (0 | 0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
940 #define IDLE_CYCLE_MASK (PP_ON | 0 | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
941 #define IDLE_CYCLE_VALUE (0 | 0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
943 static void ironlake_wait_panel_status(struct intel_dp *intel_dp,
947 struct drm_device *dev = intel_dp_to_dev(intel_dp);
948 struct drm_i915_private *dev_priv = dev->dev_private;
949 u32 pp_stat_reg, pp_ctrl_reg;
951 pp_stat_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_STATUS : PCH_PP_STATUS;
952 pp_ctrl_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_CONTROL : PCH_PP_CONTROL;
954 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
956 I915_READ(pp_stat_reg),
957 I915_READ(pp_ctrl_reg));
959 if (_wait_for((I915_READ(pp_stat_reg) & mask) == value, 5000, 10)) {
960 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
961 I915_READ(pp_stat_reg),
962 I915_READ(pp_ctrl_reg));
966 static void ironlake_wait_panel_on(struct intel_dp *intel_dp)
968 DRM_DEBUG_KMS("Wait for panel power on\n");
969 ironlake_wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
972 static void ironlake_wait_panel_off(struct intel_dp *intel_dp)
974 DRM_DEBUG_KMS("Wait for panel power off time\n");
975 ironlake_wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
978 static void ironlake_wait_panel_power_cycle(struct intel_dp *intel_dp)
980 DRM_DEBUG_KMS("Wait for panel power cycle\n");
981 ironlake_wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
985 /* Read the current pp_control value, unlocking the register if it
989 static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
991 struct drm_device *dev = intel_dp_to_dev(intel_dp);
992 struct drm_i915_private *dev_priv = dev->dev_private;
996 pp_ctrl_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_CONTROL : PCH_PP_CONTROL;
997 control = I915_READ(pp_ctrl_reg);
999 control &= ~PANEL_UNLOCK_MASK;
1000 control |= PANEL_UNLOCK_REGS;
1004 void ironlake_edp_panel_vdd_on(struct intel_dp *intel_dp)
1006 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1007 struct drm_i915_private *dev_priv = dev->dev_private;
1009 u32 pp_stat_reg, pp_ctrl_reg;
1011 if (!is_edp(intel_dp))
1013 DRM_DEBUG_KMS("Turn eDP VDD on\n");
1015 WARN(intel_dp->want_panel_vdd,
1016 "eDP VDD already requested on\n");
1018 intel_dp->want_panel_vdd = true;
1020 if (ironlake_edp_have_panel_vdd(intel_dp)) {
1021 DRM_DEBUG_KMS("eDP VDD already on\n");
1025 if (!ironlake_edp_have_panel_power(intel_dp))
1026 ironlake_wait_panel_power_cycle(intel_dp);
1028 pp = ironlake_get_pp_control(intel_dp);
1029 pp |= EDP_FORCE_VDD;
1031 pp_stat_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_STATUS : PCH_PP_STATUS;
1032 pp_ctrl_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_CONTROL : PCH_PP_CONTROL;
1034 I915_WRITE(pp_ctrl_reg, pp);
1035 POSTING_READ(pp_ctrl_reg);
1036 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1037 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
1039 * If the panel wasn't on, delay before accessing aux channel
1041 if (!ironlake_edp_have_panel_power(intel_dp)) {
1042 DRM_DEBUG_KMS("eDP was not running\n");
1043 msleep(intel_dp->panel_power_up_delay);
1047 static void ironlake_panel_vdd_off_sync(struct intel_dp *intel_dp)
1049 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1050 struct drm_i915_private *dev_priv = dev->dev_private;
1052 u32 pp_stat_reg, pp_ctrl_reg;
1054 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
1056 if (!intel_dp->want_panel_vdd && ironlake_edp_have_panel_vdd(intel_dp)) {
1057 pp = ironlake_get_pp_control(intel_dp);
1058 pp &= ~EDP_FORCE_VDD;
1060 pp_stat_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_STATUS : PCH_PP_STATUS;
1061 pp_ctrl_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_CONTROL : PCH_PP_CONTROL;
1063 I915_WRITE(pp_ctrl_reg, pp);
1064 POSTING_READ(pp_ctrl_reg);
1066 /* Make sure sequencer is idle before allowing subsequent activity */
1067 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1068 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
1069 msleep(intel_dp->panel_power_down_delay);
1073 static void ironlake_panel_vdd_work(struct work_struct *__work)
1075 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
1076 struct intel_dp, panel_vdd_work);
1077 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1079 mutex_lock(&dev->mode_config.mutex);
1080 ironlake_panel_vdd_off_sync(intel_dp);
1081 mutex_unlock(&dev->mode_config.mutex);
1084 void ironlake_edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
1086 if (!is_edp(intel_dp))
1089 DRM_DEBUG_KMS("Turn eDP VDD off %d\n", intel_dp->want_panel_vdd);
1090 WARN(!intel_dp->want_panel_vdd, "eDP VDD not forced on");
1092 intel_dp->want_panel_vdd = false;
1095 ironlake_panel_vdd_off_sync(intel_dp);
1098 * Queue the timer to fire a long
1099 * time from now (relative to the power down delay)
1100 * to keep the panel power up across a sequence of operations
1102 schedule_delayed_work(&intel_dp->panel_vdd_work,
1103 msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5));
1107 void ironlake_edp_panel_on(struct intel_dp *intel_dp)
1109 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1110 struct drm_i915_private *dev_priv = dev->dev_private;
1114 if (!is_edp(intel_dp))
1117 DRM_DEBUG_KMS("Turn eDP power on\n");
1119 if (ironlake_edp_have_panel_power(intel_dp)) {
1120 DRM_DEBUG_KMS("eDP power already on\n");
1124 ironlake_wait_panel_power_cycle(intel_dp);
1126 pp = ironlake_get_pp_control(intel_dp);
1128 /* ILK workaround: disable reset around power sequence */
1129 pp &= ~PANEL_POWER_RESET;
1130 I915_WRITE(PCH_PP_CONTROL, pp);
1131 POSTING_READ(PCH_PP_CONTROL);
1134 pp |= POWER_TARGET_ON;
1136 pp |= PANEL_POWER_RESET;
1138 pp_ctrl_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_CONTROL : PCH_PP_CONTROL;
1140 I915_WRITE(pp_ctrl_reg, pp);
1141 POSTING_READ(pp_ctrl_reg);
1143 ironlake_wait_panel_on(intel_dp);
1146 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
1147 I915_WRITE(PCH_PP_CONTROL, pp);
1148 POSTING_READ(PCH_PP_CONTROL);
1152 void ironlake_edp_panel_off(struct intel_dp *intel_dp)
1154 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1155 struct drm_i915_private *dev_priv = dev->dev_private;
1159 if (!is_edp(intel_dp))
1162 DRM_DEBUG_KMS("Turn eDP power off\n");
1164 WARN(!intel_dp->want_panel_vdd, "Need VDD to turn off panel\n");
1166 pp = ironlake_get_pp_control(intel_dp);
1167 /* We need to switch off panel power _and_ force vdd, for otherwise some
1168 * panels get very unhappy and cease to work. */
1169 pp &= ~(POWER_TARGET_ON | EDP_FORCE_VDD | PANEL_POWER_RESET | EDP_BLC_ENABLE);
1171 pp_ctrl_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_CONTROL : PCH_PP_CONTROL;
1173 I915_WRITE(pp_ctrl_reg, pp);
1174 POSTING_READ(pp_ctrl_reg);
1176 intel_dp->want_panel_vdd = false;
1178 ironlake_wait_panel_off(intel_dp);
1181 void ironlake_edp_backlight_on(struct intel_dp *intel_dp)
1183 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1184 struct drm_device *dev = intel_dig_port->base.base.dev;
1185 struct drm_i915_private *dev_priv = dev->dev_private;
1186 int pipe = to_intel_crtc(intel_dig_port->base.base.crtc)->pipe;
1190 if (!is_edp(intel_dp))
1193 DRM_DEBUG_KMS("\n");
1195 * If we enable the backlight right away following a panel power
1196 * on, we may see slight flicker as the panel syncs with the eDP
1197 * link. So delay a bit to make sure the image is solid before
1198 * allowing it to appear.
1200 msleep(intel_dp->backlight_on_delay);
1201 pp = ironlake_get_pp_control(intel_dp);
1202 pp |= EDP_BLC_ENABLE;
1204 pp_ctrl_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_CONTROL : PCH_PP_CONTROL;
1206 I915_WRITE(pp_ctrl_reg, pp);
1207 POSTING_READ(pp_ctrl_reg);
1209 intel_panel_enable_backlight(dev, pipe);
1212 void ironlake_edp_backlight_off(struct intel_dp *intel_dp)
1214 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1215 struct drm_i915_private *dev_priv = dev->dev_private;
1219 if (!is_edp(intel_dp))
1222 intel_panel_disable_backlight(dev);
1224 DRM_DEBUG_KMS("\n");
1225 pp = ironlake_get_pp_control(intel_dp);
1226 pp &= ~EDP_BLC_ENABLE;
1228 pp_ctrl_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_CONTROL : PCH_PP_CONTROL;
1230 I915_WRITE(pp_ctrl_reg, pp);
1231 POSTING_READ(pp_ctrl_reg);
1232 msleep(intel_dp->backlight_off_delay);
1235 static void ironlake_edp_pll_on(struct intel_dp *intel_dp)
1237 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1238 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
1239 struct drm_device *dev = crtc->dev;
1240 struct drm_i915_private *dev_priv = dev->dev_private;
1243 assert_pipe_disabled(dev_priv,
1244 to_intel_crtc(crtc)->pipe);
1246 DRM_DEBUG_KMS("\n");
1247 dpa_ctl = I915_READ(DP_A);
1248 WARN(dpa_ctl & DP_PLL_ENABLE, "dp pll on, should be off\n");
1249 WARN(dpa_ctl & DP_PORT_EN, "dp port still on, should be off\n");
1251 /* We don't adjust intel_dp->DP while tearing down the link, to
1252 * facilitate link retraining (e.g. after hotplug). Hence clear all
1253 * enable bits here to ensure that we don't enable too much. */
1254 intel_dp->DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
1255 intel_dp->DP |= DP_PLL_ENABLE;
1256 I915_WRITE(DP_A, intel_dp->DP);
1261 static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
1263 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1264 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
1265 struct drm_device *dev = crtc->dev;
1266 struct drm_i915_private *dev_priv = dev->dev_private;
1269 assert_pipe_disabled(dev_priv,
1270 to_intel_crtc(crtc)->pipe);
1272 dpa_ctl = I915_READ(DP_A);
1273 WARN((dpa_ctl & DP_PLL_ENABLE) == 0,
1274 "dp pll off, should be on\n");
1275 WARN(dpa_ctl & DP_PORT_EN, "dp port still on, should be off\n");
1277 /* We can't rely on the value tracked for the DP register in
1278 * intel_dp->DP because link_down must not change that (otherwise link
1279 * re-training will fail. */
1280 dpa_ctl &= ~DP_PLL_ENABLE;
1281 I915_WRITE(DP_A, dpa_ctl);
1286 /* If the sink supports it, try to set the power state appropriately */
1287 void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
1291 /* Should have a valid DPCD by this point */
1292 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
1295 if (mode != DRM_MODE_DPMS_ON) {
1296 ret = intel_dp_aux_native_write_1(intel_dp, DP_SET_POWER,
1299 DRM_DEBUG_DRIVER("failed to write sink power state\n");
1302 * When turning on, we need to retry for 1ms to give the sink
1305 for (i = 0; i < 3; i++) {
1306 ret = intel_dp_aux_native_write_1(intel_dp,
1316 static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
1319 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1320 enum port port = dp_to_dig_port(intel_dp)->port;
1321 struct drm_device *dev = encoder->base.dev;
1322 struct drm_i915_private *dev_priv = dev->dev_private;
1323 u32 tmp = I915_READ(intel_dp->output_reg);
1325 if (!(tmp & DP_PORT_EN))
1328 if (port == PORT_A && IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) {
1329 *pipe = PORT_TO_PIPE_CPT(tmp);
1330 } else if (!HAS_PCH_CPT(dev) || port == PORT_A) {
1331 *pipe = PORT_TO_PIPE(tmp);
1337 switch (intel_dp->output_reg) {
1339 trans_sel = TRANS_DP_PORT_SEL_B;
1342 trans_sel = TRANS_DP_PORT_SEL_C;
1345 trans_sel = TRANS_DP_PORT_SEL_D;
1352 trans_dp = I915_READ(TRANS_DP_CTL(i));
1353 if ((trans_dp & TRANS_DP_PORT_SEL_MASK) == trans_sel) {
1359 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
1360 intel_dp->output_reg);
1366 static void intel_dp_get_config(struct intel_encoder *encoder,
1367 struct intel_crtc_config *pipe_config)
1369 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1371 struct drm_device *dev = encoder->base.dev;
1372 struct drm_i915_private *dev_priv = dev->dev_private;
1373 enum port port = dp_to_dig_port(intel_dp)->port;
1374 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
1376 if ((port == PORT_A) || !HAS_PCH_CPT(dev)) {
1377 tmp = I915_READ(intel_dp->output_reg);
1378 if (tmp & DP_SYNC_HS_HIGH)
1379 flags |= DRM_MODE_FLAG_PHSYNC;
1381 flags |= DRM_MODE_FLAG_NHSYNC;
1383 if (tmp & DP_SYNC_VS_HIGH)
1384 flags |= DRM_MODE_FLAG_PVSYNC;
1386 flags |= DRM_MODE_FLAG_NVSYNC;
1388 tmp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1389 if (tmp & TRANS_DP_HSYNC_ACTIVE_HIGH)
1390 flags |= DRM_MODE_FLAG_PHSYNC;
1392 flags |= DRM_MODE_FLAG_NHSYNC;
1394 if (tmp & TRANS_DP_VSYNC_ACTIVE_HIGH)
1395 flags |= DRM_MODE_FLAG_PVSYNC;
1397 flags |= DRM_MODE_FLAG_NVSYNC;
1400 pipe_config->adjusted_mode.flags |= flags;
1402 if (dp_to_dig_port(intel_dp)->port == PORT_A) {
1403 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_160MHZ)
1404 pipe_config->port_clock = 162000;
1406 pipe_config->port_clock = 270000;
1410 static bool is_edp_psr(struct intel_dp *intel_dp)
1412 return is_edp(intel_dp) &&
1413 intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED;
1416 static bool intel_edp_is_psr_enabled(struct drm_device *dev)
1418 struct drm_i915_private *dev_priv = dev->dev_private;
1420 if (!IS_HASWELL(dev))
1423 return I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
1426 static void intel_edp_psr_write_vsc(struct intel_dp *intel_dp,
1427 struct edp_vsc_psr *vsc_psr)
1429 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1430 struct drm_device *dev = dig_port->base.base.dev;
1431 struct drm_i915_private *dev_priv = dev->dev_private;
1432 struct intel_crtc *crtc = to_intel_crtc(dig_port->base.base.crtc);
1433 u32 ctl_reg = HSW_TVIDEO_DIP_CTL(crtc->config.cpu_transcoder);
1434 u32 data_reg = HSW_TVIDEO_DIP_VSC_DATA(crtc->config.cpu_transcoder);
1435 uint32_t *data = (uint32_t *) vsc_psr;
1438 /* As per BSPec (Pipe Video Data Island Packet), we need to disable
1439 the video DIP being updated before program video DIP data buffer
1440 registers for DIP being updated. */
1441 I915_WRITE(ctl_reg, 0);
1442 POSTING_READ(ctl_reg);
1444 for (i = 0; i < VIDEO_DIP_VSC_DATA_SIZE; i += 4) {
1445 if (i < sizeof(struct edp_vsc_psr))
1446 I915_WRITE(data_reg + i, *data++);
1448 I915_WRITE(data_reg + i, 0);
1451 I915_WRITE(ctl_reg, VIDEO_DIP_ENABLE_VSC_HSW);
1452 POSTING_READ(ctl_reg);
1455 static void intel_edp_psr_setup(struct intel_dp *intel_dp)
1457 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1458 struct drm_i915_private *dev_priv = dev->dev_private;
1459 struct edp_vsc_psr psr_vsc;
1461 if (intel_dp->psr_setup_done)
1464 /* Prepare VSC packet as per EDP 1.3 spec, Table 3.10 */
1465 memset(&psr_vsc, 0, sizeof(psr_vsc));
1466 psr_vsc.sdp_header.HB0 = 0;
1467 psr_vsc.sdp_header.HB1 = 0x7;
1468 psr_vsc.sdp_header.HB2 = 0x2;
1469 psr_vsc.sdp_header.HB3 = 0x8;
1470 intel_edp_psr_write_vsc(intel_dp, &psr_vsc);
1472 /* Avoid continuous PSR exit by masking memup and hpd */
1473 I915_WRITE(EDP_PSR_DEBUG_CTL, EDP_PSR_DEBUG_MASK_MEMUP |
1474 EDP_PSR_DEBUG_MASK_HPD);
1476 intel_dp->psr_setup_done = true;
1479 static void intel_edp_psr_enable_sink(struct intel_dp *intel_dp)
1481 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1482 struct drm_i915_private *dev_priv = dev->dev_private;
1483 uint32_t aux_clock_divider = get_aux_clock_divider(intel_dp, 0);
1484 int precharge = 0x3;
1485 int msg_size = 5; /* Header(4) + Message(1) */
1487 /* Enable PSR in sink */
1488 if (intel_dp->psr_dpcd[1] & DP_PSR_NO_TRAIN_ON_EXIT)
1489 intel_dp_aux_native_write_1(intel_dp, DP_PSR_EN_CFG,
1491 ~DP_PSR_MAIN_LINK_ACTIVE);
1493 intel_dp_aux_native_write_1(intel_dp, DP_PSR_EN_CFG,
1495 DP_PSR_MAIN_LINK_ACTIVE);
1497 /* Setup AUX registers */
1498 I915_WRITE(EDP_PSR_AUX_DATA1, EDP_PSR_DPCD_COMMAND);
1499 I915_WRITE(EDP_PSR_AUX_DATA2, EDP_PSR_DPCD_NORMAL_OPERATION);
1500 I915_WRITE(EDP_PSR_AUX_CTL,
1501 DP_AUX_CH_CTL_TIME_OUT_400us |
1502 (msg_size << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
1503 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
1504 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT));
1507 static void intel_edp_psr_enable_source(struct intel_dp *intel_dp)
1509 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1510 struct drm_i915_private *dev_priv = dev->dev_private;
1511 uint32_t max_sleep_time = 0x1f;
1512 uint32_t idle_frames = 1;
1515 if (intel_dp->psr_dpcd[1] & DP_PSR_NO_TRAIN_ON_EXIT) {
1516 val |= EDP_PSR_LINK_STANDBY;
1517 val |= EDP_PSR_TP2_TP3_TIME_0us;
1518 val |= EDP_PSR_TP1_TIME_0us;
1519 val |= EDP_PSR_SKIP_AUX_EXIT;
1521 val |= EDP_PSR_LINK_DISABLE;
1523 I915_WRITE(EDP_PSR_CTL, val |
1524 EDP_PSR_MIN_LINK_ENTRY_TIME_8_LINES |
1525 max_sleep_time << EDP_PSR_MAX_SLEEP_TIME_SHIFT |
1526 idle_frames << EDP_PSR_IDLE_FRAME_SHIFT |
1530 static bool intel_edp_psr_match_conditions(struct intel_dp *intel_dp)
1532 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1533 struct drm_device *dev = dig_port->base.base.dev;
1534 struct drm_i915_private *dev_priv = dev->dev_private;
1535 struct drm_crtc *crtc = dig_port->base.base.crtc;
1536 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1537 struct drm_i915_gem_object *obj = to_intel_framebuffer(crtc->fb)->obj;
1538 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
1540 if (!IS_HASWELL(dev)) {
1541 DRM_DEBUG_KMS("PSR not supported on this platform\n");
1542 dev_priv->no_psr_reason = PSR_NO_SOURCE;
1546 if ((intel_encoder->type != INTEL_OUTPUT_EDP) ||
1547 (dig_port->port != PORT_A)) {
1548 DRM_DEBUG_KMS("HSW ties PSR to DDI A (eDP)\n");
1549 dev_priv->no_psr_reason = PSR_HSW_NOT_DDIA;
1553 if (!is_edp_psr(intel_dp)) {
1554 DRM_DEBUG_KMS("PSR not supported by this panel\n");
1555 dev_priv->no_psr_reason = PSR_NO_SINK;
1559 if (!i915_enable_psr) {
1560 DRM_DEBUG_KMS("PSR disable by flag\n");
1561 dev_priv->no_psr_reason = PSR_MODULE_PARAM;
1565 crtc = dig_port->base.base.crtc;
1567 DRM_DEBUG_KMS("crtc not active for PSR\n");
1568 dev_priv->no_psr_reason = PSR_CRTC_NOT_ACTIVE;
1572 intel_crtc = to_intel_crtc(crtc);
1573 if (!intel_crtc->active || !crtc->fb || !crtc->mode.clock) {
1574 DRM_DEBUG_KMS("crtc not active for PSR\n");
1575 dev_priv->no_psr_reason = PSR_CRTC_NOT_ACTIVE;
1579 obj = to_intel_framebuffer(crtc->fb)->obj;
1580 if (obj->tiling_mode != I915_TILING_X ||
1581 obj->fence_reg == I915_FENCE_REG_NONE) {
1582 DRM_DEBUG_KMS("PSR condition failed: fb not tiled or fenced\n");
1583 dev_priv->no_psr_reason = PSR_NOT_TILED;
1587 if (I915_READ(SPRCTL(intel_crtc->pipe)) & SPRITE_ENABLE) {
1588 DRM_DEBUG_KMS("PSR condition failed: Sprite is Enabled\n");
1589 dev_priv->no_psr_reason = PSR_SPRITE_ENABLED;
1593 if (I915_READ(HSW_STEREO_3D_CTL(intel_crtc->config.cpu_transcoder)) &
1595 DRM_DEBUG_KMS("PSR condition failed: Stereo 3D is Enabled\n");
1596 dev_priv->no_psr_reason = PSR_S3D_ENABLED;
1600 if (crtc->mode.flags & DRM_MODE_FLAG_INTERLACE) {
1601 DRM_DEBUG_KMS("PSR condition failed: Interlaced is Enabled\n");
1602 dev_priv->no_psr_reason = PSR_INTERLACED_ENABLED;
1609 static void intel_edp_psr_do_enable(struct intel_dp *intel_dp)
1611 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1613 if (!intel_edp_psr_match_conditions(intel_dp) ||
1614 intel_edp_is_psr_enabled(dev))
1617 /* Setup PSR once */
1618 intel_edp_psr_setup(intel_dp);
1620 /* Enable PSR on the panel */
1621 intel_edp_psr_enable_sink(intel_dp);
1623 /* Enable PSR on the host */
1624 intel_edp_psr_enable_source(intel_dp);
1627 void intel_edp_psr_enable(struct intel_dp *intel_dp)
1629 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1631 if (intel_edp_psr_match_conditions(intel_dp) &&
1632 !intel_edp_is_psr_enabled(dev))
1633 intel_edp_psr_do_enable(intel_dp);
1636 void intel_edp_psr_disable(struct intel_dp *intel_dp)
1638 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1639 struct drm_i915_private *dev_priv = dev->dev_private;
1641 if (!intel_edp_is_psr_enabled(dev))
1644 I915_WRITE(EDP_PSR_CTL, I915_READ(EDP_PSR_CTL) & ~EDP_PSR_ENABLE);
1646 /* Wait till PSR is idle */
1647 if (_wait_for((I915_READ(EDP_PSR_STATUS_CTL) &
1648 EDP_PSR_STATUS_STATE_MASK) == 0, 2000, 10))
1649 DRM_ERROR("Timed out waiting for PSR Idle State\n");
1652 void intel_edp_psr_update(struct drm_device *dev)
1654 struct intel_encoder *encoder;
1655 struct intel_dp *intel_dp = NULL;
1657 list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head)
1658 if (encoder->type == INTEL_OUTPUT_EDP) {
1659 intel_dp = enc_to_intel_dp(&encoder->base);
1661 if (!is_edp_psr(intel_dp))
1664 if (!intel_edp_psr_match_conditions(intel_dp))
1665 intel_edp_psr_disable(intel_dp);
1667 if (!intel_edp_is_psr_enabled(dev))
1668 intel_edp_psr_do_enable(intel_dp);
1672 static void intel_disable_dp(struct intel_encoder *encoder)
1674 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1675 enum port port = dp_to_dig_port(intel_dp)->port;
1676 struct drm_device *dev = encoder->base.dev;
1678 /* Make sure the panel is off before trying to change the mode. But also
1679 * ensure that we have vdd while we switch off the panel. */
1680 ironlake_edp_panel_vdd_on(intel_dp);
1681 ironlake_edp_backlight_off(intel_dp);
1682 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1683 ironlake_edp_panel_off(intel_dp);
1685 /* cpu edp my only be disable _after_ the cpu pipe/plane is disabled. */
1686 if (!(port == PORT_A || IS_VALLEYVIEW(dev)))
1687 intel_dp_link_down(intel_dp);
1690 static void intel_post_disable_dp(struct intel_encoder *encoder)
1692 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1693 enum port port = dp_to_dig_port(intel_dp)->port;
1694 struct drm_device *dev = encoder->base.dev;
1696 if (port == PORT_A || IS_VALLEYVIEW(dev)) {
1697 intel_dp_link_down(intel_dp);
1698 if (!IS_VALLEYVIEW(dev))
1699 ironlake_edp_pll_off(intel_dp);
1703 static void intel_enable_dp(struct intel_encoder *encoder)
1705 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1706 struct drm_device *dev = encoder->base.dev;
1707 struct drm_i915_private *dev_priv = dev->dev_private;
1708 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
1710 if (WARN_ON(dp_reg & DP_PORT_EN))
1713 ironlake_edp_panel_vdd_on(intel_dp);
1714 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1715 intel_dp_start_link_train(intel_dp);
1716 ironlake_edp_panel_on(intel_dp);
1717 ironlake_edp_panel_vdd_off(intel_dp, true);
1718 intel_dp_complete_link_train(intel_dp);
1719 intel_dp_stop_link_train(intel_dp);
1720 ironlake_edp_backlight_on(intel_dp);
1723 static void g4x_enable_dp(struct intel_encoder *encoder)
1725 intel_enable_dp(encoder);
1728 static void vlv_enable_dp(struct intel_encoder *encoder)
1732 static void g4x_pre_enable_dp(struct intel_encoder *encoder)
1734 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1735 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
1737 if (dport->port == PORT_A)
1738 ironlake_edp_pll_on(intel_dp);
1741 static void vlv_pre_enable_dp(struct intel_encoder *encoder)
1743 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1744 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
1745 struct drm_device *dev = encoder->base.dev;
1746 struct drm_i915_private *dev_priv = dev->dev_private;
1747 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
1748 int port = vlv_dport_to_channel(dport);
1749 int pipe = intel_crtc->pipe;
1752 mutex_lock(&dev_priv->dpio_lock);
1754 val = vlv_dpio_read(dev_priv, pipe, DPIO_DATA_LANE_A(port));
1761 vlv_dpio_write(dev_priv, pipe, DPIO_DATA_CHANNEL(port), val);
1762 vlv_dpio_write(dev_priv, pipe, DPIO_PCS_CLOCKBUF0(port), 0x00760018);
1763 vlv_dpio_write(dev_priv, pipe, DPIO_PCS_CLOCKBUF8(port), 0x00400888);
1765 mutex_unlock(&dev_priv->dpio_lock);
1767 intel_enable_dp(encoder);
1769 vlv_wait_port_ready(dev_priv, port);
1772 static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder)
1774 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1775 struct drm_device *dev = encoder->base.dev;
1776 struct drm_i915_private *dev_priv = dev->dev_private;
1777 struct intel_crtc *intel_crtc =
1778 to_intel_crtc(encoder->base.crtc);
1779 int port = vlv_dport_to_channel(dport);
1780 int pipe = intel_crtc->pipe;
1782 /* Program Tx lane resets to default */
1783 mutex_lock(&dev_priv->dpio_lock);
1784 vlv_dpio_write(dev_priv, pipe, DPIO_PCS_TX(port),
1785 DPIO_PCS_TX_LANE2_RESET |
1786 DPIO_PCS_TX_LANE1_RESET);
1787 vlv_dpio_write(dev_priv, pipe, DPIO_PCS_CLK(port),
1788 DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
1789 DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
1790 (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
1791 DPIO_PCS_CLK_SOFT_RESET);
1793 /* Fix up inter-pair skew failure */
1794 vlv_dpio_write(dev_priv, pipe, DPIO_PCS_STAGGER1(port), 0x00750f00);
1795 vlv_dpio_write(dev_priv, pipe, DPIO_TX_CTL(port), 0x00001500);
1796 vlv_dpio_write(dev_priv, pipe, DPIO_TX_LANE(port), 0x40400000);
1797 mutex_unlock(&dev_priv->dpio_lock);
1801 * Native read with retry for link status and receiver capability reads for
1802 * cases where the sink may still be asleep.
1805 intel_dp_aux_native_read_retry(struct intel_dp *intel_dp, uint16_t address,
1806 uint8_t *recv, int recv_bytes)
1811 * Sinks are *supposed* to come up within 1ms from an off state,
1812 * but we're also supposed to retry 3 times per the spec.
1814 for (i = 0; i < 3; i++) {
1815 ret = intel_dp_aux_native_read(intel_dp, address, recv,
1817 if (ret == recv_bytes)
1826 * Fetch AUX CH registers 0x202 - 0x207 which contain
1827 * link status information
1830 intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
1832 return intel_dp_aux_native_read_retry(intel_dp,
1835 DP_LINK_STATUS_SIZE);
1839 static char *voltage_names[] = {
1840 "0.4V", "0.6V", "0.8V", "1.2V"
1842 static char *pre_emph_names[] = {
1843 "0dB", "3.5dB", "6dB", "9.5dB"
1845 static char *link_train_names[] = {
1846 "pattern 1", "pattern 2", "idle", "off"
1851 * These are source-specific values; current Intel hardware supports
1852 * a maximum voltage of 800mV and a maximum pre-emphasis of 6dB
1856 intel_dp_voltage_max(struct intel_dp *intel_dp)
1858 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1859 enum port port = dp_to_dig_port(intel_dp)->port;
1861 if (IS_VALLEYVIEW(dev))
1862 return DP_TRAIN_VOLTAGE_SWING_1200;
1863 else if (IS_GEN7(dev) && port == PORT_A)
1864 return DP_TRAIN_VOLTAGE_SWING_800;
1865 else if (HAS_PCH_CPT(dev) && port != PORT_A)
1866 return DP_TRAIN_VOLTAGE_SWING_1200;
1868 return DP_TRAIN_VOLTAGE_SWING_800;
1872 intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
1874 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1875 enum port port = dp_to_dig_port(intel_dp)->port;
1878 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
1879 case DP_TRAIN_VOLTAGE_SWING_400:
1880 return DP_TRAIN_PRE_EMPHASIS_9_5;
1881 case DP_TRAIN_VOLTAGE_SWING_600:
1882 return DP_TRAIN_PRE_EMPHASIS_6;
1883 case DP_TRAIN_VOLTAGE_SWING_800:
1884 return DP_TRAIN_PRE_EMPHASIS_3_5;
1885 case DP_TRAIN_VOLTAGE_SWING_1200:
1887 return DP_TRAIN_PRE_EMPHASIS_0;
1889 } else if (IS_VALLEYVIEW(dev)) {
1890 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
1891 case DP_TRAIN_VOLTAGE_SWING_400:
1892 return DP_TRAIN_PRE_EMPHASIS_9_5;
1893 case DP_TRAIN_VOLTAGE_SWING_600:
1894 return DP_TRAIN_PRE_EMPHASIS_6;
1895 case DP_TRAIN_VOLTAGE_SWING_800:
1896 return DP_TRAIN_PRE_EMPHASIS_3_5;
1897 case DP_TRAIN_VOLTAGE_SWING_1200:
1899 return DP_TRAIN_PRE_EMPHASIS_0;
1901 } else if (IS_GEN7(dev) && port == PORT_A) {
1902 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
1903 case DP_TRAIN_VOLTAGE_SWING_400:
1904 return DP_TRAIN_PRE_EMPHASIS_6;
1905 case DP_TRAIN_VOLTAGE_SWING_600:
1906 case DP_TRAIN_VOLTAGE_SWING_800:
1907 return DP_TRAIN_PRE_EMPHASIS_3_5;
1909 return DP_TRAIN_PRE_EMPHASIS_0;
1912 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
1913 case DP_TRAIN_VOLTAGE_SWING_400:
1914 return DP_TRAIN_PRE_EMPHASIS_6;
1915 case DP_TRAIN_VOLTAGE_SWING_600:
1916 return DP_TRAIN_PRE_EMPHASIS_6;
1917 case DP_TRAIN_VOLTAGE_SWING_800:
1918 return DP_TRAIN_PRE_EMPHASIS_3_5;
1919 case DP_TRAIN_VOLTAGE_SWING_1200:
1921 return DP_TRAIN_PRE_EMPHASIS_0;
1926 static uint32_t intel_vlv_signal_levels(struct intel_dp *intel_dp)
1928 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1929 struct drm_i915_private *dev_priv = dev->dev_private;
1930 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
1931 struct intel_crtc *intel_crtc =
1932 to_intel_crtc(dport->base.base.crtc);
1933 unsigned long demph_reg_value, preemph_reg_value,
1934 uniqtranscale_reg_value;
1935 uint8_t train_set = intel_dp->train_set[0];
1936 int port = vlv_dport_to_channel(dport);
1937 int pipe = intel_crtc->pipe;
1939 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
1940 case DP_TRAIN_PRE_EMPHASIS_0:
1941 preemph_reg_value = 0x0004000;
1942 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
1943 case DP_TRAIN_VOLTAGE_SWING_400:
1944 demph_reg_value = 0x2B405555;
1945 uniqtranscale_reg_value = 0x552AB83A;
1947 case DP_TRAIN_VOLTAGE_SWING_600:
1948 demph_reg_value = 0x2B404040;
1949 uniqtranscale_reg_value = 0x5548B83A;
1951 case DP_TRAIN_VOLTAGE_SWING_800:
1952 demph_reg_value = 0x2B245555;
1953 uniqtranscale_reg_value = 0x5560B83A;
1955 case DP_TRAIN_VOLTAGE_SWING_1200:
1956 demph_reg_value = 0x2B405555;
1957 uniqtranscale_reg_value = 0x5598DA3A;
1963 case DP_TRAIN_PRE_EMPHASIS_3_5:
1964 preemph_reg_value = 0x0002000;
1965 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
1966 case DP_TRAIN_VOLTAGE_SWING_400:
1967 demph_reg_value = 0x2B404040;
1968 uniqtranscale_reg_value = 0x5552B83A;
1970 case DP_TRAIN_VOLTAGE_SWING_600:
1971 demph_reg_value = 0x2B404848;
1972 uniqtranscale_reg_value = 0x5580B83A;
1974 case DP_TRAIN_VOLTAGE_SWING_800:
1975 demph_reg_value = 0x2B404040;
1976 uniqtranscale_reg_value = 0x55ADDA3A;
1982 case DP_TRAIN_PRE_EMPHASIS_6:
1983 preemph_reg_value = 0x0000000;
1984 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
1985 case DP_TRAIN_VOLTAGE_SWING_400:
1986 demph_reg_value = 0x2B305555;
1987 uniqtranscale_reg_value = 0x5570B83A;
1989 case DP_TRAIN_VOLTAGE_SWING_600:
1990 demph_reg_value = 0x2B2B4040;
1991 uniqtranscale_reg_value = 0x55ADDA3A;
1997 case DP_TRAIN_PRE_EMPHASIS_9_5:
1998 preemph_reg_value = 0x0006000;
1999 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
2000 case DP_TRAIN_VOLTAGE_SWING_400:
2001 demph_reg_value = 0x1B405555;
2002 uniqtranscale_reg_value = 0x55ADDA3A;
2012 mutex_lock(&dev_priv->dpio_lock);
2013 vlv_dpio_write(dev_priv, pipe, DPIO_TX_OCALINIT(port), 0x00000000);
2014 vlv_dpio_write(dev_priv, pipe, DPIO_TX_SWING_CTL4(port), demph_reg_value);
2015 vlv_dpio_write(dev_priv, pipe, DPIO_TX_SWING_CTL2(port),
2016 uniqtranscale_reg_value);
2017 vlv_dpio_write(dev_priv, pipe, DPIO_TX_SWING_CTL3(port), 0x0C782040);
2018 vlv_dpio_write(dev_priv, pipe, DPIO_PCS_STAGGER0(port), 0x00030000);
2019 vlv_dpio_write(dev_priv, pipe, DPIO_PCS_CTL_OVER1(port), preemph_reg_value);
2020 vlv_dpio_write(dev_priv, pipe, DPIO_TX_OCALINIT(port), 0x80000000);
2021 mutex_unlock(&dev_priv->dpio_lock);
2027 intel_get_adjust_train(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
2032 uint8_t voltage_max;
2033 uint8_t preemph_max;
2035 for (lane = 0; lane < intel_dp->lane_count; lane++) {
2036 uint8_t this_v = drm_dp_get_adjust_request_voltage(link_status, lane);
2037 uint8_t this_p = drm_dp_get_adjust_request_pre_emphasis(link_status, lane);
2045 voltage_max = intel_dp_voltage_max(intel_dp);
2046 if (v >= voltage_max)
2047 v = voltage_max | DP_TRAIN_MAX_SWING_REACHED;
2049 preemph_max = intel_dp_pre_emphasis_max(intel_dp, v);
2050 if (p >= preemph_max)
2051 p = preemph_max | DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
2053 for (lane = 0; lane < 4; lane++)
2054 intel_dp->train_set[lane] = v | p;
2058 intel_gen4_signal_levels(uint8_t train_set)
2060 uint32_t signal_levels = 0;
2062 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
2063 case DP_TRAIN_VOLTAGE_SWING_400:
2065 signal_levels |= DP_VOLTAGE_0_4;
2067 case DP_TRAIN_VOLTAGE_SWING_600:
2068 signal_levels |= DP_VOLTAGE_0_6;
2070 case DP_TRAIN_VOLTAGE_SWING_800:
2071 signal_levels |= DP_VOLTAGE_0_8;
2073 case DP_TRAIN_VOLTAGE_SWING_1200:
2074 signal_levels |= DP_VOLTAGE_1_2;
2077 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
2078 case DP_TRAIN_PRE_EMPHASIS_0:
2080 signal_levels |= DP_PRE_EMPHASIS_0;
2082 case DP_TRAIN_PRE_EMPHASIS_3_5:
2083 signal_levels |= DP_PRE_EMPHASIS_3_5;
2085 case DP_TRAIN_PRE_EMPHASIS_6:
2086 signal_levels |= DP_PRE_EMPHASIS_6;
2088 case DP_TRAIN_PRE_EMPHASIS_9_5:
2089 signal_levels |= DP_PRE_EMPHASIS_9_5;
2092 return signal_levels;
2095 /* Gen6's DP voltage swing and pre-emphasis control */
2097 intel_gen6_edp_signal_levels(uint8_t train_set)
2099 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
2100 DP_TRAIN_PRE_EMPHASIS_MASK);
2101 switch (signal_levels) {
2102 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
2103 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
2104 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
2105 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
2106 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
2107 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
2108 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
2109 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
2110 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
2111 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
2112 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
2113 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
2114 case DP_TRAIN_VOLTAGE_SWING_1200 | DP_TRAIN_PRE_EMPHASIS_0:
2115 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
2117 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
2118 "0x%x\n", signal_levels);
2119 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
2123 /* Gen7's DP voltage swing and pre-emphasis control */
2125 intel_gen7_edp_signal_levels(uint8_t train_set)
2127 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
2128 DP_TRAIN_PRE_EMPHASIS_MASK);
2129 switch (signal_levels) {
2130 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
2131 return EDP_LINK_TRAIN_400MV_0DB_IVB;
2132 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
2133 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
2134 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
2135 return EDP_LINK_TRAIN_400MV_6DB_IVB;
2137 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
2138 return EDP_LINK_TRAIN_600MV_0DB_IVB;
2139 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
2140 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
2142 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
2143 return EDP_LINK_TRAIN_800MV_0DB_IVB;
2144 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
2145 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
2148 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
2149 "0x%x\n", signal_levels);
2150 return EDP_LINK_TRAIN_500MV_0DB_IVB;
2154 /* Gen7.5's (HSW) DP voltage swing and pre-emphasis control */
2156 intel_hsw_signal_levels(uint8_t train_set)
2158 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
2159 DP_TRAIN_PRE_EMPHASIS_MASK);
2160 switch (signal_levels) {
2161 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
2162 return DDI_BUF_EMP_400MV_0DB_HSW;
2163 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
2164 return DDI_BUF_EMP_400MV_3_5DB_HSW;
2165 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
2166 return DDI_BUF_EMP_400MV_6DB_HSW;
2167 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_9_5:
2168 return DDI_BUF_EMP_400MV_9_5DB_HSW;
2170 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
2171 return DDI_BUF_EMP_600MV_0DB_HSW;
2172 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
2173 return DDI_BUF_EMP_600MV_3_5DB_HSW;
2174 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
2175 return DDI_BUF_EMP_600MV_6DB_HSW;
2177 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
2178 return DDI_BUF_EMP_800MV_0DB_HSW;
2179 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
2180 return DDI_BUF_EMP_800MV_3_5DB_HSW;
2182 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
2183 "0x%x\n", signal_levels);
2184 return DDI_BUF_EMP_400MV_0DB_HSW;
2188 /* Properly updates "DP" with the correct signal levels. */
2190 intel_dp_set_signal_levels(struct intel_dp *intel_dp, uint32_t *DP)
2192 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2193 enum port port = intel_dig_port->port;
2194 struct drm_device *dev = intel_dig_port->base.base.dev;
2195 uint32_t signal_levels, mask;
2196 uint8_t train_set = intel_dp->train_set[0];
2199 signal_levels = intel_hsw_signal_levels(train_set);
2200 mask = DDI_BUF_EMP_MASK;
2201 } else if (IS_VALLEYVIEW(dev)) {
2202 signal_levels = intel_vlv_signal_levels(intel_dp);
2204 } else if (IS_GEN7(dev) && port == PORT_A) {
2205 signal_levels = intel_gen7_edp_signal_levels(train_set);
2206 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
2207 } else if (IS_GEN6(dev) && port == PORT_A) {
2208 signal_levels = intel_gen6_edp_signal_levels(train_set);
2209 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
2211 signal_levels = intel_gen4_signal_levels(train_set);
2212 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
2215 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
2217 *DP = (*DP & ~mask) | signal_levels;
2221 intel_dp_set_link_train(struct intel_dp *intel_dp,
2222 uint32_t dp_reg_value,
2223 uint8_t dp_train_pat)
2225 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2226 struct drm_device *dev = intel_dig_port->base.base.dev;
2227 struct drm_i915_private *dev_priv = dev->dev_private;
2228 enum port port = intel_dig_port->port;
2232 uint32_t temp = I915_READ(DP_TP_CTL(port));
2234 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2235 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2237 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2239 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2240 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2241 case DP_TRAINING_PATTERN_DISABLE:
2242 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2245 case DP_TRAINING_PATTERN_1:
2246 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2248 case DP_TRAINING_PATTERN_2:
2249 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2251 case DP_TRAINING_PATTERN_3:
2252 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2255 I915_WRITE(DP_TP_CTL(port), temp);
2257 } else if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || port != PORT_A)) {
2258 dp_reg_value &= ~DP_LINK_TRAIN_MASK_CPT;
2260 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2261 case DP_TRAINING_PATTERN_DISABLE:
2262 dp_reg_value |= DP_LINK_TRAIN_OFF_CPT;
2264 case DP_TRAINING_PATTERN_1:
2265 dp_reg_value |= DP_LINK_TRAIN_PAT_1_CPT;
2267 case DP_TRAINING_PATTERN_2:
2268 dp_reg_value |= DP_LINK_TRAIN_PAT_2_CPT;
2270 case DP_TRAINING_PATTERN_3:
2271 DRM_ERROR("DP training pattern 3 not supported\n");
2272 dp_reg_value |= DP_LINK_TRAIN_PAT_2_CPT;
2277 dp_reg_value &= ~DP_LINK_TRAIN_MASK;
2279 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2280 case DP_TRAINING_PATTERN_DISABLE:
2281 dp_reg_value |= DP_LINK_TRAIN_OFF;
2283 case DP_TRAINING_PATTERN_1:
2284 dp_reg_value |= DP_LINK_TRAIN_PAT_1;
2286 case DP_TRAINING_PATTERN_2:
2287 dp_reg_value |= DP_LINK_TRAIN_PAT_2;
2289 case DP_TRAINING_PATTERN_3:
2290 DRM_ERROR("DP training pattern 3 not supported\n");
2291 dp_reg_value |= DP_LINK_TRAIN_PAT_2;
2296 I915_WRITE(intel_dp->output_reg, dp_reg_value);
2297 POSTING_READ(intel_dp->output_reg);
2299 intel_dp_aux_native_write_1(intel_dp,
2300 DP_TRAINING_PATTERN_SET,
2303 if ((dp_train_pat & DP_TRAINING_PATTERN_MASK) !=
2304 DP_TRAINING_PATTERN_DISABLE) {
2305 ret = intel_dp_aux_native_write(intel_dp,
2306 DP_TRAINING_LANE0_SET,
2307 intel_dp->train_set,
2308 intel_dp->lane_count);
2309 if (ret != intel_dp->lane_count)
2316 static void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
2318 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2319 struct drm_device *dev = intel_dig_port->base.base.dev;
2320 struct drm_i915_private *dev_priv = dev->dev_private;
2321 enum port port = intel_dig_port->port;
2327 val = I915_READ(DP_TP_CTL(port));
2328 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2329 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
2330 I915_WRITE(DP_TP_CTL(port), val);
2333 * On PORT_A we can have only eDP in SST mode. There the only reason
2334 * we need to set idle transmission mode is to work around a HW issue
2335 * where we enable the pipe while not in idle link-training mode.
2336 * In this case there is requirement to wait for a minimum number of
2337 * idle patterns to be sent.
2342 if (wait_for((I915_READ(DP_TP_STATUS(port)) & DP_TP_STATUS_IDLE_DONE),
2344 DRM_ERROR("Timed out waiting for DP idle patterns\n");
2347 /* Enable corresponding port and start training pattern 1 */
2349 intel_dp_start_link_train(struct intel_dp *intel_dp)
2351 struct drm_encoder *encoder = &dp_to_dig_port(intel_dp)->base.base;
2352 struct drm_device *dev = encoder->dev;
2355 int voltage_tries, loop_tries;
2356 uint32_t DP = intel_dp->DP;
2359 intel_ddi_prepare_link_retrain(encoder);
2361 /* Write the link configuration data */
2362 intel_dp_aux_native_write(intel_dp, DP_LINK_BW_SET,
2363 intel_dp->link_configuration,
2364 DP_LINK_CONFIGURATION_SIZE);
2368 memset(intel_dp->train_set, 0, 4);
2373 /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */
2374 uint8_t link_status[DP_LINK_STATUS_SIZE];
2376 intel_dp_set_signal_levels(intel_dp, &DP);
2378 /* Set training pattern 1 */
2379 if (!intel_dp_set_link_train(intel_dp, DP,
2380 DP_TRAINING_PATTERN_1 |
2381 DP_LINK_SCRAMBLING_DISABLE))
2384 drm_dp_link_train_clock_recovery_delay(intel_dp->dpcd);
2385 if (!intel_dp_get_link_status(intel_dp, link_status)) {
2386 DRM_ERROR("failed to get link status\n");
2390 if (drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
2391 DRM_DEBUG_KMS("clock recovery OK\n");
2395 /* Check to see if we've tried the max voltage */
2396 for (i = 0; i < intel_dp->lane_count; i++)
2397 if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
2399 if (i == intel_dp->lane_count) {
2401 if (loop_tries == 5) {
2402 DRM_DEBUG_KMS("too many full retries, give up\n");
2405 memset(intel_dp->train_set, 0, 4);
2410 /* Check to see if we've tried the same voltage 5 times */
2411 if ((intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) == voltage) {
2413 if (voltage_tries == 5) {
2414 DRM_DEBUG_KMS("too many voltage retries, give up\n");
2419 voltage = intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
2421 /* Compute new intel_dp->train_set as requested by target */
2422 intel_get_adjust_train(intel_dp, link_status);
2429 intel_dp_complete_link_train(struct intel_dp *intel_dp)
2431 bool channel_eq = false;
2432 int tries, cr_tries;
2433 uint32_t DP = intel_dp->DP;
2435 /* channel equalization */
2440 uint8_t link_status[DP_LINK_STATUS_SIZE];
2443 DRM_ERROR("failed to train DP, aborting\n");
2444 intel_dp_link_down(intel_dp);
2448 intel_dp_set_signal_levels(intel_dp, &DP);
2450 /* channel eq pattern */
2451 if (!intel_dp_set_link_train(intel_dp, DP,
2452 DP_TRAINING_PATTERN_2 |
2453 DP_LINK_SCRAMBLING_DISABLE))
2456 drm_dp_link_train_channel_eq_delay(intel_dp->dpcd);
2457 if (!intel_dp_get_link_status(intel_dp, link_status))
2460 /* Make sure clock is still ok */
2461 if (!drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
2462 intel_dp_start_link_train(intel_dp);
2467 if (drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
2472 /* Try 5 times, then try clock recovery if that fails */
2474 intel_dp_link_down(intel_dp);
2475 intel_dp_start_link_train(intel_dp);
2481 /* Compute new intel_dp->train_set as requested by target */
2482 intel_get_adjust_train(intel_dp, link_status);
2486 intel_dp_set_idle_link_train(intel_dp);
2491 DRM_DEBUG_KMS("Channel EQ done. DP Training successful\n");
2495 void intel_dp_stop_link_train(struct intel_dp *intel_dp)
2497 intel_dp_set_link_train(intel_dp, intel_dp->DP,
2498 DP_TRAINING_PATTERN_DISABLE);
2502 intel_dp_link_down(struct intel_dp *intel_dp)
2504 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2505 enum port port = intel_dig_port->port;
2506 struct drm_device *dev = intel_dig_port->base.base.dev;
2507 struct drm_i915_private *dev_priv = dev->dev_private;
2508 struct intel_crtc *intel_crtc =
2509 to_intel_crtc(intel_dig_port->base.base.crtc);
2510 uint32_t DP = intel_dp->DP;
2513 * DDI code has a strict mode set sequence and we should try to respect
2514 * it, otherwise we might hang the machine in many different ways. So we
2515 * really should be disabling the port only on a complete crtc_disable
2516 * sequence. This function is just called under two conditions on DDI
2518 * - Link train failed while doing crtc_enable, and on this case we
2519 * really should respect the mode set sequence and wait for a
2521 * - Someone turned the monitor off and intel_dp_check_link_status
2522 * called us. We don't need to disable the whole port on this case, so
2523 * when someone turns the monitor on again,
2524 * intel_ddi_prepare_link_retrain will take care of redoing the link
2530 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
2533 DRM_DEBUG_KMS("\n");
2535 if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || port != PORT_A)) {
2536 DP &= ~DP_LINK_TRAIN_MASK_CPT;
2537 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT);
2539 DP &= ~DP_LINK_TRAIN_MASK;
2540 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE);
2542 POSTING_READ(intel_dp->output_reg);
2544 /* We don't really know why we're doing this */
2545 intel_wait_for_vblank(dev, intel_crtc->pipe);
2547 if (HAS_PCH_IBX(dev) &&
2548 I915_READ(intel_dp->output_reg) & DP_PIPEB_SELECT) {
2549 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
2551 /* Hardware workaround: leaving our transcoder select
2552 * set to transcoder B while it's off will prevent the
2553 * corresponding HDMI output on transcoder A.
2555 * Combine this with another hardware workaround:
2556 * transcoder select bit can only be cleared while the
2559 DP &= ~DP_PIPEB_SELECT;
2560 I915_WRITE(intel_dp->output_reg, DP);
2562 /* Changes to enable or select take place the vblank
2563 * after being written.
2565 if (WARN_ON(crtc == NULL)) {
2566 /* We should never try to disable a port without a crtc
2567 * attached. For paranoia keep the code around for a
2569 POSTING_READ(intel_dp->output_reg);
2572 intel_wait_for_vblank(dev, intel_crtc->pipe);
2575 DP &= ~DP_AUDIO_OUTPUT_ENABLE;
2576 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
2577 POSTING_READ(intel_dp->output_reg);
2578 msleep(intel_dp->panel_power_down_delay);
2582 intel_dp_get_dpcd(struct intel_dp *intel_dp)
2584 char dpcd_hex_dump[sizeof(intel_dp->dpcd) * 3];
2586 if (intel_dp_aux_native_read_retry(intel_dp, 0x000, intel_dp->dpcd,
2587 sizeof(intel_dp->dpcd)) == 0)
2588 return false; /* aux transfer failed */
2590 hex_dump_to_buffer(intel_dp->dpcd, sizeof(intel_dp->dpcd),
2591 32, 1, dpcd_hex_dump, sizeof(dpcd_hex_dump), false);
2592 DRM_DEBUG_KMS("DPCD: %s\n", dpcd_hex_dump);
2594 if (intel_dp->dpcd[DP_DPCD_REV] == 0)
2595 return false; /* DPCD not present */
2597 /* Check if the panel supports PSR */
2598 memset(intel_dp->psr_dpcd, 0, sizeof(intel_dp->psr_dpcd));
2599 intel_dp_aux_native_read_retry(intel_dp, DP_PSR_SUPPORT,
2601 sizeof(intel_dp->psr_dpcd));
2602 if (is_edp_psr(intel_dp))
2603 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
2604 if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
2605 DP_DWN_STRM_PORT_PRESENT))
2606 return true; /* native DP sink */
2608 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
2609 return true; /* no per-port downstream info */
2611 if (intel_dp_aux_native_read_retry(intel_dp, DP_DOWNSTREAM_PORT_0,
2612 intel_dp->downstream_ports,
2613 DP_MAX_DOWNSTREAM_PORTS) == 0)
2614 return false; /* downstream port status fetch failed */
2620 intel_dp_probe_oui(struct intel_dp *intel_dp)
2624 if (!(intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] & DP_OUI_SUPPORT))
2627 ironlake_edp_panel_vdd_on(intel_dp);
2629 if (intel_dp_aux_native_read_retry(intel_dp, DP_SINK_OUI, buf, 3))
2630 DRM_DEBUG_KMS("Sink OUI: %02hx%02hx%02hx\n",
2631 buf[0], buf[1], buf[2]);
2633 if (intel_dp_aux_native_read_retry(intel_dp, DP_BRANCH_OUI, buf, 3))
2634 DRM_DEBUG_KMS("Branch OUI: %02hx%02hx%02hx\n",
2635 buf[0], buf[1], buf[2]);
2637 ironlake_edp_panel_vdd_off(intel_dp, false);
2641 intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
2645 ret = intel_dp_aux_native_read_retry(intel_dp,
2646 DP_DEVICE_SERVICE_IRQ_VECTOR,
2647 sink_irq_vector, 1);
2655 intel_dp_handle_test_request(struct intel_dp *intel_dp)
2657 /* NAK by default */
2658 intel_dp_aux_native_write_1(intel_dp, DP_TEST_RESPONSE, DP_TEST_NAK);
2662 * According to DP spec
2665 * 2. Configure link according to Receiver Capabilities
2666 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
2667 * 4. Check link status on receipt of hot-plug interrupt
2671 intel_dp_check_link_status(struct intel_dp *intel_dp)
2673 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
2675 u8 link_status[DP_LINK_STATUS_SIZE];
2677 if (!intel_encoder->connectors_active)
2680 if (WARN_ON(!intel_encoder->base.crtc))
2683 /* Try to read receiver status if the link appears to be up */
2684 if (!intel_dp_get_link_status(intel_dp, link_status)) {
2685 intel_dp_link_down(intel_dp);
2689 /* Now read the DPCD to see if it's actually running */
2690 if (!intel_dp_get_dpcd(intel_dp)) {
2691 intel_dp_link_down(intel_dp);
2695 /* Try to read the source of the interrupt */
2696 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
2697 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector)) {
2698 /* Clear interrupt source */
2699 intel_dp_aux_native_write_1(intel_dp,
2700 DP_DEVICE_SERVICE_IRQ_VECTOR,
2703 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
2704 intel_dp_handle_test_request(intel_dp);
2705 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
2706 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
2709 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
2710 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
2711 drm_get_encoder_name(&intel_encoder->base));
2712 intel_dp_start_link_train(intel_dp);
2713 intel_dp_complete_link_train(intel_dp);
2714 intel_dp_stop_link_train(intel_dp);
2718 /* XXX this is probably wrong for multiple downstream ports */
2719 static enum drm_connector_status
2720 intel_dp_detect_dpcd(struct intel_dp *intel_dp)
2722 uint8_t *dpcd = intel_dp->dpcd;
2726 if (!intel_dp_get_dpcd(intel_dp))
2727 return connector_status_disconnected;
2729 /* if there's no downstream port, we're done */
2730 if (!(dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT))
2731 return connector_status_connected;
2733 /* If we're HPD-aware, SINK_COUNT changes dynamically */
2734 hpd = !!(intel_dp->downstream_ports[0] & DP_DS_PORT_HPD);
2737 if (!intel_dp_aux_native_read_retry(intel_dp, DP_SINK_COUNT,
2739 return connector_status_unknown;
2740 return DP_GET_SINK_COUNT(reg) ? connector_status_connected
2741 : connector_status_disconnected;
2744 /* If no HPD, poke DDC gently */
2745 if (drm_probe_ddc(&intel_dp->adapter))
2746 return connector_status_connected;
2748 /* Well we tried, say unknown for unreliable port types */
2749 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
2750 if (type == DP_DS_PORT_TYPE_VGA || type == DP_DS_PORT_TYPE_NON_EDID)
2751 return connector_status_unknown;
2753 /* Anything else is out of spec, warn and ignore */
2754 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
2755 return connector_status_disconnected;
2758 static enum drm_connector_status
2759 ironlake_dp_detect(struct intel_dp *intel_dp)
2761 struct drm_device *dev = intel_dp_to_dev(intel_dp);
2762 struct drm_i915_private *dev_priv = dev->dev_private;
2763 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2764 enum drm_connector_status status;
2766 /* Can't disconnect eDP, but you can close the lid... */
2767 if (is_edp(intel_dp)) {
2768 status = intel_panel_detect(dev);
2769 if (status == connector_status_unknown)
2770 status = connector_status_connected;
2774 if (!ibx_digital_port_connected(dev_priv, intel_dig_port))
2775 return connector_status_disconnected;
2777 return intel_dp_detect_dpcd(intel_dp);
2780 static enum drm_connector_status
2781 g4x_dp_detect(struct intel_dp *intel_dp)
2783 struct drm_device *dev = intel_dp_to_dev(intel_dp);
2784 struct drm_i915_private *dev_priv = dev->dev_private;
2785 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2788 /* Can't disconnect eDP, but you can close the lid... */
2789 if (is_edp(intel_dp)) {
2790 enum drm_connector_status status;
2792 status = intel_panel_detect(dev);
2793 if (status == connector_status_unknown)
2794 status = connector_status_connected;
2798 switch (intel_dig_port->port) {
2800 bit = PORTB_HOTPLUG_LIVE_STATUS;
2803 bit = PORTC_HOTPLUG_LIVE_STATUS;
2806 bit = PORTD_HOTPLUG_LIVE_STATUS;
2809 return connector_status_unknown;
2812 if ((I915_READ(PORT_HOTPLUG_STAT) & bit) == 0)
2813 return connector_status_disconnected;
2815 return intel_dp_detect_dpcd(intel_dp);
2818 static struct edid *
2819 intel_dp_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
2821 struct intel_connector *intel_connector = to_intel_connector(connector);
2823 /* use cached edid if we have one */
2824 if (intel_connector->edid) {
2829 if (IS_ERR(intel_connector->edid))
2832 size = (intel_connector->edid->extensions + 1) * EDID_LENGTH;
2833 edid = kmemdup(intel_connector->edid, size, GFP_KERNEL);
2840 return drm_get_edid(connector, adapter);
2844 intel_dp_get_edid_modes(struct drm_connector *connector, struct i2c_adapter *adapter)
2846 struct intel_connector *intel_connector = to_intel_connector(connector);
2848 /* use cached edid if we have one */
2849 if (intel_connector->edid) {
2851 if (IS_ERR(intel_connector->edid))
2854 return intel_connector_update_modes(connector,
2855 intel_connector->edid);
2858 return intel_ddc_get_modes(connector, adapter);
2861 static enum drm_connector_status
2862 intel_dp_detect(struct drm_connector *connector, bool force)
2864 struct intel_dp *intel_dp = intel_attached_dp(connector);
2865 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2866 struct intel_encoder *intel_encoder = &intel_dig_port->base;
2867 struct drm_device *dev = connector->dev;
2868 enum drm_connector_status status;
2869 struct edid *edid = NULL;
2871 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2872 connector->base.id, drm_get_connector_name(connector));
2874 intel_dp->has_audio = false;
2876 if (HAS_PCH_SPLIT(dev))
2877 status = ironlake_dp_detect(intel_dp);
2879 status = g4x_dp_detect(intel_dp);
2881 if (status != connector_status_connected)
2884 intel_dp_probe_oui(intel_dp);
2886 if (intel_dp->force_audio != HDMI_AUDIO_AUTO) {
2887 intel_dp->has_audio = (intel_dp->force_audio == HDMI_AUDIO_ON);
2889 edid = intel_dp_get_edid(connector, &intel_dp->adapter);
2891 intel_dp->has_audio = drm_detect_monitor_audio(edid);
2896 if (intel_encoder->type != INTEL_OUTPUT_EDP)
2897 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
2898 return connector_status_connected;
2901 static int intel_dp_get_modes(struct drm_connector *connector)
2903 struct intel_dp *intel_dp = intel_attached_dp(connector);
2904 struct intel_connector *intel_connector = to_intel_connector(connector);
2905 struct drm_device *dev = connector->dev;
2908 /* We should parse the EDID data and find out if it has an audio sink
2911 ret = intel_dp_get_edid_modes(connector, &intel_dp->adapter);
2915 /* if eDP has no EDID, fall back to fixed mode */
2916 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
2917 struct drm_display_mode *mode;
2918 mode = drm_mode_duplicate(dev,
2919 intel_connector->panel.fixed_mode);
2921 drm_mode_probed_add(connector, mode);
2929 intel_dp_detect_audio(struct drm_connector *connector)
2931 struct intel_dp *intel_dp = intel_attached_dp(connector);
2933 bool has_audio = false;
2935 edid = intel_dp_get_edid(connector, &intel_dp->adapter);
2937 has_audio = drm_detect_monitor_audio(edid);
2945 intel_dp_set_property(struct drm_connector *connector,
2946 struct drm_property *property,
2949 struct drm_i915_private *dev_priv = connector->dev->dev_private;
2950 struct intel_connector *intel_connector = to_intel_connector(connector);
2951 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
2952 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2955 ret = drm_object_property_set_value(&connector->base, property, val);
2959 if (property == dev_priv->force_audio_property) {
2963 if (i == intel_dp->force_audio)
2966 intel_dp->force_audio = i;
2968 if (i == HDMI_AUDIO_AUTO)
2969 has_audio = intel_dp_detect_audio(connector);
2971 has_audio = (i == HDMI_AUDIO_ON);
2973 if (has_audio == intel_dp->has_audio)
2976 intel_dp->has_audio = has_audio;
2980 if (property == dev_priv->broadcast_rgb_property) {
2981 bool old_auto = intel_dp->color_range_auto;
2982 uint32_t old_range = intel_dp->color_range;
2985 case INTEL_BROADCAST_RGB_AUTO:
2986 intel_dp->color_range_auto = true;
2988 case INTEL_BROADCAST_RGB_FULL:
2989 intel_dp->color_range_auto = false;
2990 intel_dp->color_range = 0;
2992 case INTEL_BROADCAST_RGB_LIMITED:
2993 intel_dp->color_range_auto = false;
2994 intel_dp->color_range = DP_COLOR_RANGE_16_235;
3000 if (old_auto == intel_dp->color_range_auto &&
3001 old_range == intel_dp->color_range)
3007 if (is_edp(intel_dp) &&
3008 property == connector->dev->mode_config.scaling_mode_property) {
3009 if (val == DRM_MODE_SCALE_NONE) {
3010 DRM_DEBUG_KMS("no scaling not supported\n");
3014 if (intel_connector->panel.fitting_mode == val) {
3015 /* the eDP scaling property is not changed */
3018 intel_connector->panel.fitting_mode = val;
3026 if (intel_encoder->base.crtc)
3027 intel_crtc_restore_mode(intel_encoder->base.crtc);
3033 intel_dp_connector_destroy(struct drm_connector *connector)
3035 struct intel_connector *intel_connector = to_intel_connector(connector);
3037 if (!IS_ERR_OR_NULL(intel_connector->edid))
3038 kfree(intel_connector->edid);
3040 /* Can't call is_edp() since the encoder may have been destroyed
3042 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
3043 intel_panel_fini(&intel_connector->panel);
3045 drm_sysfs_connector_remove(connector);
3046 drm_connector_cleanup(connector);
3050 void intel_dp_encoder_destroy(struct drm_encoder *encoder)
3052 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
3053 struct intel_dp *intel_dp = &intel_dig_port->dp;
3054 struct drm_device *dev = intel_dp_to_dev(intel_dp);
3056 i2c_del_adapter(&intel_dp->adapter);
3057 drm_encoder_cleanup(encoder);
3058 if (is_edp(intel_dp)) {
3059 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
3060 mutex_lock(&dev->mode_config.mutex);
3061 ironlake_panel_vdd_off_sync(intel_dp);
3062 mutex_unlock(&dev->mode_config.mutex);
3064 kfree(intel_dig_port);
3067 static const struct drm_connector_funcs intel_dp_connector_funcs = {
3068 .dpms = intel_connector_dpms,
3069 .detect = intel_dp_detect,
3070 .fill_modes = drm_helper_probe_single_connector_modes,
3071 .set_property = intel_dp_set_property,
3072 .destroy = intel_dp_connector_destroy,
3075 static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
3076 .get_modes = intel_dp_get_modes,
3077 .mode_valid = intel_dp_mode_valid,
3078 .best_encoder = intel_best_encoder,
3081 static const struct drm_encoder_funcs intel_dp_enc_funcs = {
3082 .destroy = intel_dp_encoder_destroy,
3086 intel_dp_hot_plug(struct intel_encoder *intel_encoder)
3088 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
3090 intel_dp_check_link_status(intel_dp);
3093 /* Return which DP Port should be selected for Transcoder DP control */
3095 intel_trans_dp_port_sel(struct drm_crtc *crtc)
3097 struct drm_device *dev = crtc->dev;
3098 struct intel_encoder *intel_encoder;
3099 struct intel_dp *intel_dp;
3101 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
3102 intel_dp = enc_to_intel_dp(&intel_encoder->base);
3104 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
3105 intel_encoder->type == INTEL_OUTPUT_EDP)
3106 return intel_dp->output_reg;
3112 /* check the VBT to see whether the eDP is on DP-D port */
3113 bool intel_dpd_is_edp(struct drm_device *dev)
3115 struct drm_i915_private *dev_priv = dev->dev_private;
3116 struct child_device_config *p_child;
3119 if (!dev_priv->vbt.child_dev_num)
3122 for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
3123 p_child = dev_priv->vbt.child_dev + i;
3125 if (p_child->dvo_port == PORT_IDPD &&
3126 p_child->device_type == DEVICE_TYPE_eDP)
3133 intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
3135 struct intel_connector *intel_connector = to_intel_connector(connector);
3137 intel_attach_force_audio_property(connector);
3138 intel_attach_broadcast_rgb_property(connector);
3139 intel_dp->color_range_auto = true;
3141 if (is_edp(intel_dp)) {
3142 drm_mode_create_scaling_mode_property(connector->dev);
3143 drm_object_attach_property(
3145 connector->dev->mode_config.scaling_mode_property,
3146 DRM_MODE_SCALE_ASPECT);
3147 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
3152 intel_dp_init_panel_power_sequencer(struct drm_device *dev,
3153 struct intel_dp *intel_dp,
3154 struct edp_power_seq *out)
3156 struct drm_i915_private *dev_priv = dev->dev_private;
3157 struct edp_power_seq cur, vbt, spec, final;
3158 u32 pp_on, pp_off, pp_div, pp;
3159 int pp_control_reg, pp_on_reg, pp_off_reg, pp_div_reg;
3161 if (HAS_PCH_SPLIT(dev)) {
3162 pp_control_reg = PCH_PP_CONTROL;
3163 pp_on_reg = PCH_PP_ON_DELAYS;
3164 pp_off_reg = PCH_PP_OFF_DELAYS;
3165 pp_div_reg = PCH_PP_DIVISOR;
3167 pp_control_reg = PIPEA_PP_CONTROL;
3168 pp_on_reg = PIPEA_PP_ON_DELAYS;
3169 pp_off_reg = PIPEA_PP_OFF_DELAYS;
3170 pp_div_reg = PIPEA_PP_DIVISOR;
3173 /* Workaround: Need to write PP_CONTROL with the unlock key as
3174 * the very first thing. */
3175 pp = ironlake_get_pp_control(intel_dp);
3176 I915_WRITE(pp_control_reg, pp);
3178 pp_on = I915_READ(pp_on_reg);
3179 pp_off = I915_READ(pp_off_reg);
3180 pp_div = I915_READ(pp_div_reg);
3182 /* Pull timing values out of registers */
3183 cur.t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
3184 PANEL_POWER_UP_DELAY_SHIFT;
3186 cur.t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
3187 PANEL_LIGHT_ON_DELAY_SHIFT;
3189 cur.t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
3190 PANEL_LIGHT_OFF_DELAY_SHIFT;
3192 cur.t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
3193 PANEL_POWER_DOWN_DELAY_SHIFT;
3195 cur.t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
3196 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
3198 DRM_DEBUG_KMS("cur t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
3199 cur.t1_t3, cur.t8, cur.t9, cur.t10, cur.t11_t12);
3201 vbt = dev_priv->vbt.edp_pps;
3203 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
3204 * our hw here, which are all in 100usec. */
3205 spec.t1_t3 = 210 * 10;
3206 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
3207 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
3208 spec.t10 = 500 * 10;
3209 /* This one is special and actually in units of 100ms, but zero
3210 * based in the hw (so we need to add 100 ms). But the sw vbt
3211 * table multiplies it with 1000 to make it in units of 100usec,
3213 spec.t11_t12 = (510 + 100) * 10;
3215 DRM_DEBUG_KMS("vbt t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
3216 vbt.t1_t3, vbt.t8, vbt.t9, vbt.t10, vbt.t11_t12);
3218 /* Use the max of the register settings and vbt. If both are
3219 * unset, fall back to the spec limits. */
3220 #define assign_final(field) final.field = (max(cur.field, vbt.field) == 0 ? \
3222 max(cur.field, vbt.field))
3223 assign_final(t1_t3);
3227 assign_final(t11_t12);
3230 #define get_delay(field) (DIV_ROUND_UP(final.field, 10))
3231 intel_dp->panel_power_up_delay = get_delay(t1_t3);
3232 intel_dp->backlight_on_delay = get_delay(t8);
3233 intel_dp->backlight_off_delay = get_delay(t9);
3234 intel_dp->panel_power_down_delay = get_delay(t10);
3235 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
3238 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
3239 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
3240 intel_dp->panel_power_cycle_delay);
3242 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
3243 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
3250 intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
3251 struct intel_dp *intel_dp,
3252 struct edp_power_seq *seq)
3254 struct drm_i915_private *dev_priv = dev->dev_private;
3255 u32 pp_on, pp_off, pp_div, port_sel = 0;
3256 int div = HAS_PCH_SPLIT(dev) ? intel_pch_rawclk(dev) : intel_hrawclk(dev);
3257 int pp_on_reg, pp_off_reg, pp_div_reg;
3259 if (HAS_PCH_SPLIT(dev)) {
3260 pp_on_reg = PCH_PP_ON_DELAYS;
3261 pp_off_reg = PCH_PP_OFF_DELAYS;
3262 pp_div_reg = PCH_PP_DIVISOR;
3264 pp_on_reg = PIPEA_PP_ON_DELAYS;
3265 pp_off_reg = PIPEA_PP_OFF_DELAYS;
3266 pp_div_reg = PIPEA_PP_DIVISOR;
3269 /* And finally store the new values in the power sequencer. */
3270 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
3271 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
3272 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
3273 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
3274 /* Compute the divisor for the pp clock, simply match the Bspec
3276 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
3277 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
3278 << PANEL_POWER_CYCLE_DELAY_SHIFT);
3280 /* Haswell doesn't have any port selection bits for the panel
3281 * power sequencer any more. */
3282 if (IS_VALLEYVIEW(dev)) {
3283 port_sel = I915_READ(pp_on_reg) & 0xc0000000;
3284 } else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) {
3285 if (dp_to_dig_port(intel_dp)->port == PORT_A)
3286 port_sel = PANEL_POWER_PORT_DP_A;
3288 port_sel = PANEL_POWER_PORT_DP_D;
3293 I915_WRITE(pp_on_reg, pp_on);
3294 I915_WRITE(pp_off_reg, pp_off);
3295 I915_WRITE(pp_div_reg, pp_div);
3297 DRM_DEBUG_KMS("panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n",
3298 I915_READ(pp_on_reg),
3299 I915_READ(pp_off_reg),
3300 I915_READ(pp_div_reg));
3303 static bool intel_edp_init_connector(struct intel_dp *intel_dp,
3304 struct intel_connector *intel_connector)
3306 struct drm_connector *connector = &intel_connector->base;
3307 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3308 struct drm_device *dev = intel_dig_port->base.base.dev;
3309 struct drm_i915_private *dev_priv = dev->dev_private;
3310 struct drm_display_mode *fixed_mode = NULL;
3311 struct edp_power_seq power_seq = { 0 };
3313 struct drm_display_mode *scan;
3316 if (!is_edp(intel_dp))
3319 intel_dp_init_panel_power_sequencer(dev, intel_dp, &power_seq);
3321 /* Cache DPCD and EDID for edp. */
3322 ironlake_edp_panel_vdd_on(intel_dp);
3323 has_dpcd = intel_dp_get_dpcd(intel_dp);
3324 ironlake_edp_panel_vdd_off(intel_dp, false);
3327 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3328 dev_priv->no_aux_handshake =
3329 intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3330 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3332 /* if this fails, presume the device is a ghost */
3333 DRM_INFO("failed to retrieve link info, disabling eDP\n");
3337 /* We now know it's not a ghost, init power sequence regs. */
3338 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp,
3341 ironlake_edp_panel_vdd_on(intel_dp);
3342 edid = drm_get_edid(connector, &intel_dp->adapter);
3344 if (drm_add_edid_modes(connector, edid)) {
3345 drm_mode_connector_update_edid_property(connector,
3347 drm_edid_to_eld(connector, edid);
3350 edid = ERR_PTR(-EINVAL);
3353 edid = ERR_PTR(-ENOENT);
3355 intel_connector->edid = edid;
3357 /* prefer fixed mode from EDID if available */
3358 list_for_each_entry(scan, &connector->probed_modes, head) {
3359 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
3360 fixed_mode = drm_mode_duplicate(dev, scan);
3365 /* fallback to VBT if available for eDP */
3366 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
3367 fixed_mode = drm_mode_duplicate(dev,
3368 dev_priv->vbt.lfp_lvds_vbt_mode);
3370 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
3373 ironlake_edp_panel_vdd_off(intel_dp, false);
3375 intel_panel_init(&intel_connector->panel, fixed_mode);
3376 intel_panel_setup_backlight(connector);
3382 intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
3383 struct intel_connector *intel_connector)
3385 struct drm_connector *connector = &intel_connector->base;
3386 struct intel_dp *intel_dp = &intel_dig_port->dp;
3387 struct intel_encoder *intel_encoder = &intel_dig_port->base;
3388 struct drm_device *dev = intel_encoder->base.dev;
3389 struct drm_i915_private *dev_priv = dev->dev_private;
3390 enum port port = intel_dig_port->port;
3391 const char *name = NULL;
3394 /* Preserve the current hw state. */
3395 intel_dp->DP = I915_READ(intel_dp->output_reg);
3396 intel_dp->attached_connector = intel_connector;
3398 type = DRM_MODE_CONNECTOR_DisplayPort;
3400 * FIXME : We need to initialize built-in panels before external panels.
3401 * For X0, DP_C is fixed as eDP. Revisit this as part of VLV eDP cleanup
3405 type = DRM_MODE_CONNECTOR_eDP;
3408 if (IS_VALLEYVIEW(dev))
3409 type = DRM_MODE_CONNECTOR_eDP;
3412 if (HAS_PCH_SPLIT(dev) && intel_dpd_is_edp(dev))
3413 type = DRM_MODE_CONNECTOR_eDP;
3415 default: /* silence GCC warning */
3420 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
3421 * for DP the encoder type can be set by the caller to
3422 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
3424 if (type == DRM_MODE_CONNECTOR_eDP)
3425 intel_encoder->type = INTEL_OUTPUT_EDP;
3427 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
3428 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
3431 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
3432 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
3434 connector->interlace_allowed = true;
3435 connector->doublescan_allowed = 0;
3437 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
3438 ironlake_panel_vdd_work);
3440 intel_connector_attach_encoder(intel_connector, intel_encoder);
3441 drm_sysfs_connector_add(connector);
3444 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
3446 intel_connector->get_hw_state = intel_connector_get_hw_state;
3448 intel_dp->aux_ch_ctl_reg = intel_dp->output_reg + 0x10;
3450 switch (intel_dig_port->port) {
3452 intel_dp->aux_ch_ctl_reg = DPA_AUX_CH_CTL;
3455 intel_dp->aux_ch_ctl_reg = PCH_DPB_AUX_CH_CTL;
3458 intel_dp->aux_ch_ctl_reg = PCH_DPC_AUX_CH_CTL;
3461 intel_dp->aux_ch_ctl_reg = PCH_DPD_AUX_CH_CTL;
3468 /* Set up the DDC bus. */
3471 intel_encoder->hpd_pin = HPD_PORT_A;
3475 intel_encoder->hpd_pin = HPD_PORT_B;
3479 intel_encoder->hpd_pin = HPD_PORT_C;
3483 intel_encoder->hpd_pin = HPD_PORT_D;
3490 error = intel_dp_i2c_init(intel_dp, intel_connector, name);
3491 WARN(error, "intel_dp_i2c_init failed with error %d for port %c\n",
3492 error, port_name(port));
3494 intel_dp->psr_setup_done = false;
3496 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
3497 i2c_del_adapter(&intel_dp->adapter);
3498 if (is_edp(intel_dp)) {
3499 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
3500 mutex_lock(&dev->mode_config.mutex);
3501 ironlake_panel_vdd_off_sync(intel_dp);
3502 mutex_unlock(&dev->mode_config.mutex);
3504 drm_sysfs_connector_remove(connector);
3505 drm_connector_cleanup(connector);
3509 intel_dp_add_properties(intel_dp, connector);
3511 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
3512 * 0xd. Failure to do so will result in spurious interrupts being
3513 * generated on the port when a cable is not attached.
3515 if (IS_G4X(dev) && !IS_GM45(dev)) {
3516 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
3517 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
3524 intel_dp_init(struct drm_device *dev, int output_reg, enum port port)
3526 struct intel_digital_port *intel_dig_port;
3527 struct intel_encoder *intel_encoder;
3528 struct drm_encoder *encoder;
3529 struct intel_connector *intel_connector;
3531 intel_dig_port = kzalloc(sizeof(struct intel_digital_port), GFP_KERNEL);
3532 if (!intel_dig_port)
3535 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
3536 if (!intel_connector) {
3537 kfree(intel_dig_port);
3541 intel_encoder = &intel_dig_port->base;
3542 encoder = &intel_encoder->base;
3544 drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
3545 DRM_MODE_ENCODER_TMDS);
3547 intel_encoder->compute_config = intel_dp_compute_config;
3548 intel_encoder->mode_set = intel_dp_mode_set;
3549 intel_encoder->disable = intel_disable_dp;
3550 intel_encoder->post_disable = intel_post_disable_dp;
3551 intel_encoder->get_hw_state = intel_dp_get_hw_state;
3552 intel_encoder->get_config = intel_dp_get_config;
3553 if (IS_VALLEYVIEW(dev)) {
3554 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
3555 intel_encoder->pre_enable = vlv_pre_enable_dp;
3556 intel_encoder->enable = vlv_enable_dp;
3558 intel_encoder->pre_enable = g4x_pre_enable_dp;
3559 intel_encoder->enable = g4x_enable_dp;
3562 intel_dig_port->port = port;
3563 intel_dig_port->dp.output_reg = output_reg;
3565 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
3566 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
3567 intel_encoder->cloneable = false;
3568 intel_encoder->hot_plug = intel_dp_hot_plug;
3570 if (!intel_dp_init_connector(intel_dig_port, intel_connector)) {
3571 drm_encoder_cleanup(encoder);
3572 kfree(intel_dig_port);
3573 kfree(intel_connector);