1 // SPDX-License-Identifier: MIT
3 * Copyright © 2018 Intel Corporation
8 #define for_each_combo_port(__dev_priv, __port) \
9 for ((__port) = PORT_A; (__port) < I915_MAX_PORTS; (__port)++) \
10 for_each_if(intel_port_is_combophy(__dev_priv, __port))
12 #define for_each_combo_port_reverse(__dev_priv, __port) \
13 for ((__port) = I915_MAX_PORTS; (__port)-- > PORT_A;) \
14 for_each_if(intel_port_is_combophy(__dev_priv, __port))
24 static const struct cnl_procmon {
26 } cnl_procmon_values[] = {
27 [PROCMON_0_85V_DOT_0] =
28 { .dw1 = 0x00000000, .dw9 = 0x62AB67BB, .dw10 = 0x51914F96, },
29 [PROCMON_0_95V_DOT_0] =
30 { .dw1 = 0x00000000, .dw9 = 0x86E172C7, .dw10 = 0x77CA5EAB, },
31 [PROCMON_0_95V_DOT_1] =
32 { .dw1 = 0x00000000, .dw9 = 0x93F87FE1, .dw10 = 0x8AE871C5, },
33 [PROCMON_1_05V_DOT_0] =
34 { .dw1 = 0x00000000, .dw9 = 0x98FA82DD, .dw10 = 0x89E46DC1, },
35 [PROCMON_1_05V_DOT_1] =
36 { .dw1 = 0x00440000, .dw9 = 0x9A00AB25, .dw10 = 0x8AE38FF1, },
40 * CNL has just one set of registers, while ICL has two sets: one for port A and
41 * the other for port B. The CNL registers are equivalent to the ICL port A
42 * registers, that's why we call the ICL macros even though the function has CNL
45 static const struct cnl_procmon *
46 cnl_get_procmon_ref_values(struct drm_i915_private *dev_priv, enum port port)
48 const struct cnl_procmon *procmon;
51 val = I915_READ(ICL_PORT_COMP_DW3(port));
52 switch (val & (PROCESS_INFO_MASK | VOLTAGE_INFO_MASK)) {
56 case VOLTAGE_INFO_0_85V | PROCESS_INFO_DOT_0:
57 procmon = &cnl_procmon_values[PROCMON_0_85V_DOT_0];
59 case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_0:
60 procmon = &cnl_procmon_values[PROCMON_0_95V_DOT_0];
62 case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_1:
63 procmon = &cnl_procmon_values[PROCMON_0_95V_DOT_1];
65 case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_0:
66 procmon = &cnl_procmon_values[PROCMON_1_05V_DOT_0];
68 case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_1:
69 procmon = &cnl_procmon_values[PROCMON_1_05V_DOT_1];
76 static void cnl_set_procmon_ref_values(struct drm_i915_private *dev_priv,
79 const struct cnl_procmon *procmon;
82 procmon = cnl_get_procmon_ref_values(dev_priv, port);
84 val = I915_READ(ICL_PORT_COMP_DW1(port));
85 val &= ~((0xff << 16) | 0xff);
87 I915_WRITE(ICL_PORT_COMP_DW1(port), val);
89 I915_WRITE(ICL_PORT_COMP_DW9(port), procmon->dw9);
90 I915_WRITE(ICL_PORT_COMP_DW10(port), procmon->dw10);
93 static bool check_phy_reg(struct drm_i915_private *dev_priv,
94 enum port port, i915_reg_t reg, u32 mask,
97 u32 val = I915_READ(reg);
99 if ((val & mask) != expected_val) {
100 DRM_DEBUG_DRIVER("Port %c combo PHY reg %08x state mismatch: "
101 "current %08x mask %08x expected %08x\n",
103 reg.reg, val, mask, expected_val);
110 static bool cnl_verify_procmon_ref_values(struct drm_i915_private *dev_priv,
113 const struct cnl_procmon *procmon;
116 procmon = cnl_get_procmon_ref_values(dev_priv, port);
118 ret = check_phy_reg(dev_priv, port, ICL_PORT_COMP_DW1(port),
119 (0xff << 16) | 0xff, procmon->dw1);
120 ret &= check_phy_reg(dev_priv, port, ICL_PORT_COMP_DW9(port),
122 ret &= check_phy_reg(dev_priv, port, ICL_PORT_COMP_DW10(port),
128 static bool cnl_combo_phy_enabled(struct drm_i915_private *dev_priv)
130 return !(I915_READ(CHICKEN_MISC_2) & CNL_COMP_PWR_DOWN) &&
131 (I915_READ(CNL_PORT_COMP_DW0) & COMP_INIT);
134 static bool cnl_combo_phy_verify_state(struct drm_i915_private *dev_priv)
136 enum port port = PORT_A;
139 if (!cnl_combo_phy_enabled(dev_priv))
142 ret = cnl_verify_procmon_ref_values(dev_priv, port);
144 ret &= check_phy_reg(dev_priv, port, CNL_PORT_CL1CM_DW5,
145 CL_POWER_DOWN_ENABLE, CL_POWER_DOWN_ENABLE);
150 void cnl_combo_phys_init(struct drm_i915_private *dev_priv)
154 val = I915_READ(CHICKEN_MISC_2);
155 val &= ~CNL_COMP_PWR_DOWN;
156 I915_WRITE(CHICKEN_MISC_2, val);
158 /* Dummy PORT_A to get the correct CNL register from the ICL macro */
159 cnl_set_procmon_ref_values(dev_priv, PORT_A);
161 val = I915_READ(CNL_PORT_COMP_DW0);
163 I915_WRITE(CNL_PORT_COMP_DW0, val);
165 val = I915_READ(CNL_PORT_CL1CM_DW5);
166 val |= CL_POWER_DOWN_ENABLE;
167 I915_WRITE(CNL_PORT_CL1CM_DW5, val);
170 void cnl_combo_phys_uninit(struct drm_i915_private *dev_priv)
174 if (!cnl_combo_phy_verify_state(dev_priv))
175 DRM_WARN("Combo PHY HW state changed unexpectedly.\n");
177 val = I915_READ(CHICKEN_MISC_2);
178 val |= CNL_COMP_PWR_DOWN;
179 I915_WRITE(CHICKEN_MISC_2, val);
182 static bool icl_combo_phy_enabled(struct drm_i915_private *dev_priv,
185 return !(I915_READ(ICL_PHY_MISC(port)) &
186 ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN) &&
187 (I915_READ(ICL_PORT_COMP_DW0(port)) & COMP_INIT);
190 static bool icl_combo_phy_verify_state(struct drm_i915_private *dev_priv,
195 if (!icl_combo_phy_enabled(dev_priv, port))
198 ret = cnl_verify_procmon_ref_values(dev_priv, port);
200 ret &= check_phy_reg(dev_priv, port, ICL_PORT_CL_DW5(port),
201 CL_POWER_DOWN_ENABLE, CL_POWER_DOWN_ENABLE);
206 void icl_combo_phys_init(struct drm_i915_private *dev_priv)
210 for_each_combo_port(dev_priv, port) {
213 if (icl_combo_phy_verify_state(dev_priv, port)) {
214 DRM_DEBUG_DRIVER("Port %c combo PHY already enabled, won't reprogram it.\n",
219 val = I915_READ(ICL_PHY_MISC(port));
220 val &= ~ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN;
221 I915_WRITE(ICL_PHY_MISC(port), val);
223 cnl_set_procmon_ref_values(dev_priv, port);
225 val = I915_READ(ICL_PORT_COMP_DW0(port));
227 I915_WRITE(ICL_PORT_COMP_DW0(port), val);
229 val = I915_READ(ICL_PORT_CL_DW5(port));
230 val |= CL_POWER_DOWN_ENABLE;
231 I915_WRITE(ICL_PORT_CL_DW5(port), val);
235 void icl_combo_phys_uninit(struct drm_i915_private *dev_priv)
239 for_each_combo_port_reverse(dev_priv, port) {
242 if (port == PORT_A &&
243 !icl_combo_phy_verify_state(dev_priv, port))
244 DRM_WARN("Port %c combo PHY HW state changed unexpectedly\n",
247 val = I915_READ(ICL_PHY_MISC(port));
248 val |= ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN;
249 I915_WRITE(ICL_PHY_MISC(port), val);
251 val = I915_READ(ICL_PORT_COMP_DW0(port));
253 I915_WRITE(ICL_PORT_COMP_DW0(port), val);