]>
Commit | Line | Data |
---|---|---|
a4fc5ed6 KP |
1 | /* |
2 | * Copyright © 2008 Intel Corporation | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining a | |
5 | * copy of this software and associated documentation files (the "Software"), | |
6 | * to deal in the Software without restriction, including without limitation | |
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
8 | * and/or sell copies of the Software, and to permit persons to whom the | |
9 | * Software is furnished to do so, subject to the following conditions: | |
10 | * | |
11 | * The above copyright notice and this permission notice (including the next | |
12 | * paragraph) shall be included in all copies or substantial portions of the | |
13 | * Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
21 | * IN THE SOFTWARE. | |
22 | * | |
23 | * Authors: | |
24 | * Keith Packard <keithp@keithp.com> | |
25 | * | |
26 | */ | |
27 | ||
28 | #include <linux/i2c.h> | |
5a0e3ad6 | 29 | #include <linux/slab.h> |
2d1a8a48 | 30 | #include <linux/export.h> |
01527b31 CT |
31 | #include <linux/notifier.h> |
32 | #include <linux/reboot.h> | |
760285e7 | 33 | #include <drm/drmP.h> |
c6f95f27 | 34 | #include <drm/drm_atomic_helper.h> |
760285e7 DH |
35 | #include <drm/drm_crtc.h> |
36 | #include <drm/drm_crtc_helper.h> | |
37 | #include <drm/drm_edid.h> | |
a4fc5ed6 | 38 | #include "intel_drv.h" |
760285e7 | 39 | #include <drm/i915_drm.h> |
a4fc5ed6 | 40 | #include "i915_drv.h" |
a4fc5ed6 | 41 | |
a4fc5ed6 KP |
42 | #define DP_LINK_CHECK_TIMEOUT (10 * 1000) |
43 | ||
559be30c TP |
44 | /* Compliance test status bits */ |
45 | #define INTEL_DP_RESOLUTION_SHIFT_MASK 0 | |
46 | #define INTEL_DP_RESOLUTION_PREFERRED (1 << INTEL_DP_RESOLUTION_SHIFT_MASK) | |
47 | #define INTEL_DP_RESOLUTION_STANDARD (2 << INTEL_DP_RESOLUTION_SHIFT_MASK) | |
48 | #define INTEL_DP_RESOLUTION_FAILSAFE (3 << INTEL_DP_RESOLUTION_SHIFT_MASK) | |
49 | ||
9dd4ffdf | 50 | struct dp_link_dpll { |
840b32b7 | 51 | int clock; |
9dd4ffdf CML |
52 | struct dpll dpll; |
53 | }; | |
54 | ||
55 | static const struct dp_link_dpll gen4_dpll[] = { | |
840b32b7 | 56 | { 162000, |
9dd4ffdf | 57 | { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } }, |
840b32b7 | 58 | { 270000, |
9dd4ffdf CML |
59 | { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } } |
60 | }; | |
61 | ||
62 | static const struct dp_link_dpll pch_dpll[] = { | |
840b32b7 | 63 | { 162000, |
9dd4ffdf | 64 | { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } }, |
840b32b7 | 65 | { 270000, |
9dd4ffdf CML |
66 | { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } } |
67 | }; | |
68 | ||
65ce4bf5 | 69 | static const struct dp_link_dpll vlv_dpll[] = { |
840b32b7 | 70 | { 162000, |
58f6e632 | 71 | { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } }, |
840b32b7 | 72 | { 270000, |
65ce4bf5 CML |
73 | { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } } |
74 | }; | |
75 | ||
ef9348c8 CML |
76 | /* |
77 | * CHV supports eDP 1.4 that have more link rates. | |
78 | * Below only provides the fixed rate but exclude variable rate. | |
79 | */ | |
80 | static const struct dp_link_dpll chv_dpll[] = { | |
81 | /* | |
82 | * CHV requires to program fractional division for m2. | |
83 | * m2 is stored in fixed point format using formula below | |
84 | * (m2_int << 22) | m2_fraction | |
85 | */ | |
840b32b7 | 86 | { 162000, /* m2_int = 32, m2_fraction = 1677722 */ |
ef9348c8 | 87 | { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } }, |
840b32b7 | 88 | { 270000, /* m2_int = 27, m2_fraction = 0 */ |
ef9348c8 | 89 | { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }, |
840b32b7 | 90 | { 540000, /* m2_int = 27, m2_fraction = 0 */ |
ef9348c8 CML |
91 | { .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } } |
92 | }; | |
637a9c63 | 93 | |
64987fc5 SJ |
94 | static const int bxt_rates[] = { 162000, 216000, 243000, 270000, |
95 | 324000, 432000, 540000 }; | |
637a9c63 | 96 | static const int skl_rates[] = { 162000, 216000, 270000, |
f4896f15 VS |
97 | 324000, 432000, 540000 }; |
98 | static const int default_rates[] = { 162000, 270000, 540000 }; | |
ef9348c8 | 99 | |
cfcb0fc9 JB |
100 | /** |
101 | * is_edp - is the given port attached to an eDP panel (either CPU or PCH) | |
102 | * @intel_dp: DP struct | |
103 | * | |
104 | * If a CPU or PCH DP output is attached to an eDP panel, this function | |
105 | * will return true, and false otherwise. | |
106 | */ | |
107 | static bool is_edp(struct intel_dp *intel_dp) | |
108 | { | |
da63a9f2 PZ |
109 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
110 | ||
111 | return intel_dig_port->base.type == INTEL_OUTPUT_EDP; | |
cfcb0fc9 JB |
112 | } |
113 | ||
68b4d824 | 114 | static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp) |
cfcb0fc9 | 115 | { |
68b4d824 ID |
116 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
117 | ||
118 | return intel_dig_port->base.base.dev; | |
cfcb0fc9 JB |
119 | } |
120 | ||
df0e9248 CW |
121 | static struct intel_dp *intel_attached_dp(struct drm_connector *connector) |
122 | { | |
fa90ecef | 123 | return enc_to_intel_dp(&intel_attached_encoder(connector)->base); |
df0e9248 CW |
124 | } |
125 | ||
ea5b213a | 126 | static void intel_dp_link_down(struct intel_dp *intel_dp); |
1e0560e0 | 127 | static bool edp_panel_vdd_on(struct intel_dp *intel_dp); |
4be73780 | 128 | static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync); |
093e3f13 | 129 | static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp); |
a8c3344e VS |
130 | static void vlv_steal_power_sequencer(struct drm_device *dev, |
131 | enum pipe pipe); | |
a4fc5ed6 | 132 | |
e0fce78f VS |
133 | static unsigned int intel_dp_unused_lane_mask(int lane_count) |
134 | { | |
135 | return ~((1 << lane_count) - 1) & 0xf; | |
136 | } | |
137 | ||
ed4e9c1d VS |
138 | static int |
139 | intel_dp_max_link_bw(struct intel_dp *intel_dp) | |
a4fc5ed6 | 140 | { |
7183dc29 | 141 | int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE]; |
a4fc5ed6 KP |
142 | |
143 | switch (max_link_bw) { | |
144 | case DP_LINK_BW_1_62: | |
145 | case DP_LINK_BW_2_7: | |
1db10e28 | 146 | case DP_LINK_BW_5_4: |
d4eead50 | 147 | break; |
a4fc5ed6 | 148 | default: |
d4eead50 ID |
149 | WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n", |
150 | max_link_bw); | |
a4fc5ed6 KP |
151 | max_link_bw = DP_LINK_BW_1_62; |
152 | break; | |
153 | } | |
154 | return max_link_bw; | |
155 | } | |
156 | ||
eeb6324d PZ |
157 | static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp) |
158 | { | |
159 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); | |
eeb6324d PZ |
160 | u8 source_max, sink_max; |
161 | ||
ccb1a831 | 162 | source_max = intel_dig_port->max_lanes; |
eeb6324d PZ |
163 | sink_max = drm_dp_max_lane_count(intel_dp->dpcd); |
164 | ||
165 | return min(source_max, sink_max); | |
166 | } | |
167 | ||
cd9dde44 AJ |
168 | /* |
169 | * The units on the numbers in the next two are... bizarre. Examples will | |
170 | * make it clearer; this one parallels an example in the eDP spec. | |
171 | * | |
172 | * intel_dp_max_data_rate for one lane of 2.7GHz evaluates as: | |
173 | * | |
174 | * 270000 * 1 * 8 / 10 == 216000 | |
175 | * | |
176 | * The actual data capacity of that configuration is 2.16Gbit/s, so the | |
177 | * units are decakilobits. ->clock in a drm_display_mode is in kilohertz - | |
178 | * or equivalently, kilopixels per second - so for 1680x1050R it'd be | |
179 | * 119000. At 18bpp that's 2142000 kilobits per second. | |
180 | * | |
181 | * Thus the strange-looking division by 10 in intel_dp_link_required, to | |
182 | * get the result in decakilobits instead of kilobits. | |
183 | */ | |
184 | ||
a4fc5ed6 | 185 | static int |
c898261c | 186 | intel_dp_link_required(int pixel_clock, int bpp) |
a4fc5ed6 | 187 | { |
cd9dde44 | 188 | return (pixel_clock * bpp + 9) / 10; |
a4fc5ed6 KP |
189 | } |
190 | ||
fe27d53e DA |
191 | static int |
192 | intel_dp_max_data_rate(int max_link_clock, int max_lanes) | |
193 | { | |
194 | return (max_link_clock * max_lanes * 8) / 10; | |
195 | } | |
196 | ||
c19de8eb | 197 | static enum drm_mode_status |
a4fc5ed6 KP |
198 | intel_dp_mode_valid(struct drm_connector *connector, |
199 | struct drm_display_mode *mode) | |
200 | { | |
df0e9248 | 201 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
dd06f90e JN |
202 | struct intel_connector *intel_connector = to_intel_connector(connector); |
203 | struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode; | |
36008365 DV |
204 | int target_clock = mode->clock; |
205 | int max_rate, mode_rate, max_lanes, max_link_clock; | |
799487f5 | 206 | int max_dotclk = to_i915(connector->dev)->max_dotclk_freq; |
a4fc5ed6 | 207 | |
dd06f90e JN |
208 | if (is_edp(intel_dp) && fixed_mode) { |
209 | if (mode->hdisplay > fixed_mode->hdisplay) | |
7de56f43 ZY |
210 | return MODE_PANEL; |
211 | ||
dd06f90e | 212 | if (mode->vdisplay > fixed_mode->vdisplay) |
7de56f43 | 213 | return MODE_PANEL; |
03afc4a2 DV |
214 | |
215 | target_clock = fixed_mode->clock; | |
7de56f43 ZY |
216 | } |
217 | ||
50fec21a | 218 | max_link_clock = intel_dp_max_link_rate(intel_dp); |
eeb6324d | 219 | max_lanes = intel_dp_max_lane_count(intel_dp); |
36008365 DV |
220 | |
221 | max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes); | |
222 | mode_rate = intel_dp_link_required(target_clock, 18); | |
223 | ||
799487f5 | 224 | if (mode_rate > max_rate || target_clock > max_dotclk) |
c4867936 | 225 | return MODE_CLOCK_HIGH; |
a4fc5ed6 KP |
226 | |
227 | if (mode->clock < 10000) | |
228 | return MODE_CLOCK_LOW; | |
229 | ||
0af78a2b DV |
230 | if (mode->flags & DRM_MODE_FLAG_DBLCLK) |
231 | return MODE_H_ILLEGAL; | |
232 | ||
a4fc5ed6 KP |
233 | return MODE_OK; |
234 | } | |
235 | ||
a4f1289e | 236 | uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes) |
a4fc5ed6 KP |
237 | { |
238 | int i; | |
239 | uint32_t v = 0; | |
240 | ||
241 | if (src_bytes > 4) | |
242 | src_bytes = 4; | |
243 | for (i = 0; i < src_bytes; i++) | |
244 | v |= ((uint32_t) src[i]) << ((3-i) * 8); | |
245 | return v; | |
246 | } | |
247 | ||
c2af70e2 | 248 | static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes) |
a4fc5ed6 KP |
249 | { |
250 | int i; | |
251 | if (dst_bytes > 4) | |
252 | dst_bytes = 4; | |
253 | for (i = 0; i < dst_bytes; i++) | |
254 | dst[i] = src >> ((3-i) * 8); | |
255 | } | |
256 | ||
bf13e81b JN |
257 | static void |
258 | intel_dp_init_panel_power_sequencer(struct drm_device *dev, | |
36b5f425 | 259 | struct intel_dp *intel_dp); |
bf13e81b JN |
260 | static void |
261 | intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev, | |
36b5f425 | 262 | struct intel_dp *intel_dp); |
bf13e81b | 263 | |
773538e8 VS |
264 | static void pps_lock(struct intel_dp *intel_dp) |
265 | { | |
266 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); | |
267 | struct intel_encoder *encoder = &intel_dig_port->base; | |
268 | struct drm_device *dev = encoder->base.dev; | |
269 | struct drm_i915_private *dev_priv = dev->dev_private; | |
270 | enum intel_display_power_domain power_domain; | |
271 | ||
272 | /* | |
273 | * See vlv_power_sequencer_reset() why we need | |
274 | * a power domain reference here. | |
275 | */ | |
25f78f58 | 276 | power_domain = intel_display_port_aux_power_domain(encoder); |
773538e8 VS |
277 | intel_display_power_get(dev_priv, power_domain); |
278 | ||
279 | mutex_lock(&dev_priv->pps_mutex); | |
280 | } | |
281 | ||
282 | static void pps_unlock(struct intel_dp *intel_dp) | |
283 | { | |
284 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); | |
285 | struct intel_encoder *encoder = &intel_dig_port->base; | |
286 | struct drm_device *dev = encoder->base.dev; | |
287 | struct drm_i915_private *dev_priv = dev->dev_private; | |
288 | enum intel_display_power_domain power_domain; | |
289 | ||
290 | mutex_unlock(&dev_priv->pps_mutex); | |
291 | ||
25f78f58 | 292 | power_domain = intel_display_port_aux_power_domain(encoder); |
773538e8 VS |
293 | intel_display_power_put(dev_priv, power_domain); |
294 | } | |
295 | ||
961a0db0 VS |
296 | static void |
297 | vlv_power_sequencer_kick(struct intel_dp *intel_dp) | |
298 | { | |
299 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); | |
300 | struct drm_device *dev = intel_dig_port->base.base.dev; | |
301 | struct drm_i915_private *dev_priv = dev->dev_private; | |
302 | enum pipe pipe = intel_dp->pps_pipe; | |
0047eedc VS |
303 | bool pll_enabled, release_cl_override = false; |
304 | enum dpio_phy phy = DPIO_PHY(pipe); | |
305 | enum dpio_channel ch = vlv_pipe_to_channel(pipe); | |
961a0db0 VS |
306 | uint32_t DP; |
307 | ||
308 | if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN, | |
309 | "skipping pipe %c power seqeuncer kick due to port %c being active\n", | |
310 | pipe_name(pipe), port_name(intel_dig_port->port))) | |
311 | return; | |
312 | ||
313 | DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n", | |
314 | pipe_name(pipe), port_name(intel_dig_port->port)); | |
315 | ||
316 | /* Preserve the BIOS-computed detected bit. This is | |
317 | * supposed to be read-only. | |
318 | */ | |
319 | DP = I915_READ(intel_dp->output_reg) & DP_DETECTED; | |
320 | DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0; | |
321 | DP |= DP_PORT_WIDTH(1); | |
322 | DP |= DP_LINK_TRAIN_PAT_1; | |
323 | ||
324 | if (IS_CHERRYVIEW(dev)) | |
325 | DP |= DP_PIPE_SELECT_CHV(pipe); | |
326 | else if (pipe == PIPE_B) | |
327 | DP |= DP_PIPEB_SELECT; | |
328 | ||
d288f65f VS |
329 | pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE; |
330 | ||
331 | /* | |
332 | * The DPLL for the pipe must be enabled for this to work. | |
333 | * So enable temporarily it if it's not already enabled. | |
334 | */ | |
0047eedc VS |
335 | if (!pll_enabled) { |
336 | release_cl_override = IS_CHERRYVIEW(dev) && | |
337 | !chv_phy_powergate_ch(dev_priv, phy, ch, true); | |
338 | ||
3f36b937 TU |
339 | if (vlv_force_pll_on(dev, pipe, IS_CHERRYVIEW(dev) ? |
340 | &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) { | |
341 | DRM_ERROR("Failed to force on pll for pipe %c!\n", | |
342 | pipe_name(pipe)); | |
343 | return; | |
344 | } | |
0047eedc | 345 | } |
d288f65f | 346 | |
961a0db0 VS |
347 | /* |
348 | * Similar magic as in intel_dp_enable_port(). | |
349 | * We _must_ do this port enable + disable trick | |
350 | * to make this power seqeuencer lock onto the port. | |
351 | * Otherwise even VDD force bit won't work. | |
352 | */ | |
353 | I915_WRITE(intel_dp->output_reg, DP); | |
354 | POSTING_READ(intel_dp->output_reg); | |
355 | ||
356 | I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN); | |
357 | POSTING_READ(intel_dp->output_reg); | |
358 | ||
359 | I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN); | |
360 | POSTING_READ(intel_dp->output_reg); | |
d288f65f | 361 | |
0047eedc | 362 | if (!pll_enabled) { |
d288f65f | 363 | vlv_force_pll_off(dev, pipe); |
0047eedc VS |
364 | |
365 | if (release_cl_override) | |
366 | chv_phy_powergate_ch(dev_priv, phy, ch, false); | |
367 | } | |
961a0db0 VS |
368 | } |
369 | ||
bf13e81b JN |
370 | static enum pipe |
371 | vlv_power_sequencer_pipe(struct intel_dp *intel_dp) | |
372 | { | |
373 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); | |
bf13e81b JN |
374 | struct drm_device *dev = intel_dig_port->base.base.dev; |
375 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a4a5d2f8 VS |
376 | struct intel_encoder *encoder; |
377 | unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B); | |
a8c3344e | 378 | enum pipe pipe; |
bf13e81b | 379 | |
e39b999a | 380 | lockdep_assert_held(&dev_priv->pps_mutex); |
bf13e81b | 381 | |
a8c3344e VS |
382 | /* We should never land here with regular DP ports */ |
383 | WARN_ON(!is_edp(intel_dp)); | |
384 | ||
a4a5d2f8 VS |
385 | if (intel_dp->pps_pipe != INVALID_PIPE) |
386 | return intel_dp->pps_pipe; | |
387 | ||
388 | /* | |
389 | * We don't have power sequencer currently. | |
390 | * Pick one that's not used by other ports. | |
391 | */ | |
19c8054c | 392 | for_each_intel_encoder(dev, encoder) { |
a4a5d2f8 VS |
393 | struct intel_dp *tmp; |
394 | ||
395 | if (encoder->type != INTEL_OUTPUT_EDP) | |
396 | continue; | |
397 | ||
398 | tmp = enc_to_intel_dp(&encoder->base); | |
399 | ||
400 | if (tmp->pps_pipe != INVALID_PIPE) | |
401 | pipes &= ~(1 << tmp->pps_pipe); | |
402 | } | |
403 | ||
404 | /* | |
405 | * Didn't find one. This should not happen since there | |
406 | * are two power sequencers and up to two eDP ports. | |
407 | */ | |
408 | if (WARN_ON(pipes == 0)) | |
a8c3344e VS |
409 | pipe = PIPE_A; |
410 | else | |
411 | pipe = ffs(pipes) - 1; | |
a4a5d2f8 | 412 | |
a8c3344e VS |
413 | vlv_steal_power_sequencer(dev, pipe); |
414 | intel_dp->pps_pipe = pipe; | |
a4a5d2f8 VS |
415 | |
416 | DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n", | |
417 | pipe_name(intel_dp->pps_pipe), | |
418 | port_name(intel_dig_port->port)); | |
419 | ||
420 | /* init power sequencer on this pipe and port */ | |
36b5f425 VS |
421 | intel_dp_init_panel_power_sequencer(dev, intel_dp); |
422 | intel_dp_init_panel_power_sequencer_registers(dev, intel_dp); | |
a4a5d2f8 | 423 | |
961a0db0 VS |
424 | /* |
425 | * Even vdd force doesn't work until we've made | |
426 | * the power sequencer lock in on the port. | |
427 | */ | |
428 | vlv_power_sequencer_kick(intel_dp); | |
a4a5d2f8 VS |
429 | |
430 | return intel_dp->pps_pipe; | |
431 | } | |
432 | ||
6491ab27 VS |
433 | typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv, |
434 | enum pipe pipe); | |
435 | ||
436 | static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv, | |
437 | enum pipe pipe) | |
438 | { | |
439 | return I915_READ(VLV_PIPE_PP_STATUS(pipe)) & PP_ON; | |
440 | } | |
441 | ||
442 | static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv, | |
443 | enum pipe pipe) | |
444 | { | |
445 | return I915_READ(VLV_PIPE_PP_CONTROL(pipe)) & EDP_FORCE_VDD; | |
446 | } | |
447 | ||
448 | static bool vlv_pipe_any(struct drm_i915_private *dev_priv, | |
449 | enum pipe pipe) | |
450 | { | |
451 | return true; | |
452 | } | |
bf13e81b | 453 | |
a4a5d2f8 | 454 | static enum pipe |
6491ab27 VS |
455 | vlv_initial_pps_pipe(struct drm_i915_private *dev_priv, |
456 | enum port port, | |
457 | vlv_pipe_check pipe_check) | |
a4a5d2f8 VS |
458 | { |
459 | enum pipe pipe; | |
bf13e81b | 460 | |
bf13e81b JN |
461 | for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) { |
462 | u32 port_sel = I915_READ(VLV_PIPE_PP_ON_DELAYS(pipe)) & | |
463 | PANEL_PORT_SELECT_MASK; | |
a4a5d2f8 VS |
464 | |
465 | if (port_sel != PANEL_PORT_SELECT_VLV(port)) | |
466 | continue; | |
467 | ||
6491ab27 VS |
468 | if (!pipe_check(dev_priv, pipe)) |
469 | continue; | |
470 | ||
a4a5d2f8 | 471 | return pipe; |
bf13e81b JN |
472 | } |
473 | ||
a4a5d2f8 VS |
474 | return INVALID_PIPE; |
475 | } | |
476 | ||
477 | static void | |
478 | vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp) | |
479 | { | |
480 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); | |
481 | struct drm_device *dev = intel_dig_port->base.base.dev; | |
482 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a4a5d2f8 VS |
483 | enum port port = intel_dig_port->port; |
484 | ||
485 | lockdep_assert_held(&dev_priv->pps_mutex); | |
486 | ||
487 | /* try to find a pipe with this port selected */ | |
6491ab27 VS |
488 | /* first pick one where the panel is on */ |
489 | intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port, | |
490 | vlv_pipe_has_pp_on); | |
491 | /* didn't find one? pick one where vdd is on */ | |
492 | if (intel_dp->pps_pipe == INVALID_PIPE) | |
493 | intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port, | |
494 | vlv_pipe_has_vdd_on); | |
495 | /* didn't find one? pick one with just the correct port */ | |
496 | if (intel_dp->pps_pipe == INVALID_PIPE) | |
497 | intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port, | |
498 | vlv_pipe_any); | |
a4a5d2f8 VS |
499 | |
500 | /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */ | |
501 | if (intel_dp->pps_pipe == INVALID_PIPE) { | |
502 | DRM_DEBUG_KMS("no initial power sequencer for port %c\n", | |
503 | port_name(port)); | |
504 | return; | |
bf13e81b JN |
505 | } |
506 | ||
a4a5d2f8 VS |
507 | DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n", |
508 | port_name(port), pipe_name(intel_dp->pps_pipe)); | |
509 | ||
36b5f425 VS |
510 | intel_dp_init_panel_power_sequencer(dev, intel_dp); |
511 | intel_dp_init_panel_power_sequencer_registers(dev, intel_dp); | |
bf13e81b JN |
512 | } |
513 | ||
773538e8 VS |
514 | void vlv_power_sequencer_reset(struct drm_i915_private *dev_priv) |
515 | { | |
516 | struct drm_device *dev = dev_priv->dev; | |
517 | struct intel_encoder *encoder; | |
518 | ||
666a4537 | 519 | if (WARN_ON(!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev))) |
773538e8 VS |
520 | return; |
521 | ||
522 | /* | |
523 | * We can't grab pps_mutex here due to deadlock with power_domain | |
524 | * mutex when power_domain functions are called while holding pps_mutex. | |
525 | * That also means that in order to use pps_pipe the code needs to | |
526 | * hold both a power domain reference and pps_mutex, and the power domain | |
527 | * reference get/put must be done while _not_ holding pps_mutex. | |
528 | * pps_{lock,unlock}() do these steps in the correct order, so one | |
529 | * should use them always. | |
530 | */ | |
531 | ||
19c8054c | 532 | for_each_intel_encoder(dev, encoder) { |
773538e8 VS |
533 | struct intel_dp *intel_dp; |
534 | ||
535 | if (encoder->type != INTEL_OUTPUT_EDP) | |
536 | continue; | |
537 | ||
538 | intel_dp = enc_to_intel_dp(&encoder->base); | |
539 | intel_dp->pps_pipe = INVALID_PIPE; | |
540 | } | |
bf13e81b JN |
541 | } |
542 | ||
f0f59a00 VS |
543 | static i915_reg_t |
544 | _pp_ctrl_reg(struct intel_dp *intel_dp) | |
bf13e81b JN |
545 | { |
546 | struct drm_device *dev = intel_dp_to_dev(intel_dp); | |
547 | ||
b0a08bec VK |
548 | if (IS_BROXTON(dev)) |
549 | return BXT_PP_CONTROL(0); | |
550 | else if (HAS_PCH_SPLIT(dev)) | |
bf13e81b JN |
551 | return PCH_PP_CONTROL; |
552 | else | |
553 | return VLV_PIPE_PP_CONTROL(vlv_power_sequencer_pipe(intel_dp)); | |
554 | } | |
555 | ||
f0f59a00 VS |
556 | static i915_reg_t |
557 | _pp_stat_reg(struct intel_dp *intel_dp) | |
bf13e81b JN |
558 | { |
559 | struct drm_device *dev = intel_dp_to_dev(intel_dp); | |
560 | ||
b0a08bec VK |
561 | if (IS_BROXTON(dev)) |
562 | return BXT_PP_STATUS(0); | |
563 | else if (HAS_PCH_SPLIT(dev)) | |
bf13e81b JN |
564 | return PCH_PP_STATUS; |
565 | else | |
566 | return VLV_PIPE_PP_STATUS(vlv_power_sequencer_pipe(intel_dp)); | |
567 | } | |
568 | ||
01527b31 CT |
569 | /* Reboot notifier handler to shutdown panel power to guarantee T12 timing |
570 | This function only applicable when panel PM state is not to be tracked */ | |
571 | static int edp_notify_handler(struct notifier_block *this, unsigned long code, | |
572 | void *unused) | |
573 | { | |
574 | struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp), | |
575 | edp_notifier); | |
576 | struct drm_device *dev = intel_dp_to_dev(intel_dp); | |
577 | struct drm_i915_private *dev_priv = dev->dev_private; | |
01527b31 CT |
578 | |
579 | if (!is_edp(intel_dp) || code != SYS_RESTART) | |
580 | return 0; | |
581 | ||
773538e8 | 582 | pps_lock(intel_dp); |
e39b999a | 583 | |
666a4537 | 584 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
e39b999a | 585 | enum pipe pipe = vlv_power_sequencer_pipe(intel_dp); |
f0f59a00 | 586 | i915_reg_t pp_ctrl_reg, pp_div_reg; |
649636ef | 587 | u32 pp_div; |
e39b999a | 588 | |
01527b31 CT |
589 | pp_ctrl_reg = VLV_PIPE_PP_CONTROL(pipe); |
590 | pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe); | |
591 | pp_div = I915_READ(pp_div_reg); | |
592 | pp_div &= PP_REFERENCE_DIVIDER_MASK; | |
593 | ||
594 | /* 0x1F write to PP_DIV_REG sets max cycle delay */ | |
595 | I915_WRITE(pp_div_reg, pp_div | 0x1F); | |
596 | I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF); | |
597 | msleep(intel_dp->panel_power_cycle_delay); | |
598 | } | |
599 | ||
773538e8 | 600 | pps_unlock(intel_dp); |
e39b999a | 601 | |
01527b31 CT |
602 | return 0; |
603 | } | |
604 | ||
4be73780 | 605 | static bool edp_have_panel_power(struct intel_dp *intel_dp) |
ebf33b18 | 606 | { |
30add22d | 607 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
ebf33b18 KP |
608 | struct drm_i915_private *dev_priv = dev->dev_private; |
609 | ||
e39b999a VS |
610 | lockdep_assert_held(&dev_priv->pps_mutex); |
611 | ||
666a4537 | 612 | if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) && |
9a42356b VS |
613 | intel_dp->pps_pipe == INVALID_PIPE) |
614 | return false; | |
615 | ||
bf13e81b | 616 | return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0; |
ebf33b18 KP |
617 | } |
618 | ||
4be73780 | 619 | static bool edp_have_panel_vdd(struct intel_dp *intel_dp) |
ebf33b18 | 620 | { |
30add22d | 621 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
ebf33b18 KP |
622 | struct drm_i915_private *dev_priv = dev->dev_private; |
623 | ||
e39b999a VS |
624 | lockdep_assert_held(&dev_priv->pps_mutex); |
625 | ||
666a4537 | 626 | if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) && |
9a42356b VS |
627 | intel_dp->pps_pipe == INVALID_PIPE) |
628 | return false; | |
629 | ||
773538e8 | 630 | return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD; |
ebf33b18 KP |
631 | } |
632 | ||
9b984dae KP |
633 | static void |
634 | intel_dp_check_edp(struct intel_dp *intel_dp) | |
635 | { | |
30add22d | 636 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
9b984dae | 637 | struct drm_i915_private *dev_priv = dev->dev_private; |
ebf33b18 | 638 | |
9b984dae KP |
639 | if (!is_edp(intel_dp)) |
640 | return; | |
453c5420 | 641 | |
4be73780 | 642 | if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) { |
9b984dae KP |
643 | WARN(1, "eDP powered off while attempting aux channel communication.\n"); |
644 | DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n", | |
bf13e81b JN |
645 | I915_READ(_pp_stat_reg(intel_dp)), |
646 | I915_READ(_pp_ctrl_reg(intel_dp))); | |
9b984dae KP |
647 | } |
648 | } | |
649 | ||
9ee32fea DV |
650 | static uint32_t |
651 | intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq) | |
652 | { | |
653 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); | |
654 | struct drm_device *dev = intel_dig_port->base.base.dev; | |
655 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f0f59a00 | 656 | i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg; |
9ee32fea DV |
657 | uint32_t status; |
658 | bool done; | |
659 | ||
ef04f00d | 660 | #define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0) |
9ee32fea | 661 | if (has_aux_irq) |
b18ac466 | 662 | done = wait_event_timeout(dev_priv->gmbus_wait_queue, C, |
3598706b | 663 | msecs_to_jiffies_timeout(10)); |
9ee32fea DV |
664 | else |
665 | done = wait_for_atomic(C, 10) == 0; | |
666 | if (!done) | |
667 | DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n", | |
668 | has_aux_irq); | |
669 | #undef C | |
670 | ||
671 | return status; | |
672 | } | |
673 | ||
ec5b01dd | 674 | static uint32_t i9xx_get_aux_clock_divider(struct intel_dp *intel_dp, int index) |
a4fc5ed6 | 675 | { |
174edf1f | 676 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
e7dc33f3 | 677 | struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev); |
9ee32fea | 678 | |
ec5b01dd DL |
679 | /* |
680 | * The clock divider is based off the hrawclk, and would like to run at | |
681 | * 2MHz. So, take the hrawclk value and divide by 2 and use that | |
a4fc5ed6 | 682 | */ |
e7dc33f3 | 683 | return index ? 0 : DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000); |
ec5b01dd DL |
684 | } |
685 | ||
686 | static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index) | |
687 | { | |
688 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); | |
689 | struct drm_device *dev = intel_dig_port->base.base.dev; | |
469d4b2a | 690 | struct drm_i915_private *dev_priv = dev->dev_private; |
ec5b01dd DL |
691 | |
692 | if (index) | |
693 | return 0; | |
694 | ||
e7dc33f3 | 695 | if (intel_dig_port->port == PORT_A) |
fce18c4c | 696 | return DIV_ROUND_CLOSEST(dev_priv->cdclk_freq, 2000); |
e7dc33f3 VS |
697 | else |
698 | return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000); | |
ec5b01dd DL |
699 | } |
700 | ||
701 | static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index) | |
702 | { | |
703 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); | |
704 | struct drm_device *dev = intel_dig_port->base.base.dev; | |
705 | struct drm_i915_private *dev_priv = dev->dev_private; | |
706 | ||
707 | if (intel_dig_port->port == PORT_A) { | |
708 | if (index) | |
709 | return 0; | |
05024da3 | 710 | return DIV_ROUND_CLOSEST(dev_priv->cdclk_freq, 2000); |
56f5f700 | 711 | } else if (HAS_PCH_LPT_H(dev_priv)) { |
2c55c336 | 712 | /* Workaround for non-ULT HSW */ |
bc86625a CW |
713 | switch (index) { |
714 | case 0: return 63; | |
715 | case 1: return 72; | |
716 | default: return 0; | |
717 | } | |
ec5b01dd | 718 | } else { |
e7dc33f3 | 719 | return index ? 0 : DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000); |
2c55c336 | 720 | } |
b84a1cf8 RV |
721 | } |
722 | ||
ec5b01dd DL |
723 | static uint32_t vlv_get_aux_clock_divider(struct intel_dp *intel_dp, int index) |
724 | { | |
725 | return index ? 0 : 100; | |
726 | } | |
727 | ||
b6b5e383 DL |
728 | static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index) |
729 | { | |
730 | /* | |
731 | * SKL doesn't need us to program the AUX clock divider (Hardware will | |
732 | * derive the clock from CDCLK automatically). We still implement the | |
733 | * get_aux_clock_divider vfunc to plug-in into the existing code. | |
734 | */ | |
735 | return index ? 0 : 1; | |
736 | } | |
737 | ||
5ed12a19 DL |
738 | static uint32_t i9xx_get_aux_send_ctl(struct intel_dp *intel_dp, |
739 | bool has_aux_irq, | |
740 | int send_bytes, | |
741 | uint32_t aux_clock_divider) | |
742 | { | |
743 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); | |
744 | struct drm_device *dev = intel_dig_port->base.base.dev; | |
745 | uint32_t precharge, timeout; | |
746 | ||
747 | if (IS_GEN6(dev)) | |
748 | precharge = 3; | |
749 | else | |
750 | precharge = 5; | |
751 | ||
f3c6a3a7 | 752 | if (IS_BROADWELL(dev) && intel_dig_port->port == PORT_A) |
5ed12a19 DL |
753 | timeout = DP_AUX_CH_CTL_TIME_OUT_600us; |
754 | else | |
755 | timeout = DP_AUX_CH_CTL_TIME_OUT_400us; | |
756 | ||
757 | return DP_AUX_CH_CTL_SEND_BUSY | | |
788d4433 | 758 | DP_AUX_CH_CTL_DONE | |
5ed12a19 | 759 | (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) | |
788d4433 | 760 | DP_AUX_CH_CTL_TIME_OUT_ERROR | |
5ed12a19 | 761 | timeout | |
788d4433 | 762 | DP_AUX_CH_CTL_RECEIVE_ERROR | |
5ed12a19 DL |
763 | (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) | |
764 | (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) | | |
788d4433 | 765 | (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT); |
5ed12a19 DL |
766 | } |
767 | ||
b9ca5fad DL |
768 | static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp, |
769 | bool has_aux_irq, | |
770 | int send_bytes, | |
771 | uint32_t unused) | |
772 | { | |
773 | return DP_AUX_CH_CTL_SEND_BUSY | | |
774 | DP_AUX_CH_CTL_DONE | | |
775 | (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) | | |
776 | DP_AUX_CH_CTL_TIME_OUT_ERROR | | |
777 | DP_AUX_CH_CTL_TIME_OUT_1600us | | |
778 | DP_AUX_CH_CTL_RECEIVE_ERROR | | |
779 | (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) | | |
780 | DP_AUX_CH_CTL_SYNC_PULSE_SKL(32); | |
781 | } | |
782 | ||
b84a1cf8 RV |
783 | static int |
784 | intel_dp_aux_ch(struct intel_dp *intel_dp, | |
bd9f74a5 | 785 | const uint8_t *send, int send_bytes, |
b84a1cf8 RV |
786 | uint8_t *recv, int recv_size) |
787 | { | |
788 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); | |
789 | struct drm_device *dev = intel_dig_port->base.base.dev; | |
790 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f0f59a00 | 791 | i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg; |
bc86625a | 792 | uint32_t aux_clock_divider; |
b84a1cf8 RV |
793 | int i, ret, recv_bytes; |
794 | uint32_t status; | |
5ed12a19 | 795 | int try, clock = 0; |
4e6b788c | 796 | bool has_aux_irq = HAS_AUX_IRQ(dev); |
884f19e9 JN |
797 | bool vdd; |
798 | ||
773538e8 | 799 | pps_lock(intel_dp); |
e39b999a | 800 | |
72c3500a VS |
801 | /* |
802 | * We will be called with VDD already enabled for dpcd/edid/oui reads. | |
803 | * In such cases we want to leave VDD enabled and it's up to upper layers | |
804 | * to turn it off. But for eg. i2c-dev access we need to turn it on/off | |
805 | * ourselves. | |
806 | */ | |
1e0560e0 | 807 | vdd = edp_panel_vdd_on(intel_dp); |
b84a1cf8 RV |
808 | |
809 | /* dp aux is extremely sensitive to irq latency, hence request the | |
810 | * lowest possible wakeup latency and so prevent the cpu from going into | |
811 | * deep sleep states. | |
812 | */ | |
813 | pm_qos_update_request(&dev_priv->pm_qos, 0); | |
814 | ||
815 | intel_dp_check_edp(intel_dp); | |
5eb08b69 | 816 | |
11bee43e JB |
817 | /* Try to wait for any previous AUX channel activity */ |
818 | for (try = 0; try < 3; try++) { | |
ef04f00d | 819 | status = I915_READ_NOTRACE(ch_ctl); |
11bee43e JB |
820 | if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0) |
821 | break; | |
822 | msleep(1); | |
823 | } | |
824 | ||
825 | if (try == 3) { | |
02196c77 MK |
826 | static u32 last_status = -1; |
827 | const u32 status = I915_READ(ch_ctl); | |
828 | ||
829 | if (status != last_status) { | |
830 | WARN(1, "dp_aux_ch not started status 0x%08x\n", | |
831 | status); | |
832 | last_status = status; | |
833 | } | |
834 | ||
9ee32fea DV |
835 | ret = -EBUSY; |
836 | goto out; | |
4f7f7b7e CW |
837 | } |
838 | ||
46a5ae9f PZ |
839 | /* Only 5 data registers! */ |
840 | if (WARN_ON(send_bytes > 20 || recv_size > 20)) { | |
841 | ret = -E2BIG; | |
842 | goto out; | |
843 | } | |
844 | ||
ec5b01dd | 845 | while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) { |
153b1100 DL |
846 | u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp, |
847 | has_aux_irq, | |
848 | send_bytes, | |
849 | aux_clock_divider); | |
5ed12a19 | 850 | |
bc86625a CW |
851 | /* Must try at least 3 times according to DP spec */ |
852 | for (try = 0; try < 5; try++) { | |
853 | /* Load the send data into the aux channel data registers */ | |
854 | for (i = 0; i < send_bytes; i += 4) | |
330e20ec | 855 | I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2], |
a4f1289e RV |
856 | intel_dp_pack_aux(send + i, |
857 | send_bytes - i)); | |
bc86625a CW |
858 | |
859 | /* Send the command and wait for it to complete */ | |
5ed12a19 | 860 | I915_WRITE(ch_ctl, send_ctl); |
bc86625a CW |
861 | |
862 | status = intel_dp_aux_wait_done(intel_dp, has_aux_irq); | |
863 | ||
864 | /* Clear done status and any errors */ | |
865 | I915_WRITE(ch_ctl, | |
866 | status | | |
867 | DP_AUX_CH_CTL_DONE | | |
868 | DP_AUX_CH_CTL_TIME_OUT_ERROR | | |
869 | DP_AUX_CH_CTL_RECEIVE_ERROR); | |
870 | ||
74ebf294 | 871 | if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) |
bc86625a | 872 | continue; |
74ebf294 TP |
873 | |
874 | /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2 | |
875 | * 400us delay required for errors and timeouts | |
876 | * Timeout errors from the HW already meet this | |
877 | * requirement so skip to next iteration | |
878 | */ | |
879 | if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) { | |
880 | usleep_range(400, 500); | |
bc86625a | 881 | continue; |
74ebf294 | 882 | } |
bc86625a | 883 | if (status & DP_AUX_CH_CTL_DONE) |
e058c945 | 884 | goto done; |
bc86625a | 885 | } |
a4fc5ed6 KP |
886 | } |
887 | ||
a4fc5ed6 | 888 | if ((status & DP_AUX_CH_CTL_DONE) == 0) { |
1ae8c0a5 | 889 | DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status); |
9ee32fea DV |
890 | ret = -EBUSY; |
891 | goto out; | |
a4fc5ed6 KP |
892 | } |
893 | ||
e058c945 | 894 | done: |
a4fc5ed6 KP |
895 | /* Check for timeout or receive error. |
896 | * Timeouts occur when the sink is not connected | |
897 | */ | |
a5b3da54 | 898 | if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) { |
1ae8c0a5 | 899 | DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status); |
9ee32fea DV |
900 | ret = -EIO; |
901 | goto out; | |
a5b3da54 | 902 | } |
1ae8c0a5 KP |
903 | |
904 | /* Timeouts occur when the device isn't connected, so they're | |
905 | * "normal" -- don't fill the kernel log with these */ | |
a5b3da54 | 906 | if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) { |
28c97730 | 907 | DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status); |
9ee32fea DV |
908 | ret = -ETIMEDOUT; |
909 | goto out; | |
a4fc5ed6 KP |
910 | } |
911 | ||
912 | /* Unload any bytes sent back from the other side */ | |
913 | recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >> | |
914 | DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT); | |
14e01889 RV |
915 | |
916 | /* | |
917 | * By BSpec: "Message sizes of 0 or >20 are not allowed." | |
918 | * We have no idea of what happened so we return -EBUSY so | |
919 | * drm layer takes care for the necessary retries. | |
920 | */ | |
921 | if (recv_bytes == 0 || recv_bytes > 20) { | |
922 | DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n", | |
923 | recv_bytes); | |
924 | /* | |
925 | * FIXME: This patch was created on top of a series that | |
926 | * organize the retries at drm level. There EBUSY should | |
927 | * also take care for 1ms wait before retrying. | |
928 | * That aux retries re-org is still needed and after that is | |
929 | * merged we remove this sleep from here. | |
930 | */ | |
931 | usleep_range(1000, 1500); | |
932 | ret = -EBUSY; | |
933 | goto out; | |
934 | } | |
935 | ||
a4fc5ed6 KP |
936 | if (recv_bytes > recv_size) |
937 | recv_bytes = recv_size; | |
0206e353 | 938 | |
4f7f7b7e | 939 | for (i = 0; i < recv_bytes; i += 4) |
330e20ec | 940 | intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]), |
a4f1289e | 941 | recv + i, recv_bytes - i); |
a4fc5ed6 | 942 | |
9ee32fea DV |
943 | ret = recv_bytes; |
944 | out: | |
945 | pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE); | |
946 | ||
884f19e9 JN |
947 | if (vdd) |
948 | edp_panel_vdd_off(intel_dp, false); | |
949 | ||
773538e8 | 950 | pps_unlock(intel_dp); |
e39b999a | 951 | |
9ee32fea | 952 | return ret; |
a4fc5ed6 KP |
953 | } |
954 | ||
a6c8aff0 JN |
955 | #define BARE_ADDRESS_SIZE 3 |
956 | #define HEADER_SIZE (BARE_ADDRESS_SIZE + 1) | |
9d1a1031 JN |
957 | static ssize_t |
958 | intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg) | |
a4fc5ed6 | 959 | { |
9d1a1031 JN |
960 | struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux); |
961 | uint8_t txbuf[20], rxbuf[20]; | |
962 | size_t txsize, rxsize; | |
a4fc5ed6 | 963 | int ret; |
a4fc5ed6 | 964 | |
d2d9cbbd VS |
965 | txbuf[0] = (msg->request << 4) | |
966 | ((msg->address >> 16) & 0xf); | |
967 | txbuf[1] = (msg->address >> 8) & 0xff; | |
9d1a1031 JN |
968 | txbuf[2] = msg->address & 0xff; |
969 | txbuf[3] = msg->size - 1; | |
46a5ae9f | 970 | |
9d1a1031 JN |
971 | switch (msg->request & ~DP_AUX_I2C_MOT) { |
972 | case DP_AUX_NATIVE_WRITE: | |
973 | case DP_AUX_I2C_WRITE: | |
c1e74122 | 974 | case DP_AUX_I2C_WRITE_STATUS_UPDATE: |
a6c8aff0 | 975 | txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE; |
a1ddefd8 | 976 | rxsize = 2; /* 0 or 1 data bytes */ |
f51a44b9 | 977 | |
9d1a1031 JN |
978 | if (WARN_ON(txsize > 20)) |
979 | return -E2BIG; | |
a4fc5ed6 | 980 | |
d81a67cc ID |
981 | if (msg->buffer) |
982 | memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size); | |
983 | else | |
984 | WARN_ON(msg->size); | |
a4fc5ed6 | 985 | |
9d1a1031 JN |
986 | ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize); |
987 | if (ret > 0) { | |
988 | msg->reply = rxbuf[0] >> 4; | |
a4fc5ed6 | 989 | |
a1ddefd8 JN |
990 | if (ret > 1) { |
991 | /* Number of bytes written in a short write. */ | |
992 | ret = clamp_t(int, rxbuf[1], 0, msg->size); | |
993 | } else { | |
994 | /* Return payload size. */ | |
995 | ret = msg->size; | |
996 | } | |
9d1a1031 JN |
997 | } |
998 | break; | |
46a5ae9f | 999 | |
9d1a1031 JN |
1000 | case DP_AUX_NATIVE_READ: |
1001 | case DP_AUX_I2C_READ: | |
a6c8aff0 | 1002 | txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE; |
9d1a1031 | 1003 | rxsize = msg->size + 1; |
a4fc5ed6 | 1004 | |
9d1a1031 JN |
1005 | if (WARN_ON(rxsize > 20)) |
1006 | return -E2BIG; | |
a4fc5ed6 | 1007 | |
9d1a1031 JN |
1008 | ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize); |
1009 | if (ret > 0) { | |
1010 | msg->reply = rxbuf[0] >> 4; | |
1011 | /* | |
1012 | * Assume happy day, and copy the data. The caller is | |
1013 | * expected to check msg->reply before touching it. | |
1014 | * | |
1015 | * Return payload size. | |
1016 | */ | |
1017 | ret--; | |
1018 | memcpy(msg->buffer, rxbuf + 1, ret); | |
a4fc5ed6 | 1019 | } |
9d1a1031 JN |
1020 | break; |
1021 | ||
1022 | default: | |
1023 | ret = -EINVAL; | |
1024 | break; | |
a4fc5ed6 | 1025 | } |
f51a44b9 | 1026 | |
9d1a1031 | 1027 | return ret; |
a4fc5ed6 KP |
1028 | } |
1029 | ||
f0f59a00 VS |
1030 | static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv, |
1031 | enum port port) | |
da00bdcf VS |
1032 | { |
1033 | switch (port) { | |
1034 | case PORT_B: | |
1035 | case PORT_C: | |
1036 | case PORT_D: | |
1037 | return DP_AUX_CH_CTL(port); | |
1038 | default: | |
1039 | MISSING_CASE(port); | |
1040 | return DP_AUX_CH_CTL(PORT_B); | |
1041 | } | |
1042 | } | |
1043 | ||
f0f59a00 VS |
1044 | static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv, |
1045 | enum port port, int index) | |
330e20ec VS |
1046 | { |
1047 | switch (port) { | |
1048 | case PORT_B: | |
1049 | case PORT_C: | |
1050 | case PORT_D: | |
1051 | return DP_AUX_CH_DATA(port, index); | |
1052 | default: | |
1053 | MISSING_CASE(port); | |
1054 | return DP_AUX_CH_DATA(PORT_B, index); | |
1055 | } | |
1056 | } | |
1057 | ||
f0f59a00 VS |
1058 | static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv, |
1059 | enum port port) | |
da00bdcf VS |
1060 | { |
1061 | switch (port) { | |
1062 | case PORT_A: | |
1063 | return DP_AUX_CH_CTL(port); | |
1064 | case PORT_B: | |
1065 | case PORT_C: | |
1066 | case PORT_D: | |
1067 | return PCH_DP_AUX_CH_CTL(port); | |
1068 | default: | |
1069 | MISSING_CASE(port); | |
1070 | return DP_AUX_CH_CTL(PORT_A); | |
1071 | } | |
1072 | } | |
1073 | ||
f0f59a00 VS |
1074 | static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv, |
1075 | enum port port, int index) | |
330e20ec VS |
1076 | { |
1077 | switch (port) { | |
1078 | case PORT_A: | |
1079 | return DP_AUX_CH_DATA(port, index); | |
1080 | case PORT_B: | |
1081 | case PORT_C: | |
1082 | case PORT_D: | |
1083 | return PCH_DP_AUX_CH_DATA(port, index); | |
1084 | default: | |
1085 | MISSING_CASE(port); | |
1086 | return DP_AUX_CH_DATA(PORT_A, index); | |
1087 | } | |
1088 | } | |
1089 | ||
da00bdcf VS |
1090 | /* |
1091 | * On SKL we don't have Aux for port E so we rely | |
1092 | * on VBT to set a proper alternate aux channel. | |
1093 | */ | |
1094 | static enum port skl_porte_aux_port(struct drm_i915_private *dev_priv) | |
1095 | { | |
1096 | const struct ddi_vbt_port_info *info = | |
1097 | &dev_priv->vbt.ddi_port_info[PORT_E]; | |
1098 | ||
1099 | switch (info->alternate_aux_channel) { | |
1100 | case DP_AUX_A: | |
1101 | return PORT_A; | |
1102 | case DP_AUX_B: | |
1103 | return PORT_B; | |
1104 | case DP_AUX_C: | |
1105 | return PORT_C; | |
1106 | case DP_AUX_D: | |
1107 | return PORT_D; | |
1108 | default: | |
1109 | MISSING_CASE(info->alternate_aux_channel); | |
1110 | return PORT_A; | |
1111 | } | |
1112 | } | |
1113 | ||
f0f59a00 VS |
1114 | static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv, |
1115 | enum port port) | |
da00bdcf VS |
1116 | { |
1117 | if (port == PORT_E) | |
1118 | port = skl_porte_aux_port(dev_priv); | |
1119 | ||
1120 | switch (port) { | |
1121 | case PORT_A: | |
1122 | case PORT_B: | |
1123 | case PORT_C: | |
1124 | case PORT_D: | |
1125 | return DP_AUX_CH_CTL(port); | |
1126 | default: | |
1127 | MISSING_CASE(port); | |
1128 | return DP_AUX_CH_CTL(PORT_A); | |
1129 | } | |
1130 | } | |
1131 | ||
f0f59a00 VS |
1132 | static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv, |
1133 | enum port port, int index) | |
330e20ec VS |
1134 | { |
1135 | if (port == PORT_E) | |
1136 | port = skl_porte_aux_port(dev_priv); | |
1137 | ||
1138 | switch (port) { | |
1139 | case PORT_A: | |
1140 | case PORT_B: | |
1141 | case PORT_C: | |
1142 | case PORT_D: | |
1143 | return DP_AUX_CH_DATA(port, index); | |
1144 | default: | |
1145 | MISSING_CASE(port); | |
1146 | return DP_AUX_CH_DATA(PORT_A, index); | |
1147 | } | |
1148 | } | |
1149 | ||
f0f59a00 VS |
1150 | static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv, |
1151 | enum port port) | |
330e20ec VS |
1152 | { |
1153 | if (INTEL_INFO(dev_priv)->gen >= 9) | |
1154 | return skl_aux_ctl_reg(dev_priv, port); | |
1155 | else if (HAS_PCH_SPLIT(dev_priv)) | |
1156 | return ilk_aux_ctl_reg(dev_priv, port); | |
1157 | else | |
1158 | return g4x_aux_ctl_reg(dev_priv, port); | |
1159 | } | |
1160 | ||
f0f59a00 VS |
1161 | static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv, |
1162 | enum port port, int index) | |
330e20ec VS |
1163 | { |
1164 | if (INTEL_INFO(dev_priv)->gen >= 9) | |
1165 | return skl_aux_data_reg(dev_priv, port, index); | |
1166 | else if (HAS_PCH_SPLIT(dev_priv)) | |
1167 | return ilk_aux_data_reg(dev_priv, port, index); | |
1168 | else | |
1169 | return g4x_aux_data_reg(dev_priv, port, index); | |
1170 | } | |
1171 | ||
1172 | static void intel_aux_reg_init(struct intel_dp *intel_dp) | |
1173 | { | |
1174 | struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); | |
1175 | enum port port = dp_to_dig_port(intel_dp)->port; | |
1176 | int i; | |
1177 | ||
1178 | intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port); | |
1179 | for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++) | |
1180 | intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i); | |
1181 | } | |
1182 | ||
9d1a1031 | 1183 | static void |
a121f4e5 VS |
1184 | intel_dp_aux_fini(struct intel_dp *intel_dp) |
1185 | { | |
1186 | drm_dp_aux_unregister(&intel_dp->aux); | |
1187 | kfree(intel_dp->aux.name); | |
1188 | } | |
1189 | ||
1190 | static int | |
9d1a1031 JN |
1191 | intel_dp_aux_init(struct intel_dp *intel_dp, struct intel_connector *connector) |
1192 | { | |
1193 | struct drm_device *dev = intel_dp_to_dev(intel_dp); | |
33ad6626 JN |
1194 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
1195 | enum port port = intel_dig_port->port; | |
ab2c0672 DA |
1196 | int ret; |
1197 | ||
330e20ec | 1198 | intel_aux_reg_init(intel_dp); |
8316f337 | 1199 | |
a121f4e5 VS |
1200 | intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port)); |
1201 | if (!intel_dp->aux.name) | |
1202 | return -ENOMEM; | |
1203 | ||
9d1a1031 JN |
1204 | intel_dp->aux.dev = dev->dev; |
1205 | intel_dp->aux.transfer = intel_dp_aux_transfer; | |
8316f337 | 1206 | |
a121f4e5 VS |
1207 | DRM_DEBUG_KMS("registering %s bus for %s\n", |
1208 | intel_dp->aux.name, | |
0b99836f | 1209 | connector->base.kdev->kobj.name); |
8316f337 | 1210 | |
4f71d0cb | 1211 | ret = drm_dp_aux_register(&intel_dp->aux); |
0b99836f | 1212 | if (ret < 0) { |
4f71d0cb | 1213 | DRM_ERROR("drm_dp_aux_register() for %s failed (%d)\n", |
a121f4e5 VS |
1214 | intel_dp->aux.name, ret); |
1215 | kfree(intel_dp->aux.name); | |
1216 | return ret; | |
ab2c0672 | 1217 | } |
8a5e6aeb | 1218 | |
0b99836f JN |
1219 | ret = sysfs_create_link(&connector->base.kdev->kobj, |
1220 | &intel_dp->aux.ddc.dev.kobj, | |
1221 | intel_dp->aux.ddc.dev.kobj.name); | |
1222 | if (ret < 0) { | |
a121f4e5 VS |
1223 | DRM_ERROR("sysfs_create_link() for %s failed (%d)\n", |
1224 | intel_dp->aux.name, ret); | |
1225 | intel_dp_aux_fini(intel_dp); | |
1226 | return ret; | |
ab2c0672 | 1227 | } |
a121f4e5 VS |
1228 | |
1229 | return 0; | |
a4fc5ed6 KP |
1230 | } |
1231 | ||
80f65de3 ID |
1232 | static void |
1233 | intel_dp_connector_unregister(struct intel_connector *intel_connector) | |
1234 | { | |
1235 | struct intel_dp *intel_dp = intel_attached_dp(&intel_connector->base); | |
1236 | ||
0e32b39c DA |
1237 | if (!intel_connector->mst_port) |
1238 | sysfs_remove_link(&intel_connector->base.kdev->kobj, | |
1239 | intel_dp->aux.ddc.dev.kobj.name); | |
80f65de3 ID |
1240 | intel_connector_unregister(intel_connector); |
1241 | } | |
1242 | ||
5416d871 | 1243 | static void |
840b32b7 | 1244 | skl_edp_set_pll_config(struct intel_crtc_state *pipe_config) |
5416d871 DL |
1245 | { |
1246 | u32 ctrl1; | |
1247 | ||
dd3cd74a ACO |
1248 | memset(&pipe_config->dpll_hw_state, 0, |
1249 | sizeof(pipe_config->dpll_hw_state)); | |
1250 | ||
5416d871 DL |
1251 | pipe_config->ddi_pll_sel = SKL_DPLL0; |
1252 | pipe_config->dpll_hw_state.cfgcr1 = 0; | |
1253 | pipe_config->dpll_hw_state.cfgcr2 = 0; | |
1254 | ||
1255 | ctrl1 = DPLL_CTRL1_OVERRIDE(SKL_DPLL0); | |
840b32b7 | 1256 | switch (pipe_config->port_clock / 2) { |
c3346ef6 | 1257 | case 81000: |
71cd8423 | 1258 | ctrl1 |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810, |
5416d871 DL |
1259 | SKL_DPLL0); |
1260 | break; | |
c3346ef6 | 1261 | case 135000: |
71cd8423 | 1262 | ctrl1 |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1350, |
5416d871 DL |
1263 | SKL_DPLL0); |
1264 | break; | |
c3346ef6 | 1265 | case 270000: |
71cd8423 | 1266 | ctrl1 |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_2700, |
5416d871 DL |
1267 | SKL_DPLL0); |
1268 | break; | |
c3346ef6 | 1269 | case 162000: |
71cd8423 | 1270 | ctrl1 |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1620, |
c3346ef6 SJ |
1271 | SKL_DPLL0); |
1272 | break; | |
1273 | /* TBD: For DP link rates 2.16 GHz and 4.32 GHz, VCO is 8640 which | |
1274 | results in CDCLK change. Need to handle the change of CDCLK by | |
1275 | disabling pipes and re-enabling them */ | |
1276 | case 108000: | |
71cd8423 | 1277 | ctrl1 |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080, |
c3346ef6 SJ |
1278 | SKL_DPLL0); |
1279 | break; | |
1280 | case 216000: | |
71cd8423 | 1281 | ctrl1 |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_2160, |
c3346ef6 SJ |
1282 | SKL_DPLL0); |
1283 | break; | |
1284 | ||
5416d871 DL |
1285 | } |
1286 | pipe_config->dpll_hw_state.ctrl1 = ctrl1; | |
1287 | } | |
1288 | ||
6fa2d197 | 1289 | void |
840b32b7 | 1290 | hsw_dp_set_ddi_pll_sel(struct intel_crtc_state *pipe_config) |
0e50338c | 1291 | { |
ee46f3c7 ACO |
1292 | memset(&pipe_config->dpll_hw_state, 0, |
1293 | sizeof(pipe_config->dpll_hw_state)); | |
1294 | ||
840b32b7 VS |
1295 | switch (pipe_config->port_clock / 2) { |
1296 | case 81000: | |
0e50338c DV |
1297 | pipe_config->ddi_pll_sel = PORT_CLK_SEL_LCPLL_810; |
1298 | break; | |
840b32b7 | 1299 | case 135000: |
0e50338c DV |
1300 | pipe_config->ddi_pll_sel = PORT_CLK_SEL_LCPLL_1350; |
1301 | break; | |
840b32b7 | 1302 | case 270000: |
0e50338c DV |
1303 | pipe_config->ddi_pll_sel = PORT_CLK_SEL_LCPLL_2700; |
1304 | break; | |
1305 | } | |
1306 | } | |
1307 | ||
fc0f8e25 | 1308 | static int |
12f6a2e2 | 1309 | intel_dp_sink_rates(struct intel_dp *intel_dp, const int **sink_rates) |
fc0f8e25 | 1310 | { |
94ca719e VS |
1311 | if (intel_dp->num_sink_rates) { |
1312 | *sink_rates = intel_dp->sink_rates; | |
1313 | return intel_dp->num_sink_rates; | |
fc0f8e25 | 1314 | } |
12f6a2e2 VS |
1315 | |
1316 | *sink_rates = default_rates; | |
1317 | ||
1318 | return (intel_dp_max_link_bw(intel_dp) >> 3) + 1; | |
fc0f8e25 SJ |
1319 | } |
1320 | ||
e588fa18 | 1321 | bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp) |
ed63baaf | 1322 | { |
e588fa18 ACO |
1323 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
1324 | struct drm_device *dev = dig_port->base.base.dev; | |
1325 | ||
ed63baaf | 1326 | /* WaDisableHBR2:skl */ |
e87a005d | 1327 | if (IS_SKL_REVID(dev, 0, SKL_REVID_B0)) |
ed63baaf TS |
1328 | return false; |
1329 | ||
1330 | if ((IS_HASWELL(dev) && !IS_HSW_ULX(dev)) || IS_BROADWELL(dev) || | |
1331 | (INTEL_INFO(dev)->gen >= 9)) | |
1332 | return true; | |
1333 | else | |
1334 | return false; | |
1335 | } | |
1336 | ||
a8f3ef61 | 1337 | static int |
e588fa18 | 1338 | intel_dp_source_rates(struct intel_dp *intel_dp, const int **source_rates) |
a8f3ef61 | 1339 | { |
e588fa18 ACO |
1340 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
1341 | struct drm_device *dev = dig_port->base.base.dev; | |
af7080f5 TS |
1342 | int size; |
1343 | ||
64987fc5 SJ |
1344 | if (IS_BROXTON(dev)) { |
1345 | *source_rates = bxt_rates; | |
af7080f5 | 1346 | size = ARRAY_SIZE(bxt_rates); |
ef11bdb3 | 1347 | } else if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) { |
637a9c63 | 1348 | *source_rates = skl_rates; |
af7080f5 TS |
1349 | size = ARRAY_SIZE(skl_rates); |
1350 | } else { | |
1351 | *source_rates = default_rates; | |
1352 | size = ARRAY_SIZE(default_rates); | |
a8f3ef61 | 1353 | } |
636280ba | 1354 | |
ed63baaf | 1355 | /* This depends on the fact that 5.4 is last value in the array */ |
e588fa18 | 1356 | if (!intel_dp_source_supports_hbr2(intel_dp)) |
af7080f5 | 1357 | size--; |
636280ba | 1358 | |
af7080f5 | 1359 | return size; |
a8f3ef61 SJ |
1360 | } |
1361 | ||
c6bb3538 DV |
1362 | static void |
1363 | intel_dp_set_clock(struct intel_encoder *encoder, | |
840b32b7 | 1364 | struct intel_crtc_state *pipe_config) |
c6bb3538 DV |
1365 | { |
1366 | struct drm_device *dev = encoder->base.dev; | |
9dd4ffdf CML |
1367 | const struct dp_link_dpll *divisor = NULL; |
1368 | int i, count = 0; | |
c6bb3538 DV |
1369 | |
1370 | if (IS_G4X(dev)) { | |
9dd4ffdf CML |
1371 | divisor = gen4_dpll; |
1372 | count = ARRAY_SIZE(gen4_dpll); | |
c6bb3538 | 1373 | } else if (HAS_PCH_SPLIT(dev)) { |
9dd4ffdf CML |
1374 | divisor = pch_dpll; |
1375 | count = ARRAY_SIZE(pch_dpll); | |
ef9348c8 CML |
1376 | } else if (IS_CHERRYVIEW(dev)) { |
1377 | divisor = chv_dpll; | |
1378 | count = ARRAY_SIZE(chv_dpll); | |
c6bb3538 | 1379 | } else if (IS_VALLEYVIEW(dev)) { |
65ce4bf5 CML |
1380 | divisor = vlv_dpll; |
1381 | count = ARRAY_SIZE(vlv_dpll); | |
c6bb3538 | 1382 | } |
9dd4ffdf CML |
1383 | |
1384 | if (divisor && count) { | |
1385 | for (i = 0; i < count; i++) { | |
840b32b7 | 1386 | if (pipe_config->port_clock == divisor[i].clock) { |
9dd4ffdf CML |
1387 | pipe_config->dpll = divisor[i].dpll; |
1388 | pipe_config->clock_set = true; | |
1389 | break; | |
1390 | } | |
1391 | } | |
c6bb3538 DV |
1392 | } |
1393 | } | |
1394 | ||
2ecae76a VS |
1395 | static int intersect_rates(const int *source_rates, int source_len, |
1396 | const int *sink_rates, int sink_len, | |
94ca719e | 1397 | int *common_rates) |
a8f3ef61 SJ |
1398 | { |
1399 | int i = 0, j = 0, k = 0; | |
1400 | ||
a8f3ef61 SJ |
1401 | while (i < source_len && j < sink_len) { |
1402 | if (source_rates[i] == sink_rates[j]) { | |
e6bda3e4 VS |
1403 | if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES)) |
1404 | return k; | |
94ca719e | 1405 | common_rates[k] = source_rates[i]; |
a8f3ef61 SJ |
1406 | ++k; |
1407 | ++i; | |
1408 | ++j; | |
1409 | } else if (source_rates[i] < sink_rates[j]) { | |
1410 | ++i; | |
1411 | } else { | |
1412 | ++j; | |
1413 | } | |
1414 | } | |
1415 | return k; | |
1416 | } | |
1417 | ||
94ca719e VS |
1418 | static int intel_dp_common_rates(struct intel_dp *intel_dp, |
1419 | int *common_rates) | |
2ecae76a | 1420 | { |
2ecae76a VS |
1421 | const int *source_rates, *sink_rates; |
1422 | int source_len, sink_len; | |
1423 | ||
1424 | sink_len = intel_dp_sink_rates(intel_dp, &sink_rates); | |
e588fa18 | 1425 | source_len = intel_dp_source_rates(intel_dp, &source_rates); |
2ecae76a VS |
1426 | |
1427 | return intersect_rates(source_rates, source_len, | |
1428 | sink_rates, sink_len, | |
94ca719e | 1429 | common_rates); |
2ecae76a VS |
1430 | } |
1431 | ||
0336400e VS |
1432 | static void snprintf_int_array(char *str, size_t len, |
1433 | const int *array, int nelem) | |
1434 | { | |
1435 | int i; | |
1436 | ||
1437 | str[0] = '\0'; | |
1438 | ||
1439 | for (i = 0; i < nelem; i++) { | |
b2f505be | 1440 | int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]); |
0336400e VS |
1441 | if (r >= len) |
1442 | return; | |
1443 | str += r; | |
1444 | len -= r; | |
1445 | } | |
1446 | } | |
1447 | ||
1448 | static void intel_dp_print_rates(struct intel_dp *intel_dp) | |
1449 | { | |
0336400e | 1450 | const int *source_rates, *sink_rates; |
94ca719e VS |
1451 | int source_len, sink_len, common_len; |
1452 | int common_rates[DP_MAX_SUPPORTED_RATES]; | |
0336400e VS |
1453 | char str[128]; /* FIXME: too big for stack? */ |
1454 | ||
1455 | if ((drm_debug & DRM_UT_KMS) == 0) | |
1456 | return; | |
1457 | ||
e588fa18 | 1458 | source_len = intel_dp_source_rates(intel_dp, &source_rates); |
0336400e VS |
1459 | snprintf_int_array(str, sizeof(str), source_rates, source_len); |
1460 | DRM_DEBUG_KMS("source rates: %s\n", str); | |
1461 | ||
1462 | sink_len = intel_dp_sink_rates(intel_dp, &sink_rates); | |
1463 | snprintf_int_array(str, sizeof(str), sink_rates, sink_len); | |
1464 | DRM_DEBUG_KMS("sink rates: %s\n", str); | |
1465 | ||
94ca719e VS |
1466 | common_len = intel_dp_common_rates(intel_dp, common_rates); |
1467 | snprintf_int_array(str, sizeof(str), common_rates, common_len); | |
1468 | DRM_DEBUG_KMS("common rates: %s\n", str); | |
0336400e VS |
1469 | } |
1470 | ||
f4896f15 | 1471 | static int rate_to_index(int find, const int *rates) |
a8f3ef61 SJ |
1472 | { |
1473 | int i = 0; | |
1474 | ||
1475 | for (i = 0; i < DP_MAX_SUPPORTED_RATES; ++i) | |
1476 | if (find == rates[i]) | |
1477 | break; | |
1478 | ||
1479 | return i; | |
1480 | } | |
1481 | ||
50fec21a VS |
1482 | int |
1483 | intel_dp_max_link_rate(struct intel_dp *intel_dp) | |
1484 | { | |
1485 | int rates[DP_MAX_SUPPORTED_RATES] = {}; | |
1486 | int len; | |
1487 | ||
94ca719e | 1488 | len = intel_dp_common_rates(intel_dp, rates); |
50fec21a VS |
1489 | if (WARN_ON(len <= 0)) |
1490 | return 162000; | |
1491 | ||
1492 | return rates[rate_to_index(0, rates) - 1]; | |
1493 | } | |
1494 | ||
ed4e9c1d VS |
1495 | int intel_dp_rate_select(struct intel_dp *intel_dp, int rate) |
1496 | { | |
94ca719e | 1497 | return rate_to_index(rate, intel_dp->sink_rates); |
ed4e9c1d VS |
1498 | } |
1499 | ||
94223d04 ACO |
1500 | void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock, |
1501 | uint8_t *link_bw, uint8_t *rate_select) | |
04a60f9f VS |
1502 | { |
1503 | if (intel_dp->num_sink_rates) { | |
1504 | *link_bw = 0; | |
1505 | *rate_select = | |
1506 | intel_dp_rate_select(intel_dp, port_clock); | |
1507 | } else { | |
1508 | *link_bw = drm_dp_link_rate_to_bw_code(port_clock); | |
1509 | *rate_select = 0; | |
1510 | } | |
1511 | } | |
1512 | ||
00c09d70 | 1513 | bool |
5bfe2ac0 | 1514 | intel_dp_compute_config(struct intel_encoder *encoder, |
5cec258b | 1515 | struct intel_crtc_state *pipe_config) |
a4fc5ed6 | 1516 | { |
5bfe2ac0 | 1517 | struct drm_device *dev = encoder->base.dev; |
36008365 | 1518 | struct drm_i915_private *dev_priv = dev->dev_private; |
2d112de7 | 1519 | struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
5bfe2ac0 | 1520 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
bc7d38a4 | 1521 | enum port port = dp_to_dig_port(intel_dp)->port; |
84556d58 | 1522 | struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc); |
dd06f90e | 1523 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
a4fc5ed6 | 1524 | int lane_count, clock; |
56071a20 | 1525 | int min_lane_count = 1; |
eeb6324d | 1526 | int max_lane_count = intel_dp_max_lane_count(intel_dp); |
06ea66b6 | 1527 | /* Conveniently, the link BW constants become indices with a shift...*/ |
56071a20 | 1528 | int min_clock = 0; |
a8f3ef61 | 1529 | int max_clock; |
083f9560 | 1530 | int bpp, mode_rate; |
ff9a6750 | 1531 | int link_avail, link_clock; |
94ca719e VS |
1532 | int common_rates[DP_MAX_SUPPORTED_RATES] = {}; |
1533 | int common_len; | |
04a60f9f | 1534 | uint8_t link_bw, rate_select; |
a8f3ef61 | 1535 | |
94ca719e | 1536 | common_len = intel_dp_common_rates(intel_dp, common_rates); |
a8f3ef61 SJ |
1537 | |
1538 | /* No common link rates between source and sink */ | |
94ca719e | 1539 | WARN_ON(common_len <= 0); |
a8f3ef61 | 1540 | |
94ca719e | 1541 | max_clock = common_len - 1; |
a4fc5ed6 | 1542 | |
bc7d38a4 | 1543 | if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev) && port != PORT_A) |
5bfe2ac0 DV |
1544 | pipe_config->has_pch_encoder = true; |
1545 | ||
03afc4a2 | 1546 | pipe_config->has_dp_encoder = true; |
f769cd24 | 1547 | pipe_config->has_drrs = false; |
9fcb1704 | 1548 | pipe_config->has_audio = intel_dp->has_audio && port != PORT_A; |
a4fc5ed6 | 1549 | |
dd06f90e JN |
1550 | if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) { |
1551 | intel_fixed_panel_mode(intel_connector->panel.fixed_mode, | |
1552 | adjusted_mode); | |
a1b2278e CK |
1553 | |
1554 | if (INTEL_INFO(dev)->gen >= 9) { | |
1555 | int ret; | |
e435d6e5 | 1556 | ret = skl_update_scaler_crtc(pipe_config); |
a1b2278e CK |
1557 | if (ret) |
1558 | return ret; | |
1559 | } | |
1560 | ||
b5667627 | 1561 | if (HAS_GMCH_DISPLAY(dev)) |
2dd24552 JB |
1562 | intel_gmch_panel_fitting(intel_crtc, pipe_config, |
1563 | intel_connector->panel.fitting_mode); | |
1564 | else | |
b074cec8 JB |
1565 | intel_pch_panel_fitting(intel_crtc, pipe_config, |
1566 | intel_connector->panel.fitting_mode); | |
0d3a1bee ZY |
1567 | } |
1568 | ||
cb1793ce | 1569 | if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK) |
0af78a2b DV |
1570 | return false; |
1571 | ||
083f9560 | 1572 | DRM_DEBUG_KMS("DP link computation with max lane count %i " |
a8f3ef61 | 1573 | "max bw %d pixel clock %iKHz\n", |
94ca719e | 1574 | max_lane_count, common_rates[max_clock], |
241bfc38 | 1575 | adjusted_mode->crtc_clock); |
083f9560 | 1576 | |
36008365 DV |
1577 | /* Walk through all bpp values. Luckily they're all nicely spaced with 2 |
1578 | * bpc in between. */ | |
3e7ca985 | 1579 | bpp = pipe_config->pipe_bpp; |
56071a20 | 1580 | if (is_edp(intel_dp)) { |
22ce5628 TS |
1581 | |
1582 | /* Get bpp from vbt only for panels that dont have bpp in edid */ | |
1583 | if (intel_connector->base.display_info.bpc == 0 && | |
1584 | (dev_priv->vbt.edp_bpp && dev_priv->vbt.edp_bpp < bpp)) { | |
56071a20 JN |
1585 | DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n", |
1586 | dev_priv->vbt.edp_bpp); | |
1587 | bpp = dev_priv->vbt.edp_bpp; | |
1588 | } | |
1589 | ||
344c5bbc JN |
1590 | /* |
1591 | * Use the maximum clock and number of lanes the eDP panel | |
1592 | * advertizes being capable of. The panels are generally | |
1593 | * designed to support only a single clock and lane | |
1594 | * configuration, and typically these values correspond to the | |
1595 | * native resolution of the panel. | |
1596 | */ | |
1597 | min_lane_count = max_lane_count; | |
1598 | min_clock = max_clock; | |
7984211e | 1599 | } |
657445fe | 1600 | |
36008365 | 1601 | for (; bpp >= 6*3; bpp -= 2*3) { |
241bfc38 DL |
1602 | mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock, |
1603 | bpp); | |
36008365 | 1604 | |
c6930992 | 1605 | for (clock = min_clock; clock <= max_clock; clock++) { |
a8f3ef61 SJ |
1606 | for (lane_count = min_lane_count; |
1607 | lane_count <= max_lane_count; | |
1608 | lane_count <<= 1) { | |
1609 | ||
94ca719e | 1610 | link_clock = common_rates[clock]; |
36008365 DV |
1611 | link_avail = intel_dp_max_data_rate(link_clock, |
1612 | lane_count); | |
1613 | ||
1614 | if (mode_rate <= link_avail) { | |
1615 | goto found; | |
1616 | } | |
1617 | } | |
1618 | } | |
1619 | } | |
c4867936 | 1620 | |
36008365 | 1621 | return false; |
3685a8f3 | 1622 | |
36008365 | 1623 | found: |
55bc60db VS |
1624 | if (intel_dp->color_range_auto) { |
1625 | /* | |
1626 | * See: | |
1627 | * CEA-861-E - 5.1 Default Encoding Parameters | |
1628 | * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry | |
1629 | */ | |
0f2a2a75 VS |
1630 | pipe_config->limited_color_range = |
1631 | bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1; | |
1632 | } else { | |
1633 | pipe_config->limited_color_range = | |
1634 | intel_dp->limited_color_range; | |
55bc60db VS |
1635 | } |
1636 | ||
90a6b7b0 | 1637 | pipe_config->lane_count = lane_count; |
a8f3ef61 | 1638 | |
657445fe | 1639 | pipe_config->pipe_bpp = bpp; |
94ca719e | 1640 | pipe_config->port_clock = common_rates[clock]; |
a4fc5ed6 | 1641 | |
04a60f9f VS |
1642 | intel_dp_compute_rate(intel_dp, pipe_config->port_clock, |
1643 | &link_bw, &rate_select); | |
1644 | ||
1645 | DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n", | |
1646 | link_bw, rate_select, pipe_config->lane_count, | |
ff9a6750 | 1647 | pipe_config->port_clock, bpp); |
36008365 DV |
1648 | DRM_DEBUG_KMS("DP link bw required %i available %i\n", |
1649 | mode_rate, link_avail); | |
a4fc5ed6 | 1650 | |
03afc4a2 | 1651 | intel_link_compute_m_n(bpp, lane_count, |
241bfc38 DL |
1652 | adjusted_mode->crtc_clock, |
1653 | pipe_config->port_clock, | |
03afc4a2 | 1654 | &pipe_config->dp_m_n); |
9d1a455b | 1655 | |
439d7ac0 | 1656 | if (intel_connector->panel.downclock_mode != NULL && |
96178eeb | 1657 | dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) { |
f769cd24 | 1658 | pipe_config->has_drrs = true; |
439d7ac0 PB |
1659 | intel_link_compute_m_n(bpp, lane_count, |
1660 | intel_connector->panel.downclock_mode->clock, | |
1661 | pipe_config->port_clock, | |
1662 | &pipe_config->dp_m2_n2); | |
1663 | } | |
1664 | ||
ef11bdb3 | 1665 | if ((IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) && is_edp(intel_dp)) |
840b32b7 | 1666 | skl_edp_set_pll_config(pipe_config); |
977bb38d S |
1667 | else if (IS_BROXTON(dev)) |
1668 | /* handled in ddi */; | |
5416d871 | 1669 | else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
840b32b7 | 1670 | hsw_dp_set_ddi_pll_sel(pipe_config); |
0e50338c | 1671 | else |
840b32b7 | 1672 | intel_dp_set_clock(encoder, pipe_config); |
c6bb3538 | 1673 | |
03afc4a2 | 1674 | return true; |
a4fc5ed6 KP |
1675 | } |
1676 | ||
901c2daf VS |
1677 | void intel_dp_set_link_params(struct intel_dp *intel_dp, |
1678 | const struct intel_crtc_state *pipe_config) | |
1679 | { | |
1680 | intel_dp->link_rate = pipe_config->port_clock; | |
1681 | intel_dp->lane_count = pipe_config->lane_count; | |
1682 | } | |
1683 | ||
8ac33ed3 | 1684 | static void intel_dp_prepare(struct intel_encoder *encoder) |
a4fc5ed6 | 1685 | { |
b934223d | 1686 | struct drm_device *dev = encoder->base.dev; |
417e822d | 1687 | struct drm_i915_private *dev_priv = dev->dev_private; |
b934223d | 1688 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
bc7d38a4 | 1689 | enum port port = dp_to_dig_port(intel_dp)->port; |
b934223d | 1690 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
7c5f93b0 | 1691 | const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode; |
a4fc5ed6 | 1692 | |
901c2daf VS |
1693 | intel_dp_set_link_params(intel_dp, crtc->config); |
1694 | ||
417e822d | 1695 | /* |
1a2eb460 | 1696 | * There are four kinds of DP registers: |
417e822d KP |
1697 | * |
1698 | * IBX PCH | |
1a2eb460 KP |
1699 | * SNB CPU |
1700 | * IVB CPU | |
417e822d KP |
1701 | * CPT PCH |
1702 | * | |
1703 | * IBX PCH and CPU are the same for almost everything, | |
1704 | * except that the CPU DP PLL is configured in this | |
1705 | * register | |
1706 | * | |
1707 | * CPT PCH is quite different, having many bits moved | |
1708 | * to the TRANS_DP_CTL register instead. That | |
1709 | * configuration happens (oddly) in ironlake_pch_enable | |
1710 | */ | |
9c9e7927 | 1711 | |
417e822d KP |
1712 | /* Preserve the BIOS-computed detected bit. This is |
1713 | * supposed to be read-only. | |
1714 | */ | |
1715 | intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED; | |
a4fc5ed6 | 1716 | |
417e822d | 1717 | /* Handle DP bits in common between all three register formats */ |
417e822d | 1718 | intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0; |
90a6b7b0 | 1719 | intel_dp->DP |= DP_PORT_WIDTH(crtc->config->lane_count); |
a4fc5ed6 | 1720 | |
417e822d | 1721 | /* Split out the IBX/CPU vs CPT settings */ |
32f9d658 | 1722 | |
39e5fa88 | 1723 | if (IS_GEN7(dev) && port == PORT_A) { |
1a2eb460 KP |
1724 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
1725 | intel_dp->DP |= DP_SYNC_HS_HIGH; | |
1726 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) | |
1727 | intel_dp->DP |= DP_SYNC_VS_HIGH; | |
1728 | intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT; | |
1729 | ||
6aba5b6c | 1730 | if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) |
1a2eb460 KP |
1731 | intel_dp->DP |= DP_ENHANCED_FRAMING; |
1732 | ||
7c62a164 | 1733 | intel_dp->DP |= crtc->pipe << 29; |
39e5fa88 | 1734 | } else if (HAS_PCH_CPT(dev) && port != PORT_A) { |
e3ef4479 VS |
1735 | u32 trans_dp; |
1736 | ||
39e5fa88 | 1737 | intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT; |
e3ef4479 VS |
1738 | |
1739 | trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe)); | |
1740 | if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) | |
1741 | trans_dp |= TRANS_DP_ENH_FRAMING; | |
1742 | else | |
1743 | trans_dp &= ~TRANS_DP_ENH_FRAMING; | |
1744 | I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp); | |
39e5fa88 | 1745 | } else { |
0f2a2a75 | 1746 | if (!HAS_PCH_SPLIT(dev) && !IS_VALLEYVIEW(dev) && |
666a4537 | 1747 | !IS_CHERRYVIEW(dev) && crtc->config->limited_color_range) |
0f2a2a75 | 1748 | intel_dp->DP |= DP_COLOR_RANGE_16_235; |
417e822d KP |
1749 | |
1750 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) | |
1751 | intel_dp->DP |= DP_SYNC_HS_HIGH; | |
1752 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) | |
1753 | intel_dp->DP |= DP_SYNC_VS_HIGH; | |
1754 | intel_dp->DP |= DP_LINK_TRAIN_OFF; | |
1755 | ||
6aba5b6c | 1756 | if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) |
417e822d KP |
1757 | intel_dp->DP |= DP_ENHANCED_FRAMING; |
1758 | ||
39e5fa88 | 1759 | if (IS_CHERRYVIEW(dev)) |
44f37d1f | 1760 | intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe); |
39e5fa88 VS |
1761 | else if (crtc->pipe == PIPE_B) |
1762 | intel_dp->DP |= DP_PIPEB_SELECT; | |
32f9d658 | 1763 | } |
a4fc5ed6 KP |
1764 | } |
1765 | ||
ffd6749d PZ |
1766 | #define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK) |
1767 | #define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE) | |
99ea7127 | 1768 | |
1a5ef5b7 PZ |
1769 | #define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0) |
1770 | #define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0) | |
99ea7127 | 1771 | |
ffd6749d PZ |
1772 | #define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK) |
1773 | #define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE) | |
99ea7127 | 1774 | |
4be73780 | 1775 | static void wait_panel_status(struct intel_dp *intel_dp, |
99ea7127 KP |
1776 | u32 mask, |
1777 | u32 value) | |
bd943159 | 1778 | { |
30add22d | 1779 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
99ea7127 | 1780 | struct drm_i915_private *dev_priv = dev->dev_private; |
f0f59a00 | 1781 | i915_reg_t pp_stat_reg, pp_ctrl_reg; |
453c5420 | 1782 | |
e39b999a VS |
1783 | lockdep_assert_held(&dev_priv->pps_mutex); |
1784 | ||
bf13e81b JN |
1785 | pp_stat_reg = _pp_stat_reg(intel_dp); |
1786 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); | |
32ce697c | 1787 | |
99ea7127 | 1788 | DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n", |
453c5420 JB |
1789 | mask, value, |
1790 | I915_READ(pp_stat_reg), | |
1791 | I915_READ(pp_ctrl_reg)); | |
32ce697c | 1792 | |
3f177625 TU |
1793 | if (_wait_for((I915_READ(pp_stat_reg) & mask) == value, |
1794 | 5 * USEC_PER_SEC, 10 * USEC_PER_MSEC)) | |
99ea7127 | 1795 | DRM_ERROR("Panel status timeout: status %08x control %08x\n", |
453c5420 JB |
1796 | I915_READ(pp_stat_reg), |
1797 | I915_READ(pp_ctrl_reg)); | |
54c136d4 CW |
1798 | |
1799 | DRM_DEBUG_KMS("Wait complete\n"); | |
99ea7127 | 1800 | } |
32ce697c | 1801 | |
4be73780 | 1802 | static void wait_panel_on(struct intel_dp *intel_dp) |
99ea7127 KP |
1803 | { |
1804 | DRM_DEBUG_KMS("Wait for panel power on\n"); | |
4be73780 | 1805 | wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE); |
bd943159 KP |
1806 | } |
1807 | ||
4be73780 | 1808 | static void wait_panel_off(struct intel_dp *intel_dp) |
99ea7127 KP |
1809 | { |
1810 | DRM_DEBUG_KMS("Wait for panel power off time\n"); | |
4be73780 | 1811 | wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE); |
99ea7127 KP |
1812 | } |
1813 | ||
4be73780 | 1814 | static void wait_panel_power_cycle(struct intel_dp *intel_dp) |
99ea7127 | 1815 | { |
d28d4731 AK |
1816 | ktime_t panel_power_on_time; |
1817 | s64 panel_power_off_duration; | |
1818 | ||
99ea7127 | 1819 | DRM_DEBUG_KMS("Wait for panel power cycle\n"); |
dce56b3c | 1820 | |
d28d4731 AK |
1821 | /* take the difference of currrent time and panel power off time |
1822 | * and then make panel wait for t11_t12 if needed. */ | |
1823 | panel_power_on_time = ktime_get_boottime(); | |
1824 | panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time); | |
1825 | ||
dce56b3c PZ |
1826 | /* When we disable the VDD override bit last we have to do the manual |
1827 | * wait. */ | |
d28d4731 AK |
1828 | if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay) |
1829 | wait_remaining_ms_from_jiffies(jiffies, | |
1830 | intel_dp->panel_power_cycle_delay - panel_power_off_duration); | |
dce56b3c | 1831 | |
4be73780 | 1832 | wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE); |
99ea7127 KP |
1833 | } |
1834 | ||
4be73780 | 1835 | static void wait_backlight_on(struct intel_dp *intel_dp) |
dce56b3c PZ |
1836 | { |
1837 | wait_remaining_ms_from_jiffies(intel_dp->last_power_on, | |
1838 | intel_dp->backlight_on_delay); | |
1839 | } | |
1840 | ||
4be73780 | 1841 | static void edp_wait_backlight_off(struct intel_dp *intel_dp) |
dce56b3c PZ |
1842 | { |
1843 | wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off, | |
1844 | intel_dp->backlight_off_delay); | |
1845 | } | |
99ea7127 | 1846 | |
832dd3c1 KP |
1847 | /* Read the current pp_control value, unlocking the register if it |
1848 | * is locked | |
1849 | */ | |
1850 | ||
453c5420 | 1851 | static u32 ironlake_get_pp_control(struct intel_dp *intel_dp) |
832dd3c1 | 1852 | { |
453c5420 JB |
1853 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
1854 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1855 | u32 control; | |
832dd3c1 | 1856 | |
e39b999a VS |
1857 | lockdep_assert_held(&dev_priv->pps_mutex); |
1858 | ||
bf13e81b | 1859 | control = I915_READ(_pp_ctrl_reg(intel_dp)); |
b0a08bec VK |
1860 | if (!IS_BROXTON(dev)) { |
1861 | control &= ~PANEL_UNLOCK_MASK; | |
1862 | control |= PANEL_UNLOCK_REGS; | |
1863 | } | |
832dd3c1 | 1864 | return control; |
bd943159 KP |
1865 | } |
1866 | ||
951468f3 VS |
1867 | /* |
1868 | * Must be paired with edp_panel_vdd_off(). | |
1869 | * Must hold pps_mutex around the whole on/off sequence. | |
1870 | * Can be nested with intel_edp_panel_vdd_{on,off}() calls. | |
1871 | */ | |
1e0560e0 | 1872 | static bool edp_panel_vdd_on(struct intel_dp *intel_dp) |
5d613501 | 1873 | { |
30add22d | 1874 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
4e6e1a54 ID |
1875 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
1876 | struct intel_encoder *intel_encoder = &intel_dig_port->base; | |
5d613501 | 1877 | struct drm_i915_private *dev_priv = dev->dev_private; |
4e6e1a54 | 1878 | enum intel_display_power_domain power_domain; |
5d613501 | 1879 | u32 pp; |
f0f59a00 | 1880 | i915_reg_t pp_stat_reg, pp_ctrl_reg; |
adddaaf4 | 1881 | bool need_to_disable = !intel_dp->want_panel_vdd; |
5d613501 | 1882 | |
e39b999a VS |
1883 | lockdep_assert_held(&dev_priv->pps_mutex); |
1884 | ||
97af61f5 | 1885 | if (!is_edp(intel_dp)) |
adddaaf4 | 1886 | return false; |
bd943159 | 1887 | |
2c623c11 | 1888 | cancel_delayed_work(&intel_dp->panel_vdd_work); |
bd943159 | 1889 | intel_dp->want_panel_vdd = true; |
99ea7127 | 1890 | |
4be73780 | 1891 | if (edp_have_panel_vdd(intel_dp)) |
adddaaf4 | 1892 | return need_to_disable; |
b0665d57 | 1893 | |
25f78f58 | 1894 | power_domain = intel_display_port_aux_power_domain(intel_encoder); |
4e6e1a54 | 1895 | intel_display_power_get(dev_priv, power_domain); |
e9cb81a2 | 1896 | |
3936fcf4 VS |
1897 | DRM_DEBUG_KMS("Turning eDP port %c VDD on\n", |
1898 | port_name(intel_dig_port->port)); | |
bd943159 | 1899 | |
4be73780 DV |
1900 | if (!edp_have_panel_power(intel_dp)) |
1901 | wait_panel_power_cycle(intel_dp); | |
99ea7127 | 1902 | |
453c5420 | 1903 | pp = ironlake_get_pp_control(intel_dp); |
5d613501 | 1904 | pp |= EDP_FORCE_VDD; |
ebf33b18 | 1905 | |
bf13e81b JN |
1906 | pp_stat_reg = _pp_stat_reg(intel_dp); |
1907 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); | |
453c5420 JB |
1908 | |
1909 | I915_WRITE(pp_ctrl_reg, pp); | |
1910 | POSTING_READ(pp_ctrl_reg); | |
1911 | DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n", | |
1912 | I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg)); | |
ebf33b18 KP |
1913 | /* |
1914 | * If the panel wasn't on, delay before accessing aux channel | |
1915 | */ | |
4be73780 | 1916 | if (!edp_have_panel_power(intel_dp)) { |
3936fcf4 VS |
1917 | DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n", |
1918 | port_name(intel_dig_port->port)); | |
f01eca2e | 1919 | msleep(intel_dp->panel_power_up_delay); |
f01eca2e | 1920 | } |
adddaaf4 JN |
1921 | |
1922 | return need_to_disable; | |
1923 | } | |
1924 | ||
951468f3 VS |
1925 | /* |
1926 | * Must be paired with intel_edp_panel_vdd_off() or | |
1927 | * intel_edp_panel_off(). | |
1928 | * Nested calls to these functions are not allowed since | |
1929 | * we drop the lock. Caller must use some higher level | |
1930 | * locking to prevent nested calls from other threads. | |
1931 | */ | |
b80d6c78 | 1932 | void intel_edp_panel_vdd_on(struct intel_dp *intel_dp) |
adddaaf4 | 1933 | { |
c695b6b6 | 1934 | bool vdd; |
adddaaf4 | 1935 | |
c695b6b6 VS |
1936 | if (!is_edp(intel_dp)) |
1937 | return; | |
1938 | ||
773538e8 | 1939 | pps_lock(intel_dp); |
c695b6b6 | 1940 | vdd = edp_panel_vdd_on(intel_dp); |
773538e8 | 1941 | pps_unlock(intel_dp); |
c695b6b6 | 1942 | |
e2c719b7 | 1943 | I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n", |
3936fcf4 | 1944 | port_name(dp_to_dig_port(intel_dp)->port)); |
5d613501 JB |
1945 | } |
1946 | ||
4be73780 | 1947 | static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp) |
5d613501 | 1948 | { |
30add22d | 1949 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
5d613501 | 1950 | struct drm_i915_private *dev_priv = dev->dev_private; |
be2c9196 VS |
1951 | struct intel_digital_port *intel_dig_port = |
1952 | dp_to_dig_port(intel_dp); | |
1953 | struct intel_encoder *intel_encoder = &intel_dig_port->base; | |
1954 | enum intel_display_power_domain power_domain; | |
5d613501 | 1955 | u32 pp; |
f0f59a00 | 1956 | i915_reg_t pp_stat_reg, pp_ctrl_reg; |
5d613501 | 1957 | |
e39b999a | 1958 | lockdep_assert_held(&dev_priv->pps_mutex); |
a0e99e68 | 1959 | |
15e899a0 | 1960 | WARN_ON(intel_dp->want_panel_vdd); |
4e6e1a54 | 1961 | |
15e899a0 | 1962 | if (!edp_have_panel_vdd(intel_dp)) |
be2c9196 | 1963 | return; |
b0665d57 | 1964 | |
3936fcf4 VS |
1965 | DRM_DEBUG_KMS("Turning eDP port %c VDD off\n", |
1966 | port_name(intel_dig_port->port)); | |
bd943159 | 1967 | |
be2c9196 VS |
1968 | pp = ironlake_get_pp_control(intel_dp); |
1969 | pp &= ~EDP_FORCE_VDD; | |
453c5420 | 1970 | |
be2c9196 VS |
1971 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
1972 | pp_stat_reg = _pp_stat_reg(intel_dp); | |
99ea7127 | 1973 | |
be2c9196 VS |
1974 | I915_WRITE(pp_ctrl_reg, pp); |
1975 | POSTING_READ(pp_ctrl_reg); | |
90791a5c | 1976 | |
be2c9196 VS |
1977 | /* Make sure sequencer is idle before allowing subsequent activity */ |
1978 | DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n", | |
1979 | I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg)); | |
e9cb81a2 | 1980 | |
be2c9196 | 1981 | if ((pp & POWER_TARGET_ON) == 0) |
d28d4731 | 1982 | intel_dp->panel_power_off_time = ktime_get_boottime(); |
e9cb81a2 | 1983 | |
25f78f58 | 1984 | power_domain = intel_display_port_aux_power_domain(intel_encoder); |
be2c9196 | 1985 | intel_display_power_put(dev_priv, power_domain); |
bd943159 | 1986 | } |
5d613501 | 1987 | |
4be73780 | 1988 | static void edp_panel_vdd_work(struct work_struct *__work) |
bd943159 KP |
1989 | { |
1990 | struct intel_dp *intel_dp = container_of(to_delayed_work(__work), | |
1991 | struct intel_dp, panel_vdd_work); | |
bd943159 | 1992 | |
773538e8 | 1993 | pps_lock(intel_dp); |
15e899a0 VS |
1994 | if (!intel_dp->want_panel_vdd) |
1995 | edp_panel_vdd_off_sync(intel_dp); | |
773538e8 | 1996 | pps_unlock(intel_dp); |
bd943159 KP |
1997 | } |
1998 | ||
aba86890 ID |
1999 | static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp) |
2000 | { | |
2001 | unsigned long delay; | |
2002 | ||
2003 | /* | |
2004 | * Queue the timer to fire a long time from now (relative to the power | |
2005 | * down delay) to keep the panel power up across a sequence of | |
2006 | * operations. | |
2007 | */ | |
2008 | delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5); | |
2009 | schedule_delayed_work(&intel_dp->panel_vdd_work, delay); | |
2010 | } | |
2011 | ||
951468f3 VS |
2012 | /* |
2013 | * Must be paired with edp_panel_vdd_on(). | |
2014 | * Must hold pps_mutex around the whole on/off sequence. | |
2015 | * Can be nested with intel_edp_panel_vdd_{on,off}() calls. | |
2016 | */ | |
4be73780 | 2017 | static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync) |
bd943159 | 2018 | { |
e39b999a VS |
2019 | struct drm_i915_private *dev_priv = |
2020 | intel_dp_to_dev(intel_dp)->dev_private; | |
2021 | ||
2022 | lockdep_assert_held(&dev_priv->pps_mutex); | |
2023 | ||
97af61f5 KP |
2024 | if (!is_edp(intel_dp)) |
2025 | return; | |
5d613501 | 2026 | |
e2c719b7 | 2027 | I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on", |
3936fcf4 | 2028 | port_name(dp_to_dig_port(intel_dp)->port)); |
f2e8b18a | 2029 | |
bd943159 KP |
2030 | intel_dp->want_panel_vdd = false; |
2031 | ||
aba86890 | 2032 | if (sync) |
4be73780 | 2033 | edp_panel_vdd_off_sync(intel_dp); |
aba86890 ID |
2034 | else |
2035 | edp_panel_vdd_schedule_off(intel_dp); | |
5d613501 JB |
2036 | } |
2037 | ||
9f0fb5be | 2038 | static void edp_panel_on(struct intel_dp *intel_dp) |
9934c132 | 2039 | { |
30add22d | 2040 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
9934c132 | 2041 | struct drm_i915_private *dev_priv = dev->dev_private; |
99ea7127 | 2042 | u32 pp; |
f0f59a00 | 2043 | i915_reg_t pp_ctrl_reg; |
9934c132 | 2044 | |
9f0fb5be VS |
2045 | lockdep_assert_held(&dev_priv->pps_mutex); |
2046 | ||
97af61f5 | 2047 | if (!is_edp(intel_dp)) |
bd943159 | 2048 | return; |
99ea7127 | 2049 | |
3936fcf4 VS |
2050 | DRM_DEBUG_KMS("Turn eDP port %c panel power on\n", |
2051 | port_name(dp_to_dig_port(intel_dp)->port)); | |
e39b999a | 2052 | |
e7a89ace VS |
2053 | if (WARN(edp_have_panel_power(intel_dp), |
2054 | "eDP port %c panel power already on\n", | |
2055 | port_name(dp_to_dig_port(intel_dp)->port))) | |
9f0fb5be | 2056 | return; |
9934c132 | 2057 | |
4be73780 | 2058 | wait_panel_power_cycle(intel_dp); |
37c6c9b0 | 2059 | |
bf13e81b | 2060 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
453c5420 | 2061 | pp = ironlake_get_pp_control(intel_dp); |
05ce1a49 KP |
2062 | if (IS_GEN5(dev)) { |
2063 | /* ILK workaround: disable reset around power sequence */ | |
2064 | pp &= ~PANEL_POWER_RESET; | |
bf13e81b JN |
2065 | I915_WRITE(pp_ctrl_reg, pp); |
2066 | POSTING_READ(pp_ctrl_reg); | |
05ce1a49 | 2067 | } |
37c6c9b0 | 2068 | |
1c0ae80a | 2069 | pp |= POWER_TARGET_ON; |
99ea7127 KP |
2070 | if (!IS_GEN5(dev)) |
2071 | pp |= PANEL_POWER_RESET; | |
2072 | ||
453c5420 JB |
2073 | I915_WRITE(pp_ctrl_reg, pp); |
2074 | POSTING_READ(pp_ctrl_reg); | |
9934c132 | 2075 | |
4be73780 | 2076 | wait_panel_on(intel_dp); |
dce56b3c | 2077 | intel_dp->last_power_on = jiffies; |
9934c132 | 2078 | |
05ce1a49 KP |
2079 | if (IS_GEN5(dev)) { |
2080 | pp |= PANEL_POWER_RESET; /* restore panel reset bit */ | |
bf13e81b JN |
2081 | I915_WRITE(pp_ctrl_reg, pp); |
2082 | POSTING_READ(pp_ctrl_reg); | |
05ce1a49 | 2083 | } |
9f0fb5be | 2084 | } |
e39b999a | 2085 | |
9f0fb5be VS |
2086 | void intel_edp_panel_on(struct intel_dp *intel_dp) |
2087 | { | |
2088 | if (!is_edp(intel_dp)) | |
2089 | return; | |
2090 | ||
2091 | pps_lock(intel_dp); | |
2092 | edp_panel_on(intel_dp); | |
773538e8 | 2093 | pps_unlock(intel_dp); |
9934c132 JB |
2094 | } |
2095 | ||
9f0fb5be VS |
2096 | |
2097 | static void edp_panel_off(struct intel_dp *intel_dp) | |
9934c132 | 2098 | { |
4e6e1a54 ID |
2099 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
2100 | struct intel_encoder *intel_encoder = &intel_dig_port->base; | |
30add22d | 2101 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
9934c132 | 2102 | struct drm_i915_private *dev_priv = dev->dev_private; |
4e6e1a54 | 2103 | enum intel_display_power_domain power_domain; |
99ea7127 | 2104 | u32 pp; |
f0f59a00 | 2105 | i915_reg_t pp_ctrl_reg; |
9934c132 | 2106 | |
9f0fb5be VS |
2107 | lockdep_assert_held(&dev_priv->pps_mutex); |
2108 | ||
97af61f5 KP |
2109 | if (!is_edp(intel_dp)) |
2110 | return; | |
37c6c9b0 | 2111 | |
3936fcf4 VS |
2112 | DRM_DEBUG_KMS("Turn eDP port %c panel power off\n", |
2113 | port_name(dp_to_dig_port(intel_dp)->port)); | |
37c6c9b0 | 2114 | |
3936fcf4 VS |
2115 | WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n", |
2116 | port_name(dp_to_dig_port(intel_dp)->port)); | |
24f3e092 | 2117 | |
453c5420 | 2118 | pp = ironlake_get_pp_control(intel_dp); |
35a38556 DV |
2119 | /* We need to switch off panel power _and_ force vdd, for otherwise some |
2120 | * panels get very unhappy and cease to work. */ | |
b3064154 PJ |
2121 | pp &= ~(POWER_TARGET_ON | PANEL_POWER_RESET | EDP_FORCE_VDD | |
2122 | EDP_BLC_ENABLE); | |
453c5420 | 2123 | |
bf13e81b | 2124 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
453c5420 | 2125 | |
849e39f5 PZ |
2126 | intel_dp->want_panel_vdd = false; |
2127 | ||
453c5420 JB |
2128 | I915_WRITE(pp_ctrl_reg, pp); |
2129 | POSTING_READ(pp_ctrl_reg); | |
9934c132 | 2130 | |
d28d4731 | 2131 | intel_dp->panel_power_off_time = ktime_get_boottime(); |
4be73780 | 2132 | wait_panel_off(intel_dp); |
849e39f5 PZ |
2133 | |
2134 | /* We got a reference when we enabled the VDD. */ | |
25f78f58 | 2135 | power_domain = intel_display_port_aux_power_domain(intel_encoder); |
4e6e1a54 | 2136 | intel_display_power_put(dev_priv, power_domain); |
9f0fb5be | 2137 | } |
e39b999a | 2138 | |
9f0fb5be VS |
2139 | void intel_edp_panel_off(struct intel_dp *intel_dp) |
2140 | { | |
2141 | if (!is_edp(intel_dp)) | |
2142 | return; | |
e39b999a | 2143 | |
9f0fb5be VS |
2144 | pps_lock(intel_dp); |
2145 | edp_panel_off(intel_dp); | |
773538e8 | 2146 | pps_unlock(intel_dp); |
9934c132 JB |
2147 | } |
2148 | ||
1250d107 JN |
2149 | /* Enable backlight in the panel power control. */ |
2150 | static void _intel_edp_backlight_on(struct intel_dp *intel_dp) | |
32f9d658 | 2151 | { |
da63a9f2 PZ |
2152 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
2153 | struct drm_device *dev = intel_dig_port->base.base.dev; | |
32f9d658 ZW |
2154 | struct drm_i915_private *dev_priv = dev->dev_private; |
2155 | u32 pp; | |
f0f59a00 | 2156 | i915_reg_t pp_ctrl_reg; |
32f9d658 | 2157 | |
01cb9ea6 JB |
2158 | /* |
2159 | * If we enable the backlight right away following a panel power | |
2160 | * on, we may see slight flicker as the panel syncs with the eDP | |
2161 | * link. So delay a bit to make sure the image is solid before | |
2162 | * allowing it to appear. | |
2163 | */ | |
4be73780 | 2164 | wait_backlight_on(intel_dp); |
e39b999a | 2165 | |
773538e8 | 2166 | pps_lock(intel_dp); |
e39b999a | 2167 | |
453c5420 | 2168 | pp = ironlake_get_pp_control(intel_dp); |
32f9d658 | 2169 | pp |= EDP_BLC_ENABLE; |
453c5420 | 2170 | |
bf13e81b | 2171 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
453c5420 JB |
2172 | |
2173 | I915_WRITE(pp_ctrl_reg, pp); | |
2174 | POSTING_READ(pp_ctrl_reg); | |
e39b999a | 2175 | |
773538e8 | 2176 | pps_unlock(intel_dp); |
32f9d658 ZW |
2177 | } |
2178 | ||
1250d107 JN |
2179 | /* Enable backlight PWM and backlight PP control. */ |
2180 | void intel_edp_backlight_on(struct intel_dp *intel_dp) | |
2181 | { | |
2182 | if (!is_edp(intel_dp)) | |
2183 | return; | |
2184 | ||
2185 | DRM_DEBUG_KMS("\n"); | |
2186 | ||
2187 | intel_panel_enable_backlight(intel_dp->attached_connector); | |
2188 | _intel_edp_backlight_on(intel_dp); | |
2189 | } | |
2190 | ||
2191 | /* Disable backlight in the panel power control. */ | |
2192 | static void _intel_edp_backlight_off(struct intel_dp *intel_dp) | |
32f9d658 | 2193 | { |
30add22d | 2194 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
32f9d658 ZW |
2195 | struct drm_i915_private *dev_priv = dev->dev_private; |
2196 | u32 pp; | |
f0f59a00 | 2197 | i915_reg_t pp_ctrl_reg; |
32f9d658 | 2198 | |
f01eca2e KP |
2199 | if (!is_edp(intel_dp)) |
2200 | return; | |
2201 | ||
773538e8 | 2202 | pps_lock(intel_dp); |
e39b999a | 2203 | |
453c5420 | 2204 | pp = ironlake_get_pp_control(intel_dp); |
32f9d658 | 2205 | pp &= ~EDP_BLC_ENABLE; |
453c5420 | 2206 | |
bf13e81b | 2207 | pp_ctrl_reg = _pp_ctrl_reg(intel_dp); |
453c5420 JB |
2208 | |
2209 | I915_WRITE(pp_ctrl_reg, pp); | |
2210 | POSTING_READ(pp_ctrl_reg); | |
f7d2323c | 2211 | |
773538e8 | 2212 | pps_unlock(intel_dp); |
e39b999a VS |
2213 | |
2214 | intel_dp->last_backlight_off = jiffies; | |
f7d2323c | 2215 | edp_wait_backlight_off(intel_dp); |
1250d107 | 2216 | } |
f7d2323c | 2217 | |
1250d107 JN |
2218 | /* Disable backlight PP control and backlight PWM. */ |
2219 | void intel_edp_backlight_off(struct intel_dp *intel_dp) | |
2220 | { | |
2221 | if (!is_edp(intel_dp)) | |
2222 | return; | |
2223 | ||
2224 | DRM_DEBUG_KMS("\n"); | |
f7d2323c | 2225 | |
1250d107 | 2226 | _intel_edp_backlight_off(intel_dp); |
f7d2323c | 2227 | intel_panel_disable_backlight(intel_dp->attached_connector); |
32f9d658 | 2228 | } |
a4fc5ed6 | 2229 | |
73580fb7 JN |
2230 | /* |
2231 | * Hook for controlling the panel power control backlight through the bl_power | |
2232 | * sysfs attribute. Take care to handle multiple calls. | |
2233 | */ | |
2234 | static void intel_edp_backlight_power(struct intel_connector *connector, | |
2235 | bool enable) | |
2236 | { | |
2237 | struct intel_dp *intel_dp = intel_attached_dp(&connector->base); | |
e39b999a VS |
2238 | bool is_enabled; |
2239 | ||
773538e8 | 2240 | pps_lock(intel_dp); |
e39b999a | 2241 | is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE; |
773538e8 | 2242 | pps_unlock(intel_dp); |
73580fb7 JN |
2243 | |
2244 | if (is_enabled == enable) | |
2245 | return; | |
2246 | ||
23ba9373 JN |
2247 | DRM_DEBUG_KMS("panel power control backlight %s\n", |
2248 | enable ? "enable" : "disable"); | |
73580fb7 JN |
2249 | |
2250 | if (enable) | |
2251 | _intel_edp_backlight_on(intel_dp); | |
2252 | else | |
2253 | _intel_edp_backlight_off(intel_dp); | |
2254 | } | |
2255 | ||
64e1077a VS |
2256 | static void assert_dp_port(struct intel_dp *intel_dp, bool state) |
2257 | { | |
2258 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); | |
2259 | struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); | |
2260 | bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN; | |
2261 | ||
2262 | I915_STATE_WARN(cur_state != state, | |
2263 | "DP port %c state assertion failure (expected %s, current %s)\n", | |
2264 | port_name(dig_port->port), | |
87ad3212 | 2265 | onoff(state), onoff(cur_state)); |
64e1077a VS |
2266 | } |
2267 | #define assert_dp_port_disabled(d) assert_dp_port((d), false) | |
2268 | ||
2269 | static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state) | |
2270 | { | |
2271 | bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE; | |
2272 | ||
2273 | I915_STATE_WARN(cur_state != state, | |
2274 | "eDP PLL state assertion failure (expected %s, current %s)\n", | |
87ad3212 | 2275 | onoff(state), onoff(cur_state)); |
64e1077a VS |
2276 | } |
2277 | #define assert_edp_pll_enabled(d) assert_edp_pll((d), true) | |
2278 | #define assert_edp_pll_disabled(d) assert_edp_pll((d), false) | |
2279 | ||
2bd2ad64 | 2280 | static void ironlake_edp_pll_on(struct intel_dp *intel_dp) |
d240f20f | 2281 | { |
da63a9f2 | 2282 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
64e1077a VS |
2283 | struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc); |
2284 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); | |
d240f20f | 2285 | |
64e1077a VS |
2286 | assert_pipe_disabled(dev_priv, crtc->pipe); |
2287 | assert_dp_port_disabled(intel_dp); | |
2288 | assert_edp_pll_disabled(dev_priv); | |
2bd2ad64 | 2289 | |
abfce949 VS |
2290 | DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n", |
2291 | crtc->config->port_clock); | |
2292 | ||
2293 | intel_dp->DP &= ~DP_PLL_FREQ_MASK; | |
2294 | ||
2295 | if (crtc->config->port_clock == 162000) | |
2296 | intel_dp->DP |= DP_PLL_FREQ_162MHZ; | |
2297 | else | |
2298 | intel_dp->DP |= DP_PLL_FREQ_270MHZ; | |
2299 | ||
2300 | I915_WRITE(DP_A, intel_dp->DP); | |
2301 | POSTING_READ(DP_A); | |
2302 | udelay(500); | |
2303 | ||
0767935e | 2304 | intel_dp->DP |= DP_PLL_ENABLE; |
6fec7662 | 2305 | |
0767935e | 2306 | I915_WRITE(DP_A, intel_dp->DP); |
298b0b39 JB |
2307 | POSTING_READ(DP_A); |
2308 | udelay(200); | |
d240f20f JB |
2309 | } |
2310 | ||
2bd2ad64 | 2311 | static void ironlake_edp_pll_off(struct intel_dp *intel_dp) |
d240f20f | 2312 | { |
da63a9f2 | 2313 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
64e1077a VS |
2314 | struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc); |
2315 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); | |
d240f20f | 2316 | |
64e1077a VS |
2317 | assert_pipe_disabled(dev_priv, crtc->pipe); |
2318 | assert_dp_port_disabled(intel_dp); | |
2319 | assert_edp_pll_enabled(dev_priv); | |
2bd2ad64 | 2320 | |
abfce949 VS |
2321 | DRM_DEBUG_KMS("disabling eDP PLL\n"); |
2322 | ||
6fec7662 | 2323 | intel_dp->DP &= ~DP_PLL_ENABLE; |
0767935e | 2324 | |
6fec7662 | 2325 | I915_WRITE(DP_A, intel_dp->DP); |
1af5fa1b | 2326 | POSTING_READ(DP_A); |
d240f20f JB |
2327 | udelay(200); |
2328 | } | |
2329 | ||
c7ad3810 | 2330 | /* If the sink supports it, try to set the power state appropriately */ |
c19b0669 | 2331 | void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode) |
c7ad3810 JB |
2332 | { |
2333 | int ret, i; | |
2334 | ||
2335 | /* Should have a valid DPCD by this point */ | |
2336 | if (intel_dp->dpcd[DP_DPCD_REV] < 0x11) | |
2337 | return; | |
2338 | ||
2339 | if (mode != DRM_MODE_DPMS_ON) { | |
9d1a1031 JN |
2340 | ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER, |
2341 | DP_SET_POWER_D3); | |
c7ad3810 JB |
2342 | } else { |
2343 | /* | |
2344 | * When turning on, we need to retry for 1ms to give the sink | |
2345 | * time to wake up. | |
2346 | */ | |
2347 | for (i = 0; i < 3; i++) { | |
9d1a1031 JN |
2348 | ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER, |
2349 | DP_SET_POWER_D0); | |
c7ad3810 JB |
2350 | if (ret == 1) |
2351 | break; | |
2352 | msleep(1); | |
2353 | } | |
2354 | } | |
f9cac721 JN |
2355 | |
2356 | if (ret != 1) | |
2357 | DRM_DEBUG_KMS("failed to %s sink power state\n", | |
2358 | mode == DRM_MODE_DPMS_ON ? "enable" : "disable"); | |
c7ad3810 JB |
2359 | } |
2360 | ||
19d8fe15 DV |
2361 | static bool intel_dp_get_hw_state(struct intel_encoder *encoder, |
2362 | enum pipe *pipe) | |
d240f20f | 2363 | { |
19d8fe15 | 2364 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
bc7d38a4 | 2365 | enum port port = dp_to_dig_port(intel_dp)->port; |
19d8fe15 DV |
2366 | struct drm_device *dev = encoder->base.dev; |
2367 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6d129bea ID |
2368 | enum intel_display_power_domain power_domain; |
2369 | u32 tmp; | |
6fa9a5ec | 2370 | bool ret; |
6d129bea ID |
2371 | |
2372 | power_domain = intel_display_port_power_domain(encoder); | |
6fa9a5ec | 2373 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
6d129bea ID |
2374 | return false; |
2375 | ||
6fa9a5ec ID |
2376 | ret = false; |
2377 | ||
6d129bea | 2378 | tmp = I915_READ(intel_dp->output_reg); |
19d8fe15 DV |
2379 | |
2380 | if (!(tmp & DP_PORT_EN)) | |
6fa9a5ec | 2381 | goto out; |
19d8fe15 | 2382 | |
39e5fa88 | 2383 | if (IS_GEN7(dev) && port == PORT_A) { |
19d8fe15 | 2384 | *pipe = PORT_TO_PIPE_CPT(tmp); |
39e5fa88 | 2385 | } else if (HAS_PCH_CPT(dev) && port != PORT_A) { |
adc289d7 | 2386 | enum pipe p; |
19d8fe15 | 2387 | |
adc289d7 VS |
2388 | for_each_pipe(dev_priv, p) { |
2389 | u32 trans_dp = I915_READ(TRANS_DP_CTL(p)); | |
2390 | if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) { | |
2391 | *pipe = p; | |
6fa9a5ec ID |
2392 | ret = true; |
2393 | ||
2394 | goto out; | |
19d8fe15 DV |
2395 | } |
2396 | } | |
19d8fe15 | 2397 | |
4a0833ec | 2398 | DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n", |
f0f59a00 | 2399 | i915_mmio_reg_offset(intel_dp->output_reg)); |
39e5fa88 VS |
2400 | } else if (IS_CHERRYVIEW(dev)) { |
2401 | *pipe = DP_PORT_TO_PIPE_CHV(tmp); | |
2402 | } else { | |
2403 | *pipe = PORT_TO_PIPE(tmp); | |
4a0833ec | 2404 | } |
d240f20f | 2405 | |
6fa9a5ec ID |
2406 | ret = true; |
2407 | ||
2408 | out: | |
2409 | intel_display_power_put(dev_priv, power_domain); | |
2410 | ||
2411 | return ret; | |
19d8fe15 | 2412 | } |
d240f20f | 2413 | |
045ac3b5 | 2414 | static void intel_dp_get_config(struct intel_encoder *encoder, |
5cec258b | 2415 | struct intel_crtc_state *pipe_config) |
045ac3b5 JB |
2416 | { |
2417 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); | |
045ac3b5 | 2418 | u32 tmp, flags = 0; |
63000ef6 XZ |
2419 | struct drm_device *dev = encoder->base.dev; |
2420 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2421 | enum port port = dp_to_dig_port(intel_dp)->port; | |
2422 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); | |
045ac3b5 | 2423 | |
9ed109a7 | 2424 | tmp = I915_READ(intel_dp->output_reg); |
9fcb1704 JN |
2425 | |
2426 | pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A; | |
9ed109a7 | 2427 | |
39e5fa88 | 2428 | if (HAS_PCH_CPT(dev) && port != PORT_A) { |
b81e34c2 VS |
2429 | u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe)); |
2430 | ||
2431 | if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH) | |
63000ef6 XZ |
2432 | flags |= DRM_MODE_FLAG_PHSYNC; |
2433 | else | |
2434 | flags |= DRM_MODE_FLAG_NHSYNC; | |
045ac3b5 | 2435 | |
b81e34c2 | 2436 | if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH) |
63000ef6 XZ |
2437 | flags |= DRM_MODE_FLAG_PVSYNC; |
2438 | else | |
2439 | flags |= DRM_MODE_FLAG_NVSYNC; | |
2440 | } else { | |
39e5fa88 | 2441 | if (tmp & DP_SYNC_HS_HIGH) |
63000ef6 XZ |
2442 | flags |= DRM_MODE_FLAG_PHSYNC; |
2443 | else | |
2444 | flags |= DRM_MODE_FLAG_NHSYNC; | |
045ac3b5 | 2445 | |
39e5fa88 | 2446 | if (tmp & DP_SYNC_VS_HIGH) |
63000ef6 XZ |
2447 | flags |= DRM_MODE_FLAG_PVSYNC; |
2448 | else | |
2449 | flags |= DRM_MODE_FLAG_NVSYNC; | |
2450 | } | |
045ac3b5 | 2451 | |
2d112de7 | 2452 | pipe_config->base.adjusted_mode.flags |= flags; |
f1f644dc | 2453 | |
8c875fca | 2454 | if (!HAS_PCH_SPLIT(dev) && !IS_VALLEYVIEW(dev) && |
666a4537 | 2455 | !IS_CHERRYVIEW(dev) && tmp & DP_COLOR_RANGE_16_235) |
8c875fca VS |
2456 | pipe_config->limited_color_range = true; |
2457 | ||
eb14cb74 VS |
2458 | pipe_config->has_dp_encoder = true; |
2459 | ||
90a6b7b0 VS |
2460 | pipe_config->lane_count = |
2461 | ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1; | |
2462 | ||
eb14cb74 VS |
2463 | intel_dp_get_m_n(crtc, pipe_config); |
2464 | ||
18442d08 | 2465 | if (port == PORT_A) { |
b377e0df | 2466 | if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ) |
f1f644dc JB |
2467 | pipe_config->port_clock = 162000; |
2468 | else | |
2469 | pipe_config->port_clock = 270000; | |
2470 | } | |
18442d08 | 2471 | |
e3b247da VS |
2472 | pipe_config->base.adjusted_mode.crtc_clock = |
2473 | intel_dotclock_calculate(pipe_config->port_clock, | |
2474 | &pipe_config->dp_m_n); | |
7f16e5c1 | 2475 | |
c6cd2ee2 JN |
2476 | if (is_edp(intel_dp) && dev_priv->vbt.edp_bpp && |
2477 | pipe_config->pipe_bpp > dev_priv->vbt.edp_bpp) { | |
2478 | /* | |
2479 | * This is a big fat ugly hack. | |
2480 | * | |
2481 | * Some machines in UEFI boot mode provide us a VBT that has 18 | |
2482 | * bpp and 1.62 GHz link bandwidth for eDP, which for reasons | |
2483 | * unknown we fail to light up. Yet the same BIOS boots up with | |
2484 | * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as | |
2485 | * max, not what it tells us to use. | |
2486 | * | |
2487 | * Note: This will still be broken if the eDP panel is not lit | |
2488 | * up by the BIOS, and thus we can't get the mode at module | |
2489 | * load. | |
2490 | */ | |
2491 | DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n", | |
2492 | pipe_config->pipe_bpp, dev_priv->vbt.edp_bpp); | |
2493 | dev_priv->vbt.edp_bpp = pipe_config->pipe_bpp; | |
2494 | } | |
045ac3b5 JB |
2495 | } |
2496 | ||
e8cb4558 | 2497 | static void intel_disable_dp(struct intel_encoder *encoder) |
d240f20f | 2498 | { |
e8cb4558 | 2499 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
982a3866 | 2500 | struct drm_device *dev = encoder->base.dev; |
495a5bb8 JN |
2501 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
2502 | ||
6e3c9717 | 2503 | if (crtc->config->has_audio) |
495a5bb8 | 2504 | intel_audio_codec_disable(encoder); |
6cb49835 | 2505 | |
b32c6f48 RV |
2506 | if (HAS_PSR(dev) && !HAS_DDI(dev)) |
2507 | intel_psr_disable(intel_dp); | |
2508 | ||
6cb49835 DV |
2509 | /* Make sure the panel is off before trying to change the mode. But also |
2510 | * ensure that we have vdd while we switch off the panel. */ | |
24f3e092 | 2511 | intel_edp_panel_vdd_on(intel_dp); |
4be73780 | 2512 | intel_edp_backlight_off(intel_dp); |
fdbc3b1f | 2513 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF); |
4be73780 | 2514 | intel_edp_panel_off(intel_dp); |
3739850b | 2515 | |
08aff3fe VS |
2516 | /* disable the port before the pipe on g4x */ |
2517 | if (INTEL_INFO(dev)->gen < 5) | |
3739850b | 2518 | intel_dp_link_down(intel_dp); |
d240f20f JB |
2519 | } |
2520 | ||
08aff3fe | 2521 | static void ilk_post_disable_dp(struct intel_encoder *encoder) |
d240f20f | 2522 | { |
2bd2ad64 | 2523 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
982a3866 | 2524 | enum port port = dp_to_dig_port(intel_dp)->port; |
2bd2ad64 | 2525 | |
49277c31 | 2526 | intel_dp_link_down(intel_dp); |
abfce949 VS |
2527 | |
2528 | /* Only ilk+ has port A */ | |
08aff3fe VS |
2529 | if (port == PORT_A) |
2530 | ironlake_edp_pll_off(intel_dp); | |
49277c31 VS |
2531 | } |
2532 | ||
2533 | static void vlv_post_disable_dp(struct intel_encoder *encoder) | |
2534 | { | |
2535 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); | |
2536 | ||
2537 | intel_dp_link_down(intel_dp); | |
2bd2ad64 DV |
2538 | } |
2539 | ||
a8f327fb VS |
2540 | static void chv_data_lane_soft_reset(struct intel_encoder *encoder, |
2541 | bool reset) | |
580d3811 | 2542 | { |
a8f327fb VS |
2543 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
2544 | enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base)); | |
2545 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); | |
2546 | enum pipe pipe = crtc->pipe; | |
2547 | uint32_t val; | |
580d3811 | 2548 | |
a8f327fb VS |
2549 | val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW0(ch)); |
2550 | if (reset) | |
2551 | val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET); | |
2552 | else | |
2553 | val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET; | |
2554 | vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW0(ch), val); | |
580d3811 | 2555 | |
a8f327fb VS |
2556 | if (crtc->config->lane_count > 2) { |
2557 | val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW0(ch)); | |
2558 | if (reset) | |
2559 | val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET); | |
2560 | else | |
2561 | val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET; | |
2562 | vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW0(ch), val); | |
2563 | } | |
580d3811 | 2564 | |
97fd4d5c | 2565 | val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW1(ch)); |
d2152b25 | 2566 | val |= CHV_PCS_REQ_SOFTRESET_EN; |
a8f327fb VS |
2567 | if (reset) |
2568 | val &= ~DPIO_PCS_CLK_SOFT_RESET; | |
2569 | else | |
2570 | val |= DPIO_PCS_CLK_SOFT_RESET; | |
97fd4d5c | 2571 | vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW1(ch), val); |
d2152b25 | 2572 | |
a8f327fb | 2573 | if (crtc->config->lane_count > 2) { |
e0fce78f VS |
2574 | val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW1(ch)); |
2575 | val |= CHV_PCS_REQ_SOFTRESET_EN; | |
a8f327fb VS |
2576 | if (reset) |
2577 | val &= ~DPIO_PCS_CLK_SOFT_RESET; | |
2578 | else | |
2579 | val |= DPIO_PCS_CLK_SOFT_RESET; | |
e0fce78f VS |
2580 | vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW1(ch), val); |
2581 | } | |
a8f327fb | 2582 | } |
97fd4d5c | 2583 | |
a8f327fb VS |
2584 | static void chv_post_disable_dp(struct intel_encoder *encoder) |
2585 | { | |
2586 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); | |
2587 | struct drm_device *dev = encoder->base.dev; | |
2588 | struct drm_i915_private *dev_priv = dev->dev_private; | |
97fd4d5c | 2589 | |
a8f327fb VS |
2590 | intel_dp_link_down(intel_dp); |
2591 | ||
2592 | mutex_lock(&dev_priv->sb_lock); | |
2593 | ||
2594 | /* Assert data lane reset */ | |
2595 | chv_data_lane_soft_reset(encoder, true); | |
580d3811 | 2596 | |
a580516d | 2597 | mutex_unlock(&dev_priv->sb_lock); |
580d3811 VS |
2598 | } |
2599 | ||
7b13b58a VS |
2600 | static void |
2601 | _intel_dp_set_link_train(struct intel_dp *intel_dp, | |
2602 | uint32_t *DP, | |
2603 | uint8_t dp_train_pat) | |
2604 | { | |
2605 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); | |
2606 | struct drm_device *dev = intel_dig_port->base.base.dev; | |
2607 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2608 | enum port port = intel_dig_port->port; | |
2609 | ||
2610 | if (HAS_DDI(dev)) { | |
2611 | uint32_t temp = I915_READ(DP_TP_CTL(port)); | |
2612 | ||
2613 | if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE) | |
2614 | temp |= DP_TP_CTL_SCRAMBLE_DISABLE; | |
2615 | else | |
2616 | temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE; | |
2617 | ||
2618 | temp &= ~DP_TP_CTL_LINK_TRAIN_MASK; | |
2619 | switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) { | |
2620 | case DP_TRAINING_PATTERN_DISABLE: | |
2621 | temp |= DP_TP_CTL_LINK_TRAIN_NORMAL; | |
2622 | ||
2623 | break; | |
2624 | case DP_TRAINING_PATTERN_1: | |
2625 | temp |= DP_TP_CTL_LINK_TRAIN_PAT1; | |
2626 | break; | |
2627 | case DP_TRAINING_PATTERN_2: | |
2628 | temp |= DP_TP_CTL_LINK_TRAIN_PAT2; | |
2629 | break; | |
2630 | case DP_TRAINING_PATTERN_3: | |
2631 | temp |= DP_TP_CTL_LINK_TRAIN_PAT3; | |
2632 | break; | |
2633 | } | |
2634 | I915_WRITE(DP_TP_CTL(port), temp); | |
2635 | ||
39e5fa88 VS |
2636 | } else if ((IS_GEN7(dev) && port == PORT_A) || |
2637 | (HAS_PCH_CPT(dev) && port != PORT_A)) { | |
7b13b58a VS |
2638 | *DP &= ~DP_LINK_TRAIN_MASK_CPT; |
2639 | ||
2640 | switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) { | |
2641 | case DP_TRAINING_PATTERN_DISABLE: | |
2642 | *DP |= DP_LINK_TRAIN_OFF_CPT; | |
2643 | break; | |
2644 | case DP_TRAINING_PATTERN_1: | |
2645 | *DP |= DP_LINK_TRAIN_PAT_1_CPT; | |
2646 | break; | |
2647 | case DP_TRAINING_PATTERN_2: | |
2648 | *DP |= DP_LINK_TRAIN_PAT_2_CPT; | |
2649 | break; | |
2650 | case DP_TRAINING_PATTERN_3: | |
2651 | DRM_ERROR("DP training pattern 3 not supported\n"); | |
2652 | *DP |= DP_LINK_TRAIN_PAT_2_CPT; | |
2653 | break; | |
2654 | } | |
2655 | ||
2656 | } else { | |
2657 | if (IS_CHERRYVIEW(dev)) | |
2658 | *DP &= ~DP_LINK_TRAIN_MASK_CHV; | |
2659 | else | |
2660 | *DP &= ~DP_LINK_TRAIN_MASK; | |
2661 | ||
2662 | switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) { | |
2663 | case DP_TRAINING_PATTERN_DISABLE: | |
2664 | *DP |= DP_LINK_TRAIN_OFF; | |
2665 | break; | |
2666 | case DP_TRAINING_PATTERN_1: | |
2667 | *DP |= DP_LINK_TRAIN_PAT_1; | |
2668 | break; | |
2669 | case DP_TRAINING_PATTERN_2: | |
2670 | *DP |= DP_LINK_TRAIN_PAT_2; | |
2671 | break; | |
2672 | case DP_TRAINING_PATTERN_3: | |
2673 | if (IS_CHERRYVIEW(dev)) { | |
2674 | *DP |= DP_LINK_TRAIN_PAT_3_CHV; | |
2675 | } else { | |
2676 | DRM_ERROR("DP training pattern 3 not supported\n"); | |
2677 | *DP |= DP_LINK_TRAIN_PAT_2; | |
2678 | } | |
2679 | break; | |
2680 | } | |
2681 | } | |
2682 | } | |
2683 | ||
2684 | static void intel_dp_enable_port(struct intel_dp *intel_dp) | |
2685 | { | |
2686 | struct drm_device *dev = intel_dp_to_dev(intel_dp); | |
2687 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6fec7662 VS |
2688 | struct intel_crtc *crtc = |
2689 | to_intel_crtc(dp_to_dig_port(intel_dp)->base.base.crtc); | |
7b13b58a | 2690 | |
7b13b58a VS |
2691 | /* enable with pattern 1 (as per spec) */ |
2692 | _intel_dp_set_link_train(intel_dp, &intel_dp->DP, | |
2693 | DP_TRAINING_PATTERN_1); | |
2694 | ||
2695 | I915_WRITE(intel_dp->output_reg, intel_dp->DP); | |
2696 | POSTING_READ(intel_dp->output_reg); | |
7b713f50 VS |
2697 | |
2698 | /* | |
2699 | * Magic for VLV/CHV. We _must_ first set up the register | |
2700 | * without actually enabling the port, and then do another | |
2701 | * write to enable the port. Otherwise link training will | |
2702 | * fail when the power sequencer is freshly used for this port. | |
2703 | */ | |
2704 | intel_dp->DP |= DP_PORT_EN; | |
6fec7662 VS |
2705 | if (crtc->config->has_audio) |
2706 | intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE; | |
7b713f50 VS |
2707 | |
2708 | I915_WRITE(intel_dp->output_reg, intel_dp->DP); | |
2709 | POSTING_READ(intel_dp->output_reg); | |
580d3811 VS |
2710 | } |
2711 | ||
e8cb4558 | 2712 | static void intel_enable_dp(struct intel_encoder *encoder) |
d240f20f | 2713 | { |
e8cb4558 DV |
2714 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
2715 | struct drm_device *dev = encoder->base.dev; | |
2716 | struct drm_i915_private *dev_priv = dev->dev_private; | |
c1dec79a | 2717 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
e8cb4558 | 2718 | uint32_t dp_reg = I915_READ(intel_dp->output_reg); |
d6fbdd15 VS |
2719 | enum port port = dp_to_dig_port(intel_dp)->port; |
2720 | enum pipe pipe = crtc->pipe; | |
5d613501 | 2721 | |
0c33d8d7 DV |
2722 | if (WARN_ON(dp_reg & DP_PORT_EN)) |
2723 | return; | |
5d613501 | 2724 | |
093e3f13 VS |
2725 | pps_lock(intel_dp); |
2726 | ||
666a4537 | 2727 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) |
093e3f13 VS |
2728 | vlv_init_panel_power_sequencer(intel_dp); |
2729 | ||
7864578a VS |
2730 | /* |
2731 | * We get an occasional spurious underrun between the port | |
2732 | * enable and vdd enable, when enabling port A eDP. | |
2733 | * | |
2734 | * FIXME: Not sure if this applies to (PCH) port D eDP as well | |
2735 | */ | |
2736 | if (port == PORT_A) | |
2737 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
2738 | ||
7b13b58a | 2739 | intel_dp_enable_port(intel_dp); |
093e3f13 | 2740 | |
d6fbdd15 VS |
2741 | if (port == PORT_A && IS_GEN5(dev_priv)) { |
2742 | /* | |
2743 | * Underrun reporting for the other pipe was disabled in | |
2744 | * g4x_pre_enable_dp(). The eDP PLL and port have now been | |
2745 | * enabled, so it's now safe to re-enable underrun reporting. | |
2746 | */ | |
2747 | intel_wait_for_vblank_if_active(dev_priv->dev, !pipe); | |
2748 | intel_set_cpu_fifo_underrun_reporting(dev_priv, !pipe, true); | |
2749 | intel_set_pch_fifo_underrun_reporting(dev_priv, !pipe, true); | |
2750 | } | |
2751 | ||
093e3f13 VS |
2752 | edp_panel_vdd_on(intel_dp); |
2753 | edp_panel_on(intel_dp); | |
2754 | edp_panel_vdd_off(intel_dp, true); | |
2755 | ||
7864578a VS |
2756 | if (port == PORT_A) |
2757 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); | |
2758 | ||
093e3f13 VS |
2759 | pps_unlock(intel_dp); |
2760 | ||
666a4537 | 2761 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
e0fce78f VS |
2762 | unsigned int lane_mask = 0x0; |
2763 | ||
2764 | if (IS_CHERRYVIEW(dev)) | |
2765 | lane_mask = intel_dp_unused_lane_mask(crtc->config->lane_count); | |
2766 | ||
9b6de0a1 VS |
2767 | vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp), |
2768 | lane_mask); | |
e0fce78f | 2769 | } |
61234fa5 | 2770 | |
f01eca2e | 2771 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); |
33a34e4e | 2772 | intel_dp_start_link_train(intel_dp); |
3ab9c637 | 2773 | intel_dp_stop_link_train(intel_dp); |
c1dec79a | 2774 | |
6e3c9717 | 2775 | if (crtc->config->has_audio) { |
c1dec79a | 2776 | DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n", |
d6fbdd15 | 2777 | pipe_name(pipe)); |
c1dec79a JN |
2778 | intel_audio_codec_enable(encoder); |
2779 | } | |
ab1f90f9 | 2780 | } |
89b667f8 | 2781 | |
ecff4f3b JN |
2782 | static void g4x_enable_dp(struct intel_encoder *encoder) |
2783 | { | |
828f5c6e JN |
2784 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
2785 | ||
ecff4f3b | 2786 | intel_enable_dp(encoder); |
4be73780 | 2787 | intel_edp_backlight_on(intel_dp); |
ab1f90f9 | 2788 | } |
89b667f8 | 2789 | |
ab1f90f9 JN |
2790 | static void vlv_enable_dp(struct intel_encoder *encoder) |
2791 | { | |
828f5c6e JN |
2792 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
2793 | ||
4be73780 | 2794 | intel_edp_backlight_on(intel_dp); |
b32c6f48 | 2795 | intel_psr_enable(intel_dp); |
d240f20f JB |
2796 | } |
2797 | ||
ecff4f3b | 2798 | static void g4x_pre_enable_dp(struct intel_encoder *encoder) |
ab1f90f9 | 2799 | { |
d6fbdd15 | 2800 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
ab1f90f9 | 2801 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
d6fbdd15 VS |
2802 | enum port port = dp_to_dig_port(intel_dp)->port; |
2803 | enum pipe pipe = to_intel_crtc(encoder->base.crtc)->pipe; | |
ab1f90f9 | 2804 | |
8ac33ed3 DV |
2805 | intel_dp_prepare(encoder); |
2806 | ||
d6fbdd15 VS |
2807 | if (port == PORT_A && IS_GEN5(dev_priv)) { |
2808 | /* | |
2809 | * We get FIFO underruns on the other pipe when | |
2810 | * enabling the CPU eDP PLL, and when enabling CPU | |
2811 | * eDP port. We could potentially avoid the PLL | |
2812 | * underrun with a vblank wait just prior to enabling | |
2813 | * the PLL, but that doesn't appear to help the port | |
2814 | * enable case. Just sweep it all under the rug. | |
2815 | */ | |
2816 | intel_set_cpu_fifo_underrun_reporting(dev_priv, !pipe, false); | |
2817 | intel_set_pch_fifo_underrun_reporting(dev_priv, !pipe, false); | |
2818 | } | |
2819 | ||
d41f1efb | 2820 | /* Only ilk+ has port A */ |
abfce949 | 2821 | if (port == PORT_A) |
ab1f90f9 JN |
2822 | ironlake_edp_pll_on(intel_dp); |
2823 | } | |
2824 | ||
83b84597 VS |
2825 | static void vlv_detach_power_sequencer(struct intel_dp *intel_dp) |
2826 | { | |
2827 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); | |
2828 | struct drm_i915_private *dev_priv = intel_dig_port->base.base.dev->dev_private; | |
2829 | enum pipe pipe = intel_dp->pps_pipe; | |
f0f59a00 | 2830 | i915_reg_t pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe); |
83b84597 VS |
2831 | |
2832 | edp_panel_vdd_off_sync(intel_dp); | |
2833 | ||
2834 | /* | |
2835 | * VLV seems to get confused when multiple power seqeuencers | |
2836 | * have the same port selected (even if only one has power/vdd | |
2837 | * enabled). The failure manifests as vlv_wait_port_ready() failing | |
2838 | * CHV on the other hand doesn't seem to mind having the same port | |
2839 | * selected in multiple power seqeuencers, but let's clear the | |
2840 | * port select always when logically disconnecting a power sequencer | |
2841 | * from a port. | |
2842 | */ | |
2843 | DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n", | |
2844 | pipe_name(pipe), port_name(intel_dig_port->port)); | |
2845 | I915_WRITE(pp_on_reg, 0); | |
2846 | POSTING_READ(pp_on_reg); | |
2847 | ||
2848 | intel_dp->pps_pipe = INVALID_PIPE; | |
2849 | } | |
2850 | ||
a4a5d2f8 VS |
2851 | static void vlv_steal_power_sequencer(struct drm_device *dev, |
2852 | enum pipe pipe) | |
2853 | { | |
2854 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2855 | struct intel_encoder *encoder; | |
2856 | ||
2857 | lockdep_assert_held(&dev_priv->pps_mutex); | |
2858 | ||
ac3c12e4 VS |
2859 | if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B)) |
2860 | return; | |
2861 | ||
19c8054c | 2862 | for_each_intel_encoder(dev, encoder) { |
a4a5d2f8 | 2863 | struct intel_dp *intel_dp; |
773538e8 | 2864 | enum port port; |
a4a5d2f8 VS |
2865 | |
2866 | if (encoder->type != INTEL_OUTPUT_EDP) | |
2867 | continue; | |
2868 | ||
2869 | intel_dp = enc_to_intel_dp(&encoder->base); | |
773538e8 | 2870 | port = dp_to_dig_port(intel_dp)->port; |
a4a5d2f8 VS |
2871 | |
2872 | if (intel_dp->pps_pipe != pipe) | |
2873 | continue; | |
2874 | ||
2875 | DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n", | |
773538e8 | 2876 | pipe_name(pipe), port_name(port)); |
a4a5d2f8 | 2877 | |
e02f9a06 | 2878 | WARN(encoder->base.crtc, |
034e43c6 VS |
2879 | "stealing pipe %c power sequencer from active eDP port %c\n", |
2880 | pipe_name(pipe), port_name(port)); | |
a4a5d2f8 | 2881 | |
a4a5d2f8 | 2882 | /* make sure vdd is off before we steal it */ |
83b84597 | 2883 | vlv_detach_power_sequencer(intel_dp); |
a4a5d2f8 VS |
2884 | } |
2885 | } | |
2886 | ||
2887 | static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp) | |
2888 | { | |
2889 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); | |
2890 | struct intel_encoder *encoder = &intel_dig_port->base; | |
2891 | struct drm_device *dev = encoder->base.dev; | |
2892 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2893 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); | |
a4a5d2f8 VS |
2894 | |
2895 | lockdep_assert_held(&dev_priv->pps_mutex); | |
2896 | ||
093e3f13 VS |
2897 | if (!is_edp(intel_dp)) |
2898 | return; | |
2899 | ||
a4a5d2f8 VS |
2900 | if (intel_dp->pps_pipe == crtc->pipe) |
2901 | return; | |
2902 | ||
2903 | /* | |
2904 | * If another power sequencer was being used on this | |
2905 | * port previously make sure to turn off vdd there while | |
2906 | * we still have control of it. | |
2907 | */ | |
2908 | if (intel_dp->pps_pipe != INVALID_PIPE) | |
83b84597 | 2909 | vlv_detach_power_sequencer(intel_dp); |
a4a5d2f8 VS |
2910 | |
2911 | /* | |
2912 | * We may be stealing the power | |
2913 | * sequencer from another port. | |
2914 | */ | |
2915 | vlv_steal_power_sequencer(dev, crtc->pipe); | |
2916 | ||
2917 | /* now it's all ours */ | |
2918 | intel_dp->pps_pipe = crtc->pipe; | |
2919 | ||
2920 | DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n", | |
2921 | pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port)); | |
2922 | ||
2923 | /* init power sequencer on this pipe and port */ | |
36b5f425 VS |
2924 | intel_dp_init_panel_power_sequencer(dev, intel_dp); |
2925 | intel_dp_init_panel_power_sequencer_registers(dev, intel_dp); | |
a4a5d2f8 VS |
2926 | } |
2927 | ||
ab1f90f9 | 2928 | static void vlv_pre_enable_dp(struct intel_encoder *encoder) |
a4fc5ed6 | 2929 | { |
2bd2ad64 | 2930 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
bc7d38a4 | 2931 | struct intel_digital_port *dport = dp_to_dig_port(intel_dp); |
b2634017 | 2932 | struct drm_device *dev = encoder->base.dev; |
89b667f8 | 2933 | struct drm_i915_private *dev_priv = dev->dev_private; |
ab1f90f9 | 2934 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc); |
e4607fcf | 2935 | enum dpio_channel port = vlv_dport_to_channel(dport); |
ab1f90f9 JN |
2936 | int pipe = intel_crtc->pipe; |
2937 | u32 val; | |
a4fc5ed6 | 2938 | |
a580516d | 2939 | mutex_lock(&dev_priv->sb_lock); |
89b667f8 | 2940 | |
ab3c759a | 2941 | val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(port)); |
ab1f90f9 JN |
2942 | val = 0; |
2943 | if (pipe) | |
2944 | val |= (1<<21); | |
2945 | else | |
2946 | val &= ~(1<<21); | |
2947 | val |= 0x001000c4; | |
ab3c759a CML |
2948 | vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW8(port), val); |
2949 | vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW14(port), 0x00760018); | |
2950 | vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW23(port), 0x00400888); | |
89b667f8 | 2951 | |
a580516d | 2952 | mutex_unlock(&dev_priv->sb_lock); |
ab1f90f9 JN |
2953 | |
2954 | intel_enable_dp(encoder); | |
89b667f8 JB |
2955 | } |
2956 | ||
ecff4f3b | 2957 | static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder) |
89b667f8 JB |
2958 | { |
2959 | struct intel_digital_port *dport = enc_to_dig_port(&encoder->base); | |
2960 | struct drm_device *dev = encoder->base.dev; | |
2961 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5e69f97f CML |
2962 | struct intel_crtc *intel_crtc = |
2963 | to_intel_crtc(encoder->base.crtc); | |
e4607fcf | 2964 | enum dpio_channel port = vlv_dport_to_channel(dport); |
5e69f97f | 2965 | int pipe = intel_crtc->pipe; |
89b667f8 | 2966 | |
8ac33ed3 DV |
2967 | intel_dp_prepare(encoder); |
2968 | ||
89b667f8 | 2969 | /* Program Tx lane resets to default */ |
a580516d | 2970 | mutex_lock(&dev_priv->sb_lock); |
ab3c759a | 2971 | vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port), |
89b667f8 JB |
2972 | DPIO_PCS_TX_LANE2_RESET | |
2973 | DPIO_PCS_TX_LANE1_RESET); | |
ab3c759a | 2974 | vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port), |
89b667f8 JB |
2975 | DPIO_PCS_CLK_CRI_RXEB_EIOS_EN | |
2976 | DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN | | |
2977 | (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) | | |
2978 | DPIO_PCS_CLK_SOFT_RESET); | |
2979 | ||
2980 | /* Fix up inter-pair skew failure */ | |
ab3c759a CML |
2981 | vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW12(port), 0x00750f00); |
2982 | vlv_dpio_write(dev_priv, pipe, VLV_TX_DW11(port), 0x00001500); | |
2983 | vlv_dpio_write(dev_priv, pipe, VLV_TX_DW14(port), 0x40400000); | |
a580516d | 2984 | mutex_unlock(&dev_priv->sb_lock); |
a4fc5ed6 KP |
2985 | } |
2986 | ||
e4a1d846 CML |
2987 | static void chv_pre_enable_dp(struct intel_encoder *encoder) |
2988 | { | |
2989 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); | |
2990 | struct intel_digital_port *dport = dp_to_dig_port(intel_dp); | |
2991 | struct drm_device *dev = encoder->base.dev; | |
2992 | struct drm_i915_private *dev_priv = dev->dev_private; | |
e4a1d846 CML |
2993 | struct intel_crtc *intel_crtc = |
2994 | to_intel_crtc(encoder->base.crtc); | |
2995 | enum dpio_channel ch = vlv_dport_to_channel(dport); | |
2996 | int pipe = intel_crtc->pipe; | |
2e523e98 | 2997 | int data, i, stagger; |
949c1d43 | 2998 | u32 val; |
e4a1d846 | 2999 | |
a580516d | 3000 | mutex_lock(&dev_priv->sb_lock); |
949c1d43 | 3001 | |
570e2a74 VS |
3002 | /* allow hardware to manage TX FIFO reset source */ |
3003 | val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch)); | |
3004 | val &= ~DPIO_LANEDESKEW_STRAP_OVRD; | |
3005 | vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val); | |
3006 | ||
e0fce78f VS |
3007 | if (intel_crtc->config->lane_count > 2) { |
3008 | val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch)); | |
3009 | val &= ~DPIO_LANEDESKEW_STRAP_OVRD; | |
3010 | vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val); | |
3011 | } | |
570e2a74 | 3012 | |
949c1d43 | 3013 | /* Program Tx lane latency optimal setting*/ |
e0fce78f | 3014 | for (i = 0; i < intel_crtc->config->lane_count; i++) { |
e4a1d846 | 3015 | /* Set the upar bit */ |
e0fce78f VS |
3016 | if (intel_crtc->config->lane_count == 1) |
3017 | data = 0x0; | |
3018 | else | |
3019 | data = (i == 1) ? 0x0 : 0x1; | |
e4a1d846 CML |
3020 | vlv_dpio_write(dev_priv, pipe, CHV_TX_DW14(ch, i), |
3021 | data << DPIO_UPAR_SHIFT); | |
3022 | } | |
3023 | ||
3024 | /* Data lane stagger programming */ | |
2e523e98 VS |
3025 | if (intel_crtc->config->port_clock > 270000) |
3026 | stagger = 0x18; | |
3027 | else if (intel_crtc->config->port_clock > 135000) | |
3028 | stagger = 0xd; | |
3029 | else if (intel_crtc->config->port_clock > 67500) | |
3030 | stagger = 0x7; | |
3031 | else if (intel_crtc->config->port_clock > 33750) | |
3032 | stagger = 0x4; | |
3033 | else | |
3034 | stagger = 0x2; | |
3035 | ||
3036 | val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch)); | |
3037 | val |= DPIO_TX2_STAGGER_MASK(0x1f); | |
3038 | vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val); | |
3039 | ||
e0fce78f VS |
3040 | if (intel_crtc->config->lane_count > 2) { |
3041 | val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch)); | |
3042 | val |= DPIO_TX2_STAGGER_MASK(0x1f); | |
3043 | vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val); | |
3044 | } | |
2e523e98 VS |
3045 | |
3046 | vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW12(ch), | |
3047 | DPIO_LANESTAGGER_STRAP(stagger) | | |
3048 | DPIO_LANESTAGGER_STRAP_OVRD | | |
3049 | DPIO_TX1_STAGGER_MASK(0x1f) | | |
3050 | DPIO_TX1_STAGGER_MULT(6) | | |
3051 | DPIO_TX2_STAGGER_MULT(0)); | |
3052 | ||
e0fce78f VS |
3053 | if (intel_crtc->config->lane_count > 2) { |
3054 | vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW12(ch), | |
3055 | DPIO_LANESTAGGER_STRAP(stagger) | | |
3056 | DPIO_LANESTAGGER_STRAP_OVRD | | |
3057 | DPIO_TX1_STAGGER_MASK(0x1f) | | |
3058 | DPIO_TX1_STAGGER_MULT(7) | | |
3059 | DPIO_TX2_STAGGER_MULT(5)); | |
3060 | } | |
e4a1d846 | 3061 | |
a8f327fb VS |
3062 | /* Deassert data lane reset */ |
3063 | chv_data_lane_soft_reset(encoder, false); | |
3064 | ||
a580516d | 3065 | mutex_unlock(&dev_priv->sb_lock); |
e4a1d846 | 3066 | |
e4a1d846 | 3067 | intel_enable_dp(encoder); |
b0b33846 VS |
3068 | |
3069 | /* Second common lane will stay alive on its own now */ | |
3070 | if (dport->release_cl2_override) { | |
3071 | chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, false); | |
3072 | dport->release_cl2_override = false; | |
3073 | } | |
e4a1d846 CML |
3074 | } |
3075 | ||
9197c88b VS |
3076 | static void chv_dp_pre_pll_enable(struct intel_encoder *encoder) |
3077 | { | |
3078 | struct intel_digital_port *dport = enc_to_dig_port(&encoder->base); | |
3079 | struct drm_device *dev = encoder->base.dev; | |
3080 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3081 | struct intel_crtc *intel_crtc = | |
3082 | to_intel_crtc(encoder->base.crtc); | |
3083 | enum dpio_channel ch = vlv_dport_to_channel(dport); | |
3084 | enum pipe pipe = intel_crtc->pipe; | |
e0fce78f VS |
3085 | unsigned int lane_mask = |
3086 | intel_dp_unused_lane_mask(intel_crtc->config->lane_count); | |
9197c88b VS |
3087 | u32 val; |
3088 | ||
625695f8 VS |
3089 | intel_dp_prepare(encoder); |
3090 | ||
b0b33846 VS |
3091 | /* |
3092 | * Must trick the second common lane into life. | |
3093 | * Otherwise we can't even access the PLL. | |
3094 | */ | |
3095 | if (ch == DPIO_CH0 && pipe == PIPE_B) | |
3096 | dport->release_cl2_override = | |
3097 | !chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, true); | |
3098 | ||
e0fce78f VS |
3099 | chv_phy_powergate_lanes(encoder, true, lane_mask); |
3100 | ||
a580516d | 3101 | mutex_lock(&dev_priv->sb_lock); |
9197c88b | 3102 | |
a8f327fb VS |
3103 | /* Assert data lane reset */ |
3104 | chv_data_lane_soft_reset(encoder, true); | |
3105 | ||
b9e5ac3c VS |
3106 | /* program left/right clock distribution */ |
3107 | if (pipe != PIPE_B) { | |
3108 | val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0); | |
3109 | val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK); | |
3110 | if (ch == DPIO_CH0) | |
3111 | val |= CHV_BUFLEFTENA1_FORCE; | |
3112 | if (ch == DPIO_CH1) | |
3113 | val |= CHV_BUFRIGHTENA1_FORCE; | |
3114 | vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val); | |
3115 | } else { | |
3116 | val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1); | |
3117 | val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK); | |
3118 | if (ch == DPIO_CH0) | |
3119 | val |= CHV_BUFLEFTENA2_FORCE; | |
3120 | if (ch == DPIO_CH1) | |
3121 | val |= CHV_BUFRIGHTENA2_FORCE; | |
3122 | vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val); | |
3123 | } | |
3124 | ||
9197c88b VS |
3125 | /* program clock channel usage */ |
3126 | val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(ch)); | |
3127 | val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE; | |
3128 | if (pipe != PIPE_B) | |
3129 | val &= ~CHV_PCS_USEDCLKCHANNEL; | |
3130 | else | |
3131 | val |= CHV_PCS_USEDCLKCHANNEL; | |
3132 | vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW8(ch), val); | |
3133 | ||
e0fce78f VS |
3134 | if (intel_crtc->config->lane_count > 2) { |
3135 | val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW8(ch)); | |
3136 | val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE; | |
3137 | if (pipe != PIPE_B) | |
3138 | val &= ~CHV_PCS_USEDCLKCHANNEL; | |
3139 | else | |
3140 | val |= CHV_PCS_USEDCLKCHANNEL; | |
3141 | vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW8(ch), val); | |
3142 | } | |
9197c88b VS |
3143 | |
3144 | /* | |
3145 | * This a a bit weird since generally CL | |
3146 | * matches the pipe, but here we need to | |
3147 | * pick the CL based on the port. | |
3148 | */ | |
3149 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW19(ch)); | |
3150 | if (pipe != PIPE_B) | |
3151 | val &= ~CHV_CMN_USEDCLKCHANNEL; | |
3152 | else | |
3153 | val |= CHV_CMN_USEDCLKCHANNEL; | |
3154 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW19(ch), val); | |
3155 | ||
a580516d | 3156 | mutex_unlock(&dev_priv->sb_lock); |
9197c88b VS |
3157 | } |
3158 | ||
d6db995f VS |
3159 | static void chv_dp_post_pll_disable(struct intel_encoder *encoder) |
3160 | { | |
3161 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); | |
3162 | enum pipe pipe = to_intel_crtc(encoder->base.crtc)->pipe; | |
3163 | u32 val; | |
3164 | ||
3165 | mutex_lock(&dev_priv->sb_lock); | |
3166 | ||
3167 | /* disable left/right clock distribution */ | |
3168 | if (pipe != PIPE_B) { | |
3169 | val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0); | |
3170 | val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK); | |
3171 | vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val); | |
3172 | } else { | |
3173 | val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1); | |
3174 | val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK); | |
3175 | vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val); | |
3176 | } | |
3177 | ||
3178 | mutex_unlock(&dev_priv->sb_lock); | |
e0fce78f | 3179 | |
b0b33846 VS |
3180 | /* |
3181 | * Leave the power down bit cleared for at least one | |
3182 | * lane so that chv_powergate_phy_ch() will power | |
3183 | * on something when the channel is otherwise unused. | |
3184 | * When the port is off and the override is removed | |
3185 | * the lanes power down anyway, so otherwise it doesn't | |
3186 | * really matter what the state of power down bits is | |
3187 | * after this. | |
3188 | */ | |
e0fce78f | 3189 | chv_phy_powergate_lanes(encoder, false, 0x0); |
d6db995f VS |
3190 | } |
3191 | ||
a4fc5ed6 | 3192 | /* |
df0c237d JB |
3193 | * Native read with retry for link status and receiver capability reads for |
3194 | * cases where the sink may still be asleep. | |
9d1a1031 JN |
3195 | * |
3196 | * Sinks are *supposed* to come up within 1ms from an off state, but we're also | |
3197 | * supposed to retry 3 times per the spec. | |
a4fc5ed6 | 3198 | */ |
9d1a1031 JN |
3199 | static ssize_t |
3200 | intel_dp_dpcd_read_wake(struct drm_dp_aux *aux, unsigned int offset, | |
3201 | void *buffer, size_t size) | |
a4fc5ed6 | 3202 | { |
9d1a1031 JN |
3203 | ssize_t ret; |
3204 | int i; | |
61da5fab | 3205 | |
f6a19066 VS |
3206 | /* |
3207 | * Sometime we just get the same incorrect byte repeated | |
3208 | * over the entire buffer. Doing just one throw away read | |
3209 | * initially seems to "solve" it. | |
3210 | */ | |
3211 | drm_dp_dpcd_read(aux, DP_DPCD_REV, buffer, 1); | |
3212 | ||
61da5fab | 3213 | for (i = 0; i < 3; i++) { |
9d1a1031 JN |
3214 | ret = drm_dp_dpcd_read(aux, offset, buffer, size); |
3215 | if (ret == size) | |
3216 | return ret; | |
61da5fab JB |
3217 | msleep(1); |
3218 | } | |
a4fc5ed6 | 3219 | |
9d1a1031 | 3220 | return ret; |
a4fc5ed6 KP |
3221 | } |
3222 | ||
3223 | /* | |
3224 | * Fetch AUX CH registers 0x202 - 0x207 which contain | |
3225 | * link status information | |
3226 | */ | |
94223d04 | 3227 | bool |
93f62dad | 3228 | intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE]) |
a4fc5ed6 | 3229 | { |
9d1a1031 JN |
3230 | return intel_dp_dpcd_read_wake(&intel_dp->aux, |
3231 | DP_LANE0_1_STATUS, | |
3232 | link_status, | |
3233 | DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE; | |
a4fc5ed6 KP |
3234 | } |
3235 | ||
1100244e | 3236 | /* These are source-specific values. */ |
94223d04 | 3237 | uint8_t |
1a2eb460 | 3238 | intel_dp_voltage_max(struct intel_dp *intel_dp) |
a4fc5ed6 | 3239 | { |
30add22d | 3240 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
7ad14a29 | 3241 | struct drm_i915_private *dev_priv = dev->dev_private; |
bc7d38a4 | 3242 | enum port port = dp_to_dig_port(intel_dp)->port; |
1a2eb460 | 3243 | |
9314726b VK |
3244 | if (IS_BROXTON(dev)) |
3245 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_3; | |
3246 | else if (INTEL_INFO(dev)->gen >= 9) { | |
9e458034 | 3247 | if (dev_priv->edp_low_vswing && port == PORT_A) |
7ad14a29 | 3248 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_3; |
5a9d1f1a | 3249 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_2; |
666a4537 | 3250 | } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) |
bd60018a | 3251 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_3; |
bc7d38a4 | 3252 | else if (IS_GEN7(dev) && port == PORT_A) |
bd60018a | 3253 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_2; |
bc7d38a4 | 3254 | else if (HAS_PCH_CPT(dev) && port != PORT_A) |
bd60018a | 3255 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_3; |
1a2eb460 | 3256 | else |
bd60018a | 3257 | return DP_TRAIN_VOLTAGE_SWING_LEVEL_2; |
1a2eb460 KP |
3258 | } |
3259 | ||
94223d04 | 3260 | uint8_t |
1a2eb460 KP |
3261 | intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing) |
3262 | { | |
30add22d | 3263 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
bc7d38a4 | 3264 | enum port port = dp_to_dig_port(intel_dp)->port; |
1a2eb460 | 3265 | |
5a9d1f1a DL |
3266 | if (INTEL_INFO(dev)->gen >= 9) { |
3267 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { | |
3268 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: | |
3269 | return DP_TRAIN_PRE_EMPH_LEVEL_3; | |
3270 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: | |
3271 | return DP_TRAIN_PRE_EMPH_LEVEL_2; | |
3272 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: | |
3273 | return DP_TRAIN_PRE_EMPH_LEVEL_1; | |
7ad14a29 SJ |
3274 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
3275 | return DP_TRAIN_PRE_EMPH_LEVEL_0; | |
5a9d1f1a DL |
3276 | default: |
3277 | return DP_TRAIN_PRE_EMPH_LEVEL_0; | |
3278 | } | |
3279 | } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { | |
d6c0d722 | 3280 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
bd60018a SJ |
3281 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
3282 | return DP_TRAIN_PRE_EMPH_LEVEL_3; | |
3283 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: | |
3284 | return DP_TRAIN_PRE_EMPH_LEVEL_2; | |
3285 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: | |
3286 | return DP_TRAIN_PRE_EMPH_LEVEL_1; | |
3287 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: | |
d6c0d722 | 3288 | default: |
bd60018a | 3289 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
d6c0d722 | 3290 | } |
666a4537 | 3291 | } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
e2fa6fba | 3292 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
bd60018a SJ |
3293 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
3294 | return DP_TRAIN_PRE_EMPH_LEVEL_3; | |
3295 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: | |
3296 | return DP_TRAIN_PRE_EMPH_LEVEL_2; | |
3297 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: | |
3298 | return DP_TRAIN_PRE_EMPH_LEVEL_1; | |
3299 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: | |
e2fa6fba | 3300 | default: |
bd60018a | 3301 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
e2fa6fba | 3302 | } |
bc7d38a4 | 3303 | } else if (IS_GEN7(dev) && port == PORT_A) { |
1a2eb460 | 3304 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
bd60018a SJ |
3305 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
3306 | return DP_TRAIN_PRE_EMPH_LEVEL_2; | |
3307 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: | |
3308 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: | |
3309 | return DP_TRAIN_PRE_EMPH_LEVEL_1; | |
1a2eb460 | 3310 | default: |
bd60018a | 3311 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
1a2eb460 KP |
3312 | } |
3313 | } else { | |
3314 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { | |
bd60018a SJ |
3315 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
3316 | return DP_TRAIN_PRE_EMPH_LEVEL_2; | |
3317 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: | |
3318 | return DP_TRAIN_PRE_EMPH_LEVEL_2; | |
3319 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: | |
3320 | return DP_TRAIN_PRE_EMPH_LEVEL_1; | |
3321 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: | |
1a2eb460 | 3322 | default: |
bd60018a | 3323 | return DP_TRAIN_PRE_EMPH_LEVEL_0; |
1a2eb460 | 3324 | } |
a4fc5ed6 KP |
3325 | } |
3326 | } | |
3327 | ||
5829975c | 3328 | static uint32_t vlv_signal_levels(struct intel_dp *intel_dp) |
e2fa6fba P |
3329 | { |
3330 | struct drm_device *dev = intel_dp_to_dev(intel_dp); | |
3331 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3332 | struct intel_digital_port *dport = dp_to_dig_port(intel_dp); | |
5e69f97f CML |
3333 | struct intel_crtc *intel_crtc = |
3334 | to_intel_crtc(dport->base.base.crtc); | |
e2fa6fba P |
3335 | unsigned long demph_reg_value, preemph_reg_value, |
3336 | uniqtranscale_reg_value; | |
3337 | uint8_t train_set = intel_dp->train_set[0]; | |
e4607fcf | 3338 | enum dpio_channel port = vlv_dport_to_channel(dport); |
5e69f97f | 3339 | int pipe = intel_crtc->pipe; |
e2fa6fba P |
3340 | |
3341 | switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) { | |
bd60018a | 3342 | case DP_TRAIN_PRE_EMPH_LEVEL_0: |
e2fa6fba P |
3343 | preemph_reg_value = 0x0004000; |
3344 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { | |
bd60018a | 3345 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
e2fa6fba P |
3346 | demph_reg_value = 0x2B405555; |
3347 | uniqtranscale_reg_value = 0x552AB83A; | |
3348 | break; | |
bd60018a | 3349 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
e2fa6fba P |
3350 | demph_reg_value = 0x2B404040; |
3351 | uniqtranscale_reg_value = 0x5548B83A; | |
3352 | break; | |
bd60018a | 3353 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
e2fa6fba P |
3354 | demph_reg_value = 0x2B245555; |
3355 | uniqtranscale_reg_value = 0x5560B83A; | |
3356 | break; | |
bd60018a | 3357 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
e2fa6fba P |
3358 | demph_reg_value = 0x2B405555; |
3359 | uniqtranscale_reg_value = 0x5598DA3A; | |
3360 | break; | |
3361 | default: | |
3362 | return 0; | |
3363 | } | |
3364 | break; | |
bd60018a | 3365 | case DP_TRAIN_PRE_EMPH_LEVEL_1: |
e2fa6fba P |
3366 | preemph_reg_value = 0x0002000; |
3367 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { | |
bd60018a | 3368 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
e2fa6fba P |
3369 | demph_reg_value = 0x2B404040; |
3370 | uniqtranscale_reg_value = 0x5552B83A; | |
3371 | break; | |
bd60018a | 3372 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
e2fa6fba P |
3373 | demph_reg_value = 0x2B404848; |
3374 | uniqtranscale_reg_value = 0x5580B83A; | |
3375 | break; | |
bd60018a | 3376 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
e2fa6fba P |
3377 | demph_reg_value = 0x2B404040; |
3378 | uniqtranscale_reg_value = 0x55ADDA3A; | |
3379 | break; | |
3380 | default: | |
3381 | return 0; | |
3382 | } | |
3383 | break; | |
bd60018a | 3384 | case DP_TRAIN_PRE_EMPH_LEVEL_2: |
e2fa6fba P |
3385 | preemph_reg_value = 0x0000000; |
3386 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { | |
bd60018a | 3387 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
e2fa6fba P |
3388 | demph_reg_value = 0x2B305555; |
3389 | uniqtranscale_reg_value = 0x5570B83A; | |
3390 | break; | |
bd60018a | 3391 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
e2fa6fba P |
3392 | demph_reg_value = 0x2B2B4040; |
3393 | uniqtranscale_reg_value = 0x55ADDA3A; | |
3394 | break; | |
3395 | default: | |
3396 | return 0; | |
3397 | } | |
3398 | break; | |
bd60018a | 3399 | case DP_TRAIN_PRE_EMPH_LEVEL_3: |
e2fa6fba P |
3400 | preemph_reg_value = 0x0006000; |
3401 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { | |
bd60018a | 3402 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
e2fa6fba P |
3403 | demph_reg_value = 0x1B405555; |
3404 | uniqtranscale_reg_value = 0x55ADDA3A; | |
3405 | break; | |
3406 | default: | |
3407 | return 0; | |
3408 | } | |
3409 | break; | |
3410 | default: | |
3411 | return 0; | |
3412 | } | |
3413 | ||
a580516d | 3414 | mutex_lock(&dev_priv->sb_lock); |
ab3c759a CML |
3415 | vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0x00000000); |
3416 | vlv_dpio_write(dev_priv, pipe, VLV_TX_DW4(port), demph_reg_value); | |
3417 | vlv_dpio_write(dev_priv, pipe, VLV_TX_DW2(port), | |
e2fa6fba | 3418 | uniqtranscale_reg_value); |
ab3c759a CML |
3419 | vlv_dpio_write(dev_priv, pipe, VLV_TX_DW3(port), 0x0C782040); |
3420 | vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW11(port), 0x00030000); | |
3421 | vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW9(port), preemph_reg_value); | |
3422 | vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0x80000000); | |
a580516d | 3423 | mutex_unlock(&dev_priv->sb_lock); |
e2fa6fba P |
3424 | |
3425 | return 0; | |
3426 | } | |
3427 | ||
67fa24b4 VS |
3428 | static bool chv_need_uniq_trans_scale(uint8_t train_set) |
3429 | { | |
3430 | return (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) == DP_TRAIN_PRE_EMPH_LEVEL_0 && | |
3431 | (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) == DP_TRAIN_VOLTAGE_SWING_LEVEL_3; | |
3432 | } | |
3433 | ||
5829975c | 3434 | static uint32_t chv_signal_levels(struct intel_dp *intel_dp) |
e4a1d846 CML |
3435 | { |
3436 | struct drm_device *dev = intel_dp_to_dev(intel_dp); | |
3437 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3438 | struct intel_digital_port *dport = dp_to_dig_port(intel_dp); | |
3439 | struct intel_crtc *intel_crtc = to_intel_crtc(dport->base.base.crtc); | |
f72df8db | 3440 | u32 deemph_reg_value, margin_reg_value, val; |
e4a1d846 CML |
3441 | uint8_t train_set = intel_dp->train_set[0]; |
3442 | enum dpio_channel ch = vlv_dport_to_channel(dport); | |
f72df8db VS |
3443 | enum pipe pipe = intel_crtc->pipe; |
3444 | int i; | |
e4a1d846 CML |
3445 | |
3446 | switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) { | |
bd60018a | 3447 | case DP_TRAIN_PRE_EMPH_LEVEL_0: |
e4a1d846 | 3448 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
bd60018a | 3449 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
e4a1d846 CML |
3450 | deemph_reg_value = 128; |
3451 | margin_reg_value = 52; | |
3452 | break; | |
bd60018a | 3453 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
e4a1d846 CML |
3454 | deemph_reg_value = 128; |
3455 | margin_reg_value = 77; | |
3456 | break; | |
bd60018a | 3457 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
e4a1d846 CML |
3458 | deemph_reg_value = 128; |
3459 | margin_reg_value = 102; | |
3460 | break; | |
bd60018a | 3461 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
e4a1d846 CML |
3462 | deemph_reg_value = 128; |
3463 | margin_reg_value = 154; | |
3464 | /* FIXME extra to set for 1200 */ | |
3465 | break; | |
3466 | default: | |
3467 | return 0; | |
3468 | } | |
3469 | break; | |
bd60018a | 3470 | case DP_TRAIN_PRE_EMPH_LEVEL_1: |
e4a1d846 | 3471 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
bd60018a | 3472 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
e4a1d846 CML |
3473 | deemph_reg_value = 85; |
3474 | margin_reg_value = 78; | |
3475 | break; | |
bd60018a | 3476 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
e4a1d846 CML |
3477 | deemph_reg_value = 85; |
3478 | margin_reg_value = 116; | |
3479 | break; | |
bd60018a | 3480 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
e4a1d846 CML |
3481 | deemph_reg_value = 85; |
3482 | margin_reg_value = 154; | |
3483 | break; | |
3484 | default: | |
3485 | return 0; | |
3486 | } | |
3487 | break; | |
bd60018a | 3488 | case DP_TRAIN_PRE_EMPH_LEVEL_2: |
e4a1d846 | 3489 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
bd60018a | 3490 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
e4a1d846 CML |
3491 | deemph_reg_value = 64; |
3492 | margin_reg_value = 104; | |
3493 | break; | |
bd60018a | 3494 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
e4a1d846 CML |
3495 | deemph_reg_value = 64; |
3496 | margin_reg_value = 154; | |
3497 | break; | |
3498 | default: | |
3499 | return 0; | |
3500 | } | |
3501 | break; | |
bd60018a | 3502 | case DP_TRAIN_PRE_EMPH_LEVEL_3: |
e4a1d846 | 3503 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
bd60018a | 3504 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
e4a1d846 CML |
3505 | deemph_reg_value = 43; |
3506 | margin_reg_value = 154; | |
3507 | break; | |
3508 | default: | |
3509 | return 0; | |
3510 | } | |
3511 | break; | |
3512 | default: | |
3513 | return 0; | |
3514 | } | |
3515 | ||
a580516d | 3516 | mutex_lock(&dev_priv->sb_lock); |
e4a1d846 CML |
3517 | |
3518 | /* Clear calc init */ | |
1966e59e VS |
3519 | val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch)); |
3520 | val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3); | |
a02ef3c7 VS |
3521 | val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK); |
3522 | val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5; | |
1966e59e VS |
3523 | vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val); |
3524 | ||
e0fce78f VS |
3525 | if (intel_crtc->config->lane_count > 2) { |
3526 | val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch)); | |
3527 | val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3); | |
3528 | val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK); | |
3529 | val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5; | |
3530 | vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val); | |
3531 | } | |
e4a1d846 | 3532 | |
a02ef3c7 VS |
3533 | val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW9(ch)); |
3534 | val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK); | |
3535 | val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000; | |
3536 | vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW9(ch), val); | |
3537 | ||
e0fce78f VS |
3538 | if (intel_crtc->config->lane_count > 2) { |
3539 | val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW9(ch)); | |
3540 | val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK); | |
3541 | val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000; | |
3542 | vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW9(ch), val); | |
3543 | } | |
a02ef3c7 | 3544 | |
e4a1d846 | 3545 | /* Program swing deemph */ |
e0fce78f | 3546 | for (i = 0; i < intel_crtc->config->lane_count; i++) { |
f72df8db VS |
3547 | val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW4(ch, i)); |
3548 | val &= ~DPIO_SWING_DEEMPH9P5_MASK; | |
3549 | val |= deemph_reg_value << DPIO_SWING_DEEMPH9P5_SHIFT; | |
3550 | vlv_dpio_write(dev_priv, pipe, CHV_TX_DW4(ch, i), val); | |
3551 | } | |
e4a1d846 CML |
3552 | |
3553 | /* Program swing margin */ | |
e0fce78f | 3554 | for (i = 0; i < intel_crtc->config->lane_count; i++) { |
f72df8db | 3555 | val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW2(ch, i)); |
67fa24b4 | 3556 | |
1fb44505 VS |
3557 | val &= ~DPIO_SWING_MARGIN000_MASK; |
3558 | val |= margin_reg_value << DPIO_SWING_MARGIN000_SHIFT; | |
67fa24b4 VS |
3559 | |
3560 | /* | |
3561 | * Supposedly this value shouldn't matter when unique transition | |
3562 | * scale is disabled, but in fact it does matter. Let's just | |
3563 | * always program the same value and hope it's OK. | |
3564 | */ | |
3565 | val &= ~(0xff << DPIO_UNIQ_TRANS_SCALE_SHIFT); | |
3566 | val |= 0x9a << DPIO_UNIQ_TRANS_SCALE_SHIFT; | |
3567 | ||
f72df8db VS |
3568 | vlv_dpio_write(dev_priv, pipe, CHV_TX_DW2(ch, i), val); |
3569 | } | |
e4a1d846 | 3570 | |
67fa24b4 VS |
3571 | /* |
3572 | * The document said it needs to set bit 27 for ch0 and bit 26 | |
3573 | * for ch1. Might be a typo in the doc. | |
3574 | * For now, for this unique transition scale selection, set bit | |
3575 | * 27 for ch0 and ch1. | |
3576 | */ | |
e0fce78f | 3577 | for (i = 0; i < intel_crtc->config->lane_count; i++) { |
f72df8db | 3578 | val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW3(ch, i)); |
67fa24b4 | 3579 | if (chv_need_uniq_trans_scale(train_set)) |
f72df8db | 3580 | val |= DPIO_TX_UNIQ_TRANS_SCALE_EN; |
67fa24b4 VS |
3581 | else |
3582 | val &= ~DPIO_TX_UNIQ_TRANS_SCALE_EN; | |
3583 | vlv_dpio_write(dev_priv, pipe, CHV_TX_DW3(ch, i), val); | |
e4a1d846 CML |
3584 | } |
3585 | ||
3586 | /* Start swing calculation */ | |
1966e59e VS |
3587 | val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch)); |
3588 | val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3; | |
3589 | vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val); | |
3590 | ||
e0fce78f VS |
3591 | if (intel_crtc->config->lane_count > 2) { |
3592 | val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch)); | |
3593 | val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3; | |
3594 | vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val); | |
3595 | } | |
e4a1d846 | 3596 | |
a580516d | 3597 | mutex_unlock(&dev_priv->sb_lock); |
e4a1d846 CML |
3598 | |
3599 | return 0; | |
3600 | } | |
3601 | ||
a4fc5ed6 | 3602 | static uint32_t |
5829975c | 3603 | gen4_signal_levels(uint8_t train_set) |
a4fc5ed6 | 3604 | { |
3cf2efb1 | 3605 | uint32_t signal_levels = 0; |
a4fc5ed6 | 3606 | |
3cf2efb1 | 3607 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
bd60018a | 3608 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: |
a4fc5ed6 KP |
3609 | default: |
3610 | signal_levels |= DP_VOLTAGE_0_4; | |
3611 | break; | |
bd60018a | 3612 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: |
a4fc5ed6 KP |
3613 | signal_levels |= DP_VOLTAGE_0_6; |
3614 | break; | |
bd60018a | 3615 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: |
a4fc5ed6 KP |
3616 | signal_levels |= DP_VOLTAGE_0_8; |
3617 | break; | |
bd60018a | 3618 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: |
a4fc5ed6 KP |
3619 | signal_levels |= DP_VOLTAGE_1_2; |
3620 | break; | |
3621 | } | |
3cf2efb1 | 3622 | switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) { |
bd60018a | 3623 | case DP_TRAIN_PRE_EMPH_LEVEL_0: |
a4fc5ed6 KP |
3624 | default: |
3625 | signal_levels |= DP_PRE_EMPHASIS_0; | |
3626 | break; | |
bd60018a | 3627 | case DP_TRAIN_PRE_EMPH_LEVEL_1: |
a4fc5ed6 KP |
3628 | signal_levels |= DP_PRE_EMPHASIS_3_5; |
3629 | break; | |
bd60018a | 3630 | case DP_TRAIN_PRE_EMPH_LEVEL_2: |
a4fc5ed6 KP |
3631 | signal_levels |= DP_PRE_EMPHASIS_6; |
3632 | break; | |
bd60018a | 3633 | case DP_TRAIN_PRE_EMPH_LEVEL_3: |
a4fc5ed6 KP |
3634 | signal_levels |= DP_PRE_EMPHASIS_9_5; |
3635 | break; | |
3636 | } | |
3637 | return signal_levels; | |
3638 | } | |
3639 | ||
e3421a18 ZW |
3640 | /* Gen6's DP voltage swing and pre-emphasis control */ |
3641 | static uint32_t | |
5829975c | 3642 | gen6_edp_signal_levels(uint8_t train_set) |
e3421a18 | 3643 | { |
3c5a62b5 YL |
3644 | int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK | |
3645 | DP_TRAIN_PRE_EMPHASIS_MASK); | |
3646 | switch (signal_levels) { | |
bd60018a SJ |
3647 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0: |
3648 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0: | |
3c5a62b5 | 3649 | return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B; |
bd60018a | 3650 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1: |
3c5a62b5 | 3651 | return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B; |
bd60018a SJ |
3652 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2: |
3653 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2: | |
3c5a62b5 | 3654 | return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B; |
bd60018a SJ |
3655 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1: |
3656 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1: | |
3c5a62b5 | 3657 | return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B; |
bd60018a SJ |
3658 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0: |
3659 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0: | |
3c5a62b5 | 3660 | return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B; |
e3421a18 | 3661 | default: |
3c5a62b5 YL |
3662 | DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:" |
3663 | "0x%x\n", signal_levels); | |
3664 | return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B; | |
e3421a18 ZW |
3665 | } |
3666 | } | |
3667 | ||
1a2eb460 KP |
3668 | /* Gen7's DP voltage swing and pre-emphasis control */ |
3669 | static uint32_t | |
5829975c | 3670 | gen7_edp_signal_levels(uint8_t train_set) |
1a2eb460 KP |
3671 | { |
3672 | int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK | | |
3673 | DP_TRAIN_PRE_EMPHASIS_MASK); | |
3674 | switch (signal_levels) { | |
bd60018a | 3675 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0: |
1a2eb460 | 3676 | return EDP_LINK_TRAIN_400MV_0DB_IVB; |
bd60018a | 3677 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1: |
1a2eb460 | 3678 | return EDP_LINK_TRAIN_400MV_3_5DB_IVB; |
bd60018a | 3679 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2: |
1a2eb460 KP |
3680 | return EDP_LINK_TRAIN_400MV_6DB_IVB; |
3681 | ||
bd60018a | 3682 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0: |
1a2eb460 | 3683 | return EDP_LINK_TRAIN_600MV_0DB_IVB; |
bd60018a | 3684 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1: |
1a2eb460 KP |
3685 | return EDP_LINK_TRAIN_600MV_3_5DB_IVB; |
3686 | ||
bd60018a | 3687 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0: |
1a2eb460 | 3688 | return EDP_LINK_TRAIN_800MV_0DB_IVB; |
bd60018a | 3689 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1: |
1a2eb460 KP |
3690 | return EDP_LINK_TRAIN_800MV_3_5DB_IVB; |
3691 | ||
3692 | default: | |
3693 | DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:" | |
3694 | "0x%x\n", signal_levels); | |
3695 | return EDP_LINK_TRAIN_500MV_0DB_IVB; | |
3696 | } | |
3697 | } | |
3698 | ||
94223d04 | 3699 | void |
f4eb692e | 3700 | intel_dp_set_signal_levels(struct intel_dp *intel_dp) |
f0a3424e PZ |
3701 | { |
3702 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); | |
bc7d38a4 | 3703 | enum port port = intel_dig_port->port; |
f0a3424e | 3704 | struct drm_device *dev = intel_dig_port->base.base.dev; |
b905a915 | 3705 | struct drm_i915_private *dev_priv = to_i915(dev); |
f8896f5d | 3706 | uint32_t signal_levels, mask = 0; |
f0a3424e PZ |
3707 | uint8_t train_set = intel_dp->train_set[0]; |
3708 | ||
f8896f5d DW |
3709 | if (HAS_DDI(dev)) { |
3710 | signal_levels = ddi_signal_levels(intel_dp); | |
3711 | ||
3712 | if (IS_BROXTON(dev)) | |
3713 | signal_levels = 0; | |
3714 | else | |
3715 | mask = DDI_BUF_EMP_MASK; | |
e4a1d846 | 3716 | } else if (IS_CHERRYVIEW(dev)) { |
5829975c | 3717 | signal_levels = chv_signal_levels(intel_dp); |
e2fa6fba | 3718 | } else if (IS_VALLEYVIEW(dev)) { |
5829975c | 3719 | signal_levels = vlv_signal_levels(intel_dp); |
bc7d38a4 | 3720 | } else if (IS_GEN7(dev) && port == PORT_A) { |
5829975c | 3721 | signal_levels = gen7_edp_signal_levels(train_set); |
f0a3424e | 3722 | mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB; |
bc7d38a4 | 3723 | } else if (IS_GEN6(dev) && port == PORT_A) { |
5829975c | 3724 | signal_levels = gen6_edp_signal_levels(train_set); |
f0a3424e PZ |
3725 | mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB; |
3726 | } else { | |
5829975c | 3727 | signal_levels = gen4_signal_levels(train_set); |
f0a3424e PZ |
3728 | mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK; |
3729 | } | |
3730 | ||
96fb9f9b VK |
3731 | if (mask) |
3732 | DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels); | |
3733 | ||
3734 | DRM_DEBUG_KMS("Using vswing level %d\n", | |
3735 | train_set & DP_TRAIN_VOLTAGE_SWING_MASK); | |
3736 | DRM_DEBUG_KMS("Using pre-emphasis level %d\n", | |
3737 | (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >> | |
3738 | DP_TRAIN_PRE_EMPHASIS_SHIFT); | |
f0a3424e | 3739 | |
f4eb692e | 3740 | intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels; |
b905a915 ACO |
3741 | |
3742 | I915_WRITE(intel_dp->output_reg, intel_dp->DP); | |
3743 | POSTING_READ(intel_dp->output_reg); | |
f0a3424e PZ |
3744 | } |
3745 | ||
94223d04 | 3746 | void |
e9c176d5 ACO |
3747 | intel_dp_program_link_training_pattern(struct intel_dp *intel_dp, |
3748 | uint8_t dp_train_pat) | |
a4fc5ed6 | 3749 | { |
174edf1f | 3750 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
90a6b7b0 VS |
3751 | struct drm_i915_private *dev_priv = |
3752 | to_i915(intel_dig_port->base.base.dev); | |
a4fc5ed6 | 3753 | |
f4eb692e | 3754 | _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat); |
47ea7542 | 3755 | |
f4eb692e | 3756 | I915_WRITE(intel_dp->output_reg, intel_dp->DP); |
ea5b213a | 3757 | POSTING_READ(intel_dp->output_reg); |
e9c176d5 ACO |
3758 | } |
3759 | ||
94223d04 | 3760 | void intel_dp_set_idle_link_train(struct intel_dp *intel_dp) |
3ab9c637 ID |
3761 | { |
3762 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); | |
3763 | struct drm_device *dev = intel_dig_port->base.base.dev; | |
3764 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3765 | enum port port = intel_dig_port->port; | |
3766 | uint32_t val; | |
3767 | ||
3768 | if (!HAS_DDI(dev)) | |
3769 | return; | |
3770 | ||
3771 | val = I915_READ(DP_TP_CTL(port)); | |
3772 | val &= ~DP_TP_CTL_LINK_TRAIN_MASK; | |
3773 | val |= DP_TP_CTL_LINK_TRAIN_IDLE; | |
3774 | I915_WRITE(DP_TP_CTL(port), val); | |
3775 | ||
3776 | /* | |
3777 | * On PORT_A we can have only eDP in SST mode. There the only reason | |
3778 | * we need to set idle transmission mode is to work around a HW issue | |
3779 | * where we enable the pipe while not in idle link-training mode. | |
3780 | * In this case there is requirement to wait for a minimum number of | |
3781 | * idle patterns to be sent. | |
3782 | */ | |
3783 | if (port == PORT_A) | |
3784 | return; | |
3785 | ||
3786 | if (wait_for((I915_READ(DP_TP_STATUS(port)) & DP_TP_STATUS_IDLE_DONE), | |
3787 | 1)) | |
3788 | DRM_ERROR("Timed out waiting for DP idle patterns\n"); | |
3789 | } | |
3790 | ||
a4fc5ed6 | 3791 | static void |
ea5b213a | 3792 | intel_dp_link_down(struct intel_dp *intel_dp) |
a4fc5ed6 | 3793 | { |
da63a9f2 | 3794 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
1612c8bd | 3795 | struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc); |
bc7d38a4 | 3796 | enum port port = intel_dig_port->port; |
da63a9f2 | 3797 | struct drm_device *dev = intel_dig_port->base.base.dev; |
a4fc5ed6 | 3798 | struct drm_i915_private *dev_priv = dev->dev_private; |
ea5b213a | 3799 | uint32_t DP = intel_dp->DP; |
a4fc5ed6 | 3800 | |
bc76e320 | 3801 | if (WARN_ON(HAS_DDI(dev))) |
c19b0669 PZ |
3802 | return; |
3803 | ||
0c33d8d7 | 3804 | if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0)) |
1b39d6f3 CW |
3805 | return; |
3806 | ||
28c97730 | 3807 | DRM_DEBUG_KMS("\n"); |
32f9d658 | 3808 | |
39e5fa88 VS |
3809 | if ((IS_GEN7(dev) && port == PORT_A) || |
3810 | (HAS_PCH_CPT(dev) && port != PORT_A)) { | |
e3421a18 | 3811 | DP &= ~DP_LINK_TRAIN_MASK_CPT; |
1612c8bd | 3812 | DP |= DP_LINK_TRAIN_PAT_IDLE_CPT; |
e3421a18 | 3813 | } else { |
aad3d14d VS |
3814 | if (IS_CHERRYVIEW(dev)) |
3815 | DP &= ~DP_LINK_TRAIN_MASK_CHV; | |
3816 | else | |
3817 | DP &= ~DP_LINK_TRAIN_MASK; | |
1612c8bd | 3818 | DP |= DP_LINK_TRAIN_PAT_IDLE; |
e3421a18 | 3819 | } |
1612c8bd | 3820 | I915_WRITE(intel_dp->output_reg, DP); |
fe255d00 | 3821 | POSTING_READ(intel_dp->output_reg); |
5eb08b69 | 3822 | |
1612c8bd VS |
3823 | DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE); |
3824 | I915_WRITE(intel_dp->output_reg, DP); | |
3825 | POSTING_READ(intel_dp->output_reg); | |
3826 | ||
3827 | /* | |
3828 | * HW workaround for IBX, we need to move the port | |
3829 | * to transcoder A after disabling it to allow the | |
3830 | * matching HDMI port to be enabled on transcoder A. | |
3831 | */ | |
3832 | if (HAS_PCH_IBX(dev) && crtc->pipe == PIPE_B && port != PORT_A) { | |
0c241d5b VS |
3833 | /* |
3834 | * We get CPU/PCH FIFO underruns on the other pipe when | |
3835 | * doing the workaround. Sweep them under the rug. | |
3836 | */ | |
3837 | intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false); | |
3838 | intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false); | |
3839 | ||
1612c8bd VS |
3840 | /* always enable with pattern 1 (as per spec) */ |
3841 | DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK); | |
3842 | DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1; | |
3843 | I915_WRITE(intel_dp->output_reg, DP); | |
3844 | POSTING_READ(intel_dp->output_reg); | |
3845 | ||
3846 | DP &= ~DP_PORT_EN; | |
5bddd17f | 3847 | I915_WRITE(intel_dp->output_reg, DP); |
0ca09685 | 3848 | POSTING_READ(intel_dp->output_reg); |
0c241d5b VS |
3849 | |
3850 | intel_wait_for_vblank_if_active(dev_priv->dev, PIPE_A); | |
3851 | intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true); | |
3852 | intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true); | |
5bddd17f EA |
3853 | } |
3854 | ||
f01eca2e | 3855 | msleep(intel_dp->panel_power_down_delay); |
6fec7662 VS |
3856 | |
3857 | intel_dp->DP = DP; | |
a4fc5ed6 KP |
3858 | } |
3859 | ||
26d61aad KP |
3860 | static bool |
3861 | intel_dp_get_dpcd(struct intel_dp *intel_dp) | |
92fd8fd1 | 3862 | { |
a031d709 RV |
3863 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
3864 | struct drm_device *dev = dig_port->base.base.dev; | |
3865 | struct drm_i915_private *dev_priv = dev->dev_private; | |
fc0f8e25 | 3866 | uint8_t rev; |
a031d709 | 3867 | |
9d1a1031 JN |
3868 | if (intel_dp_dpcd_read_wake(&intel_dp->aux, 0x000, intel_dp->dpcd, |
3869 | sizeof(intel_dp->dpcd)) < 0) | |
edb39244 | 3870 | return false; /* aux transfer failed */ |
92fd8fd1 | 3871 | |
a8e98153 | 3872 | DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd); |
577c7a50 | 3873 | |
edb39244 AJ |
3874 | if (intel_dp->dpcd[DP_DPCD_REV] == 0) |
3875 | return false; /* DPCD not present */ | |
3876 | ||
2293bb5c SK |
3877 | /* Check if the panel supports PSR */ |
3878 | memset(intel_dp->psr_dpcd, 0, sizeof(intel_dp->psr_dpcd)); | |
50003939 | 3879 | if (is_edp(intel_dp)) { |
9d1a1031 JN |
3880 | intel_dp_dpcd_read_wake(&intel_dp->aux, DP_PSR_SUPPORT, |
3881 | intel_dp->psr_dpcd, | |
3882 | sizeof(intel_dp->psr_dpcd)); | |
a031d709 RV |
3883 | if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) { |
3884 | dev_priv->psr.sink_support = true; | |
50003939 | 3885 | DRM_DEBUG_KMS("Detected EDP PSR Panel.\n"); |
a031d709 | 3886 | } |
474d1ec4 SJ |
3887 | |
3888 | if (INTEL_INFO(dev)->gen >= 9 && | |
3889 | (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) { | |
3890 | uint8_t frame_sync_cap; | |
3891 | ||
3892 | dev_priv->psr.sink_support = true; | |
3893 | intel_dp_dpcd_read_wake(&intel_dp->aux, | |
3894 | DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP, | |
3895 | &frame_sync_cap, 1); | |
3896 | dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false; | |
3897 | /* PSR2 needs frame sync as well */ | |
3898 | dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync; | |
3899 | DRM_DEBUG_KMS("PSR2 %s on sink", | |
3900 | dev_priv->psr.psr2_support ? "supported" : "not supported"); | |
3901 | } | |
50003939 JN |
3902 | } |
3903 | ||
bc5133d5 | 3904 | DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n", |
e588fa18 | 3905 | yesno(intel_dp_source_supports_hbr2(intel_dp)), |
742f491d | 3906 | yesno(drm_dp_tps3_supported(intel_dp->dpcd))); |
06ea66b6 | 3907 | |
fc0f8e25 SJ |
3908 | /* Intermediate frequency support */ |
3909 | if (is_edp(intel_dp) && | |
3910 | (intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) && | |
3911 | (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_EDP_DPCD_REV, &rev, 1) == 1) && | |
3912 | (rev >= 0x03)) { /* eDp v1.4 or higher */ | |
94ca719e | 3913 | __le16 sink_rates[DP_MAX_SUPPORTED_RATES]; |
ea2d8a42 VS |
3914 | int i; |
3915 | ||
fc0f8e25 SJ |
3916 | intel_dp_dpcd_read_wake(&intel_dp->aux, |
3917 | DP_SUPPORTED_LINK_RATES, | |
94ca719e VS |
3918 | sink_rates, |
3919 | sizeof(sink_rates)); | |
ea2d8a42 | 3920 | |
94ca719e VS |
3921 | for (i = 0; i < ARRAY_SIZE(sink_rates); i++) { |
3922 | int val = le16_to_cpu(sink_rates[i]); | |
ea2d8a42 VS |
3923 | |
3924 | if (val == 0) | |
3925 | break; | |
3926 | ||
af77b974 SJ |
3927 | /* Value read is in kHz while drm clock is saved in deca-kHz */ |
3928 | intel_dp->sink_rates[i] = (val * 200) / 10; | |
ea2d8a42 | 3929 | } |
94ca719e | 3930 | intel_dp->num_sink_rates = i; |
fc0f8e25 | 3931 | } |
0336400e VS |
3932 | |
3933 | intel_dp_print_rates(intel_dp); | |
3934 | ||
edb39244 AJ |
3935 | if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] & |
3936 | DP_DWN_STRM_PORT_PRESENT)) | |
3937 | return true; /* native DP sink */ | |
3938 | ||
3939 | if (intel_dp->dpcd[DP_DPCD_REV] == 0x10) | |
3940 | return true; /* no per-port downstream info */ | |
3941 | ||
9d1a1031 JN |
3942 | if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_DOWNSTREAM_PORT_0, |
3943 | intel_dp->downstream_ports, | |
3944 | DP_MAX_DOWNSTREAM_PORTS) < 0) | |
edb39244 AJ |
3945 | return false; /* downstream port status fetch failed */ |
3946 | ||
3947 | return true; | |
92fd8fd1 KP |
3948 | } |
3949 | ||
0d198328 AJ |
3950 | static void |
3951 | intel_dp_probe_oui(struct intel_dp *intel_dp) | |
3952 | { | |
3953 | u8 buf[3]; | |
3954 | ||
3955 | if (!(intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] & DP_OUI_SUPPORT)) | |
3956 | return; | |
3957 | ||
9d1a1031 | 3958 | if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_SINK_OUI, buf, 3) == 3) |
0d198328 AJ |
3959 | DRM_DEBUG_KMS("Sink OUI: %02hx%02hx%02hx\n", |
3960 | buf[0], buf[1], buf[2]); | |
3961 | ||
9d1a1031 | 3962 | if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_BRANCH_OUI, buf, 3) == 3) |
0d198328 AJ |
3963 | DRM_DEBUG_KMS("Branch OUI: %02hx%02hx%02hx\n", |
3964 | buf[0], buf[1], buf[2]); | |
3965 | } | |
3966 | ||
0e32b39c DA |
3967 | static bool |
3968 | intel_dp_probe_mst(struct intel_dp *intel_dp) | |
3969 | { | |
3970 | u8 buf[1]; | |
3971 | ||
3972 | if (!intel_dp->can_mst) | |
3973 | return false; | |
3974 | ||
3975 | if (intel_dp->dpcd[DP_DPCD_REV] < 0x12) | |
3976 | return false; | |
3977 | ||
0e32b39c DA |
3978 | if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_MSTM_CAP, buf, 1)) { |
3979 | if (buf[0] & DP_MST_CAP) { | |
3980 | DRM_DEBUG_KMS("Sink is MST capable\n"); | |
3981 | intel_dp->is_mst = true; | |
3982 | } else { | |
3983 | DRM_DEBUG_KMS("Sink is not MST capable\n"); | |
3984 | intel_dp->is_mst = false; | |
3985 | } | |
3986 | } | |
0e32b39c DA |
3987 | |
3988 | drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst); | |
3989 | return intel_dp->is_mst; | |
3990 | } | |
3991 | ||
e5a1cab5 | 3992 | static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp) |
d2e216d0 | 3993 | { |
082dcc7c | 3994 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
d72f9d91 | 3995 | struct drm_device *dev = dig_port->base.base.dev; |
082dcc7c | 3996 | struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc); |
ad9dc91b | 3997 | u8 buf; |
e5a1cab5 | 3998 | int ret = 0; |
c6297843 RV |
3999 | int count = 0; |
4000 | int attempts = 10; | |
d2e216d0 | 4001 | |
082dcc7c RV |
4002 | if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) { |
4003 | DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n"); | |
e5a1cab5 RV |
4004 | ret = -EIO; |
4005 | goto out; | |
4373f0f2 PZ |
4006 | } |
4007 | ||
082dcc7c | 4008 | if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK, |
e5a1cab5 | 4009 | buf & ~DP_TEST_SINK_START) < 0) { |
082dcc7c | 4010 | DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n"); |
e5a1cab5 RV |
4011 | ret = -EIO; |
4012 | goto out; | |
4013 | } | |
d2e216d0 | 4014 | |
c6297843 RV |
4015 | do { |
4016 | intel_wait_for_vblank(dev, intel_crtc->pipe); | |
4017 | ||
4018 | if (drm_dp_dpcd_readb(&intel_dp->aux, | |
4019 | DP_TEST_SINK_MISC, &buf) < 0) { | |
4020 | ret = -EIO; | |
4021 | goto out; | |
4022 | } | |
4023 | count = buf & DP_TEST_COUNT_MASK; | |
4024 | } while (--attempts && count); | |
4025 | ||
4026 | if (attempts == 0) { | |
dc5a9037 | 4027 | DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n"); |
c6297843 RV |
4028 | ret = -ETIMEDOUT; |
4029 | } | |
4030 | ||
e5a1cab5 | 4031 | out: |
082dcc7c | 4032 | hsw_enable_ips(intel_crtc); |
e5a1cab5 | 4033 | return ret; |
082dcc7c RV |
4034 | } |
4035 | ||
4036 | static int intel_dp_sink_crc_start(struct intel_dp *intel_dp) | |
4037 | { | |
4038 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); | |
d72f9d91 | 4039 | struct drm_device *dev = dig_port->base.base.dev; |
082dcc7c RV |
4040 | struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc); |
4041 | u8 buf; | |
e5a1cab5 RV |
4042 | int ret; |
4043 | ||
082dcc7c RV |
4044 | if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0) |
4045 | return -EIO; | |
4046 | ||
4047 | if (!(buf & DP_TEST_CRC_SUPPORTED)) | |
4048 | return -ENOTTY; | |
4049 | ||
4050 | if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) | |
4051 | return -EIO; | |
4052 | ||
6d8175da RV |
4053 | if (buf & DP_TEST_SINK_START) { |
4054 | ret = intel_dp_sink_crc_stop(intel_dp); | |
4055 | if (ret) | |
4056 | return ret; | |
4057 | } | |
4058 | ||
082dcc7c | 4059 | hsw_disable_ips(intel_crtc); |
1dda5f93 | 4060 | |
9d1a1031 | 4061 | if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK, |
082dcc7c RV |
4062 | buf | DP_TEST_SINK_START) < 0) { |
4063 | hsw_enable_ips(intel_crtc); | |
4064 | return -EIO; | |
4373f0f2 PZ |
4065 | } |
4066 | ||
d72f9d91 | 4067 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
082dcc7c RV |
4068 | return 0; |
4069 | } | |
4070 | ||
4071 | int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc) | |
4072 | { | |
4073 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); | |
4074 | struct drm_device *dev = dig_port->base.base.dev; | |
4075 | struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc); | |
4076 | u8 buf; | |
621d4c76 | 4077 | int count, ret; |
082dcc7c | 4078 | int attempts = 6; |
082dcc7c RV |
4079 | |
4080 | ret = intel_dp_sink_crc_start(intel_dp); | |
4081 | if (ret) | |
4082 | return ret; | |
4083 | ||
ad9dc91b | 4084 | do { |
621d4c76 RV |
4085 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
4086 | ||
1dda5f93 | 4087 | if (drm_dp_dpcd_readb(&intel_dp->aux, |
4373f0f2 PZ |
4088 | DP_TEST_SINK_MISC, &buf) < 0) { |
4089 | ret = -EIO; | |
afe0d67e | 4090 | goto stop; |
4373f0f2 | 4091 | } |
621d4c76 | 4092 | count = buf & DP_TEST_COUNT_MASK; |
aabc95dc | 4093 | |
7e38eeff | 4094 | } while (--attempts && count == 0); |
ad9dc91b RV |
4095 | |
4096 | if (attempts == 0) { | |
7e38eeff RV |
4097 | DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n"); |
4098 | ret = -ETIMEDOUT; | |
4099 | goto stop; | |
4100 | } | |
4101 | ||
4102 | if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) { | |
4103 | ret = -EIO; | |
4104 | goto stop; | |
ad9dc91b | 4105 | } |
d2e216d0 | 4106 | |
afe0d67e | 4107 | stop: |
082dcc7c | 4108 | intel_dp_sink_crc_stop(intel_dp); |
4373f0f2 | 4109 | return ret; |
d2e216d0 RV |
4110 | } |
4111 | ||
a60f0e38 JB |
4112 | static bool |
4113 | intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector) | |
4114 | { | |
9d1a1031 JN |
4115 | return intel_dp_dpcd_read_wake(&intel_dp->aux, |
4116 | DP_DEVICE_SERVICE_IRQ_VECTOR, | |
4117 | sink_irq_vector, 1) == 1; | |
a60f0e38 JB |
4118 | } |
4119 | ||
0e32b39c DA |
4120 | static bool |
4121 | intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector) | |
4122 | { | |
4123 | int ret; | |
4124 | ||
4125 | ret = intel_dp_dpcd_read_wake(&intel_dp->aux, | |
4126 | DP_SINK_COUNT_ESI, | |
4127 | sink_irq_vector, 14); | |
4128 | if (ret != 14) | |
4129 | return false; | |
4130 | ||
4131 | return true; | |
4132 | } | |
4133 | ||
c5d5ab7a TP |
4134 | static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp) |
4135 | { | |
4136 | uint8_t test_result = DP_TEST_ACK; | |
4137 | return test_result; | |
4138 | } | |
4139 | ||
4140 | static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp) | |
4141 | { | |
4142 | uint8_t test_result = DP_TEST_NAK; | |
4143 | return test_result; | |
4144 | } | |
4145 | ||
4146 | static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp) | |
a60f0e38 | 4147 | { |
c5d5ab7a | 4148 | uint8_t test_result = DP_TEST_NAK; |
559be30c TP |
4149 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
4150 | struct drm_connector *connector = &intel_connector->base; | |
4151 | ||
4152 | if (intel_connector->detect_edid == NULL || | |
ac6f2e29 | 4153 | connector->edid_corrupt || |
559be30c TP |
4154 | intel_dp->aux.i2c_defer_count > 6) { |
4155 | /* Check EDID read for NACKs, DEFERs and corruption | |
4156 | * (DP CTS 1.2 Core r1.1) | |
4157 | * 4.2.2.4 : Failed EDID read, I2C_NAK | |
4158 | * 4.2.2.5 : Failed EDID read, I2C_DEFER | |
4159 | * 4.2.2.6 : EDID corruption detected | |
4160 | * Use failsafe mode for all cases | |
4161 | */ | |
4162 | if (intel_dp->aux.i2c_nack_count > 0 || | |
4163 | intel_dp->aux.i2c_defer_count > 0) | |
4164 | DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n", | |
4165 | intel_dp->aux.i2c_nack_count, | |
4166 | intel_dp->aux.i2c_defer_count); | |
4167 | intel_dp->compliance_test_data = INTEL_DP_RESOLUTION_FAILSAFE; | |
4168 | } else { | |
f79b468e TS |
4169 | struct edid *block = intel_connector->detect_edid; |
4170 | ||
4171 | /* We have to write the checksum | |
4172 | * of the last block read | |
4173 | */ | |
4174 | block += intel_connector->detect_edid->extensions; | |
4175 | ||
559be30c TP |
4176 | if (!drm_dp_dpcd_write(&intel_dp->aux, |
4177 | DP_TEST_EDID_CHECKSUM, | |
f79b468e | 4178 | &block->checksum, |
5a1cc655 | 4179 | 1)) |
559be30c TP |
4180 | DRM_DEBUG_KMS("Failed to write EDID checksum\n"); |
4181 | ||
4182 | test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE; | |
4183 | intel_dp->compliance_test_data = INTEL_DP_RESOLUTION_STANDARD; | |
4184 | } | |
4185 | ||
4186 | /* Set test active flag here so userspace doesn't interrupt things */ | |
4187 | intel_dp->compliance_test_active = 1; | |
4188 | ||
c5d5ab7a TP |
4189 | return test_result; |
4190 | } | |
4191 | ||
4192 | static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp) | |
a60f0e38 | 4193 | { |
c5d5ab7a TP |
4194 | uint8_t test_result = DP_TEST_NAK; |
4195 | return test_result; | |
4196 | } | |
4197 | ||
4198 | static void intel_dp_handle_test_request(struct intel_dp *intel_dp) | |
4199 | { | |
4200 | uint8_t response = DP_TEST_NAK; | |
4201 | uint8_t rxdata = 0; | |
4202 | int status = 0; | |
4203 | ||
c5d5ab7a TP |
4204 | status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_REQUEST, &rxdata, 1); |
4205 | if (status <= 0) { | |
4206 | DRM_DEBUG_KMS("Could not read test request from sink\n"); | |
4207 | goto update_status; | |
4208 | } | |
4209 | ||
4210 | switch (rxdata) { | |
4211 | case DP_TEST_LINK_TRAINING: | |
4212 | DRM_DEBUG_KMS("LINK_TRAINING test requested\n"); | |
4213 | intel_dp->compliance_test_type = DP_TEST_LINK_TRAINING; | |
4214 | response = intel_dp_autotest_link_training(intel_dp); | |
4215 | break; | |
4216 | case DP_TEST_LINK_VIDEO_PATTERN: | |
4217 | DRM_DEBUG_KMS("TEST_PATTERN test requested\n"); | |
4218 | intel_dp->compliance_test_type = DP_TEST_LINK_VIDEO_PATTERN; | |
4219 | response = intel_dp_autotest_video_pattern(intel_dp); | |
4220 | break; | |
4221 | case DP_TEST_LINK_EDID_READ: | |
4222 | DRM_DEBUG_KMS("EDID test requested\n"); | |
4223 | intel_dp->compliance_test_type = DP_TEST_LINK_EDID_READ; | |
4224 | response = intel_dp_autotest_edid(intel_dp); | |
4225 | break; | |
4226 | case DP_TEST_LINK_PHY_TEST_PATTERN: | |
4227 | DRM_DEBUG_KMS("PHY_PATTERN test requested\n"); | |
4228 | intel_dp->compliance_test_type = DP_TEST_LINK_PHY_TEST_PATTERN; | |
4229 | response = intel_dp_autotest_phy_pattern(intel_dp); | |
4230 | break; | |
4231 | default: | |
4232 | DRM_DEBUG_KMS("Invalid test request '%02x'\n", rxdata); | |
4233 | break; | |
4234 | } | |
4235 | ||
4236 | update_status: | |
4237 | status = drm_dp_dpcd_write(&intel_dp->aux, | |
4238 | DP_TEST_RESPONSE, | |
4239 | &response, 1); | |
4240 | if (status <= 0) | |
4241 | DRM_DEBUG_KMS("Could not write test response to sink\n"); | |
a60f0e38 JB |
4242 | } |
4243 | ||
0e32b39c DA |
4244 | static int |
4245 | intel_dp_check_mst_status(struct intel_dp *intel_dp) | |
4246 | { | |
4247 | bool bret; | |
4248 | ||
4249 | if (intel_dp->is_mst) { | |
4250 | u8 esi[16] = { 0 }; | |
4251 | int ret = 0; | |
4252 | int retry; | |
4253 | bool handled; | |
4254 | bret = intel_dp_get_sink_irq_esi(intel_dp, esi); | |
4255 | go_again: | |
4256 | if (bret == true) { | |
4257 | ||
4258 | /* check link status - esi[10] = 0x200c */ | |
90a6b7b0 | 4259 | if (intel_dp->active_mst_links && |
901c2daf | 4260 | !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) { |
0e32b39c DA |
4261 | DRM_DEBUG_KMS("channel EQ not ok, retraining\n"); |
4262 | intel_dp_start_link_train(intel_dp); | |
0e32b39c DA |
4263 | intel_dp_stop_link_train(intel_dp); |
4264 | } | |
4265 | ||
6f34cc39 | 4266 | DRM_DEBUG_KMS("got esi %3ph\n", esi); |
0e32b39c DA |
4267 | ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled); |
4268 | ||
4269 | if (handled) { | |
4270 | for (retry = 0; retry < 3; retry++) { | |
4271 | int wret; | |
4272 | wret = drm_dp_dpcd_write(&intel_dp->aux, | |
4273 | DP_SINK_COUNT_ESI+1, | |
4274 | &esi[1], 3); | |
4275 | if (wret == 3) { | |
4276 | break; | |
4277 | } | |
4278 | } | |
4279 | ||
4280 | bret = intel_dp_get_sink_irq_esi(intel_dp, esi); | |
4281 | if (bret == true) { | |
6f34cc39 | 4282 | DRM_DEBUG_KMS("got esi2 %3ph\n", esi); |
0e32b39c DA |
4283 | goto go_again; |
4284 | } | |
4285 | } else | |
4286 | ret = 0; | |
4287 | ||
4288 | return ret; | |
4289 | } else { | |
4290 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); | |
4291 | DRM_DEBUG_KMS("failed to get ESI - device may have failed\n"); | |
4292 | intel_dp->is_mst = false; | |
4293 | drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst); | |
4294 | /* send a hotplug event */ | |
4295 | drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev); | |
4296 | } | |
4297 | } | |
4298 | return -EINVAL; | |
4299 | } | |
4300 | ||
a4fc5ed6 KP |
4301 | /* |
4302 | * According to DP spec | |
4303 | * 5.1.2: | |
4304 | * 1. Read DPCD | |
4305 | * 2. Configure link according to Receiver Capabilities | |
4306 | * 3. Use Link Training from 2.5.3.3 and 3.5.1.3 | |
4307 | * 4. Check link status on receipt of hot-plug interrupt | |
4308 | */ | |
a5146200 | 4309 | static void |
ea5b213a | 4310 | intel_dp_check_link_status(struct intel_dp *intel_dp) |
a4fc5ed6 | 4311 | { |
5b215bcf | 4312 | struct drm_device *dev = intel_dp_to_dev(intel_dp); |
da63a9f2 | 4313 | struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base; |
a60f0e38 | 4314 | u8 sink_irq_vector; |
93f62dad | 4315 | u8 link_status[DP_LINK_STATUS_SIZE]; |
a60f0e38 | 4316 | |
5b215bcf DA |
4317 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
4318 | ||
4df6960e SS |
4319 | /* |
4320 | * Clearing compliance test variables to allow capturing | |
4321 | * of values for next automated test request. | |
4322 | */ | |
4323 | intel_dp->compliance_test_active = 0; | |
4324 | intel_dp->compliance_test_type = 0; | |
4325 | intel_dp->compliance_test_data = 0; | |
4326 | ||
e02f9a06 | 4327 | if (!intel_encoder->base.crtc) |
a4fc5ed6 KP |
4328 | return; |
4329 | ||
1a125d8a ID |
4330 | if (!to_intel_crtc(intel_encoder->base.crtc)->active) |
4331 | return; | |
4332 | ||
92fd8fd1 | 4333 | /* Try to read receiver status if the link appears to be up */ |
93f62dad | 4334 | if (!intel_dp_get_link_status(intel_dp, link_status)) { |
a4fc5ed6 KP |
4335 | return; |
4336 | } | |
4337 | ||
92fd8fd1 | 4338 | /* Now read the DPCD to see if it's actually running */ |
26d61aad | 4339 | if (!intel_dp_get_dpcd(intel_dp)) { |
59cd09e1 JB |
4340 | return; |
4341 | } | |
4342 | ||
a60f0e38 JB |
4343 | /* Try to read the source of the interrupt */ |
4344 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 && | |
4345 | intel_dp_get_sink_irq(intel_dp, &sink_irq_vector)) { | |
4346 | /* Clear interrupt source */ | |
9d1a1031 JN |
4347 | drm_dp_dpcd_writeb(&intel_dp->aux, |
4348 | DP_DEVICE_SERVICE_IRQ_VECTOR, | |
4349 | sink_irq_vector); | |
a60f0e38 JB |
4350 | |
4351 | if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST) | |
09b1eb13 | 4352 | DRM_DEBUG_DRIVER("Test request in short pulse not handled\n"); |
a60f0e38 JB |
4353 | if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ)) |
4354 | DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n"); | |
4355 | } | |
4356 | ||
14631e9d SS |
4357 | /* if link training is requested we should perform it always */ |
4358 | if ((intel_dp->compliance_test_type == DP_TEST_LINK_TRAINING) || | |
4359 | (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count))) { | |
92fd8fd1 | 4360 | DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n", |
8e329a03 | 4361 | intel_encoder->base.name); |
33a34e4e | 4362 | intel_dp_start_link_train(intel_dp); |
3ab9c637 | 4363 | intel_dp_stop_link_train(intel_dp); |
33a34e4e | 4364 | } |
a4fc5ed6 | 4365 | } |
a4fc5ed6 | 4366 | |
caf9ab24 | 4367 | /* XXX this is probably wrong for multiple downstream ports */ |
71ba9000 | 4368 | static enum drm_connector_status |
26d61aad | 4369 | intel_dp_detect_dpcd(struct intel_dp *intel_dp) |
71ba9000 | 4370 | { |
caf9ab24 | 4371 | uint8_t *dpcd = intel_dp->dpcd; |
caf9ab24 AJ |
4372 | uint8_t type; |
4373 | ||
4374 | if (!intel_dp_get_dpcd(intel_dp)) | |
4375 | return connector_status_disconnected; | |
4376 | ||
4377 | /* if there's no downstream port, we're done */ | |
4378 | if (!(dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT)) | |
26d61aad | 4379 | return connector_status_connected; |
caf9ab24 AJ |
4380 | |
4381 | /* If we're HPD-aware, SINK_COUNT changes dynamically */ | |
c9ff160b JN |
4382 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 && |
4383 | intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) { | |
23235177 | 4384 | uint8_t reg; |
9d1a1031 JN |
4385 | |
4386 | if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_SINK_COUNT, | |
4387 | ®, 1) < 0) | |
caf9ab24 | 4388 | return connector_status_unknown; |
9d1a1031 | 4389 | |
23235177 AJ |
4390 | return DP_GET_SINK_COUNT(reg) ? connector_status_connected |
4391 | : connector_status_disconnected; | |
caf9ab24 AJ |
4392 | } |
4393 | ||
4394 | /* If no HPD, poke DDC gently */ | |
0b99836f | 4395 | if (drm_probe_ddc(&intel_dp->aux.ddc)) |
26d61aad | 4396 | return connector_status_connected; |
caf9ab24 AJ |
4397 | |
4398 | /* Well we tried, say unknown for unreliable port types */ | |
c9ff160b JN |
4399 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) { |
4400 | type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK; | |
4401 | if (type == DP_DS_PORT_TYPE_VGA || | |
4402 | type == DP_DS_PORT_TYPE_NON_EDID) | |
4403 | return connector_status_unknown; | |
4404 | } else { | |
4405 | type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] & | |
4406 | DP_DWN_STRM_PORT_TYPE_MASK; | |
4407 | if (type == DP_DWN_STRM_PORT_TYPE_ANALOG || | |
4408 | type == DP_DWN_STRM_PORT_TYPE_OTHER) | |
4409 | return connector_status_unknown; | |
4410 | } | |
caf9ab24 AJ |
4411 | |
4412 | /* Anything else is out of spec, warn and ignore */ | |
4413 | DRM_DEBUG_KMS("Broken DP branch device, ignoring\n"); | |
26d61aad | 4414 | return connector_status_disconnected; |
71ba9000 AJ |
4415 | } |
4416 | ||
d410b56d CW |
4417 | static enum drm_connector_status |
4418 | edp_detect(struct intel_dp *intel_dp) | |
4419 | { | |
4420 | struct drm_device *dev = intel_dp_to_dev(intel_dp); | |
4421 | enum drm_connector_status status; | |
4422 | ||
4423 | status = intel_panel_detect(dev); | |
4424 | if (status == connector_status_unknown) | |
4425 | status = connector_status_connected; | |
4426 | ||
4427 | return status; | |
4428 | } | |
4429 | ||
b93433cc JN |
4430 | static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv, |
4431 | struct intel_digital_port *port) | |
5eb08b69 | 4432 | { |
b93433cc | 4433 | u32 bit; |
01cb9ea6 | 4434 | |
0df53b77 JN |
4435 | switch (port->port) { |
4436 | case PORT_A: | |
4437 | return true; | |
4438 | case PORT_B: | |
4439 | bit = SDE_PORTB_HOTPLUG; | |
4440 | break; | |
4441 | case PORT_C: | |
4442 | bit = SDE_PORTC_HOTPLUG; | |
4443 | break; | |
4444 | case PORT_D: | |
4445 | bit = SDE_PORTD_HOTPLUG; | |
4446 | break; | |
4447 | default: | |
4448 | MISSING_CASE(port->port); | |
4449 | return false; | |
4450 | } | |
4451 | ||
4452 | return I915_READ(SDEISR) & bit; | |
4453 | } | |
4454 | ||
4455 | static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv, | |
4456 | struct intel_digital_port *port) | |
4457 | { | |
4458 | u32 bit; | |
4459 | ||
4460 | switch (port->port) { | |
4461 | case PORT_A: | |
4462 | return true; | |
4463 | case PORT_B: | |
4464 | bit = SDE_PORTB_HOTPLUG_CPT; | |
4465 | break; | |
4466 | case PORT_C: | |
4467 | bit = SDE_PORTC_HOTPLUG_CPT; | |
4468 | break; | |
4469 | case PORT_D: | |
4470 | bit = SDE_PORTD_HOTPLUG_CPT; | |
4471 | break; | |
a78695d3 JN |
4472 | case PORT_E: |
4473 | bit = SDE_PORTE_HOTPLUG_SPT; | |
4474 | break; | |
0df53b77 JN |
4475 | default: |
4476 | MISSING_CASE(port->port); | |
4477 | return false; | |
b93433cc | 4478 | } |
1b469639 | 4479 | |
b93433cc | 4480 | return I915_READ(SDEISR) & bit; |
5eb08b69 ZW |
4481 | } |
4482 | ||
7e66bcf2 | 4483 | static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv, |
1d245987 | 4484 | struct intel_digital_port *port) |
a4fc5ed6 | 4485 | { |
9642c81c | 4486 | u32 bit; |
5eb08b69 | 4487 | |
9642c81c JN |
4488 | switch (port->port) { |
4489 | case PORT_B: | |
4490 | bit = PORTB_HOTPLUG_LIVE_STATUS_G4X; | |
4491 | break; | |
4492 | case PORT_C: | |
4493 | bit = PORTC_HOTPLUG_LIVE_STATUS_G4X; | |
4494 | break; | |
4495 | case PORT_D: | |
4496 | bit = PORTD_HOTPLUG_LIVE_STATUS_G4X; | |
4497 | break; | |
4498 | default: | |
4499 | MISSING_CASE(port->port); | |
4500 | return false; | |
4501 | } | |
4502 | ||
4503 | return I915_READ(PORT_HOTPLUG_STAT) & bit; | |
4504 | } | |
4505 | ||
0780cd36 VS |
4506 | static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv, |
4507 | struct intel_digital_port *port) | |
9642c81c JN |
4508 | { |
4509 | u32 bit; | |
4510 | ||
4511 | switch (port->port) { | |
4512 | case PORT_B: | |
0780cd36 | 4513 | bit = PORTB_HOTPLUG_LIVE_STATUS_GM45; |
9642c81c JN |
4514 | break; |
4515 | case PORT_C: | |
0780cd36 | 4516 | bit = PORTC_HOTPLUG_LIVE_STATUS_GM45; |
9642c81c JN |
4517 | break; |
4518 | case PORT_D: | |
0780cd36 | 4519 | bit = PORTD_HOTPLUG_LIVE_STATUS_GM45; |
9642c81c JN |
4520 | break; |
4521 | default: | |
4522 | MISSING_CASE(port->port); | |
4523 | return false; | |
a4fc5ed6 KP |
4524 | } |
4525 | ||
1d245987 | 4526 | return I915_READ(PORT_HOTPLUG_STAT) & bit; |
2a592bec DA |
4527 | } |
4528 | ||
e464bfde | 4529 | static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv, |
e2ec35a5 | 4530 | struct intel_digital_port *intel_dig_port) |
e464bfde | 4531 | { |
e2ec35a5 SJ |
4532 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
4533 | enum port port; | |
e464bfde JN |
4534 | u32 bit; |
4535 | ||
e2ec35a5 SJ |
4536 | intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port); |
4537 | switch (port) { | |
e464bfde JN |
4538 | case PORT_A: |
4539 | bit = BXT_DE_PORT_HP_DDIA; | |
4540 | break; | |
4541 | case PORT_B: | |
4542 | bit = BXT_DE_PORT_HP_DDIB; | |
4543 | break; | |
4544 | case PORT_C: | |
4545 | bit = BXT_DE_PORT_HP_DDIC; | |
4546 | break; | |
4547 | default: | |
e2ec35a5 | 4548 | MISSING_CASE(port); |
e464bfde JN |
4549 | return false; |
4550 | } | |
4551 | ||
4552 | return I915_READ(GEN8_DE_PORT_ISR) & bit; | |
4553 | } | |
4554 | ||
7e66bcf2 JN |
4555 | /* |
4556 | * intel_digital_port_connected - is the specified port connected? | |
4557 | * @dev_priv: i915 private structure | |
4558 | * @port: the port to test | |
4559 | * | |
4560 | * Return %true if @port is connected, %false otherwise. | |
4561 | */ | |
237ed86c | 4562 | bool intel_digital_port_connected(struct drm_i915_private *dev_priv, |
7e66bcf2 JN |
4563 | struct intel_digital_port *port) |
4564 | { | |
0df53b77 | 4565 | if (HAS_PCH_IBX(dev_priv)) |
7e66bcf2 | 4566 | return ibx_digital_port_connected(dev_priv, port); |
22824fac | 4567 | else if (HAS_PCH_SPLIT(dev_priv)) |
0df53b77 | 4568 | return cpt_digital_port_connected(dev_priv, port); |
e464bfde JN |
4569 | else if (IS_BROXTON(dev_priv)) |
4570 | return bxt_digital_port_connected(dev_priv, port); | |
0780cd36 VS |
4571 | else if (IS_GM45(dev_priv)) |
4572 | return gm45_digital_port_connected(dev_priv, port); | |
7e66bcf2 JN |
4573 | else |
4574 | return g4x_digital_port_connected(dev_priv, port); | |
4575 | } | |
4576 | ||
8c241fef | 4577 | static struct edid * |
beb60608 | 4578 | intel_dp_get_edid(struct intel_dp *intel_dp) |
8c241fef | 4579 | { |
beb60608 | 4580 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
d6f24d0f | 4581 | |
9cd300e0 JN |
4582 | /* use cached edid if we have one */ |
4583 | if (intel_connector->edid) { | |
9cd300e0 JN |
4584 | /* invalid edid */ |
4585 | if (IS_ERR(intel_connector->edid)) | |
d6f24d0f JB |
4586 | return NULL; |
4587 | ||
55e9edeb | 4588 | return drm_edid_duplicate(intel_connector->edid); |
beb60608 CW |
4589 | } else |
4590 | return drm_get_edid(&intel_connector->base, | |
4591 | &intel_dp->aux.ddc); | |
4592 | } | |
8c241fef | 4593 | |
beb60608 CW |
4594 | static void |
4595 | intel_dp_set_edid(struct intel_dp *intel_dp) | |
4596 | { | |
4597 | struct intel_connector *intel_connector = intel_dp->attached_connector; | |
4598 | struct edid *edid; | |
8c241fef | 4599 | |
beb60608 CW |
4600 | edid = intel_dp_get_edid(intel_dp); |
4601 | intel_connector->detect_edid = edid; | |
4602 | ||
4603 | if (intel_dp->force_audio != HDMI_AUDIO_AUTO) | |
4604 | intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON; | |
4605 | else | |
4606 | intel_dp->has_audio = drm_detect_monitor_audio(edid); | |
8c241fef KP |
4607 | } |
4608 | ||
beb60608 CW |
4609 | static void |
4610 | intel_dp_unset_edid(struct intel_dp *intel_dp) | |
8c241fef | 4611 | { |
beb60608 | 4612 | struct intel_connector *intel_connector = intel_dp->attached_connector; |
8c241fef | 4613 | |
beb60608 CW |
4614 | kfree(intel_connector->detect_edid); |
4615 | intel_connector->detect_edid = NULL; | |
9cd300e0 | 4616 | |
beb60608 CW |
4617 | intel_dp->has_audio = false; |
4618 | } | |
d6f24d0f | 4619 | |
a9756bb5 ZW |
4620 | static enum drm_connector_status |
4621 | intel_dp_detect(struct drm_connector *connector, bool force) | |
4622 | { | |
4623 | struct intel_dp *intel_dp = intel_attached_dp(connector); | |
d63885da PZ |
4624 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
4625 | struct intel_encoder *intel_encoder = &intel_dig_port->base; | |
fa90ecef | 4626 | struct drm_device *dev = connector->dev; |
a9756bb5 | 4627 | enum drm_connector_status status; |
671dedd2 | 4628 | enum intel_display_power_domain power_domain; |
0e32b39c | 4629 | bool ret; |
09b1eb13 | 4630 | u8 sink_irq_vector; |
a9756bb5 | 4631 | |
164c8598 | 4632 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
c23cc417 | 4633 | connector->base.id, connector->name); |
beb60608 | 4634 | intel_dp_unset_edid(intel_dp); |
164c8598 | 4635 | |
0e32b39c DA |
4636 | if (intel_dp->is_mst) { |
4637 | /* MST devices are disconnected from a monitor POV */ | |
4638 | if (intel_encoder->type != INTEL_OUTPUT_EDP) | |
4639 | intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT; | |
beb60608 | 4640 | return connector_status_disconnected; |
0e32b39c DA |
4641 | } |
4642 | ||
25f78f58 VS |
4643 | power_domain = intel_display_port_aux_power_domain(intel_encoder); |
4644 | intel_display_power_get(to_i915(dev), power_domain); | |
a9756bb5 | 4645 | |
d410b56d CW |
4646 | /* Can't disconnect eDP, but you can close the lid... */ |
4647 | if (is_edp(intel_dp)) | |
4648 | status = edp_detect(intel_dp); | |
c555a81d ACO |
4649 | else if (intel_digital_port_connected(to_i915(dev), |
4650 | dp_to_dig_port(intel_dp))) | |
4651 | status = intel_dp_detect_dpcd(intel_dp); | |
a9756bb5 | 4652 | else |
c555a81d ACO |
4653 | status = connector_status_disconnected; |
4654 | ||
4df6960e SS |
4655 | if (status != connector_status_connected) { |
4656 | intel_dp->compliance_test_active = 0; | |
4657 | intel_dp->compliance_test_type = 0; | |
4658 | intel_dp->compliance_test_data = 0; | |
4659 | ||
c8c8fb33 | 4660 | goto out; |
4df6960e | 4661 | } |
a9756bb5 | 4662 | |
0d198328 AJ |
4663 | intel_dp_probe_oui(intel_dp); |
4664 | ||
0e32b39c DA |
4665 | ret = intel_dp_probe_mst(intel_dp); |
4666 | if (ret) { | |
4667 | /* if we are in MST mode then this connector | |
4668 | won't appear connected or have anything with EDID on it */ | |
4669 | if (intel_encoder->type != INTEL_OUTPUT_EDP) | |
4670 | intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT; | |
4671 | status = connector_status_disconnected; | |
4672 | goto out; | |
4673 | } | |
4674 | ||
4df6960e SS |
4675 | /* |
4676 | * Clearing NACK and defer counts to get their exact values | |
4677 | * while reading EDID which are required by Compliance tests | |
4678 | * 4.2.2.4 and 4.2.2.5 | |
4679 | */ | |
4680 | intel_dp->aux.i2c_nack_count = 0; | |
4681 | intel_dp->aux.i2c_defer_count = 0; | |
4682 | ||
beb60608 | 4683 | intel_dp_set_edid(intel_dp); |
a9756bb5 | 4684 | |
d63885da PZ |
4685 | if (intel_encoder->type != INTEL_OUTPUT_EDP) |
4686 | intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT; | |
c8c8fb33 PZ |
4687 | status = connector_status_connected; |
4688 | ||
09b1eb13 TP |
4689 | /* Try to read the source of the interrupt */ |
4690 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 && | |
4691 | intel_dp_get_sink_irq(intel_dp, &sink_irq_vector)) { | |
4692 | /* Clear interrupt source */ | |
4693 | drm_dp_dpcd_writeb(&intel_dp->aux, | |
4694 | DP_DEVICE_SERVICE_IRQ_VECTOR, | |
4695 | sink_irq_vector); | |
4696 | ||
4697 | if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST) | |
4698 | intel_dp_handle_test_request(intel_dp); | |
4699 | if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ)) | |
4700 | DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n"); | |
4701 | } | |
4702 | ||
c8c8fb33 | 4703 | out: |
25f78f58 | 4704 | intel_display_power_put(to_i915(dev), power_domain); |
c8c8fb33 | 4705 | return status; |
a4fc5ed6 KP |
4706 | } |
4707 | ||
beb60608 CW |
4708 | static void |
4709 | intel_dp_force(struct drm_connector *connector) | |
a4fc5ed6 | 4710 | { |
df0e9248 | 4711 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
beb60608 | 4712 | struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base; |
25f78f58 | 4713 | struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev); |
671dedd2 | 4714 | enum intel_display_power_domain power_domain; |
a4fc5ed6 | 4715 | |
beb60608 CW |
4716 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
4717 | connector->base.id, connector->name); | |
4718 | intel_dp_unset_edid(intel_dp); | |
a4fc5ed6 | 4719 | |
beb60608 CW |
4720 | if (connector->status != connector_status_connected) |
4721 | return; | |
671dedd2 | 4722 | |
25f78f58 VS |
4723 | power_domain = intel_display_port_aux_power_domain(intel_encoder); |
4724 | intel_display_power_get(dev_priv, power_domain); | |
beb60608 CW |
4725 | |
4726 | intel_dp_set_edid(intel_dp); | |
4727 | ||
25f78f58 | 4728 | intel_display_power_put(dev_priv, power_domain); |
beb60608 CW |
4729 | |
4730 | if (intel_encoder->type != INTEL_OUTPUT_EDP) | |
4731 | intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT; | |
4732 | } | |
4733 | ||
4734 | static int intel_dp_get_modes(struct drm_connector *connector) | |
4735 | { | |
4736 | struct intel_connector *intel_connector = to_intel_connector(connector); | |
4737 | struct edid *edid; | |
4738 | ||
4739 | edid = intel_connector->detect_edid; | |
4740 | if (edid) { | |
4741 | int ret = intel_connector_update_modes(connector, edid); | |
4742 | if (ret) | |
4743 | return ret; | |
4744 | } | |
32f9d658 | 4745 | |
f8779fda | 4746 | /* if eDP has no EDID, fall back to fixed mode */ |
beb60608 CW |
4747 | if (is_edp(intel_attached_dp(connector)) && |
4748 | intel_connector->panel.fixed_mode) { | |
f8779fda | 4749 | struct drm_display_mode *mode; |
beb60608 CW |
4750 | |
4751 | mode = drm_mode_duplicate(connector->dev, | |
dd06f90e | 4752 | intel_connector->panel.fixed_mode); |
f8779fda | 4753 | if (mode) { |
32f9d658 ZW |
4754 | drm_mode_probed_add(connector, mode); |
4755 | return 1; | |
4756 | } | |
4757 | } | |
beb60608 | 4758 | |
32f9d658 | 4759 | return 0; |
a4fc5ed6 KP |
4760 | } |
4761 | ||
1aad7ac0 CW |
4762 | static bool |
4763 | intel_dp_detect_audio(struct drm_connector *connector) | |
4764 | { | |
1aad7ac0 | 4765 | bool has_audio = false; |
beb60608 | 4766 | struct edid *edid; |
1aad7ac0 | 4767 | |
beb60608 CW |
4768 | edid = to_intel_connector(connector)->detect_edid; |
4769 | if (edid) | |
1aad7ac0 | 4770 | has_audio = drm_detect_monitor_audio(edid); |
671dedd2 | 4771 | |
1aad7ac0 CW |
4772 | return has_audio; |
4773 | } | |
4774 | ||
f684960e CW |
4775 | static int |
4776 | intel_dp_set_property(struct drm_connector *connector, | |
4777 | struct drm_property *property, | |
4778 | uint64_t val) | |
4779 | { | |
e953fd7b | 4780 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
53b41837 | 4781 | struct intel_connector *intel_connector = to_intel_connector(connector); |
da63a9f2 PZ |
4782 | struct intel_encoder *intel_encoder = intel_attached_encoder(connector); |
4783 | struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base); | |
f684960e CW |
4784 | int ret; |
4785 | ||
662595df | 4786 | ret = drm_object_property_set_value(&connector->base, property, val); |
f684960e CW |
4787 | if (ret) |
4788 | return ret; | |
4789 | ||
3f43c48d | 4790 | if (property == dev_priv->force_audio_property) { |
1aad7ac0 CW |
4791 | int i = val; |
4792 | bool has_audio; | |
4793 | ||
4794 | if (i == intel_dp->force_audio) | |
f684960e CW |
4795 | return 0; |
4796 | ||
1aad7ac0 | 4797 | intel_dp->force_audio = i; |
f684960e | 4798 | |
c3e5f67b | 4799 | if (i == HDMI_AUDIO_AUTO) |
1aad7ac0 CW |
4800 | has_audio = intel_dp_detect_audio(connector); |
4801 | else | |
c3e5f67b | 4802 | has_audio = (i == HDMI_AUDIO_ON); |
1aad7ac0 CW |
4803 | |
4804 | if (has_audio == intel_dp->has_audio) | |
f684960e CW |
4805 | return 0; |
4806 | ||
1aad7ac0 | 4807 | intel_dp->has_audio = has_audio; |
f684960e CW |
4808 | goto done; |
4809 | } | |
4810 | ||
e953fd7b | 4811 | if (property == dev_priv->broadcast_rgb_property) { |
ae4edb80 | 4812 | bool old_auto = intel_dp->color_range_auto; |
0f2a2a75 | 4813 | bool old_range = intel_dp->limited_color_range; |
ae4edb80 | 4814 | |
55bc60db VS |
4815 | switch (val) { |
4816 | case INTEL_BROADCAST_RGB_AUTO: | |
4817 | intel_dp->color_range_auto = true; | |
4818 | break; | |
4819 | case INTEL_BROADCAST_RGB_FULL: | |
4820 | intel_dp->color_range_auto = false; | |
0f2a2a75 | 4821 | intel_dp->limited_color_range = false; |
55bc60db VS |
4822 | break; |
4823 | case INTEL_BROADCAST_RGB_LIMITED: | |
4824 | intel_dp->color_range_auto = false; | |
0f2a2a75 | 4825 | intel_dp->limited_color_range = true; |
55bc60db VS |
4826 | break; |
4827 | default: | |
4828 | return -EINVAL; | |
4829 | } | |
ae4edb80 DV |
4830 | |
4831 | if (old_auto == intel_dp->color_range_auto && | |
0f2a2a75 | 4832 | old_range == intel_dp->limited_color_range) |
ae4edb80 DV |
4833 | return 0; |
4834 | ||
e953fd7b CW |
4835 | goto done; |
4836 | } | |
4837 | ||
53b41837 YN |
4838 | if (is_edp(intel_dp) && |
4839 | property == connector->dev->mode_config.scaling_mode_property) { | |
4840 | if (val == DRM_MODE_SCALE_NONE) { | |
4841 | DRM_DEBUG_KMS("no scaling not supported\n"); | |
4842 | return -EINVAL; | |
4843 | } | |
4844 | ||
4845 | if (intel_connector->panel.fitting_mode == val) { | |
4846 | /* the eDP scaling property is not changed */ | |
4847 | return 0; | |
4848 | } | |
4849 | intel_connector->panel.fitting_mode = val; | |
4850 | ||
4851 | goto done; | |
4852 | } | |
4853 | ||
f684960e CW |
4854 | return -EINVAL; |
4855 | ||
4856 | done: | |
c0c36b94 CW |
4857 | if (intel_encoder->base.crtc) |
4858 | intel_crtc_restore_mode(intel_encoder->base.crtc); | |
f684960e CW |
4859 | |
4860 | return 0; | |
4861 | } | |
4862 | ||
a4fc5ed6 | 4863 | static void |
73845adf | 4864 | intel_dp_connector_destroy(struct drm_connector *connector) |
a4fc5ed6 | 4865 | { |
1d508706 | 4866 | struct intel_connector *intel_connector = to_intel_connector(connector); |
aaa6fd2a | 4867 | |
10e972d3 | 4868 | kfree(intel_connector->detect_edid); |
beb60608 | 4869 | |
9cd300e0 JN |
4870 | if (!IS_ERR_OR_NULL(intel_connector->edid)) |
4871 | kfree(intel_connector->edid); | |
4872 | ||
acd8db10 PZ |
4873 | /* Can't call is_edp() since the encoder may have been destroyed |
4874 | * already. */ | |
4875 | if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) | |
1d508706 | 4876 | intel_panel_fini(&intel_connector->panel); |
aaa6fd2a | 4877 | |
a4fc5ed6 | 4878 | drm_connector_cleanup(connector); |
55f78c43 | 4879 | kfree(connector); |
a4fc5ed6 KP |
4880 | } |
4881 | ||
00c09d70 | 4882 | void intel_dp_encoder_destroy(struct drm_encoder *encoder) |
24d05927 | 4883 | { |
da63a9f2 PZ |
4884 | struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder); |
4885 | struct intel_dp *intel_dp = &intel_dig_port->dp; | |
24d05927 | 4886 | |
a121f4e5 | 4887 | intel_dp_aux_fini(intel_dp); |
0e32b39c | 4888 | intel_dp_mst_encoder_cleanup(intel_dig_port); |
bd943159 KP |
4889 | if (is_edp(intel_dp)) { |
4890 | cancel_delayed_work_sync(&intel_dp->panel_vdd_work); | |
951468f3 VS |
4891 | /* |
4892 | * vdd might still be enabled do to the delayed vdd off. | |
4893 | * Make sure vdd is actually turned off here. | |
4894 | */ | |
773538e8 | 4895 | pps_lock(intel_dp); |
4be73780 | 4896 | edp_panel_vdd_off_sync(intel_dp); |
773538e8 VS |
4897 | pps_unlock(intel_dp); |
4898 | ||
01527b31 CT |
4899 | if (intel_dp->edp_notifier.notifier_call) { |
4900 | unregister_reboot_notifier(&intel_dp->edp_notifier); | |
4901 | intel_dp->edp_notifier.notifier_call = NULL; | |
4902 | } | |
bd943159 | 4903 | } |
c8bd0e49 | 4904 | drm_encoder_cleanup(encoder); |
da63a9f2 | 4905 | kfree(intel_dig_port); |
24d05927 DV |
4906 | } |
4907 | ||
07f9cd0b ID |
4908 | static void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder) |
4909 | { | |
4910 | struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base); | |
4911 | ||
4912 | if (!is_edp(intel_dp)) | |
4913 | return; | |
4914 | ||
951468f3 VS |
4915 | /* |
4916 | * vdd might still be enabled do to the delayed vdd off. | |
4917 | * Make sure vdd is actually turned off here. | |
4918 | */ | |
afa4e53a | 4919 | cancel_delayed_work_sync(&intel_dp->panel_vdd_work); |
773538e8 | 4920 | pps_lock(intel_dp); |
07f9cd0b | 4921 | edp_panel_vdd_off_sync(intel_dp); |
773538e8 | 4922 | pps_unlock(intel_dp); |
07f9cd0b ID |
4923 | } |
4924 | ||
49e6bc51 VS |
4925 | static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp) |
4926 | { | |
4927 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); | |
4928 | struct drm_device *dev = intel_dig_port->base.base.dev; | |
4929 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4930 | enum intel_display_power_domain power_domain; | |
4931 | ||
4932 | lockdep_assert_held(&dev_priv->pps_mutex); | |
4933 | ||
4934 | if (!edp_have_panel_vdd(intel_dp)) | |
4935 | return; | |
4936 | ||
4937 | /* | |
4938 | * The VDD bit needs a power domain reference, so if the bit is | |
4939 | * already enabled when we boot or resume, grab this reference and | |
4940 | * schedule a vdd off, so we don't hold on to the reference | |
4941 | * indefinitely. | |
4942 | */ | |
4943 | DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n"); | |
25f78f58 | 4944 | power_domain = intel_display_port_aux_power_domain(&intel_dig_port->base); |
49e6bc51 VS |
4945 | intel_display_power_get(dev_priv, power_domain); |
4946 | ||
4947 | edp_panel_vdd_schedule_off(intel_dp); | |
4948 | } | |
4949 | ||
6d93c0c4 ID |
4950 | static void intel_dp_encoder_reset(struct drm_encoder *encoder) |
4951 | { | |
49e6bc51 VS |
4952 | struct intel_dp *intel_dp; |
4953 | ||
4954 | if (to_intel_encoder(encoder)->type != INTEL_OUTPUT_EDP) | |
4955 | return; | |
4956 | ||
4957 | intel_dp = enc_to_intel_dp(encoder); | |
4958 | ||
4959 | pps_lock(intel_dp); | |
4960 | ||
4961 | /* | |
4962 | * Read out the current power sequencer assignment, | |
4963 | * in case the BIOS did something with it. | |
4964 | */ | |
666a4537 | 4965 | if (IS_VALLEYVIEW(encoder->dev) || IS_CHERRYVIEW(encoder->dev)) |
49e6bc51 VS |
4966 | vlv_initial_power_sequencer_setup(intel_dp); |
4967 | ||
4968 | intel_edp_panel_vdd_sanitize(intel_dp); | |
4969 | ||
4970 | pps_unlock(intel_dp); | |
6d93c0c4 ID |
4971 | } |
4972 | ||
a4fc5ed6 | 4973 | static const struct drm_connector_funcs intel_dp_connector_funcs = { |
4d688a2a | 4974 | .dpms = drm_atomic_helper_connector_dpms, |
a4fc5ed6 | 4975 | .detect = intel_dp_detect, |
beb60608 | 4976 | .force = intel_dp_force, |
a4fc5ed6 | 4977 | .fill_modes = drm_helper_probe_single_connector_modes, |
f684960e | 4978 | .set_property = intel_dp_set_property, |
2545e4a6 | 4979 | .atomic_get_property = intel_connector_atomic_get_property, |
73845adf | 4980 | .destroy = intel_dp_connector_destroy, |
c6f95f27 | 4981 | .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, |
98969725 | 4982 | .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, |
a4fc5ed6 KP |
4983 | }; |
4984 | ||
4985 | static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = { | |
4986 | .get_modes = intel_dp_get_modes, | |
4987 | .mode_valid = intel_dp_mode_valid, | |
df0e9248 | 4988 | .best_encoder = intel_best_encoder, |
a4fc5ed6 KP |
4989 | }; |
4990 | ||
a4fc5ed6 | 4991 | static const struct drm_encoder_funcs intel_dp_enc_funcs = { |
6d93c0c4 | 4992 | .reset = intel_dp_encoder_reset, |
24d05927 | 4993 | .destroy = intel_dp_encoder_destroy, |
a4fc5ed6 KP |
4994 | }; |
4995 | ||
b2c5c181 | 4996 | enum irqreturn |
13cf5504 DA |
4997 | intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd) |
4998 | { | |
4999 | struct intel_dp *intel_dp = &intel_dig_port->dp; | |
1c767b33 | 5000 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
0e32b39c DA |
5001 | struct drm_device *dev = intel_dig_port->base.base.dev; |
5002 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1c767b33 | 5003 | enum intel_display_power_domain power_domain; |
b2c5c181 | 5004 | enum irqreturn ret = IRQ_NONE; |
1c767b33 | 5005 | |
2540058f TI |
5006 | if (intel_dig_port->base.type != INTEL_OUTPUT_EDP && |
5007 | intel_dig_port->base.type != INTEL_OUTPUT_HDMI) | |
0e32b39c | 5008 | intel_dig_port->base.type = INTEL_OUTPUT_DISPLAYPORT; |
13cf5504 | 5009 | |
7a7f84cc VS |
5010 | if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) { |
5011 | /* | |
5012 | * vdd off can generate a long pulse on eDP which | |
5013 | * would require vdd on to handle it, and thus we | |
5014 | * would end up in an endless cycle of | |
5015 | * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..." | |
5016 | */ | |
5017 | DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n", | |
5018 | port_name(intel_dig_port->port)); | |
a8b3d52f | 5019 | return IRQ_HANDLED; |
7a7f84cc VS |
5020 | } |
5021 | ||
26fbb774 VS |
5022 | DRM_DEBUG_KMS("got hpd irq on port %c - %s\n", |
5023 | port_name(intel_dig_port->port), | |
0e32b39c | 5024 | long_hpd ? "long" : "short"); |
13cf5504 | 5025 | |
25f78f58 | 5026 | power_domain = intel_display_port_aux_power_domain(intel_encoder); |
1c767b33 ID |
5027 | intel_display_power_get(dev_priv, power_domain); |
5028 | ||
0e32b39c | 5029 | if (long_hpd) { |
5fa836a9 MK |
5030 | /* indicate that we need to restart link training */ |
5031 | intel_dp->train_set_valid = false; | |
2a592bec | 5032 | |
7e66bcf2 JN |
5033 | if (!intel_digital_port_connected(dev_priv, intel_dig_port)) |
5034 | goto mst_fail; | |
0e32b39c DA |
5035 | |
5036 | if (!intel_dp_get_dpcd(intel_dp)) { | |
5037 | goto mst_fail; | |
5038 | } | |
5039 | ||
5040 | intel_dp_probe_oui(intel_dp); | |
5041 | ||
d14e7b6d VS |
5042 | if (!intel_dp_probe_mst(intel_dp)) { |
5043 | drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); | |
5044 | intel_dp_check_link_status(intel_dp); | |
5045 | drm_modeset_unlock(&dev->mode_config.connection_mutex); | |
0e32b39c | 5046 | goto mst_fail; |
d14e7b6d | 5047 | } |
0e32b39c DA |
5048 | } else { |
5049 | if (intel_dp->is_mst) { | |
1c767b33 | 5050 | if (intel_dp_check_mst_status(intel_dp) == -EINVAL) |
0e32b39c DA |
5051 | goto mst_fail; |
5052 | } | |
5053 | ||
5054 | if (!intel_dp->is_mst) { | |
5b215bcf | 5055 | drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); |
0e32b39c | 5056 | intel_dp_check_link_status(intel_dp); |
5b215bcf | 5057 | drm_modeset_unlock(&dev->mode_config.connection_mutex); |
0e32b39c DA |
5058 | } |
5059 | } | |
b2c5c181 DV |
5060 | |
5061 | ret = IRQ_HANDLED; | |
5062 | ||
1c767b33 | 5063 | goto put_power; |
0e32b39c DA |
5064 | mst_fail: |
5065 | /* if we were in MST mode, and device is not there get out of MST mode */ | |
5066 | if (intel_dp->is_mst) { | |
5067 | DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n", intel_dp->is_mst, intel_dp->mst_mgr.mst_state); | |
5068 | intel_dp->is_mst = false; | |
5069 | drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst); | |
5070 | } | |
1c767b33 ID |
5071 | put_power: |
5072 | intel_display_power_put(dev_priv, power_domain); | |
5073 | ||
5074 | return ret; | |
13cf5504 DA |
5075 | } |
5076 | ||
477ec328 | 5077 | /* check the VBT to see whether the eDP is on another port */ |
5d8a7752 | 5078 | bool intel_dp_is_edp(struct drm_device *dev, enum port port) |
36e83a18 ZY |
5079 | { |
5080 | struct drm_i915_private *dev_priv = dev->dev_private; | |
768f69c9 | 5081 | union child_device_config *p_child; |
36e83a18 | 5082 | int i; |
5d8a7752 | 5083 | static const short port_mapping[] = { |
477ec328 RV |
5084 | [PORT_B] = DVO_PORT_DPB, |
5085 | [PORT_C] = DVO_PORT_DPC, | |
5086 | [PORT_D] = DVO_PORT_DPD, | |
5087 | [PORT_E] = DVO_PORT_DPE, | |
5d8a7752 | 5088 | }; |
36e83a18 | 5089 | |
53ce81a7 VS |
5090 | /* |
5091 | * eDP not supported on g4x. so bail out early just | |
5092 | * for a bit extra safety in case the VBT is bonkers. | |
5093 | */ | |
5094 | if (INTEL_INFO(dev)->gen < 5) | |
5095 | return false; | |
5096 | ||
3b32a35b VS |
5097 | if (port == PORT_A) |
5098 | return true; | |
5099 | ||
41aa3448 | 5100 | if (!dev_priv->vbt.child_dev_num) |
36e83a18 ZY |
5101 | return false; |
5102 | ||
41aa3448 RV |
5103 | for (i = 0; i < dev_priv->vbt.child_dev_num; i++) { |
5104 | p_child = dev_priv->vbt.child_dev + i; | |
36e83a18 | 5105 | |
5d8a7752 | 5106 | if (p_child->common.dvo_port == port_mapping[port] && |
f02586df VS |
5107 | (p_child->common.device_type & DEVICE_TYPE_eDP_BITS) == |
5108 | (DEVICE_TYPE_eDP & DEVICE_TYPE_eDP_BITS)) | |
36e83a18 ZY |
5109 | return true; |
5110 | } | |
5111 | return false; | |
5112 | } | |
5113 | ||
0e32b39c | 5114 | void |
f684960e CW |
5115 | intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector) |
5116 | { | |
53b41837 YN |
5117 | struct intel_connector *intel_connector = to_intel_connector(connector); |
5118 | ||
3f43c48d | 5119 | intel_attach_force_audio_property(connector); |
e953fd7b | 5120 | intel_attach_broadcast_rgb_property(connector); |
55bc60db | 5121 | intel_dp->color_range_auto = true; |
53b41837 YN |
5122 | |
5123 | if (is_edp(intel_dp)) { | |
5124 | drm_mode_create_scaling_mode_property(connector->dev); | |
6de6d846 RC |
5125 | drm_object_attach_property( |
5126 | &connector->base, | |
53b41837 | 5127 | connector->dev->mode_config.scaling_mode_property, |
8e740cd1 YN |
5128 | DRM_MODE_SCALE_ASPECT); |
5129 | intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT; | |
53b41837 | 5130 | } |
f684960e CW |
5131 | } |
5132 | ||
dada1a9f ID |
5133 | static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp) |
5134 | { | |
d28d4731 | 5135 | intel_dp->panel_power_off_time = ktime_get_boottime(); |
dada1a9f ID |
5136 | intel_dp->last_power_on = jiffies; |
5137 | intel_dp->last_backlight_off = jiffies; | |
5138 | } | |
5139 | ||
67a54566 DV |
5140 | static void |
5141 | intel_dp_init_panel_power_sequencer(struct drm_device *dev, | |
36b5f425 | 5142 | struct intel_dp *intel_dp) |
67a54566 DV |
5143 | { |
5144 | struct drm_i915_private *dev_priv = dev->dev_private; | |
36b5f425 VS |
5145 | struct edp_power_seq cur, vbt, spec, |
5146 | *final = &intel_dp->pps_delays; | |
b0a08bec | 5147 | u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0; |
f0f59a00 | 5148 | i915_reg_t pp_ctrl_reg, pp_on_reg, pp_off_reg, pp_div_reg; |
453c5420 | 5149 | |
e39b999a VS |
5150 | lockdep_assert_held(&dev_priv->pps_mutex); |
5151 | ||
81ddbc69 VS |
5152 | /* already initialized? */ |
5153 | if (final->t11_t12 != 0) | |
5154 | return; | |
5155 | ||
b0a08bec VK |
5156 | if (IS_BROXTON(dev)) { |
5157 | /* | |
5158 | * TODO: BXT has 2 sets of PPS registers. | |
5159 | * Correct Register for Broxton need to be identified | |
5160 | * using VBT. hardcoding for now | |
5161 | */ | |
5162 | pp_ctrl_reg = BXT_PP_CONTROL(0); | |
5163 | pp_on_reg = BXT_PP_ON_DELAYS(0); | |
5164 | pp_off_reg = BXT_PP_OFF_DELAYS(0); | |
5165 | } else if (HAS_PCH_SPLIT(dev)) { | |
bf13e81b | 5166 | pp_ctrl_reg = PCH_PP_CONTROL; |
453c5420 JB |
5167 | pp_on_reg = PCH_PP_ON_DELAYS; |
5168 | pp_off_reg = PCH_PP_OFF_DELAYS; | |
5169 | pp_div_reg = PCH_PP_DIVISOR; | |
5170 | } else { | |
bf13e81b JN |
5171 | enum pipe pipe = vlv_power_sequencer_pipe(intel_dp); |
5172 | ||
5173 | pp_ctrl_reg = VLV_PIPE_PP_CONTROL(pipe); | |
5174 | pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe); | |
5175 | pp_off_reg = VLV_PIPE_PP_OFF_DELAYS(pipe); | |
5176 | pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe); | |
453c5420 | 5177 | } |
67a54566 DV |
5178 | |
5179 | /* Workaround: Need to write PP_CONTROL with the unlock key as | |
5180 | * the very first thing. */ | |
b0a08bec | 5181 | pp_ctl = ironlake_get_pp_control(intel_dp); |
67a54566 | 5182 | |
453c5420 JB |
5183 | pp_on = I915_READ(pp_on_reg); |
5184 | pp_off = I915_READ(pp_off_reg); | |
b0a08bec VK |
5185 | if (!IS_BROXTON(dev)) { |
5186 | I915_WRITE(pp_ctrl_reg, pp_ctl); | |
5187 | pp_div = I915_READ(pp_div_reg); | |
5188 | } | |
67a54566 DV |
5189 | |
5190 | /* Pull timing values out of registers */ | |
5191 | cur.t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >> | |
5192 | PANEL_POWER_UP_DELAY_SHIFT; | |
5193 | ||
5194 | cur.t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >> | |
5195 | PANEL_LIGHT_ON_DELAY_SHIFT; | |
5196 | ||
5197 | cur.t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >> | |
5198 | PANEL_LIGHT_OFF_DELAY_SHIFT; | |
5199 | ||
5200 | cur.t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >> | |
5201 | PANEL_POWER_DOWN_DELAY_SHIFT; | |
5202 | ||
b0a08bec VK |
5203 | if (IS_BROXTON(dev)) { |
5204 | u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >> | |
5205 | BXT_POWER_CYCLE_DELAY_SHIFT; | |
5206 | if (tmp > 0) | |
5207 | cur.t11_t12 = (tmp - 1) * 1000; | |
5208 | else | |
5209 | cur.t11_t12 = 0; | |
5210 | } else { | |
5211 | cur.t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >> | |
67a54566 | 5212 | PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000; |
b0a08bec | 5213 | } |
67a54566 DV |
5214 | |
5215 | DRM_DEBUG_KMS("cur t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n", | |
5216 | cur.t1_t3, cur.t8, cur.t9, cur.t10, cur.t11_t12); | |
5217 | ||
41aa3448 | 5218 | vbt = dev_priv->vbt.edp_pps; |
67a54566 DV |
5219 | |
5220 | /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of | |
5221 | * our hw here, which are all in 100usec. */ | |
5222 | spec.t1_t3 = 210 * 10; | |
5223 | spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */ | |
5224 | spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */ | |
5225 | spec.t10 = 500 * 10; | |
5226 | /* This one is special and actually in units of 100ms, but zero | |
5227 | * based in the hw (so we need to add 100 ms). But the sw vbt | |
5228 | * table multiplies it with 1000 to make it in units of 100usec, | |
5229 | * too. */ | |
5230 | spec.t11_t12 = (510 + 100) * 10; | |
5231 | ||
5232 | DRM_DEBUG_KMS("vbt t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n", | |
5233 | vbt.t1_t3, vbt.t8, vbt.t9, vbt.t10, vbt.t11_t12); | |
5234 | ||
5235 | /* Use the max of the register settings and vbt. If both are | |
5236 | * unset, fall back to the spec limits. */ | |
36b5f425 | 5237 | #define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \ |
67a54566 DV |
5238 | spec.field : \ |
5239 | max(cur.field, vbt.field)) | |
5240 | assign_final(t1_t3); | |
5241 | assign_final(t8); | |
5242 | assign_final(t9); | |
5243 | assign_final(t10); | |
5244 | assign_final(t11_t12); | |
5245 | #undef assign_final | |
5246 | ||
36b5f425 | 5247 | #define get_delay(field) (DIV_ROUND_UP(final->field, 10)) |
67a54566 DV |
5248 | intel_dp->panel_power_up_delay = get_delay(t1_t3); |
5249 | intel_dp->backlight_on_delay = get_delay(t8); | |
5250 | intel_dp->backlight_off_delay = get_delay(t9); | |
5251 | intel_dp->panel_power_down_delay = get_delay(t10); | |
5252 | intel_dp->panel_power_cycle_delay = get_delay(t11_t12); | |
5253 | #undef get_delay | |
5254 | ||
f30d26e4 JN |
5255 | DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n", |
5256 | intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay, | |
5257 | intel_dp->panel_power_cycle_delay); | |
5258 | ||
5259 | DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n", | |
5260 | intel_dp->backlight_on_delay, intel_dp->backlight_off_delay); | |
f30d26e4 JN |
5261 | } |
5262 | ||
5263 | static void | |
5264 | intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev, | |
36b5f425 | 5265 | struct intel_dp *intel_dp) |
f30d26e4 JN |
5266 | { |
5267 | struct drm_i915_private *dev_priv = dev->dev_private; | |
453c5420 | 5268 | u32 pp_on, pp_off, pp_div, port_sel = 0; |
e7dc33f3 | 5269 | int div = dev_priv->rawclk_freq / 1000; |
f0f59a00 | 5270 | i915_reg_t pp_on_reg, pp_off_reg, pp_div_reg, pp_ctrl_reg; |
ad933b56 | 5271 | enum port port = dp_to_dig_port(intel_dp)->port; |
36b5f425 | 5272 | const struct edp_power_seq *seq = &intel_dp->pps_delays; |
453c5420 | 5273 | |
e39b999a | 5274 | lockdep_assert_held(&dev_priv->pps_mutex); |
453c5420 | 5275 | |
b0a08bec VK |
5276 | if (IS_BROXTON(dev)) { |
5277 | /* | |
5278 | * TODO: BXT has 2 sets of PPS registers. | |
5279 | * Correct Register for Broxton need to be identified | |
5280 | * using VBT. hardcoding for now | |
5281 | */ | |
5282 | pp_ctrl_reg = BXT_PP_CONTROL(0); | |
5283 | pp_on_reg = BXT_PP_ON_DELAYS(0); | |
5284 | pp_off_reg = BXT_PP_OFF_DELAYS(0); | |
5285 | ||
5286 | } else if (HAS_PCH_SPLIT(dev)) { | |
453c5420 JB |
5287 | pp_on_reg = PCH_PP_ON_DELAYS; |
5288 | pp_off_reg = PCH_PP_OFF_DELAYS; | |
5289 | pp_div_reg = PCH_PP_DIVISOR; | |
5290 | } else { | |
bf13e81b JN |
5291 | enum pipe pipe = vlv_power_sequencer_pipe(intel_dp); |
5292 | ||
5293 | pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe); | |
5294 | pp_off_reg = VLV_PIPE_PP_OFF_DELAYS(pipe); | |
5295 | pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe); | |
453c5420 JB |
5296 | } |
5297 | ||
b2f19d1a PZ |
5298 | /* |
5299 | * And finally store the new values in the power sequencer. The | |
5300 | * backlight delays are set to 1 because we do manual waits on them. For | |
5301 | * T8, even BSpec recommends doing it. For T9, if we don't do this, | |
5302 | * we'll end up waiting for the backlight off delay twice: once when we | |
5303 | * do the manual sleep, and once when we disable the panel and wait for | |
5304 | * the PP_STATUS bit to become zero. | |
5305 | */ | |
f30d26e4 | 5306 | pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) | |
b2f19d1a PZ |
5307 | (1 << PANEL_LIGHT_ON_DELAY_SHIFT); |
5308 | pp_off = (1 << PANEL_LIGHT_OFF_DELAY_SHIFT) | | |
f30d26e4 | 5309 | (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT); |
67a54566 DV |
5310 | /* Compute the divisor for the pp clock, simply match the Bspec |
5311 | * formula. */ | |
b0a08bec VK |
5312 | if (IS_BROXTON(dev)) { |
5313 | pp_div = I915_READ(pp_ctrl_reg); | |
5314 | pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK; | |
5315 | pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000) | |
5316 | << BXT_POWER_CYCLE_DELAY_SHIFT); | |
5317 | } else { | |
5318 | pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT; | |
5319 | pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000) | |
5320 | << PANEL_POWER_CYCLE_DELAY_SHIFT); | |
5321 | } | |
67a54566 DV |
5322 | |
5323 | /* Haswell doesn't have any port selection bits for the panel | |
5324 | * power sequencer any more. */ | |
666a4537 | 5325 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
ad933b56 | 5326 | port_sel = PANEL_PORT_SELECT_VLV(port); |
bc7d38a4 | 5327 | } else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) { |
ad933b56 | 5328 | if (port == PORT_A) |
a24c144c | 5329 | port_sel = PANEL_PORT_SELECT_DPA; |
67a54566 | 5330 | else |
a24c144c | 5331 | port_sel = PANEL_PORT_SELECT_DPD; |
67a54566 DV |
5332 | } |
5333 | ||
453c5420 JB |
5334 | pp_on |= port_sel; |
5335 | ||
5336 | I915_WRITE(pp_on_reg, pp_on); | |
5337 | I915_WRITE(pp_off_reg, pp_off); | |
b0a08bec VK |
5338 | if (IS_BROXTON(dev)) |
5339 | I915_WRITE(pp_ctrl_reg, pp_div); | |
5340 | else | |
5341 | I915_WRITE(pp_div_reg, pp_div); | |
67a54566 | 5342 | |
67a54566 | 5343 | DRM_DEBUG_KMS("panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n", |
453c5420 JB |
5344 | I915_READ(pp_on_reg), |
5345 | I915_READ(pp_off_reg), | |
b0a08bec VK |
5346 | IS_BROXTON(dev) ? |
5347 | (I915_READ(pp_ctrl_reg) & BXT_POWER_CYCLE_DELAY_MASK) : | |
453c5420 | 5348 | I915_READ(pp_div_reg)); |
f684960e CW |
5349 | } |
5350 | ||
b33a2815 VK |
5351 | /** |
5352 | * intel_dp_set_drrs_state - program registers for RR switch to take effect | |
5353 | * @dev: DRM device | |
5354 | * @refresh_rate: RR to be programmed | |
5355 | * | |
5356 | * This function gets called when refresh rate (RR) has to be changed from | |
5357 | * one frequency to another. Switches can be between high and low RR | |
5358 | * supported by the panel or to any other RR based on media playback (in | |
5359 | * this case, RR value needs to be passed from user space). | |
5360 | * | |
5361 | * The caller of this function needs to take a lock on dev_priv->drrs. | |
5362 | */ | |
96178eeb | 5363 | static void intel_dp_set_drrs_state(struct drm_device *dev, int refresh_rate) |
439d7ac0 PB |
5364 | { |
5365 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5366 | struct intel_encoder *encoder; | |
96178eeb VK |
5367 | struct intel_digital_port *dig_port = NULL; |
5368 | struct intel_dp *intel_dp = dev_priv->drrs.dp; | |
5cec258b | 5369 | struct intel_crtc_state *config = NULL; |
439d7ac0 | 5370 | struct intel_crtc *intel_crtc = NULL; |
96178eeb | 5371 | enum drrs_refresh_rate_type index = DRRS_HIGH_RR; |
439d7ac0 PB |
5372 | |
5373 | if (refresh_rate <= 0) { | |
5374 | DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n"); | |
5375 | return; | |
5376 | } | |
5377 | ||
96178eeb VK |
5378 | if (intel_dp == NULL) { |
5379 | DRM_DEBUG_KMS("DRRS not supported.\n"); | |
439d7ac0 PB |
5380 | return; |
5381 | } | |
5382 | ||
1fcc9d1c | 5383 | /* |
e4d59f6b RV |
5384 | * FIXME: This needs proper synchronization with psr state for some |
5385 | * platforms that cannot have PSR and DRRS enabled at the same time. | |
1fcc9d1c | 5386 | */ |
439d7ac0 | 5387 | |
96178eeb VK |
5388 | dig_port = dp_to_dig_port(intel_dp); |
5389 | encoder = &dig_port->base; | |
723f9aab | 5390 | intel_crtc = to_intel_crtc(encoder->base.crtc); |
439d7ac0 PB |
5391 | |
5392 | if (!intel_crtc) { | |
5393 | DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n"); | |
5394 | return; | |
5395 | } | |
5396 | ||
6e3c9717 | 5397 | config = intel_crtc->config; |
439d7ac0 | 5398 | |
96178eeb | 5399 | if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) { |
439d7ac0 PB |
5400 | DRM_DEBUG_KMS("Only Seamless DRRS supported.\n"); |
5401 | return; | |
5402 | } | |
5403 | ||
96178eeb VK |
5404 | if (intel_dp->attached_connector->panel.downclock_mode->vrefresh == |
5405 | refresh_rate) | |
439d7ac0 PB |
5406 | index = DRRS_LOW_RR; |
5407 | ||
96178eeb | 5408 | if (index == dev_priv->drrs.refresh_rate_type) { |
439d7ac0 PB |
5409 | DRM_DEBUG_KMS( |
5410 | "DRRS requested for previously set RR...ignoring\n"); | |
5411 | return; | |
5412 | } | |
5413 | ||
5414 | if (!intel_crtc->active) { | |
5415 | DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n"); | |
5416 | return; | |
5417 | } | |
5418 | ||
44395bfe | 5419 | if (INTEL_INFO(dev)->gen >= 8 && !IS_CHERRYVIEW(dev)) { |
a4c30b1d VK |
5420 | switch (index) { |
5421 | case DRRS_HIGH_RR: | |
5422 | intel_dp_set_m_n(intel_crtc, M1_N1); | |
5423 | break; | |
5424 | case DRRS_LOW_RR: | |
5425 | intel_dp_set_m_n(intel_crtc, M2_N2); | |
5426 | break; | |
5427 | case DRRS_MAX_RR: | |
5428 | default: | |
5429 | DRM_ERROR("Unsupported refreshrate type\n"); | |
5430 | } | |
5431 | } else if (INTEL_INFO(dev)->gen > 6) { | |
f0f59a00 | 5432 | i915_reg_t reg = PIPECONF(intel_crtc->config->cpu_transcoder); |
649636ef | 5433 | u32 val; |
a4c30b1d | 5434 | |
649636ef | 5435 | val = I915_READ(reg); |
439d7ac0 | 5436 | if (index > DRRS_HIGH_RR) { |
666a4537 | 5437 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) |
6fa7aec1 VK |
5438 | val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV; |
5439 | else | |
5440 | val |= PIPECONF_EDP_RR_MODE_SWITCH; | |
439d7ac0 | 5441 | } else { |
666a4537 | 5442 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) |
6fa7aec1 VK |
5443 | val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV; |
5444 | else | |
5445 | val &= ~PIPECONF_EDP_RR_MODE_SWITCH; | |
439d7ac0 PB |
5446 | } |
5447 | I915_WRITE(reg, val); | |
5448 | } | |
5449 | ||
4e9ac947 VK |
5450 | dev_priv->drrs.refresh_rate_type = index; |
5451 | ||
5452 | DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate); | |
5453 | } | |
5454 | ||
b33a2815 VK |
5455 | /** |
5456 | * intel_edp_drrs_enable - init drrs struct if supported | |
5457 | * @intel_dp: DP struct | |
5458 | * | |
5459 | * Initializes frontbuffer_bits and drrs.dp | |
5460 | */ | |
c395578e VK |
5461 | void intel_edp_drrs_enable(struct intel_dp *intel_dp) |
5462 | { | |
5463 | struct drm_device *dev = intel_dp_to_dev(intel_dp); | |
5464 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5465 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); | |
5466 | struct drm_crtc *crtc = dig_port->base.base.crtc; | |
5467 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
5468 | ||
5469 | if (!intel_crtc->config->has_drrs) { | |
5470 | DRM_DEBUG_KMS("Panel doesn't support DRRS\n"); | |
5471 | return; | |
5472 | } | |
5473 | ||
5474 | mutex_lock(&dev_priv->drrs.mutex); | |
5475 | if (WARN_ON(dev_priv->drrs.dp)) { | |
5476 | DRM_ERROR("DRRS already enabled\n"); | |
5477 | goto unlock; | |
5478 | } | |
5479 | ||
5480 | dev_priv->drrs.busy_frontbuffer_bits = 0; | |
5481 | ||
5482 | dev_priv->drrs.dp = intel_dp; | |
5483 | ||
5484 | unlock: | |
5485 | mutex_unlock(&dev_priv->drrs.mutex); | |
5486 | } | |
5487 | ||
b33a2815 VK |
5488 | /** |
5489 | * intel_edp_drrs_disable - Disable DRRS | |
5490 | * @intel_dp: DP struct | |
5491 | * | |
5492 | */ | |
c395578e VK |
5493 | void intel_edp_drrs_disable(struct intel_dp *intel_dp) |
5494 | { | |
5495 | struct drm_device *dev = intel_dp_to_dev(intel_dp); | |
5496 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5497 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); | |
5498 | struct drm_crtc *crtc = dig_port->base.base.crtc; | |
5499 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
5500 | ||
5501 | if (!intel_crtc->config->has_drrs) | |
5502 | return; | |
5503 | ||
5504 | mutex_lock(&dev_priv->drrs.mutex); | |
5505 | if (!dev_priv->drrs.dp) { | |
5506 | mutex_unlock(&dev_priv->drrs.mutex); | |
5507 | return; | |
5508 | } | |
5509 | ||
5510 | if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR) | |
5511 | intel_dp_set_drrs_state(dev_priv->dev, | |
5512 | intel_dp->attached_connector->panel. | |
5513 | fixed_mode->vrefresh); | |
5514 | ||
5515 | dev_priv->drrs.dp = NULL; | |
5516 | mutex_unlock(&dev_priv->drrs.mutex); | |
5517 | ||
5518 | cancel_delayed_work_sync(&dev_priv->drrs.work); | |
5519 | } | |
5520 | ||
4e9ac947 VK |
5521 | static void intel_edp_drrs_downclock_work(struct work_struct *work) |
5522 | { | |
5523 | struct drm_i915_private *dev_priv = | |
5524 | container_of(work, typeof(*dev_priv), drrs.work.work); | |
5525 | struct intel_dp *intel_dp; | |
5526 | ||
5527 | mutex_lock(&dev_priv->drrs.mutex); | |
5528 | ||
5529 | intel_dp = dev_priv->drrs.dp; | |
5530 | ||
5531 | if (!intel_dp) | |
5532 | goto unlock; | |
5533 | ||
439d7ac0 | 5534 | /* |
4e9ac947 VK |
5535 | * The delayed work can race with an invalidate hence we need to |
5536 | * recheck. | |
439d7ac0 PB |
5537 | */ |
5538 | ||
4e9ac947 VK |
5539 | if (dev_priv->drrs.busy_frontbuffer_bits) |
5540 | goto unlock; | |
439d7ac0 | 5541 | |
4e9ac947 VK |
5542 | if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) |
5543 | intel_dp_set_drrs_state(dev_priv->dev, | |
5544 | intel_dp->attached_connector->panel. | |
5545 | downclock_mode->vrefresh); | |
439d7ac0 | 5546 | |
4e9ac947 | 5547 | unlock: |
4e9ac947 | 5548 | mutex_unlock(&dev_priv->drrs.mutex); |
439d7ac0 PB |
5549 | } |
5550 | ||
b33a2815 | 5551 | /** |
0ddfd203 | 5552 | * intel_edp_drrs_invalidate - Disable Idleness DRRS |
b33a2815 VK |
5553 | * @dev: DRM device |
5554 | * @frontbuffer_bits: frontbuffer plane tracking bits | |
5555 | * | |
0ddfd203 R |
5556 | * This function gets called everytime rendering on the given planes start. |
5557 | * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR). | |
b33a2815 VK |
5558 | * |
5559 | * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits. | |
5560 | */ | |
a93fad0f VK |
5561 | void intel_edp_drrs_invalidate(struct drm_device *dev, |
5562 | unsigned frontbuffer_bits) | |
5563 | { | |
5564 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5565 | struct drm_crtc *crtc; | |
5566 | enum pipe pipe; | |
5567 | ||
9da7d693 | 5568 | if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED) |
a93fad0f VK |
5569 | return; |
5570 | ||
88f933a8 | 5571 | cancel_delayed_work(&dev_priv->drrs.work); |
3954e733 | 5572 | |
a93fad0f | 5573 | mutex_lock(&dev_priv->drrs.mutex); |
9da7d693 DV |
5574 | if (!dev_priv->drrs.dp) { |
5575 | mutex_unlock(&dev_priv->drrs.mutex); | |
5576 | return; | |
5577 | } | |
5578 | ||
a93fad0f VK |
5579 | crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc; |
5580 | pipe = to_intel_crtc(crtc)->pipe; | |
5581 | ||
c1d038c6 DV |
5582 | frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe); |
5583 | dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits; | |
5584 | ||
0ddfd203 | 5585 | /* invalidate means busy screen hence upclock */ |
c1d038c6 | 5586 | if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR) |
a93fad0f VK |
5587 | intel_dp_set_drrs_state(dev_priv->dev, |
5588 | dev_priv->drrs.dp->attached_connector->panel. | |
5589 | fixed_mode->vrefresh); | |
a93fad0f | 5590 | |
a93fad0f VK |
5591 | mutex_unlock(&dev_priv->drrs.mutex); |
5592 | } | |
5593 | ||
b33a2815 | 5594 | /** |
0ddfd203 | 5595 | * intel_edp_drrs_flush - Restart Idleness DRRS |
b33a2815 VK |
5596 | * @dev: DRM device |
5597 | * @frontbuffer_bits: frontbuffer plane tracking bits | |
5598 | * | |
0ddfd203 R |
5599 | * This function gets called every time rendering on the given planes has |
5600 | * completed or flip on a crtc is completed. So DRRS should be upclocked | |
5601 | * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again, | |
5602 | * if no other planes are dirty. | |
b33a2815 VK |
5603 | * |
5604 | * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits. | |
5605 | */ | |
a93fad0f VK |
5606 | void intel_edp_drrs_flush(struct drm_device *dev, |
5607 | unsigned frontbuffer_bits) | |
5608 | { | |
5609 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5610 | struct drm_crtc *crtc; | |
5611 | enum pipe pipe; | |
5612 | ||
9da7d693 | 5613 | if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED) |
a93fad0f VK |
5614 | return; |
5615 | ||
88f933a8 | 5616 | cancel_delayed_work(&dev_priv->drrs.work); |
3954e733 | 5617 | |
a93fad0f | 5618 | mutex_lock(&dev_priv->drrs.mutex); |
9da7d693 DV |
5619 | if (!dev_priv->drrs.dp) { |
5620 | mutex_unlock(&dev_priv->drrs.mutex); | |
5621 | return; | |
5622 | } | |
5623 | ||
a93fad0f VK |
5624 | crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc; |
5625 | pipe = to_intel_crtc(crtc)->pipe; | |
c1d038c6 DV |
5626 | |
5627 | frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe); | |
a93fad0f VK |
5628 | dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits; |
5629 | ||
0ddfd203 | 5630 | /* flush means busy screen hence upclock */ |
c1d038c6 | 5631 | if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR) |
0ddfd203 R |
5632 | intel_dp_set_drrs_state(dev_priv->dev, |
5633 | dev_priv->drrs.dp->attached_connector->panel. | |
5634 | fixed_mode->vrefresh); | |
5635 | ||
5636 | /* | |
5637 | * flush also means no more activity hence schedule downclock, if all | |
5638 | * other fbs are quiescent too | |
5639 | */ | |
5640 | if (!dev_priv->drrs.busy_frontbuffer_bits) | |
a93fad0f VK |
5641 | schedule_delayed_work(&dev_priv->drrs.work, |
5642 | msecs_to_jiffies(1000)); | |
5643 | mutex_unlock(&dev_priv->drrs.mutex); | |
5644 | } | |
5645 | ||
b33a2815 VK |
5646 | /** |
5647 | * DOC: Display Refresh Rate Switching (DRRS) | |
5648 | * | |
5649 | * Display Refresh Rate Switching (DRRS) is a power conservation feature | |
5650 | * which enables swtching between low and high refresh rates, | |
5651 | * dynamically, based on the usage scenario. This feature is applicable | |
5652 | * for internal panels. | |
5653 | * | |
5654 | * Indication that the panel supports DRRS is given by the panel EDID, which | |
5655 | * would list multiple refresh rates for one resolution. | |
5656 | * | |
5657 | * DRRS is of 2 types - static and seamless. | |
5658 | * Static DRRS involves changing refresh rate (RR) by doing a full modeset | |
5659 | * (may appear as a blink on screen) and is used in dock-undock scenario. | |
5660 | * Seamless DRRS involves changing RR without any visual effect to the user | |
5661 | * and can be used during normal system usage. This is done by programming | |
5662 | * certain registers. | |
5663 | * | |
5664 | * Support for static/seamless DRRS may be indicated in the VBT based on | |
5665 | * inputs from the panel spec. | |
5666 | * | |
5667 | * DRRS saves power by switching to low RR based on usage scenarios. | |
5668 | * | |
5669 | * eDP DRRS:- | |
5670 | * The implementation is based on frontbuffer tracking implementation. | |
5671 | * When there is a disturbance on the screen triggered by user activity or a | |
5672 | * periodic system activity, DRRS is disabled (RR is changed to high RR). | |
5673 | * When there is no movement on screen, after a timeout of 1 second, a switch | |
5674 | * to low RR is made. | |
5675 | * For integration with frontbuffer tracking code, | |
5676 | * intel_edp_drrs_invalidate() and intel_edp_drrs_flush() are called. | |
5677 | * | |
5678 | * DRRS can be further extended to support other internal panels and also | |
5679 | * the scenario of video playback wherein RR is set based on the rate | |
5680 | * requested by userspace. | |
5681 | */ | |
5682 | ||
5683 | /** | |
5684 | * intel_dp_drrs_init - Init basic DRRS work and mutex. | |
5685 | * @intel_connector: eDP connector | |
5686 | * @fixed_mode: preferred mode of panel | |
5687 | * | |
5688 | * This function is called only once at driver load to initialize basic | |
5689 | * DRRS stuff. | |
5690 | * | |
5691 | * Returns: | |
5692 | * Downclock mode if panel supports it, else return NULL. | |
5693 | * DRRS support is determined by the presence of downclock mode (apart | |
5694 | * from VBT setting). | |
5695 | */ | |
4f9db5b5 | 5696 | static struct drm_display_mode * |
96178eeb VK |
5697 | intel_dp_drrs_init(struct intel_connector *intel_connector, |
5698 | struct drm_display_mode *fixed_mode) | |
4f9db5b5 PB |
5699 | { |
5700 | struct drm_connector *connector = &intel_connector->base; | |
96178eeb | 5701 | struct drm_device *dev = connector->dev; |
4f9db5b5 PB |
5702 | struct drm_i915_private *dev_priv = dev->dev_private; |
5703 | struct drm_display_mode *downclock_mode = NULL; | |
5704 | ||
9da7d693 DV |
5705 | INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work); |
5706 | mutex_init(&dev_priv->drrs.mutex); | |
5707 | ||
4f9db5b5 PB |
5708 | if (INTEL_INFO(dev)->gen <= 6) { |
5709 | DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n"); | |
5710 | return NULL; | |
5711 | } | |
5712 | ||
5713 | if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) { | |
4079b8d1 | 5714 | DRM_DEBUG_KMS("VBT doesn't support DRRS\n"); |
4f9db5b5 PB |
5715 | return NULL; |
5716 | } | |
5717 | ||
5718 | downclock_mode = intel_find_panel_downclock | |
5719 | (dev, fixed_mode, connector); | |
5720 | ||
5721 | if (!downclock_mode) { | |
a1d26342 | 5722 | DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n"); |
4f9db5b5 PB |
5723 | return NULL; |
5724 | } | |
5725 | ||
96178eeb | 5726 | dev_priv->drrs.type = dev_priv->vbt.drrs_type; |
4f9db5b5 | 5727 | |
96178eeb | 5728 | dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR; |
4079b8d1 | 5729 | DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n"); |
4f9db5b5 PB |
5730 | return downclock_mode; |
5731 | } | |
5732 | ||
ed92f0b2 | 5733 | static bool intel_edp_init_connector(struct intel_dp *intel_dp, |
36b5f425 | 5734 | struct intel_connector *intel_connector) |
ed92f0b2 PZ |
5735 | { |
5736 | struct drm_connector *connector = &intel_connector->base; | |
5737 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); | |
63635217 PZ |
5738 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
5739 | struct drm_device *dev = intel_encoder->base.dev; | |
ed92f0b2 PZ |
5740 | struct drm_i915_private *dev_priv = dev->dev_private; |
5741 | struct drm_display_mode *fixed_mode = NULL; | |
4f9db5b5 | 5742 | struct drm_display_mode *downclock_mode = NULL; |
ed92f0b2 PZ |
5743 | bool has_dpcd; |
5744 | struct drm_display_mode *scan; | |
5745 | struct edid *edid; | |
6517d273 | 5746 | enum pipe pipe = INVALID_PIPE; |
ed92f0b2 PZ |
5747 | |
5748 | if (!is_edp(intel_dp)) | |
5749 | return true; | |
5750 | ||
49e6bc51 VS |
5751 | pps_lock(intel_dp); |
5752 | intel_edp_panel_vdd_sanitize(intel_dp); | |
5753 | pps_unlock(intel_dp); | |
63635217 | 5754 | |
ed92f0b2 | 5755 | /* Cache DPCD and EDID for edp. */ |
ed92f0b2 | 5756 | has_dpcd = intel_dp_get_dpcd(intel_dp); |
ed92f0b2 PZ |
5757 | |
5758 | if (has_dpcd) { | |
5759 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) | |
5760 | dev_priv->no_aux_handshake = | |
5761 | intel_dp->dpcd[DP_MAX_DOWNSPREAD] & | |
5762 | DP_NO_AUX_HANDSHAKE_LINK_TRAINING; | |
5763 | } else { | |
5764 | /* if this fails, presume the device is a ghost */ | |
5765 | DRM_INFO("failed to retrieve link info, disabling eDP\n"); | |
ed92f0b2 PZ |
5766 | return false; |
5767 | } | |
5768 | ||
5769 | /* We now know it's not a ghost, init power sequence regs. */ | |
773538e8 | 5770 | pps_lock(intel_dp); |
36b5f425 | 5771 | intel_dp_init_panel_power_sequencer_registers(dev, intel_dp); |
773538e8 | 5772 | pps_unlock(intel_dp); |
ed92f0b2 | 5773 | |
060c8778 | 5774 | mutex_lock(&dev->mode_config.mutex); |
0b99836f | 5775 | edid = drm_get_edid(connector, &intel_dp->aux.ddc); |
ed92f0b2 PZ |
5776 | if (edid) { |
5777 | if (drm_add_edid_modes(connector, edid)) { | |
5778 | drm_mode_connector_update_edid_property(connector, | |
5779 | edid); | |
5780 | drm_edid_to_eld(connector, edid); | |
5781 | } else { | |
5782 | kfree(edid); | |
5783 | edid = ERR_PTR(-EINVAL); | |
5784 | } | |
5785 | } else { | |
5786 | edid = ERR_PTR(-ENOENT); | |
5787 | } | |
5788 | intel_connector->edid = edid; | |
5789 | ||
5790 | /* prefer fixed mode from EDID if available */ | |
5791 | list_for_each_entry(scan, &connector->probed_modes, head) { | |
5792 | if ((scan->type & DRM_MODE_TYPE_PREFERRED)) { | |
5793 | fixed_mode = drm_mode_duplicate(dev, scan); | |
4f9db5b5 | 5794 | downclock_mode = intel_dp_drrs_init( |
4f9db5b5 | 5795 | intel_connector, fixed_mode); |
ed92f0b2 PZ |
5796 | break; |
5797 | } | |
5798 | } | |
5799 | ||
5800 | /* fallback to VBT if available for eDP */ | |
5801 | if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) { | |
5802 | fixed_mode = drm_mode_duplicate(dev, | |
5803 | dev_priv->vbt.lfp_lvds_vbt_mode); | |
5804 | if (fixed_mode) | |
5805 | fixed_mode->type |= DRM_MODE_TYPE_PREFERRED; | |
5806 | } | |
060c8778 | 5807 | mutex_unlock(&dev->mode_config.mutex); |
ed92f0b2 | 5808 | |
666a4537 | 5809 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
01527b31 CT |
5810 | intel_dp->edp_notifier.notifier_call = edp_notify_handler; |
5811 | register_reboot_notifier(&intel_dp->edp_notifier); | |
6517d273 VS |
5812 | |
5813 | /* | |
5814 | * Figure out the current pipe for the initial backlight setup. | |
5815 | * If the current pipe isn't valid, try the PPS pipe, and if that | |
5816 | * fails just assume pipe A. | |
5817 | */ | |
5818 | if (IS_CHERRYVIEW(dev)) | |
5819 | pipe = DP_PORT_TO_PIPE_CHV(intel_dp->DP); | |
5820 | else | |
5821 | pipe = PORT_TO_PIPE(intel_dp->DP); | |
5822 | ||
5823 | if (pipe != PIPE_A && pipe != PIPE_B) | |
5824 | pipe = intel_dp->pps_pipe; | |
5825 | ||
5826 | if (pipe != PIPE_A && pipe != PIPE_B) | |
5827 | pipe = PIPE_A; | |
5828 | ||
5829 | DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n", | |
5830 | pipe_name(pipe)); | |
01527b31 CT |
5831 | } |
5832 | ||
4f9db5b5 | 5833 | intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode); |
5507faeb | 5834 | intel_connector->panel.backlight.power = intel_edp_backlight_power; |
6517d273 | 5835 | intel_panel_setup_backlight(connector, pipe); |
ed92f0b2 PZ |
5836 | |
5837 | return true; | |
5838 | } | |
5839 | ||
16c25533 | 5840 | bool |
f0fec3f2 PZ |
5841 | intel_dp_init_connector(struct intel_digital_port *intel_dig_port, |
5842 | struct intel_connector *intel_connector) | |
a4fc5ed6 | 5843 | { |
f0fec3f2 PZ |
5844 | struct drm_connector *connector = &intel_connector->base; |
5845 | struct intel_dp *intel_dp = &intel_dig_port->dp; | |
5846 | struct intel_encoder *intel_encoder = &intel_dig_port->base; | |
5847 | struct drm_device *dev = intel_encoder->base.dev; | |
a4fc5ed6 | 5848 | struct drm_i915_private *dev_priv = dev->dev_private; |
174edf1f | 5849 | enum port port = intel_dig_port->port; |
a121f4e5 | 5850 | int type, ret; |
a4fc5ed6 | 5851 | |
ccb1a831 VS |
5852 | if (WARN(intel_dig_port->max_lanes < 1, |
5853 | "Not enough lanes (%d) for DP on port %c\n", | |
5854 | intel_dig_port->max_lanes, port_name(port))) | |
5855 | return false; | |
5856 | ||
a4a5d2f8 VS |
5857 | intel_dp->pps_pipe = INVALID_PIPE; |
5858 | ||
ec5b01dd | 5859 | /* intel_dp vfuncs */ |
b6b5e383 DL |
5860 | if (INTEL_INFO(dev)->gen >= 9) |
5861 | intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider; | |
666a4537 | 5862 | else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) |
ec5b01dd DL |
5863 | intel_dp->get_aux_clock_divider = vlv_get_aux_clock_divider; |
5864 | else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) | |
5865 | intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider; | |
5866 | else if (HAS_PCH_SPLIT(dev)) | |
5867 | intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider; | |
5868 | else | |
5869 | intel_dp->get_aux_clock_divider = i9xx_get_aux_clock_divider; | |
5870 | ||
b9ca5fad DL |
5871 | if (INTEL_INFO(dev)->gen >= 9) |
5872 | intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl; | |
5873 | else | |
5874 | intel_dp->get_aux_send_ctl = i9xx_get_aux_send_ctl; | |
153b1100 | 5875 | |
ad64217b ACO |
5876 | if (HAS_DDI(dev)) |
5877 | intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain; | |
5878 | ||
0767935e DV |
5879 | /* Preserve the current hw state. */ |
5880 | intel_dp->DP = I915_READ(intel_dp->output_reg); | |
dd06f90e | 5881 | intel_dp->attached_connector = intel_connector; |
3d3dc149 | 5882 | |
3b32a35b | 5883 | if (intel_dp_is_edp(dev, port)) |
b329530c | 5884 | type = DRM_MODE_CONNECTOR_eDP; |
3b32a35b VS |
5885 | else |
5886 | type = DRM_MODE_CONNECTOR_DisplayPort; | |
b329530c | 5887 | |
f7d24902 ID |
5888 | /* |
5889 | * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but | |
5890 | * for DP the encoder type can be set by the caller to | |
5891 | * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it. | |
5892 | */ | |
5893 | if (type == DRM_MODE_CONNECTOR_eDP) | |
5894 | intel_encoder->type = INTEL_OUTPUT_EDP; | |
5895 | ||
c17ed5b5 | 5896 | /* eDP only on port B and/or C on vlv/chv */ |
666a4537 WB |
5897 | if (WARN_ON((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) && |
5898 | is_edp(intel_dp) && port != PORT_B && port != PORT_C)) | |
c17ed5b5 VS |
5899 | return false; |
5900 | ||
e7281eab ID |
5901 | DRM_DEBUG_KMS("Adding %s connector on port %c\n", |
5902 | type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP", | |
5903 | port_name(port)); | |
5904 | ||
b329530c | 5905 | drm_connector_init(dev, connector, &intel_dp_connector_funcs, type); |
a4fc5ed6 KP |
5906 | drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs); |
5907 | ||
a4fc5ed6 KP |
5908 | connector->interlace_allowed = true; |
5909 | connector->doublescan_allowed = 0; | |
5910 | ||
f0fec3f2 | 5911 | INIT_DELAYED_WORK(&intel_dp->panel_vdd_work, |
4be73780 | 5912 | edp_panel_vdd_work); |
a4fc5ed6 | 5913 | |
df0e9248 | 5914 | intel_connector_attach_encoder(intel_connector, intel_encoder); |
34ea3d38 | 5915 | drm_connector_register(connector); |
a4fc5ed6 | 5916 | |
affa9354 | 5917 | if (HAS_DDI(dev)) |
bcbc889b PZ |
5918 | intel_connector->get_hw_state = intel_ddi_connector_get_hw_state; |
5919 | else | |
5920 | intel_connector->get_hw_state = intel_connector_get_hw_state; | |
80f65de3 | 5921 | intel_connector->unregister = intel_dp_connector_unregister; |
bcbc889b | 5922 | |
0b99836f | 5923 | /* Set up the hotplug pin. */ |
ab9d7c30 PZ |
5924 | switch (port) { |
5925 | case PORT_A: | |
1d843f9d | 5926 | intel_encoder->hpd_pin = HPD_PORT_A; |
ab9d7c30 PZ |
5927 | break; |
5928 | case PORT_B: | |
1d843f9d | 5929 | intel_encoder->hpd_pin = HPD_PORT_B; |
e87a005d | 5930 | if (IS_BXT_REVID(dev, 0, BXT_REVID_A1)) |
cf1d5883 | 5931 | intel_encoder->hpd_pin = HPD_PORT_A; |
ab9d7c30 PZ |
5932 | break; |
5933 | case PORT_C: | |
1d843f9d | 5934 | intel_encoder->hpd_pin = HPD_PORT_C; |
ab9d7c30 PZ |
5935 | break; |
5936 | case PORT_D: | |
1d843f9d | 5937 | intel_encoder->hpd_pin = HPD_PORT_D; |
ab9d7c30 | 5938 | break; |
26951caf XZ |
5939 | case PORT_E: |
5940 | intel_encoder->hpd_pin = HPD_PORT_E; | |
5941 | break; | |
ab9d7c30 | 5942 | default: |
ad1c0b19 | 5943 | BUG(); |
5eb08b69 ZW |
5944 | } |
5945 | ||
dada1a9f | 5946 | if (is_edp(intel_dp)) { |
773538e8 | 5947 | pps_lock(intel_dp); |
1e74a324 | 5948 | intel_dp_init_panel_power_timestamps(intel_dp); |
666a4537 | 5949 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) |
a4a5d2f8 | 5950 | vlv_initial_power_sequencer_setup(intel_dp); |
1e74a324 | 5951 | else |
36b5f425 | 5952 | intel_dp_init_panel_power_sequencer(dev, intel_dp); |
773538e8 | 5953 | pps_unlock(intel_dp); |
dada1a9f | 5954 | } |
0095e6dc | 5955 | |
a121f4e5 VS |
5956 | ret = intel_dp_aux_init(intel_dp, intel_connector); |
5957 | if (ret) | |
5958 | goto fail; | |
c1f05264 | 5959 | |
0e32b39c | 5960 | /* init MST on ports that can support it */ |
0c9b3715 JN |
5961 | if (HAS_DP_MST(dev) && |
5962 | (port == PORT_B || port == PORT_C || port == PORT_D)) | |
5963 | intel_dp_mst_encoder_init(intel_dig_port, | |
5964 | intel_connector->base.base.id); | |
0e32b39c | 5965 | |
36b5f425 | 5966 | if (!intel_edp_init_connector(intel_dp, intel_connector)) { |
a121f4e5 VS |
5967 | intel_dp_aux_fini(intel_dp); |
5968 | intel_dp_mst_encoder_cleanup(intel_dig_port); | |
5969 | goto fail; | |
b2f246a8 | 5970 | } |
32f9d658 | 5971 | |
f684960e CW |
5972 | intel_dp_add_properties(intel_dp, connector); |
5973 | ||
a4fc5ed6 KP |
5974 | /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written |
5975 | * 0xd. Failure to do so will result in spurious interrupts being | |
5976 | * generated on the port when a cable is not attached. | |
5977 | */ | |
5978 | if (IS_G4X(dev) && !IS_GM45(dev)) { | |
5979 | u32 temp = I915_READ(PEG_BAND_GAP_DATA); | |
5980 | I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd); | |
5981 | } | |
16c25533 | 5982 | |
aa7471d2 JN |
5983 | i915_debugfs_connector_add(connector); |
5984 | ||
16c25533 | 5985 | return true; |
a121f4e5 VS |
5986 | |
5987 | fail: | |
5988 | if (is_edp(intel_dp)) { | |
5989 | cancel_delayed_work_sync(&intel_dp->panel_vdd_work); | |
5990 | /* | |
5991 | * vdd might still be enabled do to the delayed vdd off. | |
5992 | * Make sure vdd is actually turned off here. | |
5993 | */ | |
5994 | pps_lock(intel_dp); | |
5995 | edp_panel_vdd_off_sync(intel_dp); | |
5996 | pps_unlock(intel_dp); | |
5997 | } | |
5998 | drm_connector_unregister(connector); | |
5999 | drm_connector_cleanup(connector); | |
6000 | ||
6001 | return false; | |
a4fc5ed6 | 6002 | } |
f0fec3f2 PZ |
6003 | |
6004 | void | |
f0f59a00 VS |
6005 | intel_dp_init(struct drm_device *dev, |
6006 | i915_reg_t output_reg, enum port port) | |
f0fec3f2 | 6007 | { |
13cf5504 | 6008 | struct drm_i915_private *dev_priv = dev->dev_private; |
f0fec3f2 PZ |
6009 | struct intel_digital_port *intel_dig_port; |
6010 | struct intel_encoder *intel_encoder; | |
6011 | struct drm_encoder *encoder; | |
6012 | struct intel_connector *intel_connector; | |
6013 | ||
b14c5679 | 6014 | intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL); |
f0fec3f2 PZ |
6015 | if (!intel_dig_port) |
6016 | return; | |
6017 | ||
08d9bc92 | 6018 | intel_connector = intel_connector_alloc(); |
11aee0f6 SM |
6019 | if (!intel_connector) |
6020 | goto err_connector_alloc; | |
f0fec3f2 PZ |
6021 | |
6022 | intel_encoder = &intel_dig_port->base; | |
6023 | encoder = &intel_encoder->base; | |
6024 | ||
893da0c9 | 6025 | if (drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs, |
ade1ba73 | 6026 | DRM_MODE_ENCODER_TMDS, NULL)) |
893da0c9 | 6027 | goto err_encoder_init; |
f0fec3f2 | 6028 | |
5bfe2ac0 | 6029 | intel_encoder->compute_config = intel_dp_compute_config; |
00c09d70 | 6030 | intel_encoder->disable = intel_disable_dp; |
00c09d70 | 6031 | intel_encoder->get_hw_state = intel_dp_get_hw_state; |
045ac3b5 | 6032 | intel_encoder->get_config = intel_dp_get_config; |
07f9cd0b | 6033 | intel_encoder->suspend = intel_dp_encoder_suspend; |
e4a1d846 | 6034 | if (IS_CHERRYVIEW(dev)) { |
9197c88b | 6035 | intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable; |
e4a1d846 CML |
6036 | intel_encoder->pre_enable = chv_pre_enable_dp; |
6037 | intel_encoder->enable = vlv_enable_dp; | |
580d3811 | 6038 | intel_encoder->post_disable = chv_post_disable_dp; |
d6db995f | 6039 | intel_encoder->post_pll_disable = chv_dp_post_pll_disable; |
e4a1d846 | 6040 | } else if (IS_VALLEYVIEW(dev)) { |
ecff4f3b | 6041 | intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable; |
ab1f90f9 JN |
6042 | intel_encoder->pre_enable = vlv_pre_enable_dp; |
6043 | intel_encoder->enable = vlv_enable_dp; | |
49277c31 | 6044 | intel_encoder->post_disable = vlv_post_disable_dp; |
ab1f90f9 | 6045 | } else { |
ecff4f3b JN |
6046 | intel_encoder->pre_enable = g4x_pre_enable_dp; |
6047 | intel_encoder->enable = g4x_enable_dp; | |
08aff3fe VS |
6048 | if (INTEL_INFO(dev)->gen >= 5) |
6049 | intel_encoder->post_disable = ilk_post_disable_dp; | |
ab1f90f9 | 6050 | } |
f0fec3f2 | 6051 | |
174edf1f | 6052 | intel_dig_port->port = port; |
0bdf5a05 | 6053 | dev_priv->dig_port_map[port] = intel_encoder; |
f0fec3f2 | 6054 | intel_dig_port->dp.output_reg = output_reg; |
ccb1a831 | 6055 | intel_dig_port->max_lanes = 4; |
f0fec3f2 | 6056 | |
00c09d70 | 6057 | intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT; |
882ec384 VS |
6058 | if (IS_CHERRYVIEW(dev)) { |
6059 | if (port == PORT_D) | |
6060 | intel_encoder->crtc_mask = 1 << 2; | |
6061 | else | |
6062 | intel_encoder->crtc_mask = (1 << 0) | (1 << 1); | |
6063 | } else { | |
6064 | intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2); | |
6065 | } | |
bc079e8b | 6066 | intel_encoder->cloneable = 0; |
f0fec3f2 | 6067 | |
13cf5504 | 6068 | intel_dig_port->hpd_pulse = intel_dp_hpd_pulse; |
5fcece80 | 6069 | dev_priv->hotplug.irq_port[port] = intel_dig_port; |
13cf5504 | 6070 | |
11aee0f6 SM |
6071 | if (!intel_dp_init_connector(intel_dig_port, intel_connector)) |
6072 | goto err_init_connector; | |
6073 | ||
6074 | return; | |
6075 | ||
6076 | err_init_connector: | |
6077 | drm_encoder_cleanup(encoder); | |
893da0c9 | 6078 | err_encoder_init: |
11aee0f6 SM |
6079 | kfree(intel_connector); |
6080 | err_connector_alloc: | |
6081 | kfree(intel_dig_port); | |
6082 | ||
6083 | return; | |
f0fec3f2 | 6084 | } |
0e32b39c DA |
6085 | |
6086 | void intel_dp_mst_suspend(struct drm_device *dev) | |
6087 | { | |
6088 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6089 | int i; | |
6090 | ||
6091 | /* disable MST */ | |
6092 | for (i = 0; i < I915_MAX_PORTS; i++) { | |
5fcece80 | 6093 | struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i]; |
0e32b39c DA |
6094 | if (!intel_dig_port) |
6095 | continue; | |
6096 | ||
6097 | if (intel_dig_port->base.type == INTEL_OUTPUT_DISPLAYPORT) { | |
6098 | if (!intel_dig_port->dp.can_mst) | |
6099 | continue; | |
6100 | if (intel_dig_port->dp.is_mst) | |
6101 | drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr); | |
6102 | } | |
6103 | } | |
6104 | } | |
6105 | ||
6106 | void intel_dp_mst_resume(struct drm_device *dev) | |
6107 | { | |
6108 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6109 | int i; | |
6110 | ||
6111 | for (i = 0; i < I915_MAX_PORTS; i++) { | |
5fcece80 | 6112 | struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i]; |
0e32b39c DA |
6113 | if (!intel_dig_port) |
6114 | continue; | |
6115 | if (intel_dig_port->base.type == INTEL_OUTPUT_DISPLAYPORT) { | |
6116 | int ret; | |
6117 | ||
6118 | if (!intel_dig_port->dp.can_mst) | |
6119 | continue; | |
6120 | ||
6121 | ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr); | |
6122 | if (ret != 0) { | |
6123 | intel_dp_check_mst_status(&intel_dig_port->dp); | |
6124 | } | |
6125 | } | |
6126 | } | |
6127 | } |