1 // SPDX-License-Identifier: MIT
3 * Copyright © 2018 Intel Corporation
6 #include "intel_combo_phy.h"
8 #include "intel_display_types.h"
10 #define for_each_combo_phy(__dev_priv, __phy) \
11 for ((__phy) = PHY_A; (__phy) < I915_MAX_PHYS; (__phy)++) \
12 for_each_if(intel_phy_is_combo(__dev_priv, __phy))
14 #define for_each_combo_phy_reverse(__dev_priv, __phy) \
15 for ((__phy) = I915_MAX_PHYS; (__phy)-- > PHY_A;) \
16 for_each_if(intel_phy_is_combo(__dev_priv, __phy))
26 static const struct cnl_procmon {
28 } cnl_procmon_values[] = {
29 [PROCMON_0_85V_DOT_0] =
30 { .dw1 = 0x00000000, .dw9 = 0x62AB67BB, .dw10 = 0x51914F96, },
31 [PROCMON_0_95V_DOT_0] =
32 { .dw1 = 0x00000000, .dw9 = 0x86E172C7, .dw10 = 0x77CA5EAB, },
33 [PROCMON_0_95V_DOT_1] =
34 { .dw1 = 0x00000000, .dw9 = 0x93F87FE1, .dw10 = 0x8AE871C5, },
35 [PROCMON_1_05V_DOT_0] =
36 { .dw1 = 0x00000000, .dw9 = 0x98FA82DD, .dw10 = 0x89E46DC1, },
37 [PROCMON_1_05V_DOT_1] =
38 { .dw1 = 0x00440000, .dw9 = 0x9A00AB25, .dw10 = 0x8AE38FF1, },
42 * CNL has just one set of registers, while gen11 has a set for each combo PHY.
43 * The CNL registers are equivalent to the gen11 PHY A registers, that's why we
44 * call the ICL macros even though the function has CNL on its name.
46 static const struct cnl_procmon *
47 cnl_get_procmon_ref_values(struct drm_i915_private *dev_priv, enum phy phy)
49 const struct cnl_procmon *procmon;
52 val = intel_de_read(dev_priv, ICL_PORT_COMP_DW3(phy));
53 switch (val & (PROCESS_INFO_MASK | VOLTAGE_INFO_MASK)) {
57 case VOLTAGE_INFO_0_85V | PROCESS_INFO_DOT_0:
58 procmon = &cnl_procmon_values[PROCMON_0_85V_DOT_0];
60 case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_0:
61 procmon = &cnl_procmon_values[PROCMON_0_95V_DOT_0];
63 case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_1:
64 procmon = &cnl_procmon_values[PROCMON_0_95V_DOT_1];
66 case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_0:
67 procmon = &cnl_procmon_values[PROCMON_1_05V_DOT_0];
69 case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_1:
70 procmon = &cnl_procmon_values[PROCMON_1_05V_DOT_1];
77 static void cnl_set_procmon_ref_values(struct drm_i915_private *dev_priv,
80 const struct cnl_procmon *procmon;
83 procmon = cnl_get_procmon_ref_values(dev_priv, phy);
85 val = intel_de_read(dev_priv, ICL_PORT_COMP_DW1(phy));
86 val &= ~((0xff << 16) | 0xff);
88 intel_de_write(dev_priv, ICL_PORT_COMP_DW1(phy), val);
90 intel_de_write(dev_priv, ICL_PORT_COMP_DW9(phy), procmon->dw9);
91 intel_de_write(dev_priv, ICL_PORT_COMP_DW10(phy), procmon->dw10);
94 static bool check_phy_reg(struct drm_i915_private *dev_priv,
95 enum phy phy, i915_reg_t reg, u32 mask,
98 u32 val = intel_de_read(dev_priv, reg);
100 if ((val & mask) != expected_val) {
101 drm_dbg(&dev_priv->drm,
102 "Combo PHY %c reg %08x state mismatch: "
103 "current %08x mask %08x expected %08x\n",
105 reg.reg, val, mask, expected_val);
112 static bool cnl_verify_procmon_ref_values(struct drm_i915_private *dev_priv,
115 const struct cnl_procmon *procmon;
118 procmon = cnl_get_procmon_ref_values(dev_priv, phy);
120 ret = check_phy_reg(dev_priv, phy, ICL_PORT_COMP_DW1(phy),
121 (0xff << 16) | 0xff, procmon->dw1);
122 ret &= check_phy_reg(dev_priv, phy, ICL_PORT_COMP_DW9(phy),
124 ret &= check_phy_reg(dev_priv, phy, ICL_PORT_COMP_DW10(phy),
130 static bool cnl_combo_phy_enabled(struct drm_i915_private *dev_priv)
132 return !(intel_de_read(dev_priv, CHICKEN_MISC_2) & CNL_COMP_PWR_DOWN) &&
133 (intel_de_read(dev_priv, CNL_PORT_COMP_DW0) & COMP_INIT);
136 static bool cnl_combo_phy_verify_state(struct drm_i915_private *dev_priv)
138 enum phy phy = PHY_A;
141 if (!cnl_combo_phy_enabled(dev_priv))
144 ret = cnl_verify_procmon_ref_values(dev_priv, phy);
146 ret &= check_phy_reg(dev_priv, phy, CNL_PORT_CL1CM_DW5,
147 CL_POWER_DOWN_ENABLE, CL_POWER_DOWN_ENABLE);
152 static void cnl_combo_phys_init(struct drm_i915_private *dev_priv)
156 val = intel_de_read(dev_priv, CHICKEN_MISC_2);
157 val &= ~CNL_COMP_PWR_DOWN;
158 intel_de_write(dev_priv, CHICKEN_MISC_2, val);
160 /* Dummy PORT_A to get the correct CNL register from the ICL macro */
161 cnl_set_procmon_ref_values(dev_priv, PHY_A);
163 val = intel_de_read(dev_priv, CNL_PORT_COMP_DW0);
165 intel_de_write(dev_priv, CNL_PORT_COMP_DW0, val);
167 val = intel_de_read(dev_priv, CNL_PORT_CL1CM_DW5);
168 val |= CL_POWER_DOWN_ENABLE;
169 intel_de_write(dev_priv, CNL_PORT_CL1CM_DW5, val);
172 static void cnl_combo_phys_uninit(struct drm_i915_private *dev_priv)
176 if (!cnl_combo_phy_verify_state(dev_priv))
177 drm_warn(&dev_priv->drm,
178 "Combo PHY HW state changed unexpectedly.\n");
180 val = intel_de_read(dev_priv, CHICKEN_MISC_2);
181 val |= CNL_COMP_PWR_DOWN;
182 intel_de_write(dev_priv, CHICKEN_MISC_2, val);
185 static bool has_phy_misc(struct drm_i915_private *i915, enum phy phy)
188 * Some platforms only expect PHY_MISC to be programmed for PHY-A and
189 * PHY-B and may not even have instances of the register for the
192 * ADL-S technically has three instances of PHY_MISC, but only requires
193 * that we program it for PHY A.
196 if (IS_ALDERLAKE_S(i915))
198 else if (IS_JSL_EHL(i915) ||
199 IS_ROCKETLAKE(i915) ||
206 static bool icl_combo_phy_enabled(struct drm_i915_private *dev_priv,
209 /* The PHY C added by EHL has no PHY_MISC register */
210 if (!has_phy_misc(dev_priv, phy))
211 return intel_de_read(dev_priv, ICL_PORT_COMP_DW0(phy)) & COMP_INIT;
213 return !(intel_de_read(dev_priv, ICL_PHY_MISC(phy)) &
214 ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN) &&
215 (intel_de_read(dev_priv, ICL_PORT_COMP_DW0(phy)) & COMP_INIT);
218 static bool ehl_vbt_ddi_d_present(struct drm_i915_private *i915)
220 bool ddi_a_present = intel_bios_is_port_present(i915, PORT_A);
221 bool ddi_d_present = intel_bios_is_port_present(i915, PORT_D);
222 bool dsi_present = intel_bios_is_dsi_present(i915, NULL);
225 * VBT's 'dvo port' field for child devices references the DDI, not
226 * the PHY. So if combo PHY A is wired up to drive an external
227 * display, we should see a child device present on PORT_D and
228 * nothing on PORT_A and no DSI.
230 if (ddi_d_present && !ddi_a_present && !dsi_present)
234 * If we encounter a VBT that claims to have an external display on
235 * DDI-D _and_ an internal display on DDI-A/DSI leave an error message
236 * in the log and let the internal display win.
240 "VBT claims to have both internal and external displays on PHY A. Configuring for internal.\n");
245 static bool phy_is_master(struct drm_i915_private *dev_priv, enum phy phy)
248 * Certain PHYs are connected to compensation resistors and act
249 * as masters to other PHYs.
252 * A(master) -> B(slave), C(slave)
254 * A(master) -> B(slave)
255 * C(master) -> D(slave)
257 * A(master) -> B(slave), C(slave)
258 * D(master) -> E(slave)
260 * We must set the IREFGEN bit for any PHY acting as a master
265 else if (IS_ALDERLAKE_S(dev_priv))
267 else if (IS_DG1(dev_priv) || IS_ROCKETLAKE(dev_priv))
273 static bool icl_combo_phy_verify_state(struct drm_i915_private *dev_priv,
277 u32 expected_val = 0;
279 if (!icl_combo_phy_enabled(dev_priv, phy))
282 if (DISPLAY_VER(dev_priv) >= 12) {
283 ret &= check_phy_reg(dev_priv, phy, ICL_PORT_TX_DW8_LN0(phy),
284 ICL_PORT_TX_DW8_ODCC_CLK_SEL |
285 ICL_PORT_TX_DW8_ODCC_CLK_DIV_SEL_MASK,
286 ICL_PORT_TX_DW8_ODCC_CLK_SEL |
287 ICL_PORT_TX_DW8_ODCC_CLK_DIV_SEL_DIV2);
289 ret &= check_phy_reg(dev_priv, phy, ICL_PORT_PCS_DW1_LN0(phy),
290 DCC_MODE_SELECT_MASK,
291 DCC_MODE_SELECT_CONTINUOSLY);
294 ret &= cnl_verify_procmon_ref_values(dev_priv, phy);
296 if (phy_is_master(dev_priv, phy)) {
297 ret &= check_phy_reg(dev_priv, phy, ICL_PORT_COMP_DW8(phy),
300 if (IS_JSL_EHL(dev_priv)) {
301 if (ehl_vbt_ddi_d_present(dev_priv))
302 expected_val = ICL_PHY_MISC_MUX_DDID;
304 ret &= check_phy_reg(dev_priv, phy, ICL_PHY_MISC(phy),
305 ICL_PHY_MISC_MUX_DDID,
310 ret &= check_phy_reg(dev_priv, phy, ICL_PORT_CL_DW5(phy),
311 CL_POWER_DOWN_ENABLE, CL_POWER_DOWN_ENABLE);
316 void intel_combo_phy_power_up_lanes(struct drm_i915_private *dev_priv,
317 enum phy phy, bool is_dsi,
318 int lane_count, bool lane_reversal)
324 drm_WARN_ON(&dev_priv->drm, lane_reversal);
326 switch (lane_count) {
328 lane_mask = PWR_DOWN_LN_3_1_0;
331 lane_mask = PWR_DOWN_LN_3_1;
334 lane_mask = PWR_DOWN_LN_3;
337 MISSING_CASE(lane_count);
340 lane_mask = PWR_UP_ALL_LANES;
344 switch (lane_count) {
346 lane_mask = lane_reversal ? PWR_DOWN_LN_2_1_0 :
350 lane_mask = lane_reversal ? PWR_DOWN_LN_1_0 :
354 MISSING_CASE(lane_count);
357 lane_mask = PWR_UP_ALL_LANES;
362 val = intel_de_read(dev_priv, ICL_PORT_CL_DW10(phy));
363 val &= ~PWR_DOWN_LN_MASK;
364 val |= lane_mask << PWR_DOWN_LN_SHIFT;
365 intel_de_write(dev_priv, ICL_PORT_CL_DW10(phy), val);
368 static void icl_combo_phys_init(struct drm_i915_private *dev_priv)
372 for_each_combo_phy(dev_priv, phy) {
375 if (icl_combo_phy_verify_state(dev_priv, phy)) {
376 drm_dbg(&dev_priv->drm,
377 "Combo PHY %c already enabled, won't reprogram it.\n",
382 if (!has_phy_misc(dev_priv, phy))
386 * EHL's combo PHY A can be hooked up to either an external
387 * display (via DDI-D) or an internal display (via DDI-A or
388 * the DSI DPHY). This is a motherboard design decision that
389 * can't be changed on the fly, so initialize the PHY's mux
390 * based on whether our VBT indicates the presence of any
391 * "internal" child devices.
393 val = intel_de_read(dev_priv, ICL_PHY_MISC(phy));
394 if (IS_JSL_EHL(dev_priv) && phy == PHY_A) {
395 val &= ~ICL_PHY_MISC_MUX_DDID;
397 if (ehl_vbt_ddi_d_present(dev_priv))
398 val |= ICL_PHY_MISC_MUX_DDID;
401 val &= ~ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN;
402 intel_de_write(dev_priv, ICL_PHY_MISC(phy), val);
405 if (DISPLAY_VER(dev_priv) >= 12) {
406 val = intel_de_read(dev_priv, ICL_PORT_TX_DW8_LN0(phy));
407 val &= ~ICL_PORT_TX_DW8_ODCC_CLK_DIV_SEL_MASK;
408 val |= ICL_PORT_TX_DW8_ODCC_CLK_SEL;
409 val |= ICL_PORT_TX_DW8_ODCC_CLK_DIV_SEL_DIV2;
410 intel_de_write(dev_priv, ICL_PORT_TX_DW8_GRP(phy), val);
412 val = intel_de_read(dev_priv, ICL_PORT_PCS_DW1_LN0(phy));
413 val &= ~DCC_MODE_SELECT_MASK;
414 val |= DCC_MODE_SELECT_CONTINUOSLY;
415 intel_de_write(dev_priv, ICL_PORT_PCS_DW1_GRP(phy), val);
418 cnl_set_procmon_ref_values(dev_priv, phy);
420 if (phy_is_master(dev_priv, phy)) {
421 val = intel_de_read(dev_priv, ICL_PORT_COMP_DW8(phy));
423 intel_de_write(dev_priv, ICL_PORT_COMP_DW8(phy), val);
426 val = intel_de_read(dev_priv, ICL_PORT_COMP_DW0(phy));
428 intel_de_write(dev_priv, ICL_PORT_COMP_DW0(phy), val);
430 val = intel_de_read(dev_priv, ICL_PORT_CL_DW5(phy));
431 val |= CL_POWER_DOWN_ENABLE;
432 intel_de_write(dev_priv, ICL_PORT_CL_DW5(phy), val);
436 static void icl_combo_phys_uninit(struct drm_i915_private *dev_priv)
440 for_each_combo_phy_reverse(dev_priv, phy) {
444 !icl_combo_phy_verify_state(dev_priv, phy)) {
445 if (IS_TIGERLAKE(dev_priv) || IS_DG1(dev_priv)) {
447 * A known problem with old ifwi:
448 * https://gitlab.freedesktop.org/drm/intel/-/issues/2411
449 * Suppress the warning for CI. Remove ASAP!
451 drm_dbg_kms(&dev_priv->drm,
452 "Combo PHY %c HW state changed unexpectedly\n",
455 drm_warn(&dev_priv->drm,
456 "Combo PHY %c HW state changed unexpectedly\n",
461 if (!has_phy_misc(dev_priv, phy))
464 val = intel_de_read(dev_priv, ICL_PHY_MISC(phy));
465 val |= ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN;
466 intel_de_write(dev_priv, ICL_PHY_MISC(phy), val);
469 val = intel_de_read(dev_priv, ICL_PORT_COMP_DW0(phy));
471 intel_de_write(dev_priv, ICL_PORT_COMP_DW0(phy), val);
475 void intel_combo_phy_init(struct drm_i915_private *i915)
477 if (DISPLAY_VER(i915) >= 11)
478 icl_combo_phys_init(i915);
479 else if (IS_CANNONLAKE(i915))
480 cnl_combo_phys_init(i915);
483 void intel_combo_phy_uninit(struct drm_i915_private *i915)
485 if (DISPLAY_VER(i915) >= 11)
486 icl_combo_phys_uninit(i915);
487 else if (IS_CANNONLAKE(i915))
488 cnl_combo_phys_uninit(i915);