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 * CHV supports eDP 1.4 that have more link rates.
69 * Below only provides the fixed rate but exclude variable rate.
71 static const struct dp_link_dpll chv_dpll[] = {
73 * CHV requires to program fractional division for m2.
74 * m2 is stored in fixed point format using formula below
75 * (m2_int << 22) | m2_fraction
77 { DP_LINK_BW_1_62, /* m2_int = 32, m2_fraction = 1677722 */
78 { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } },
79 { DP_LINK_BW_2_7, /* m2_int = 27, m2_fraction = 0 */
80 { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } },
81 { DP_LINK_BW_5_4, /* m2_int = 27, m2_fraction = 0 */
82 { .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }
86 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
87 * @intel_dp: DP struct
89 * If a CPU or PCH DP output is attached to an eDP panel, this function
90 * will return true, and false otherwise.
92 static bool is_edp(struct intel_dp *intel_dp)
94 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
96 return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
99 static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp)
101 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
103 return intel_dig_port->base.base.dev;
106 static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
108 return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
111 static void intel_dp_link_down(struct intel_dp *intel_dp);
112 static bool _edp_panel_vdd_on(struct intel_dp *intel_dp);
113 static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
116 intel_dp_max_link_bw(struct intel_dp *intel_dp)
118 int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
119 struct drm_device *dev = intel_dp->attached_connector->base.dev;
121 switch (max_link_bw) {
122 case DP_LINK_BW_1_62:
125 case DP_LINK_BW_5_4: /* 1.2 capable displays may advertise higher bw */
126 if ((IS_HASWELL(dev) || INTEL_INFO(dev)->gen >= 8) &&
127 intel_dp->dpcd[DP_DPCD_REV] >= 0x12)
128 max_link_bw = DP_LINK_BW_5_4;
130 max_link_bw = DP_LINK_BW_2_7;
133 WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
135 max_link_bw = DP_LINK_BW_1_62;
142 * The units on the numbers in the next two are... bizarre. Examples will
143 * make it clearer; this one parallels an example in the eDP spec.
145 * intel_dp_max_data_rate for one lane of 2.7GHz evaluates as:
147 * 270000 * 1 * 8 / 10 == 216000
149 * The actual data capacity of that configuration is 2.16Gbit/s, so the
150 * units are decakilobits. ->clock in a drm_display_mode is in kilohertz -
151 * or equivalently, kilopixels per second - so for 1680x1050R it'd be
152 * 119000. At 18bpp that's 2142000 kilobits per second.
154 * Thus the strange-looking division by 10 in intel_dp_link_required, to
155 * get the result in decakilobits instead of kilobits.
159 intel_dp_link_required(int pixel_clock, int bpp)
161 return (pixel_clock * bpp + 9) / 10;
165 intel_dp_max_data_rate(int max_link_clock, int max_lanes)
167 return (max_link_clock * max_lanes * 8) / 10;
170 static enum drm_mode_status
171 intel_dp_mode_valid(struct drm_connector *connector,
172 struct drm_display_mode *mode)
174 struct intel_dp *intel_dp = intel_attached_dp(connector);
175 struct intel_connector *intel_connector = to_intel_connector(connector);
176 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
177 int target_clock = mode->clock;
178 int max_rate, mode_rate, max_lanes, max_link_clock;
180 if (is_edp(intel_dp) && fixed_mode) {
181 if (mode->hdisplay > fixed_mode->hdisplay)
184 if (mode->vdisplay > fixed_mode->vdisplay)
187 target_clock = fixed_mode->clock;
190 max_link_clock = drm_dp_bw_code_to_link_rate(intel_dp_max_link_bw(intel_dp));
191 max_lanes = drm_dp_max_lane_count(intel_dp->dpcd);
193 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
194 mode_rate = intel_dp_link_required(target_clock, 18);
196 if (mode_rate > max_rate)
197 return MODE_CLOCK_HIGH;
199 if (mode->clock < 10000)
200 return MODE_CLOCK_LOW;
202 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
203 return MODE_H_ILLEGAL;
209 pack_aux(uint8_t *src, int src_bytes)
216 for (i = 0; i < src_bytes; i++)
217 v |= ((uint32_t) src[i]) << ((3-i) * 8);
222 unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
227 for (i = 0; i < dst_bytes; i++)
228 dst[i] = src >> ((3-i) * 8);
231 /* hrawclock is 1/4 the FSB frequency */
233 intel_hrawclk(struct drm_device *dev)
235 struct drm_i915_private *dev_priv = dev->dev_private;
238 /* There is no CLKCFG reg in Valleyview. VLV hrawclk is 200 MHz */
239 if (IS_VALLEYVIEW(dev))
242 clkcfg = I915_READ(CLKCFG);
243 switch (clkcfg & CLKCFG_FSB_MASK) {
252 case CLKCFG_FSB_1067:
254 case CLKCFG_FSB_1333:
256 /* these two are just a guess; one of them might be right */
257 case CLKCFG_FSB_1600:
258 case CLKCFG_FSB_1600_ALT:
266 intel_dp_init_panel_power_sequencer(struct drm_device *dev,
267 struct intel_dp *intel_dp,
268 struct edp_power_seq *out);
270 intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
271 struct intel_dp *intel_dp,
272 struct edp_power_seq *out);
275 vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
277 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
278 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
279 struct drm_device *dev = intel_dig_port->base.base.dev;
280 struct drm_i915_private *dev_priv = dev->dev_private;
281 enum port port = intel_dig_port->port;
284 /* modeset should have pipe */
286 return to_intel_crtc(crtc)->pipe;
288 /* init time, try to find a pipe with this port selected */
289 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
290 u32 port_sel = I915_READ(VLV_PIPE_PP_ON_DELAYS(pipe)) &
291 PANEL_PORT_SELECT_MASK;
292 if (port_sel == PANEL_PORT_SELECT_DPB_VLV && port == PORT_B)
294 if (port_sel == PANEL_PORT_SELECT_DPC_VLV && port == PORT_C)
302 static u32 _pp_ctrl_reg(struct intel_dp *intel_dp)
304 struct drm_device *dev = intel_dp_to_dev(intel_dp);
306 if (HAS_PCH_SPLIT(dev))
307 return PCH_PP_CONTROL;
309 return VLV_PIPE_PP_CONTROL(vlv_power_sequencer_pipe(intel_dp));
312 static u32 _pp_stat_reg(struct intel_dp *intel_dp)
314 struct drm_device *dev = intel_dp_to_dev(intel_dp);
316 if (HAS_PCH_SPLIT(dev))
317 return PCH_PP_STATUS;
319 return VLV_PIPE_PP_STATUS(vlv_power_sequencer_pipe(intel_dp));
322 static bool edp_have_panel_power(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 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
330 static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
332 struct drm_device *dev = intel_dp_to_dev(intel_dp);
333 struct drm_i915_private *dev_priv = dev->dev_private;
334 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
335 struct intel_encoder *intel_encoder = &intel_dig_port->base;
336 enum intel_display_power_domain power_domain;
338 power_domain = intel_display_port_power_domain(intel_encoder);
339 return intel_display_power_enabled(dev_priv, power_domain) &&
340 (I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD) != 0;
344 intel_dp_check_edp(struct intel_dp *intel_dp)
346 struct drm_device *dev = intel_dp_to_dev(intel_dp);
347 struct drm_i915_private *dev_priv = dev->dev_private;
349 if (!is_edp(intel_dp))
352 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
353 WARN(1, "eDP powered off while attempting aux channel communication.\n");
354 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
355 I915_READ(_pp_stat_reg(intel_dp)),
356 I915_READ(_pp_ctrl_reg(intel_dp)));
361 intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
363 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
364 struct drm_device *dev = intel_dig_port->base.base.dev;
365 struct drm_i915_private *dev_priv = dev->dev_private;
366 uint32_t ch_ctl = intel_dp->aux_ch_ctl_reg;
370 #define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
372 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
373 msecs_to_jiffies_timeout(10));
375 done = wait_for_atomic(C, 10) == 0;
377 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
384 static uint32_t i9xx_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
386 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
387 struct drm_device *dev = intel_dig_port->base.base.dev;
390 * The clock divider is based off the hrawclk, and would like to run at
391 * 2MHz. So, take the hrawclk value and divide by 2 and use that
393 return index ? 0 : intel_hrawclk(dev) / 2;
396 static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
398 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
399 struct drm_device *dev = intel_dig_port->base.base.dev;
404 if (intel_dig_port->port == PORT_A) {
405 if (IS_GEN6(dev) || IS_GEN7(dev))
406 return 200; /* SNB & IVB eDP input clock at 400Mhz */
408 return 225; /* eDP input clock at 450Mhz */
410 return DIV_ROUND_UP(intel_pch_rawclk(dev), 2);
414 static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
416 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
417 struct drm_device *dev = intel_dig_port->base.base.dev;
418 struct drm_i915_private *dev_priv = dev->dev_private;
420 if (intel_dig_port->port == PORT_A) {
423 return DIV_ROUND_CLOSEST(intel_ddi_get_cdclk_freq(dev_priv), 2000);
424 } else if (dev_priv->pch_id == INTEL_PCH_LPT_DEVICE_ID_TYPE) {
425 /* Workaround for non-ULT HSW */
432 return index ? 0 : DIV_ROUND_UP(intel_pch_rawclk(dev), 2);
436 static uint32_t vlv_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
438 return index ? 0 : 100;
441 static uint32_t i9xx_get_aux_send_ctl(struct intel_dp *intel_dp,
444 uint32_t aux_clock_divider)
446 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
447 struct drm_device *dev = intel_dig_port->base.base.dev;
448 uint32_t precharge, timeout;
455 if (IS_BROADWELL(dev) && intel_dp->aux_ch_ctl_reg == DPA_AUX_CH_CTL)
456 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
458 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
460 return DP_AUX_CH_CTL_SEND_BUSY |
462 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
463 DP_AUX_CH_CTL_TIME_OUT_ERROR |
465 DP_AUX_CH_CTL_RECEIVE_ERROR |
466 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
467 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
468 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
472 intel_dp_aux_ch(struct intel_dp *intel_dp,
473 uint8_t *send, int send_bytes,
474 uint8_t *recv, int recv_size)
476 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
477 struct drm_device *dev = intel_dig_port->base.base.dev;
478 struct drm_i915_private *dev_priv = dev->dev_private;
479 uint32_t ch_ctl = intel_dp->aux_ch_ctl_reg;
480 uint32_t ch_data = ch_ctl + 4;
481 uint32_t aux_clock_divider;
482 int i, ret, recv_bytes;
485 bool has_aux_irq = HAS_AUX_IRQ(dev);
488 vdd = _edp_panel_vdd_on(intel_dp);
490 /* dp aux is extremely sensitive to irq latency, hence request the
491 * lowest possible wakeup latency and so prevent the cpu from going into
494 pm_qos_update_request(&dev_priv->pm_qos, 0);
496 intel_dp_check_edp(intel_dp);
498 intel_aux_display_runtime_get(dev_priv);
500 /* Try to wait for any previous AUX channel activity */
501 for (try = 0; try < 3; try++) {
502 status = I915_READ_NOTRACE(ch_ctl);
503 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
509 WARN(1, "dp_aux_ch not started status 0x%08x\n",
515 /* Only 5 data registers! */
516 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
521 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
522 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
527 /* Must try at least 3 times according to DP spec */
528 for (try = 0; try < 5; try++) {
529 /* Load the send data into the aux channel data registers */
530 for (i = 0; i < send_bytes; i += 4)
531 I915_WRITE(ch_data + i,
532 pack_aux(send + i, send_bytes - i));
534 /* Send the command and wait for it to complete */
535 I915_WRITE(ch_ctl, send_ctl);
537 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
539 /* Clear done status and any errors */
543 DP_AUX_CH_CTL_TIME_OUT_ERROR |
544 DP_AUX_CH_CTL_RECEIVE_ERROR);
546 if (status & (DP_AUX_CH_CTL_TIME_OUT_ERROR |
547 DP_AUX_CH_CTL_RECEIVE_ERROR))
549 if (status & DP_AUX_CH_CTL_DONE)
552 if (status & DP_AUX_CH_CTL_DONE)
556 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
557 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
562 /* Check for timeout or receive error.
563 * Timeouts occur when the sink is not connected
565 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
566 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
571 /* Timeouts occur when the device isn't connected, so they're
572 * "normal" -- don't fill the kernel log with these */
573 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
574 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
579 /* Unload any bytes sent back from the other side */
580 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
581 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
582 if (recv_bytes > recv_size)
583 recv_bytes = recv_size;
585 for (i = 0; i < recv_bytes; i += 4)
586 unpack_aux(I915_READ(ch_data + i),
587 recv + i, recv_bytes - i);
591 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
592 intel_aux_display_runtime_put(dev_priv);
595 edp_panel_vdd_off(intel_dp, false);
600 #define BARE_ADDRESS_SIZE 3
601 #define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
603 intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
605 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
606 uint8_t txbuf[20], rxbuf[20];
607 size_t txsize, rxsize;
610 txbuf[0] = msg->request << 4;
611 txbuf[1] = msg->address >> 8;
612 txbuf[2] = msg->address & 0xff;
613 txbuf[3] = msg->size - 1;
615 switch (msg->request & ~DP_AUX_I2C_MOT) {
616 case DP_AUX_NATIVE_WRITE:
617 case DP_AUX_I2C_WRITE:
618 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
621 if (WARN_ON(txsize > 20))
624 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
626 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
628 msg->reply = rxbuf[0] >> 4;
630 /* Return payload size. */
635 case DP_AUX_NATIVE_READ:
636 case DP_AUX_I2C_READ:
637 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
638 rxsize = msg->size + 1;
640 if (WARN_ON(rxsize > 20))
643 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
645 msg->reply = rxbuf[0] >> 4;
647 * Assume happy day, and copy the data. The caller is
648 * expected to check msg->reply before touching it.
650 * Return payload size.
653 memcpy(msg->buffer, rxbuf + 1, ret);
666 intel_dp_aux_init(struct intel_dp *intel_dp, struct intel_connector *connector)
668 struct drm_device *dev = intel_dp_to_dev(intel_dp);
669 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
670 enum port port = intel_dig_port->port;
671 const char *name = NULL;
676 intel_dp->aux_ch_ctl_reg = DPA_AUX_CH_CTL;
680 intel_dp->aux_ch_ctl_reg = PCH_DPB_AUX_CH_CTL;
684 intel_dp->aux_ch_ctl_reg = PCH_DPC_AUX_CH_CTL;
688 intel_dp->aux_ch_ctl_reg = PCH_DPD_AUX_CH_CTL;
696 intel_dp->aux_ch_ctl_reg = intel_dp->output_reg + 0x10;
698 intel_dp->aux.name = name;
699 intel_dp->aux.dev = dev->dev;
700 intel_dp->aux.transfer = intel_dp_aux_transfer;
702 DRM_DEBUG_KMS("registering %s bus for %s\n", name,
703 connector->base.kdev->kobj.name);
705 ret = drm_dp_aux_register_i2c_bus(&intel_dp->aux);
707 DRM_ERROR("drm_dp_aux_register_i2c_bus() for %s failed (%d)\n",
712 ret = sysfs_create_link(&connector->base.kdev->kobj,
713 &intel_dp->aux.ddc.dev.kobj,
714 intel_dp->aux.ddc.dev.kobj.name);
716 DRM_ERROR("sysfs_create_link() for %s failed (%d)\n", name, ret);
717 drm_dp_aux_unregister_i2c_bus(&intel_dp->aux);
722 intel_dp_connector_unregister(struct intel_connector *intel_connector)
724 struct intel_dp *intel_dp = intel_attached_dp(&intel_connector->base);
726 sysfs_remove_link(&intel_connector->base.kdev->kobj,
727 intel_dp->aux.ddc.dev.kobj.name);
728 intel_connector_unregister(intel_connector);
732 intel_dp_set_clock(struct intel_encoder *encoder,
733 struct intel_crtc_config *pipe_config, int link_bw)
735 struct drm_device *dev = encoder->base.dev;
736 const struct dp_link_dpll *divisor = NULL;
741 count = ARRAY_SIZE(gen4_dpll);
742 } else if (IS_HASWELL(dev)) {
743 /* Haswell has special-purpose DP DDI clocks. */
744 } else if (HAS_PCH_SPLIT(dev)) {
746 count = ARRAY_SIZE(pch_dpll);
747 } else if (IS_CHERRYVIEW(dev)) {
749 count = ARRAY_SIZE(chv_dpll);
750 } else if (IS_VALLEYVIEW(dev)) {
752 count = ARRAY_SIZE(vlv_dpll);
755 if (divisor && count) {
756 for (i = 0; i < count; i++) {
757 if (link_bw == divisor[i].link_bw) {
758 pipe_config->dpll = divisor[i].dpll;
759 pipe_config->clock_set = true;
767 intel_dp_set_m2_n2(struct intel_crtc *crtc, struct intel_link_m_n *m_n)
769 struct drm_device *dev = crtc->base.dev;
770 struct drm_i915_private *dev_priv = dev->dev_private;
771 enum transcoder transcoder = crtc->config.cpu_transcoder;
773 I915_WRITE(PIPE_DATA_M2(transcoder),
774 TU_SIZE(m_n->tu) | m_n->gmch_m);
775 I915_WRITE(PIPE_DATA_N2(transcoder), m_n->gmch_n);
776 I915_WRITE(PIPE_LINK_M2(transcoder), m_n->link_m);
777 I915_WRITE(PIPE_LINK_N2(transcoder), m_n->link_n);
781 intel_dp_compute_config(struct intel_encoder *encoder,
782 struct intel_crtc_config *pipe_config)
784 struct drm_device *dev = encoder->base.dev;
785 struct drm_i915_private *dev_priv = dev->dev_private;
786 struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
787 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
788 enum port port = dp_to_dig_port(intel_dp)->port;
789 struct intel_crtc *intel_crtc = encoder->new_crtc;
790 struct intel_connector *intel_connector = intel_dp->attached_connector;
791 int lane_count, clock;
792 int max_lane_count = drm_dp_max_lane_count(intel_dp->dpcd);
793 /* Conveniently, the link BW constants become indices with a shift...*/
794 int max_clock = intel_dp_max_link_bw(intel_dp) >> 3;
796 static int bws[] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7, DP_LINK_BW_5_4 };
797 int link_avail, link_clock;
799 if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev) && port != PORT_A)
800 pipe_config->has_pch_encoder = true;
802 pipe_config->has_dp_encoder = true;
804 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
805 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
807 if (!HAS_PCH_SPLIT(dev))
808 intel_gmch_panel_fitting(intel_crtc, pipe_config,
809 intel_connector->panel.fitting_mode);
811 intel_pch_panel_fitting(intel_crtc, pipe_config,
812 intel_connector->panel.fitting_mode);
815 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
818 DRM_DEBUG_KMS("DP link computation with max lane count %i "
819 "max bw %02x pixel clock %iKHz\n",
820 max_lane_count, bws[max_clock],
821 adjusted_mode->crtc_clock);
823 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
825 bpp = pipe_config->pipe_bpp;
826 if (is_edp(intel_dp) && dev_priv->vbt.edp_bpp &&
827 dev_priv->vbt.edp_bpp < bpp) {
828 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
829 dev_priv->vbt.edp_bpp);
830 bpp = dev_priv->vbt.edp_bpp;
833 for (; bpp >= 6*3; bpp -= 2*3) {
834 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
837 for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) {
838 for (clock = 0; clock <= max_clock; clock++) {
839 link_clock = drm_dp_bw_code_to_link_rate(bws[clock]);
840 link_avail = intel_dp_max_data_rate(link_clock,
843 if (mode_rate <= link_avail) {
853 if (intel_dp->color_range_auto) {
856 * CEA-861-E - 5.1 Default Encoding Parameters
857 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
859 if (bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1)
860 intel_dp->color_range = DP_COLOR_RANGE_16_235;
862 intel_dp->color_range = 0;
865 if (intel_dp->color_range)
866 pipe_config->limited_color_range = true;
868 intel_dp->link_bw = bws[clock];
869 intel_dp->lane_count = lane_count;
870 pipe_config->pipe_bpp = bpp;
871 pipe_config->port_clock = drm_dp_bw_code_to_link_rate(intel_dp->link_bw);
873 DRM_DEBUG_KMS("DP link bw %02x lane count %d clock %d bpp %d\n",
874 intel_dp->link_bw, intel_dp->lane_count,
875 pipe_config->port_clock, bpp);
876 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
877 mode_rate, link_avail);
879 intel_link_compute_m_n(bpp, lane_count,
880 adjusted_mode->crtc_clock,
881 pipe_config->port_clock,
882 &pipe_config->dp_m_n);
884 if (intel_connector->panel.downclock_mode != NULL &&
885 intel_dp->drrs_state.type == SEAMLESS_DRRS_SUPPORT) {
886 intel_link_compute_m_n(bpp, lane_count,
887 intel_connector->panel.downclock_mode->clock,
888 pipe_config->port_clock,
889 &pipe_config->dp_m2_n2);
892 intel_dp_set_clock(encoder, pipe_config, intel_dp->link_bw);
897 static void ironlake_set_pll_cpu_edp(struct intel_dp *intel_dp)
899 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
900 struct intel_crtc *crtc = to_intel_crtc(dig_port->base.base.crtc);
901 struct drm_device *dev = crtc->base.dev;
902 struct drm_i915_private *dev_priv = dev->dev_private;
905 DRM_DEBUG_KMS("eDP PLL enable for clock %d\n", crtc->config.port_clock);
906 dpa_ctl = I915_READ(DP_A);
907 dpa_ctl &= ~DP_PLL_FREQ_MASK;
909 if (crtc->config.port_clock == 162000) {
910 /* For a long time we've carried around a ILK-DevA w/a for the
911 * 160MHz clock. If we're really unlucky, it's still required.
913 DRM_DEBUG_KMS("160MHz cpu eDP clock, might need ilk devA w/a\n");
914 dpa_ctl |= DP_PLL_FREQ_160MHZ;
915 intel_dp->DP |= DP_PLL_FREQ_160MHZ;
917 dpa_ctl |= DP_PLL_FREQ_270MHZ;
918 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
921 I915_WRITE(DP_A, dpa_ctl);
927 static void intel_dp_mode_set(struct intel_encoder *encoder)
929 struct drm_device *dev = encoder->base.dev;
930 struct drm_i915_private *dev_priv = dev->dev_private;
931 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
932 enum port port = dp_to_dig_port(intel_dp)->port;
933 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
934 struct drm_display_mode *adjusted_mode = &crtc->config.adjusted_mode;
937 * There are four kinds of DP registers:
944 * IBX PCH and CPU are the same for almost everything,
945 * except that the CPU DP PLL is configured in this
948 * CPT PCH is quite different, having many bits moved
949 * to the TRANS_DP_CTL register instead. That
950 * configuration happens (oddly) in ironlake_pch_enable
953 /* Preserve the BIOS-computed detected bit. This is
954 * supposed to be read-only.
956 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
958 /* Handle DP bits in common between all three register formats */
959 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
960 intel_dp->DP |= DP_PORT_WIDTH(intel_dp->lane_count);
962 if (intel_dp->has_audio) {
963 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
964 pipe_name(crtc->pipe));
965 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
966 intel_write_eld(&encoder->base, adjusted_mode);
969 /* Split out the IBX/CPU vs CPT settings */
971 if (port == PORT_A && IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) {
972 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
973 intel_dp->DP |= DP_SYNC_HS_HIGH;
974 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
975 intel_dp->DP |= DP_SYNC_VS_HIGH;
976 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
978 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
979 intel_dp->DP |= DP_ENHANCED_FRAMING;
981 intel_dp->DP |= crtc->pipe << 29;
982 } else if (!HAS_PCH_CPT(dev) || port == PORT_A) {
983 if (!HAS_PCH_SPLIT(dev) && !IS_VALLEYVIEW(dev))
984 intel_dp->DP |= intel_dp->color_range;
986 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
987 intel_dp->DP |= DP_SYNC_HS_HIGH;
988 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
989 intel_dp->DP |= DP_SYNC_VS_HIGH;
990 intel_dp->DP |= DP_LINK_TRAIN_OFF;
992 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
993 intel_dp->DP |= DP_ENHANCED_FRAMING;
995 if (!IS_CHERRYVIEW(dev)) {
997 intel_dp->DP |= DP_PIPEB_SELECT;
999 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
1002 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1005 if (port == PORT_A && !IS_VALLEYVIEW(dev))
1006 ironlake_set_pll_cpu_edp(intel_dp);
1009 #define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1010 #define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
1012 #define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1013 #define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
1015 #define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1016 #define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
1018 static void wait_panel_status(struct intel_dp *intel_dp,
1022 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1023 struct drm_i915_private *dev_priv = dev->dev_private;
1024 u32 pp_stat_reg, pp_ctrl_reg;
1026 pp_stat_reg = _pp_stat_reg(intel_dp);
1027 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
1029 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
1031 I915_READ(pp_stat_reg),
1032 I915_READ(pp_ctrl_reg));
1034 if (_wait_for((I915_READ(pp_stat_reg) & mask) == value, 5000, 10)) {
1035 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
1036 I915_READ(pp_stat_reg),
1037 I915_READ(pp_ctrl_reg));
1040 DRM_DEBUG_KMS("Wait complete\n");
1043 static void wait_panel_on(struct intel_dp *intel_dp)
1045 DRM_DEBUG_KMS("Wait for panel power on\n");
1046 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
1049 static void wait_panel_off(struct intel_dp *intel_dp)
1051 DRM_DEBUG_KMS("Wait for panel power off time\n");
1052 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
1055 static void wait_panel_power_cycle(struct intel_dp *intel_dp)
1057 DRM_DEBUG_KMS("Wait for panel power cycle\n");
1059 /* When we disable the VDD override bit last we have to do the manual
1061 wait_remaining_ms_from_jiffies(intel_dp->last_power_cycle,
1062 intel_dp->panel_power_cycle_delay);
1064 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
1067 static void wait_backlight_on(struct intel_dp *intel_dp)
1069 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1070 intel_dp->backlight_on_delay);
1073 static void edp_wait_backlight_off(struct intel_dp *intel_dp)
1075 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
1076 intel_dp->backlight_off_delay);
1079 /* Read the current pp_control value, unlocking the register if it
1083 static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
1085 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1086 struct drm_i915_private *dev_priv = dev->dev_private;
1089 control = I915_READ(_pp_ctrl_reg(intel_dp));
1090 control &= ~PANEL_UNLOCK_MASK;
1091 control |= PANEL_UNLOCK_REGS;
1095 static bool _edp_panel_vdd_on(struct intel_dp *intel_dp)
1097 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1098 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1099 struct intel_encoder *intel_encoder = &intel_dig_port->base;
1100 struct drm_i915_private *dev_priv = dev->dev_private;
1101 enum intel_display_power_domain power_domain;
1103 u32 pp_stat_reg, pp_ctrl_reg;
1104 bool need_to_disable = !intel_dp->want_panel_vdd;
1106 if (!is_edp(intel_dp))
1109 intel_dp->want_panel_vdd = true;
1111 if (edp_have_panel_vdd(intel_dp))
1112 return need_to_disable;
1114 power_domain = intel_display_port_power_domain(intel_encoder);
1115 intel_display_power_get(dev_priv, power_domain);
1117 DRM_DEBUG_KMS("Turning eDP VDD on\n");
1119 if (!edp_have_panel_power(intel_dp))
1120 wait_panel_power_cycle(intel_dp);
1122 pp = ironlake_get_pp_control(intel_dp);
1123 pp |= EDP_FORCE_VDD;
1125 pp_stat_reg = _pp_stat_reg(intel_dp);
1126 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
1128 I915_WRITE(pp_ctrl_reg, pp);
1129 POSTING_READ(pp_ctrl_reg);
1130 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1131 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
1133 * If the panel wasn't on, delay before accessing aux channel
1135 if (!edp_have_panel_power(intel_dp)) {
1136 DRM_DEBUG_KMS("eDP was not running\n");
1137 msleep(intel_dp->panel_power_up_delay);
1140 return need_to_disable;
1143 void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
1145 if (is_edp(intel_dp)) {
1146 bool vdd = _edp_panel_vdd_on(intel_dp);
1148 WARN(!vdd, "eDP VDD already requested on\n");
1152 static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
1154 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1155 struct drm_i915_private *dev_priv = dev->dev_private;
1157 u32 pp_stat_reg, pp_ctrl_reg;
1159 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
1161 if (!intel_dp->want_panel_vdd && edp_have_panel_vdd(intel_dp)) {
1162 struct intel_digital_port *intel_dig_port =
1163 dp_to_dig_port(intel_dp);
1164 struct intel_encoder *intel_encoder = &intel_dig_port->base;
1165 enum intel_display_power_domain power_domain;
1167 DRM_DEBUG_KMS("Turning eDP VDD off\n");
1169 pp = ironlake_get_pp_control(intel_dp);
1170 pp &= ~EDP_FORCE_VDD;
1172 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
1173 pp_stat_reg = _pp_stat_reg(intel_dp);
1175 I915_WRITE(pp_ctrl_reg, pp);
1176 POSTING_READ(pp_ctrl_reg);
1178 /* Make sure sequencer is idle before allowing subsequent activity */
1179 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1180 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
1182 if ((pp & POWER_TARGET_ON) == 0)
1183 intel_dp->last_power_cycle = jiffies;
1185 power_domain = intel_display_port_power_domain(intel_encoder);
1186 intel_display_power_put(dev_priv, power_domain);
1190 static void edp_panel_vdd_work(struct work_struct *__work)
1192 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
1193 struct intel_dp, panel_vdd_work);
1194 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1196 mutex_lock(&dev->mode_config.mutex);
1197 edp_panel_vdd_off_sync(intel_dp);
1198 mutex_unlock(&dev->mode_config.mutex);
1201 static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
1203 if (!is_edp(intel_dp))
1206 WARN(!intel_dp->want_panel_vdd, "eDP VDD not forced on");
1208 intel_dp->want_panel_vdd = false;
1211 edp_panel_vdd_off_sync(intel_dp);
1214 * Queue the timer to fire a long
1215 * time from now (relative to the power down delay)
1216 * to keep the panel power up across a sequence of operations
1218 schedule_delayed_work(&intel_dp->panel_vdd_work,
1219 msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5));
1223 void intel_edp_panel_on(struct intel_dp *intel_dp)
1225 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1226 struct drm_i915_private *dev_priv = dev->dev_private;
1230 if (!is_edp(intel_dp))
1233 DRM_DEBUG_KMS("Turn eDP power on\n");
1235 if (edp_have_panel_power(intel_dp)) {
1236 DRM_DEBUG_KMS("eDP power already on\n");
1240 wait_panel_power_cycle(intel_dp);
1242 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
1243 pp = ironlake_get_pp_control(intel_dp);
1245 /* ILK workaround: disable reset around power sequence */
1246 pp &= ~PANEL_POWER_RESET;
1247 I915_WRITE(pp_ctrl_reg, pp);
1248 POSTING_READ(pp_ctrl_reg);
1251 pp |= POWER_TARGET_ON;
1253 pp |= PANEL_POWER_RESET;
1255 I915_WRITE(pp_ctrl_reg, pp);
1256 POSTING_READ(pp_ctrl_reg);
1258 wait_panel_on(intel_dp);
1259 intel_dp->last_power_on = jiffies;
1262 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
1263 I915_WRITE(pp_ctrl_reg, pp);
1264 POSTING_READ(pp_ctrl_reg);
1268 void intel_edp_panel_off(struct intel_dp *intel_dp)
1270 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1271 struct intel_encoder *intel_encoder = &intel_dig_port->base;
1272 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1273 struct drm_i915_private *dev_priv = dev->dev_private;
1274 enum intel_display_power_domain power_domain;
1278 if (!is_edp(intel_dp))
1281 DRM_DEBUG_KMS("Turn eDP power off\n");
1283 edp_wait_backlight_off(intel_dp);
1285 WARN(!intel_dp->want_panel_vdd, "Need VDD to turn off panel\n");
1287 pp = ironlake_get_pp_control(intel_dp);
1288 /* We need to switch off panel power _and_ force vdd, for otherwise some
1289 * panels get very unhappy and cease to work. */
1290 pp &= ~(POWER_TARGET_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
1293 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
1295 intel_dp->want_panel_vdd = false;
1297 I915_WRITE(pp_ctrl_reg, pp);
1298 POSTING_READ(pp_ctrl_reg);
1300 intel_dp->last_power_cycle = jiffies;
1301 wait_panel_off(intel_dp);
1303 /* We got a reference when we enabled the VDD. */
1304 power_domain = intel_display_port_power_domain(intel_encoder);
1305 intel_display_power_put(dev_priv, power_domain);
1308 void intel_edp_backlight_on(struct intel_dp *intel_dp)
1310 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1311 struct drm_device *dev = intel_dig_port->base.base.dev;
1312 struct drm_i915_private *dev_priv = dev->dev_private;
1316 if (!is_edp(intel_dp))
1319 DRM_DEBUG_KMS("\n");
1321 * If we enable the backlight right away following a panel power
1322 * on, we may see slight flicker as the panel syncs with the eDP
1323 * link. So delay a bit to make sure the image is solid before
1324 * allowing it to appear.
1326 wait_backlight_on(intel_dp);
1327 pp = ironlake_get_pp_control(intel_dp);
1328 pp |= EDP_BLC_ENABLE;
1330 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
1332 I915_WRITE(pp_ctrl_reg, pp);
1333 POSTING_READ(pp_ctrl_reg);
1335 intel_panel_enable_backlight(intel_dp->attached_connector);
1338 void intel_edp_backlight_off(struct intel_dp *intel_dp)
1340 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1341 struct drm_i915_private *dev_priv = dev->dev_private;
1345 if (!is_edp(intel_dp))
1348 intel_panel_disable_backlight(intel_dp->attached_connector);
1350 DRM_DEBUG_KMS("\n");
1351 pp = ironlake_get_pp_control(intel_dp);
1352 pp &= ~EDP_BLC_ENABLE;
1354 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
1356 I915_WRITE(pp_ctrl_reg, pp);
1357 POSTING_READ(pp_ctrl_reg);
1358 intel_dp->last_backlight_off = jiffies;
1361 static void ironlake_edp_pll_on(struct intel_dp *intel_dp)
1363 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1364 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
1365 struct drm_device *dev = crtc->dev;
1366 struct drm_i915_private *dev_priv = dev->dev_private;
1369 assert_pipe_disabled(dev_priv,
1370 to_intel_crtc(crtc)->pipe);
1372 DRM_DEBUG_KMS("\n");
1373 dpa_ctl = I915_READ(DP_A);
1374 WARN(dpa_ctl & DP_PLL_ENABLE, "dp pll on, should be off\n");
1375 WARN(dpa_ctl & DP_PORT_EN, "dp port still on, should be off\n");
1377 /* We don't adjust intel_dp->DP while tearing down the link, to
1378 * facilitate link retraining (e.g. after hotplug). Hence clear all
1379 * enable bits here to ensure that we don't enable too much. */
1380 intel_dp->DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
1381 intel_dp->DP |= DP_PLL_ENABLE;
1382 I915_WRITE(DP_A, intel_dp->DP);
1387 static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
1389 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1390 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
1391 struct drm_device *dev = crtc->dev;
1392 struct drm_i915_private *dev_priv = dev->dev_private;
1395 assert_pipe_disabled(dev_priv,
1396 to_intel_crtc(crtc)->pipe);
1398 dpa_ctl = I915_READ(DP_A);
1399 WARN((dpa_ctl & DP_PLL_ENABLE) == 0,
1400 "dp pll off, should be on\n");
1401 WARN(dpa_ctl & DP_PORT_EN, "dp port still on, should be off\n");
1403 /* We can't rely on the value tracked for the DP register in
1404 * intel_dp->DP because link_down must not change that (otherwise link
1405 * re-training will fail. */
1406 dpa_ctl &= ~DP_PLL_ENABLE;
1407 I915_WRITE(DP_A, dpa_ctl);
1412 /* If the sink supports it, try to set the power state appropriately */
1413 void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
1417 /* Should have a valid DPCD by this point */
1418 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
1421 if (mode != DRM_MODE_DPMS_ON) {
1422 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
1425 DRM_DEBUG_DRIVER("failed to write sink power state\n");
1428 * When turning on, we need to retry for 1ms to give the sink
1431 for (i = 0; i < 3; i++) {
1432 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
1441 static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
1444 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1445 enum port port = dp_to_dig_port(intel_dp)->port;
1446 struct drm_device *dev = encoder->base.dev;
1447 struct drm_i915_private *dev_priv = dev->dev_private;
1448 enum intel_display_power_domain power_domain;
1451 power_domain = intel_display_port_power_domain(encoder);
1452 if (!intel_display_power_enabled(dev_priv, power_domain))
1455 tmp = I915_READ(intel_dp->output_reg);
1457 if (!(tmp & DP_PORT_EN))
1460 if (port == PORT_A && IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) {
1461 *pipe = PORT_TO_PIPE_CPT(tmp);
1462 } else if (!HAS_PCH_CPT(dev) || port == PORT_A) {
1463 *pipe = PORT_TO_PIPE(tmp);
1469 switch (intel_dp->output_reg) {
1471 trans_sel = TRANS_DP_PORT_SEL_B;
1474 trans_sel = TRANS_DP_PORT_SEL_C;
1477 trans_sel = TRANS_DP_PORT_SEL_D;
1484 trans_dp = I915_READ(TRANS_DP_CTL(i));
1485 if ((trans_dp & TRANS_DP_PORT_SEL_MASK) == trans_sel) {
1491 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
1492 intel_dp->output_reg);
1498 static void intel_dp_get_config(struct intel_encoder *encoder,
1499 struct intel_crtc_config *pipe_config)
1501 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1503 struct drm_device *dev = encoder->base.dev;
1504 struct drm_i915_private *dev_priv = dev->dev_private;
1505 enum port port = dp_to_dig_port(intel_dp)->port;
1506 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
1509 if ((port == PORT_A) || !HAS_PCH_CPT(dev)) {
1510 tmp = I915_READ(intel_dp->output_reg);
1511 if (tmp & DP_SYNC_HS_HIGH)
1512 flags |= DRM_MODE_FLAG_PHSYNC;
1514 flags |= DRM_MODE_FLAG_NHSYNC;
1516 if (tmp & DP_SYNC_VS_HIGH)
1517 flags |= DRM_MODE_FLAG_PVSYNC;
1519 flags |= DRM_MODE_FLAG_NVSYNC;
1521 tmp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1522 if (tmp & TRANS_DP_HSYNC_ACTIVE_HIGH)
1523 flags |= DRM_MODE_FLAG_PHSYNC;
1525 flags |= DRM_MODE_FLAG_NHSYNC;
1527 if (tmp & TRANS_DP_VSYNC_ACTIVE_HIGH)
1528 flags |= DRM_MODE_FLAG_PVSYNC;
1530 flags |= DRM_MODE_FLAG_NVSYNC;
1533 pipe_config->adjusted_mode.flags |= flags;
1535 pipe_config->has_dp_encoder = true;
1537 intel_dp_get_m_n(crtc, pipe_config);
1539 if (port == PORT_A) {
1540 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_160MHZ)
1541 pipe_config->port_clock = 162000;
1543 pipe_config->port_clock = 270000;
1546 dotclock = intel_dotclock_calculate(pipe_config->port_clock,
1547 &pipe_config->dp_m_n);
1549 if (HAS_PCH_SPLIT(dev_priv->dev) && port != PORT_A)
1550 ironlake_check_encoder_dotclock(pipe_config, dotclock);
1552 pipe_config->adjusted_mode.crtc_clock = dotclock;
1554 if (is_edp(intel_dp) && dev_priv->vbt.edp_bpp &&
1555 pipe_config->pipe_bpp > dev_priv->vbt.edp_bpp) {
1557 * This is a big fat ugly hack.
1559 * Some machines in UEFI boot mode provide us a VBT that has 18
1560 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
1561 * unknown we fail to light up. Yet the same BIOS boots up with
1562 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
1563 * max, not what it tells us to use.
1565 * Note: This will still be broken if the eDP panel is not lit
1566 * up by the BIOS, and thus we can't get the mode at module
1569 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
1570 pipe_config->pipe_bpp, dev_priv->vbt.edp_bpp);
1571 dev_priv->vbt.edp_bpp = pipe_config->pipe_bpp;
1575 static bool is_edp_psr(struct drm_device *dev)
1577 struct drm_i915_private *dev_priv = dev->dev_private;
1579 return dev_priv->psr.sink_support;
1582 static bool intel_edp_is_psr_enabled(struct drm_device *dev)
1584 struct drm_i915_private *dev_priv = dev->dev_private;
1589 return I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
1592 static void intel_edp_psr_write_vsc(struct intel_dp *intel_dp,
1593 struct edp_vsc_psr *vsc_psr)
1595 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1596 struct drm_device *dev = dig_port->base.base.dev;
1597 struct drm_i915_private *dev_priv = dev->dev_private;
1598 struct intel_crtc *crtc = to_intel_crtc(dig_port->base.base.crtc);
1599 u32 ctl_reg = HSW_TVIDEO_DIP_CTL(crtc->config.cpu_transcoder);
1600 u32 data_reg = HSW_TVIDEO_DIP_VSC_DATA(crtc->config.cpu_transcoder);
1601 uint32_t *data = (uint32_t *) vsc_psr;
1604 /* As per BSPec (Pipe Video Data Island Packet), we need to disable
1605 the video DIP being updated before program video DIP data buffer
1606 registers for DIP being updated. */
1607 I915_WRITE(ctl_reg, 0);
1608 POSTING_READ(ctl_reg);
1610 for (i = 0; i < VIDEO_DIP_VSC_DATA_SIZE; i += 4) {
1611 if (i < sizeof(struct edp_vsc_psr))
1612 I915_WRITE(data_reg + i, *data++);
1614 I915_WRITE(data_reg + i, 0);
1617 I915_WRITE(ctl_reg, VIDEO_DIP_ENABLE_VSC_HSW);
1618 POSTING_READ(ctl_reg);
1621 static void intel_edp_psr_setup(struct intel_dp *intel_dp)
1623 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1624 struct drm_i915_private *dev_priv = dev->dev_private;
1625 struct edp_vsc_psr psr_vsc;
1627 if (intel_dp->psr_setup_done)
1630 /* Prepare VSC packet as per EDP 1.3 spec, Table 3.10 */
1631 memset(&psr_vsc, 0, sizeof(psr_vsc));
1632 psr_vsc.sdp_header.HB0 = 0;
1633 psr_vsc.sdp_header.HB1 = 0x7;
1634 psr_vsc.sdp_header.HB2 = 0x2;
1635 psr_vsc.sdp_header.HB3 = 0x8;
1636 intel_edp_psr_write_vsc(intel_dp, &psr_vsc);
1638 /* Avoid continuous PSR exit by masking memup and hpd */
1639 I915_WRITE(EDP_PSR_DEBUG_CTL(dev), EDP_PSR_DEBUG_MASK_MEMUP |
1640 EDP_PSR_DEBUG_MASK_HPD | EDP_PSR_DEBUG_MASK_LPSP);
1642 intel_dp->psr_setup_done = true;
1645 static void intel_edp_psr_enable_sink(struct intel_dp *intel_dp)
1647 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1648 struct drm_i915_private *dev_priv = dev->dev_private;
1649 uint32_t aux_clock_divider;
1650 int precharge = 0x3;
1651 int msg_size = 5; /* Header(4) + Message(1) */
1653 aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, 0);
1655 /* Enable PSR in sink */
1656 if (intel_dp->psr_dpcd[1] & DP_PSR_NO_TRAIN_ON_EXIT)
1657 drm_dp_dpcd_writeb(&intel_dp->aux, DP_PSR_EN_CFG,
1658 DP_PSR_ENABLE & ~DP_PSR_MAIN_LINK_ACTIVE);
1660 drm_dp_dpcd_writeb(&intel_dp->aux, DP_PSR_EN_CFG,
1661 DP_PSR_ENABLE | DP_PSR_MAIN_LINK_ACTIVE);
1663 /* Setup AUX registers */
1664 I915_WRITE(EDP_PSR_AUX_DATA1(dev), EDP_PSR_DPCD_COMMAND);
1665 I915_WRITE(EDP_PSR_AUX_DATA2(dev), EDP_PSR_DPCD_NORMAL_OPERATION);
1666 I915_WRITE(EDP_PSR_AUX_CTL(dev),
1667 DP_AUX_CH_CTL_TIME_OUT_400us |
1668 (msg_size << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
1669 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
1670 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT));
1673 static void intel_edp_psr_enable_source(struct intel_dp *intel_dp)
1675 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1676 struct drm_i915_private *dev_priv = dev->dev_private;
1677 uint32_t max_sleep_time = 0x1f;
1678 uint32_t idle_frames = 1;
1680 const uint32_t link_entry_time = EDP_PSR_MIN_LINK_ENTRY_TIME_8_LINES;
1682 if (intel_dp->psr_dpcd[1] & DP_PSR_NO_TRAIN_ON_EXIT) {
1683 val |= EDP_PSR_LINK_STANDBY;
1684 val |= EDP_PSR_TP2_TP3_TIME_0us;
1685 val |= EDP_PSR_TP1_TIME_0us;
1686 val |= EDP_PSR_SKIP_AUX_EXIT;
1688 val |= EDP_PSR_LINK_DISABLE;
1690 I915_WRITE(EDP_PSR_CTL(dev), val |
1691 (IS_BROADWELL(dev) ? 0 : link_entry_time) |
1692 max_sleep_time << EDP_PSR_MAX_SLEEP_TIME_SHIFT |
1693 idle_frames << EDP_PSR_IDLE_FRAME_SHIFT |
1697 static bool intel_edp_psr_match_conditions(struct intel_dp *intel_dp)
1699 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1700 struct drm_device *dev = dig_port->base.base.dev;
1701 struct drm_i915_private *dev_priv = dev->dev_private;
1702 struct drm_crtc *crtc = dig_port->base.base.crtc;
1703 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1704 struct drm_i915_gem_object *obj = to_intel_framebuffer(crtc->primary->fb)->obj;
1705 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
1707 dev_priv->psr.source_ok = false;
1709 if (!HAS_PSR(dev)) {
1710 DRM_DEBUG_KMS("PSR not supported on this platform\n");
1714 if ((intel_encoder->type != INTEL_OUTPUT_EDP) ||
1715 (dig_port->port != PORT_A)) {
1716 DRM_DEBUG_KMS("HSW ties PSR to DDI A (eDP)\n");
1720 if (!i915.enable_psr) {
1721 DRM_DEBUG_KMS("PSR disable by flag\n");
1725 crtc = dig_port->base.base.crtc;
1727 DRM_DEBUG_KMS("crtc not active for PSR\n");
1731 intel_crtc = to_intel_crtc(crtc);
1732 if (!intel_crtc_active(crtc)) {
1733 DRM_DEBUG_KMS("crtc not active for PSR\n");
1737 obj = to_intel_framebuffer(crtc->primary->fb)->obj;
1738 if (obj->tiling_mode != I915_TILING_X ||
1739 obj->fence_reg == I915_FENCE_REG_NONE) {
1740 DRM_DEBUG_KMS("PSR condition failed: fb not tiled or fenced\n");
1744 if (I915_READ(SPRCTL(intel_crtc->pipe)) & SPRITE_ENABLE) {
1745 DRM_DEBUG_KMS("PSR condition failed: Sprite is Enabled\n");
1749 if (I915_READ(HSW_STEREO_3D_CTL(intel_crtc->config.cpu_transcoder)) &
1751 DRM_DEBUG_KMS("PSR condition failed: Stereo 3D is Enabled\n");
1755 if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
1756 DRM_DEBUG_KMS("PSR condition failed: Interlaced is Enabled\n");
1760 dev_priv->psr.source_ok = true;
1764 static void intel_edp_psr_do_enable(struct intel_dp *intel_dp)
1766 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1768 if (!intel_edp_psr_match_conditions(intel_dp) ||
1769 intel_edp_is_psr_enabled(dev))
1772 /* Setup PSR once */
1773 intel_edp_psr_setup(intel_dp);
1775 /* Enable PSR on the panel */
1776 intel_edp_psr_enable_sink(intel_dp);
1778 /* Enable PSR on the host */
1779 intel_edp_psr_enable_source(intel_dp);
1782 void intel_edp_psr_enable(struct intel_dp *intel_dp)
1784 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1786 if (intel_edp_psr_match_conditions(intel_dp) &&
1787 !intel_edp_is_psr_enabled(dev))
1788 intel_edp_psr_do_enable(intel_dp);
1791 void intel_edp_psr_disable(struct intel_dp *intel_dp)
1793 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1794 struct drm_i915_private *dev_priv = dev->dev_private;
1796 if (!intel_edp_is_psr_enabled(dev))
1799 I915_WRITE(EDP_PSR_CTL(dev),
1800 I915_READ(EDP_PSR_CTL(dev)) & ~EDP_PSR_ENABLE);
1802 /* Wait till PSR is idle */
1803 if (_wait_for((I915_READ(EDP_PSR_STATUS_CTL(dev)) &
1804 EDP_PSR_STATUS_STATE_MASK) == 0, 2000, 10))
1805 DRM_ERROR("Timed out waiting for PSR Idle State\n");
1808 void intel_edp_psr_update(struct drm_device *dev)
1810 struct intel_encoder *encoder;
1811 struct intel_dp *intel_dp = NULL;
1813 list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head)
1814 if (encoder->type == INTEL_OUTPUT_EDP) {
1815 intel_dp = enc_to_intel_dp(&encoder->base);
1817 if (!is_edp_psr(dev))
1820 if (!intel_edp_psr_match_conditions(intel_dp))
1821 intel_edp_psr_disable(intel_dp);
1823 if (!intel_edp_is_psr_enabled(dev))
1824 intel_edp_psr_do_enable(intel_dp);
1828 static void intel_disable_dp(struct intel_encoder *encoder)
1830 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1831 enum port port = dp_to_dig_port(intel_dp)->port;
1832 struct drm_device *dev = encoder->base.dev;
1834 /* Make sure the panel is off before trying to change the mode. But also
1835 * ensure that we have vdd while we switch off the panel. */
1836 intel_edp_panel_vdd_on(intel_dp);
1837 intel_edp_backlight_off(intel_dp);
1838 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
1839 intel_edp_panel_off(intel_dp);
1841 /* cpu edp my only be disable _after_ the cpu pipe/plane is disabled. */
1842 if (!(port == PORT_A || IS_VALLEYVIEW(dev)))
1843 intel_dp_link_down(intel_dp);
1846 static void g4x_post_disable_dp(struct intel_encoder *encoder)
1848 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1849 enum port port = dp_to_dig_port(intel_dp)->port;
1854 intel_dp_link_down(intel_dp);
1855 ironlake_edp_pll_off(intel_dp);
1858 static void vlv_post_disable_dp(struct intel_encoder *encoder)
1860 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1862 intel_dp_link_down(intel_dp);
1865 static void intel_enable_dp(struct intel_encoder *encoder)
1867 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1868 struct drm_device *dev = encoder->base.dev;
1869 struct drm_i915_private *dev_priv = dev->dev_private;
1870 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
1872 if (WARN_ON(dp_reg & DP_PORT_EN))
1875 intel_edp_panel_vdd_on(intel_dp);
1876 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1877 intel_dp_start_link_train(intel_dp);
1878 intel_edp_panel_on(intel_dp);
1879 edp_panel_vdd_off(intel_dp, true);
1880 intel_dp_complete_link_train(intel_dp);
1881 intel_dp_stop_link_train(intel_dp);
1884 static void g4x_enable_dp(struct intel_encoder *encoder)
1886 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1888 intel_enable_dp(encoder);
1889 intel_edp_backlight_on(intel_dp);
1892 static void vlv_enable_dp(struct intel_encoder *encoder)
1894 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1896 intel_edp_backlight_on(intel_dp);
1899 static void g4x_pre_enable_dp(struct intel_encoder *encoder)
1901 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1902 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
1904 if (dport->port == PORT_A)
1905 ironlake_edp_pll_on(intel_dp);
1908 static void vlv_pre_enable_dp(struct intel_encoder *encoder)
1910 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1911 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
1912 struct drm_device *dev = encoder->base.dev;
1913 struct drm_i915_private *dev_priv = dev->dev_private;
1914 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
1915 enum dpio_channel port = vlv_dport_to_channel(dport);
1916 int pipe = intel_crtc->pipe;
1917 struct edp_power_seq power_seq;
1920 mutex_lock(&dev_priv->dpio_lock);
1922 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(port));
1929 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW8(port), val);
1930 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW14(port), 0x00760018);
1931 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW23(port), 0x00400888);
1933 mutex_unlock(&dev_priv->dpio_lock);
1935 if (is_edp(intel_dp)) {
1936 /* init power sequencer on this pipe and port */
1937 intel_dp_init_panel_power_sequencer(dev, intel_dp, &power_seq);
1938 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp,
1942 intel_enable_dp(encoder);
1944 vlv_wait_port_ready(dev_priv, dport);
1947 static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder)
1949 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1950 struct drm_device *dev = encoder->base.dev;
1951 struct drm_i915_private *dev_priv = dev->dev_private;
1952 struct intel_crtc *intel_crtc =
1953 to_intel_crtc(encoder->base.crtc);
1954 enum dpio_channel port = vlv_dport_to_channel(dport);
1955 int pipe = intel_crtc->pipe;
1957 /* Program Tx lane resets to default */
1958 mutex_lock(&dev_priv->dpio_lock);
1959 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port),
1960 DPIO_PCS_TX_LANE2_RESET |
1961 DPIO_PCS_TX_LANE1_RESET);
1962 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port),
1963 DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
1964 DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
1965 (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
1966 DPIO_PCS_CLK_SOFT_RESET);
1968 /* Fix up inter-pair skew failure */
1969 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW12(port), 0x00750f00);
1970 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW11(port), 0x00001500);
1971 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW14(port), 0x40400000);
1972 mutex_unlock(&dev_priv->dpio_lock);
1975 static void chv_pre_enable_dp(struct intel_encoder *encoder)
1977 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1978 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
1979 struct drm_device *dev = encoder->base.dev;
1980 struct drm_i915_private *dev_priv = dev->dev_private;
1981 struct edp_power_seq power_seq;
1982 struct intel_crtc *intel_crtc =
1983 to_intel_crtc(encoder->base.crtc);
1984 enum dpio_channel ch = vlv_dport_to_channel(dport);
1985 int pipe = intel_crtc->pipe;
1988 /* Program Tx lane latency optimal setting*/
1989 mutex_lock(&dev_priv->dpio_lock);
1990 for (i = 0; i < 4; i++) {
1991 /* Set the latency optimal bit */
1992 data = (i == 1) ? 0x0 : 0x6;
1993 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW11(ch, i),
1994 data << DPIO_FRC_LATENCY_SHFIT);
1996 /* Set the upar bit */
1997 data = (i == 1) ? 0x0 : 0x1;
1998 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW14(ch, i),
1999 data << DPIO_UPAR_SHIFT);
2002 /* Data lane stagger programming */
2003 /* FIXME: Fix up value only after power analysis */
2005 mutex_unlock(&dev_priv->dpio_lock);
2007 if (is_edp(intel_dp)) {
2008 /* init power sequencer on this pipe and port */
2009 intel_dp_init_panel_power_sequencer(dev, intel_dp, &power_seq);
2010 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp,
2014 intel_enable_dp(encoder);
2016 vlv_wait_port_ready(dev_priv, dport);
2020 * Native read with retry for link status and receiver capability reads for
2021 * cases where the sink may still be asleep.
2023 * Sinks are *supposed* to come up within 1ms from an off state, but we're also
2024 * supposed to retry 3 times per the spec.
2027 intel_dp_dpcd_read_wake(struct drm_dp_aux *aux, unsigned int offset,
2028 void *buffer, size_t size)
2033 for (i = 0; i < 3; i++) {
2034 ret = drm_dp_dpcd_read(aux, offset, buffer, size);
2044 * Fetch AUX CH registers 0x202 - 0x207 which contain
2045 * link status information
2048 intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
2050 return intel_dp_dpcd_read_wake(&intel_dp->aux,
2053 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
2057 * These are source-specific values; current Intel hardware supports
2058 * a maximum voltage of 800mV and a maximum pre-emphasis of 6dB
2062 intel_dp_voltage_max(struct intel_dp *intel_dp)
2064 struct drm_device *dev = intel_dp_to_dev(intel_dp);
2065 enum port port = dp_to_dig_port(intel_dp)->port;
2067 if (IS_VALLEYVIEW(dev) || IS_BROADWELL(dev))
2068 return DP_TRAIN_VOLTAGE_SWING_1200;
2069 else if (IS_GEN7(dev) && port == PORT_A)
2070 return DP_TRAIN_VOLTAGE_SWING_800;
2071 else if (HAS_PCH_CPT(dev) && port != PORT_A)
2072 return DP_TRAIN_VOLTAGE_SWING_1200;
2074 return DP_TRAIN_VOLTAGE_SWING_800;
2078 intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
2080 struct drm_device *dev = intel_dp_to_dev(intel_dp);
2081 enum port port = dp_to_dig_port(intel_dp)->port;
2083 if (IS_BROADWELL(dev)) {
2084 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
2085 case DP_TRAIN_VOLTAGE_SWING_400:
2086 case DP_TRAIN_VOLTAGE_SWING_600:
2087 return DP_TRAIN_PRE_EMPHASIS_6;
2088 case DP_TRAIN_VOLTAGE_SWING_800:
2089 return DP_TRAIN_PRE_EMPHASIS_3_5;
2090 case DP_TRAIN_VOLTAGE_SWING_1200:
2092 return DP_TRAIN_PRE_EMPHASIS_0;
2094 } else if (IS_HASWELL(dev)) {
2095 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
2096 case DP_TRAIN_VOLTAGE_SWING_400:
2097 return DP_TRAIN_PRE_EMPHASIS_9_5;
2098 case DP_TRAIN_VOLTAGE_SWING_600:
2099 return DP_TRAIN_PRE_EMPHASIS_6;
2100 case DP_TRAIN_VOLTAGE_SWING_800:
2101 return DP_TRAIN_PRE_EMPHASIS_3_5;
2102 case DP_TRAIN_VOLTAGE_SWING_1200:
2104 return DP_TRAIN_PRE_EMPHASIS_0;
2106 } else if (IS_VALLEYVIEW(dev)) {
2107 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
2108 case DP_TRAIN_VOLTAGE_SWING_400:
2109 return DP_TRAIN_PRE_EMPHASIS_9_5;
2110 case DP_TRAIN_VOLTAGE_SWING_600:
2111 return DP_TRAIN_PRE_EMPHASIS_6;
2112 case DP_TRAIN_VOLTAGE_SWING_800:
2113 return DP_TRAIN_PRE_EMPHASIS_3_5;
2114 case DP_TRAIN_VOLTAGE_SWING_1200:
2116 return DP_TRAIN_PRE_EMPHASIS_0;
2118 } else if (IS_GEN7(dev) && port == PORT_A) {
2119 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
2120 case DP_TRAIN_VOLTAGE_SWING_400:
2121 return DP_TRAIN_PRE_EMPHASIS_6;
2122 case DP_TRAIN_VOLTAGE_SWING_600:
2123 case DP_TRAIN_VOLTAGE_SWING_800:
2124 return DP_TRAIN_PRE_EMPHASIS_3_5;
2126 return DP_TRAIN_PRE_EMPHASIS_0;
2129 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
2130 case DP_TRAIN_VOLTAGE_SWING_400:
2131 return DP_TRAIN_PRE_EMPHASIS_6;
2132 case DP_TRAIN_VOLTAGE_SWING_600:
2133 return DP_TRAIN_PRE_EMPHASIS_6;
2134 case DP_TRAIN_VOLTAGE_SWING_800:
2135 return DP_TRAIN_PRE_EMPHASIS_3_5;
2136 case DP_TRAIN_VOLTAGE_SWING_1200:
2138 return DP_TRAIN_PRE_EMPHASIS_0;
2143 static uint32_t intel_vlv_signal_levels(struct intel_dp *intel_dp)
2145 struct drm_device *dev = intel_dp_to_dev(intel_dp);
2146 struct drm_i915_private *dev_priv = dev->dev_private;
2147 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
2148 struct intel_crtc *intel_crtc =
2149 to_intel_crtc(dport->base.base.crtc);
2150 unsigned long demph_reg_value, preemph_reg_value,
2151 uniqtranscale_reg_value;
2152 uint8_t train_set = intel_dp->train_set[0];
2153 enum dpio_channel port = vlv_dport_to_channel(dport);
2154 int pipe = intel_crtc->pipe;
2156 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
2157 case DP_TRAIN_PRE_EMPHASIS_0:
2158 preemph_reg_value = 0x0004000;
2159 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
2160 case DP_TRAIN_VOLTAGE_SWING_400:
2161 demph_reg_value = 0x2B405555;
2162 uniqtranscale_reg_value = 0x552AB83A;
2164 case DP_TRAIN_VOLTAGE_SWING_600:
2165 demph_reg_value = 0x2B404040;
2166 uniqtranscale_reg_value = 0x5548B83A;
2168 case DP_TRAIN_VOLTAGE_SWING_800:
2169 demph_reg_value = 0x2B245555;
2170 uniqtranscale_reg_value = 0x5560B83A;
2172 case DP_TRAIN_VOLTAGE_SWING_1200:
2173 demph_reg_value = 0x2B405555;
2174 uniqtranscale_reg_value = 0x5598DA3A;
2180 case DP_TRAIN_PRE_EMPHASIS_3_5:
2181 preemph_reg_value = 0x0002000;
2182 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
2183 case DP_TRAIN_VOLTAGE_SWING_400:
2184 demph_reg_value = 0x2B404040;
2185 uniqtranscale_reg_value = 0x5552B83A;
2187 case DP_TRAIN_VOLTAGE_SWING_600:
2188 demph_reg_value = 0x2B404848;
2189 uniqtranscale_reg_value = 0x5580B83A;
2191 case DP_TRAIN_VOLTAGE_SWING_800:
2192 demph_reg_value = 0x2B404040;
2193 uniqtranscale_reg_value = 0x55ADDA3A;
2199 case DP_TRAIN_PRE_EMPHASIS_6:
2200 preemph_reg_value = 0x0000000;
2201 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
2202 case DP_TRAIN_VOLTAGE_SWING_400:
2203 demph_reg_value = 0x2B305555;
2204 uniqtranscale_reg_value = 0x5570B83A;
2206 case DP_TRAIN_VOLTAGE_SWING_600:
2207 demph_reg_value = 0x2B2B4040;
2208 uniqtranscale_reg_value = 0x55ADDA3A;
2214 case DP_TRAIN_PRE_EMPHASIS_9_5:
2215 preemph_reg_value = 0x0006000;
2216 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
2217 case DP_TRAIN_VOLTAGE_SWING_400:
2218 demph_reg_value = 0x1B405555;
2219 uniqtranscale_reg_value = 0x55ADDA3A;
2229 mutex_lock(&dev_priv->dpio_lock);
2230 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0x00000000);
2231 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW4(port), demph_reg_value);
2232 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW2(port),
2233 uniqtranscale_reg_value);
2234 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW3(port), 0x0C782040);
2235 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW11(port), 0x00030000);
2236 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW9(port), preemph_reg_value);
2237 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0x80000000);
2238 mutex_unlock(&dev_priv->dpio_lock);
2243 static uint32_t intel_chv_signal_levels(struct intel_dp *intel_dp)
2245 struct drm_device *dev = intel_dp_to_dev(intel_dp);
2246 struct drm_i915_private *dev_priv = dev->dev_private;
2247 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
2248 struct intel_crtc *intel_crtc = to_intel_crtc(dport->base.base.crtc);
2249 u32 deemph_reg_value, margin_reg_value, val, tx_dw2;
2250 uint8_t train_set = intel_dp->train_set[0];
2251 enum dpio_channel ch = vlv_dport_to_channel(dport);
2252 int pipe = intel_crtc->pipe;
2254 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
2255 case DP_TRAIN_PRE_EMPHASIS_0:
2256 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
2257 case DP_TRAIN_VOLTAGE_SWING_400:
2258 deemph_reg_value = 128;
2259 margin_reg_value = 52;
2261 case DP_TRAIN_VOLTAGE_SWING_600:
2262 deemph_reg_value = 128;
2263 margin_reg_value = 77;
2265 case DP_TRAIN_VOLTAGE_SWING_800:
2266 deemph_reg_value = 128;
2267 margin_reg_value = 102;
2269 case DP_TRAIN_VOLTAGE_SWING_1200:
2270 deemph_reg_value = 128;
2271 margin_reg_value = 154;
2272 /* FIXME extra to set for 1200 */
2278 case DP_TRAIN_PRE_EMPHASIS_3_5:
2279 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
2280 case DP_TRAIN_VOLTAGE_SWING_400:
2281 deemph_reg_value = 85;
2282 margin_reg_value = 78;
2284 case DP_TRAIN_VOLTAGE_SWING_600:
2285 deemph_reg_value = 85;
2286 margin_reg_value = 116;
2288 case DP_TRAIN_VOLTAGE_SWING_800:
2289 deemph_reg_value = 85;
2290 margin_reg_value = 154;
2296 case DP_TRAIN_PRE_EMPHASIS_6:
2297 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
2298 case DP_TRAIN_VOLTAGE_SWING_400:
2299 deemph_reg_value = 64;
2300 margin_reg_value = 104;
2302 case DP_TRAIN_VOLTAGE_SWING_600:
2303 deemph_reg_value = 64;
2304 margin_reg_value = 154;
2310 case DP_TRAIN_PRE_EMPHASIS_9_5:
2311 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
2312 case DP_TRAIN_VOLTAGE_SWING_400:
2313 deemph_reg_value = 43;
2314 margin_reg_value = 154;
2324 mutex_lock(&dev_priv->dpio_lock);
2326 /* Clear calc init */
2327 vlv_dpio_write(dev_priv, pipe, CHV_PCS_DW10(ch), 0);
2329 /* Program swing deemph */
2330 val = vlv_dpio_read(dev_priv, pipe, VLV_TX_DW4(ch));
2331 val &= ~DPIO_SWING_DEEMPH9P5_MASK;
2332 val |= deemph_reg_value << DPIO_SWING_DEEMPH9P5_SHIFT;
2333 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW4(ch), val);
2335 /* Program swing margin */
2336 tx_dw2 = vlv_dpio_read(dev_priv, pipe, VLV_TX_DW2(ch));
2337 tx_dw2 &= ~DPIO_SWING_MARGIN_MASK;
2338 tx_dw2 |= margin_reg_value << DPIO_SWING_MARGIN_SHIFT;
2339 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW2(ch), tx_dw2);
2341 /* Disable unique transition scale */
2342 val = vlv_dpio_read(dev_priv, pipe, VLV_TX_DW3(ch));
2343 val &= ~DPIO_TX_UNIQ_TRANS_SCALE_EN;
2344 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW3(ch), val);
2346 if (((train_set & DP_TRAIN_PRE_EMPHASIS_MASK)
2347 == DP_TRAIN_PRE_EMPHASIS_0) &&
2348 ((train_set & DP_TRAIN_VOLTAGE_SWING_MASK)
2349 == DP_TRAIN_VOLTAGE_SWING_1200)) {
2352 * The document said it needs to set bit 27 for ch0 and bit 26
2353 * for ch1. Might be a typo in the doc.
2354 * For now, for this unique transition scale selection, set bit
2355 * 27 for ch0 and ch1.
2357 val = vlv_dpio_read(dev_priv, pipe, VLV_TX_DW3(ch));
2358 val |= DPIO_TX_UNIQ_TRANS_SCALE_EN;
2359 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW3(ch), val);
2361 tx_dw2 |= (0x9a << DPIO_UNIQ_TRANS_SCALE_SHIFT);
2362 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW2(ch), tx_dw2);
2365 /* Start swing calculation */
2366 vlv_dpio_write(dev_priv, pipe, CHV_PCS_DW10(ch),
2367 (DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3));
2370 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
2371 val |= DPIO_LRC_BYPASS;
2372 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, val);
2374 mutex_unlock(&dev_priv->dpio_lock);
2380 intel_get_adjust_train(struct intel_dp *intel_dp,
2381 const uint8_t link_status[DP_LINK_STATUS_SIZE])
2386 uint8_t voltage_max;
2387 uint8_t preemph_max;
2389 for (lane = 0; lane < intel_dp->lane_count; lane++) {
2390 uint8_t this_v = drm_dp_get_adjust_request_voltage(link_status, lane);
2391 uint8_t this_p = drm_dp_get_adjust_request_pre_emphasis(link_status, lane);
2399 voltage_max = intel_dp_voltage_max(intel_dp);
2400 if (v >= voltage_max)
2401 v = voltage_max | DP_TRAIN_MAX_SWING_REACHED;
2403 preemph_max = intel_dp_pre_emphasis_max(intel_dp, v);
2404 if (p >= preemph_max)
2405 p = preemph_max | DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
2407 for (lane = 0; lane < 4; lane++)
2408 intel_dp->train_set[lane] = v | p;
2412 intel_gen4_signal_levels(uint8_t train_set)
2414 uint32_t signal_levels = 0;
2416 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
2417 case DP_TRAIN_VOLTAGE_SWING_400:
2419 signal_levels |= DP_VOLTAGE_0_4;
2421 case DP_TRAIN_VOLTAGE_SWING_600:
2422 signal_levels |= DP_VOLTAGE_0_6;
2424 case DP_TRAIN_VOLTAGE_SWING_800:
2425 signal_levels |= DP_VOLTAGE_0_8;
2427 case DP_TRAIN_VOLTAGE_SWING_1200:
2428 signal_levels |= DP_VOLTAGE_1_2;
2431 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
2432 case DP_TRAIN_PRE_EMPHASIS_0:
2434 signal_levels |= DP_PRE_EMPHASIS_0;
2436 case DP_TRAIN_PRE_EMPHASIS_3_5:
2437 signal_levels |= DP_PRE_EMPHASIS_3_5;
2439 case DP_TRAIN_PRE_EMPHASIS_6:
2440 signal_levels |= DP_PRE_EMPHASIS_6;
2442 case DP_TRAIN_PRE_EMPHASIS_9_5:
2443 signal_levels |= DP_PRE_EMPHASIS_9_5;
2446 return signal_levels;
2449 /* Gen6's DP voltage swing and pre-emphasis control */
2451 intel_gen6_edp_signal_levels(uint8_t train_set)
2453 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
2454 DP_TRAIN_PRE_EMPHASIS_MASK);
2455 switch (signal_levels) {
2456 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
2457 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
2458 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
2459 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
2460 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
2461 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
2462 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
2463 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
2464 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
2465 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
2466 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
2467 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
2468 case DP_TRAIN_VOLTAGE_SWING_1200 | DP_TRAIN_PRE_EMPHASIS_0:
2469 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
2471 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
2472 "0x%x\n", signal_levels);
2473 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
2477 /* Gen7's DP voltage swing and pre-emphasis control */
2479 intel_gen7_edp_signal_levels(uint8_t train_set)
2481 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
2482 DP_TRAIN_PRE_EMPHASIS_MASK);
2483 switch (signal_levels) {
2484 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
2485 return EDP_LINK_TRAIN_400MV_0DB_IVB;
2486 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
2487 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
2488 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
2489 return EDP_LINK_TRAIN_400MV_6DB_IVB;
2491 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
2492 return EDP_LINK_TRAIN_600MV_0DB_IVB;
2493 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
2494 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
2496 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
2497 return EDP_LINK_TRAIN_800MV_0DB_IVB;
2498 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
2499 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
2502 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
2503 "0x%x\n", signal_levels);
2504 return EDP_LINK_TRAIN_500MV_0DB_IVB;
2508 /* Gen7.5's (HSW) DP voltage swing and pre-emphasis control */
2510 intel_hsw_signal_levels(uint8_t train_set)
2512 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
2513 DP_TRAIN_PRE_EMPHASIS_MASK);
2514 switch (signal_levels) {
2515 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
2516 return DDI_BUF_EMP_400MV_0DB_HSW;
2517 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
2518 return DDI_BUF_EMP_400MV_3_5DB_HSW;
2519 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
2520 return DDI_BUF_EMP_400MV_6DB_HSW;
2521 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_9_5:
2522 return DDI_BUF_EMP_400MV_9_5DB_HSW;
2524 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
2525 return DDI_BUF_EMP_600MV_0DB_HSW;
2526 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
2527 return DDI_BUF_EMP_600MV_3_5DB_HSW;
2528 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
2529 return DDI_BUF_EMP_600MV_6DB_HSW;
2531 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
2532 return DDI_BUF_EMP_800MV_0DB_HSW;
2533 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
2534 return DDI_BUF_EMP_800MV_3_5DB_HSW;
2536 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
2537 "0x%x\n", signal_levels);
2538 return DDI_BUF_EMP_400MV_0DB_HSW;
2543 intel_bdw_signal_levels(uint8_t train_set)
2545 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
2546 DP_TRAIN_PRE_EMPHASIS_MASK);
2547 switch (signal_levels) {
2548 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
2549 return DDI_BUF_EMP_400MV_0DB_BDW; /* Sel0 */
2550 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
2551 return DDI_BUF_EMP_400MV_3_5DB_BDW; /* Sel1 */
2552 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
2553 return DDI_BUF_EMP_400MV_6DB_BDW; /* Sel2 */
2555 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
2556 return DDI_BUF_EMP_600MV_0DB_BDW; /* Sel3 */
2557 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
2558 return DDI_BUF_EMP_600MV_3_5DB_BDW; /* Sel4 */
2559 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
2560 return DDI_BUF_EMP_600MV_6DB_BDW; /* Sel5 */
2562 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
2563 return DDI_BUF_EMP_800MV_0DB_BDW; /* Sel6 */
2564 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
2565 return DDI_BUF_EMP_800MV_3_5DB_BDW; /* Sel7 */
2567 case DP_TRAIN_VOLTAGE_SWING_1200 | DP_TRAIN_PRE_EMPHASIS_0:
2568 return DDI_BUF_EMP_1200MV_0DB_BDW; /* Sel8 */
2571 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
2572 "0x%x\n", signal_levels);
2573 return DDI_BUF_EMP_400MV_0DB_BDW; /* Sel0 */
2577 /* Properly updates "DP" with the correct signal levels. */
2579 intel_dp_set_signal_levels(struct intel_dp *intel_dp, uint32_t *DP)
2581 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2582 enum port port = intel_dig_port->port;
2583 struct drm_device *dev = intel_dig_port->base.base.dev;
2584 uint32_t signal_levels, mask;
2585 uint8_t train_set = intel_dp->train_set[0];
2587 if (IS_BROADWELL(dev)) {
2588 signal_levels = intel_bdw_signal_levels(train_set);
2589 mask = DDI_BUF_EMP_MASK;
2590 } else if (IS_HASWELL(dev)) {
2591 signal_levels = intel_hsw_signal_levels(train_set);
2592 mask = DDI_BUF_EMP_MASK;
2593 } else if (IS_CHERRYVIEW(dev)) {
2594 signal_levels = intel_chv_signal_levels(intel_dp);
2596 } else if (IS_VALLEYVIEW(dev)) {
2597 signal_levels = intel_vlv_signal_levels(intel_dp);
2599 } else if (IS_GEN7(dev) && port == PORT_A) {
2600 signal_levels = intel_gen7_edp_signal_levels(train_set);
2601 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
2602 } else if (IS_GEN6(dev) && port == PORT_A) {
2603 signal_levels = intel_gen6_edp_signal_levels(train_set);
2604 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
2606 signal_levels = intel_gen4_signal_levels(train_set);
2607 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
2610 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
2612 *DP = (*DP & ~mask) | signal_levels;
2616 intel_dp_set_link_train(struct intel_dp *intel_dp,
2618 uint8_t dp_train_pat)
2620 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2621 struct drm_device *dev = intel_dig_port->base.base.dev;
2622 struct drm_i915_private *dev_priv = dev->dev_private;
2623 enum port port = intel_dig_port->port;
2624 uint8_t buf[sizeof(intel_dp->train_set) + 1];
2628 uint32_t temp = I915_READ(DP_TP_CTL(port));
2630 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2631 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2633 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2635 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2636 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2637 case DP_TRAINING_PATTERN_DISABLE:
2638 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2641 case DP_TRAINING_PATTERN_1:
2642 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2644 case DP_TRAINING_PATTERN_2:
2645 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2647 case DP_TRAINING_PATTERN_3:
2648 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2651 I915_WRITE(DP_TP_CTL(port), temp);
2653 } else if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || port != PORT_A)) {
2654 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2656 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2657 case DP_TRAINING_PATTERN_DISABLE:
2658 *DP |= DP_LINK_TRAIN_OFF_CPT;
2660 case DP_TRAINING_PATTERN_1:
2661 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2663 case DP_TRAINING_PATTERN_2:
2664 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2666 case DP_TRAINING_PATTERN_3:
2667 DRM_ERROR("DP training pattern 3 not supported\n");
2668 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2673 *DP &= ~DP_LINK_TRAIN_MASK;
2675 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2676 case DP_TRAINING_PATTERN_DISABLE:
2677 *DP |= DP_LINK_TRAIN_OFF;
2679 case DP_TRAINING_PATTERN_1:
2680 *DP |= DP_LINK_TRAIN_PAT_1;
2682 case DP_TRAINING_PATTERN_2:
2683 *DP |= DP_LINK_TRAIN_PAT_2;
2685 case DP_TRAINING_PATTERN_3:
2686 DRM_ERROR("DP training pattern 3 not supported\n");
2687 *DP |= DP_LINK_TRAIN_PAT_2;
2692 I915_WRITE(intel_dp->output_reg, *DP);
2693 POSTING_READ(intel_dp->output_reg);
2695 buf[0] = dp_train_pat;
2696 if ((dp_train_pat & DP_TRAINING_PATTERN_MASK) ==
2697 DP_TRAINING_PATTERN_DISABLE) {
2698 /* don't write DP_TRAINING_LANEx_SET on disable */
2701 /* DP_TRAINING_LANEx_SET follow DP_TRAINING_PATTERN_SET */
2702 memcpy(buf + 1, intel_dp->train_set, intel_dp->lane_count);
2703 len = intel_dp->lane_count + 1;
2706 ret = drm_dp_dpcd_write(&intel_dp->aux, DP_TRAINING_PATTERN_SET,
2713 intel_dp_reset_link_train(struct intel_dp *intel_dp, uint32_t *DP,
2714 uint8_t dp_train_pat)
2716 memset(intel_dp->train_set, 0, sizeof(intel_dp->train_set));
2717 intel_dp_set_signal_levels(intel_dp, DP);
2718 return intel_dp_set_link_train(intel_dp, DP, dp_train_pat);
2722 intel_dp_update_link_train(struct intel_dp *intel_dp, uint32_t *DP,
2723 const uint8_t link_status[DP_LINK_STATUS_SIZE])
2725 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2726 struct drm_device *dev = intel_dig_port->base.base.dev;
2727 struct drm_i915_private *dev_priv = dev->dev_private;
2730 intel_get_adjust_train(intel_dp, link_status);
2731 intel_dp_set_signal_levels(intel_dp, DP);
2733 I915_WRITE(intel_dp->output_reg, *DP);
2734 POSTING_READ(intel_dp->output_reg);
2736 ret = drm_dp_dpcd_write(&intel_dp->aux, DP_TRAINING_LANE0_SET,
2737 intel_dp->train_set, intel_dp->lane_count);
2739 return ret == intel_dp->lane_count;
2742 static void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
2744 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2745 struct drm_device *dev = intel_dig_port->base.base.dev;
2746 struct drm_i915_private *dev_priv = dev->dev_private;
2747 enum port port = intel_dig_port->port;
2753 val = I915_READ(DP_TP_CTL(port));
2754 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2755 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
2756 I915_WRITE(DP_TP_CTL(port), val);
2759 * On PORT_A we can have only eDP in SST mode. There the only reason
2760 * we need to set idle transmission mode is to work around a HW issue
2761 * where we enable the pipe while not in idle link-training mode.
2762 * In this case there is requirement to wait for a minimum number of
2763 * idle patterns to be sent.
2768 if (wait_for((I915_READ(DP_TP_STATUS(port)) & DP_TP_STATUS_IDLE_DONE),
2770 DRM_ERROR("Timed out waiting for DP idle patterns\n");
2773 /* Enable corresponding port and start training pattern 1 */
2775 intel_dp_start_link_train(struct intel_dp *intel_dp)
2777 struct drm_encoder *encoder = &dp_to_dig_port(intel_dp)->base.base;
2778 struct drm_device *dev = encoder->dev;
2781 int voltage_tries, loop_tries;
2782 uint32_t DP = intel_dp->DP;
2783 uint8_t link_config[2];
2786 intel_ddi_prepare_link_retrain(encoder);
2788 /* Write the link configuration data */
2789 link_config[0] = intel_dp->link_bw;
2790 link_config[1] = intel_dp->lane_count;
2791 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
2792 link_config[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
2793 drm_dp_dpcd_write(&intel_dp->aux, DP_LINK_BW_SET, link_config, 2);
2796 link_config[1] = DP_SET_ANSI_8B10B;
2797 drm_dp_dpcd_write(&intel_dp->aux, DP_DOWNSPREAD_CTRL, link_config, 2);
2801 /* clock recovery */
2802 if (!intel_dp_reset_link_train(intel_dp, &DP,
2803 DP_TRAINING_PATTERN_1 |
2804 DP_LINK_SCRAMBLING_DISABLE)) {
2805 DRM_ERROR("failed to enable link training\n");
2813 uint8_t link_status[DP_LINK_STATUS_SIZE];
2815 drm_dp_link_train_clock_recovery_delay(intel_dp->dpcd);
2816 if (!intel_dp_get_link_status(intel_dp, link_status)) {
2817 DRM_ERROR("failed to get link status\n");
2821 if (drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
2822 DRM_DEBUG_KMS("clock recovery OK\n");
2826 /* Check to see if we've tried the max voltage */
2827 for (i = 0; i < intel_dp->lane_count; i++)
2828 if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
2830 if (i == intel_dp->lane_count) {
2832 if (loop_tries == 5) {
2833 DRM_ERROR("too many full retries, give up\n");
2836 intel_dp_reset_link_train(intel_dp, &DP,
2837 DP_TRAINING_PATTERN_1 |
2838 DP_LINK_SCRAMBLING_DISABLE);
2843 /* Check to see if we've tried the same voltage 5 times */
2844 if ((intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) == voltage) {
2846 if (voltage_tries == 5) {
2847 DRM_ERROR("too many voltage retries, give up\n");
2852 voltage = intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
2854 /* Update training set as requested by target */
2855 if (!intel_dp_update_link_train(intel_dp, &DP, link_status)) {
2856 DRM_ERROR("failed to update link training\n");
2865 intel_dp_complete_link_train(struct intel_dp *intel_dp)
2867 bool channel_eq = false;
2868 int tries, cr_tries;
2869 uint32_t DP = intel_dp->DP;
2870 uint32_t training_pattern = DP_TRAINING_PATTERN_2;
2872 /* Training Pattern 3 for HBR2 ot 1.2 devices that support it*/
2873 if (intel_dp->link_bw == DP_LINK_BW_5_4 || intel_dp->use_tps3)
2874 training_pattern = DP_TRAINING_PATTERN_3;
2876 /* channel equalization */
2877 if (!intel_dp_set_link_train(intel_dp, &DP,
2879 DP_LINK_SCRAMBLING_DISABLE)) {
2880 DRM_ERROR("failed to start channel equalization\n");
2888 uint8_t link_status[DP_LINK_STATUS_SIZE];
2891 DRM_ERROR("failed to train DP, aborting\n");
2895 drm_dp_link_train_channel_eq_delay(intel_dp->dpcd);
2896 if (!intel_dp_get_link_status(intel_dp, link_status)) {
2897 DRM_ERROR("failed to get link status\n");
2901 /* Make sure clock is still ok */
2902 if (!drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
2903 intel_dp_start_link_train(intel_dp);
2904 intel_dp_set_link_train(intel_dp, &DP,
2906 DP_LINK_SCRAMBLING_DISABLE);
2911 if (drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
2916 /* Try 5 times, then try clock recovery if that fails */
2918 intel_dp_link_down(intel_dp);
2919 intel_dp_start_link_train(intel_dp);
2920 intel_dp_set_link_train(intel_dp, &DP,
2922 DP_LINK_SCRAMBLING_DISABLE);
2928 /* Update training set as requested by target */
2929 if (!intel_dp_update_link_train(intel_dp, &DP, link_status)) {
2930 DRM_ERROR("failed to update link training\n");
2936 intel_dp_set_idle_link_train(intel_dp);
2941 DRM_DEBUG_KMS("Channel EQ done. DP Training successful\n");
2945 void intel_dp_stop_link_train(struct intel_dp *intel_dp)
2947 intel_dp_set_link_train(intel_dp, &intel_dp->DP,
2948 DP_TRAINING_PATTERN_DISABLE);
2952 intel_dp_link_down(struct intel_dp *intel_dp)
2954 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2955 enum port port = intel_dig_port->port;
2956 struct drm_device *dev = intel_dig_port->base.base.dev;
2957 struct drm_i915_private *dev_priv = dev->dev_private;
2958 struct intel_crtc *intel_crtc =
2959 to_intel_crtc(intel_dig_port->base.base.crtc);
2960 uint32_t DP = intel_dp->DP;
2963 * DDI code has a strict mode set sequence and we should try to respect
2964 * it, otherwise we might hang the machine in many different ways. So we
2965 * really should be disabling the port only on a complete crtc_disable
2966 * sequence. This function is just called under two conditions on DDI
2968 * - Link train failed while doing crtc_enable, and on this case we
2969 * really should respect the mode set sequence and wait for a
2971 * - Someone turned the monitor off and intel_dp_check_link_status
2972 * called us. We don't need to disable the whole port on this case, so
2973 * when someone turns the monitor on again,
2974 * intel_ddi_prepare_link_retrain will take care of redoing the link
2980 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
2983 DRM_DEBUG_KMS("\n");
2985 if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || port != PORT_A)) {
2986 DP &= ~DP_LINK_TRAIN_MASK_CPT;
2987 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT);
2989 DP &= ~DP_LINK_TRAIN_MASK;
2990 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE);
2992 POSTING_READ(intel_dp->output_reg);
2994 if (HAS_PCH_IBX(dev) &&
2995 I915_READ(intel_dp->output_reg) & DP_PIPEB_SELECT) {
2996 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
2998 /* Hardware workaround: leaving our transcoder select
2999 * set to transcoder B while it's off will prevent the
3000 * corresponding HDMI output on transcoder A.
3002 * Combine this with another hardware workaround:
3003 * transcoder select bit can only be cleared while the
3006 DP &= ~DP_PIPEB_SELECT;
3007 I915_WRITE(intel_dp->output_reg, DP);
3009 /* Changes to enable or select take place the vblank
3010 * after being written.
3012 if (WARN_ON(crtc == NULL)) {
3013 /* We should never try to disable a port without a crtc
3014 * attached. For paranoia keep the code around for a
3016 POSTING_READ(intel_dp->output_reg);
3019 intel_wait_for_vblank(dev, intel_crtc->pipe);
3022 DP &= ~DP_AUDIO_OUTPUT_ENABLE;
3023 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
3024 POSTING_READ(intel_dp->output_reg);
3025 msleep(intel_dp->panel_power_down_delay);
3029 intel_dp_get_dpcd(struct intel_dp *intel_dp)
3031 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
3032 struct drm_device *dev = dig_port->base.base.dev;
3033 struct drm_i915_private *dev_priv = dev->dev_private;
3035 char dpcd_hex_dump[sizeof(intel_dp->dpcd) * 3];
3037 if (intel_dp_dpcd_read_wake(&intel_dp->aux, 0x000, intel_dp->dpcd,
3038 sizeof(intel_dp->dpcd)) < 0)
3039 return false; /* aux transfer failed */
3041 hex_dump_to_buffer(intel_dp->dpcd, sizeof(intel_dp->dpcd),
3042 32, 1, dpcd_hex_dump, sizeof(dpcd_hex_dump), false);
3043 DRM_DEBUG_KMS("DPCD: %s\n", dpcd_hex_dump);
3045 if (intel_dp->dpcd[DP_DPCD_REV] == 0)
3046 return false; /* DPCD not present */
3048 /* Check if the panel supports PSR */
3049 memset(intel_dp->psr_dpcd, 0, sizeof(intel_dp->psr_dpcd));
3050 if (is_edp(intel_dp)) {
3051 intel_dp_dpcd_read_wake(&intel_dp->aux, DP_PSR_SUPPORT,
3053 sizeof(intel_dp->psr_dpcd));
3054 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3055 dev_priv->psr.sink_support = true;
3056 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3060 /* Training Pattern 3 support */
3061 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x12 &&
3062 intel_dp->dpcd[DP_MAX_LANE_COUNT] & DP_TPS3_SUPPORTED) {
3063 intel_dp->use_tps3 = true;
3064 DRM_DEBUG_KMS("Displayport TPS3 supported");
3066 intel_dp->use_tps3 = false;
3068 if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
3069 DP_DWN_STRM_PORT_PRESENT))
3070 return true; /* native DP sink */
3072 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3073 return true; /* no per-port downstream info */
3075 if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3076 intel_dp->downstream_ports,
3077 DP_MAX_DOWNSTREAM_PORTS) < 0)
3078 return false; /* downstream port status fetch failed */
3084 intel_dp_probe_oui(struct intel_dp *intel_dp)
3088 if (!(intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] & DP_OUI_SUPPORT))
3091 intel_edp_panel_vdd_on(intel_dp);
3093 if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_SINK_OUI, buf, 3) == 3)
3094 DRM_DEBUG_KMS("Sink OUI: %02hx%02hx%02hx\n",
3095 buf[0], buf[1], buf[2]);
3097 if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_BRANCH_OUI, buf, 3) == 3)
3098 DRM_DEBUG_KMS("Branch OUI: %02hx%02hx%02hx\n",
3099 buf[0], buf[1], buf[2]);
3101 edp_panel_vdd_off(intel_dp, false);
3104 int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3106 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3107 struct drm_device *dev = intel_dig_port->base.base.dev;
3108 struct intel_crtc *intel_crtc =
3109 to_intel_crtc(intel_dig_port->base.base.crtc);
3112 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, buf) < 0)
3115 if (!(buf[0] & DP_TEST_CRC_SUPPORTED))
3118 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3119 DP_TEST_SINK_START) < 0)
3122 /* Wait 2 vblanks to be sure we will have the correct CRC value */
3123 intel_wait_for_vblank(dev, intel_crtc->pipe);
3124 intel_wait_for_vblank(dev, intel_crtc->pipe);
3126 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0)
3129 drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK, 0);
3134 intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3136 return intel_dp_dpcd_read_wake(&intel_dp->aux,
3137 DP_DEVICE_SERVICE_IRQ_VECTOR,
3138 sink_irq_vector, 1) == 1;
3142 intel_dp_handle_test_request(struct intel_dp *intel_dp)
3144 /* NAK by default */
3145 drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, DP_TEST_NAK);
3149 * According to DP spec
3152 * 2. Configure link according to Receiver Capabilities
3153 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
3154 * 4. Check link status on receipt of hot-plug interrupt
3158 intel_dp_check_link_status(struct intel_dp *intel_dp)
3160 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
3162 u8 link_status[DP_LINK_STATUS_SIZE];
3164 if (!intel_encoder->connectors_active)
3167 if (WARN_ON(!intel_encoder->base.crtc))
3170 /* Try to read receiver status if the link appears to be up */
3171 if (!intel_dp_get_link_status(intel_dp, link_status)) {
3175 /* Now read the DPCD to see if it's actually running */
3176 if (!intel_dp_get_dpcd(intel_dp)) {
3180 /* Try to read the source of the interrupt */
3181 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
3182 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector)) {
3183 /* Clear interrupt source */
3184 drm_dp_dpcd_writeb(&intel_dp->aux,
3185 DP_DEVICE_SERVICE_IRQ_VECTOR,
3188 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
3189 intel_dp_handle_test_request(intel_dp);
3190 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
3191 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
3194 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
3195 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
3196 drm_get_encoder_name(&intel_encoder->base));
3197 intel_dp_start_link_train(intel_dp);
3198 intel_dp_complete_link_train(intel_dp);
3199 intel_dp_stop_link_train(intel_dp);
3203 /* XXX this is probably wrong for multiple downstream ports */
3204 static enum drm_connector_status
3205 intel_dp_detect_dpcd(struct intel_dp *intel_dp)
3207 uint8_t *dpcd = intel_dp->dpcd;
3210 if (!intel_dp_get_dpcd(intel_dp))
3211 return connector_status_disconnected;
3213 /* if there's no downstream port, we're done */
3214 if (!(dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT))
3215 return connector_status_connected;
3217 /* If we're HPD-aware, SINK_COUNT changes dynamically */
3218 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
3219 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
3222 if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_SINK_COUNT,
3224 return connector_status_unknown;
3226 return DP_GET_SINK_COUNT(reg) ? connector_status_connected
3227 : connector_status_disconnected;
3230 /* If no HPD, poke DDC gently */
3231 if (drm_probe_ddc(&intel_dp->aux.ddc))
3232 return connector_status_connected;
3234 /* Well we tried, say unknown for unreliable port types */
3235 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
3236 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
3237 if (type == DP_DS_PORT_TYPE_VGA ||
3238 type == DP_DS_PORT_TYPE_NON_EDID)
3239 return connector_status_unknown;
3241 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
3242 DP_DWN_STRM_PORT_TYPE_MASK;
3243 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
3244 type == DP_DWN_STRM_PORT_TYPE_OTHER)
3245 return connector_status_unknown;
3248 /* Anything else is out of spec, warn and ignore */
3249 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
3250 return connector_status_disconnected;
3253 static enum drm_connector_status
3254 ironlake_dp_detect(struct intel_dp *intel_dp)
3256 struct drm_device *dev = intel_dp_to_dev(intel_dp);
3257 struct drm_i915_private *dev_priv = dev->dev_private;
3258 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3259 enum drm_connector_status status;
3261 /* Can't disconnect eDP, but you can close the lid... */
3262 if (is_edp(intel_dp)) {
3263 status = intel_panel_detect(dev);
3264 if (status == connector_status_unknown)
3265 status = connector_status_connected;
3269 if (!ibx_digital_port_connected(dev_priv, intel_dig_port))
3270 return connector_status_disconnected;
3272 return intel_dp_detect_dpcd(intel_dp);
3275 static enum drm_connector_status
3276 g4x_dp_detect(struct intel_dp *intel_dp)
3278 struct drm_device *dev = intel_dp_to_dev(intel_dp);
3279 struct drm_i915_private *dev_priv = dev->dev_private;
3280 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3283 /* Can't disconnect eDP, but you can close the lid... */
3284 if (is_edp(intel_dp)) {
3285 enum drm_connector_status status;
3287 status = intel_panel_detect(dev);
3288 if (status == connector_status_unknown)
3289 status = connector_status_connected;
3293 if (IS_VALLEYVIEW(dev)) {
3294 switch (intel_dig_port->port) {
3296 bit = PORTB_HOTPLUG_LIVE_STATUS_VLV;
3299 bit = PORTC_HOTPLUG_LIVE_STATUS_VLV;
3302 bit = PORTD_HOTPLUG_LIVE_STATUS_VLV;
3305 return connector_status_unknown;
3308 switch (intel_dig_port->port) {
3310 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
3313 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
3316 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
3319 return connector_status_unknown;
3323 if ((I915_READ(PORT_HOTPLUG_STAT) & bit) == 0)
3324 return connector_status_disconnected;
3326 return intel_dp_detect_dpcd(intel_dp);
3329 static struct edid *
3330 intel_dp_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
3332 struct intel_connector *intel_connector = to_intel_connector(connector);
3334 /* use cached edid if we have one */
3335 if (intel_connector->edid) {
3337 if (IS_ERR(intel_connector->edid))
3340 return drm_edid_duplicate(intel_connector->edid);
3343 return drm_get_edid(connector, adapter);
3347 intel_dp_get_edid_modes(struct drm_connector *connector, struct i2c_adapter *adapter)
3349 struct intel_connector *intel_connector = to_intel_connector(connector);
3351 /* use cached edid if we have one */
3352 if (intel_connector->edid) {
3354 if (IS_ERR(intel_connector->edid))
3357 return intel_connector_update_modes(connector,
3358 intel_connector->edid);
3361 return intel_ddc_get_modes(connector, adapter);
3364 static enum drm_connector_status
3365 intel_dp_detect(struct drm_connector *connector, bool force)
3367 struct intel_dp *intel_dp = intel_attached_dp(connector);
3368 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3369 struct intel_encoder *intel_encoder = &intel_dig_port->base;
3370 struct drm_device *dev = connector->dev;
3371 struct drm_i915_private *dev_priv = dev->dev_private;
3372 enum drm_connector_status status;
3373 enum intel_display_power_domain power_domain;
3374 struct edid *edid = NULL;
3376 intel_runtime_pm_get(dev_priv);
3378 power_domain = intel_display_port_power_domain(intel_encoder);
3379 intel_display_power_get(dev_priv, power_domain);
3381 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
3382 connector->base.id, drm_get_connector_name(connector));
3384 intel_dp->has_audio = false;
3386 if (HAS_PCH_SPLIT(dev))
3387 status = ironlake_dp_detect(intel_dp);
3389 status = g4x_dp_detect(intel_dp);
3391 if (status != connector_status_connected)
3394 intel_dp_probe_oui(intel_dp);
3396 if (intel_dp->force_audio != HDMI_AUDIO_AUTO) {
3397 intel_dp->has_audio = (intel_dp->force_audio == HDMI_AUDIO_ON);
3399 edid = intel_dp_get_edid(connector, &intel_dp->aux.ddc);
3401 intel_dp->has_audio = drm_detect_monitor_audio(edid);
3406 if (intel_encoder->type != INTEL_OUTPUT_EDP)
3407 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
3408 status = connector_status_connected;
3411 intel_display_power_put(dev_priv, power_domain);
3413 intel_runtime_pm_put(dev_priv);
3418 static int intel_dp_get_modes(struct drm_connector *connector)
3420 struct intel_dp *intel_dp = intel_attached_dp(connector);
3421 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3422 struct intel_encoder *intel_encoder = &intel_dig_port->base;
3423 struct intel_connector *intel_connector = to_intel_connector(connector);
3424 struct drm_device *dev = connector->dev;
3425 struct drm_i915_private *dev_priv = dev->dev_private;
3426 enum intel_display_power_domain power_domain;
3429 /* We should parse the EDID data and find out if it has an audio sink
3432 power_domain = intel_display_port_power_domain(intel_encoder);
3433 intel_display_power_get(dev_priv, power_domain);
3435 ret = intel_dp_get_edid_modes(connector, &intel_dp->aux.ddc);
3436 intel_display_power_put(dev_priv, power_domain);
3440 /* if eDP has no EDID, fall back to fixed mode */
3441 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
3442 struct drm_display_mode *mode;
3443 mode = drm_mode_duplicate(dev,
3444 intel_connector->panel.fixed_mode);
3446 drm_mode_probed_add(connector, mode);
3454 intel_dp_detect_audio(struct drm_connector *connector)
3456 struct intel_dp *intel_dp = intel_attached_dp(connector);
3457 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3458 struct intel_encoder *intel_encoder = &intel_dig_port->base;
3459 struct drm_device *dev = connector->dev;
3460 struct drm_i915_private *dev_priv = dev->dev_private;
3461 enum intel_display_power_domain power_domain;
3463 bool has_audio = false;
3465 power_domain = intel_display_port_power_domain(intel_encoder);
3466 intel_display_power_get(dev_priv, power_domain);
3468 edid = intel_dp_get_edid(connector, &intel_dp->aux.ddc);
3470 has_audio = drm_detect_monitor_audio(edid);
3474 intel_display_power_put(dev_priv, power_domain);
3480 intel_dp_set_property(struct drm_connector *connector,
3481 struct drm_property *property,
3484 struct drm_i915_private *dev_priv = connector->dev->dev_private;
3485 struct intel_connector *intel_connector = to_intel_connector(connector);
3486 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
3487 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
3490 ret = drm_object_property_set_value(&connector->base, property, val);
3494 if (property == dev_priv->force_audio_property) {
3498 if (i == intel_dp->force_audio)
3501 intel_dp->force_audio = i;
3503 if (i == HDMI_AUDIO_AUTO)
3504 has_audio = intel_dp_detect_audio(connector);
3506 has_audio = (i == HDMI_AUDIO_ON);
3508 if (has_audio == intel_dp->has_audio)
3511 intel_dp->has_audio = has_audio;
3515 if (property == dev_priv->broadcast_rgb_property) {
3516 bool old_auto = intel_dp->color_range_auto;
3517 uint32_t old_range = intel_dp->color_range;
3520 case INTEL_BROADCAST_RGB_AUTO:
3521 intel_dp->color_range_auto = true;
3523 case INTEL_BROADCAST_RGB_FULL:
3524 intel_dp->color_range_auto = false;
3525 intel_dp->color_range = 0;
3527 case INTEL_BROADCAST_RGB_LIMITED:
3528 intel_dp->color_range_auto = false;
3529 intel_dp->color_range = DP_COLOR_RANGE_16_235;
3535 if (old_auto == intel_dp->color_range_auto &&
3536 old_range == intel_dp->color_range)
3542 if (is_edp(intel_dp) &&
3543 property == connector->dev->mode_config.scaling_mode_property) {
3544 if (val == DRM_MODE_SCALE_NONE) {
3545 DRM_DEBUG_KMS("no scaling not supported\n");
3549 if (intel_connector->panel.fitting_mode == val) {
3550 /* the eDP scaling property is not changed */
3553 intel_connector->panel.fitting_mode = val;
3561 if (intel_encoder->base.crtc)
3562 intel_crtc_restore_mode(intel_encoder->base.crtc);
3568 intel_dp_connector_destroy(struct drm_connector *connector)
3570 struct intel_connector *intel_connector = to_intel_connector(connector);
3572 if (!IS_ERR_OR_NULL(intel_connector->edid))
3573 kfree(intel_connector->edid);
3575 /* Can't call is_edp() since the encoder may have been destroyed
3577 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
3578 intel_panel_fini(&intel_connector->panel);
3580 drm_connector_cleanup(connector);
3584 void intel_dp_encoder_destroy(struct drm_encoder *encoder)
3586 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
3587 struct intel_dp *intel_dp = &intel_dig_port->dp;
3588 struct drm_device *dev = intel_dp_to_dev(intel_dp);
3590 drm_dp_aux_unregister_i2c_bus(&intel_dp->aux);
3591 drm_encoder_cleanup(encoder);
3592 if (is_edp(intel_dp)) {
3593 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
3594 mutex_lock(&dev->mode_config.mutex);
3595 edp_panel_vdd_off_sync(intel_dp);
3596 mutex_unlock(&dev->mode_config.mutex);
3598 kfree(intel_dig_port);
3601 static const struct drm_connector_funcs intel_dp_connector_funcs = {
3602 .dpms = intel_connector_dpms,
3603 .detect = intel_dp_detect,
3604 .fill_modes = drm_helper_probe_single_connector_modes,
3605 .set_property = intel_dp_set_property,
3606 .destroy = intel_dp_connector_destroy,
3609 static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
3610 .get_modes = intel_dp_get_modes,
3611 .mode_valid = intel_dp_mode_valid,
3612 .best_encoder = intel_best_encoder,
3615 static const struct drm_encoder_funcs intel_dp_enc_funcs = {
3616 .destroy = intel_dp_encoder_destroy,
3620 intel_dp_hot_plug(struct intel_encoder *intel_encoder)
3622 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
3624 intel_dp_check_link_status(intel_dp);
3627 /* Return which DP Port should be selected for Transcoder DP control */
3629 intel_trans_dp_port_sel(struct drm_crtc *crtc)
3631 struct drm_device *dev = crtc->dev;
3632 struct intel_encoder *intel_encoder;
3633 struct intel_dp *intel_dp;
3635 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
3636 intel_dp = enc_to_intel_dp(&intel_encoder->base);
3638 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
3639 intel_encoder->type == INTEL_OUTPUT_EDP)
3640 return intel_dp->output_reg;
3646 /* check the VBT to see whether the eDP is on DP-D port */
3647 bool intel_dp_is_edp(struct drm_device *dev, enum port port)
3649 struct drm_i915_private *dev_priv = dev->dev_private;
3650 union child_device_config *p_child;
3652 static const short port_mapping[] = {
3653 [PORT_B] = PORT_IDPB,
3654 [PORT_C] = PORT_IDPC,
3655 [PORT_D] = PORT_IDPD,
3661 if (!dev_priv->vbt.child_dev_num)
3664 for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
3665 p_child = dev_priv->vbt.child_dev + i;
3667 if (p_child->common.dvo_port == port_mapping[port] &&
3668 (p_child->common.device_type & DEVICE_TYPE_eDP_BITS) ==
3669 (DEVICE_TYPE_eDP & DEVICE_TYPE_eDP_BITS))
3676 intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
3678 struct intel_connector *intel_connector = to_intel_connector(connector);
3680 intel_attach_force_audio_property(connector);
3681 intel_attach_broadcast_rgb_property(connector);
3682 intel_dp->color_range_auto = true;
3684 if (is_edp(intel_dp)) {
3685 drm_mode_create_scaling_mode_property(connector->dev);
3686 drm_object_attach_property(
3688 connector->dev->mode_config.scaling_mode_property,
3689 DRM_MODE_SCALE_ASPECT);
3690 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
3694 static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
3696 intel_dp->last_power_cycle = jiffies;
3697 intel_dp->last_power_on = jiffies;
3698 intel_dp->last_backlight_off = jiffies;
3702 intel_dp_init_panel_power_sequencer(struct drm_device *dev,
3703 struct intel_dp *intel_dp,
3704 struct edp_power_seq *out)
3706 struct drm_i915_private *dev_priv = dev->dev_private;
3707 struct edp_power_seq cur, vbt, spec, final;
3708 u32 pp_on, pp_off, pp_div, pp;
3709 int pp_ctrl_reg, pp_on_reg, pp_off_reg, pp_div_reg;
3711 if (HAS_PCH_SPLIT(dev)) {
3712 pp_ctrl_reg = PCH_PP_CONTROL;
3713 pp_on_reg = PCH_PP_ON_DELAYS;
3714 pp_off_reg = PCH_PP_OFF_DELAYS;
3715 pp_div_reg = PCH_PP_DIVISOR;
3717 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
3719 pp_ctrl_reg = VLV_PIPE_PP_CONTROL(pipe);
3720 pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe);
3721 pp_off_reg = VLV_PIPE_PP_OFF_DELAYS(pipe);
3722 pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe);
3725 /* Workaround: Need to write PP_CONTROL with the unlock key as
3726 * the very first thing. */
3727 pp = ironlake_get_pp_control(intel_dp);
3728 I915_WRITE(pp_ctrl_reg, pp);
3730 pp_on = I915_READ(pp_on_reg);
3731 pp_off = I915_READ(pp_off_reg);
3732 pp_div = I915_READ(pp_div_reg);
3734 /* Pull timing values out of registers */
3735 cur.t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
3736 PANEL_POWER_UP_DELAY_SHIFT;
3738 cur.t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
3739 PANEL_LIGHT_ON_DELAY_SHIFT;
3741 cur.t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
3742 PANEL_LIGHT_OFF_DELAY_SHIFT;
3744 cur.t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
3745 PANEL_POWER_DOWN_DELAY_SHIFT;
3747 cur.t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
3748 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
3750 DRM_DEBUG_KMS("cur t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
3751 cur.t1_t3, cur.t8, cur.t9, cur.t10, cur.t11_t12);
3753 vbt = dev_priv->vbt.edp_pps;
3755 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
3756 * our hw here, which are all in 100usec. */
3757 spec.t1_t3 = 210 * 10;
3758 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
3759 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
3760 spec.t10 = 500 * 10;
3761 /* This one is special and actually in units of 100ms, but zero
3762 * based in the hw (so we need to add 100 ms). But the sw vbt
3763 * table multiplies it with 1000 to make it in units of 100usec,
3765 spec.t11_t12 = (510 + 100) * 10;
3767 DRM_DEBUG_KMS("vbt t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
3768 vbt.t1_t3, vbt.t8, vbt.t9, vbt.t10, vbt.t11_t12);
3770 /* Use the max of the register settings and vbt. If both are
3771 * unset, fall back to the spec limits. */
3772 #define assign_final(field) final.field = (max(cur.field, vbt.field) == 0 ? \
3774 max(cur.field, vbt.field))
3775 assign_final(t1_t3);
3779 assign_final(t11_t12);
3782 #define get_delay(field) (DIV_ROUND_UP(final.field, 10))
3783 intel_dp->panel_power_up_delay = get_delay(t1_t3);
3784 intel_dp->backlight_on_delay = get_delay(t8);
3785 intel_dp->backlight_off_delay = get_delay(t9);
3786 intel_dp->panel_power_down_delay = get_delay(t10);
3787 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
3790 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
3791 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
3792 intel_dp->panel_power_cycle_delay);
3794 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
3795 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
3802 intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
3803 struct intel_dp *intel_dp,
3804 struct edp_power_seq *seq)
3806 struct drm_i915_private *dev_priv = dev->dev_private;
3807 u32 pp_on, pp_off, pp_div, port_sel = 0;
3808 int div = HAS_PCH_SPLIT(dev) ? intel_pch_rawclk(dev) : intel_hrawclk(dev);
3809 int pp_on_reg, pp_off_reg, pp_div_reg;
3811 if (HAS_PCH_SPLIT(dev)) {
3812 pp_on_reg = PCH_PP_ON_DELAYS;
3813 pp_off_reg = PCH_PP_OFF_DELAYS;
3814 pp_div_reg = PCH_PP_DIVISOR;
3816 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
3818 pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe);
3819 pp_off_reg = VLV_PIPE_PP_OFF_DELAYS(pipe);
3820 pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe);
3824 * And finally store the new values in the power sequencer. The
3825 * backlight delays are set to 1 because we do manual waits on them. For
3826 * T8, even BSpec recommends doing it. For T9, if we don't do this,
3827 * we'll end up waiting for the backlight off delay twice: once when we
3828 * do the manual sleep, and once when we disable the panel and wait for
3829 * the PP_STATUS bit to become zero.
3831 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
3832 (1 << PANEL_LIGHT_ON_DELAY_SHIFT);
3833 pp_off = (1 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
3834 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
3835 /* Compute the divisor for the pp clock, simply match the Bspec
3837 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
3838 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
3839 << PANEL_POWER_CYCLE_DELAY_SHIFT);
3841 /* Haswell doesn't have any port selection bits for the panel
3842 * power sequencer any more. */
3843 if (IS_VALLEYVIEW(dev)) {
3844 if (dp_to_dig_port(intel_dp)->port == PORT_B)
3845 port_sel = PANEL_PORT_SELECT_DPB_VLV;
3847 port_sel = PANEL_PORT_SELECT_DPC_VLV;
3848 } else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) {
3849 if (dp_to_dig_port(intel_dp)->port == PORT_A)
3850 port_sel = PANEL_PORT_SELECT_DPA;
3852 port_sel = PANEL_PORT_SELECT_DPD;
3857 I915_WRITE(pp_on_reg, pp_on);
3858 I915_WRITE(pp_off_reg, pp_off);
3859 I915_WRITE(pp_div_reg, pp_div);
3861 DRM_DEBUG_KMS("panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n",
3862 I915_READ(pp_on_reg),
3863 I915_READ(pp_off_reg),
3864 I915_READ(pp_div_reg));
3867 void intel_dp_set_drrs_state(struct drm_device *dev, int refresh_rate)
3869 struct drm_i915_private *dev_priv = dev->dev_private;
3870 struct intel_encoder *encoder;
3871 struct intel_dp *intel_dp = NULL;
3872 struct intel_crtc_config *config = NULL;
3873 struct intel_crtc *intel_crtc = NULL;
3874 struct intel_connector *intel_connector = dev_priv->drrs.connector;
3876 enum edp_drrs_refresh_rate_type index = DRRS_HIGH_RR;
3878 if (refresh_rate <= 0) {
3879 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
3883 if (intel_connector == NULL) {
3884 DRM_DEBUG_KMS("DRRS supported for eDP only.\n");
3888 if (INTEL_INFO(dev)->gen < 8 && intel_edp_is_psr_enabled(dev)) {
3889 DRM_DEBUG_KMS("DRRS is disabled as PSR is enabled\n");
3893 encoder = intel_attached_encoder(&intel_connector->base);
3894 intel_dp = enc_to_intel_dp(&encoder->base);
3895 intel_crtc = encoder->new_crtc;
3898 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
3902 config = &intel_crtc->config;
3904 if (intel_dp->drrs_state.type < SEAMLESS_DRRS_SUPPORT) {
3905 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
3909 if (intel_connector->panel.downclock_mode->vrefresh == refresh_rate)
3910 index = DRRS_LOW_RR;
3912 if (index == intel_dp->drrs_state.refresh_rate_type) {
3914 "DRRS requested for previously set RR...ignoring\n");
3918 if (!intel_crtc->active) {
3919 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
3923 if (INTEL_INFO(dev)->gen > 6 && INTEL_INFO(dev)->gen < 8) {
3924 reg = PIPECONF(intel_crtc->config.cpu_transcoder);
3925 val = I915_READ(reg);
3926 if (index > DRRS_HIGH_RR) {
3927 val |= PIPECONF_EDP_RR_MODE_SWITCH;
3928 intel_dp_set_m2_n2(intel_crtc, &config->dp_m2_n2);
3930 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
3932 I915_WRITE(reg, val);
3936 * mutex taken to ensure that there is no race between differnt
3937 * drrs calls trying to update refresh rate. This scenario may occur
3938 * in future when idleness detection based DRRS in kernel and
3939 * possible calls from user space to set differnt RR are made.
3942 mutex_lock(&intel_dp->drrs_state.mutex);
3944 intel_dp->drrs_state.refresh_rate_type = index;
3946 mutex_unlock(&intel_dp->drrs_state.mutex);
3948 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
3951 static struct drm_display_mode *
3952 intel_dp_drrs_init(struct intel_digital_port *intel_dig_port,
3953 struct intel_connector *intel_connector,
3954 struct drm_display_mode *fixed_mode)
3956 struct drm_connector *connector = &intel_connector->base;
3957 struct intel_dp *intel_dp = &intel_dig_port->dp;
3958 struct drm_device *dev = intel_dig_port->base.base.dev;
3959 struct drm_i915_private *dev_priv = dev->dev_private;
3960 struct drm_display_mode *downclock_mode = NULL;
3962 if (INTEL_INFO(dev)->gen <= 6) {
3963 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
3967 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
3968 DRM_INFO("VBT doesn't support DRRS\n");
3972 downclock_mode = intel_find_panel_downclock
3973 (dev, fixed_mode, connector);
3975 if (!downclock_mode) {
3976 DRM_INFO("DRRS not supported\n");
3980 dev_priv->drrs.connector = intel_connector;
3982 mutex_init(&intel_dp->drrs_state.mutex);
3984 intel_dp->drrs_state.type = dev_priv->vbt.drrs_type;
3986 intel_dp->drrs_state.refresh_rate_type = DRRS_HIGH_RR;
3987 DRM_INFO("seamless DRRS supported for eDP panel.\n");
3988 return downclock_mode;
3991 static bool intel_edp_init_connector(struct intel_dp *intel_dp,
3992 struct intel_connector *intel_connector,
3993 struct edp_power_seq *power_seq)
3995 struct drm_connector *connector = &intel_connector->base;
3996 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3997 struct intel_encoder *intel_encoder = &intel_dig_port->base;
3998 struct drm_device *dev = intel_encoder->base.dev;
3999 struct drm_i915_private *dev_priv = dev->dev_private;
4000 struct drm_display_mode *fixed_mode = NULL;
4001 struct drm_display_mode *downclock_mode = NULL;
4003 struct drm_display_mode *scan;
4006 intel_dp->drrs_state.type = DRRS_NOT_SUPPORTED;
4008 if (!is_edp(intel_dp))
4011 /* The VDD bit needs a power domain reference, so if the bit is already
4012 * enabled when we boot, grab this reference. */
4013 if (edp_have_panel_vdd(intel_dp)) {
4014 enum intel_display_power_domain power_domain;
4015 power_domain = intel_display_port_power_domain(intel_encoder);
4016 intel_display_power_get(dev_priv, power_domain);
4019 /* Cache DPCD and EDID for edp. */
4020 intel_edp_panel_vdd_on(intel_dp);
4021 has_dpcd = intel_dp_get_dpcd(intel_dp);
4022 edp_panel_vdd_off(intel_dp, false);
4025 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
4026 dev_priv->no_aux_handshake =
4027 intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
4028 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
4030 /* if this fails, presume the device is a ghost */
4031 DRM_INFO("failed to retrieve link info, disabling eDP\n");
4035 /* We now know it's not a ghost, init power sequence regs. */
4036 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, power_seq);
4038 mutex_lock(&dev->mode_config.mutex);
4039 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
4041 if (drm_add_edid_modes(connector, edid)) {
4042 drm_mode_connector_update_edid_property(connector,
4044 drm_edid_to_eld(connector, edid);
4047 edid = ERR_PTR(-EINVAL);
4050 edid = ERR_PTR(-ENOENT);
4052 intel_connector->edid = edid;
4054 /* prefer fixed mode from EDID if available */
4055 list_for_each_entry(scan, &connector->probed_modes, head) {
4056 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
4057 fixed_mode = drm_mode_duplicate(dev, scan);
4058 downclock_mode = intel_dp_drrs_init(
4060 intel_connector, fixed_mode);
4065 /* fallback to VBT if available for eDP */
4066 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
4067 fixed_mode = drm_mode_duplicate(dev,
4068 dev_priv->vbt.lfp_lvds_vbt_mode);
4070 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
4072 mutex_unlock(&dev->mode_config.mutex);
4074 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
4075 intel_panel_setup_backlight(connector);
4081 intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
4082 struct intel_connector *intel_connector)
4084 struct drm_connector *connector = &intel_connector->base;
4085 struct intel_dp *intel_dp = &intel_dig_port->dp;
4086 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4087 struct drm_device *dev = intel_encoder->base.dev;
4088 struct drm_i915_private *dev_priv = dev->dev_private;
4089 enum port port = intel_dig_port->port;
4090 struct edp_power_seq power_seq = { 0 };
4093 /* intel_dp vfuncs */
4094 if (IS_VALLEYVIEW(dev))
4095 intel_dp->get_aux_clock_divider = vlv_get_aux_clock_divider;
4096 else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
4097 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
4098 else if (HAS_PCH_SPLIT(dev))
4099 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
4101 intel_dp->get_aux_clock_divider = i9xx_get_aux_clock_divider;
4103 intel_dp->get_aux_send_ctl = i9xx_get_aux_send_ctl;
4105 /* Preserve the current hw state. */
4106 intel_dp->DP = I915_READ(intel_dp->output_reg);
4107 intel_dp->attached_connector = intel_connector;
4109 if (intel_dp_is_edp(dev, port))
4110 type = DRM_MODE_CONNECTOR_eDP;
4112 type = DRM_MODE_CONNECTOR_DisplayPort;
4115 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
4116 * for DP the encoder type can be set by the caller to
4117 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
4119 if (type == DRM_MODE_CONNECTOR_eDP)
4120 intel_encoder->type = INTEL_OUTPUT_EDP;
4122 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
4123 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
4126 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
4127 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
4129 connector->interlace_allowed = true;
4130 connector->doublescan_allowed = 0;
4132 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
4133 edp_panel_vdd_work);
4135 intel_connector_attach_encoder(intel_connector, intel_encoder);
4136 drm_sysfs_connector_add(connector);
4139 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
4141 intel_connector->get_hw_state = intel_connector_get_hw_state;
4142 intel_connector->unregister = intel_dp_connector_unregister;
4144 /* Set up the hotplug pin. */
4147 intel_encoder->hpd_pin = HPD_PORT_A;
4150 intel_encoder->hpd_pin = HPD_PORT_B;
4153 intel_encoder->hpd_pin = HPD_PORT_C;
4156 intel_encoder->hpd_pin = HPD_PORT_D;
4162 if (is_edp(intel_dp)) {
4163 intel_dp_init_panel_power_timestamps(intel_dp);
4164 intel_dp_init_panel_power_sequencer(dev, intel_dp, &power_seq);
4167 intel_dp_aux_init(intel_dp, intel_connector);
4169 intel_dp->psr_setup_done = false;
4171 if (!intel_edp_init_connector(intel_dp, intel_connector, &power_seq)) {
4172 drm_dp_aux_unregister_i2c_bus(&intel_dp->aux);
4173 if (is_edp(intel_dp)) {
4174 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
4175 mutex_lock(&dev->mode_config.mutex);
4176 edp_panel_vdd_off_sync(intel_dp);
4177 mutex_unlock(&dev->mode_config.mutex);
4179 drm_sysfs_connector_remove(connector);
4180 drm_connector_cleanup(connector);
4184 intel_dp_add_properties(intel_dp, connector);
4186 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
4187 * 0xd. Failure to do so will result in spurious interrupts being
4188 * generated on the port when a cable is not attached.
4190 if (IS_G4X(dev) && !IS_GM45(dev)) {
4191 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
4192 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
4199 intel_dp_init(struct drm_device *dev, int output_reg, enum port port)
4201 struct intel_digital_port *intel_dig_port;
4202 struct intel_encoder *intel_encoder;
4203 struct drm_encoder *encoder;
4204 struct intel_connector *intel_connector;
4206 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
4207 if (!intel_dig_port)
4210 intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
4211 if (!intel_connector) {
4212 kfree(intel_dig_port);
4216 intel_encoder = &intel_dig_port->base;
4217 encoder = &intel_encoder->base;
4219 drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
4220 DRM_MODE_ENCODER_TMDS);
4222 intel_encoder->compute_config = intel_dp_compute_config;
4223 intel_encoder->mode_set = intel_dp_mode_set;
4224 intel_encoder->disable = intel_disable_dp;
4225 intel_encoder->get_hw_state = intel_dp_get_hw_state;
4226 intel_encoder->get_config = intel_dp_get_config;
4227 if (IS_CHERRYVIEW(dev)) {
4228 intel_encoder->pre_enable = chv_pre_enable_dp;
4229 intel_encoder->enable = vlv_enable_dp;
4230 } else if (IS_VALLEYVIEW(dev)) {
4231 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
4232 intel_encoder->pre_enable = vlv_pre_enable_dp;
4233 intel_encoder->enable = vlv_enable_dp;
4234 intel_encoder->post_disable = vlv_post_disable_dp;
4236 intel_encoder->pre_enable = g4x_pre_enable_dp;
4237 intel_encoder->enable = g4x_enable_dp;
4238 intel_encoder->post_disable = g4x_post_disable_dp;
4241 intel_dig_port->port = port;
4242 intel_dig_port->dp.output_reg = output_reg;
4244 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
4245 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
4246 intel_encoder->cloneable = 0;
4247 intel_encoder->hot_plug = intel_dp_hot_plug;
4249 if (!intel_dp_init_connector(intel_dig_port, intel_connector)) {
4250 drm_encoder_cleanup(encoder);
4251 kfree(intel_dig_port);
4252 kfree(intel_connector);