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_MTL)
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_ICP)
171 hpd->pch_hpd = hpd_icp;
172 else if (HAS_PCH_CNP(dev_priv) || HAS_PCH_SPT(dev_priv))
173 hpd->pch_hpd = hpd_spt;
174 else if (HAS_PCH_LPT(dev_priv) || HAS_PCH_CPT(dev_priv))
175 hpd->pch_hpd = hpd_cpt;
176 else if (HAS_PCH_IBX(dev_priv))
177 hpd->pch_hpd = hpd_ibx;
179 MISSING_CASE(INTEL_PCH_TYPE(dev_priv));
182 /* For display hotplug interrupt */
183 void i915_hotplug_interrupt_update_locked(struct drm_i915_private *dev_priv,
186 lockdep_assert_held(&dev_priv->irq_lock);
187 drm_WARN_ON(&dev_priv->drm, bits & ~mask);
189 intel_uncore_rmw(&dev_priv->uncore, PORT_HOTPLUG_EN, mask, bits);
193 * i915_hotplug_interrupt_update - update hotplug interrupt enable
194 * @dev_priv: driver private
195 * @mask: bits to update
196 * @bits: bits to enable
197 * NOTE: the HPD enable bits are modified both inside and outside
198 * of an interrupt context. To avoid that read-modify-write cycles
199 * interfer, these bits are protected by a spinlock. Since this
200 * function is usually not called from a context where the lock is
201 * held already, this function acquires the lock itself. A non-locking
202 * version is also available.
204 void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv,
208 spin_lock_irq(&dev_priv->irq_lock);
209 i915_hotplug_interrupt_update_locked(dev_priv, mask, bits);
210 spin_unlock_irq(&dev_priv->irq_lock);
213 static bool gen11_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
222 return val & GEN11_HOTPLUG_CTL_LONG_DETECT(pin);
228 static bool bxt_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
232 return val & PORTA_HOTPLUG_LONG_DETECT;
234 return val & PORTB_HOTPLUG_LONG_DETECT;
236 return val & PORTC_HOTPLUG_LONG_DETECT;
242 static bool icp_ddi_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
249 return val & SHOTPLUG_CTL_DDI_HPD_LONG_DETECT(pin);
255 static bool icp_tc_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
264 return val & ICP_TC_HPD_LONG_DETECT(pin);
270 static bool spt_port_hotplug2_long_detect(enum hpd_pin pin, u32 val)
274 return val & PORTE_HOTPLUG_LONG_DETECT;
280 static bool spt_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
284 return val & PORTA_HOTPLUG_LONG_DETECT;
286 return val & PORTB_HOTPLUG_LONG_DETECT;
288 return val & PORTC_HOTPLUG_LONG_DETECT;
290 return val & PORTD_HOTPLUG_LONG_DETECT;
296 static bool ilk_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
300 return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT;
306 static bool pch_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
310 return val & PORTB_HOTPLUG_LONG_DETECT;
312 return val & PORTC_HOTPLUG_LONG_DETECT;
314 return val & PORTD_HOTPLUG_LONG_DETECT;
320 static bool i9xx_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
324 return val & PORTB_HOTPLUG_INT_LONG_PULSE;
326 return val & PORTC_HOTPLUG_INT_LONG_PULSE;
328 return val & PORTD_HOTPLUG_INT_LONG_PULSE;
335 * Get a bit mask of pins that have triggered, and which ones may be long.
336 * This can be called multiple times with the same masks to accumulate
337 * hotplug detection results from several registers.
339 * Note that the caller is expected to zero out the masks initially.
341 static void intel_get_hpd_pins(struct drm_i915_private *dev_priv,
342 u32 *pin_mask, u32 *long_mask,
343 u32 hotplug_trigger, u32 dig_hotplug_reg,
344 const u32 hpd[HPD_NUM_PINS],
345 bool long_pulse_detect(enum hpd_pin pin, u32 val))
349 BUILD_BUG_ON(BITS_PER_TYPE(*pin_mask) < HPD_NUM_PINS);
351 for_each_hpd_pin(pin) {
352 if ((hpd[pin] & hotplug_trigger) == 0)
355 *pin_mask |= BIT(pin);
357 if (long_pulse_detect(pin, dig_hotplug_reg))
358 *long_mask |= BIT(pin);
361 drm_dbg(&dev_priv->drm,
362 "hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x, long 0x%08x\n",
363 hotplug_trigger, dig_hotplug_reg, *pin_mask, *long_mask);
366 static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv,
367 const u32 hpd[HPD_NUM_PINS])
369 struct intel_encoder *encoder;
370 u32 enabled_irqs = 0;
372 for_each_intel_encoder(&dev_priv->drm, encoder)
373 if (dev_priv->display.hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
374 enabled_irqs |= hpd[encoder->hpd_pin];
379 static u32 intel_hpd_hotplug_irqs(struct drm_i915_private *dev_priv,
380 const u32 hpd[HPD_NUM_PINS])
382 struct intel_encoder *encoder;
383 u32 hotplug_irqs = 0;
385 for_each_intel_encoder(&dev_priv->drm, encoder)
386 hotplug_irqs |= hpd[encoder->hpd_pin];
391 static u32 intel_hpd_hotplug_mask(struct drm_i915_private *i915,
392 hotplug_mask_func hotplug_mask)
397 for_each_hpd_pin(pin)
398 hotplug |= hotplug_mask(pin);
403 static u32 intel_hpd_hotplug_enables(struct drm_i915_private *i915,
404 hotplug_enables_func hotplug_enables)
406 struct intel_encoder *encoder;
409 for_each_intel_encoder(&i915->drm, encoder)
410 hotplug |= hotplug_enables(encoder);
415 u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv)
417 u32 hotplug_status = 0, hotplug_status_mask;
420 if (IS_G4X(dev_priv) ||
421 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
422 hotplug_status_mask = HOTPLUG_INT_STATUS_G4X |
423 DP_AUX_CHANNEL_MASK_INT_STATUS_G4X;
425 hotplug_status_mask = HOTPLUG_INT_STATUS_I915;
428 * We absolutely have to clear all the pending interrupt
429 * bits in PORT_HOTPLUG_STAT. Otherwise the ISR port
430 * interrupt bit won't have an edge, and the i965/g4x
431 * edge triggered IIR will not notice that an interrupt
432 * is still pending. We can't use PORT_HOTPLUG_EN to
433 * guarantee the edge as the act of toggling the enable
434 * bits can itself generate a new hotplug interrupt :(
436 for (i = 0; i < 10; i++) {
437 u32 tmp = intel_uncore_read(&dev_priv->uncore, PORT_HOTPLUG_STAT) & hotplug_status_mask;
440 return hotplug_status;
442 hotplug_status |= tmp;
443 intel_uncore_write(&dev_priv->uncore, PORT_HOTPLUG_STAT, hotplug_status);
446 drm_WARN_ONCE(&dev_priv->drm, 1,
447 "PORT_HOTPLUG_STAT did not clear (0x%08x)\n",
448 intel_uncore_read(&dev_priv->uncore, PORT_HOTPLUG_STAT));
450 return hotplug_status;
453 void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv, u32 hotplug_status)
455 u32 pin_mask = 0, long_mask = 0;
458 if (IS_G4X(dev_priv) ||
459 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
460 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
462 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
464 if (hotplug_trigger) {
465 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
466 hotplug_trigger, hotplug_trigger,
467 dev_priv->display.hotplug.hpd,
468 i9xx_port_hotplug_long_detect);
470 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
473 if ((IS_G4X(dev_priv) ||
474 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
475 hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
476 intel_dp_aux_irq_handler(dev_priv);
479 void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv, u32 hotplug_trigger)
481 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
484 * Somehow the PCH doesn't seem to really ack the interrupt to the CPU
485 * unless we touch the hotplug register, even if hotplug_trigger is
486 * zero. Not acking leads to "The master control interrupt lied (SDE)!"
489 dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG);
490 if (!hotplug_trigger) {
491 u32 mask = PORTA_HOTPLUG_STATUS_MASK |
492 PORTD_HOTPLUG_STATUS_MASK |
493 PORTC_HOTPLUG_STATUS_MASK |
494 PORTB_HOTPLUG_STATUS_MASK;
495 dig_hotplug_reg &= ~mask;
498 intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG, dig_hotplug_reg);
499 if (!hotplug_trigger)
502 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
503 hotplug_trigger, dig_hotplug_reg,
504 dev_priv->display.hotplug.pch_hpd,
505 pch_port_hotplug_long_detect);
507 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
510 void xelpdp_pica_irq_handler(struct drm_i915_private *i915, u32 iir)
513 u32 hotplug_trigger = iir & (XELPDP_DP_ALT_HOTPLUG_MASK | XELPDP_TBT_HOTPLUG_MASK);
514 u32 trigger_aux = iir & XELPDP_AUX_TC_MASK;
515 u32 pin_mask = 0, long_mask = 0;
517 if (DISPLAY_VER(i915) >= 20)
518 trigger_aux |= iir & XE2LPD_AUX_DDI_MASK;
520 for (pin = HPD_PORT_TC1; pin <= HPD_PORT_TC4; pin++) {
523 if (!(i915->display.hotplug.hpd[pin] & hotplug_trigger))
526 pin_mask |= BIT(pin);
528 val = intel_de_read(i915, XELPDP_PORT_HOTPLUG_CTL(pin));
529 intel_de_write(i915, XELPDP_PORT_HOTPLUG_CTL(pin), val);
531 if (val & (XELPDP_DP_ALT_HPD_LONG_DETECT | XELPDP_TBT_HPD_LONG_DETECT))
532 long_mask |= BIT(pin);
537 "pica hotplug event received, stat 0x%08x, pins 0x%08x, long 0x%08x\n",
538 hotplug_trigger, pin_mask, long_mask);
540 intel_hpd_irq_handler(i915, pin_mask, long_mask);
544 intel_dp_aux_irq_handler(i915);
546 if (!pin_mask && !trigger_aux)
548 "Unexpected DE HPD/AUX interrupt 0x%08x\n", iir);
551 void icp_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
553 u32 ddi_hotplug_trigger = pch_iir & SDE_DDI_HOTPLUG_MASK_ICP;
554 u32 tc_hotplug_trigger = pch_iir & SDE_TC_HOTPLUG_MASK_ICP;
555 u32 pin_mask = 0, long_mask = 0;
557 if (ddi_hotplug_trigger) {
560 /* Locking due to DSI native GPIO sequences */
561 spin_lock(&dev_priv->irq_lock);
562 dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, SHOTPLUG_CTL_DDI, 0, 0);
563 spin_unlock(&dev_priv->irq_lock);
565 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
566 ddi_hotplug_trigger, dig_hotplug_reg,
567 dev_priv->display.hotplug.pch_hpd,
568 icp_ddi_port_hotplug_long_detect);
571 if (tc_hotplug_trigger) {
574 dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, SHOTPLUG_CTL_TC, 0, 0);
576 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
577 tc_hotplug_trigger, dig_hotplug_reg,
578 dev_priv->display.hotplug.pch_hpd,
579 icp_tc_port_hotplug_long_detect);
583 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
585 if (pch_iir & SDE_GMBUS_ICP)
586 intel_gmbus_irq_handler(dev_priv);
589 void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
591 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
592 ~SDE_PORTE_HOTPLUG_SPT;
593 u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
594 u32 pin_mask = 0, long_mask = 0;
596 if (hotplug_trigger) {
599 dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG, 0, 0);
601 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
602 hotplug_trigger, dig_hotplug_reg,
603 dev_priv->display.hotplug.pch_hpd,
604 spt_port_hotplug_long_detect);
607 if (hotplug2_trigger) {
610 dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG2, 0, 0);
612 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
613 hotplug2_trigger, dig_hotplug_reg,
614 dev_priv->display.hotplug.pch_hpd,
615 spt_port_hotplug2_long_detect);
619 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
621 if (pch_iir & SDE_GMBUS_CPT)
622 intel_gmbus_irq_handler(dev_priv);
625 void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv, u32 hotplug_trigger)
627 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
629 dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, DIGITAL_PORT_HOTPLUG_CNTRL, 0, 0);
631 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
632 hotplug_trigger, dig_hotplug_reg,
633 dev_priv->display.hotplug.hpd,
634 ilk_port_hotplug_long_detect);
636 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
639 void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv, u32 hotplug_trigger)
641 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
643 dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG, 0, 0);
645 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
646 hotplug_trigger, dig_hotplug_reg,
647 dev_priv->display.hotplug.hpd,
648 bxt_port_hotplug_long_detect);
650 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
653 void gen11_hpd_irq_handler(struct drm_i915_private *dev_priv, u32 iir)
655 u32 pin_mask = 0, long_mask = 0;
656 u32 trigger_tc = iir & GEN11_DE_TC_HOTPLUG_MASK;
657 u32 trigger_tbt = iir & GEN11_DE_TBT_HOTPLUG_MASK;
662 dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, GEN11_TC_HOTPLUG_CTL, 0, 0);
664 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
665 trigger_tc, dig_hotplug_reg,
666 dev_priv->display.hotplug.hpd,
667 gen11_port_hotplug_long_detect);
673 dig_hotplug_reg = intel_uncore_rmw(&dev_priv->uncore, GEN11_TBT_HOTPLUG_CTL, 0, 0);
675 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
676 trigger_tbt, dig_hotplug_reg,
677 dev_priv->display.hotplug.hpd,
678 gen11_port_hotplug_long_detect);
682 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
684 drm_err(&dev_priv->drm,
685 "Unexpected DE HPD interrupt 0x%08x\n", iir);
688 static u32 ibx_hotplug_mask(enum hpd_pin hpd_pin)
692 return PORTA_HOTPLUG_ENABLE;
694 return PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_MASK;
696 return PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_MASK;
698 return PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_MASK;
704 static u32 ibx_hotplug_enables(struct intel_encoder *encoder)
706 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
708 switch (encoder->hpd_pin) {
711 * When CPU and PCH are on the same package, port A
712 * HPD must be enabled in both north and south.
714 return HAS_PCH_LPT_LP(i915) ?
715 PORTA_HOTPLUG_ENABLE : 0;
717 return PORTB_HOTPLUG_ENABLE |
718 PORTB_PULSE_DURATION_2ms;
720 return PORTC_HOTPLUG_ENABLE |
721 PORTC_PULSE_DURATION_2ms;
723 return PORTD_HOTPLUG_ENABLE |
724 PORTD_PULSE_DURATION_2ms;
730 static void ibx_hpd_detection_setup(struct drm_i915_private *dev_priv)
733 * Enable digital hotplug on the PCH, and configure the DP short pulse
734 * duration to 2ms (which is the minimum in the Display Port spec).
735 * The pulse duration bits are reserved on LPT+.
737 intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG,
738 intel_hpd_hotplug_mask(dev_priv, ibx_hotplug_mask),
739 intel_hpd_hotplug_enables(dev_priv, ibx_hotplug_enables));
742 static void ibx_hpd_enable_detection(struct intel_encoder *encoder)
744 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
746 intel_uncore_rmw(&i915->uncore, PCH_PORT_HOTPLUG,
747 ibx_hotplug_mask(encoder->hpd_pin),
748 ibx_hotplug_enables(encoder));
751 static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv)
753 u32 hotplug_irqs, enabled_irqs;
755 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
756 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
758 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
760 ibx_hpd_detection_setup(dev_priv);
763 static u32 icp_ddi_hotplug_mask(enum hpd_pin hpd_pin)
770 return SHOTPLUG_CTL_DDI_HPD_ENABLE(hpd_pin);
776 static u32 icp_ddi_hotplug_enables(struct intel_encoder *encoder)
778 return icp_ddi_hotplug_mask(encoder->hpd_pin);
781 static u32 icp_tc_hotplug_mask(enum hpd_pin hpd_pin)
790 return ICP_TC_HPD_ENABLE(hpd_pin);
796 static u32 icp_tc_hotplug_enables(struct intel_encoder *encoder)
798 return icp_tc_hotplug_mask(encoder->hpd_pin);
801 static void icp_ddi_hpd_detection_setup(struct drm_i915_private *dev_priv)
803 intel_uncore_rmw(&dev_priv->uncore, SHOTPLUG_CTL_DDI,
804 intel_hpd_hotplug_mask(dev_priv, icp_ddi_hotplug_mask),
805 intel_hpd_hotplug_enables(dev_priv, icp_ddi_hotplug_enables));
808 static void icp_ddi_hpd_enable_detection(struct intel_encoder *encoder)
810 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
812 intel_uncore_rmw(&i915->uncore, SHOTPLUG_CTL_DDI,
813 icp_ddi_hotplug_mask(encoder->hpd_pin),
814 icp_ddi_hotplug_enables(encoder));
817 static void icp_tc_hpd_detection_setup(struct drm_i915_private *dev_priv)
819 intel_uncore_rmw(&dev_priv->uncore, SHOTPLUG_CTL_TC,
820 intel_hpd_hotplug_mask(dev_priv, icp_tc_hotplug_mask),
821 intel_hpd_hotplug_enables(dev_priv, icp_tc_hotplug_enables));
824 static void icp_tc_hpd_enable_detection(struct intel_encoder *encoder)
826 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
828 intel_uncore_rmw(&i915->uncore, SHOTPLUG_CTL_TC,
829 icp_tc_hotplug_mask(encoder->hpd_pin),
830 icp_tc_hotplug_enables(encoder));
833 static void icp_hpd_enable_detection(struct intel_encoder *encoder)
835 icp_ddi_hpd_enable_detection(encoder);
836 icp_tc_hpd_enable_detection(encoder);
839 static void icp_hpd_irq_setup(struct drm_i915_private *dev_priv)
841 u32 hotplug_irqs, enabled_irqs;
843 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
844 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
846 if (INTEL_PCH_TYPE(dev_priv) <= PCH_TGP)
847 intel_uncore_write(&dev_priv->uncore, SHPD_FILTER_CNT, SHPD_FILTER_CNT_500_ADJ);
849 intel_uncore_write(&dev_priv->uncore, SHPD_FILTER_CNT, SHPD_FILTER_CNT_250);
851 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
853 icp_ddi_hpd_detection_setup(dev_priv);
854 icp_tc_hpd_detection_setup(dev_priv);
857 static u32 gen11_hotplug_mask(enum hpd_pin hpd_pin)
866 return GEN11_HOTPLUG_CTL_ENABLE(hpd_pin);
872 static u32 gen11_hotplug_enables(struct intel_encoder *encoder)
874 return gen11_hotplug_mask(encoder->hpd_pin);
877 static void dg1_hpd_invert(struct drm_i915_private *i915)
879 u32 val = (INVERT_DDIA_HPD |
883 intel_uncore_rmw(&i915->uncore, SOUTH_CHICKEN1, 0, val);
886 static void dg1_hpd_enable_detection(struct intel_encoder *encoder)
888 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
890 dg1_hpd_invert(i915);
891 icp_hpd_enable_detection(encoder);
894 static void dg1_hpd_irq_setup(struct drm_i915_private *dev_priv)
896 dg1_hpd_invert(dev_priv);
897 icp_hpd_irq_setup(dev_priv);
900 static void gen11_tc_hpd_detection_setup(struct drm_i915_private *dev_priv)
902 intel_uncore_rmw(&dev_priv->uncore, GEN11_TC_HOTPLUG_CTL,
903 intel_hpd_hotplug_mask(dev_priv, gen11_hotplug_mask),
904 intel_hpd_hotplug_enables(dev_priv, gen11_hotplug_enables));
907 static void gen11_tc_hpd_enable_detection(struct intel_encoder *encoder)
909 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
911 intel_uncore_rmw(&i915->uncore, GEN11_TC_HOTPLUG_CTL,
912 gen11_hotplug_mask(encoder->hpd_pin),
913 gen11_hotplug_enables(encoder));
916 static void gen11_tbt_hpd_detection_setup(struct drm_i915_private *dev_priv)
918 intel_uncore_rmw(&dev_priv->uncore, GEN11_TBT_HOTPLUG_CTL,
919 intel_hpd_hotplug_mask(dev_priv, gen11_hotplug_mask),
920 intel_hpd_hotplug_enables(dev_priv, gen11_hotplug_enables));
923 static void gen11_tbt_hpd_enable_detection(struct intel_encoder *encoder)
925 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
927 intel_uncore_rmw(&i915->uncore, GEN11_TBT_HOTPLUG_CTL,
928 gen11_hotplug_mask(encoder->hpd_pin),
929 gen11_hotplug_enables(encoder));
932 static void gen11_hpd_enable_detection(struct intel_encoder *encoder)
934 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
936 gen11_tc_hpd_enable_detection(encoder);
937 gen11_tbt_hpd_enable_detection(encoder);
939 if (INTEL_PCH_TYPE(i915) >= PCH_ICP)
940 icp_hpd_enable_detection(encoder);
943 static void gen11_hpd_irq_setup(struct drm_i915_private *dev_priv)
945 u32 hotplug_irqs, enabled_irqs;
947 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.hpd);
948 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.hpd);
950 intel_uncore_rmw(&dev_priv->uncore, GEN11_DE_HPD_IMR, hotplug_irqs,
951 ~enabled_irqs & hotplug_irqs);
952 intel_uncore_posting_read(&dev_priv->uncore, GEN11_DE_HPD_IMR);
954 gen11_tc_hpd_detection_setup(dev_priv);
955 gen11_tbt_hpd_detection_setup(dev_priv);
957 if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
958 icp_hpd_irq_setup(dev_priv);
961 static u32 mtp_ddi_hotplug_mask(enum hpd_pin hpd_pin)
966 return SHOTPLUG_CTL_DDI_HPD_ENABLE(hpd_pin);
972 static u32 mtp_ddi_hotplug_enables(struct intel_encoder *encoder)
974 return mtp_ddi_hotplug_mask(encoder->hpd_pin);
977 static u32 mtp_tc_hotplug_mask(enum hpd_pin hpd_pin)
984 return ICP_TC_HPD_ENABLE(hpd_pin);
990 static u32 mtp_tc_hotplug_enables(struct intel_encoder *encoder)
992 return mtp_tc_hotplug_mask(encoder->hpd_pin);
995 static void mtp_ddi_hpd_detection_setup(struct drm_i915_private *i915)
997 intel_de_rmw(i915, SHOTPLUG_CTL_DDI,
998 intel_hpd_hotplug_mask(i915, mtp_ddi_hotplug_mask),
999 intel_hpd_hotplug_enables(i915, mtp_ddi_hotplug_enables));
1002 static void mtp_ddi_hpd_enable_detection(struct intel_encoder *encoder)
1004 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1006 intel_de_rmw(i915, SHOTPLUG_CTL_DDI,
1007 mtp_ddi_hotplug_mask(encoder->hpd_pin),
1008 mtp_ddi_hotplug_enables(encoder));
1011 static void mtp_tc_hpd_detection_setup(struct drm_i915_private *i915)
1013 intel_de_rmw(i915, SHOTPLUG_CTL_TC,
1014 intel_hpd_hotplug_mask(i915, mtp_tc_hotplug_mask),
1015 intel_hpd_hotplug_enables(i915, mtp_tc_hotplug_enables));
1018 static void mtp_tc_hpd_enable_detection(struct intel_encoder *encoder)
1020 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1022 intel_de_rmw(i915, SHOTPLUG_CTL_DDI,
1023 mtp_tc_hotplug_mask(encoder->hpd_pin),
1024 mtp_tc_hotplug_enables(encoder));
1027 static void mtp_hpd_invert(struct drm_i915_private *i915)
1029 u32 val = (INVERT_DDIA_HPD |
1036 INVERT_DDID_HPD_MTP |
1038 intel_de_rmw(i915, SOUTH_CHICKEN1, 0, val);
1041 static void mtp_hpd_enable_detection(struct intel_encoder *encoder)
1043 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1045 mtp_hpd_invert(i915);
1046 mtp_ddi_hpd_enable_detection(encoder);
1047 mtp_tc_hpd_enable_detection(encoder);
1050 static void mtp_hpd_irq_setup(struct drm_i915_private *i915)
1052 u32 hotplug_irqs, enabled_irqs;
1054 enabled_irqs = intel_hpd_enabled_irqs(i915, i915->display.hotplug.pch_hpd);
1055 hotplug_irqs = intel_hpd_hotplug_irqs(i915, i915->display.hotplug.pch_hpd);
1057 intel_de_write(i915, SHPD_FILTER_CNT, SHPD_FILTER_CNT_250);
1059 mtp_hpd_invert(i915);
1060 ibx_display_interrupt_update(i915, hotplug_irqs, enabled_irqs);
1062 mtp_ddi_hpd_detection_setup(i915);
1063 mtp_tc_hpd_detection_setup(i915);
1066 static void xe2lpd_sde_hpd_irq_setup(struct drm_i915_private *i915)
1068 u32 hotplug_irqs, enabled_irqs;
1070 enabled_irqs = intel_hpd_enabled_irqs(i915, i915->display.hotplug.pch_hpd);
1071 hotplug_irqs = intel_hpd_hotplug_irqs(i915, i915->display.hotplug.pch_hpd);
1073 ibx_display_interrupt_update(i915, hotplug_irqs, enabled_irqs);
1075 mtp_ddi_hpd_detection_setup(i915);
1076 mtp_tc_hpd_detection_setup(i915);
1079 static bool is_xelpdp_pica_hpd_pin(enum hpd_pin hpd_pin)
1081 return hpd_pin >= HPD_PORT_TC1 && hpd_pin <= HPD_PORT_TC4;
1084 static void _xelpdp_pica_hpd_detection_setup(struct drm_i915_private *i915,
1085 enum hpd_pin hpd_pin, bool enable)
1087 u32 mask = XELPDP_TBT_HOTPLUG_ENABLE |
1088 XELPDP_DP_ALT_HOTPLUG_ENABLE;
1090 if (!is_xelpdp_pica_hpd_pin(hpd_pin))
1093 intel_de_rmw(i915, XELPDP_PORT_HOTPLUG_CTL(hpd_pin),
1094 mask, enable ? mask : 0);
1097 static void xelpdp_pica_hpd_enable_detection(struct intel_encoder *encoder)
1099 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1101 _xelpdp_pica_hpd_detection_setup(i915, encoder->hpd_pin, true);
1104 static void xelpdp_pica_hpd_detection_setup(struct drm_i915_private *i915)
1106 struct intel_encoder *encoder;
1107 u32 available_pins = 0;
1110 BUILD_BUG_ON(BITS_PER_TYPE(available_pins) < HPD_NUM_PINS);
1112 for_each_intel_encoder(&i915->drm, encoder)
1113 available_pins |= BIT(encoder->hpd_pin);
1115 for_each_hpd_pin(pin)
1116 _xelpdp_pica_hpd_detection_setup(i915, pin, available_pins & BIT(pin));
1119 static void xelpdp_hpd_enable_detection(struct intel_encoder *encoder)
1121 xelpdp_pica_hpd_enable_detection(encoder);
1122 mtp_hpd_enable_detection(encoder);
1125 static void xelpdp_hpd_irq_setup(struct drm_i915_private *i915)
1127 u32 hotplug_irqs, enabled_irqs;
1129 enabled_irqs = intel_hpd_enabled_irqs(i915, i915->display.hotplug.hpd);
1130 hotplug_irqs = intel_hpd_hotplug_irqs(i915, i915->display.hotplug.hpd);
1132 intel_de_rmw(i915, PICAINTERRUPT_IMR, hotplug_irqs,
1133 ~enabled_irqs & hotplug_irqs);
1134 intel_uncore_posting_read(&i915->uncore, PICAINTERRUPT_IMR);
1136 xelpdp_pica_hpd_detection_setup(i915);
1138 if (INTEL_PCH_TYPE(i915) >= PCH_LNL)
1139 xe2lpd_sde_hpd_irq_setup(i915);
1140 else if (INTEL_PCH_TYPE(i915) >= PCH_MTL)
1141 mtp_hpd_irq_setup(i915);
1144 static u32 spt_hotplug_mask(enum hpd_pin hpd_pin)
1148 return PORTA_HOTPLUG_ENABLE;
1150 return PORTB_HOTPLUG_ENABLE;
1152 return PORTC_HOTPLUG_ENABLE;
1154 return PORTD_HOTPLUG_ENABLE;
1160 static u32 spt_hotplug_enables(struct intel_encoder *encoder)
1162 return spt_hotplug_mask(encoder->hpd_pin);
1165 static u32 spt_hotplug2_mask(enum hpd_pin hpd_pin)
1169 return PORTE_HOTPLUG_ENABLE;
1175 static u32 spt_hotplug2_enables(struct intel_encoder *encoder)
1177 return spt_hotplug2_mask(encoder->hpd_pin);
1180 static void spt_hpd_detection_setup(struct drm_i915_private *dev_priv)
1182 /* Display WA #1179 WaHardHangonHotPlug: cnp */
1183 if (HAS_PCH_CNP(dev_priv)) {
1184 intel_uncore_rmw(&dev_priv->uncore, SOUTH_CHICKEN1, CHASSIS_CLK_REQ_DURATION_MASK,
1185 CHASSIS_CLK_REQ_DURATION(0xf));
1188 /* Enable digital hotplug on the PCH */
1189 intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG,
1190 intel_hpd_hotplug_mask(dev_priv, spt_hotplug_mask),
1191 intel_hpd_hotplug_enables(dev_priv, spt_hotplug_enables));
1193 intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG2,
1194 intel_hpd_hotplug_mask(dev_priv, spt_hotplug2_mask),
1195 intel_hpd_hotplug_enables(dev_priv, spt_hotplug2_enables));
1198 static void spt_hpd_enable_detection(struct intel_encoder *encoder)
1200 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1202 /* Display WA #1179 WaHardHangonHotPlug: cnp */
1203 if (HAS_PCH_CNP(i915)) {
1204 intel_uncore_rmw(&i915->uncore, SOUTH_CHICKEN1,
1205 CHASSIS_CLK_REQ_DURATION_MASK,
1206 CHASSIS_CLK_REQ_DURATION(0xf));
1209 intel_uncore_rmw(&i915->uncore, PCH_PORT_HOTPLUG,
1210 spt_hotplug_mask(encoder->hpd_pin),
1211 spt_hotplug_enables(encoder));
1213 intel_uncore_rmw(&i915->uncore, PCH_PORT_HOTPLUG2,
1214 spt_hotplug2_mask(encoder->hpd_pin),
1215 spt_hotplug2_enables(encoder));
1218 static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv)
1220 u32 hotplug_irqs, enabled_irqs;
1222 if (INTEL_PCH_TYPE(dev_priv) >= PCH_CNP)
1223 intel_uncore_write(&dev_priv->uncore, SHPD_FILTER_CNT, SHPD_FILTER_CNT_500_ADJ);
1225 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
1226 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
1228 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
1230 spt_hpd_detection_setup(dev_priv);
1233 static u32 ilk_hotplug_mask(enum hpd_pin hpd_pin)
1237 return DIGITAL_PORTA_HOTPLUG_ENABLE |
1238 DIGITAL_PORTA_PULSE_DURATION_MASK;
1244 static u32 ilk_hotplug_enables(struct intel_encoder *encoder)
1246 switch (encoder->hpd_pin) {
1248 return DIGITAL_PORTA_HOTPLUG_ENABLE |
1249 DIGITAL_PORTA_PULSE_DURATION_2ms;
1255 static void ilk_hpd_detection_setup(struct drm_i915_private *dev_priv)
1258 * Enable digital hotplug on the CPU, and configure the DP short pulse
1259 * duration to 2ms (which is the minimum in the Display Port spec)
1260 * The pulse duration bits are reserved on HSW+.
1262 intel_uncore_rmw(&dev_priv->uncore, DIGITAL_PORT_HOTPLUG_CNTRL,
1263 intel_hpd_hotplug_mask(dev_priv, ilk_hotplug_mask),
1264 intel_hpd_hotplug_enables(dev_priv, ilk_hotplug_enables));
1267 static void ilk_hpd_enable_detection(struct intel_encoder *encoder)
1269 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1271 intel_uncore_rmw(&i915->uncore, DIGITAL_PORT_HOTPLUG_CNTRL,
1272 ilk_hotplug_mask(encoder->hpd_pin),
1273 ilk_hotplug_enables(encoder));
1275 ibx_hpd_enable_detection(encoder);
1278 static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv)
1280 u32 hotplug_irqs, enabled_irqs;
1282 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.hpd);
1283 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.hpd);
1285 if (DISPLAY_VER(dev_priv) >= 8)
1286 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
1288 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
1290 ilk_hpd_detection_setup(dev_priv);
1292 ibx_hpd_irq_setup(dev_priv);
1295 static u32 bxt_hotplug_mask(enum hpd_pin hpd_pin)
1299 return PORTA_HOTPLUG_ENABLE | BXT_DDIA_HPD_INVERT;
1301 return PORTB_HOTPLUG_ENABLE | BXT_DDIB_HPD_INVERT;
1303 return PORTC_HOTPLUG_ENABLE | BXT_DDIC_HPD_INVERT;
1309 static u32 bxt_hotplug_enables(struct intel_encoder *encoder)
1313 switch (encoder->hpd_pin) {
1315 hotplug = PORTA_HOTPLUG_ENABLE;
1316 if (intel_bios_encoder_hpd_invert(encoder->devdata))
1317 hotplug |= BXT_DDIA_HPD_INVERT;
1320 hotplug = PORTB_HOTPLUG_ENABLE;
1321 if (intel_bios_encoder_hpd_invert(encoder->devdata))
1322 hotplug |= BXT_DDIB_HPD_INVERT;
1325 hotplug = PORTC_HOTPLUG_ENABLE;
1326 if (intel_bios_encoder_hpd_invert(encoder->devdata))
1327 hotplug |= BXT_DDIC_HPD_INVERT;
1334 static void bxt_hpd_detection_setup(struct drm_i915_private *dev_priv)
1336 intel_uncore_rmw(&dev_priv->uncore, PCH_PORT_HOTPLUG,
1337 intel_hpd_hotplug_mask(dev_priv, bxt_hotplug_mask),
1338 intel_hpd_hotplug_enables(dev_priv, bxt_hotplug_enables));
1341 static void bxt_hpd_enable_detection(struct intel_encoder *encoder)
1343 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1345 intel_uncore_rmw(&i915->uncore, PCH_PORT_HOTPLUG,
1346 bxt_hotplug_mask(encoder->hpd_pin),
1347 bxt_hotplug_enables(encoder));
1350 static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv)
1352 u32 hotplug_irqs, enabled_irqs;
1354 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.hpd);
1355 hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.hpd);
1357 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
1359 bxt_hpd_detection_setup(dev_priv);
1362 static void g45_hpd_peg_band_gap_wa(struct drm_i915_private *i915)
1365 * For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
1366 * 0xd. Failure to do so will result in spurious interrupts being
1367 * generated on the port when a cable is not attached.
1369 intel_de_rmw(i915, PEG_BAND_GAP_DATA, 0xf, 0xd);
1372 static void i915_hpd_enable_detection(struct intel_encoder *encoder)
1374 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1375 u32 hotplug_en = hpd_mask_i915[encoder->hpd_pin];
1378 g45_hpd_peg_band_gap_wa(i915);
1380 /* HPD sense and interrupt enable are one and the same */
1381 i915_hotplug_interrupt_update(i915, hotplug_en, hotplug_en);
1384 static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv)
1388 lockdep_assert_held(&dev_priv->irq_lock);
1391 * Note HDMI and DP share hotplug bits. Enable bits are the same for all
1394 hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915);
1396 * Programming the CRT detection parameters tends to generate a spurious
1397 * hotplug event about three seconds later. So just do it once.
1399 if (IS_G4X(dev_priv))
1400 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
1401 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
1403 if (IS_G45(dev_priv))
1404 g45_hpd_peg_band_gap_wa(dev_priv);
1406 /* Ignore TV since it's buggy */
1407 i915_hotplug_interrupt_update_locked(dev_priv,
1408 HOTPLUG_INT_EN_MASK |
1409 CRT_HOTPLUG_VOLTAGE_COMPARE_MASK |
1410 CRT_HOTPLUG_ACTIVATION_PERIOD_64,
1414 struct intel_hotplug_funcs {
1415 /* Enable HPD sense and interrupts for all present encoders */
1416 void (*hpd_irq_setup)(struct drm_i915_private *i915);
1417 /* Enable HPD sense for a single encoder */
1418 void (*hpd_enable_detection)(struct intel_encoder *encoder);
1421 #define HPD_FUNCS(platform) \
1422 static const struct intel_hotplug_funcs platform##_hpd_funcs = { \
1423 .hpd_irq_setup = platform##_hpd_irq_setup, \
1424 .hpd_enable_detection = platform##_hpd_enable_detection, \
1437 void intel_hpd_enable_detection(struct intel_encoder *encoder)
1439 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1441 if (i915->display.funcs.hotplug)
1442 i915->display.funcs.hotplug->hpd_enable_detection(encoder);
1445 void intel_hpd_irq_setup(struct drm_i915_private *i915)
1447 if (i915->display.irq.display_irqs_enabled && i915->display.funcs.hotplug)
1448 i915->display.funcs.hotplug->hpd_irq_setup(i915);
1451 void intel_hotplug_irq_init(struct drm_i915_private *i915)
1453 intel_hpd_init_pins(i915);
1455 intel_hpd_init_early(i915);
1457 if (HAS_GMCH(i915)) {
1458 if (I915_HAS_HOTPLUG(i915))
1459 i915->display.funcs.hotplug = &i915_hpd_funcs;
1461 if (HAS_PCH_DG2(i915))
1462 i915->display.funcs.hotplug = &icp_hpd_funcs;
1463 else if (HAS_PCH_DG1(i915))
1464 i915->display.funcs.hotplug = &dg1_hpd_funcs;
1465 else if (DISPLAY_VER(i915) >= 14)
1466 i915->display.funcs.hotplug = &xelpdp_hpd_funcs;
1467 else if (DISPLAY_VER(i915) >= 11)
1468 i915->display.funcs.hotplug = &gen11_hpd_funcs;
1469 else if (IS_GEMINILAKE(i915) || IS_BROXTON(i915))
1470 i915->display.funcs.hotplug = &bxt_hpd_funcs;
1471 else if (INTEL_PCH_TYPE(i915) >= PCH_ICP)
1472 i915->display.funcs.hotplug = &icp_hpd_funcs;
1473 else if (INTEL_PCH_TYPE(i915) >= PCH_SPT)
1474 i915->display.funcs.hotplug = &spt_hpd_funcs;
1476 i915->display.funcs.hotplug = &ilk_hpd_funcs;