1 // SPDX-License-Identifier: MIT
3 * Copyright © 2018 Intel Corporation
7 #include "intel_combo_phy.h"
8 #include "intel_combo_phy_regs.h"
10 #include "intel_display_types.h"
12 #define for_each_combo_phy(__dev_priv, __phy) \
13 for ((__phy) = PHY_A; (__phy) < I915_MAX_PHYS; (__phy)++) \
14 for_each_if(intel_phy_is_combo(__dev_priv, __phy))
16 #define for_each_combo_phy_reverse(__dev_priv, __phy) \
17 for ((__phy) = I915_MAX_PHYS; (__phy)-- > PHY_A;) \
18 for_each_if(intel_phy_is_combo(__dev_priv, __phy))
28 static const struct icl_procmon {
31 } icl_procmon_values[] = {
32 [PROCMON_0_85V_DOT_0] = {
33 .name = "0.85V dot0 (low-voltage)",
34 .dw1 = 0x00000000, .dw9 = 0x62AB67BB, .dw10 = 0x51914F96,
36 [PROCMON_0_95V_DOT_0] = {
38 .dw1 = 0x00000000, .dw9 = 0x86E172C7, .dw10 = 0x77CA5EAB,
40 [PROCMON_0_95V_DOT_1] = {
42 .dw1 = 0x00000000, .dw9 = 0x93F87FE1, .dw10 = 0x8AE871C5,
44 [PROCMON_1_05V_DOT_0] = {
46 .dw1 = 0x00000000, .dw9 = 0x98FA82DD, .dw10 = 0x89E46DC1,
48 [PROCMON_1_05V_DOT_1] = {
50 .dw1 = 0x00440000, .dw9 = 0x9A00AB25, .dw10 = 0x8AE38FF1,
54 static const struct icl_procmon *
55 icl_get_procmon_ref_values(struct drm_i915_private *dev_priv, enum phy phy)
59 val = intel_de_read(dev_priv, ICL_PORT_COMP_DW3(phy));
60 switch (val & (PROCESS_INFO_MASK | VOLTAGE_INFO_MASK)) {
64 case VOLTAGE_INFO_0_85V | PROCESS_INFO_DOT_0:
65 return &icl_procmon_values[PROCMON_0_85V_DOT_0];
66 case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_0:
67 return &icl_procmon_values[PROCMON_0_95V_DOT_0];
68 case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_1:
69 return &icl_procmon_values[PROCMON_0_95V_DOT_1];
70 case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_0:
71 return &icl_procmon_values[PROCMON_1_05V_DOT_0];
72 case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_1:
73 return &icl_procmon_values[PROCMON_1_05V_DOT_1];
77 static void icl_set_procmon_ref_values(struct drm_i915_private *dev_priv,
80 const struct icl_procmon *procmon;
82 procmon = icl_get_procmon_ref_values(dev_priv, phy);
84 intel_de_rmw(dev_priv, ICL_PORT_COMP_DW1(phy),
85 (0xff << 16) | 0xff, procmon->dw1);
87 intel_de_write(dev_priv, ICL_PORT_COMP_DW9(phy), procmon->dw9);
88 intel_de_write(dev_priv, ICL_PORT_COMP_DW10(phy), procmon->dw10);
91 static bool check_phy_reg(struct drm_i915_private *dev_priv,
92 enum phy phy, i915_reg_t reg, u32 mask,
95 u32 val = intel_de_read(dev_priv, reg);
97 if ((val & mask) != expected_val) {
98 drm_dbg(&dev_priv->drm,
99 "Combo PHY %c reg %08x state mismatch: "
100 "current %08x mask %08x expected %08x\n",
102 reg.reg, val, mask, expected_val);
109 static bool icl_verify_procmon_ref_values(struct drm_i915_private *dev_priv,
112 const struct icl_procmon *procmon;
115 procmon = icl_get_procmon_ref_values(dev_priv, phy);
117 ret = check_phy_reg(dev_priv, phy, ICL_PORT_COMP_DW1(phy),
118 (0xff << 16) | 0xff, procmon->dw1);
119 ret &= check_phy_reg(dev_priv, phy, ICL_PORT_COMP_DW9(phy),
121 ret &= check_phy_reg(dev_priv, phy, ICL_PORT_COMP_DW10(phy),
127 static bool has_phy_misc(struct drm_i915_private *i915, enum phy phy)
130 * Some platforms only expect PHY_MISC to be programmed for PHY-A and
131 * PHY-B and may not even have instances of the register for the
134 * ADL-S technically has three instances of PHY_MISC, but only requires
135 * that we program it for PHY A.
138 if (IS_ALDERLAKE_S(i915))
140 else if ((IS_JASPERLAKE(i915) || IS_ELKHARTLAKE(i915)) ||
141 IS_ROCKETLAKE(i915) ||
148 static bool icl_combo_phy_enabled(struct drm_i915_private *dev_priv,
151 /* The PHY C added by EHL has no PHY_MISC register */
152 if (!has_phy_misc(dev_priv, phy))
153 return intel_de_read(dev_priv, ICL_PORT_COMP_DW0(phy)) & COMP_INIT;
155 return !(intel_de_read(dev_priv, ICL_PHY_MISC(phy)) &
156 ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN) &&
157 (intel_de_read(dev_priv, ICL_PORT_COMP_DW0(phy)) & COMP_INIT);
160 static bool ehl_vbt_ddi_d_present(struct drm_i915_private *i915)
162 bool ddi_a_present = intel_bios_is_port_present(i915, PORT_A);
163 bool ddi_d_present = intel_bios_is_port_present(i915, PORT_D);
164 bool dsi_present = intel_bios_is_dsi_present(i915, NULL);
167 * VBT's 'dvo port' field for child devices references the DDI, not
168 * the PHY. So if combo PHY A is wired up to drive an external
169 * display, we should see a child device present on PORT_D and
170 * nothing on PORT_A and no DSI.
172 if (ddi_d_present && !ddi_a_present && !dsi_present)
176 * If we encounter a VBT that claims to have an external display on
177 * DDI-D _and_ an internal display on DDI-A/DSI leave an error message
178 * in the log and let the internal display win.
182 "VBT claims to have both internal and external displays on PHY A. Configuring for internal.\n");
187 static bool phy_is_master(struct drm_i915_private *dev_priv, enum phy phy)
190 * Certain PHYs are connected to compensation resistors and act
191 * as masters to other PHYs.
194 * A(master) -> B(slave), C(slave)
196 * A(master) -> B(slave)
197 * C(master) -> D(slave)
199 * A(master) -> B(slave), C(slave)
200 * D(master) -> E(slave)
202 * We must set the IREFGEN bit for any PHY acting as a master
207 else if (IS_ALDERLAKE_S(dev_priv))
209 else if (IS_DG1(dev_priv) || IS_ROCKETLAKE(dev_priv))
215 static bool icl_combo_phy_verify_state(struct drm_i915_private *dev_priv,
219 u32 expected_val = 0;
221 if (!icl_combo_phy_enabled(dev_priv, phy))
224 if (DISPLAY_VER(dev_priv) >= 12) {
225 ret &= check_phy_reg(dev_priv, phy, ICL_PORT_TX_DW8_LN(0, phy),
226 ICL_PORT_TX_DW8_ODCC_CLK_SEL |
227 ICL_PORT_TX_DW8_ODCC_CLK_DIV_SEL_MASK,
228 ICL_PORT_TX_DW8_ODCC_CLK_SEL |
229 ICL_PORT_TX_DW8_ODCC_CLK_DIV_SEL_DIV2);
231 ret &= check_phy_reg(dev_priv, phy, ICL_PORT_PCS_DW1_LN(0, phy),
232 DCC_MODE_SELECT_MASK, RUN_DCC_ONCE);
235 ret &= icl_verify_procmon_ref_values(dev_priv, phy);
237 if (phy_is_master(dev_priv, phy)) {
238 ret &= check_phy_reg(dev_priv, phy, ICL_PORT_COMP_DW8(phy),
241 if (IS_JASPERLAKE(dev_priv) || IS_ELKHARTLAKE(dev_priv)) {
242 if (ehl_vbt_ddi_d_present(dev_priv))
243 expected_val = ICL_PHY_MISC_MUX_DDID;
245 ret &= check_phy_reg(dev_priv, phy, ICL_PHY_MISC(phy),
246 ICL_PHY_MISC_MUX_DDID,
251 ret &= check_phy_reg(dev_priv, phy, ICL_PORT_CL_DW5(phy),
252 CL_POWER_DOWN_ENABLE, CL_POWER_DOWN_ENABLE);
257 void intel_combo_phy_power_up_lanes(struct drm_i915_private *dev_priv,
258 enum phy phy, bool is_dsi,
259 int lane_count, bool lane_reversal)
264 drm_WARN_ON(&dev_priv->drm, lane_reversal);
266 switch (lane_count) {
268 lane_mask = PWR_DOWN_LN_3_1_0;
271 lane_mask = PWR_DOWN_LN_3_1;
274 lane_mask = PWR_DOWN_LN_3;
277 MISSING_CASE(lane_count);
280 lane_mask = PWR_UP_ALL_LANES;
284 switch (lane_count) {
286 lane_mask = lane_reversal ? PWR_DOWN_LN_2_1_0 :
290 lane_mask = lane_reversal ? PWR_DOWN_LN_1_0 :
294 MISSING_CASE(lane_count);
297 lane_mask = PWR_UP_ALL_LANES;
302 intel_de_rmw(dev_priv, ICL_PORT_CL_DW10(phy),
303 PWR_DOWN_LN_MASK, lane_mask);
306 static void icl_combo_phys_init(struct drm_i915_private *dev_priv)
310 for_each_combo_phy(dev_priv, phy) {
311 const struct icl_procmon *procmon;
314 if (icl_combo_phy_verify_state(dev_priv, phy))
317 procmon = icl_get_procmon_ref_values(dev_priv, phy);
319 drm_dbg(&dev_priv->drm,
320 "Initializing combo PHY %c (Voltage/Process Info : %s)\n",
321 phy_name(phy), procmon->name);
323 if (!has_phy_misc(dev_priv, phy))
327 * EHL's combo PHY A can be hooked up to either an external
328 * display (via DDI-D) or an internal display (via DDI-A or
329 * the DSI DPHY). This is a motherboard design decision that
330 * can't be changed on the fly, so initialize the PHY's mux
331 * based on whether our VBT indicates the presence of any
332 * "internal" child devices.
334 val = intel_de_read(dev_priv, ICL_PHY_MISC(phy));
335 if ((IS_JASPERLAKE(dev_priv) || IS_ELKHARTLAKE(dev_priv)) &&
337 val &= ~ICL_PHY_MISC_MUX_DDID;
339 if (ehl_vbt_ddi_d_present(dev_priv))
340 val |= ICL_PHY_MISC_MUX_DDID;
343 val &= ~ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN;
344 intel_de_write(dev_priv, ICL_PHY_MISC(phy), val);
347 if (DISPLAY_VER(dev_priv) >= 12) {
348 val = intel_de_read(dev_priv, ICL_PORT_TX_DW8_LN(0, phy));
349 val &= ~ICL_PORT_TX_DW8_ODCC_CLK_DIV_SEL_MASK;
350 val |= ICL_PORT_TX_DW8_ODCC_CLK_SEL;
351 val |= ICL_PORT_TX_DW8_ODCC_CLK_DIV_SEL_DIV2;
352 intel_de_write(dev_priv, ICL_PORT_TX_DW8_GRP(phy), val);
354 val = intel_de_read(dev_priv, ICL_PORT_PCS_DW1_LN(0, phy));
355 val &= ~DCC_MODE_SELECT_MASK;
357 intel_de_write(dev_priv, ICL_PORT_PCS_DW1_GRP(phy), val);
360 icl_set_procmon_ref_values(dev_priv, phy);
362 if (phy_is_master(dev_priv, phy))
363 intel_de_rmw(dev_priv, ICL_PORT_COMP_DW8(phy),
366 intel_de_rmw(dev_priv, ICL_PORT_COMP_DW0(phy), 0, COMP_INIT);
367 intel_de_rmw(dev_priv, ICL_PORT_CL_DW5(phy),
368 0, CL_POWER_DOWN_ENABLE);
372 static void icl_combo_phys_uninit(struct drm_i915_private *dev_priv)
376 for_each_combo_phy_reverse(dev_priv, phy) {
378 !icl_combo_phy_verify_state(dev_priv, phy)) {
379 if (IS_TIGERLAKE(dev_priv) || IS_DG1(dev_priv)) {
381 * A known problem with old ifwi:
382 * https://gitlab.freedesktop.org/drm/intel/-/issues/2411
383 * Suppress the warning for CI. Remove ASAP!
385 drm_dbg_kms(&dev_priv->drm,
386 "Combo PHY %c HW state changed unexpectedly\n",
389 drm_warn(&dev_priv->drm,
390 "Combo PHY %c HW state changed unexpectedly\n",
395 if (!has_phy_misc(dev_priv, phy))
398 intel_de_rmw(dev_priv, ICL_PHY_MISC(phy), 0,
399 ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN);
402 intel_de_rmw(dev_priv, ICL_PORT_COMP_DW0(phy), COMP_INIT, 0);
406 void intel_combo_phy_init(struct drm_i915_private *i915)
408 icl_combo_phys_init(i915);
411 void intel_combo_phy_uninit(struct drm_i915_private *i915)
413 icl_combo_phys_uninit(i915);