1 // SPDX-License-Identifier: MIT
3 * Copyright © 2023 Intel Corporation
9 #include "intel_display_irq.h"
10 #include "intel_display_types.h"
11 #include "intel_dp_aux.h"
12 #include "intel_gmbus.h"
13 #include "intel_hotplug.h"
14 #include "intel_hotplug_irq.h"
16 typedef bool (*long_pulse_detect_func)(enum hpd_pin pin, u32 val);
17 typedef u32 (*hotplug_enables_func)(struct intel_encoder *encoder);
18 typedef u32 (*hotplug_mask_func)(enum hpd_pin pin);
20 static const u32 hpd_ilk[HPD_NUM_PINS] = {
21 [HPD_PORT_A] = DE_DP_A_HOTPLUG,
24 static const u32 hpd_ivb[HPD_NUM_PINS] = {
25 [HPD_PORT_A] = DE_DP_A_HOTPLUG_IVB,
28 static const u32 hpd_bdw[HPD_NUM_PINS] = {
29 [HPD_PORT_A] = GEN8_DE_PORT_HOTPLUG(HPD_PORT_A),
32 static const u32 hpd_ibx[HPD_NUM_PINS] = {
33 [HPD_CRT] = SDE_CRT_HOTPLUG,
34 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
35 [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
36 [HPD_PORT_C] = SDE_PORTC_HOTPLUG,
37 [HPD_PORT_D] = SDE_PORTD_HOTPLUG,
40 static const u32 hpd_cpt[HPD_NUM_PINS] = {
41 [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
42 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
43 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
44 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
45 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT,
48 static const u32 hpd_spt[HPD_NUM_PINS] = {
49 [HPD_PORT_A] = SDE_PORTA_HOTPLUG_SPT,
50 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
51 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
52 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT,
53 [HPD_PORT_E] = SDE_PORTE_HOTPLUG_SPT,
56 static const u32 hpd_mask_i915[HPD_NUM_PINS] = {
57 [HPD_CRT] = CRT_HOTPLUG_INT_EN,
58 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
59 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
60 [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
61 [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
62 [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN,
65 static const u32 hpd_status_g4x[HPD_NUM_PINS] = {
66 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
67 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
68 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
69 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
70 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
71 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS,
74 static const u32 hpd_status_i915[HPD_NUM_PINS] = {
75 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
76 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
77 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
78 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
79 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
80 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS,
83 static const u32 hpd_bxt[HPD_NUM_PINS] = {
84 [HPD_PORT_A] = GEN8_DE_PORT_HOTPLUG(HPD_PORT_A),
85 [HPD_PORT_B] = GEN8_DE_PORT_HOTPLUG(HPD_PORT_B),
86 [HPD_PORT_C] = GEN8_DE_PORT_HOTPLUG(HPD_PORT_C),
89 static const u32 hpd_gen11[HPD_NUM_PINS] = {
90 [HPD_PORT_TC1] = GEN11_TC_HOTPLUG(HPD_PORT_TC1) | GEN11_TBT_HOTPLUG(HPD_PORT_TC1),
91 [HPD_PORT_TC2] = GEN11_TC_HOTPLUG(HPD_PORT_TC2) | GEN11_TBT_HOTPLUG(HPD_PORT_TC2),
92 [HPD_PORT_TC3] = GEN11_TC_HOTPLUG(HPD_PORT_TC3) | GEN11_TBT_HOTPLUG(HPD_PORT_TC3),
93 [HPD_PORT_TC4] = GEN11_TC_HOTPLUG(HPD_PORT_TC4) | GEN11_TBT_HOTPLUG(HPD_PORT_TC4),
94 [HPD_PORT_TC5] = GEN11_TC_HOTPLUG(HPD_PORT_TC5) | GEN11_TBT_HOTPLUG(HPD_PORT_TC5),
95 [HPD_PORT_TC6] = GEN11_TC_HOTPLUG(HPD_PORT_TC6) | GEN11_TBT_HOTPLUG(HPD_PORT_TC6),
98 static const u32 hpd_xelpdp[HPD_NUM_PINS] = {
99 [HPD_PORT_TC1] = XELPDP_TBT_HOTPLUG(HPD_PORT_TC1) | XELPDP_DP_ALT_HOTPLUG(HPD_PORT_TC1),
100 [HPD_PORT_TC2] = XELPDP_TBT_HOTPLUG(HPD_PORT_TC2) | XELPDP_DP_ALT_HOTPLUG(HPD_PORT_TC2),
101 [HPD_PORT_TC3] = XELPDP_TBT_HOTPLUG(HPD_PORT_TC3) | XELPDP_DP_ALT_HOTPLUG(HPD_PORT_TC3),
102 [HPD_PORT_TC4] = XELPDP_TBT_HOTPLUG(HPD_PORT_TC4) | XELPDP_DP_ALT_HOTPLUG(HPD_PORT_TC4),
105 static const u32 hpd_icp[HPD_NUM_PINS] = {
106 [HPD_PORT_A] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_A),
107 [HPD_PORT_B] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_B),
108 [HPD_PORT_C] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_C),
109 [HPD_PORT_TC1] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC1),
110 [HPD_PORT_TC2] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC2),
111 [HPD_PORT_TC3] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC3),
112 [HPD_PORT_TC4] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC4),
113 [HPD_PORT_TC5] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC5),
114 [HPD_PORT_TC6] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC6),
117 static const u32 hpd_sde_dg1[HPD_NUM_PINS] = {
118 [HPD_PORT_A] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_A),
119 [HPD_PORT_B] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_B),
120 [HPD_PORT_C] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_C),
121 [HPD_PORT_D] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_D),
122 [HPD_PORT_TC1] = SDE_TC_HOTPLUG_DG2(HPD_PORT_TC1),
125 static const u32 hpd_mtp[HPD_NUM_PINS] = {
126 [HPD_PORT_A] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_A),
127 [HPD_PORT_B] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_B),
128 [HPD_PORT_TC1] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC1),
129 [HPD_PORT_TC2] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC2),
130 [HPD_PORT_TC3] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC3),
131 [HPD_PORT_TC4] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC4),
134 static void intel_hpd_init_pins(struct drm_i915_private *dev_priv)
136 struct intel_hotplug *hpd = &dev_priv->display.hotplug;
138 if (HAS_GMCH(dev_priv)) {
139 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
140 IS_CHERRYVIEW(dev_priv))
141 hpd->hpd = hpd_status_g4x;
143 hpd->hpd = hpd_status_i915;
147 if (DISPLAY_VER(dev_priv) >= 14)
148 hpd->hpd = hpd_xelpdp;
149 else if (DISPLAY_VER(dev_priv) >= 11)
150 hpd->hpd = hpd_gen11;
151 else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
153 else if (DISPLAY_VER(dev_priv) == 9)
154 hpd->hpd = NULL; /* no north HPD on SKL */
155 else if (DISPLAY_VER(dev_priv) >= 8)
157 else if (DISPLAY_VER(dev_priv) >= 7)
162 if ((INTEL_PCH_TYPE(dev_priv) < PCH_DG1) &&
163 (!HAS_PCH_SPLIT(dev_priv) || HAS_PCH_NOP(dev_priv)))
166 if (INTEL_PCH_TYPE(dev_priv) >= PCH_LNL)
167 hpd->pch_hpd = hpd_mtp;
168 else if (INTEL_PCH_TYPE(dev_priv) >= PCH_DG1)
169 hpd->pch_hpd = hpd_sde_dg1;
170 else if (INTEL_PCH_TYPE(dev_priv) >= PCH_MTP)
171 hpd->pch_hpd = hpd_mtp;
172 else if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
173 hpd->pch_hpd = hpd_icp;
174 else if (HAS_PCH_CNP(dev_priv) || HAS_PCH_SPT(dev_priv))
175 hpd->pch_hpd = hpd_spt;
176 else if (HAS_PCH_LPT(dev_priv) || HAS_PCH_CPT(dev_priv))
177 hpd->pch_hpd = hpd_cpt;
178 else if (HAS_PCH_IBX(dev_priv))
179 hpd->pch_hpd = hpd_ibx;
181 MISSING_CASE(INTEL_PCH_TYPE(dev_priv));
184 /* For display hotplug interrupt */
185 void i915_hotplug_interrupt_update_locked(struct drm_i915_private *dev_priv,
188 lockdep_assert_held(&dev_priv->irq_lock);
189 drm_WARN_ON(&dev_priv->drm, bits & ~mask);
191 intel_uncore_rmw(&dev_priv->uncore, PORT_HOTPLUG_EN, mask, bits);
195 * i915_hotplug_interrupt_update - update hotplug interrupt enable
196 * @dev_priv: driver private
197 * @mask: bits to update
198 * @bits: bits to enable
199 * NOTE: the HPD enable bits are modified both inside and outside
200 * of an interrupt context. To avoid that read-modify-write cycles
201 * interfer, these bits are protected by a spinlock. Since this
202 * function is usually not called from a context where the lock is
203 * held already, this function acquires the lock itself. A non-locking
204 * version is also available.
206 void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv,
210 spin_lock_irq(&dev_priv->irq_lock);
211 i915_hotplug_interrupt_update_locked(dev_priv, mask, bits);
212 spin_unlock_irq(&dev_priv->irq_lock);
215 static bool gen11_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
224 return val & GEN11_HOTPLUG_CTL_LONG_DETECT(pin);
230 static bool bxt_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
234 return val & PORTA_HOTPLUG_LONG_DETECT;
236 return val & PORTB_HOTPLUG_LONG_DETECT;
238 return val & PORTC_HOTPLUG_LONG_DETECT;
244 static bool icp_ddi_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
251 return val & SHOTPLUG_CTL_DDI_HPD_LONG_DETECT(pin);
257 static bool icp_tc_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
266 return val & ICP_TC_HPD_LONG_DETECT(pin);
272 static bool spt_port_hotplug2_long_detect(enum hpd_pin pin, u32 val)
276 return val & PORTE_HOTPLUG_LONG_DETECT;
282 static bool spt_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
286 return val & PORTA_HOTPLUG_LONG_DETECT;
288 return val & PORTB_HOTPLUG_LONG_DETECT;
290 return val & PORTC_HOTPLUG_LONG_DETECT;
292 return val & PORTD_HOTPLUG_LONG_DETECT;
298 static bool ilk_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
302 return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT;
308 static bool pch_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
312 return val & PORTB_HOTPLUG_LONG_DETECT;
314 return val & PORTC_HOTPLUG_LONG_DETECT;
316 return val & PORTD_HOTPLUG_LONG_DETECT;
322 static bool i9xx_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
326 return val & PORTB_HOTPLUG_INT_LONG_PULSE;
328 return val & PORTC_HOTPLUG_INT_LONG_PULSE;
330 return val & PORTD_HOTPLUG_INT_LONG_PULSE;
337 * Get a bit mask of pins that have triggered, and which ones may be long.
338 * This can be called multiple times with the same masks to accumulate
339 * hotplug detection results from several registers.
341 * Note that the caller is expected to zero out the masks initially.
343 static void intel_get_hpd_pins(struct drm_i915_private *dev_priv,
344 u32 *pin_mask, u32 *long_mask,
345 u32 hotplug_trigger, u32 dig_hotplug_reg,
346 const u32 hpd[HPD_NUM_PINS],
347 bool long_pulse_detect(enum hpd_pin pin, u32 val))
351 BUILD_BUG_ON(BITS_PER_TYPE(*pin_mask) < HPD_NUM_PINS);
353 for_each_hpd_pin(pin) {
354 if ((hpd[pin] & hotplug_trigger) == 0)
357 *pin_mask |= BIT(pin);
359 if (long_pulse_detect(pin, dig_hotplug_reg))
360 *long_mask |= BIT(pin);
363 drm_dbg(&dev_priv->drm,
364 "hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x, long 0x%08x\n",
365 hotplug_trigger, dig_hotplug_reg, *pin_mask, *long_mask);
368 static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv,
369 const u32 hpd[HPD_NUM_PINS])
371 struct intel_encoder *encoder;
372 u32 enabled_irqs = 0;
374 for_each_intel_encoder(&dev_priv->drm, encoder)
375 if (dev_priv->display.hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
376 enabled_irqs |= hpd[encoder->hpd_pin];
381 static u32 intel_hpd_hotplug_irqs(struct drm_i915_private *dev_priv,
382 const u32 hpd[HPD_NUM_PINS])
384 struct intel_encoder *encoder;
385 u32 hotplug_irqs = 0;
387 for_each_intel_encoder(&dev_priv->drm, encoder)
388 hotplug_irqs |= hpd[encoder->hpd_pin];
393 static u32 intel_hpd_hotplug_mask(struct drm_i915_private *i915,
394 hotplug_mask_func hotplug_mask)
399 for_each_hpd_pin(pin)
400 hotplug |= hotplug_mask(pin);
405 static u32 intel_hpd_hotplug_enables(struct drm_i915_private *i915,
406 hotplug_enables_func hotplug_enables)
408 struct intel_encoder *encoder;
411 for_each_intel_encoder(&i915->drm, encoder)
412 hotplug |= hotplug_enables(encoder);
417 u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv)
419 u32 hotplug_status = 0, hotplug_status_mask;
422 if (IS_G4X(dev_priv) ||
423 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
424 hotplug_status_mask = HOTPLUG_INT_STATUS_G4X |
425 DP_AUX_CHANNEL_MASK_INT_STATUS_G4X;
427 hotplug_status_mask = HOTPLUG_INT_STATUS_I915;
430 * We absolutely have to clear all the pending interrupt
431 * bits in PORT_HOTPLUG_STAT. Otherwise the ISR port
432 * interrupt bit won't have an edge, and the i965/g4x
433 * edge triggered IIR will not notice that an interrupt
434 * is still pending. We can't use PORT_HOTPLUG_EN to
435 * guarantee the edge as the act of toggling the enable
436 * bits can itself generate a new hotplug interrupt :(
438 for (i = 0; i < 10; i++) {
439 u32 tmp = intel_uncore_read(&dev_priv->uncore, PORT_HOTPLUG_STAT) & hotplug_status_mask;
442 return hotplug_status;
444 hotplug_status |= tmp;
445 intel_uncore_write(&dev_priv->uncore, PORT_HOTPLUG_STAT, hotplug_status);
448 drm_WARN_ONCE(&dev_priv->drm, 1,
449 "PORT_HOTPLUG_STAT did not clear (0x%08x)\n",
450 intel_uncore_read(&dev_priv->uncore, PORT_HOTPLUG_STAT));
452 return hotplug_status;
455 void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv, u32 hotplug_status)
457 u32 pin_mask = 0, long_mask = 0;
460 if (IS_G4X(dev_priv) ||
461 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
462 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
464 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
466 if (hotplug_trigger) {
467 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
468 hotplug_trigger, hotplug_trigger,
469 dev_priv->display.hotplug.hpd,
470 i9xx_port_hotplug_long_detect);
472 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
475 if ((IS_G4X(dev_priv) ||
476 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
477 hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
478 intel_dp_aux_irq_handler(dev_priv);
481 void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv, u32 hotplug_trigger)
483 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
486 * Somehow the PCH doesn't seem to really ack the interrupt to the CPU
487 * unless we touch the hotplug register, even if hotplug_trigger is
488 * zero. Not acking leads to "The master control interrupt lied (SDE)!"
491 dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG);
492 if (!hotplug_trigger) {
493 u32 mask = PORTA_HOTPLUG_STATUS_MASK |
494 PORTD_HOTPLUG_STATUS_MASK |
495 PORTC_HOTPLUG_STATUS_MASK |
496 PORTB_HOTPLUG_STATUS_MASK;
497 dig_hotplug_reg &= ~mask;
500 intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG, dig_hotplug_reg);
501 if (!hotplug_trigger)
504 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
505 hotplug_trigger, dig_hotplug_reg,
506 dev_priv->display.hotplug.pch_hpd,
507 pch_port_hotplug_long_detect);
509 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
512 void xelpdp_pica_irq_handler(struct drm_i915_private *i915, u32 iir)
515 u32 hotplug_trigger = iir & (XELPDP_DP_ALT_HOTPLUG_MASK | XELPDP_TBT_HOTPLUG_MASK);
516 u32 trigger_aux = iir & XELPDP_AUX_TC_MASK;
517 u32 pin_mask = 0, long_mask = 0;
519 if (DISPLAY_VER(i915) >= 20)
520 trigger_aux |= iir & XE2LPD_AUX_DDI_MASK;
522 for (pin = HPD_PORT_TC1; pin <= HPD_PORT_TC4; pin++) {
525 if (!(i915->display.hotplug.hpd[pin] & hotplug_trigger))
528 pin_mask |= BIT(pin);
530 val = intel_de_read(i915, XELPDP_PORT_HOTPLUG_CTL(pin));
531 intel_de_write(i915, XELPDP_PORT_HOTPLUG_CTL(pin), val);
533 if (val & (XELPDP_DP_ALT_HPD_LONG_DETECT | XELPDP_TBT_HPD_LONG_DETECT))
534 long_mask |= BIT(pin);
539 "pica hotplug event received, stat 0x%08x, pins 0x%08x, long 0x%08x\n",
540 hotplug_trigger, pin_mask, long_mask);
542 intel_hpd_irq_handler(i915, pin_mask, long_mask);
546 intel_dp_aux_irq_handler(i915);
548 if (!pin_mask && !trigger_aux)
550 "Unexpected DE HPD/AUX interrupt 0x%08x\n", iir);
553 void icp_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
555 u32 ddi_hotplug_trigger = pch_iir & SDE_DDI_HOTPLUG_MASK_ICP;
556 u32 tc_hotplug_trigger = pch_iir & SDE_TC_HOTPLUG_MASK_ICP;
557 u32 pin_mask = 0, long_mask = 0;
559 if (ddi_hotplug_trigger) {
562 /* Locking due to DSI native GPIO sequences */
563 spin_lock(&dev_priv->irq_lock);
564 dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, SHOTPLUG_CTL_DDI, 0, 0);
565 spin_unlock(&dev_priv->irq_lock);
567 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
568 ddi_hotplug_trigger, dig_hotplug_reg,
569 dev_priv->display.hotplug.pch_hpd,
570 icp_ddi_port_hotplug_long_detect);
573 if (tc_hotplug_trigger) {
576 dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, SHOTPLUG_CTL_TC, 0, 0);
578 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
579 tc_hotplug_trigger, dig_hotplug_reg,
580 dev_priv->display.hotplug.pch_hpd,
581 icp_tc_port_hotplug_long_detect);
585 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
587 if (pch_iir & SDE_GMBUS_ICP)
588 intel_gmbus_irq_handler(dev_priv);
591 void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
593 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
594 ~SDE_PORTE_HOTPLUG_SPT;
595 u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
596 u32 pin_mask = 0, long_mask = 0;
598 if (hotplug_trigger) {
601 dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG, 0, 0);
603 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
604 hotplug_trigger, dig_hotplug_reg,
605 dev_priv->display.hotplug.pch_hpd,
606 spt_port_hotplug_long_detect);
609 if (hotplug2_trigger) {
612 dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG2, 0, 0);
614 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
615 hotplug2_trigger, dig_hotplug_reg,
616 dev_priv->display.hotplug.pch_hpd,
617 spt_port_hotplug2_long_detect);
621 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
623 if (pch_iir & SDE_GMBUS_CPT)
624 intel_gmbus_irq_handler(dev_priv);
627 void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv, u32 hotplug_trigger)
629 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
631 dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, DIGITAL_PORT_HOTPLUG_CNTRL, 0, 0);
633 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
634 hotplug_trigger, dig_hotplug_reg,
635 dev_priv->display.hotplug.hpd,
636 ilk_port_hotplug_long_detect);
638 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
641 void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv, u32 hotplug_trigger)
643 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
645 dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG, 0, 0);
647 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
648 hotplug_trigger, dig_hotplug_reg,
649 dev_priv->display.hotplug.hpd,
650 bxt_port_hotplug_long_detect);
652 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
655 void gen11_hpd_irq_handler(struct drm_i915_private *dev_priv, u32 iir)
657 u32 pin_mask = 0, long_mask = 0;
658 u32 trigger_tc = iir & GEN11_DE_TC_HOTPLUG_MASK;
659 u32 trigger_tbt = iir & GEN11_DE_TBT_HOTPLUG_MASK;
664 dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, GEN11_TC_HOTPLUG_CTL, 0, 0);
666 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
667 trigger_tc, dig_hotplug_reg,
668 dev_priv->display.hotplug.hpd,
669 gen11_port_hotplug_long_detect);
675 dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, GEN11_TBT_HOTPLUG_CTL, 0, 0);
677 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
678 trigger_tbt, dig_hotplug_reg,
679 dev_priv->display.hotplug.hpd,
680 gen11_port_hotplug_long_detect);
684 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
686 drm_err(&dev_priv->drm,
687 "Unexpected DE HPD interrupt 0x%08x\n", iir);
690 static u32 ibx_hotplug_mask(enum hpd_pin hpd_pin)
694 return PORTA_HOTPLUG_ENABLE;
696 return PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_MASK;
698 return PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_MASK;
700 return PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_MASK;
706 static u32 ibx_hotplug_enables(struct intel_encoder *encoder)
708 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
710 switch (encoder->hpd_pin) {
713 * When CPU and PCH are on the same package, port A
714 * HPD must be enabled in both north and south.
716 return HAS_PCH_LPT_LP(i915) ?
717 PORTA_HOTPLUG_ENABLE : 0;
719 return PORTB_HOTPLUG_ENABLE |
720 PORTB_PULSE_DURATION_2ms;
722 return PORTC_HOTPLUG_ENABLE |
723 PORTC_PULSE_DURATION_2ms;
725 return PORTD_HOTPLUG_ENABLE |
726 PORTD_PULSE_DURATION_2ms;
732 static void ibx_hpd_detection_setup(struct drm_i915_private *dev_priv)
735 * Enable digital hotplug on the PCH, and configure the DP short pulse
736 * duration to 2ms (which is the minimum in the Display Port spec).
737 * The pulse duration bits are reserved on LPT+.
739 intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG,
740 intel_hpd_hotplug_mask(dev_priv, ibx_hotplug_mask),
741 intel_hpd_hotplug_enables(dev_priv, ibx_hotplug_enables));
744 static void ibx_hpd_enable_detection(struct intel_encoder *encoder)
746 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
748 intel_uncore_rmw(&i915->uncore, PCH_PORT_HOTPLUG,
749 ibx_hotplug_mask(encoder->hpd_pin),
750 ibx_hotplug_enables(encoder));
753 static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv)
755 u32 hotplug_irqs, enabled_irqs;
757 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
758 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
760 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
762 ibx_hpd_detection_setup(dev_priv);
765 static u32 icp_ddi_hotplug_mask(enum hpd_pin hpd_pin)
772 return SHOTPLUG_CTL_DDI_HPD_ENABLE(hpd_pin);
778 static u32 icp_ddi_hotplug_enables(struct intel_encoder *encoder)
780 return icp_ddi_hotplug_mask(encoder->hpd_pin);
783 static u32 icp_tc_hotplug_mask(enum hpd_pin hpd_pin)
792 return ICP_TC_HPD_ENABLE(hpd_pin);
798 static u32 icp_tc_hotplug_enables(struct intel_encoder *encoder)
800 return icp_tc_hotplug_mask(encoder->hpd_pin);
803 static void icp_ddi_hpd_detection_setup(struct drm_i915_private *dev_priv)
805 intel_uncore_rmw(&dev_priv->uncore, SHOTPLUG_CTL_DDI,
806 intel_hpd_hotplug_mask(dev_priv, icp_ddi_hotplug_mask),
807 intel_hpd_hotplug_enables(dev_priv, icp_ddi_hotplug_enables));
810 static void icp_ddi_hpd_enable_detection(struct intel_encoder *encoder)
812 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
814 intel_uncore_rmw(&i915->uncore, SHOTPLUG_CTL_DDI,
815 icp_ddi_hotplug_mask(encoder->hpd_pin),
816 icp_ddi_hotplug_enables(encoder));
819 static void icp_tc_hpd_detection_setup(struct drm_i915_private *dev_priv)
821 intel_uncore_rmw(&dev_priv->uncore, SHOTPLUG_CTL_TC,
822 intel_hpd_hotplug_mask(dev_priv, icp_tc_hotplug_mask),
823 intel_hpd_hotplug_enables(dev_priv, icp_tc_hotplug_enables));
826 static void icp_tc_hpd_enable_detection(struct intel_encoder *encoder)
828 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
830 intel_uncore_rmw(&i915->uncore, SHOTPLUG_CTL_TC,
831 icp_tc_hotplug_mask(encoder->hpd_pin),
832 icp_tc_hotplug_enables(encoder));
835 static void icp_hpd_enable_detection(struct intel_encoder *encoder)
837 icp_ddi_hpd_enable_detection(encoder);
838 icp_tc_hpd_enable_detection(encoder);
841 static void icp_hpd_irq_setup(struct drm_i915_private *dev_priv)
843 u32 hotplug_irqs, enabled_irqs;
845 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
846 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
848 if (INTEL_PCH_TYPE(dev_priv) <= PCH_TGP)
849 intel_uncore_write(&dev_priv->uncore, SHPD_FILTER_CNT, SHPD_FILTER_CNT_500_ADJ);
851 intel_uncore_write(&dev_priv->uncore, SHPD_FILTER_CNT, SHPD_FILTER_CNT_250);
853 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
855 icp_ddi_hpd_detection_setup(dev_priv);
856 icp_tc_hpd_detection_setup(dev_priv);
859 static u32 gen11_hotplug_mask(enum hpd_pin hpd_pin)
868 return GEN11_HOTPLUG_CTL_ENABLE(hpd_pin);
874 static u32 gen11_hotplug_enables(struct intel_encoder *encoder)
876 return gen11_hotplug_mask(encoder->hpd_pin);
879 static void dg1_hpd_invert(struct drm_i915_private *i915)
881 u32 val = (INVERT_DDIA_HPD |
885 intel_uncore_rmw(&i915->uncore, SOUTH_CHICKEN1, 0, val);
888 static void dg1_hpd_enable_detection(struct intel_encoder *encoder)
890 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
892 dg1_hpd_invert(i915);
893 icp_hpd_enable_detection(encoder);
896 static void dg1_hpd_irq_setup(struct drm_i915_private *dev_priv)
898 dg1_hpd_invert(dev_priv);
899 icp_hpd_irq_setup(dev_priv);
902 static void gen11_tc_hpd_detection_setup(struct drm_i915_private *dev_priv)
904 intel_uncore_rmw(&dev_priv->uncore, GEN11_TC_HOTPLUG_CTL,
905 intel_hpd_hotplug_mask(dev_priv, gen11_hotplug_mask),
906 intel_hpd_hotplug_enables(dev_priv, gen11_hotplug_enables));
909 static void gen11_tc_hpd_enable_detection(struct intel_encoder *encoder)
911 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
913 intel_uncore_rmw(&i915->uncore, GEN11_TC_HOTPLUG_CTL,
914 gen11_hotplug_mask(encoder->hpd_pin),
915 gen11_hotplug_enables(encoder));
918 static void gen11_tbt_hpd_detection_setup(struct drm_i915_private *dev_priv)
920 intel_uncore_rmw(&dev_priv->uncore, GEN11_TBT_HOTPLUG_CTL,
921 intel_hpd_hotplug_mask(dev_priv, gen11_hotplug_mask),
922 intel_hpd_hotplug_enables(dev_priv, gen11_hotplug_enables));
925 static void gen11_tbt_hpd_enable_detection(struct intel_encoder *encoder)
927 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
929 intel_uncore_rmw(&i915->uncore, GEN11_TBT_HOTPLUG_CTL,
930 gen11_hotplug_mask(encoder->hpd_pin),
931 gen11_hotplug_enables(encoder));
934 static void gen11_hpd_enable_detection(struct intel_encoder *encoder)
936 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
938 gen11_tc_hpd_enable_detection(encoder);
939 gen11_tbt_hpd_enable_detection(encoder);
941 if (INTEL_PCH_TYPE(i915) >= PCH_ICP)
942 icp_hpd_enable_detection(encoder);
945 static void gen11_hpd_irq_setup(struct drm_i915_private *dev_priv)
947 u32 hotplug_irqs, enabled_irqs;
949 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.hpd);
950 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.hpd);
952 intel_uncore_rmw(&dev_priv->uncore, GEN11_DE_HPD_IMR, hotplug_irqs,
953 ~enabled_irqs & hotplug_irqs);
954 intel_uncore_posting_read(&dev_priv->uncore, GEN11_DE_HPD_IMR);
956 gen11_tc_hpd_detection_setup(dev_priv);
957 gen11_tbt_hpd_detection_setup(dev_priv);
959 if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
960 icp_hpd_irq_setup(dev_priv);
963 static u32 mtp_ddi_hotplug_mask(enum hpd_pin hpd_pin)
968 return SHOTPLUG_CTL_DDI_HPD_ENABLE(hpd_pin);
974 static u32 mtp_ddi_hotplug_enables(struct intel_encoder *encoder)
976 return mtp_ddi_hotplug_mask(encoder->hpd_pin);
979 static u32 mtp_tc_hotplug_mask(enum hpd_pin hpd_pin)
986 return ICP_TC_HPD_ENABLE(hpd_pin);
992 static u32 mtp_tc_hotplug_enables(struct intel_encoder *encoder)
994 return mtp_tc_hotplug_mask(encoder->hpd_pin);
997 static void mtp_ddi_hpd_detection_setup(struct drm_i915_private *i915)
999 intel_de_rmw(i915, SHOTPLUG_CTL_DDI,
1000 intel_hpd_hotplug_mask(i915, mtp_ddi_hotplug_mask),
1001 intel_hpd_hotplug_enables(i915, mtp_ddi_hotplug_enables));
1004 static void mtp_ddi_hpd_enable_detection(struct intel_encoder *encoder)
1006 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1008 intel_de_rmw(i915, SHOTPLUG_CTL_DDI,
1009 mtp_ddi_hotplug_mask(encoder->hpd_pin),
1010 mtp_ddi_hotplug_enables(encoder));
1013 static void mtp_tc_hpd_detection_setup(struct drm_i915_private *i915)
1015 intel_de_rmw(i915, SHOTPLUG_CTL_TC,
1016 intel_hpd_hotplug_mask(i915, mtp_tc_hotplug_mask),
1017 intel_hpd_hotplug_enables(i915, mtp_tc_hotplug_enables));
1020 static void mtp_tc_hpd_enable_detection(struct intel_encoder *encoder)
1022 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1024 intel_de_rmw(i915, SHOTPLUG_CTL_DDI,
1025 mtp_tc_hotplug_mask(encoder->hpd_pin),
1026 mtp_tc_hotplug_enables(encoder));
1029 static void mtp_hpd_invert(struct drm_i915_private *i915)
1031 u32 val = (INVERT_DDIA_HPD |
1038 INVERT_DDID_HPD_MTP |
1040 intel_de_rmw(i915, SOUTH_CHICKEN1, 0, val);
1043 static void mtp_hpd_enable_detection(struct intel_encoder *encoder)
1045 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1047 mtp_hpd_invert(i915);
1048 mtp_ddi_hpd_enable_detection(encoder);
1049 mtp_tc_hpd_enable_detection(encoder);
1052 static void mtp_hpd_irq_setup(struct drm_i915_private *i915)
1054 u32 hotplug_irqs, enabled_irqs;
1056 enabled_irqs = intel_hpd_enabled_irqs(i915, i915->display.hotplug.pch_hpd);
1057 hotplug_irqs = intel_hpd_hotplug_irqs(i915, i915->display.hotplug.pch_hpd);
1059 intel_de_write(i915, SHPD_FILTER_CNT, SHPD_FILTER_CNT_250);
1061 mtp_hpd_invert(i915);
1062 ibx_display_interrupt_update(i915, hotplug_irqs, enabled_irqs);
1064 mtp_ddi_hpd_detection_setup(i915);
1065 mtp_tc_hpd_detection_setup(i915);
1068 static void xe2lpd_sde_hpd_irq_setup(struct drm_i915_private *i915)
1070 u32 hotplug_irqs, enabled_irqs;
1072 enabled_irqs = intel_hpd_enabled_irqs(i915, i915->display.hotplug.pch_hpd);
1073 hotplug_irqs = intel_hpd_hotplug_irqs(i915, i915->display.hotplug.pch_hpd);
1075 ibx_display_interrupt_update(i915, hotplug_irqs, enabled_irqs);
1077 mtp_ddi_hpd_detection_setup(i915);
1078 mtp_tc_hpd_detection_setup(i915);
1081 static bool is_xelpdp_pica_hpd_pin(enum hpd_pin hpd_pin)
1083 return hpd_pin >= HPD_PORT_TC1 && hpd_pin <= HPD_PORT_TC4;
1086 static void _xelpdp_pica_hpd_detection_setup(struct drm_i915_private *i915,
1087 enum hpd_pin hpd_pin, bool enable)
1089 u32 mask = XELPDP_TBT_HOTPLUG_ENABLE |
1090 XELPDP_DP_ALT_HOTPLUG_ENABLE;
1092 if (!is_xelpdp_pica_hpd_pin(hpd_pin))
1095 intel_de_rmw(i915, XELPDP_PORT_HOTPLUG_CTL(hpd_pin),
1096 mask, enable ? mask : 0);
1099 static void xelpdp_pica_hpd_enable_detection(struct intel_encoder *encoder)
1101 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1103 _xelpdp_pica_hpd_detection_setup(i915, encoder->hpd_pin, true);
1106 static void xelpdp_pica_hpd_detection_setup(struct drm_i915_private *i915)
1108 struct intel_encoder *encoder;
1109 u32 available_pins = 0;
1112 BUILD_BUG_ON(BITS_PER_TYPE(available_pins) < HPD_NUM_PINS);
1114 for_each_intel_encoder(&i915->drm, encoder)
1115 available_pins |= BIT(encoder->hpd_pin);
1117 for_each_hpd_pin(pin)
1118 _xelpdp_pica_hpd_detection_setup(i915, pin, available_pins & BIT(pin));
1121 static void xelpdp_hpd_enable_detection(struct intel_encoder *encoder)
1123 xelpdp_pica_hpd_enable_detection(encoder);
1124 mtp_hpd_enable_detection(encoder);
1127 static void xelpdp_hpd_irq_setup(struct drm_i915_private *i915)
1129 u32 hotplug_irqs, enabled_irqs;
1131 enabled_irqs = intel_hpd_enabled_irqs(i915, i915->display.hotplug.hpd);
1132 hotplug_irqs = intel_hpd_hotplug_irqs(i915, i915->display.hotplug.hpd);
1134 intel_de_rmw(i915, PICAINTERRUPT_IMR, hotplug_irqs,
1135 ~enabled_irqs & hotplug_irqs);
1136 intel_uncore_posting_read(&i915->uncore, PICAINTERRUPT_IMR);
1138 xelpdp_pica_hpd_detection_setup(i915);
1140 if (INTEL_PCH_TYPE(i915) >= PCH_LNL)
1141 xe2lpd_sde_hpd_irq_setup(i915);
1142 else if (INTEL_PCH_TYPE(i915) >= PCH_MTP)
1143 mtp_hpd_irq_setup(i915);
1146 static u32 spt_hotplug_mask(enum hpd_pin hpd_pin)
1150 return PORTA_HOTPLUG_ENABLE;
1152 return PORTB_HOTPLUG_ENABLE;
1154 return PORTC_HOTPLUG_ENABLE;
1156 return PORTD_HOTPLUG_ENABLE;
1162 static u32 spt_hotplug_enables(struct intel_encoder *encoder)
1164 return spt_hotplug_mask(encoder->hpd_pin);
1167 static u32 spt_hotplug2_mask(enum hpd_pin hpd_pin)
1171 return PORTE_HOTPLUG_ENABLE;
1177 static u32 spt_hotplug2_enables(struct intel_encoder *encoder)
1179 return spt_hotplug2_mask(encoder->hpd_pin);
1182 static void spt_hpd_detection_setup(struct drm_i915_private *dev_priv)
1184 /* Display WA #1179 WaHardHangonHotPlug: cnp */
1185 if (HAS_PCH_CNP(dev_priv)) {
1186 intel_uncore_rmw(&dev_priv->uncore, SOUTH_CHICKEN1, CHASSIS_CLK_REQ_DURATION_MASK,
1187 CHASSIS_CLK_REQ_DURATION(0xf));
1190 /* Enable digital hotplug on the PCH */
1191 intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG,
1192 intel_hpd_hotplug_mask(dev_priv, spt_hotplug_mask),
1193 intel_hpd_hotplug_enables(dev_priv, spt_hotplug_enables));
1195 intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG2,
1196 intel_hpd_hotplug_mask(dev_priv, spt_hotplug2_mask),
1197 intel_hpd_hotplug_enables(dev_priv, spt_hotplug2_enables));
1200 static void spt_hpd_enable_detection(struct intel_encoder *encoder)
1202 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1204 /* Display WA #1179 WaHardHangonHotPlug: cnp */
1205 if (HAS_PCH_CNP(i915)) {
1206 intel_uncore_rmw(&i915->uncore, SOUTH_CHICKEN1,
1207 CHASSIS_CLK_REQ_DURATION_MASK,
1208 CHASSIS_CLK_REQ_DURATION(0xf));
1211 intel_uncore_rmw(&i915->uncore, PCH_PORT_HOTPLUG,
1212 spt_hotplug_mask(encoder->hpd_pin),
1213 spt_hotplug_enables(encoder));
1215 intel_uncore_rmw(&i915->uncore, PCH_PORT_HOTPLUG2,
1216 spt_hotplug2_mask(encoder->hpd_pin),
1217 spt_hotplug2_enables(encoder));
1220 static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv)
1222 u32 hotplug_irqs, enabled_irqs;
1224 if (INTEL_PCH_TYPE(dev_priv) >= PCH_CNP)
1225 intel_uncore_write(&dev_priv->uncore, SHPD_FILTER_CNT, SHPD_FILTER_CNT_500_ADJ);
1227 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
1228 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
1230 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
1232 spt_hpd_detection_setup(dev_priv);
1235 static u32 ilk_hotplug_mask(enum hpd_pin hpd_pin)
1239 return DIGITAL_PORTA_HOTPLUG_ENABLE |
1240 DIGITAL_PORTA_PULSE_DURATION_MASK;
1246 static u32 ilk_hotplug_enables(struct intel_encoder *encoder)
1248 switch (encoder->hpd_pin) {
1250 return DIGITAL_PORTA_HOTPLUG_ENABLE |
1251 DIGITAL_PORTA_PULSE_DURATION_2ms;
1257 static void ilk_hpd_detection_setup(struct drm_i915_private *dev_priv)
1260 * Enable digital hotplug on the CPU, and configure the DP short pulse
1261 * duration to 2ms (which is the minimum in the Display Port spec)
1262 * The pulse duration bits are reserved on HSW+.
1264 intel_uncore_rmw(&dev_priv->uncore, DIGITAL_PORT_HOTPLUG_CNTRL,
1265 intel_hpd_hotplug_mask(dev_priv, ilk_hotplug_mask),
1266 intel_hpd_hotplug_enables(dev_priv, ilk_hotplug_enables));
1269 static void ilk_hpd_enable_detection(struct intel_encoder *encoder)
1271 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1273 intel_uncore_rmw(&i915->uncore, DIGITAL_PORT_HOTPLUG_CNTRL,
1274 ilk_hotplug_mask(encoder->hpd_pin),
1275 ilk_hotplug_enables(encoder));
1277 ibx_hpd_enable_detection(encoder);
1280 static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv)
1282 u32 hotplug_irqs, enabled_irqs;
1284 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.hpd);
1285 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.hpd);
1287 if (DISPLAY_VER(dev_priv) >= 8)
1288 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
1290 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
1292 ilk_hpd_detection_setup(dev_priv);
1294 ibx_hpd_irq_setup(dev_priv);
1297 static u32 bxt_hotplug_mask(enum hpd_pin hpd_pin)
1301 return PORTA_HOTPLUG_ENABLE | BXT_DDIA_HPD_INVERT;
1303 return PORTB_HOTPLUG_ENABLE | BXT_DDIB_HPD_INVERT;
1305 return PORTC_HOTPLUG_ENABLE | BXT_DDIC_HPD_INVERT;
1311 static u32 bxt_hotplug_enables(struct intel_encoder *encoder)
1315 switch (encoder->hpd_pin) {
1317 hotplug = PORTA_HOTPLUG_ENABLE;
1318 if (intel_bios_encoder_hpd_invert(encoder->devdata))
1319 hotplug |= BXT_DDIA_HPD_INVERT;
1322 hotplug = PORTB_HOTPLUG_ENABLE;
1323 if (intel_bios_encoder_hpd_invert(encoder->devdata))
1324 hotplug |= BXT_DDIB_HPD_INVERT;
1327 hotplug = PORTC_HOTPLUG_ENABLE;
1328 if (intel_bios_encoder_hpd_invert(encoder->devdata))
1329 hotplug |= BXT_DDIC_HPD_INVERT;
1336 static void bxt_hpd_detection_setup(struct drm_i915_private *dev_priv)
1338 intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG,
1339 intel_hpd_hotplug_mask(dev_priv, bxt_hotplug_mask),
1340 intel_hpd_hotplug_enables(dev_priv, bxt_hotplug_enables));
1343 static void bxt_hpd_enable_detection(struct intel_encoder *encoder)
1345 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1347 intel_uncore_rmw(&i915->uncore, PCH_PORT_HOTPLUG,
1348 bxt_hotplug_mask(encoder->hpd_pin),
1349 bxt_hotplug_enables(encoder));
1352 static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv)
1354 u32 hotplug_irqs, enabled_irqs;
1356 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.hpd);
1357 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.hpd);
1359 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
1361 bxt_hpd_detection_setup(dev_priv);
1364 static void i915_hpd_enable_detection(struct intel_encoder *encoder)
1366 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1367 u32 hotplug_en = hpd_mask_i915[encoder->hpd_pin];
1369 /* HPD sense and interrupt enable are one and the same */
1370 i915_hotplug_interrupt_update(i915, hotplug_en, hotplug_en);
1373 static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv)
1377 lockdep_assert_held(&dev_priv->irq_lock);
1380 * Note HDMI and DP share hotplug bits. Enable bits are the same for all
1383 hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915);
1385 * Programming the CRT detection parameters tends to generate a spurious
1386 * hotplug event about three seconds later. So just do it once.
1388 if (IS_G4X(dev_priv))
1389 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
1390 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
1392 /* Ignore TV since it's buggy */
1393 i915_hotplug_interrupt_update_locked(dev_priv,
1394 HOTPLUG_INT_EN_MASK |
1395 CRT_HOTPLUG_VOLTAGE_COMPARE_MASK |
1396 CRT_HOTPLUG_ACTIVATION_PERIOD_64,
1400 struct intel_hotplug_funcs {
1401 /* Enable HPD sense and interrupts for all present encoders */
1402 void (*hpd_irq_setup)(struct drm_i915_private *i915);
1403 /* Enable HPD sense for a single encoder */
1404 void (*hpd_enable_detection)(struct intel_encoder *encoder);
1407 #define HPD_FUNCS(platform) \
1408 static const struct intel_hotplug_funcs platform##_hpd_funcs = { \
1409 .hpd_irq_setup = platform##_hpd_irq_setup, \
1410 .hpd_enable_detection = platform##_hpd_enable_detection, \
1423 void intel_hpd_enable_detection(struct intel_encoder *encoder)
1425 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1427 if (i915->display.funcs.hotplug)
1428 i915->display.funcs.hotplug->hpd_enable_detection(encoder);
1431 void intel_hpd_irq_setup(struct drm_i915_private *i915)
1433 if (i915->display_irqs_enabled && i915->display.funcs.hotplug)
1434 i915->display.funcs.hotplug->hpd_irq_setup(i915);
1437 void intel_hotplug_irq_init(struct drm_i915_private *i915)
1439 intel_hpd_init_pins(i915);
1441 intel_hpd_init_early(i915);
1443 if (HAS_GMCH(i915)) {
1444 if (I915_HAS_HOTPLUG(i915))
1445 i915->display.funcs.hotplug = &i915_hpd_funcs;
1447 if (HAS_PCH_DG2(i915))
1448 i915->display.funcs.hotplug = &icp_hpd_funcs;
1449 else if (HAS_PCH_DG1(i915))
1450 i915->display.funcs.hotplug = &dg1_hpd_funcs;
1451 else if (DISPLAY_VER(i915) >= 14)
1452 i915->display.funcs.hotplug = &xelpdp_hpd_funcs;
1453 else if (DISPLAY_VER(i915) >= 11)
1454 i915->display.funcs.hotplug = &gen11_hpd_funcs;
1455 else if (IS_GEMINILAKE(i915) || IS_BROXTON(i915))
1456 i915->display.funcs.hotplug = &bxt_hpd_funcs;
1457 else if (INTEL_PCH_TYPE(i915) >= PCH_ICP)
1458 i915->display.funcs.hotplug = &icp_hpd_funcs;
1459 else if (INTEL_PCH_TYPE(i915) >= PCH_SPT)
1460 i915->display.funcs.hotplug = &spt_hpd_funcs;
1462 i915->display.funcs.hotplug = &ilk_hpd_funcs;