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 = 3, .m2 = 81 } },
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);
94 static bool _edp_panel_vdd_on(struct intel_dp *intel_dp);
95 static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
98 intel_dp_max_link_bw(struct intel_dp *intel_dp)
100 int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
101 struct drm_device *dev = intel_dp->attached_connector->base.dev;
103 switch (max_link_bw) {
104 case DP_LINK_BW_1_62:
107 case DP_LINK_BW_5_4: /* 1.2 capable displays may advertise higher bw */
108 if ((IS_HASWELL(dev) || INTEL_INFO(dev)->gen >= 8) &&
109 intel_dp->dpcd[DP_DPCD_REV] >= 0x12)
110 max_link_bw = DP_LINK_BW_5_4;
112 max_link_bw = DP_LINK_BW_2_7;
115 WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
117 max_link_bw = DP_LINK_BW_1_62;
124 * The units on the numbers in the next two are... bizarre. Examples will
125 * make it clearer; this one parallels an example in the eDP spec.
127 * intel_dp_max_data_rate for one lane of 2.7GHz evaluates as:
129 * 270000 * 1 * 8 / 10 == 216000
131 * The actual data capacity of that configuration is 2.16Gbit/s, so the
132 * units are decakilobits. ->clock in a drm_display_mode is in kilohertz -
133 * or equivalently, kilopixels per second - so for 1680x1050R it'd be
134 * 119000. At 18bpp that's 2142000 kilobits per second.
136 * Thus the strange-looking division by 10 in intel_dp_link_required, to
137 * get the result in decakilobits instead of kilobits.
141 intel_dp_link_required(int pixel_clock, int bpp)
143 return (pixel_clock * bpp + 9) / 10;
147 intel_dp_max_data_rate(int max_link_clock, int max_lanes)
149 return (max_link_clock * max_lanes * 8) / 10;
152 static enum drm_mode_status
153 intel_dp_mode_valid(struct drm_connector *connector,
154 struct drm_display_mode *mode)
156 struct intel_dp *intel_dp = intel_attached_dp(connector);
157 struct intel_connector *intel_connector = to_intel_connector(connector);
158 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
159 int target_clock = mode->clock;
160 int max_rate, mode_rate, max_lanes, max_link_clock;
162 if (is_edp(intel_dp) && fixed_mode) {
163 if (mode->hdisplay > fixed_mode->hdisplay)
166 if (mode->vdisplay > fixed_mode->vdisplay)
169 target_clock = fixed_mode->clock;
172 max_link_clock = drm_dp_bw_code_to_link_rate(intel_dp_max_link_bw(intel_dp));
173 max_lanes = drm_dp_max_lane_count(intel_dp->dpcd);
175 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
176 mode_rate = intel_dp_link_required(target_clock, 18);
178 if (mode_rate > max_rate)
179 return MODE_CLOCK_HIGH;
181 if (mode->clock < 10000)
182 return MODE_CLOCK_LOW;
184 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
185 return MODE_H_ILLEGAL;
191 pack_aux(uint8_t *src, int src_bytes)
198 for (i = 0; i < src_bytes; i++)
199 v |= ((uint32_t) src[i]) << ((3-i) * 8);
204 unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
209 for (i = 0; i < dst_bytes; i++)
210 dst[i] = src >> ((3-i) * 8);
213 /* hrawclock is 1/4 the FSB frequency */
215 intel_hrawclk(struct drm_device *dev)
217 struct drm_i915_private *dev_priv = dev->dev_private;
220 /* There is no CLKCFG reg in Valleyview. VLV hrawclk is 200 MHz */
221 if (IS_VALLEYVIEW(dev))
224 clkcfg = I915_READ(CLKCFG);
225 switch (clkcfg & CLKCFG_FSB_MASK) {
234 case CLKCFG_FSB_1067:
236 case CLKCFG_FSB_1333:
238 /* these two are just a guess; one of them might be right */
239 case CLKCFG_FSB_1600:
240 case CLKCFG_FSB_1600_ALT:
248 intel_dp_init_panel_power_sequencer(struct drm_device *dev,
249 struct intel_dp *intel_dp,
250 struct edp_power_seq *out);
252 intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
253 struct intel_dp *intel_dp,
254 struct edp_power_seq *out);
257 vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
259 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
260 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
261 struct drm_device *dev = intel_dig_port->base.base.dev;
262 struct drm_i915_private *dev_priv = dev->dev_private;
263 enum port port = intel_dig_port->port;
266 /* modeset should have pipe */
268 return to_intel_crtc(crtc)->pipe;
270 /* init time, try to find a pipe with this port selected */
271 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
272 u32 port_sel = I915_READ(VLV_PIPE_PP_ON_DELAYS(pipe)) &
273 PANEL_PORT_SELECT_MASK;
274 if (port_sel == PANEL_PORT_SELECT_DPB_VLV && port == PORT_B)
276 if (port_sel == PANEL_PORT_SELECT_DPC_VLV && port == PORT_C)
284 static u32 _pp_ctrl_reg(struct intel_dp *intel_dp)
286 struct drm_device *dev = intel_dp_to_dev(intel_dp);
288 if (HAS_PCH_SPLIT(dev))
289 return PCH_PP_CONTROL;
291 return VLV_PIPE_PP_CONTROL(vlv_power_sequencer_pipe(intel_dp));
294 static u32 _pp_stat_reg(struct intel_dp *intel_dp)
296 struct drm_device *dev = intel_dp_to_dev(intel_dp);
298 if (HAS_PCH_SPLIT(dev))
299 return PCH_PP_STATUS;
301 return VLV_PIPE_PP_STATUS(vlv_power_sequencer_pipe(intel_dp));
304 static bool edp_have_panel_power(struct intel_dp *intel_dp)
306 struct drm_device *dev = intel_dp_to_dev(intel_dp);
307 struct drm_i915_private *dev_priv = dev->dev_private;
309 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
312 static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
314 struct drm_device *dev = intel_dp_to_dev(intel_dp);
315 struct drm_i915_private *dev_priv = dev->dev_private;
317 return !dev_priv->pm.suspended &&
318 (I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD) != 0;
322 intel_dp_check_edp(struct intel_dp *intel_dp)
324 struct drm_device *dev = intel_dp_to_dev(intel_dp);
325 struct drm_i915_private *dev_priv = dev->dev_private;
327 if (!is_edp(intel_dp))
330 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
331 WARN(1, "eDP powered off while attempting aux channel communication.\n");
332 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
333 I915_READ(_pp_stat_reg(intel_dp)),
334 I915_READ(_pp_ctrl_reg(intel_dp)));
339 intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
341 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
342 struct drm_device *dev = intel_dig_port->base.base.dev;
343 struct drm_i915_private *dev_priv = dev->dev_private;
344 uint32_t ch_ctl = intel_dp->aux_ch_ctl_reg;
348 #define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
350 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
351 msecs_to_jiffies_timeout(10));
353 done = wait_for_atomic(C, 10) == 0;
355 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
362 static uint32_t i9xx_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
364 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
365 struct drm_device *dev = intel_dig_port->base.base.dev;
368 * The clock divider is based off the hrawclk, and would like to run at
369 * 2MHz. So, take the hrawclk value and divide by 2 and use that
371 return index ? 0 : intel_hrawclk(dev) / 2;
374 static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
376 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
377 struct drm_device *dev = intel_dig_port->base.base.dev;
382 if (intel_dig_port->port == PORT_A) {
383 if (IS_GEN6(dev) || IS_GEN7(dev))
384 return 200; /* SNB & IVB eDP input clock at 400Mhz */
386 return 225; /* eDP input clock at 450Mhz */
388 return DIV_ROUND_UP(intel_pch_rawclk(dev), 2);
392 static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
394 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
395 struct drm_device *dev = intel_dig_port->base.base.dev;
396 struct drm_i915_private *dev_priv = dev->dev_private;
398 if (intel_dig_port->port == PORT_A) {
401 return DIV_ROUND_CLOSEST(intel_ddi_get_cdclk_freq(dev_priv), 2000);
402 } else if (dev_priv->pch_id == INTEL_PCH_LPT_DEVICE_ID_TYPE) {
403 /* Workaround for non-ULT HSW */
410 return index ? 0 : DIV_ROUND_UP(intel_pch_rawclk(dev), 2);
414 static uint32_t vlv_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
416 return index ? 0 : 100;
419 static uint32_t i9xx_get_aux_send_ctl(struct intel_dp *intel_dp,
422 uint32_t aux_clock_divider)
424 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
425 struct drm_device *dev = intel_dig_port->base.base.dev;
426 uint32_t precharge, timeout;
433 if (IS_BROADWELL(dev) && intel_dp->aux_ch_ctl_reg == DPA_AUX_CH_CTL)
434 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
436 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
438 return DP_AUX_CH_CTL_SEND_BUSY |
440 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
441 DP_AUX_CH_CTL_TIME_OUT_ERROR |
443 DP_AUX_CH_CTL_RECEIVE_ERROR |
444 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
445 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
446 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
450 intel_dp_aux_ch(struct intel_dp *intel_dp,
451 uint8_t *send, int send_bytes,
452 uint8_t *recv, int recv_size)
454 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
455 struct drm_device *dev = intel_dig_port->base.base.dev;
456 struct drm_i915_private *dev_priv = dev->dev_private;
457 uint32_t ch_ctl = intel_dp->aux_ch_ctl_reg;
458 uint32_t ch_data = ch_ctl + 4;
459 uint32_t aux_clock_divider;
460 int i, ret, recv_bytes;
463 bool has_aux_irq = HAS_AUX_IRQ(dev);
466 vdd = _edp_panel_vdd_on(intel_dp);
468 /* dp aux is extremely sensitive to irq latency, hence request the
469 * lowest possible wakeup latency and so prevent the cpu from going into
472 pm_qos_update_request(&dev_priv->pm_qos, 0);
474 intel_dp_check_edp(intel_dp);
476 intel_aux_display_runtime_get(dev_priv);
478 /* Try to wait for any previous AUX channel activity */
479 for (try = 0; try < 3; try++) {
480 status = I915_READ_NOTRACE(ch_ctl);
481 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
487 WARN(1, "dp_aux_ch not started status 0x%08x\n",
493 /* Only 5 data registers! */
494 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
499 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
500 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
505 /* Must try at least 3 times according to DP spec */
506 for (try = 0; try < 5; try++) {
507 /* Load the send data into the aux channel data registers */
508 for (i = 0; i < send_bytes; i += 4)
509 I915_WRITE(ch_data + i,
510 pack_aux(send + i, send_bytes - i));
512 /* Send the command and wait for it to complete */
513 I915_WRITE(ch_ctl, send_ctl);
515 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
517 /* Clear done status and any errors */
521 DP_AUX_CH_CTL_TIME_OUT_ERROR |
522 DP_AUX_CH_CTL_RECEIVE_ERROR);
524 if (status & (DP_AUX_CH_CTL_TIME_OUT_ERROR |
525 DP_AUX_CH_CTL_RECEIVE_ERROR))
527 if (status & DP_AUX_CH_CTL_DONE)
530 if (status & DP_AUX_CH_CTL_DONE)
534 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
535 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
540 /* Check for timeout or receive error.
541 * Timeouts occur when the sink is not connected
543 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
544 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
549 /* Timeouts occur when the device isn't connected, so they're
550 * "normal" -- don't fill the kernel log with these */
551 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
552 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
557 /* Unload any bytes sent back from the other side */
558 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
559 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
560 if (recv_bytes > recv_size)
561 recv_bytes = recv_size;
563 for (i = 0; i < recv_bytes; i += 4)
564 unpack_aux(I915_READ(ch_data + i),
565 recv + i, recv_bytes - i);
569 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
570 intel_aux_display_runtime_put(dev_priv);
573 edp_panel_vdd_off(intel_dp, false);
578 #define HEADER_SIZE 4
580 intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
582 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
583 uint8_t txbuf[20], rxbuf[20];
584 size_t txsize, rxsize;
587 txbuf[0] = msg->request << 4;
588 txbuf[1] = msg->address >> 8;
589 txbuf[2] = msg->address & 0xff;
590 txbuf[3] = msg->size - 1;
592 switch (msg->request & ~DP_AUX_I2C_MOT) {
593 case DP_AUX_NATIVE_WRITE:
594 case DP_AUX_I2C_WRITE:
595 txsize = HEADER_SIZE + msg->size;
598 if (WARN_ON(txsize > 20))
601 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
603 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
605 msg->reply = rxbuf[0] >> 4;
607 /* Return payload size. */
612 case DP_AUX_NATIVE_READ:
613 case DP_AUX_I2C_READ:
614 txsize = HEADER_SIZE;
615 rxsize = msg->size + 1;
617 if (WARN_ON(rxsize > 20))
620 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
622 msg->reply = rxbuf[0] >> 4;
624 * Assume happy day, and copy the data. The caller is
625 * expected to check msg->reply before touching it.
627 * Return payload size.
630 memcpy(msg->buffer, rxbuf + 1, ret);
643 intel_dp_aux_init(struct intel_dp *intel_dp, struct intel_connector *connector)
645 struct drm_device *dev = intel_dp_to_dev(intel_dp);
646 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
647 enum port port = intel_dig_port->port;
648 const char *name = NULL;
653 intel_dp->aux_ch_ctl_reg = DPA_AUX_CH_CTL;
657 intel_dp->aux_ch_ctl_reg = PCH_DPB_AUX_CH_CTL;
661 intel_dp->aux_ch_ctl_reg = PCH_DPC_AUX_CH_CTL;
665 intel_dp->aux_ch_ctl_reg = PCH_DPD_AUX_CH_CTL;
673 intel_dp->aux_ch_ctl_reg = intel_dp->output_reg + 0x10;
675 intel_dp->aux.name = name;
676 intel_dp->aux.dev = dev->dev;
677 intel_dp->aux.transfer = intel_dp_aux_transfer;
679 DRM_DEBUG_KMS("registering %s bus for %s\n", name,
680 connector->base.kdev->kobj.name);
682 ret = drm_dp_aux_register_i2c_bus(&intel_dp->aux);
684 DRM_ERROR("drm_dp_aux_register_i2c_bus() for %s failed (%d)\n",
689 ret = sysfs_create_link(&connector->base.kdev->kobj,
690 &intel_dp->aux.ddc.dev.kobj,
691 intel_dp->aux.ddc.dev.kobj.name);
693 DRM_ERROR("sysfs_create_link() for %s failed (%d)\n", name, ret);
694 drm_dp_aux_unregister_i2c_bus(&intel_dp->aux);
699 intel_dp_connector_unregister(struct intel_connector *intel_connector)
701 struct intel_dp *intel_dp = intel_attached_dp(&intel_connector->base);
703 sysfs_remove_link(&intel_connector->base.kdev->kobj,
704 intel_dp->aux.ddc.dev.kobj.name);
705 intel_connector_unregister(intel_connector);
709 intel_dp_set_clock(struct intel_encoder *encoder,
710 struct intel_crtc_config *pipe_config, int link_bw)
712 struct drm_device *dev = encoder->base.dev;
713 const struct dp_link_dpll *divisor = NULL;
718 count = ARRAY_SIZE(gen4_dpll);
719 } else if (IS_HASWELL(dev)) {
720 /* Haswell has special-purpose DP DDI clocks. */
721 } else if (HAS_PCH_SPLIT(dev)) {
723 count = ARRAY_SIZE(pch_dpll);
724 } else if (IS_VALLEYVIEW(dev)) {
726 count = ARRAY_SIZE(vlv_dpll);
729 if (divisor && count) {
730 for (i = 0; i < count; i++) {
731 if (link_bw == divisor[i].link_bw) {
732 pipe_config->dpll = divisor[i].dpll;
733 pipe_config->clock_set = true;
741 intel_dp_set_m2_n2(struct intel_crtc *crtc, struct intel_link_m_n *m_n)
743 struct drm_device *dev = crtc->base.dev;
744 struct drm_i915_private *dev_priv = dev->dev_private;
745 enum transcoder transcoder = crtc->config.cpu_transcoder;
747 I915_WRITE(PIPE_DATA_M2(transcoder),
748 TU_SIZE(m_n->tu) | m_n->gmch_m);
749 I915_WRITE(PIPE_DATA_N2(transcoder), m_n->gmch_n);
750 I915_WRITE(PIPE_LINK_M2(transcoder), m_n->link_m);
751 I915_WRITE(PIPE_LINK_N2(transcoder), m_n->link_n);
755 intel_dp_compute_config(struct intel_encoder *encoder,
756 struct intel_crtc_config *pipe_config)
758 struct drm_device *dev = encoder->base.dev;
759 struct drm_i915_private *dev_priv = dev->dev_private;
760 struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
761 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
762 enum port port = dp_to_dig_port(intel_dp)->port;
763 struct intel_crtc *intel_crtc = encoder->new_crtc;
764 struct intel_connector *intel_connector = intel_dp->attached_connector;
765 int lane_count, clock;
766 int max_lane_count = drm_dp_max_lane_count(intel_dp->dpcd);
767 /* Conveniently, the link BW constants become indices with a shift...*/
768 int max_clock = intel_dp_max_link_bw(intel_dp) >> 3;
770 static int bws[] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7, DP_LINK_BW_5_4 };
771 int link_avail, link_clock;
773 if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev) && port != PORT_A)
774 pipe_config->has_pch_encoder = true;
776 pipe_config->has_dp_encoder = true;
778 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
779 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
781 if (!HAS_PCH_SPLIT(dev))
782 intel_gmch_panel_fitting(intel_crtc, pipe_config,
783 intel_connector->panel.fitting_mode);
785 intel_pch_panel_fitting(intel_crtc, pipe_config,
786 intel_connector->panel.fitting_mode);
789 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
792 DRM_DEBUG_KMS("DP link computation with max lane count %i "
793 "max bw %02x pixel clock %iKHz\n",
794 max_lane_count, bws[max_clock],
795 adjusted_mode->crtc_clock);
797 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
799 bpp = pipe_config->pipe_bpp;
800 if (is_edp(intel_dp) && dev_priv->vbt.edp_bpp &&
801 dev_priv->vbt.edp_bpp < bpp) {
802 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
803 dev_priv->vbt.edp_bpp);
804 bpp = dev_priv->vbt.edp_bpp;
807 for (; bpp >= 6*3; bpp -= 2*3) {
808 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
811 for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) {
812 for (clock = 0; clock <= max_clock; clock++) {
813 link_clock = drm_dp_bw_code_to_link_rate(bws[clock]);
814 link_avail = intel_dp_max_data_rate(link_clock,
817 if (mode_rate <= link_avail) {
827 if (intel_dp->color_range_auto) {
830 * CEA-861-E - 5.1 Default Encoding Parameters
831 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
833 if (bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1)
834 intel_dp->color_range = DP_COLOR_RANGE_16_235;
836 intel_dp->color_range = 0;
839 if (intel_dp->color_range)
840 pipe_config->limited_color_range = true;
842 intel_dp->link_bw = bws[clock];
843 intel_dp->lane_count = lane_count;
844 pipe_config->pipe_bpp = bpp;
845 pipe_config->port_clock = drm_dp_bw_code_to_link_rate(intel_dp->link_bw);
847 DRM_DEBUG_KMS("DP link bw %02x lane count %d clock %d bpp %d\n",
848 intel_dp->link_bw, intel_dp->lane_count,
849 pipe_config->port_clock, bpp);
850 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
851 mode_rate, link_avail);
853 intel_link_compute_m_n(bpp, lane_count,
854 adjusted_mode->crtc_clock,
855 pipe_config->port_clock,
856 &pipe_config->dp_m_n);
858 if (intel_connector->panel.downclock_mode != NULL &&
859 intel_dp->drrs_state.type == SEAMLESS_DRRS_SUPPORT) {
860 intel_link_compute_m_n(bpp, lane_count,
861 intel_connector->panel.downclock_mode->clock,
862 pipe_config->port_clock,
863 &pipe_config->dp_m2_n2);
866 intel_dp_set_clock(encoder, pipe_config, intel_dp->link_bw);
871 static void ironlake_set_pll_cpu_edp(struct intel_dp *intel_dp)
873 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
874 struct intel_crtc *crtc = to_intel_crtc(dig_port->base.base.crtc);
875 struct drm_device *dev = crtc->base.dev;
876 struct drm_i915_private *dev_priv = dev->dev_private;
879 DRM_DEBUG_KMS("eDP PLL enable for clock %d\n", crtc->config.port_clock);
880 dpa_ctl = I915_READ(DP_A);
881 dpa_ctl &= ~DP_PLL_FREQ_MASK;
883 if (crtc->config.port_clock == 162000) {
884 /* For a long time we've carried around a ILK-DevA w/a for the
885 * 160MHz clock. If we're really unlucky, it's still required.
887 DRM_DEBUG_KMS("160MHz cpu eDP clock, might need ilk devA w/a\n");
888 dpa_ctl |= DP_PLL_FREQ_160MHZ;
889 intel_dp->DP |= DP_PLL_FREQ_160MHZ;
891 dpa_ctl |= DP_PLL_FREQ_270MHZ;
892 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
895 I915_WRITE(DP_A, dpa_ctl);
901 static void intel_dp_mode_set(struct intel_encoder *encoder)
903 struct drm_device *dev = encoder->base.dev;
904 struct drm_i915_private *dev_priv = dev->dev_private;
905 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
906 enum port port = dp_to_dig_port(intel_dp)->port;
907 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
908 struct drm_display_mode *adjusted_mode = &crtc->config.adjusted_mode;
911 * There are four kinds of DP registers:
918 * IBX PCH and CPU are the same for almost everything,
919 * except that the CPU DP PLL is configured in this
922 * CPT PCH is quite different, having many bits moved
923 * to the TRANS_DP_CTL register instead. That
924 * configuration happens (oddly) in ironlake_pch_enable
927 /* Preserve the BIOS-computed detected bit. This is
928 * supposed to be read-only.
930 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
932 /* Handle DP bits in common between all three register formats */
933 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
934 intel_dp->DP |= DP_PORT_WIDTH(intel_dp->lane_count);
936 if (intel_dp->has_audio) {
937 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
938 pipe_name(crtc->pipe));
939 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
940 intel_write_eld(&encoder->base, adjusted_mode);
943 /* Split out the IBX/CPU vs CPT settings */
945 if (port == PORT_A && IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) {
946 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
947 intel_dp->DP |= DP_SYNC_HS_HIGH;
948 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
949 intel_dp->DP |= DP_SYNC_VS_HIGH;
950 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
952 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
953 intel_dp->DP |= DP_ENHANCED_FRAMING;
955 intel_dp->DP |= crtc->pipe << 29;
956 } else if (!HAS_PCH_CPT(dev) || port == PORT_A) {
957 if (!HAS_PCH_SPLIT(dev) && !IS_VALLEYVIEW(dev))
958 intel_dp->DP |= intel_dp->color_range;
960 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
961 intel_dp->DP |= DP_SYNC_HS_HIGH;
962 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
963 intel_dp->DP |= DP_SYNC_VS_HIGH;
964 intel_dp->DP |= DP_LINK_TRAIN_OFF;
966 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
967 intel_dp->DP |= DP_ENHANCED_FRAMING;
970 intel_dp->DP |= DP_PIPEB_SELECT;
972 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
975 if (port == PORT_A && !IS_VALLEYVIEW(dev))
976 ironlake_set_pll_cpu_edp(intel_dp);
979 #define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
980 #define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
982 #define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
983 #define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
985 #define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
986 #define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
988 static void wait_panel_status(struct intel_dp *intel_dp,
992 struct drm_device *dev = intel_dp_to_dev(intel_dp);
993 struct drm_i915_private *dev_priv = dev->dev_private;
994 u32 pp_stat_reg, pp_ctrl_reg;
996 pp_stat_reg = _pp_stat_reg(intel_dp);
997 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
999 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
1001 I915_READ(pp_stat_reg),
1002 I915_READ(pp_ctrl_reg));
1004 if (_wait_for((I915_READ(pp_stat_reg) & mask) == value, 5000, 10)) {
1005 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
1006 I915_READ(pp_stat_reg),
1007 I915_READ(pp_ctrl_reg));
1010 DRM_DEBUG_KMS("Wait complete\n");
1013 static void wait_panel_on(struct intel_dp *intel_dp)
1015 DRM_DEBUG_KMS("Wait for panel power on\n");
1016 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
1019 static void wait_panel_off(struct intel_dp *intel_dp)
1021 DRM_DEBUG_KMS("Wait for panel power off time\n");
1022 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
1025 static void wait_panel_power_cycle(struct intel_dp *intel_dp)
1027 DRM_DEBUG_KMS("Wait for panel power cycle\n");
1029 /* When we disable the VDD override bit last we have to do the manual
1031 wait_remaining_ms_from_jiffies(intel_dp->last_power_cycle,
1032 intel_dp->panel_power_cycle_delay);
1034 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
1037 static void wait_backlight_on(struct intel_dp *intel_dp)
1039 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1040 intel_dp->backlight_on_delay);
1043 static void edp_wait_backlight_off(struct intel_dp *intel_dp)
1045 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
1046 intel_dp->backlight_off_delay);
1049 /* Read the current pp_control value, unlocking the register if it
1053 static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
1055 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1056 struct drm_i915_private *dev_priv = dev->dev_private;
1059 control = I915_READ(_pp_ctrl_reg(intel_dp));
1060 control &= ~PANEL_UNLOCK_MASK;
1061 control |= PANEL_UNLOCK_REGS;
1065 static bool _edp_panel_vdd_on(struct intel_dp *intel_dp)
1067 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1068 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1069 struct intel_encoder *intel_encoder = &intel_dig_port->base;
1070 struct drm_i915_private *dev_priv = dev->dev_private;
1071 enum intel_display_power_domain power_domain;
1073 u32 pp_stat_reg, pp_ctrl_reg;
1074 bool need_to_disable = !intel_dp->want_panel_vdd;
1076 if (!is_edp(intel_dp))
1079 intel_dp->want_panel_vdd = true;
1081 if (edp_have_panel_vdd(intel_dp))
1082 return need_to_disable;
1084 power_domain = intel_display_port_power_domain(intel_encoder);
1085 intel_display_power_get(dev_priv, power_domain);
1087 DRM_DEBUG_KMS("Turning eDP VDD on\n");
1089 if (!edp_have_panel_power(intel_dp))
1090 wait_panel_power_cycle(intel_dp);
1092 pp = ironlake_get_pp_control(intel_dp);
1093 pp |= EDP_FORCE_VDD;
1095 pp_stat_reg = _pp_stat_reg(intel_dp);
1096 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
1098 I915_WRITE(pp_ctrl_reg, pp);
1099 POSTING_READ(pp_ctrl_reg);
1100 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1101 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
1103 * If the panel wasn't on, delay before accessing aux channel
1105 if (!edp_have_panel_power(intel_dp)) {
1106 DRM_DEBUG_KMS("eDP was not running\n");
1107 msleep(intel_dp->panel_power_up_delay);
1110 return need_to_disable;
1113 void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
1115 if (is_edp(intel_dp)) {
1116 bool vdd = _edp_panel_vdd_on(intel_dp);
1118 WARN(!vdd, "eDP VDD already requested on\n");
1122 static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
1124 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1125 struct drm_i915_private *dev_priv = dev->dev_private;
1127 u32 pp_stat_reg, pp_ctrl_reg;
1129 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
1131 if (!intel_dp->want_panel_vdd && edp_have_panel_vdd(intel_dp)) {
1132 struct intel_digital_port *intel_dig_port =
1133 dp_to_dig_port(intel_dp);
1134 struct intel_encoder *intel_encoder = &intel_dig_port->base;
1135 enum intel_display_power_domain power_domain;
1137 DRM_DEBUG_KMS("Turning eDP VDD off\n");
1139 pp = ironlake_get_pp_control(intel_dp);
1140 pp &= ~EDP_FORCE_VDD;
1142 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
1143 pp_stat_reg = _pp_stat_reg(intel_dp);
1145 I915_WRITE(pp_ctrl_reg, pp);
1146 POSTING_READ(pp_ctrl_reg);
1148 /* Make sure sequencer is idle before allowing subsequent activity */
1149 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1150 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
1152 if ((pp & POWER_TARGET_ON) == 0)
1153 intel_dp->last_power_cycle = jiffies;
1155 power_domain = intel_display_port_power_domain(intel_encoder);
1156 intel_display_power_put(dev_priv, power_domain);
1160 static void edp_panel_vdd_work(struct work_struct *__work)
1162 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
1163 struct intel_dp, panel_vdd_work);
1164 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1166 mutex_lock(&dev->mode_config.mutex);
1167 edp_panel_vdd_off_sync(intel_dp);
1168 mutex_unlock(&dev->mode_config.mutex);
1171 static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
1173 if (!is_edp(intel_dp))
1176 WARN(!intel_dp->want_panel_vdd, "eDP VDD not forced on");
1178 intel_dp->want_panel_vdd = false;
1181 edp_panel_vdd_off_sync(intel_dp);
1184 * Queue the timer to fire a long
1185 * time from now (relative to the power down delay)
1186 * to keep the panel power up across a sequence of operations
1188 schedule_delayed_work(&intel_dp->panel_vdd_work,
1189 msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5));
1193 void intel_edp_panel_on(struct intel_dp *intel_dp)
1195 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1196 struct drm_i915_private *dev_priv = dev->dev_private;
1200 if (!is_edp(intel_dp))
1203 DRM_DEBUG_KMS("Turn eDP power on\n");
1205 if (edp_have_panel_power(intel_dp)) {
1206 DRM_DEBUG_KMS("eDP power already on\n");
1210 wait_panel_power_cycle(intel_dp);
1212 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
1213 pp = ironlake_get_pp_control(intel_dp);
1215 /* ILK workaround: disable reset around power sequence */
1216 pp &= ~PANEL_POWER_RESET;
1217 I915_WRITE(pp_ctrl_reg, pp);
1218 POSTING_READ(pp_ctrl_reg);
1221 pp |= POWER_TARGET_ON;
1223 pp |= PANEL_POWER_RESET;
1225 I915_WRITE(pp_ctrl_reg, pp);
1226 POSTING_READ(pp_ctrl_reg);
1228 wait_panel_on(intel_dp);
1229 intel_dp->last_power_on = jiffies;
1232 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
1233 I915_WRITE(pp_ctrl_reg, pp);
1234 POSTING_READ(pp_ctrl_reg);
1238 void intel_edp_panel_off(struct intel_dp *intel_dp)
1240 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1241 struct intel_encoder *intel_encoder = &intel_dig_port->base;
1242 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1243 struct drm_i915_private *dev_priv = dev->dev_private;
1244 enum intel_display_power_domain power_domain;
1248 if (!is_edp(intel_dp))
1251 DRM_DEBUG_KMS("Turn eDP power off\n");
1253 edp_wait_backlight_off(intel_dp);
1255 WARN(!intel_dp->want_panel_vdd, "Need VDD to turn off panel\n");
1257 pp = ironlake_get_pp_control(intel_dp);
1258 /* We need to switch off panel power _and_ force vdd, for otherwise some
1259 * panels get very unhappy and cease to work. */
1260 pp &= ~(POWER_TARGET_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
1263 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
1265 intel_dp->want_panel_vdd = false;
1267 I915_WRITE(pp_ctrl_reg, pp);
1268 POSTING_READ(pp_ctrl_reg);
1270 intel_dp->last_power_cycle = jiffies;
1271 wait_panel_off(intel_dp);
1273 /* We got a reference when we enabled the VDD. */
1274 power_domain = intel_display_port_power_domain(intel_encoder);
1275 intel_display_power_put(dev_priv, power_domain);
1278 void intel_edp_backlight_on(struct intel_dp *intel_dp)
1280 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1281 struct drm_device *dev = intel_dig_port->base.base.dev;
1282 struct drm_i915_private *dev_priv = dev->dev_private;
1286 if (!is_edp(intel_dp))
1289 DRM_DEBUG_KMS("\n");
1291 * If we enable the backlight right away following a panel power
1292 * on, we may see slight flicker as the panel syncs with the eDP
1293 * link. So delay a bit to make sure the image is solid before
1294 * allowing it to appear.
1296 wait_backlight_on(intel_dp);
1297 pp = ironlake_get_pp_control(intel_dp);
1298 pp |= EDP_BLC_ENABLE;
1300 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
1302 I915_WRITE(pp_ctrl_reg, pp);
1303 POSTING_READ(pp_ctrl_reg);
1305 intel_panel_enable_backlight(intel_dp->attached_connector);
1308 void intel_edp_backlight_off(struct intel_dp *intel_dp)
1310 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1311 struct drm_i915_private *dev_priv = dev->dev_private;
1315 if (!is_edp(intel_dp))
1318 intel_panel_disable_backlight(intel_dp->attached_connector);
1320 DRM_DEBUG_KMS("\n");
1321 pp = ironlake_get_pp_control(intel_dp);
1322 pp &= ~EDP_BLC_ENABLE;
1324 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
1326 I915_WRITE(pp_ctrl_reg, pp);
1327 POSTING_READ(pp_ctrl_reg);
1328 intel_dp->last_backlight_off = jiffies;
1331 static void ironlake_edp_pll_on(struct intel_dp *intel_dp)
1333 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1334 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
1335 struct drm_device *dev = crtc->dev;
1336 struct drm_i915_private *dev_priv = dev->dev_private;
1339 assert_pipe_disabled(dev_priv,
1340 to_intel_crtc(crtc)->pipe);
1342 DRM_DEBUG_KMS("\n");
1343 dpa_ctl = I915_READ(DP_A);
1344 WARN(dpa_ctl & DP_PLL_ENABLE, "dp pll on, should be off\n");
1345 WARN(dpa_ctl & DP_PORT_EN, "dp port still on, should be off\n");
1347 /* We don't adjust intel_dp->DP while tearing down the link, to
1348 * facilitate link retraining (e.g. after hotplug). Hence clear all
1349 * enable bits here to ensure that we don't enable too much. */
1350 intel_dp->DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
1351 intel_dp->DP |= DP_PLL_ENABLE;
1352 I915_WRITE(DP_A, intel_dp->DP);
1357 static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
1359 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1360 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
1361 struct drm_device *dev = crtc->dev;
1362 struct drm_i915_private *dev_priv = dev->dev_private;
1365 assert_pipe_disabled(dev_priv,
1366 to_intel_crtc(crtc)->pipe);
1368 dpa_ctl = I915_READ(DP_A);
1369 WARN((dpa_ctl & DP_PLL_ENABLE) == 0,
1370 "dp pll off, should be on\n");
1371 WARN(dpa_ctl & DP_PORT_EN, "dp port still on, should be off\n");
1373 /* We can't rely on the value tracked for the DP register in
1374 * intel_dp->DP because link_down must not change that (otherwise link
1375 * re-training will fail. */
1376 dpa_ctl &= ~DP_PLL_ENABLE;
1377 I915_WRITE(DP_A, dpa_ctl);
1382 /* If the sink supports it, try to set the power state appropriately */
1383 void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
1387 /* Should have a valid DPCD by this point */
1388 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
1391 if (mode != DRM_MODE_DPMS_ON) {
1392 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
1395 DRM_DEBUG_DRIVER("failed to write sink power state\n");
1398 * When turning on, we need to retry for 1ms to give the sink
1401 for (i = 0; i < 3; i++) {
1402 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
1411 static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
1414 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1415 enum port port = dp_to_dig_port(intel_dp)->port;
1416 struct drm_device *dev = encoder->base.dev;
1417 struct drm_i915_private *dev_priv = dev->dev_private;
1418 enum intel_display_power_domain power_domain;
1421 power_domain = intel_display_port_power_domain(encoder);
1422 if (!intel_display_power_enabled(dev_priv, power_domain))
1425 tmp = I915_READ(intel_dp->output_reg);
1427 if (!(tmp & DP_PORT_EN))
1430 if (port == PORT_A && IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) {
1431 *pipe = PORT_TO_PIPE_CPT(tmp);
1432 } else if (!HAS_PCH_CPT(dev) || port == PORT_A) {
1433 *pipe = PORT_TO_PIPE(tmp);
1439 switch (intel_dp->output_reg) {
1441 trans_sel = TRANS_DP_PORT_SEL_B;
1444 trans_sel = TRANS_DP_PORT_SEL_C;
1447 trans_sel = TRANS_DP_PORT_SEL_D;
1454 trans_dp = I915_READ(TRANS_DP_CTL(i));
1455 if ((trans_dp & TRANS_DP_PORT_SEL_MASK) == trans_sel) {
1461 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
1462 intel_dp->output_reg);
1468 static void intel_dp_get_config(struct intel_encoder *encoder,
1469 struct intel_crtc_config *pipe_config)
1471 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1473 struct drm_device *dev = encoder->base.dev;
1474 struct drm_i915_private *dev_priv = dev->dev_private;
1475 enum port port = dp_to_dig_port(intel_dp)->port;
1476 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
1479 if ((port == PORT_A) || !HAS_PCH_CPT(dev)) {
1480 tmp = I915_READ(intel_dp->output_reg);
1481 if (tmp & DP_SYNC_HS_HIGH)
1482 flags |= DRM_MODE_FLAG_PHSYNC;
1484 flags |= DRM_MODE_FLAG_NHSYNC;
1486 if (tmp & DP_SYNC_VS_HIGH)
1487 flags |= DRM_MODE_FLAG_PVSYNC;
1489 flags |= DRM_MODE_FLAG_NVSYNC;
1491 tmp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1492 if (tmp & TRANS_DP_HSYNC_ACTIVE_HIGH)
1493 flags |= DRM_MODE_FLAG_PHSYNC;
1495 flags |= DRM_MODE_FLAG_NHSYNC;
1497 if (tmp & TRANS_DP_VSYNC_ACTIVE_HIGH)
1498 flags |= DRM_MODE_FLAG_PVSYNC;
1500 flags |= DRM_MODE_FLAG_NVSYNC;
1503 pipe_config->adjusted_mode.flags |= flags;
1505 pipe_config->has_dp_encoder = true;
1507 intel_dp_get_m_n(crtc, pipe_config);
1509 if (port == PORT_A) {
1510 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_160MHZ)
1511 pipe_config->port_clock = 162000;
1513 pipe_config->port_clock = 270000;
1516 dotclock = intel_dotclock_calculate(pipe_config->port_clock,
1517 &pipe_config->dp_m_n);
1519 if (HAS_PCH_SPLIT(dev_priv->dev) && port != PORT_A)
1520 ironlake_check_encoder_dotclock(pipe_config, dotclock);
1522 pipe_config->adjusted_mode.crtc_clock = dotclock;
1524 if (is_edp(intel_dp) && dev_priv->vbt.edp_bpp &&
1525 pipe_config->pipe_bpp > dev_priv->vbt.edp_bpp) {
1527 * This is a big fat ugly hack.
1529 * Some machines in UEFI boot mode provide us a VBT that has 18
1530 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
1531 * unknown we fail to light up. Yet the same BIOS boots up with
1532 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
1533 * max, not what it tells us to use.
1535 * Note: This will still be broken if the eDP panel is not lit
1536 * up by the BIOS, and thus we can't get the mode at module
1539 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
1540 pipe_config->pipe_bpp, dev_priv->vbt.edp_bpp);
1541 dev_priv->vbt.edp_bpp = pipe_config->pipe_bpp;
1545 static bool is_edp_psr(struct drm_device *dev)
1547 struct drm_i915_private *dev_priv = dev->dev_private;
1549 return dev_priv->psr.sink_support;
1552 static bool intel_edp_is_psr_enabled(struct drm_device *dev)
1554 struct drm_i915_private *dev_priv = dev->dev_private;
1559 return I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
1562 static void intel_edp_psr_write_vsc(struct intel_dp *intel_dp,
1563 struct edp_vsc_psr *vsc_psr)
1565 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1566 struct drm_device *dev = dig_port->base.base.dev;
1567 struct drm_i915_private *dev_priv = dev->dev_private;
1568 struct intel_crtc *crtc = to_intel_crtc(dig_port->base.base.crtc);
1569 u32 ctl_reg = HSW_TVIDEO_DIP_CTL(crtc->config.cpu_transcoder);
1570 u32 data_reg = HSW_TVIDEO_DIP_VSC_DATA(crtc->config.cpu_transcoder);
1571 uint32_t *data = (uint32_t *) vsc_psr;
1574 /* As per BSPec (Pipe Video Data Island Packet), we need to disable
1575 the video DIP being updated before program video DIP data buffer
1576 registers for DIP being updated. */
1577 I915_WRITE(ctl_reg, 0);
1578 POSTING_READ(ctl_reg);
1580 for (i = 0; i < VIDEO_DIP_VSC_DATA_SIZE; i += 4) {
1581 if (i < sizeof(struct edp_vsc_psr))
1582 I915_WRITE(data_reg + i, *data++);
1584 I915_WRITE(data_reg + i, 0);
1587 I915_WRITE(ctl_reg, VIDEO_DIP_ENABLE_VSC_HSW);
1588 POSTING_READ(ctl_reg);
1591 static void intel_edp_psr_setup(struct intel_dp *intel_dp)
1593 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1594 struct drm_i915_private *dev_priv = dev->dev_private;
1595 struct edp_vsc_psr psr_vsc;
1597 if (intel_dp->psr_setup_done)
1600 /* Prepare VSC packet as per EDP 1.3 spec, Table 3.10 */
1601 memset(&psr_vsc, 0, sizeof(psr_vsc));
1602 psr_vsc.sdp_header.HB0 = 0;
1603 psr_vsc.sdp_header.HB1 = 0x7;
1604 psr_vsc.sdp_header.HB2 = 0x2;
1605 psr_vsc.sdp_header.HB3 = 0x8;
1606 intel_edp_psr_write_vsc(intel_dp, &psr_vsc);
1608 /* Avoid continuous PSR exit by masking memup and hpd */
1609 I915_WRITE(EDP_PSR_DEBUG_CTL(dev), EDP_PSR_DEBUG_MASK_MEMUP |
1610 EDP_PSR_DEBUG_MASK_HPD | EDP_PSR_DEBUG_MASK_LPSP);
1612 intel_dp->psr_setup_done = true;
1615 static void intel_edp_psr_enable_sink(struct intel_dp *intel_dp)
1617 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1618 struct drm_i915_private *dev_priv = dev->dev_private;
1619 uint32_t aux_clock_divider;
1620 int precharge = 0x3;
1621 int msg_size = 5; /* Header(4) + Message(1) */
1623 aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, 0);
1625 /* Enable PSR in sink */
1626 if (intel_dp->psr_dpcd[1] & DP_PSR_NO_TRAIN_ON_EXIT)
1627 drm_dp_dpcd_writeb(&intel_dp->aux, DP_PSR_EN_CFG,
1628 DP_PSR_ENABLE & ~DP_PSR_MAIN_LINK_ACTIVE);
1630 drm_dp_dpcd_writeb(&intel_dp->aux, DP_PSR_EN_CFG,
1631 DP_PSR_ENABLE | DP_PSR_MAIN_LINK_ACTIVE);
1633 /* Setup AUX registers */
1634 I915_WRITE(EDP_PSR_AUX_DATA1(dev), EDP_PSR_DPCD_COMMAND);
1635 I915_WRITE(EDP_PSR_AUX_DATA2(dev), EDP_PSR_DPCD_NORMAL_OPERATION);
1636 I915_WRITE(EDP_PSR_AUX_CTL(dev),
1637 DP_AUX_CH_CTL_TIME_OUT_400us |
1638 (msg_size << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
1639 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
1640 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT));
1643 static void intel_edp_psr_enable_source(struct intel_dp *intel_dp)
1645 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1646 struct drm_i915_private *dev_priv = dev->dev_private;
1647 uint32_t max_sleep_time = 0x1f;
1648 uint32_t idle_frames = 1;
1650 const uint32_t link_entry_time = EDP_PSR_MIN_LINK_ENTRY_TIME_8_LINES;
1652 if (intel_dp->psr_dpcd[1] & DP_PSR_NO_TRAIN_ON_EXIT) {
1653 val |= EDP_PSR_LINK_STANDBY;
1654 val |= EDP_PSR_TP2_TP3_TIME_0us;
1655 val |= EDP_PSR_TP1_TIME_0us;
1656 val |= EDP_PSR_SKIP_AUX_EXIT;
1658 val |= EDP_PSR_LINK_DISABLE;
1660 I915_WRITE(EDP_PSR_CTL(dev), val |
1661 (IS_BROADWELL(dev) ? 0 : link_entry_time) |
1662 max_sleep_time << EDP_PSR_MAX_SLEEP_TIME_SHIFT |
1663 idle_frames << EDP_PSR_IDLE_FRAME_SHIFT |
1667 static bool intel_edp_psr_match_conditions(struct intel_dp *intel_dp)
1669 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1670 struct drm_device *dev = dig_port->base.base.dev;
1671 struct drm_i915_private *dev_priv = dev->dev_private;
1672 struct drm_crtc *crtc = dig_port->base.base.crtc;
1673 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1674 struct drm_i915_gem_object *obj = to_intel_framebuffer(crtc->primary->fb)->obj;
1675 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
1677 dev_priv->psr.source_ok = false;
1679 if (!HAS_PSR(dev)) {
1680 DRM_DEBUG_KMS("PSR not supported on this platform\n");
1684 if ((intel_encoder->type != INTEL_OUTPUT_EDP) ||
1685 (dig_port->port != PORT_A)) {
1686 DRM_DEBUG_KMS("HSW ties PSR to DDI A (eDP)\n");
1690 if (!i915.enable_psr) {
1691 DRM_DEBUG_KMS("PSR disable by flag\n");
1695 crtc = dig_port->base.base.crtc;
1697 DRM_DEBUG_KMS("crtc not active for PSR\n");
1701 intel_crtc = to_intel_crtc(crtc);
1702 if (!intel_crtc_active(crtc)) {
1703 DRM_DEBUG_KMS("crtc not active for PSR\n");
1707 obj = to_intel_framebuffer(crtc->primary->fb)->obj;
1708 if (obj->tiling_mode != I915_TILING_X ||
1709 obj->fence_reg == I915_FENCE_REG_NONE) {
1710 DRM_DEBUG_KMS("PSR condition failed: fb not tiled or fenced\n");
1714 if (I915_READ(SPRCTL(intel_crtc->pipe)) & SPRITE_ENABLE) {
1715 DRM_DEBUG_KMS("PSR condition failed: Sprite is Enabled\n");
1719 if (I915_READ(HSW_STEREO_3D_CTL(intel_crtc->config.cpu_transcoder)) &
1721 DRM_DEBUG_KMS("PSR condition failed: Stereo 3D is Enabled\n");
1725 if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
1726 DRM_DEBUG_KMS("PSR condition failed: Interlaced is Enabled\n");
1730 dev_priv->psr.source_ok = true;
1734 static void intel_edp_psr_do_enable(struct intel_dp *intel_dp)
1736 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1738 if (!intel_edp_psr_match_conditions(intel_dp) ||
1739 intel_edp_is_psr_enabled(dev))
1742 /* Setup PSR once */
1743 intel_edp_psr_setup(intel_dp);
1745 /* Enable PSR on the panel */
1746 intel_edp_psr_enable_sink(intel_dp);
1748 /* Enable PSR on the host */
1749 intel_edp_psr_enable_source(intel_dp);
1752 void intel_edp_psr_enable(struct intel_dp *intel_dp)
1754 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1756 if (intel_edp_psr_match_conditions(intel_dp) &&
1757 !intel_edp_is_psr_enabled(dev))
1758 intel_edp_psr_do_enable(intel_dp);
1761 void intel_edp_psr_disable(struct intel_dp *intel_dp)
1763 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1764 struct drm_i915_private *dev_priv = dev->dev_private;
1766 if (!intel_edp_is_psr_enabled(dev))
1769 I915_WRITE(EDP_PSR_CTL(dev),
1770 I915_READ(EDP_PSR_CTL(dev)) & ~EDP_PSR_ENABLE);
1772 /* Wait till PSR is idle */
1773 if (_wait_for((I915_READ(EDP_PSR_STATUS_CTL(dev)) &
1774 EDP_PSR_STATUS_STATE_MASK) == 0, 2000, 10))
1775 DRM_ERROR("Timed out waiting for PSR Idle State\n");
1778 void intel_edp_psr_update(struct drm_device *dev)
1780 struct intel_encoder *encoder;
1781 struct intel_dp *intel_dp = NULL;
1783 list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head)
1784 if (encoder->type == INTEL_OUTPUT_EDP) {
1785 intel_dp = enc_to_intel_dp(&encoder->base);
1787 if (!is_edp_psr(dev))
1790 if (!intel_edp_psr_match_conditions(intel_dp))
1791 intel_edp_psr_disable(intel_dp);
1793 if (!intel_edp_is_psr_enabled(dev))
1794 intel_edp_psr_do_enable(intel_dp);
1798 static void intel_disable_dp(struct intel_encoder *encoder)
1800 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1801 enum port port = dp_to_dig_port(intel_dp)->port;
1802 struct drm_device *dev = encoder->base.dev;
1804 /* Make sure the panel is off before trying to change the mode. But also
1805 * ensure that we have vdd while we switch off the panel. */
1806 intel_edp_panel_vdd_on(intel_dp);
1807 intel_edp_backlight_off(intel_dp);
1808 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
1809 intel_edp_panel_off(intel_dp);
1811 /* cpu edp my only be disable _after_ the cpu pipe/plane is disabled. */
1812 if (!(port == PORT_A || IS_VALLEYVIEW(dev)))
1813 intel_dp_link_down(intel_dp);
1816 static void g4x_post_disable_dp(struct intel_encoder *encoder)
1818 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1819 enum port port = dp_to_dig_port(intel_dp)->port;
1824 intel_dp_link_down(intel_dp);
1825 ironlake_edp_pll_off(intel_dp);
1828 static void vlv_post_disable_dp(struct intel_encoder *encoder)
1830 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1832 intel_dp_link_down(intel_dp);
1835 static void intel_enable_dp(struct intel_encoder *encoder)
1837 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1838 struct drm_device *dev = encoder->base.dev;
1839 struct drm_i915_private *dev_priv = dev->dev_private;
1840 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
1842 if (WARN_ON(dp_reg & DP_PORT_EN))
1845 intel_edp_panel_vdd_on(intel_dp);
1846 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1847 intel_dp_start_link_train(intel_dp);
1848 intel_edp_panel_on(intel_dp);
1849 edp_panel_vdd_off(intel_dp, true);
1850 intel_dp_complete_link_train(intel_dp);
1851 intel_dp_stop_link_train(intel_dp);
1854 static void g4x_enable_dp(struct intel_encoder *encoder)
1856 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1858 intel_enable_dp(encoder);
1859 intel_edp_backlight_on(intel_dp);
1862 static void vlv_enable_dp(struct intel_encoder *encoder)
1864 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1866 intel_edp_backlight_on(intel_dp);
1869 static void g4x_pre_enable_dp(struct intel_encoder *encoder)
1871 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1872 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
1874 if (dport->port == PORT_A)
1875 ironlake_edp_pll_on(intel_dp);
1878 static void vlv_pre_enable_dp(struct intel_encoder *encoder)
1880 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1881 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
1882 struct drm_device *dev = encoder->base.dev;
1883 struct drm_i915_private *dev_priv = dev->dev_private;
1884 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
1885 enum dpio_channel port = vlv_dport_to_channel(dport);
1886 int pipe = intel_crtc->pipe;
1887 struct edp_power_seq power_seq;
1890 mutex_lock(&dev_priv->dpio_lock);
1892 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(port));
1899 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW8(port), val);
1900 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW14(port), 0x00760018);
1901 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW23(port), 0x00400888);
1903 mutex_unlock(&dev_priv->dpio_lock);
1905 if (is_edp(intel_dp)) {
1906 /* init power sequencer on this pipe and port */
1907 intel_dp_init_panel_power_sequencer(dev, intel_dp, &power_seq);
1908 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp,
1912 intel_enable_dp(encoder);
1914 vlv_wait_port_ready(dev_priv, dport);
1917 static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder)
1919 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1920 struct drm_device *dev = encoder->base.dev;
1921 struct drm_i915_private *dev_priv = dev->dev_private;
1922 struct intel_crtc *intel_crtc =
1923 to_intel_crtc(encoder->base.crtc);
1924 enum dpio_channel port = vlv_dport_to_channel(dport);
1925 int pipe = intel_crtc->pipe;
1927 /* Program Tx lane resets to default */
1928 mutex_lock(&dev_priv->dpio_lock);
1929 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port),
1930 DPIO_PCS_TX_LANE2_RESET |
1931 DPIO_PCS_TX_LANE1_RESET);
1932 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port),
1933 DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
1934 DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
1935 (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
1936 DPIO_PCS_CLK_SOFT_RESET);
1938 /* Fix up inter-pair skew failure */
1939 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW12(port), 0x00750f00);
1940 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW11(port), 0x00001500);
1941 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW14(port), 0x40400000);
1942 mutex_unlock(&dev_priv->dpio_lock);
1946 * Native read with retry for link status and receiver capability reads for
1947 * cases where the sink may still be asleep.
1949 * Sinks are *supposed* to come up within 1ms from an off state, but we're also
1950 * supposed to retry 3 times per the spec.
1953 intel_dp_dpcd_read_wake(struct drm_dp_aux *aux, unsigned int offset,
1954 void *buffer, size_t size)
1959 for (i = 0; i < 3; i++) {
1960 ret = drm_dp_dpcd_read(aux, offset, buffer, size);
1970 * Fetch AUX CH registers 0x202 - 0x207 which contain
1971 * link status information
1974 intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
1976 return intel_dp_dpcd_read_wake(&intel_dp->aux,
1979 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
1983 * These are source-specific values; current Intel hardware supports
1984 * a maximum voltage of 800mV and a maximum pre-emphasis of 6dB
1988 intel_dp_voltage_max(struct intel_dp *intel_dp)
1990 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1991 enum port port = dp_to_dig_port(intel_dp)->port;
1993 if (IS_VALLEYVIEW(dev) || IS_BROADWELL(dev))
1994 return DP_TRAIN_VOLTAGE_SWING_1200;
1995 else if (IS_GEN7(dev) && port == PORT_A)
1996 return DP_TRAIN_VOLTAGE_SWING_800;
1997 else if (HAS_PCH_CPT(dev) && port != PORT_A)
1998 return DP_TRAIN_VOLTAGE_SWING_1200;
2000 return DP_TRAIN_VOLTAGE_SWING_800;
2004 intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
2006 struct drm_device *dev = intel_dp_to_dev(intel_dp);
2007 enum port port = dp_to_dig_port(intel_dp)->port;
2009 if (IS_BROADWELL(dev)) {
2010 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
2011 case DP_TRAIN_VOLTAGE_SWING_400:
2012 case DP_TRAIN_VOLTAGE_SWING_600:
2013 return DP_TRAIN_PRE_EMPHASIS_6;
2014 case DP_TRAIN_VOLTAGE_SWING_800:
2015 return DP_TRAIN_PRE_EMPHASIS_3_5;
2016 case DP_TRAIN_VOLTAGE_SWING_1200:
2018 return DP_TRAIN_PRE_EMPHASIS_0;
2020 } else if (IS_HASWELL(dev)) {
2021 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
2022 case DP_TRAIN_VOLTAGE_SWING_400:
2023 return DP_TRAIN_PRE_EMPHASIS_9_5;
2024 case DP_TRAIN_VOLTAGE_SWING_600:
2025 return DP_TRAIN_PRE_EMPHASIS_6;
2026 case DP_TRAIN_VOLTAGE_SWING_800:
2027 return DP_TRAIN_PRE_EMPHASIS_3_5;
2028 case DP_TRAIN_VOLTAGE_SWING_1200:
2030 return DP_TRAIN_PRE_EMPHASIS_0;
2032 } else if (IS_VALLEYVIEW(dev)) {
2033 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
2034 case DP_TRAIN_VOLTAGE_SWING_400:
2035 return DP_TRAIN_PRE_EMPHASIS_9_5;
2036 case DP_TRAIN_VOLTAGE_SWING_600:
2037 return DP_TRAIN_PRE_EMPHASIS_6;
2038 case DP_TRAIN_VOLTAGE_SWING_800:
2039 return DP_TRAIN_PRE_EMPHASIS_3_5;
2040 case DP_TRAIN_VOLTAGE_SWING_1200:
2042 return DP_TRAIN_PRE_EMPHASIS_0;
2044 } else if (IS_GEN7(dev) && port == PORT_A) {
2045 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
2046 case DP_TRAIN_VOLTAGE_SWING_400:
2047 return DP_TRAIN_PRE_EMPHASIS_6;
2048 case DP_TRAIN_VOLTAGE_SWING_600:
2049 case DP_TRAIN_VOLTAGE_SWING_800:
2050 return DP_TRAIN_PRE_EMPHASIS_3_5;
2052 return DP_TRAIN_PRE_EMPHASIS_0;
2055 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
2056 case DP_TRAIN_VOLTAGE_SWING_400:
2057 return DP_TRAIN_PRE_EMPHASIS_6;
2058 case DP_TRAIN_VOLTAGE_SWING_600:
2059 return DP_TRAIN_PRE_EMPHASIS_6;
2060 case DP_TRAIN_VOLTAGE_SWING_800:
2061 return DP_TRAIN_PRE_EMPHASIS_3_5;
2062 case DP_TRAIN_VOLTAGE_SWING_1200:
2064 return DP_TRAIN_PRE_EMPHASIS_0;
2069 static uint32_t intel_vlv_signal_levels(struct intel_dp *intel_dp)
2071 struct drm_device *dev = intel_dp_to_dev(intel_dp);
2072 struct drm_i915_private *dev_priv = dev->dev_private;
2073 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
2074 struct intel_crtc *intel_crtc =
2075 to_intel_crtc(dport->base.base.crtc);
2076 unsigned long demph_reg_value, preemph_reg_value,
2077 uniqtranscale_reg_value;
2078 uint8_t train_set = intel_dp->train_set[0];
2079 enum dpio_channel port = vlv_dport_to_channel(dport);
2080 int pipe = intel_crtc->pipe;
2082 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
2083 case DP_TRAIN_PRE_EMPHASIS_0:
2084 preemph_reg_value = 0x0004000;
2085 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
2086 case DP_TRAIN_VOLTAGE_SWING_400:
2087 demph_reg_value = 0x2B405555;
2088 uniqtranscale_reg_value = 0x552AB83A;
2090 case DP_TRAIN_VOLTAGE_SWING_600:
2091 demph_reg_value = 0x2B404040;
2092 uniqtranscale_reg_value = 0x5548B83A;
2094 case DP_TRAIN_VOLTAGE_SWING_800:
2095 demph_reg_value = 0x2B245555;
2096 uniqtranscale_reg_value = 0x5560B83A;
2098 case DP_TRAIN_VOLTAGE_SWING_1200:
2099 demph_reg_value = 0x2B405555;
2100 uniqtranscale_reg_value = 0x5598DA3A;
2106 case DP_TRAIN_PRE_EMPHASIS_3_5:
2107 preemph_reg_value = 0x0002000;
2108 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
2109 case DP_TRAIN_VOLTAGE_SWING_400:
2110 demph_reg_value = 0x2B404040;
2111 uniqtranscale_reg_value = 0x5552B83A;
2113 case DP_TRAIN_VOLTAGE_SWING_600:
2114 demph_reg_value = 0x2B404848;
2115 uniqtranscale_reg_value = 0x5580B83A;
2117 case DP_TRAIN_VOLTAGE_SWING_800:
2118 demph_reg_value = 0x2B404040;
2119 uniqtranscale_reg_value = 0x55ADDA3A;
2125 case DP_TRAIN_PRE_EMPHASIS_6:
2126 preemph_reg_value = 0x0000000;
2127 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
2128 case DP_TRAIN_VOLTAGE_SWING_400:
2129 demph_reg_value = 0x2B305555;
2130 uniqtranscale_reg_value = 0x5570B83A;
2132 case DP_TRAIN_VOLTAGE_SWING_600:
2133 demph_reg_value = 0x2B2B4040;
2134 uniqtranscale_reg_value = 0x55ADDA3A;
2140 case DP_TRAIN_PRE_EMPHASIS_9_5:
2141 preemph_reg_value = 0x0006000;
2142 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
2143 case DP_TRAIN_VOLTAGE_SWING_400:
2144 demph_reg_value = 0x1B405555;
2145 uniqtranscale_reg_value = 0x55ADDA3A;
2155 mutex_lock(&dev_priv->dpio_lock);
2156 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0x00000000);
2157 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW4(port), demph_reg_value);
2158 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW2(port),
2159 uniqtranscale_reg_value);
2160 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW3(port), 0x0C782040);
2161 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW11(port), 0x00030000);
2162 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW9(port), preemph_reg_value);
2163 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0x80000000);
2164 mutex_unlock(&dev_priv->dpio_lock);
2170 intel_get_adjust_train(struct intel_dp *intel_dp,
2171 const uint8_t link_status[DP_LINK_STATUS_SIZE])
2176 uint8_t voltage_max;
2177 uint8_t preemph_max;
2179 for (lane = 0; lane < intel_dp->lane_count; lane++) {
2180 uint8_t this_v = drm_dp_get_adjust_request_voltage(link_status, lane);
2181 uint8_t this_p = drm_dp_get_adjust_request_pre_emphasis(link_status, lane);
2189 voltage_max = intel_dp_voltage_max(intel_dp);
2190 if (v >= voltage_max)
2191 v = voltage_max | DP_TRAIN_MAX_SWING_REACHED;
2193 preemph_max = intel_dp_pre_emphasis_max(intel_dp, v);
2194 if (p >= preemph_max)
2195 p = preemph_max | DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
2197 for (lane = 0; lane < 4; lane++)
2198 intel_dp->train_set[lane] = v | p;
2202 intel_gen4_signal_levels(uint8_t train_set)
2204 uint32_t signal_levels = 0;
2206 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
2207 case DP_TRAIN_VOLTAGE_SWING_400:
2209 signal_levels |= DP_VOLTAGE_0_4;
2211 case DP_TRAIN_VOLTAGE_SWING_600:
2212 signal_levels |= DP_VOLTAGE_0_6;
2214 case DP_TRAIN_VOLTAGE_SWING_800:
2215 signal_levels |= DP_VOLTAGE_0_8;
2217 case DP_TRAIN_VOLTAGE_SWING_1200:
2218 signal_levels |= DP_VOLTAGE_1_2;
2221 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
2222 case DP_TRAIN_PRE_EMPHASIS_0:
2224 signal_levels |= DP_PRE_EMPHASIS_0;
2226 case DP_TRAIN_PRE_EMPHASIS_3_5:
2227 signal_levels |= DP_PRE_EMPHASIS_3_5;
2229 case DP_TRAIN_PRE_EMPHASIS_6:
2230 signal_levels |= DP_PRE_EMPHASIS_6;
2232 case DP_TRAIN_PRE_EMPHASIS_9_5:
2233 signal_levels |= DP_PRE_EMPHASIS_9_5;
2236 return signal_levels;
2239 /* Gen6's DP voltage swing and pre-emphasis control */
2241 intel_gen6_edp_signal_levels(uint8_t train_set)
2243 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
2244 DP_TRAIN_PRE_EMPHASIS_MASK);
2245 switch (signal_levels) {
2246 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
2247 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
2248 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
2249 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
2250 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
2251 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
2252 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
2253 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
2254 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
2255 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
2256 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
2257 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
2258 case DP_TRAIN_VOLTAGE_SWING_1200 | DP_TRAIN_PRE_EMPHASIS_0:
2259 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
2261 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
2262 "0x%x\n", signal_levels);
2263 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
2267 /* Gen7's DP voltage swing and pre-emphasis control */
2269 intel_gen7_edp_signal_levels(uint8_t train_set)
2271 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
2272 DP_TRAIN_PRE_EMPHASIS_MASK);
2273 switch (signal_levels) {
2274 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
2275 return EDP_LINK_TRAIN_400MV_0DB_IVB;
2276 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
2277 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
2278 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
2279 return EDP_LINK_TRAIN_400MV_6DB_IVB;
2281 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
2282 return EDP_LINK_TRAIN_600MV_0DB_IVB;
2283 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
2284 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
2286 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
2287 return EDP_LINK_TRAIN_800MV_0DB_IVB;
2288 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
2289 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
2292 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
2293 "0x%x\n", signal_levels);
2294 return EDP_LINK_TRAIN_500MV_0DB_IVB;
2298 /* Gen7.5's (HSW) DP voltage swing and pre-emphasis control */
2300 intel_hsw_signal_levels(uint8_t train_set)
2302 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
2303 DP_TRAIN_PRE_EMPHASIS_MASK);
2304 switch (signal_levels) {
2305 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
2306 return DDI_BUF_EMP_400MV_0DB_HSW;
2307 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
2308 return DDI_BUF_EMP_400MV_3_5DB_HSW;
2309 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
2310 return DDI_BUF_EMP_400MV_6DB_HSW;
2311 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_9_5:
2312 return DDI_BUF_EMP_400MV_9_5DB_HSW;
2314 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
2315 return DDI_BUF_EMP_600MV_0DB_HSW;
2316 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
2317 return DDI_BUF_EMP_600MV_3_5DB_HSW;
2318 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
2319 return DDI_BUF_EMP_600MV_6DB_HSW;
2321 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
2322 return DDI_BUF_EMP_800MV_0DB_HSW;
2323 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
2324 return DDI_BUF_EMP_800MV_3_5DB_HSW;
2326 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
2327 "0x%x\n", signal_levels);
2328 return DDI_BUF_EMP_400MV_0DB_HSW;
2333 intel_bdw_signal_levels(uint8_t train_set)
2335 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
2336 DP_TRAIN_PRE_EMPHASIS_MASK);
2337 switch (signal_levels) {
2338 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
2339 return DDI_BUF_EMP_400MV_0DB_BDW; /* Sel0 */
2340 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
2341 return DDI_BUF_EMP_400MV_3_5DB_BDW; /* Sel1 */
2342 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
2343 return DDI_BUF_EMP_400MV_6DB_BDW; /* Sel2 */
2345 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
2346 return DDI_BUF_EMP_600MV_0DB_BDW; /* Sel3 */
2347 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
2348 return DDI_BUF_EMP_600MV_3_5DB_BDW; /* Sel4 */
2349 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
2350 return DDI_BUF_EMP_600MV_6DB_BDW; /* Sel5 */
2352 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
2353 return DDI_BUF_EMP_800MV_0DB_BDW; /* Sel6 */
2354 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
2355 return DDI_BUF_EMP_800MV_3_5DB_BDW; /* Sel7 */
2357 case DP_TRAIN_VOLTAGE_SWING_1200 | DP_TRAIN_PRE_EMPHASIS_0:
2358 return DDI_BUF_EMP_1200MV_0DB_BDW; /* Sel8 */
2361 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
2362 "0x%x\n", signal_levels);
2363 return DDI_BUF_EMP_400MV_0DB_BDW; /* Sel0 */
2367 /* Properly updates "DP" with the correct signal levels. */
2369 intel_dp_set_signal_levels(struct intel_dp *intel_dp, uint32_t *DP)
2371 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2372 enum port port = intel_dig_port->port;
2373 struct drm_device *dev = intel_dig_port->base.base.dev;
2374 uint32_t signal_levels, mask;
2375 uint8_t train_set = intel_dp->train_set[0];
2377 if (IS_BROADWELL(dev)) {
2378 signal_levels = intel_bdw_signal_levels(train_set);
2379 mask = DDI_BUF_EMP_MASK;
2380 } else if (IS_HASWELL(dev)) {
2381 signal_levels = intel_hsw_signal_levels(train_set);
2382 mask = DDI_BUF_EMP_MASK;
2383 } else if (IS_VALLEYVIEW(dev)) {
2384 signal_levels = intel_vlv_signal_levels(intel_dp);
2386 } else if (IS_GEN7(dev) && port == PORT_A) {
2387 signal_levels = intel_gen7_edp_signal_levels(train_set);
2388 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
2389 } else if (IS_GEN6(dev) && port == PORT_A) {
2390 signal_levels = intel_gen6_edp_signal_levels(train_set);
2391 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
2393 signal_levels = intel_gen4_signal_levels(train_set);
2394 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
2397 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
2399 *DP = (*DP & ~mask) | signal_levels;
2403 intel_dp_set_link_train(struct intel_dp *intel_dp,
2405 uint8_t dp_train_pat)
2407 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2408 struct drm_device *dev = intel_dig_port->base.base.dev;
2409 struct drm_i915_private *dev_priv = dev->dev_private;
2410 enum port port = intel_dig_port->port;
2411 uint8_t buf[sizeof(intel_dp->train_set) + 1];
2415 uint32_t temp = I915_READ(DP_TP_CTL(port));
2417 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2418 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2420 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2422 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2423 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2424 case DP_TRAINING_PATTERN_DISABLE:
2425 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2428 case DP_TRAINING_PATTERN_1:
2429 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2431 case DP_TRAINING_PATTERN_2:
2432 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2434 case DP_TRAINING_PATTERN_3:
2435 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2438 I915_WRITE(DP_TP_CTL(port), temp);
2440 } else if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || port != PORT_A)) {
2441 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2443 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2444 case DP_TRAINING_PATTERN_DISABLE:
2445 *DP |= DP_LINK_TRAIN_OFF_CPT;
2447 case DP_TRAINING_PATTERN_1:
2448 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2450 case DP_TRAINING_PATTERN_2:
2451 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2453 case DP_TRAINING_PATTERN_3:
2454 DRM_ERROR("DP training pattern 3 not supported\n");
2455 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2460 *DP &= ~DP_LINK_TRAIN_MASK;
2462 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2463 case DP_TRAINING_PATTERN_DISABLE:
2464 *DP |= DP_LINK_TRAIN_OFF;
2466 case DP_TRAINING_PATTERN_1:
2467 *DP |= DP_LINK_TRAIN_PAT_1;
2469 case DP_TRAINING_PATTERN_2:
2470 *DP |= DP_LINK_TRAIN_PAT_2;
2472 case DP_TRAINING_PATTERN_3:
2473 DRM_ERROR("DP training pattern 3 not supported\n");
2474 *DP |= DP_LINK_TRAIN_PAT_2;
2479 I915_WRITE(intel_dp->output_reg, *DP);
2480 POSTING_READ(intel_dp->output_reg);
2482 buf[0] = dp_train_pat;
2483 if ((dp_train_pat & DP_TRAINING_PATTERN_MASK) ==
2484 DP_TRAINING_PATTERN_DISABLE) {
2485 /* don't write DP_TRAINING_LANEx_SET on disable */
2488 /* DP_TRAINING_LANEx_SET follow DP_TRAINING_PATTERN_SET */
2489 memcpy(buf + 1, intel_dp->train_set, intel_dp->lane_count);
2490 len = intel_dp->lane_count + 1;
2493 ret = drm_dp_dpcd_write(&intel_dp->aux, DP_TRAINING_PATTERN_SET,
2500 intel_dp_reset_link_train(struct intel_dp *intel_dp, uint32_t *DP,
2501 uint8_t dp_train_pat)
2503 memset(intel_dp->train_set, 0, sizeof(intel_dp->train_set));
2504 intel_dp_set_signal_levels(intel_dp, DP);
2505 return intel_dp_set_link_train(intel_dp, DP, dp_train_pat);
2509 intel_dp_update_link_train(struct intel_dp *intel_dp, uint32_t *DP,
2510 const uint8_t link_status[DP_LINK_STATUS_SIZE])
2512 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2513 struct drm_device *dev = intel_dig_port->base.base.dev;
2514 struct drm_i915_private *dev_priv = dev->dev_private;
2517 intel_get_adjust_train(intel_dp, link_status);
2518 intel_dp_set_signal_levels(intel_dp, DP);
2520 I915_WRITE(intel_dp->output_reg, *DP);
2521 POSTING_READ(intel_dp->output_reg);
2523 ret = drm_dp_dpcd_write(&intel_dp->aux, DP_TRAINING_LANE0_SET,
2524 intel_dp->train_set, intel_dp->lane_count);
2526 return ret == intel_dp->lane_count;
2529 static void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
2531 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2532 struct drm_device *dev = intel_dig_port->base.base.dev;
2533 struct drm_i915_private *dev_priv = dev->dev_private;
2534 enum port port = intel_dig_port->port;
2540 val = I915_READ(DP_TP_CTL(port));
2541 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2542 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
2543 I915_WRITE(DP_TP_CTL(port), val);
2546 * On PORT_A we can have only eDP in SST mode. There the only reason
2547 * we need to set idle transmission mode is to work around a HW issue
2548 * where we enable the pipe while not in idle link-training mode.
2549 * In this case there is requirement to wait for a minimum number of
2550 * idle patterns to be sent.
2555 if (wait_for((I915_READ(DP_TP_STATUS(port)) & DP_TP_STATUS_IDLE_DONE),
2557 DRM_ERROR("Timed out waiting for DP idle patterns\n");
2560 /* Enable corresponding port and start training pattern 1 */
2562 intel_dp_start_link_train(struct intel_dp *intel_dp)
2564 struct drm_encoder *encoder = &dp_to_dig_port(intel_dp)->base.base;
2565 struct drm_device *dev = encoder->dev;
2568 int voltage_tries, loop_tries;
2569 uint32_t DP = intel_dp->DP;
2570 uint8_t link_config[2];
2573 intel_ddi_prepare_link_retrain(encoder);
2575 /* Write the link configuration data */
2576 link_config[0] = intel_dp->link_bw;
2577 link_config[1] = intel_dp->lane_count;
2578 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
2579 link_config[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
2580 drm_dp_dpcd_write(&intel_dp->aux, DP_LINK_BW_SET, link_config, 2);
2583 link_config[1] = DP_SET_ANSI_8B10B;
2584 drm_dp_dpcd_write(&intel_dp->aux, DP_DOWNSPREAD_CTRL, link_config, 2);
2588 /* clock recovery */
2589 if (!intel_dp_reset_link_train(intel_dp, &DP,
2590 DP_TRAINING_PATTERN_1 |
2591 DP_LINK_SCRAMBLING_DISABLE)) {
2592 DRM_ERROR("failed to enable link training\n");
2600 uint8_t link_status[DP_LINK_STATUS_SIZE];
2602 drm_dp_link_train_clock_recovery_delay(intel_dp->dpcd);
2603 if (!intel_dp_get_link_status(intel_dp, link_status)) {
2604 DRM_ERROR("failed to get link status\n");
2608 if (drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
2609 DRM_DEBUG_KMS("clock recovery OK\n");
2613 /* Check to see if we've tried the max voltage */
2614 for (i = 0; i < intel_dp->lane_count; i++)
2615 if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
2617 if (i == intel_dp->lane_count) {
2619 if (loop_tries == 5) {
2620 DRM_ERROR("too many full retries, give up\n");
2623 intel_dp_reset_link_train(intel_dp, &DP,
2624 DP_TRAINING_PATTERN_1 |
2625 DP_LINK_SCRAMBLING_DISABLE);
2630 /* Check to see if we've tried the same voltage 5 times */
2631 if ((intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) == voltage) {
2633 if (voltage_tries == 5) {
2634 DRM_ERROR("too many voltage retries, give up\n");
2639 voltage = intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
2641 /* Update training set as requested by target */
2642 if (!intel_dp_update_link_train(intel_dp, &DP, link_status)) {
2643 DRM_ERROR("failed to update link training\n");
2652 intel_dp_complete_link_train(struct intel_dp *intel_dp)
2654 bool channel_eq = false;
2655 int tries, cr_tries;
2656 uint32_t DP = intel_dp->DP;
2657 uint32_t training_pattern = DP_TRAINING_PATTERN_2;
2659 /* Training Pattern 3 for HBR2 ot 1.2 devices that support it*/
2660 if (intel_dp->link_bw == DP_LINK_BW_5_4 || intel_dp->use_tps3)
2661 training_pattern = DP_TRAINING_PATTERN_3;
2663 /* channel equalization */
2664 if (!intel_dp_set_link_train(intel_dp, &DP,
2666 DP_LINK_SCRAMBLING_DISABLE)) {
2667 DRM_ERROR("failed to start channel equalization\n");
2675 uint8_t link_status[DP_LINK_STATUS_SIZE];
2678 DRM_ERROR("failed to train DP, aborting\n");
2682 drm_dp_link_train_channel_eq_delay(intel_dp->dpcd);
2683 if (!intel_dp_get_link_status(intel_dp, link_status)) {
2684 DRM_ERROR("failed to get link status\n");
2688 /* Make sure clock is still ok */
2689 if (!drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
2690 intel_dp_start_link_train(intel_dp);
2691 intel_dp_set_link_train(intel_dp, &DP,
2693 DP_LINK_SCRAMBLING_DISABLE);
2698 if (drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
2703 /* Try 5 times, then try clock recovery if that fails */
2705 intel_dp_link_down(intel_dp);
2706 intel_dp_start_link_train(intel_dp);
2707 intel_dp_set_link_train(intel_dp, &DP,
2709 DP_LINK_SCRAMBLING_DISABLE);
2715 /* Update training set as requested by target */
2716 if (!intel_dp_update_link_train(intel_dp, &DP, link_status)) {
2717 DRM_ERROR("failed to update link training\n");
2723 intel_dp_set_idle_link_train(intel_dp);
2728 DRM_DEBUG_KMS("Channel EQ done. DP Training successful\n");
2732 void intel_dp_stop_link_train(struct intel_dp *intel_dp)
2734 intel_dp_set_link_train(intel_dp, &intel_dp->DP,
2735 DP_TRAINING_PATTERN_DISABLE);
2739 intel_dp_link_down(struct intel_dp *intel_dp)
2741 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2742 enum port port = intel_dig_port->port;
2743 struct drm_device *dev = intel_dig_port->base.base.dev;
2744 struct drm_i915_private *dev_priv = dev->dev_private;
2745 struct intel_crtc *intel_crtc =
2746 to_intel_crtc(intel_dig_port->base.base.crtc);
2747 uint32_t DP = intel_dp->DP;
2750 * DDI code has a strict mode set sequence and we should try to respect
2751 * it, otherwise we might hang the machine in many different ways. So we
2752 * really should be disabling the port only on a complete crtc_disable
2753 * sequence. This function is just called under two conditions on DDI
2755 * - Link train failed while doing crtc_enable, and on this case we
2756 * really should respect the mode set sequence and wait for a
2758 * - Someone turned the monitor off and intel_dp_check_link_status
2759 * called us. We don't need to disable the whole port on this case, so
2760 * when someone turns the monitor on again,
2761 * intel_ddi_prepare_link_retrain will take care of redoing the link
2767 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
2770 DRM_DEBUG_KMS("\n");
2772 if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || port != PORT_A)) {
2773 DP &= ~DP_LINK_TRAIN_MASK_CPT;
2774 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT);
2776 DP &= ~DP_LINK_TRAIN_MASK;
2777 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE);
2779 POSTING_READ(intel_dp->output_reg);
2781 /* We don't really know why we're doing this */
2782 intel_wait_for_vblank(dev, intel_crtc->pipe);
2784 if (HAS_PCH_IBX(dev) &&
2785 I915_READ(intel_dp->output_reg) & DP_PIPEB_SELECT) {
2786 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
2788 /* Hardware workaround: leaving our transcoder select
2789 * set to transcoder B while it's off will prevent the
2790 * corresponding HDMI output on transcoder A.
2792 * Combine this with another hardware workaround:
2793 * transcoder select bit can only be cleared while the
2796 DP &= ~DP_PIPEB_SELECT;
2797 I915_WRITE(intel_dp->output_reg, DP);
2799 /* Changes to enable or select take place the vblank
2800 * after being written.
2802 if (WARN_ON(crtc == NULL)) {
2803 /* We should never try to disable a port without a crtc
2804 * attached. For paranoia keep the code around for a
2806 POSTING_READ(intel_dp->output_reg);
2809 intel_wait_for_vblank(dev, intel_crtc->pipe);
2812 DP &= ~DP_AUDIO_OUTPUT_ENABLE;
2813 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
2814 POSTING_READ(intel_dp->output_reg);
2815 msleep(intel_dp->panel_power_down_delay);
2819 intel_dp_get_dpcd(struct intel_dp *intel_dp)
2821 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2822 struct drm_device *dev = dig_port->base.base.dev;
2823 struct drm_i915_private *dev_priv = dev->dev_private;
2825 char dpcd_hex_dump[sizeof(intel_dp->dpcd) * 3];
2827 if (intel_dp_dpcd_read_wake(&intel_dp->aux, 0x000, intel_dp->dpcd,
2828 sizeof(intel_dp->dpcd)) < 0)
2829 return false; /* aux transfer failed */
2831 hex_dump_to_buffer(intel_dp->dpcd, sizeof(intel_dp->dpcd),
2832 32, 1, dpcd_hex_dump, sizeof(dpcd_hex_dump), false);
2833 DRM_DEBUG_KMS("DPCD: %s\n", dpcd_hex_dump);
2835 if (intel_dp->dpcd[DP_DPCD_REV] == 0)
2836 return false; /* DPCD not present */
2838 /* Check if the panel supports PSR */
2839 memset(intel_dp->psr_dpcd, 0, sizeof(intel_dp->psr_dpcd));
2840 if (is_edp(intel_dp)) {
2841 intel_dp_dpcd_read_wake(&intel_dp->aux, DP_PSR_SUPPORT,
2843 sizeof(intel_dp->psr_dpcd));
2844 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
2845 dev_priv->psr.sink_support = true;
2846 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
2850 /* Training Pattern 3 support */
2851 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x12 &&
2852 intel_dp->dpcd[DP_MAX_LANE_COUNT] & DP_TPS3_SUPPORTED) {
2853 intel_dp->use_tps3 = true;
2854 DRM_DEBUG_KMS("Displayport TPS3 supported");
2856 intel_dp->use_tps3 = false;
2858 if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
2859 DP_DWN_STRM_PORT_PRESENT))
2860 return true; /* native DP sink */
2862 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
2863 return true; /* no per-port downstream info */
2865 if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
2866 intel_dp->downstream_ports,
2867 DP_MAX_DOWNSTREAM_PORTS) < 0)
2868 return false; /* downstream port status fetch failed */
2874 intel_dp_probe_oui(struct intel_dp *intel_dp)
2878 if (!(intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] & DP_OUI_SUPPORT))
2881 intel_edp_panel_vdd_on(intel_dp);
2883 if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_SINK_OUI, buf, 3) == 3)
2884 DRM_DEBUG_KMS("Sink OUI: %02hx%02hx%02hx\n",
2885 buf[0], buf[1], buf[2]);
2887 if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_BRANCH_OUI, buf, 3) == 3)
2888 DRM_DEBUG_KMS("Branch OUI: %02hx%02hx%02hx\n",
2889 buf[0], buf[1], buf[2]);
2891 edp_panel_vdd_off(intel_dp, false);
2894 int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
2896 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2897 struct drm_device *dev = intel_dig_port->base.base.dev;
2898 struct intel_crtc *intel_crtc =
2899 to_intel_crtc(intel_dig_port->base.base.crtc);
2902 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, buf) < 0)
2905 if (!(buf[0] & DP_TEST_CRC_SUPPORTED))
2908 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
2909 DP_TEST_SINK_START) < 0)
2912 /* Wait 2 vblanks to be sure we will have the correct CRC value */
2913 intel_wait_for_vblank(dev, intel_crtc->pipe);
2914 intel_wait_for_vblank(dev, intel_crtc->pipe);
2916 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0)
2919 drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK, 0);
2924 intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
2926 return intel_dp_dpcd_read_wake(&intel_dp->aux,
2927 DP_DEVICE_SERVICE_IRQ_VECTOR,
2928 sink_irq_vector, 1) == 1;
2932 intel_dp_handle_test_request(struct intel_dp *intel_dp)
2934 /* NAK by default */
2935 drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, DP_TEST_NAK);
2939 * According to DP spec
2942 * 2. Configure link according to Receiver Capabilities
2943 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
2944 * 4. Check link status on receipt of hot-plug interrupt
2948 intel_dp_check_link_status(struct intel_dp *intel_dp)
2950 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
2952 u8 link_status[DP_LINK_STATUS_SIZE];
2954 if (!intel_encoder->connectors_active)
2957 if (WARN_ON(!intel_encoder->base.crtc))
2960 /* Try to read receiver status if the link appears to be up */
2961 if (!intel_dp_get_link_status(intel_dp, link_status)) {
2965 /* Now read the DPCD to see if it's actually running */
2966 if (!intel_dp_get_dpcd(intel_dp)) {
2970 /* Try to read the source of the interrupt */
2971 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
2972 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector)) {
2973 /* Clear interrupt source */
2974 drm_dp_dpcd_writeb(&intel_dp->aux,
2975 DP_DEVICE_SERVICE_IRQ_VECTOR,
2978 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
2979 intel_dp_handle_test_request(intel_dp);
2980 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
2981 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
2984 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
2985 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
2986 drm_get_encoder_name(&intel_encoder->base));
2987 intel_dp_start_link_train(intel_dp);
2988 intel_dp_complete_link_train(intel_dp);
2989 intel_dp_stop_link_train(intel_dp);
2993 /* XXX this is probably wrong for multiple downstream ports */
2994 static enum drm_connector_status
2995 intel_dp_detect_dpcd(struct intel_dp *intel_dp)
2997 uint8_t *dpcd = intel_dp->dpcd;
3000 if (!intel_dp_get_dpcd(intel_dp))
3001 return connector_status_disconnected;
3003 /* if there's no downstream port, we're done */
3004 if (!(dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT))
3005 return connector_status_connected;
3007 /* If we're HPD-aware, SINK_COUNT changes dynamically */
3008 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
3009 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
3012 if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_SINK_COUNT,
3014 return connector_status_unknown;
3016 return DP_GET_SINK_COUNT(reg) ? connector_status_connected
3017 : connector_status_disconnected;
3020 /* If no HPD, poke DDC gently */
3021 if (drm_probe_ddc(&intel_dp->aux.ddc))
3022 return connector_status_connected;
3024 /* Well we tried, say unknown for unreliable port types */
3025 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
3026 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
3027 if (type == DP_DS_PORT_TYPE_VGA ||
3028 type == DP_DS_PORT_TYPE_NON_EDID)
3029 return connector_status_unknown;
3031 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
3032 DP_DWN_STRM_PORT_TYPE_MASK;
3033 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
3034 type == DP_DWN_STRM_PORT_TYPE_OTHER)
3035 return connector_status_unknown;
3038 /* Anything else is out of spec, warn and ignore */
3039 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
3040 return connector_status_disconnected;
3043 static enum drm_connector_status
3044 ironlake_dp_detect(struct intel_dp *intel_dp)
3046 struct drm_device *dev = intel_dp_to_dev(intel_dp);
3047 struct drm_i915_private *dev_priv = dev->dev_private;
3048 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3049 enum drm_connector_status status;
3051 /* Can't disconnect eDP, but you can close the lid... */
3052 if (is_edp(intel_dp)) {
3053 status = intel_panel_detect(dev);
3054 if (status == connector_status_unknown)
3055 status = connector_status_connected;
3059 if (!ibx_digital_port_connected(dev_priv, intel_dig_port))
3060 return connector_status_disconnected;
3062 return intel_dp_detect_dpcd(intel_dp);
3065 static enum drm_connector_status
3066 g4x_dp_detect(struct intel_dp *intel_dp)
3068 struct drm_device *dev = intel_dp_to_dev(intel_dp);
3069 struct drm_i915_private *dev_priv = dev->dev_private;
3070 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3073 /* Can't disconnect eDP, but you can close the lid... */
3074 if (is_edp(intel_dp)) {
3075 enum drm_connector_status status;
3077 status = intel_panel_detect(dev);
3078 if (status == connector_status_unknown)
3079 status = connector_status_connected;
3083 if (IS_VALLEYVIEW(dev)) {
3084 switch (intel_dig_port->port) {
3086 bit = PORTB_HOTPLUG_LIVE_STATUS_VLV;
3089 bit = PORTC_HOTPLUG_LIVE_STATUS_VLV;
3092 bit = PORTD_HOTPLUG_LIVE_STATUS_VLV;
3095 return connector_status_unknown;
3098 switch (intel_dig_port->port) {
3100 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
3103 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
3106 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
3109 return connector_status_unknown;
3113 if ((I915_READ(PORT_HOTPLUG_STAT) & bit) == 0)
3114 return connector_status_disconnected;
3116 return intel_dp_detect_dpcd(intel_dp);
3119 static struct edid *
3120 intel_dp_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
3122 struct intel_connector *intel_connector = to_intel_connector(connector);
3124 /* use cached edid if we have one */
3125 if (intel_connector->edid) {
3127 if (IS_ERR(intel_connector->edid))
3130 return drm_edid_duplicate(intel_connector->edid);
3133 return drm_get_edid(connector, adapter);
3137 intel_dp_get_edid_modes(struct drm_connector *connector, struct i2c_adapter *adapter)
3139 struct intel_connector *intel_connector = to_intel_connector(connector);
3141 /* use cached edid if we have one */
3142 if (intel_connector->edid) {
3144 if (IS_ERR(intel_connector->edid))
3147 return intel_connector_update_modes(connector,
3148 intel_connector->edid);
3151 return intel_ddc_get_modes(connector, adapter);
3154 static enum drm_connector_status
3155 intel_dp_detect(struct drm_connector *connector, bool force)
3157 struct intel_dp *intel_dp = intel_attached_dp(connector);
3158 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3159 struct intel_encoder *intel_encoder = &intel_dig_port->base;
3160 struct drm_device *dev = connector->dev;
3161 struct drm_i915_private *dev_priv = dev->dev_private;
3162 enum drm_connector_status status;
3163 enum intel_display_power_domain power_domain;
3164 struct edid *edid = NULL;
3166 intel_runtime_pm_get(dev_priv);
3168 power_domain = intel_display_port_power_domain(intel_encoder);
3169 intel_display_power_get(dev_priv, power_domain);
3171 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
3172 connector->base.id, drm_get_connector_name(connector));
3174 intel_dp->has_audio = false;
3176 if (HAS_PCH_SPLIT(dev))
3177 status = ironlake_dp_detect(intel_dp);
3179 status = g4x_dp_detect(intel_dp);
3181 if (status != connector_status_connected)
3184 intel_dp_probe_oui(intel_dp);
3186 if (intel_dp->force_audio != HDMI_AUDIO_AUTO) {
3187 intel_dp->has_audio = (intel_dp->force_audio == HDMI_AUDIO_ON);
3189 edid = intel_dp_get_edid(connector, &intel_dp->aux.ddc);
3191 intel_dp->has_audio = drm_detect_monitor_audio(edid);
3196 if (intel_encoder->type != INTEL_OUTPUT_EDP)
3197 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
3198 status = connector_status_connected;
3201 intel_display_power_put(dev_priv, power_domain);
3203 intel_runtime_pm_put(dev_priv);
3208 static int intel_dp_get_modes(struct drm_connector *connector)
3210 struct intel_dp *intel_dp = intel_attached_dp(connector);
3211 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3212 struct intel_encoder *intel_encoder = &intel_dig_port->base;
3213 struct intel_connector *intel_connector = to_intel_connector(connector);
3214 struct drm_device *dev = connector->dev;
3215 struct drm_i915_private *dev_priv = dev->dev_private;
3216 enum intel_display_power_domain power_domain;
3219 /* We should parse the EDID data and find out if it has an audio sink
3222 power_domain = intel_display_port_power_domain(intel_encoder);
3223 intel_display_power_get(dev_priv, power_domain);
3225 ret = intel_dp_get_edid_modes(connector, &intel_dp->aux.ddc);
3226 intel_display_power_put(dev_priv, power_domain);
3230 /* if eDP has no EDID, fall back to fixed mode */
3231 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
3232 struct drm_display_mode *mode;
3233 mode = drm_mode_duplicate(dev,
3234 intel_connector->panel.fixed_mode);
3236 drm_mode_probed_add(connector, mode);
3244 intel_dp_detect_audio(struct drm_connector *connector)
3246 struct intel_dp *intel_dp = intel_attached_dp(connector);
3247 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3248 struct intel_encoder *intel_encoder = &intel_dig_port->base;
3249 struct drm_device *dev = connector->dev;
3250 struct drm_i915_private *dev_priv = dev->dev_private;
3251 enum intel_display_power_domain power_domain;
3253 bool has_audio = false;
3255 power_domain = intel_display_port_power_domain(intel_encoder);
3256 intel_display_power_get(dev_priv, power_domain);
3258 edid = intel_dp_get_edid(connector, &intel_dp->aux.ddc);
3260 has_audio = drm_detect_monitor_audio(edid);
3264 intel_display_power_put(dev_priv, power_domain);
3270 intel_dp_set_property(struct drm_connector *connector,
3271 struct drm_property *property,
3274 struct drm_i915_private *dev_priv = connector->dev->dev_private;
3275 struct intel_connector *intel_connector = to_intel_connector(connector);
3276 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
3277 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
3280 ret = drm_object_property_set_value(&connector->base, property, val);
3284 if (property == dev_priv->force_audio_property) {
3288 if (i == intel_dp->force_audio)
3291 intel_dp->force_audio = i;
3293 if (i == HDMI_AUDIO_AUTO)
3294 has_audio = intel_dp_detect_audio(connector);
3296 has_audio = (i == HDMI_AUDIO_ON);
3298 if (has_audio == intel_dp->has_audio)
3301 intel_dp->has_audio = has_audio;
3305 if (property == dev_priv->broadcast_rgb_property) {
3306 bool old_auto = intel_dp->color_range_auto;
3307 uint32_t old_range = intel_dp->color_range;
3310 case INTEL_BROADCAST_RGB_AUTO:
3311 intel_dp->color_range_auto = true;
3313 case INTEL_BROADCAST_RGB_FULL:
3314 intel_dp->color_range_auto = false;
3315 intel_dp->color_range = 0;
3317 case INTEL_BROADCAST_RGB_LIMITED:
3318 intel_dp->color_range_auto = false;
3319 intel_dp->color_range = DP_COLOR_RANGE_16_235;
3325 if (old_auto == intel_dp->color_range_auto &&
3326 old_range == intel_dp->color_range)
3332 if (is_edp(intel_dp) &&
3333 property == connector->dev->mode_config.scaling_mode_property) {
3334 if (val == DRM_MODE_SCALE_NONE) {
3335 DRM_DEBUG_KMS("no scaling not supported\n");
3339 if (intel_connector->panel.fitting_mode == val) {
3340 /* the eDP scaling property is not changed */
3343 intel_connector->panel.fitting_mode = val;
3351 if (intel_encoder->base.crtc)
3352 intel_crtc_restore_mode(intel_encoder->base.crtc);
3358 intel_dp_connector_destroy(struct drm_connector *connector)
3360 struct intel_connector *intel_connector = to_intel_connector(connector);
3362 if (!IS_ERR_OR_NULL(intel_connector->edid))
3363 kfree(intel_connector->edid);
3365 /* Can't call is_edp() since the encoder may have been destroyed
3367 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
3368 intel_panel_fini(&intel_connector->panel);
3370 drm_connector_cleanup(connector);
3374 void intel_dp_encoder_destroy(struct drm_encoder *encoder)
3376 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
3377 struct intel_dp *intel_dp = &intel_dig_port->dp;
3378 struct drm_device *dev = intel_dp_to_dev(intel_dp);
3380 drm_dp_aux_unregister_i2c_bus(&intel_dp->aux);
3381 drm_encoder_cleanup(encoder);
3382 if (is_edp(intel_dp)) {
3383 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
3384 mutex_lock(&dev->mode_config.mutex);
3385 edp_panel_vdd_off_sync(intel_dp);
3386 mutex_unlock(&dev->mode_config.mutex);
3388 kfree(intel_dig_port);
3391 static const struct drm_connector_funcs intel_dp_connector_funcs = {
3392 .dpms = intel_connector_dpms,
3393 .detect = intel_dp_detect,
3394 .fill_modes = drm_helper_probe_single_connector_modes,
3395 .set_property = intel_dp_set_property,
3396 .destroy = intel_dp_connector_destroy,
3399 static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
3400 .get_modes = intel_dp_get_modes,
3401 .mode_valid = intel_dp_mode_valid,
3402 .best_encoder = intel_best_encoder,
3405 static const struct drm_encoder_funcs intel_dp_enc_funcs = {
3406 .destroy = intel_dp_encoder_destroy,
3410 intel_dp_hot_plug(struct intel_encoder *intel_encoder)
3412 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
3414 intel_dp_check_link_status(intel_dp);
3417 /* Return which DP Port should be selected for Transcoder DP control */
3419 intel_trans_dp_port_sel(struct drm_crtc *crtc)
3421 struct drm_device *dev = crtc->dev;
3422 struct intel_encoder *intel_encoder;
3423 struct intel_dp *intel_dp;
3425 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
3426 intel_dp = enc_to_intel_dp(&intel_encoder->base);
3428 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
3429 intel_encoder->type == INTEL_OUTPUT_EDP)
3430 return intel_dp->output_reg;
3436 /* check the VBT to see whether the eDP is on DP-D port */
3437 bool intel_dp_is_edp(struct drm_device *dev, enum port port)
3439 struct drm_i915_private *dev_priv = dev->dev_private;
3440 union child_device_config *p_child;
3442 static const short port_mapping[] = {
3443 [PORT_B] = PORT_IDPB,
3444 [PORT_C] = PORT_IDPC,
3445 [PORT_D] = PORT_IDPD,
3451 if (!dev_priv->vbt.child_dev_num)
3454 for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
3455 p_child = dev_priv->vbt.child_dev + i;
3457 if (p_child->common.dvo_port == port_mapping[port] &&
3458 (p_child->common.device_type & DEVICE_TYPE_eDP_BITS) ==
3459 (DEVICE_TYPE_eDP & DEVICE_TYPE_eDP_BITS))
3466 intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
3468 struct intel_connector *intel_connector = to_intel_connector(connector);
3470 intel_attach_force_audio_property(connector);
3471 intel_attach_broadcast_rgb_property(connector);
3472 intel_dp->color_range_auto = true;
3474 if (is_edp(intel_dp)) {
3475 drm_mode_create_scaling_mode_property(connector->dev);
3476 drm_object_attach_property(
3478 connector->dev->mode_config.scaling_mode_property,
3479 DRM_MODE_SCALE_ASPECT);
3480 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
3484 static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
3486 intel_dp->last_power_cycle = jiffies;
3487 intel_dp->last_power_on = jiffies;
3488 intel_dp->last_backlight_off = jiffies;
3492 intel_dp_init_panel_power_sequencer(struct drm_device *dev,
3493 struct intel_dp *intel_dp,
3494 struct edp_power_seq *out)
3496 struct drm_i915_private *dev_priv = dev->dev_private;
3497 struct edp_power_seq cur, vbt, spec, final;
3498 u32 pp_on, pp_off, pp_div, pp;
3499 int pp_ctrl_reg, pp_on_reg, pp_off_reg, pp_div_reg;
3501 if (HAS_PCH_SPLIT(dev)) {
3502 pp_ctrl_reg = PCH_PP_CONTROL;
3503 pp_on_reg = PCH_PP_ON_DELAYS;
3504 pp_off_reg = PCH_PP_OFF_DELAYS;
3505 pp_div_reg = PCH_PP_DIVISOR;
3507 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
3509 pp_ctrl_reg = VLV_PIPE_PP_CONTROL(pipe);
3510 pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe);
3511 pp_off_reg = VLV_PIPE_PP_OFF_DELAYS(pipe);
3512 pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe);
3515 /* Workaround: Need to write PP_CONTROL with the unlock key as
3516 * the very first thing. */
3517 pp = ironlake_get_pp_control(intel_dp);
3518 I915_WRITE(pp_ctrl_reg, pp);
3520 pp_on = I915_READ(pp_on_reg);
3521 pp_off = I915_READ(pp_off_reg);
3522 pp_div = I915_READ(pp_div_reg);
3524 /* Pull timing values out of registers */
3525 cur.t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
3526 PANEL_POWER_UP_DELAY_SHIFT;
3528 cur.t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
3529 PANEL_LIGHT_ON_DELAY_SHIFT;
3531 cur.t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
3532 PANEL_LIGHT_OFF_DELAY_SHIFT;
3534 cur.t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
3535 PANEL_POWER_DOWN_DELAY_SHIFT;
3537 cur.t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
3538 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
3540 DRM_DEBUG_KMS("cur t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
3541 cur.t1_t3, cur.t8, cur.t9, cur.t10, cur.t11_t12);
3543 vbt = dev_priv->vbt.edp_pps;
3545 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
3546 * our hw here, which are all in 100usec. */
3547 spec.t1_t3 = 210 * 10;
3548 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
3549 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
3550 spec.t10 = 500 * 10;
3551 /* This one is special and actually in units of 100ms, but zero
3552 * based in the hw (so we need to add 100 ms). But the sw vbt
3553 * table multiplies it with 1000 to make it in units of 100usec,
3555 spec.t11_t12 = (510 + 100) * 10;
3557 DRM_DEBUG_KMS("vbt t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
3558 vbt.t1_t3, vbt.t8, vbt.t9, vbt.t10, vbt.t11_t12);
3560 /* Use the max of the register settings and vbt. If both are
3561 * unset, fall back to the spec limits. */
3562 #define assign_final(field) final.field = (max(cur.field, vbt.field) == 0 ? \
3564 max(cur.field, vbt.field))
3565 assign_final(t1_t3);
3569 assign_final(t11_t12);
3572 #define get_delay(field) (DIV_ROUND_UP(final.field, 10))
3573 intel_dp->panel_power_up_delay = get_delay(t1_t3);
3574 intel_dp->backlight_on_delay = get_delay(t8);
3575 intel_dp->backlight_off_delay = get_delay(t9);
3576 intel_dp->panel_power_down_delay = get_delay(t10);
3577 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
3580 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
3581 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
3582 intel_dp->panel_power_cycle_delay);
3584 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
3585 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
3592 intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
3593 struct intel_dp *intel_dp,
3594 struct edp_power_seq *seq)
3596 struct drm_i915_private *dev_priv = dev->dev_private;
3597 u32 pp_on, pp_off, pp_div, port_sel = 0;
3598 int div = HAS_PCH_SPLIT(dev) ? intel_pch_rawclk(dev) : intel_hrawclk(dev);
3599 int pp_on_reg, pp_off_reg, pp_div_reg;
3601 if (HAS_PCH_SPLIT(dev)) {
3602 pp_on_reg = PCH_PP_ON_DELAYS;
3603 pp_off_reg = PCH_PP_OFF_DELAYS;
3604 pp_div_reg = PCH_PP_DIVISOR;
3606 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
3608 pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe);
3609 pp_off_reg = VLV_PIPE_PP_OFF_DELAYS(pipe);
3610 pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe);
3614 * And finally store the new values in the power sequencer. The
3615 * backlight delays are set to 1 because we do manual waits on them. For
3616 * T8, even BSpec recommends doing it. For T9, if we don't do this,
3617 * we'll end up waiting for the backlight off delay twice: once when we
3618 * do the manual sleep, and once when we disable the panel and wait for
3619 * the PP_STATUS bit to become zero.
3621 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
3622 (1 << PANEL_LIGHT_ON_DELAY_SHIFT);
3623 pp_off = (1 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
3624 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
3625 /* Compute the divisor for the pp clock, simply match the Bspec
3627 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
3628 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
3629 << PANEL_POWER_CYCLE_DELAY_SHIFT);
3631 /* Haswell doesn't have any port selection bits for the panel
3632 * power sequencer any more. */
3633 if (IS_VALLEYVIEW(dev)) {
3634 if (dp_to_dig_port(intel_dp)->port == PORT_B)
3635 port_sel = PANEL_PORT_SELECT_DPB_VLV;
3637 port_sel = PANEL_PORT_SELECT_DPC_VLV;
3638 } else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) {
3639 if (dp_to_dig_port(intel_dp)->port == PORT_A)
3640 port_sel = PANEL_PORT_SELECT_DPA;
3642 port_sel = PANEL_PORT_SELECT_DPD;
3647 I915_WRITE(pp_on_reg, pp_on);
3648 I915_WRITE(pp_off_reg, pp_off);
3649 I915_WRITE(pp_div_reg, pp_div);
3651 DRM_DEBUG_KMS("panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n",
3652 I915_READ(pp_on_reg),
3653 I915_READ(pp_off_reg),
3654 I915_READ(pp_div_reg));
3657 void intel_dp_set_drrs_state(struct drm_device *dev, int refresh_rate)
3659 struct drm_i915_private *dev_priv = dev->dev_private;
3660 struct intel_encoder *encoder;
3661 struct intel_dp *intel_dp = NULL;
3662 struct intel_crtc_config *config = NULL;
3663 struct intel_crtc *intel_crtc = NULL;
3664 struct intel_connector *intel_connector = dev_priv->drrs.connector;
3666 enum edp_drrs_refresh_rate_type index = DRRS_HIGH_RR;
3668 if (refresh_rate <= 0) {
3669 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
3673 if (intel_connector == NULL) {
3674 DRM_DEBUG_KMS("DRRS supported for eDP only.\n");
3678 if (INTEL_INFO(dev)->gen < 8 && intel_edp_is_psr_enabled(dev)) {
3679 DRM_DEBUG_KMS("DRRS is disabled as PSR is enabled\n");
3683 encoder = intel_attached_encoder(&intel_connector->base);
3684 intel_dp = enc_to_intel_dp(&encoder->base);
3685 intel_crtc = encoder->new_crtc;
3688 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
3692 config = &intel_crtc->config;
3694 if (intel_dp->drrs_state.type < SEAMLESS_DRRS_SUPPORT) {
3695 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
3699 if (intel_connector->panel.downclock_mode->vrefresh == refresh_rate)
3700 index = DRRS_LOW_RR;
3702 if (index == intel_dp->drrs_state.refresh_rate_type) {
3704 "DRRS requested for previously set RR...ignoring\n");
3708 if (!intel_crtc->active) {
3709 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
3713 if (INTEL_INFO(dev)->gen > 6 && INTEL_INFO(dev)->gen < 8) {
3714 reg = PIPECONF(intel_crtc->config.cpu_transcoder);
3715 val = I915_READ(reg);
3716 if (index > DRRS_HIGH_RR) {
3717 val |= PIPECONF_EDP_RR_MODE_SWITCH;
3718 intel_dp_set_m2_n2(intel_crtc, &config->dp_m2_n2);
3720 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
3722 I915_WRITE(reg, val);
3726 * mutex taken to ensure that there is no race between differnt
3727 * drrs calls trying to update refresh rate. This scenario may occur
3728 * in future when idleness detection based DRRS in kernel and
3729 * possible calls from user space to set differnt RR are made.
3732 mutex_lock(&intel_dp->drrs_state.mutex);
3734 intel_dp->drrs_state.refresh_rate_type = index;
3736 mutex_unlock(&intel_dp->drrs_state.mutex);
3738 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
3741 static struct drm_display_mode *
3742 intel_dp_drrs_init(struct intel_digital_port *intel_dig_port,
3743 struct intel_connector *intel_connector,
3744 struct drm_display_mode *fixed_mode)
3746 struct drm_connector *connector = &intel_connector->base;
3747 struct intel_dp *intel_dp = &intel_dig_port->dp;
3748 struct drm_device *dev = intel_dig_port->base.base.dev;
3749 struct drm_i915_private *dev_priv = dev->dev_private;
3750 struct drm_display_mode *downclock_mode = NULL;
3752 if (INTEL_INFO(dev)->gen <= 6) {
3753 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
3757 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
3758 DRM_INFO("VBT doesn't support DRRS\n");
3762 downclock_mode = intel_find_panel_downclock
3763 (dev, fixed_mode, connector);
3765 if (!downclock_mode) {
3766 DRM_INFO("DRRS not supported\n");
3770 dev_priv->drrs.connector = intel_connector;
3772 mutex_init(&intel_dp->drrs_state.mutex);
3774 intel_dp->drrs_state.type = dev_priv->vbt.drrs_type;
3776 intel_dp->drrs_state.refresh_rate_type = DRRS_HIGH_RR;
3777 DRM_INFO("seamless DRRS supported for eDP panel.\n");
3778 return downclock_mode;
3781 static bool intel_edp_init_connector(struct intel_dp *intel_dp,
3782 struct intel_connector *intel_connector,
3783 struct edp_power_seq *power_seq)
3785 struct drm_connector *connector = &intel_connector->base;
3786 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3787 struct drm_device *dev = intel_dig_port->base.base.dev;
3788 struct drm_i915_private *dev_priv = dev->dev_private;
3789 struct drm_display_mode *fixed_mode = NULL;
3790 struct drm_display_mode *downclock_mode = NULL;
3792 struct drm_display_mode *scan;
3795 intel_dp->drrs_state.type = DRRS_NOT_SUPPORTED;
3797 if (!is_edp(intel_dp))
3800 /* Cache DPCD and EDID for edp. */
3801 intel_edp_panel_vdd_on(intel_dp);
3802 has_dpcd = intel_dp_get_dpcd(intel_dp);
3803 edp_panel_vdd_off(intel_dp, false);
3806 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3807 dev_priv->no_aux_handshake =
3808 intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3809 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3811 /* if this fails, presume the device is a ghost */
3812 DRM_INFO("failed to retrieve link info, disabling eDP\n");
3816 /* We now know it's not a ghost, init power sequence regs. */
3817 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, power_seq);
3819 mutex_lock(&dev->mode_config.mutex);
3820 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
3822 if (drm_add_edid_modes(connector, edid)) {
3823 drm_mode_connector_update_edid_property(connector,
3825 drm_edid_to_eld(connector, edid);
3828 edid = ERR_PTR(-EINVAL);
3831 edid = ERR_PTR(-ENOENT);
3833 intel_connector->edid = edid;
3835 /* prefer fixed mode from EDID if available */
3836 list_for_each_entry(scan, &connector->probed_modes, head) {
3837 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
3838 fixed_mode = drm_mode_duplicate(dev, scan);
3839 downclock_mode = intel_dp_drrs_init(
3841 intel_connector, fixed_mode);
3846 /* fallback to VBT if available for eDP */
3847 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
3848 fixed_mode = drm_mode_duplicate(dev,
3849 dev_priv->vbt.lfp_lvds_vbt_mode);
3851 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
3853 mutex_unlock(&dev->mode_config.mutex);
3855 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
3856 intel_panel_setup_backlight(connector);
3862 intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
3863 struct intel_connector *intel_connector)
3865 struct drm_connector *connector = &intel_connector->base;
3866 struct intel_dp *intel_dp = &intel_dig_port->dp;
3867 struct intel_encoder *intel_encoder = &intel_dig_port->base;
3868 struct drm_device *dev = intel_encoder->base.dev;
3869 struct drm_i915_private *dev_priv = dev->dev_private;
3870 enum port port = intel_dig_port->port;
3871 struct edp_power_seq power_seq = { 0 };
3874 /* intel_dp vfuncs */
3875 if (IS_VALLEYVIEW(dev))
3876 intel_dp->get_aux_clock_divider = vlv_get_aux_clock_divider;
3877 else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
3878 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
3879 else if (HAS_PCH_SPLIT(dev))
3880 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
3882 intel_dp->get_aux_clock_divider = i9xx_get_aux_clock_divider;
3884 intel_dp->get_aux_send_ctl = i9xx_get_aux_send_ctl;
3886 /* Preserve the current hw state. */
3887 intel_dp->DP = I915_READ(intel_dp->output_reg);
3888 intel_dp->attached_connector = intel_connector;
3890 if (intel_dp_is_edp(dev, port))
3891 type = DRM_MODE_CONNECTOR_eDP;
3893 type = DRM_MODE_CONNECTOR_DisplayPort;
3896 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
3897 * for DP the encoder type can be set by the caller to
3898 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
3900 if (type == DRM_MODE_CONNECTOR_eDP)
3901 intel_encoder->type = INTEL_OUTPUT_EDP;
3903 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
3904 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
3907 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
3908 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
3910 connector->interlace_allowed = true;
3911 connector->doublescan_allowed = 0;
3913 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
3914 edp_panel_vdd_work);
3916 intel_connector_attach_encoder(intel_connector, intel_encoder);
3917 drm_sysfs_connector_add(connector);
3920 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
3922 intel_connector->get_hw_state = intel_connector_get_hw_state;
3923 intel_connector->unregister = intel_dp_connector_unregister;
3925 /* Set up the hotplug pin. */
3928 intel_encoder->hpd_pin = HPD_PORT_A;
3931 intel_encoder->hpd_pin = HPD_PORT_B;
3934 intel_encoder->hpd_pin = HPD_PORT_C;
3937 intel_encoder->hpd_pin = HPD_PORT_D;
3943 if (is_edp(intel_dp)) {
3944 intel_dp_init_panel_power_timestamps(intel_dp);
3945 intel_dp_init_panel_power_sequencer(dev, intel_dp, &power_seq);
3948 intel_dp_aux_init(intel_dp, intel_connector);
3950 intel_dp->psr_setup_done = false;
3952 if (!intel_edp_init_connector(intel_dp, intel_connector, &power_seq)) {
3953 drm_dp_aux_unregister_i2c_bus(&intel_dp->aux);
3954 if (is_edp(intel_dp)) {
3955 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
3956 mutex_lock(&dev->mode_config.mutex);
3957 edp_panel_vdd_off_sync(intel_dp);
3958 mutex_unlock(&dev->mode_config.mutex);
3960 drm_sysfs_connector_remove(connector);
3961 drm_connector_cleanup(connector);
3965 intel_dp_add_properties(intel_dp, connector);
3967 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
3968 * 0xd. Failure to do so will result in spurious interrupts being
3969 * generated on the port when a cable is not attached.
3971 if (IS_G4X(dev) && !IS_GM45(dev)) {
3972 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
3973 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
3980 intel_dp_init(struct drm_device *dev, int output_reg, enum port port)
3982 struct intel_digital_port *intel_dig_port;
3983 struct intel_encoder *intel_encoder;
3984 struct drm_encoder *encoder;
3985 struct intel_connector *intel_connector;
3987 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
3988 if (!intel_dig_port)
3991 intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
3992 if (!intel_connector) {
3993 kfree(intel_dig_port);
3997 intel_encoder = &intel_dig_port->base;
3998 encoder = &intel_encoder->base;
4000 drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
4001 DRM_MODE_ENCODER_TMDS);
4003 intel_encoder->compute_config = intel_dp_compute_config;
4004 intel_encoder->mode_set = intel_dp_mode_set;
4005 intel_encoder->disable = intel_disable_dp;
4006 intel_encoder->get_hw_state = intel_dp_get_hw_state;
4007 intel_encoder->get_config = intel_dp_get_config;
4008 if (IS_VALLEYVIEW(dev)) {
4009 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
4010 intel_encoder->pre_enable = vlv_pre_enable_dp;
4011 intel_encoder->enable = vlv_enable_dp;
4012 intel_encoder->post_disable = vlv_post_disable_dp;
4014 intel_encoder->pre_enable = g4x_pre_enable_dp;
4015 intel_encoder->enable = g4x_enable_dp;
4016 intel_encoder->post_disable = g4x_post_disable_dp;
4019 intel_dig_port->port = port;
4020 intel_dig_port->dp.output_reg = output_reg;
4022 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
4023 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
4024 intel_encoder->cloneable = 0;
4025 intel_encoder->hot_plug = intel_dp_hot_plug;
4027 if (!intel_dp_init_connector(intel_dig_port, intel_connector)) {
4028 drm_encoder_cleanup(encoder);
4029 kfree(intel_dig_port);
4030 kfree(intel_connector);