1 // SPDX-License-Identifier: MIT
3 * Copyright © 2018 Intel Corporation
6 #include "intel_combo_phy.h"
9 #define for_each_combo_port(__dev_priv, __port) \
10 for ((__port) = PORT_A; (__port) < I915_MAX_PORTS; (__port)++) \
11 for_each_if(intel_port_is_combophy(__dev_priv, __port))
13 #define for_each_combo_port_reverse(__dev_priv, __port) \
14 for ((__port) = I915_MAX_PORTS; (__port)-- > PORT_A;) \
15 for_each_if(intel_port_is_combophy(__dev_priv, __port))
25 static const struct cnl_procmon {
27 } cnl_procmon_values[] = {
28 [PROCMON_0_85V_DOT_0] =
29 { .dw1 = 0x00000000, .dw9 = 0x62AB67BB, .dw10 = 0x51914F96, },
30 [PROCMON_0_95V_DOT_0] =
31 { .dw1 = 0x00000000, .dw9 = 0x86E172C7, .dw10 = 0x77CA5EAB, },
32 [PROCMON_0_95V_DOT_1] =
33 { .dw1 = 0x00000000, .dw9 = 0x93F87FE1, .dw10 = 0x8AE871C5, },
34 [PROCMON_1_05V_DOT_0] =
35 { .dw1 = 0x00000000, .dw9 = 0x98FA82DD, .dw10 = 0x89E46DC1, },
36 [PROCMON_1_05V_DOT_1] =
37 { .dw1 = 0x00440000, .dw9 = 0x9A00AB25, .dw10 = 0x8AE38FF1, },
41 * CNL has just one set of registers, while ICL has two sets: one for port A and
42 * the other for port B. The CNL registers are equivalent to the ICL port A
43 * registers, that's why we call the ICL macros even though the function has CNL
46 static const struct cnl_procmon *
47 cnl_get_procmon_ref_values(struct drm_i915_private *dev_priv, enum port port)
49 const struct cnl_procmon *procmon;
52 val = I915_READ(ICL_PORT_COMP_DW3(port));
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, port);
85 val = I915_READ(ICL_PORT_COMP_DW1(port));
86 val &= ~((0xff << 16) | 0xff);
88 I915_WRITE(ICL_PORT_COMP_DW1(port), val);
90 I915_WRITE(ICL_PORT_COMP_DW9(port), procmon->dw9);
91 I915_WRITE(ICL_PORT_COMP_DW10(port), procmon->dw10);
94 static bool check_phy_reg(struct drm_i915_private *dev_priv,
95 enum port port, i915_reg_t reg, u32 mask,
98 u32 val = I915_READ(reg);
100 if ((val & mask) != expected_val) {
101 DRM_DEBUG_DRIVER("Port %c combo PHY reg %08x state mismatch: "
102 "current %08x mask %08x expected %08x\n",
104 reg.reg, val, mask, expected_val);
111 static bool cnl_verify_procmon_ref_values(struct drm_i915_private *dev_priv,
114 const struct cnl_procmon *procmon;
117 procmon = cnl_get_procmon_ref_values(dev_priv, port);
119 ret = check_phy_reg(dev_priv, port, ICL_PORT_COMP_DW1(port),
120 (0xff << 16) | 0xff, procmon->dw1);
121 ret &= check_phy_reg(dev_priv, port, ICL_PORT_COMP_DW9(port),
123 ret &= check_phy_reg(dev_priv, port, ICL_PORT_COMP_DW10(port),
129 static bool cnl_combo_phy_enabled(struct drm_i915_private *dev_priv)
131 return !(I915_READ(CHICKEN_MISC_2) & CNL_COMP_PWR_DOWN) &&
132 (I915_READ(CNL_PORT_COMP_DW0) & COMP_INIT);
135 static bool cnl_combo_phy_verify_state(struct drm_i915_private *dev_priv)
137 enum port port = PORT_A;
140 if (!cnl_combo_phy_enabled(dev_priv))
143 ret = cnl_verify_procmon_ref_values(dev_priv, port);
145 ret &= check_phy_reg(dev_priv, port, CNL_PORT_CL1CM_DW5,
146 CL_POWER_DOWN_ENABLE, CL_POWER_DOWN_ENABLE);
151 static void cnl_combo_phys_init(struct drm_i915_private *dev_priv)
155 val = I915_READ(CHICKEN_MISC_2);
156 val &= ~CNL_COMP_PWR_DOWN;
157 I915_WRITE(CHICKEN_MISC_2, val);
159 /* Dummy PORT_A to get the correct CNL register from the ICL macro */
160 cnl_set_procmon_ref_values(dev_priv, PORT_A);
162 val = I915_READ(CNL_PORT_COMP_DW0);
164 I915_WRITE(CNL_PORT_COMP_DW0, val);
166 val = I915_READ(CNL_PORT_CL1CM_DW5);
167 val |= CL_POWER_DOWN_ENABLE;
168 I915_WRITE(CNL_PORT_CL1CM_DW5, val);
171 static void cnl_combo_phys_uninit(struct drm_i915_private *dev_priv)
175 if (!cnl_combo_phy_verify_state(dev_priv))
176 DRM_WARN("Combo PHY HW state changed unexpectedly.\n");
178 val = I915_READ(CHICKEN_MISC_2);
179 val |= CNL_COMP_PWR_DOWN;
180 I915_WRITE(CHICKEN_MISC_2, val);
183 static bool icl_combo_phy_enabled(struct drm_i915_private *dev_priv,
186 return !(I915_READ(ICL_PHY_MISC(port)) &
187 ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN) &&
188 (I915_READ(ICL_PORT_COMP_DW0(port)) & COMP_INIT);
191 static bool icl_combo_phy_verify_state(struct drm_i915_private *dev_priv,
196 if (!icl_combo_phy_enabled(dev_priv, port))
199 ret = cnl_verify_procmon_ref_values(dev_priv, port);
202 ret &= check_phy_reg(dev_priv, port, ICL_PORT_COMP_DW8(port),
205 ret &= check_phy_reg(dev_priv, port, ICL_PORT_CL_DW5(port),
206 CL_POWER_DOWN_ENABLE, CL_POWER_DOWN_ENABLE);
211 void intel_combo_phy_power_up_lanes(struct drm_i915_private *dev_priv,
212 enum port port, bool is_dsi,
213 int lane_count, bool lane_reversal)
219 WARN_ON(lane_reversal);
221 switch (lane_count) {
223 lane_mask = PWR_DOWN_LN_3_1_0;
226 lane_mask = PWR_DOWN_LN_3_1;
229 lane_mask = PWR_DOWN_LN_3;
232 MISSING_CASE(lane_count);
235 lane_mask = PWR_UP_ALL_LANES;
239 switch (lane_count) {
241 lane_mask = lane_reversal ? PWR_DOWN_LN_2_1_0 :
245 lane_mask = lane_reversal ? PWR_DOWN_LN_1_0 :
249 MISSING_CASE(lane_count);
252 lane_mask = PWR_UP_ALL_LANES;
257 val = I915_READ(ICL_PORT_CL_DW10(port));
258 val &= ~PWR_DOWN_LN_MASK;
259 val |= lane_mask << PWR_DOWN_LN_SHIFT;
260 I915_WRITE(ICL_PORT_CL_DW10(port), val);
263 static void icl_combo_phys_init(struct drm_i915_private *dev_priv)
267 for_each_combo_port(dev_priv, port) {
270 if (icl_combo_phy_verify_state(dev_priv, port)) {
271 DRM_DEBUG_DRIVER("Port %c combo PHY already enabled, won't reprogram it.\n",
276 val = I915_READ(ICL_PHY_MISC(port));
277 val &= ~ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN;
278 I915_WRITE(ICL_PHY_MISC(port), val);
280 cnl_set_procmon_ref_values(dev_priv, port);
282 if (port == PORT_A) {
283 val = I915_READ(ICL_PORT_COMP_DW8(port));
285 I915_WRITE(ICL_PORT_COMP_DW8(port), val);
288 val = I915_READ(ICL_PORT_COMP_DW0(port));
290 I915_WRITE(ICL_PORT_COMP_DW0(port), val);
292 val = I915_READ(ICL_PORT_CL_DW5(port));
293 val |= CL_POWER_DOWN_ENABLE;
294 I915_WRITE(ICL_PORT_CL_DW5(port), val);
298 static void icl_combo_phys_uninit(struct drm_i915_private *dev_priv)
302 for_each_combo_port_reverse(dev_priv, port) {
305 if (port == PORT_A &&
306 !icl_combo_phy_verify_state(dev_priv, port))
307 DRM_WARN("Port %c combo PHY HW state changed unexpectedly\n",
310 val = I915_READ(ICL_PHY_MISC(port));
311 val |= ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN;
312 I915_WRITE(ICL_PHY_MISC(port), val);
314 val = I915_READ(ICL_PORT_COMP_DW0(port));
316 I915_WRITE(ICL_PORT_COMP_DW0(port), val);
320 void intel_combo_phy_init(struct drm_i915_private *i915)
322 if (INTEL_GEN(i915) >= 11)
323 icl_combo_phys_init(i915);
324 else if (IS_CANNONLAKE(i915))
325 cnl_combo_phys_init(i915);
328 void intel_combo_phy_uninit(struct drm_i915_private *i915)
330 if (INTEL_GEN(i915) >= 11)
331 icl_combo_phys_uninit(i915);
332 else if (IS_CANNONLAKE(i915))
333 cnl_combo_phys_uninit(i915);