blob: 9db977b475f8e42b71d9292c6969ba436c9b5d56 [file] [log] [blame]
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001/*
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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040030#include <linux/export.h>
Clint Taylor01527b32014-07-07 13:01:46 -070031#include <linux/notifier.h>
32#include <linux/reboot.h>
David Howells760285e2012-10-02 18:01:07 +010033#include <drm/drmP.h>
34#include <drm/drm_crtc.h>
35#include <drm/drm_crtc_helper.h>
36#include <drm/drm_edid.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070037#include "intel_drv.h"
David Howells760285e2012-10-02 18:01:07 +010038#include <drm/i915_drm.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070039#include "i915_drv.h"
Keith Packarda4fc5ed2009-04-07 16:16:42 -070040
Keith Packarda4fc5ed2009-04-07 16:16:42 -070041#define DP_LINK_CHECK_TIMEOUT (10 * 1000)
42
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080043struct dp_link_dpll {
44 int link_bw;
45 struct dpll dpll;
46};
47
48static const struct dp_link_dpll gen4_dpll[] = {
49 { DP_LINK_BW_1_62,
50 { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
51 { DP_LINK_BW_2_7,
52 { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
53};
54
55static const struct dp_link_dpll pch_dpll[] = {
56 { DP_LINK_BW_1_62,
57 { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
58 { DP_LINK_BW_2_7,
59 { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
60};
61
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080062static const struct dp_link_dpll vlv_dpll[] = {
63 { DP_LINK_BW_1_62,
Chon Ming Lee58f6e632013-09-25 15:47:51 +080064 { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } },
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080065 { DP_LINK_BW_2_7,
66 { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } }
67};
68
Chon Ming Leeef9348c2014-04-09 13:28:18 +030069/*
70 * CHV supports eDP 1.4 that have more link rates.
71 * Below only provides the fixed rate but exclude variable rate.
72 */
73static const struct dp_link_dpll chv_dpll[] = {
74 /*
75 * CHV requires to program fractional division for m2.
76 * m2 is stored in fixed point format using formula below
77 * (m2_int << 22) | m2_fraction
78 */
79 { DP_LINK_BW_1_62, /* m2_int = 32, m2_fraction = 1677722 */
80 { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } },
81 { DP_LINK_BW_2_7, /* m2_int = 27, m2_fraction = 0 */
82 { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } },
83 { DP_LINK_BW_5_4, /* m2_int = 27, m2_fraction = 0 */
84 { .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }
85};
86
Jesse Barnescfcb0fc2010-10-07 16:01:06 -070087/**
88 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
89 * @intel_dp: DP struct
90 *
91 * If a CPU or PCH DP output is attached to an eDP panel, this function
92 * will return true, and false otherwise.
93 */
94static bool is_edp(struct intel_dp *intel_dp)
95{
Paulo Zanonida63a9f2012-10-26 19:05:46 -020096 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
97
98 return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -070099}
100
Imre Deak68b4d822013-05-08 13:14:06 +0300101static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp)
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700102{
Imre Deak68b4d822013-05-08 13:14:06 +0300103 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
104
105 return intel_dig_port->base.base.dev;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700106}
107
Chris Wilsondf0e9242010-09-09 16:20:55 +0100108static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
109{
Paulo Zanonifa90ece2012-10-26 19:05:44 -0200110 return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
Chris Wilsondf0e9242010-09-09 16:20:55 +0100111}
112
Chris Wilsonea5b2132010-08-04 13:50:23 +0100113static void intel_dp_link_down(struct intel_dp *intel_dp);
Ville Syrjälä1e0560e2014-08-19 13:24:25 +0300114static bool edp_panel_vdd_on(struct intel_dp *intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +0100115static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
Ville Syrjälä093e3f12014-10-16 21:27:33 +0300116static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300117static void vlv_steal_power_sequencer(struct drm_device *dev,
118 enum pipe pipe);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700119
Dave Airlie0e32b392014-05-02 14:02:48 +1000120int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100121intel_dp_max_link_bw(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700122{
Jesse Barnes7183dc22011-07-07 11:10:58 -0700123 int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
Todd Previte06ea66b2014-01-20 10:19:39 -0700124 struct drm_device *dev = intel_dp->attached_connector->base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700125
126 switch (max_link_bw) {
127 case DP_LINK_BW_1_62:
128 case DP_LINK_BW_2_7:
129 break;
Imre Deakd4eead52013-07-09 17:05:26 +0300130 case DP_LINK_BW_5_4: /* 1.2 capable displays may advertise higher bw */
Paulo Zanoni9bbfd202014-04-29 11:00:22 -0300131 if (((IS_HASWELL(dev) && !IS_HSW_ULX(dev)) ||
132 INTEL_INFO(dev)->gen >= 8) &&
Todd Previte06ea66b2014-01-20 10:19:39 -0700133 intel_dp->dpcd[DP_DPCD_REV] >= 0x12)
134 max_link_bw = DP_LINK_BW_5_4;
135 else
136 max_link_bw = DP_LINK_BW_2_7;
Imre Deakd4eead52013-07-09 17:05:26 +0300137 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700138 default:
Imre Deakd4eead52013-07-09 17:05:26 +0300139 WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
140 max_link_bw);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700141 max_link_bw = DP_LINK_BW_1_62;
142 break;
143 }
144 return max_link_bw;
145}
146
Paulo Zanonieeb63242014-05-06 14:56:50 +0300147static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
148{
149 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
150 struct drm_device *dev = intel_dig_port->base.base.dev;
151 u8 source_max, sink_max;
152
153 source_max = 4;
154 if (HAS_DDI(dev) && intel_dig_port->port == PORT_A &&
155 (intel_dig_port->saved_port_bits & DDI_A_4_LANES) == 0)
156 source_max = 2;
157
158 sink_max = drm_dp_max_lane_count(intel_dp->dpcd);
159
160 return min(source_max, sink_max);
161}
162
Adam Jacksoncd9dde42011-10-14 12:43:49 -0400163/*
164 * The units on the numbers in the next two are... bizarre. Examples will
165 * make it clearer; this one parallels an example in the eDP spec.
166 *
167 * intel_dp_max_data_rate for one lane of 2.7GHz evaluates as:
168 *
169 * 270000 * 1 * 8 / 10 == 216000
170 *
171 * The actual data capacity of that configuration is 2.16Gbit/s, so the
172 * units are decakilobits. ->clock in a drm_display_mode is in kilohertz -
173 * or equivalently, kilopixels per second - so for 1680x1050R it'd be
174 * 119000. At 18bpp that's 2142000 kilobits per second.
175 *
176 * Thus the strange-looking division by 10 in intel_dp_link_required, to
177 * get the result in decakilobits instead of kilobits.
178 */
179
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700180static int
Keith Packardc8982612012-01-25 08:16:25 -0800181intel_dp_link_required(int pixel_clock, int bpp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700182{
Adam Jacksoncd9dde42011-10-14 12:43:49 -0400183 return (pixel_clock * bpp + 9) / 10;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700184}
185
186static int
Dave Airliefe27d532010-06-30 11:46:17 +1000187intel_dp_max_data_rate(int max_link_clock, int max_lanes)
188{
189 return (max_link_clock * max_lanes * 8) / 10;
190}
191
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000192static enum drm_mode_status
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700193intel_dp_mode_valid(struct drm_connector *connector,
194 struct drm_display_mode *mode)
195{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100196 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300197 struct intel_connector *intel_connector = to_intel_connector(connector);
198 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Daniel Vetter36008362013-03-27 00:44:59 +0100199 int target_clock = mode->clock;
200 int max_rate, mode_rate, max_lanes, max_link_clock;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700201
Jani Nikuladd06f902012-10-19 14:51:50 +0300202 if (is_edp(intel_dp) && fixed_mode) {
203 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100204 return MODE_PANEL;
205
Jani Nikuladd06f902012-10-19 14:51:50 +0300206 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100207 return MODE_PANEL;
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200208
209 target_clock = fixed_mode->clock;
Zhao Yakui7de56f42010-07-19 09:43:14 +0100210 }
211
Daniel Vetter36008362013-03-27 00:44:59 +0100212 max_link_clock = drm_dp_bw_code_to_link_rate(intel_dp_max_link_bw(intel_dp));
Paulo Zanonieeb63242014-05-06 14:56:50 +0300213 max_lanes = intel_dp_max_lane_count(intel_dp);
Daniel Vetter36008362013-03-27 00:44:59 +0100214
215 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
216 mode_rate = intel_dp_link_required(target_clock, 18);
217
218 if (mode_rate > max_rate)
Daniel Vetterc4867932012-04-10 10:42:36 +0200219 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700220
221 if (mode->clock < 10000)
222 return MODE_CLOCK_LOW;
223
Daniel Vetter0af78a22012-05-23 11:30:55 +0200224 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
225 return MODE_H_ILLEGAL;
226
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700227 return MODE_OK;
228}
229
230static uint32_t
Ville Syrjälä5ca476f2014-10-01 16:56:56 +0300231pack_aux(const uint8_t *src, int src_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700232{
233 int i;
234 uint32_t v = 0;
235
236 if (src_bytes > 4)
237 src_bytes = 4;
238 for (i = 0; i < src_bytes; i++)
239 v |= ((uint32_t) src[i]) << ((3-i) * 8);
240 return v;
241}
242
243static void
244unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
245{
246 int i;
247 if (dst_bytes > 4)
248 dst_bytes = 4;
249 for (i = 0; i < dst_bytes; i++)
250 dst[i] = src >> ((3-i) * 8);
251}
252
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700253/* hrawclock is 1/4 the FSB frequency */
254static int
255intel_hrawclk(struct drm_device *dev)
256{
257 struct drm_i915_private *dev_priv = dev->dev_private;
258 uint32_t clkcfg;
259
Vijay Purushothaman9473c8f2012-09-27 19:13:01 +0530260 /* There is no CLKCFG reg in Valleyview. VLV hrawclk is 200 MHz */
261 if (IS_VALLEYVIEW(dev))
262 return 200;
263
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700264 clkcfg = I915_READ(CLKCFG);
265 switch (clkcfg & CLKCFG_FSB_MASK) {
266 case CLKCFG_FSB_400:
267 return 100;
268 case CLKCFG_FSB_533:
269 return 133;
270 case CLKCFG_FSB_667:
271 return 166;
272 case CLKCFG_FSB_800:
273 return 200;
274 case CLKCFG_FSB_1067:
275 return 266;
276 case CLKCFG_FSB_1333:
277 return 333;
278 /* these two are just a guess; one of them might be right */
279 case CLKCFG_FSB_1600:
280 case CLKCFG_FSB_1600_ALT:
281 return 400;
282 default:
283 return 133;
284 }
285}
286
Jani Nikulabf13e812013-09-06 07:40:05 +0300287static void
288intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300289 struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300290static void
291intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300292 struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300293
Ville Syrjälä773538e82014-09-04 14:54:56 +0300294static void pps_lock(struct intel_dp *intel_dp)
295{
296 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
297 struct intel_encoder *encoder = &intel_dig_port->base;
298 struct drm_device *dev = encoder->base.dev;
299 struct drm_i915_private *dev_priv = dev->dev_private;
300 enum intel_display_power_domain power_domain;
301
302 /*
303 * See vlv_power_sequencer_reset() why we need
304 * a power domain reference here.
305 */
306 power_domain = intel_display_port_power_domain(encoder);
307 intel_display_power_get(dev_priv, power_domain);
308
309 mutex_lock(&dev_priv->pps_mutex);
310}
311
312static void pps_unlock(struct intel_dp *intel_dp)
313{
314 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
315 struct intel_encoder *encoder = &intel_dig_port->base;
316 struct drm_device *dev = encoder->base.dev;
317 struct drm_i915_private *dev_priv = dev->dev_private;
318 enum intel_display_power_domain power_domain;
319
320 mutex_unlock(&dev_priv->pps_mutex);
321
322 power_domain = intel_display_port_power_domain(encoder);
323 intel_display_power_put(dev_priv, power_domain);
324}
325
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300326static void
327vlv_power_sequencer_kick(struct intel_dp *intel_dp)
328{
329 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
330 struct drm_device *dev = intel_dig_port->base.base.dev;
331 struct drm_i915_private *dev_priv = dev->dev_private;
332 enum pipe pipe = intel_dp->pps_pipe;
333 uint32_t DP;
334
335 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
336 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
337 pipe_name(pipe), port_name(intel_dig_port->port)))
338 return;
339
340 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
341 pipe_name(pipe), port_name(intel_dig_port->port));
342
343 /* Preserve the BIOS-computed detected bit. This is
344 * supposed to be read-only.
345 */
346 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
347 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
348 DP |= DP_PORT_WIDTH(1);
349 DP |= DP_LINK_TRAIN_PAT_1;
350
351 if (IS_CHERRYVIEW(dev))
352 DP |= DP_PIPE_SELECT_CHV(pipe);
353 else if (pipe == PIPE_B)
354 DP |= DP_PIPEB_SELECT;
355
356 /*
357 * Similar magic as in intel_dp_enable_port().
358 * We _must_ do this port enable + disable trick
359 * to make this power seqeuencer lock onto the port.
360 * Otherwise even VDD force bit won't work.
361 */
362 I915_WRITE(intel_dp->output_reg, DP);
363 POSTING_READ(intel_dp->output_reg);
364
365 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
366 POSTING_READ(intel_dp->output_reg);
367
368 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
369 POSTING_READ(intel_dp->output_reg);
370}
371
Jani Nikulabf13e812013-09-06 07:40:05 +0300372static enum pipe
373vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
374{
375 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300376 struct drm_device *dev = intel_dig_port->base.base.dev;
377 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300378 struct intel_encoder *encoder;
379 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300380 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300381
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300382 lockdep_assert_held(&dev_priv->pps_mutex);
383
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300384 /* We should never land here with regular DP ports */
385 WARN_ON(!is_edp(intel_dp));
386
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300387 if (intel_dp->pps_pipe != INVALID_PIPE)
388 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300389
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300390 /*
391 * We don't have power sequencer currently.
392 * Pick one that's not used by other ports.
393 */
394 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
395 base.head) {
396 struct intel_dp *tmp;
397
398 if (encoder->type != INTEL_OUTPUT_EDP)
399 continue;
400
401 tmp = enc_to_intel_dp(&encoder->base);
402
403 if (tmp->pps_pipe != INVALID_PIPE)
404 pipes &= ~(1 << tmp->pps_pipe);
405 }
406
407 /*
408 * Didn't find one. This should not happen since there
409 * are two power sequencers and up to two eDP ports.
410 */
411 if (WARN_ON(pipes == 0))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300412 pipe = PIPE_A;
413 else
414 pipe = ffs(pipes) - 1;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300415
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300416 vlv_steal_power_sequencer(dev, pipe);
417 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300418
419 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
420 pipe_name(intel_dp->pps_pipe),
421 port_name(intel_dig_port->port));
422
423 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300424 intel_dp_init_panel_power_sequencer(dev, intel_dp);
425 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300426
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300427 /*
428 * Even vdd force doesn't work until we've made
429 * the power sequencer lock in on the port.
430 */
431 vlv_power_sequencer_kick(intel_dp);
432
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300433 return intel_dp->pps_pipe;
434}
435
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300436typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
437 enum pipe pipe);
438
439static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
440 enum pipe pipe)
441{
442 return I915_READ(VLV_PIPE_PP_STATUS(pipe)) & PP_ON;
443}
444
445static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
446 enum pipe pipe)
447{
448 return I915_READ(VLV_PIPE_PP_CONTROL(pipe)) & EDP_FORCE_VDD;
449}
450
451static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
452 enum pipe pipe)
453{
454 return true;
455}
456
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300457static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300458vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
459 enum port port,
460 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300461{
Jani Nikulabf13e812013-09-06 07:40:05 +0300462 enum pipe pipe;
463
Jani Nikulabf13e812013-09-06 07:40:05 +0300464 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
465 u32 port_sel = I915_READ(VLV_PIPE_PP_ON_DELAYS(pipe)) &
466 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300467
468 if (port_sel != PANEL_PORT_SELECT_VLV(port))
469 continue;
470
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300471 if (!pipe_check(dev_priv, pipe))
472 continue;
473
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300474 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300475 }
476
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300477 return INVALID_PIPE;
478}
479
480static void
481vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
482{
483 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
484 struct drm_device *dev = intel_dig_port->base.base.dev;
485 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300486 enum port port = intel_dig_port->port;
487
488 lockdep_assert_held(&dev_priv->pps_mutex);
489
490 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300491 /* first pick one where the panel is on */
492 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
493 vlv_pipe_has_pp_on);
494 /* didn't find one? pick one where vdd is on */
495 if (intel_dp->pps_pipe == INVALID_PIPE)
496 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
497 vlv_pipe_has_vdd_on);
498 /* didn't find one? pick one with just the correct port */
499 if (intel_dp->pps_pipe == INVALID_PIPE)
500 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
501 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300502
503 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
504 if (intel_dp->pps_pipe == INVALID_PIPE) {
505 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
506 port_name(port));
507 return;
508 }
509
510 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
511 port_name(port), pipe_name(intel_dp->pps_pipe));
512
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300513 intel_dp_init_panel_power_sequencer(dev, intel_dp);
514 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300515}
516
Ville Syrjälä773538e82014-09-04 14:54:56 +0300517void vlv_power_sequencer_reset(struct drm_i915_private *dev_priv)
518{
519 struct drm_device *dev = dev_priv->dev;
520 struct intel_encoder *encoder;
521
522 if (WARN_ON(!IS_VALLEYVIEW(dev)))
523 return;
524
525 /*
526 * We can't grab pps_mutex here due to deadlock with power_domain
527 * mutex when power_domain functions are called while holding pps_mutex.
528 * That also means that in order to use pps_pipe the code needs to
529 * hold both a power domain reference and pps_mutex, and the power domain
530 * reference get/put must be done while _not_ holding pps_mutex.
531 * pps_{lock,unlock}() do these steps in the correct order, so one
532 * should use them always.
533 */
534
535 list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
536 struct intel_dp *intel_dp;
537
538 if (encoder->type != INTEL_OUTPUT_EDP)
539 continue;
540
541 intel_dp = enc_to_intel_dp(&encoder->base);
542 intel_dp->pps_pipe = INVALID_PIPE;
543 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300544}
545
546static u32 _pp_ctrl_reg(struct intel_dp *intel_dp)
547{
548 struct drm_device *dev = intel_dp_to_dev(intel_dp);
549
550 if (HAS_PCH_SPLIT(dev))
551 return PCH_PP_CONTROL;
552 else
553 return VLV_PIPE_PP_CONTROL(vlv_power_sequencer_pipe(intel_dp));
554}
555
556static u32 _pp_stat_reg(struct intel_dp *intel_dp)
557{
558 struct drm_device *dev = intel_dp_to_dev(intel_dp);
559
560 if (HAS_PCH_SPLIT(dev))
561 return PCH_PP_STATUS;
562 else
563 return VLV_PIPE_PP_STATUS(vlv_power_sequencer_pipe(intel_dp));
564}
565
Clint Taylor01527b32014-07-07 13:01:46 -0700566/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
567 This function only applicable when panel PM state is not to be tracked */
568static int edp_notify_handler(struct notifier_block *this, unsigned long code,
569 void *unused)
570{
571 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
572 edp_notifier);
573 struct drm_device *dev = intel_dp_to_dev(intel_dp);
574 struct drm_i915_private *dev_priv = dev->dev_private;
575 u32 pp_div;
576 u32 pp_ctrl_reg, pp_div_reg;
Clint Taylor01527b32014-07-07 13:01:46 -0700577
578 if (!is_edp(intel_dp) || code != SYS_RESTART)
579 return 0;
580
Ville Syrjälä773538e82014-09-04 14:54:56 +0300581 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300582
Clint Taylor01527b32014-07-07 13:01:46 -0700583 if (IS_VALLEYVIEW(dev)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300584 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
585
Clint Taylor01527b32014-07-07 13:01:46 -0700586 pp_ctrl_reg = VLV_PIPE_PP_CONTROL(pipe);
587 pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe);
588 pp_div = I915_READ(pp_div_reg);
589 pp_div &= PP_REFERENCE_DIVIDER_MASK;
590
591 /* 0x1F write to PP_DIV_REG sets max cycle delay */
592 I915_WRITE(pp_div_reg, pp_div | 0x1F);
593 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
594 msleep(intel_dp->panel_power_cycle_delay);
595 }
596
Ville Syrjälä773538e82014-09-04 14:54:56 +0300597 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300598
Clint Taylor01527b32014-07-07 13:01:46 -0700599 return 0;
600}
601
Daniel Vetter4be73782014-01-17 14:39:48 +0100602static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700603{
Paulo Zanoni30add222012-10-26 19:05:45 -0200604 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packardebf33b12011-09-29 15:53:27 -0700605 struct drm_i915_private *dev_priv = dev->dev_private;
606
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300607 lockdep_assert_held(&dev_priv->pps_mutex);
608
Ville Syrjälä9a423562014-10-16 21:29:48 +0300609 if (IS_VALLEYVIEW(dev) &&
610 intel_dp->pps_pipe == INVALID_PIPE)
611 return false;
612
Jani Nikulabf13e812013-09-06 07:40:05 +0300613 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700614}
615
Daniel Vetter4be73782014-01-17 14:39:48 +0100616static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700617{
Paulo Zanoni30add222012-10-26 19:05:45 -0200618 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packardebf33b12011-09-29 15:53:27 -0700619 struct drm_i915_private *dev_priv = dev->dev_private;
620
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300621 lockdep_assert_held(&dev_priv->pps_mutex);
622
Ville Syrjälä9a423562014-10-16 21:29:48 +0300623 if (IS_VALLEYVIEW(dev) &&
624 intel_dp->pps_pipe == INVALID_PIPE)
625 return false;
626
Ville Syrjälä773538e82014-09-04 14:54:56 +0300627 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700628}
629
Keith Packard9b984da2011-09-19 13:54:47 -0700630static void
631intel_dp_check_edp(struct intel_dp *intel_dp)
632{
Paulo Zanoni30add222012-10-26 19:05:45 -0200633 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packard9b984da2011-09-19 13:54:47 -0700634 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packardebf33b12011-09-29 15:53:27 -0700635
Keith Packard9b984da2011-09-19 13:54:47 -0700636 if (!is_edp(intel_dp))
637 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700638
Daniel Vetter4be73782014-01-17 14:39:48 +0100639 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700640 WARN(1, "eDP powered off while attempting aux channel communication.\n");
641 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300642 I915_READ(_pp_stat_reg(intel_dp)),
643 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700644 }
645}
646
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100647static uint32_t
648intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
649{
650 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
651 struct drm_device *dev = intel_dig_port->base.base.dev;
652 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni9ed35ab2013-02-18 19:00:25 -0300653 uint32_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100654 uint32_t status;
655 bool done;
656
Daniel Vetteref04f002012-12-01 21:03:59 +0100657#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100658 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300659 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300660 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100661 else
662 done = wait_for_atomic(C, 10) == 0;
663 if (!done)
664 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
665 has_aux_irq);
666#undef C
667
668 return status;
669}
670
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000671static uint32_t i9xx_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
672{
673 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
674 struct drm_device *dev = intel_dig_port->base.base.dev;
675
676 /*
677 * The clock divider is based off the hrawclk, and would like to run at
678 * 2MHz. So, take the hrawclk value and divide by 2 and use that
679 */
680 return index ? 0 : intel_hrawclk(dev) / 2;
681}
682
683static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
684{
685 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
686 struct drm_device *dev = intel_dig_port->base.base.dev;
687
688 if (index)
689 return 0;
690
691 if (intel_dig_port->port == PORT_A) {
692 if (IS_GEN6(dev) || IS_GEN7(dev))
693 return 200; /* SNB & IVB eDP input clock at 400Mhz */
694 else
695 return 225; /* eDP input clock at 450Mhz */
696 } else {
697 return DIV_ROUND_UP(intel_pch_rawclk(dev), 2);
698 }
699}
700
701static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300702{
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
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000707 if (intel_dig_port->port == PORT_A) {
Chris Wilsonbc866252013-07-21 16:00:03 +0100708 if (index)
709 return 0;
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000710 return DIV_ROUND_CLOSEST(intel_ddi_get_cdclk_freq(dev_priv), 2000);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300711 } else if (dev_priv->pch_id == INTEL_PCH_LPT_DEVICE_ID_TYPE) {
712 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100713 switch (index) {
714 case 0: return 63;
715 case 1: return 72;
716 default: return 0;
717 }
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000718 } else {
Chris Wilsonbc866252013-07-21 16:00:03 +0100719 return index ? 0 : DIV_ROUND_UP(intel_pch_rawclk(dev), 2);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300720 }
721}
722
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000723static uint32_t vlv_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
724{
725 return index ? 0 : 100;
726}
727
Damien Lespiaub6b5e382014-01-20 16:00:59 +0000728static 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
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000738static 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
752 if (IS_BROADWELL(dev) && intel_dp->aux_ch_ctl_reg == DPA_AUX_CH_CTL)
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 |
Damien Lespiau788d4432014-01-20 15:52:31 +0000758 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000759 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000760 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000761 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +0000762 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000763 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
764 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000765 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000766}
767
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000768static 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
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700783static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100784intel_dp_aux_ch(struct intel_dp *intel_dp,
Daniel Vetterbd9f74a2014-10-02 09:45:35 +0200785 const uint8_t *send, int send_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700786 uint8_t *recv, int recv_size)
787{
Paulo Zanoni174edf12012-10-26 19:05:50 -0200788 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
789 struct drm_device *dev = intel_dig_port->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700790 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni9ed35ab2013-02-18 19:00:25 -0300791 uint32_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700792 uint32_t ch_data = ch_ctl + 4;
Chris Wilsonbc866252013-07-21 16:00:03 +0100793 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100794 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700795 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000796 int try, clock = 0;
Daniel Vetter4e6b7882014-02-07 16:33:20 +0100797 bool has_aux_irq = HAS_AUX_IRQ(dev);
Jani Nikula884f19e2014-03-14 16:51:14 +0200798 bool vdd;
799
Ville Syrjälä773538e82014-09-04 14:54:56 +0300800 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300801
Ville Syrjälä72c35002014-08-18 22:16:00 +0300802 /*
803 * We will be called with VDD already enabled for dpcd/edid/oui reads.
804 * In such cases we want to leave VDD enabled and it's up to upper layers
805 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
806 * ourselves.
807 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +0300808 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100809
810 /* dp aux is extremely sensitive to irq latency, hence request the
811 * lowest possible wakeup latency and so prevent the cpu from going into
812 * deep sleep states.
813 */
814 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700815
Keith Packard9b984da2011-09-19 13:54:47 -0700816 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +0800817
Paulo Zanonic67a4702013-08-19 13:18:09 -0300818 intel_aux_display_runtime_get(dev_priv);
819
Jesse Barnes11bee432011-08-01 15:02:20 -0700820 /* Try to wait for any previous AUX channel activity */
821 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +0100822 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -0700823 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
824 break;
825 msleep(1);
826 }
827
828 if (try == 3) {
829 WARN(1, "dp_aux_ch not started status 0x%08x\n",
830 I915_READ(ch_ctl));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100831 ret = -EBUSY;
832 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100833 }
834
Paulo Zanoni46a5ae92013-09-17 11:14:10 -0300835 /* Only 5 data registers! */
836 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
837 ret = -E2BIG;
838 goto out;
839 }
840
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000841 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +0000842 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
843 has_aux_irq,
844 send_bytes,
845 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000846
Chris Wilsonbc866252013-07-21 16:00:03 +0100847 /* Must try at least 3 times according to DP spec */
848 for (try = 0; try < 5; try++) {
849 /* Load the send data into the aux channel data registers */
850 for (i = 0; i < send_bytes; i += 4)
851 I915_WRITE(ch_data + i,
852 pack_aux(send + i, send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -0400853
Chris Wilsonbc866252013-07-21 16:00:03 +0100854 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000855 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100856
Chris Wilsonbc866252013-07-21 16:00:03 +0100857 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -0400858
Chris Wilsonbc866252013-07-21 16:00:03 +0100859 /* Clear done status and any errors */
860 I915_WRITE(ch_ctl,
861 status |
862 DP_AUX_CH_CTL_DONE |
863 DP_AUX_CH_CTL_TIME_OUT_ERROR |
864 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -0400865
Chris Wilsonbc866252013-07-21 16:00:03 +0100866 if (status & (DP_AUX_CH_CTL_TIME_OUT_ERROR |
867 DP_AUX_CH_CTL_RECEIVE_ERROR))
868 continue;
869 if (status & DP_AUX_CH_CTL_DONE)
870 break;
871 }
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100872 if (status & DP_AUX_CH_CTL_DONE)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700873 break;
874 }
875
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700876 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700877 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100878 ret = -EBUSY;
879 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700880 }
881
882 /* Check for timeout or receive error.
883 * Timeouts occur when the sink is not connected
884 */
Keith Packarda5b3da52009-06-11 22:30:32 -0700885 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700886 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100887 ret = -EIO;
888 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -0700889 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700890
891 /* Timeouts occur when the device isn't connected, so they're
892 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -0700893 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Zhao Yakui28c97732009-10-09 11:39:41 +0800894 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100895 ret = -ETIMEDOUT;
896 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700897 }
898
899 /* Unload any bytes sent back from the other side */
900 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
901 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700902 if (recv_bytes > recv_size)
903 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -0400904
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100905 for (i = 0; i < recv_bytes; i += 4)
906 unpack_aux(I915_READ(ch_data + i),
907 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700908
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100909 ret = recv_bytes;
910out:
911 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
Paulo Zanonic67a4702013-08-19 13:18:09 -0300912 intel_aux_display_runtime_put(dev_priv);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100913
Jani Nikula884f19e2014-03-14 16:51:14 +0200914 if (vdd)
915 edp_panel_vdd_off(intel_dp, false);
916
Ville Syrjälä773538e82014-09-04 14:54:56 +0300917 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300918
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100919 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700920}
921
Jani Nikulaa6c8aff02014-04-07 12:37:25 +0300922#define BARE_ADDRESS_SIZE 3
923#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +0200924static ssize_t
925intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700926{
Jani Nikula9d1a1032014-03-14 16:51:15 +0200927 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
928 uint8_t txbuf[20], rxbuf[20];
929 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700930 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700931
Jani Nikula9d1a1032014-03-14 16:51:15 +0200932 txbuf[0] = msg->request << 4;
933 txbuf[1] = msg->address >> 8;
934 txbuf[2] = msg->address & 0xff;
935 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -0300936
Jani Nikula9d1a1032014-03-14 16:51:15 +0200937 switch (msg->request & ~DP_AUX_I2C_MOT) {
938 case DP_AUX_NATIVE_WRITE:
939 case DP_AUX_I2C_WRITE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +0300940 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +0200941 rxsize = 1;
Jani Nikulaf51a44b2014-02-11 11:52:05 +0200942
Jani Nikula9d1a1032014-03-14 16:51:15 +0200943 if (WARN_ON(txsize > 20))
944 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700945
Jani Nikula9d1a1032014-03-14 16:51:15 +0200946 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700947
Jani Nikula9d1a1032014-03-14 16:51:15 +0200948 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
949 if (ret > 0) {
950 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700951
Jani Nikula9d1a1032014-03-14 16:51:15 +0200952 /* Return payload size. */
953 ret = msg->size;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700954 }
Jani Nikula9d1a1032014-03-14 16:51:15 +0200955 break;
956
957 case DP_AUX_NATIVE_READ:
958 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +0300959 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +0200960 rxsize = msg->size + 1;
961
962 if (WARN_ON(rxsize > 20))
963 return -E2BIG;
964
965 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
966 if (ret > 0) {
967 msg->reply = rxbuf[0] >> 4;
968 /*
969 * Assume happy day, and copy the data. The caller is
970 * expected to check msg->reply before touching it.
971 *
972 * Return payload size.
973 */
974 ret--;
975 memcpy(msg->buffer, rxbuf + 1, ret);
976 }
977 break;
978
979 default:
980 ret = -EINVAL;
981 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700982 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +0200983
Jani Nikula9d1a1032014-03-14 16:51:15 +0200984 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700985}
986
Jani Nikula9d1a1032014-03-14 16:51:15 +0200987static void
988intel_dp_aux_init(struct intel_dp *intel_dp, struct intel_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700989{
Jani Nikula9d1a1032014-03-14 16:51:15 +0200990 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jani Nikula33ad6622014-03-14 16:51:16 +0200991 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
992 enum port port = intel_dig_port->port;
Jani Nikula0b998362014-03-14 16:51:17 +0200993 const char *name = NULL;
Dave Airlieab2c0672009-12-04 10:55:24 +1000994 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700995
Jani Nikula33ad6622014-03-14 16:51:16 +0200996 switch (port) {
997 case PORT_A:
998 intel_dp->aux_ch_ctl_reg = DPA_AUX_CH_CTL;
Jani Nikula0b998362014-03-14 16:51:17 +0200999 name = "DPDDC-A";
Dave Airlieab2c0672009-12-04 10:55:24 +10001000 break;
Jani Nikula33ad6622014-03-14 16:51:16 +02001001 case PORT_B:
1002 intel_dp->aux_ch_ctl_reg = PCH_DPB_AUX_CH_CTL;
Jani Nikula0b998362014-03-14 16:51:17 +02001003 name = "DPDDC-B";
Jani Nikula33ad6622014-03-14 16:51:16 +02001004 break;
1005 case PORT_C:
1006 intel_dp->aux_ch_ctl_reg = PCH_DPC_AUX_CH_CTL;
Jani Nikula0b998362014-03-14 16:51:17 +02001007 name = "DPDDC-C";
Jani Nikula33ad6622014-03-14 16:51:16 +02001008 break;
1009 case PORT_D:
1010 intel_dp->aux_ch_ctl_reg = PCH_DPD_AUX_CH_CTL;
Jani Nikula0b998362014-03-14 16:51:17 +02001011 name = "DPDDC-D";
Dave Airlieab2c0672009-12-04 10:55:24 +10001012 break;
1013 default:
Jani Nikula33ad6622014-03-14 16:51:16 +02001014 BUG();
Dave Airlieab2c0672009-12-04 10:55:24 +10001015 }
1016
Damien Lespiau1b1aad72013-12-03 13:56:29 +00001017 /*
1018 * The AUX_CTL register is usually DP_CTL + 0x10.
1019 *
1020 * On Haswell and Broadwell though:
1021 * - Both port A DDI_BUF_CTL and DDI_AUX_CTL are on the CPU
1022 * - Port B/C/D AUX channels are on the PCH, DDI_BUF_CTL on the CPU
1023 *
1024 * Skylake moves AUX_CTL back next to DDI_BUF_CTL, on the CPU.
1025 */
1026 if (!IS_HASWELL(dev) && !IS_BROADWELL(dev))
Jani Nikula33ad6622014-03-14 16:51:16 +02001027 intel_dp->aux_ch_ctl_reg = intel_dp->output_reg + 0x10;
David Flynn8316f332010-12-08 16:10:21 +00001028
Jani Nikula0b998362014-03-14 16:51:17 +02001029 intel_dp->aux.name = name;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001030 intel_dp->aux.dev = dev->dev;
1031 intel_dp->aux.transfer = intel_dp_aux_transfer;
David Flynn8316f332010-12-08 16:10:21 +00001032
Jani Nikula0b998362014-03-14 16:51:17 +02001033 DRM_DEBUG_KMS("registering %s bus for %s\n", name,
1034 connector->base.kdev->kobj.name);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001035
Dave Airlie4f71d0c2014-06-04 16:02:28 +10001036 ret = drm_dp_aux_register(&intel_dp->aux);
Jani Nikula0b998362014-03-14 16:51:17 +02001037 if (ret < 0) {
Dave Airlie4f71d0c2014-06-04 16:02:28 +10001038 DRM_ERROR("drm_dp_aux_register() for %s failed (%d)\n",
Jani Nikula0b998362014-03-14 16:51:17 +02001039 name, ret);
1040 return;
Dave Airlieab2c0672009-12-04 10:55:24 +10001041 }
David Flynn8316f332010-12-08 16:10:21 +00001042
Jani Nikula0b998362014-03-14 16:51:17 +02001043 ret = sysfs_create_link(&connector->base.kdev->kobj,
1044 &intel_dp->aux.ddc.dev.kobj,
1045 intel_dp->aux.ddc.dev.kobj.name);
1046 if (ret < 0) {
1047 DRM_ERROR("sysfs_create_link() for %s failed (%d)\n", name, ret);
Dave Airlie4f71d0c2014-06-04 16:02:28 +10001048 drm_dp_aux_unregister(&intel_dp->aux);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001049 }
1050}
1051
Imre Deak80f65de2014-02-11 17:12:49 +02001052static void
1053intel_dp_connector_unregister(struct intel_connector *intel_connector)
1054{
1055 struct intel_dp *intel_dp = intel_attached_dp(&intel_connector->base);
1056
Dave Airlie0e32b392014-05-02 14:02:48 +10001057 if (!intel_connector->mst_port)
1058 sysfs_remove_link(&intel_connector->base.kdev->kobj,
1059 intel_dp->aux.ddc.dev.kobj.name);
Imre Deak80f65de2014-02-11 17:12:49 +02001060 intel_connector_unregister(intel_connector);
1061}
1062
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001063static void
Daniel Vetter0e503382014-07-04 11:26:04 -03001064hsw_dp_set_ddi_pll_sel(struct intel_crtc_config *pipe_config, int link_bw)
1065{
1066 switch (link_bw) {
1067 case DP_LINK_BW_1_62:
1068 pipe_config->ddi_pll_sel = PORT_CLK_SEL_LCPLL_810;
1069 break;
1070 case DP_LINK_BW_2_7:
1071 pipe_config->ddi_pll_sel = PORT_CLK_SEL_LCPLL_1350;
1072 break;
1073 case DP_LINK_BW_5_4:
1074 pipe_config->ddi_pll_sel = PORT_CLK_SEL_LCPLL_2700;
1075 break;
1076 }
1077}
1078
1079static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001080intel_dp_set_clock(struct intel_encoder *encoder,
1081 struct intel_crtc_config *pipe_config, int link_bw)
1082{
1083 struct drm_device *dev = encoder->base.dev;
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001084 const struct dp_link_dpll *divisor = NULL;
1085 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001086
1087 if (IS_G4X(dev)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001088 divisor = gen4_dpll;
1089 count = ARRAY_SIZE(gen4_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001090 } else if (HAS_PCH_SPLIT(dev)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001091 divisor = pch_dpll;
1092 count = ARRAY_SIZE(pch_dpll);
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001093 } else if (IS_CHERRYVIEW(dev)) {
1094 divisor = chv_dpll;
1095 count = ARRAY_SIZE(chv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001096 } else if (IS_VALLEYVIEW(dev)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001097 divisor = vlv_dpll;
1098 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001099 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001100
1101 if (divisor && count) {
1102 for (i = 0; i < count; i++) {
1103 if (link_bw == divisor[i].link_bw) {
1104 pipe_config->dpll = divisor[i].dpll;
1105 pipe_config->clock_set = true;
1106 break;
1107 }
1108 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001109 }
1110}
1111
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001112bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001113intel_dp_compute_config(struct intel_encoder *encoder,
1114 struct intel_crtc_config *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001115{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001116 struct drm_device *dev = encoder->base.dev;
Daniel Vetter36008362013-03-27 00:44:59 +01001117 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001118 struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001119 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001120 enum port port = dp_to_dig_port(intel_dp)->port;
Jesse Barnes2dd24552013-04-25 12:55:01 -07001121 struct intel_crtc *intel_crtc = encoder->new_crtc;
Jani Nikuladd06f902012-10-19 14:51:50 +03001122 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001123 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001124 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001125 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001126 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001127 int min_clock = 0;
Todd Previte06ea66b2014-01-20 10:19:39 -07001128 int max_clock = intel_dp_max_link_bw(intel_dp) >> 3;
Daniel Vetter083f9562012-04-20 20:23:49 +02001129 int bpp, mode_rate;
Todd Previte06ea66b2014-01-20 10:19:39 -07001130 static int bws[] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7, DP_LINK_BW_5_4 };
Daniel Vetterff9a6752013-06-01 17:16:21 +02001131 int link_avail, link_clock;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001132
Imre Deakbc7d38a2013-05-16 14:40:36 +03001133 if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001134 pipe_config->has_pch_encoder = true;
1135
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001136 pipe_config->has_dp_encoder = true;
Vandana Kannanf769cd22014-08-05 07:51:22 -07001137 pipe_config->has_drrs = false;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02001138 pipe_config->has_audio = intel_dp->has_audio;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001139
Jani Nikuladd06f902012-10-19 14:51:50 +03001140 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1141 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
1142 adjusted_mode);
Jesse Barnes2dd24552013-04-25 12:55:01 -07001143 if (!HAS_PCH_SPLIT(dev))
1144 intel_gmch_panel_fitting(intel_crtc, pipe_config,
1145 intel_connector->panel.fitting_mode);
1146 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001147 intel_pch_panel_fitting(intel_crtc, pipe_config,
1148 intel_connector->panel.fitting_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001149 }
1150
Daniel Vettercb1793c2012-06-04 18:39:21 +02001151 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001152 return false;
1153
Daniel Vetter083f9562012-04-20 20:23:49 +02001154 DRM_DEBUG_KMS("DP link computation with max lane count %i "
1155 "max bw %02x pixel clock %iKHz\n",
Damien Lespiau241bfc32013-09-25 16:45:37 +01001156 max_lane_count, bws[max_clock],
1157 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001158
Daniel Vetter36008362013-03-27 00:44:59 +01001159 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1160 * bpc in between. */
Daniel Vetter3e7ca982013-06-01 19:45:56 +02001161 bpp = pipe_config->pipe_bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001162 if (is_edp(intel_dp)) {
1163 if (dev_priv->vbt.edp_bpp && dev_priv->vbt.edp_bpp < bpp) {
1164 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
1165 dev_priv->vbt.edp_bpp);
1166 bpp = dev_priv->vbt.edp_bpp;
1167 }
1168
Jani Nikula344c5bb2014-09-09 11:25:13 +03001169 /*
1170 * Use the maximum clock and number of lanes the eDP panel
1171 * advertizes being capable of. The panels are generally
1172 * designed to support only a single clock and lane
1173 * configuration, and typically these values correspond to the
1174 * native resolution of the panel.
1175 */
1176 min_lane_count = max_lane_count;
1177 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001178 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001179
Daniel Vetter36008362013-03-27 00:44:59 +01001180 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001181 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1182 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001183
Dave Airliec6930992014-07-14 11:04:39 +10001184 for (clock = min_clock; clock <= max_clock; clock++) {
1185 for (lane_count = min_lane_count; lane_count <= max_lane_count; lane_count <<= 1) {
Daniel Vetter36008362013-03-27 00:44:59 +01001186 link_clock = drm_dp_bw_code_to_link_rate(bws[clock]);
1187 link_avail = intel_dp_max_data_rate(link_clock,
1188 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001189
Daniel Vetter36008362013-03-27 00:44:59 +01001190 if (mode_rate <= link_avail) {
1191 goto found;
1192 }
1193 }
1194 }
1195 }
1196
1197 return false;
1198
1199found:
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001200 if (intel_dp->color_range_auto) {
1201 /*
1202 * See:
1203 * CEA-861-E - 5.1 Default Encoding Parameters
1204 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1205 */
Thierry Reding18316c82012-12-20 15:41:44 +01001206 if (bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1)
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001207 intel_dp->color_range = DP_COLOR_RANGE_16_235;
1208 else
1209 intel_dp->color_range = 0;
1210 }
1211
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001212 if (intel_dp->color_range)
Daniel Vetter50f3b012013-03-27 00:44:56 +01001213 pipe_config->limited_color_range = true;
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001214
Daniel Vetter36008362013-03-27 00:44:59 +01001215 intel_dp->link_bw = bws[clock];
1216 intel_dp->lane_count = lane_count;
Daniel Vetter657445f2013-05-04 10:09:18 +02001217 pipe_config->pipe_bpp = bpp;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001218 pipe_config->port_clock = drm_dp_bw_code_to_link_rate(intel_dp->link_bw);
Daniel Vetterc4867932012-04-10 10:42:36 +02001219
Daniel Vetter36008362013-03-27 00:44:59 +01001220 DRM_DEBUG_KMS("DP link bw %02x lane count %d clock %d bpp %d\n",
1221 intel_dp->link_bw, intel_dp->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001222 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001223 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1224 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001225
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001226 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001227 adjusted_mode->crtc_clock,
1228 pipe_config->port_clock,
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001229 &pipe_config->dp_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001230
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301231 if (intel_connector->panel.downclock_mode != NULL &&
1232 intel_dp->drrs_state.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001233 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301234 intel_link_compute_m_n(bpp, lane_count,
1235 intel_connector->panel.downclock_mode->clock,
1236 pipe_config->port_clock,
1237 &pipe_config->dp_m2_n2);
1238 }
1239
Damien Lespiauea155f32014-07-29 18:06:20 +01001240 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Daniel Vetter0e503382014-07-04 11:26:04 -03001241 hsw_dp_set_ddi_pll_sel(pipe_config, intel_dp->link_bw);
1242 else
1243 intel_dp_set_clock(encoder, pipe_config, intel_dp->link_bw);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001244
Daniel Vetter36008362013-03-27 00:44:59 +01001245 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001246}
1247
Daniel Vetter7c62a162013-06-01 17:16:20 +02001248static void ironlake_set_pll_cpu_edp(struct intel_dp *intel_dp)
Daniel Vetterea9b6002012-11-29 15:59:31 +01001249{
Daniel Vetter7c62a162013-06-01 17:16:20 +02001250 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1251 struct intel_crtc *crtc = to_intel_crtc(dig_port->base.base.crtc);
1252 struct drm_device *dev = crtc->base.dev;
Daniel Vetterea9b6002012-11-29 15:59:31 +01001253 struct drm_i915_private *dev_priv = dev->dev_private;
1254 u32 dpa_ctl;
1255
Daniel Vetterff9a6752013-06-01 17:16:21 +02001256 DRM_DEBUG_KMS("eDP PLL enable for clock %d\n", crtc->config.port_clock);
Daniel Vetterea9b6002012-11-29 15:59:31 +01001257 dpa_ctl = I915_READ(DP_A);
1258 dpa_ctl &= ~DP_PLL_FREQ_MASK;
1259
Daniel Vetterff9a6752013-06-01 17:16:21 +02001260 if (crtc->config.port_clock == 162000) {
Daniel Vetter1ce17032012-11-29 15:59:32 +01001261 /* For a long time we've carried around a ILK-DevA w/a for the
1262 * 160MHz clock. If we're really unlucky, it's still required.
1263 */
1264 DRM_DEBUG_KMS("160MHz cpu eDP clock, might need ilk devA w/a\n");
Daniel Vetterea9b6002012-11-29 15:59:31 +01001265 dpa_ctl |= DP_PLL_FREQ_160MHZ;
Daniel Vetter7c62a162013-06-01 17:16:20 +02001266 intel_dp->DP |= DP_PLL_FREQ_160MHZ;
Daniel Vetterea9b6002012-11-29 15:59:31 +01001267 } else {
1268 dpa_ctl |= DP_PLL_FREQ_270MHZ;
Daniel Vetter7c62a162013-06-01 17:16:20 +02001269 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
Daniel Vetterea9b6002012-11-29 15:59:31 +01001270 }
Daniel Vetter1ce17032012-11-29 15:59:32 +01001271
Daniel Vetterea9b6002012-11-29 15:59:31 +01001272 I915_WRITE(DP_A, dpa_ctl);
1273
1274 POSTING_READ(DP_A);
1275 udelay(500);
1276}
1277
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02001278static void intel_dp_prepare(struct intel_encoder *encoder)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001279{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001280 struct drm_device *dev = encoder->base.dev;
Keith Packard417e8222011-11-01 19:54:11 -07001281 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001282 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001283 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001284 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
1285 struct drm_display_mode *adjusted_mode = &crtc->config.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001286
Keith Packard417e8222011-11-01 19:54:11 -07001287 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001288 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001289 *
1290 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001291 * SNB CPU
1292 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001293 * CPT PCH
1294 *
1295 * IBX PCH and CPU are the same for almost everything,
1296 * except that the CPU DP PLL is configured in this
1297 * register
1298 *
1299 * CPT PCH is quite different, having many bits moved
1300 * to the TRANS_DP_CTL register instead. That
1301 * configuration happens (oddly) in ironlake_pch_enable
1302 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001303
Keith Packard417e8222011-11-01 19:54:11 -07001304 /* Preserve the BIOS-computed detected bit. This is
1305 * supposed to be read-only.
1306 */
1307 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001308
Keith Packard417e8222011-11-01 19:54:11 -07001309 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001310 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Daniel Vetter17aa6be2013-04-30 14:01:40 +02001311 intel_dp->DP |= DP_PORT_WIDTH(intel_dp->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001312
Daniel Vetter9ed109a2014-04-24 23:54:52 +02001313 if (crtc->config.has_audio) {
Wu Fengguange0dac652011-09-05 14:25:34 +08001314 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Daniel Vetter7c62a162013-06-01 17:16:20 +02001315 pipe_name(crtc->pipe));
Chris Wilsonea5b2132010-08-04 13:50:23 +01001316 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Jani Nikula33d1e7c62014-10-27 16:26:46 +02001317 intel_write_eld(encoder);
Wu Fengguange0dac652011-09-05 14:25:34 +08001318 }
Paulo Zanoni247d89f2012-10-15 15:51:33 -03001319
Keith Packard417e8222011-11-01 19:54:11 -07001320 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001321
Imre Deakbc7d38a2013-05-16 14:40:36 +03001322 if (port == PORT_A && IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001323 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1324 intel_dp->DP |= DP_SYNC_HS_HIGH;
1325 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1326 intel_dp->DP |= DP_SYNC_VS_HIGH;
1327 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1328
Jani Nikula6aba5b62013-10-04 15:08:10 +03001329 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001330 intel_dp->DP |= DP_ENHANCED_FRAMING;
1331
Daniel Vetter7c62a162013-06-01 17:16:20 +02001332 intel_dp->DP |= crtc->pipe << 29;
Imre Deakbc7d38a2013-05-16 14:40:36 +03001333 } else if (!HAS_PCH_CPT(dev) || port == PORT_A) {
Jesse Barnesb2634012013-03-28 09:55:40 -07001334 if (!HAS_PCH_SPLIT(dev) && !IS_VALLEYVIEW(dev))
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001335 intel_dp->DP |= intel_dp->color_range;
Keith Packard417e8222011-11-01 19:54:11 -07001336
1337 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1338 intel_dp->DP |= DP_SYNC_HS_HIGH;
1339 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1340 intel_dp->DP |= DP_SYNC_VS_HIGH;
1341 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1342
Jani Nikula6aba5b62013-10-04 15:08:10 +03001343 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001344 intel_dp->DP |= DP_ENHANCED_FRAMING;
1345
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001346 if (!IS_CHERRYVIEW(dev)) {
1347 if (crtc->pipe == 1)
1348 intel_dp->DP |= DP_PIPEB_SELECT;
1349 } else {
1350 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
1351 }
Keith Packard417e8222011-11-01 19:54:11 -07001352 } else {
1353 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001354 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001355}
1356
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001357#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1358#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001359
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001360#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1361#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001362
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001363#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1364#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001365
Daniel Vetter4be73782014-01-17 14:39:48 +01001366static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001367 u32 mask,
1368 u32 value)
1369{
Paulo Zanoni30add222012-10-26 19:05:45 -02001370 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001371 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes453c5422013-03-28 09:55:41 -07001372 u32 pp_stat_reg, pp_ctrl_reg;
1373
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001374 lockdep_assert_held(&dev_priv->pps_mutex);
1375
Jani Nikulabf13e812013-09-06 07:40:05 +03001376 pp_stat_reg = _pp_stat_reg(intel_dp);
1377 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001378
1379 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001380 mask, value,
1381 I915_READ(pp_stat_reg),
1382 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001383
Jesse Barnes453c5422013-03-28 09:55:41 -07001384 if (_wait_for((I915_READ(pp_stat_reg) & mask) == value, 5000, 10)) {
Keith Packard99ea7122011-11-01 19:57:50 -07001385 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001386 I915_READ(pp_stat_reg),
1387 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001388 }
Chris Wilson54c136d2013-12-02 09:57:16 +00001389
1390 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001391}
1392
Daniel Vetter4be73782014-01-17 14:39:48 +01001393static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001394{
1395 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001396 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001397}
1398
Daniel Vetter4be73782014-01-17 14:39:48 +01001399static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001400{
Keith Packardbd943152011-09-18 23:09:52 -07001401 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001402 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001403}
Keith Packardbd943152011-09-18 23:09:52 -07001404
Daniel Vetter4be73782014-01-17 14:39:48 +01001405static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001406{
1407 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001408
1409 /* When we disable the VDD override bit last we have to do the manual
1410 * wait. */
1411 wait_remaining_ms_from_jiffies(intel_dp->last_power_cycle,
1412 intel_dp->panel_power_cycle_delay);
1413
Daniel Vetter4be73782014-01-17 14:39:48 +01001414 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001415}
Keith Packardbd943152011-09-18 23:09:52 -07001416
Daniel Vetter4be73782014-01-17 14:39:48 +01001417static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001418{
1419 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1420 intel_dp->backlight_on_delay);
1421}
1422
Daniel Vetter4be73782014-01-17 14:39:48 +01001423static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001424{
1425 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
1426 intel_dp->backlight_off_delay);
1427}
Keith Packard99ea7122011-11-01 19:57:50 -07001428
Keith Packard832dd3c2011-11-01 19:34:06 -07001429/* Read the current pp_control value, unlocking the register if it
1430 * is locked
1431 */
1432
Jesse Barnes453c5422013-03-28 09:55:41 -07001433static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07001434{
Jesse Barnes453c5422013-03-28 09:55:41 -07001435 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1436 struct drm_i915_private *dev_priv = dev->dev_private;
1437 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07001438
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001439 lockdep_assert_held(&dev_priv->pps_mutex);
1440
Jani Nikulabf13e812013-09-06 07:40:05 +03001441 control = I915_READ(_pp_ctrl_reg(intel_dp));
Keith Packard832dd3c2011-11-01 19:34:06 -07001442 control &= ~PANEL_UNLOCK_MASK;
1443 control |= PANEL_UNLOCK_REGS;
1444 return control;
Keith Packardbd943152011-09-18 23:09:52 -07001445}
1446
Ville Syrjälä951468f2014-09-04 14:55:31 +03001447/*
1448 * Must be paired with edp_panel_vdd_off().
1449 * Must hold pps_mutex around the whole on/off sequence.
1450 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
1451 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001452static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001453{
Paulo Zanoni30add222012-10-26 19:05:45 -02001454 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001455 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1456 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Jesse Barnes5d613502011-01-24 17:10:54 -08001457 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deak4e6e1a52014-03-27 17:45:11 +02001458 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08001459 u32 pp;
Jesse Barnes453c5422013-03-28 09:55:41 -07001460 u32 pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001461 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08001462
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001463 lockdep_assert_held(&dev_priv->pps_mutex);
1464
Keith Packard97af61f572011-09-28 16:23:51 -07001465 if (!is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001466 return false;
Keith Packardbd943152011-09-18 23:09:52 -07001467
1468 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07001469
Daniel Vetter4be73782014-01-17 14:39:48 +01001470 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001471 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02001472
Imre Deak4e6e1a52014-03-27 17:45:11 +02001473 power_domain = intel_display_port_power_domain(intel_encoder);
1474 intel_display_power_get(dev_priv, power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02001475
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001476 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
1477 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07001478
Daniel Vetter4be73782014-01-17 14:39:48 +01001479 if (!edp_have_panel_power(intel_dp))
1480 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001481
Jesse Barnes453c5422013-03-28 09:55:41 -07001482 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001483 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07001484
Jani Nikulabf13e812013-09-06 07:40:05 +03001485 pp_stat_reg = _pp_stat_reg(intel_dp);
1486 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001487
1488 I915_WRITE(pp_ctrl_reg, pp);
1489 POSTING_READ(pp_ctrl_reg);
1490 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1491 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07001492 /*
1493 * If the panel wasn't on, delay before accessing aux channel
1494 */
Daniel Vetter4be73782014-01-17 14:39:48 +01001495 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001496 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
1497 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07001498 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07001499 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001500
1501 return need_to_disable;
1502}
1503
Ville Syrjälä951468f2014-09-04 14:55:31 +03001504/*
1505 * Must be paired with intel_edp_panel_vdd_off() or
1506 * intel_edp_panel_off().
1507 * Nested calls to these functions are not allowed since
1508 * we drop the lock. Caller must use some higher level
1509 * locking to prevent nested calls from other threads.
1510 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01001511void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001512{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001513 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001514
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001515 if (!is_edp(intel_dp))
1516 return;
1517
Ville Syrjälä773538e82014-09-04 14:54:56 +03001518 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001519 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03001520 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001521
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001522 WARN(!vdd, "eDP port %c VDD already requested on\n",
1523 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08001524}
1525
Daniel Vetter4be73782014-01-17 14:39:48 +01001526static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001527{
Paulo Zanoni30add222012-10-26 19:05:45 -02001528 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001529 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03001530 struct intel_digital_port *intel_dig_port =
1531 dp_to_dig_port(intel_dp);
1532 struct intel_encoder *intel_encoder = &intel_dig_port->base;
1533 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08001534 u32 pp;
Jesse Barnes453c5422013-03-28 09:55:41 -07001535 u32 pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08001536
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001537 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01001538
Ville Syrjälä15e899a2014-08-18 22:16:02 +03001539 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001540
Ville Syrjälä15e899a2014-08-18 22:16:02 +03001541 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03001542 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02001543
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001544 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
1545 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07001546
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03001547 pp = ironlake_get_pp_control(intel_dp);
1548 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07001549
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03001550 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
1551 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001552
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03001553 I915_WRITE(pp_ctrl_reg, pp);
1554 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02001555
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03001556 /* Make sure sequencer is idle before allowing subsequent activity */
1557 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1558 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02001559
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03001560 if ((pp & POWER_TARGET_ON) == 0)
1561 intel_dp->last_power_cycle = jiffies;
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02001562
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03001563 power_domain = intel_display_port_power_domain(intel_encoder);
1564 intel_display_power_put(dev_priv, power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07001565}
1566
Daniel Vetter4be73782014-01-17 14:39:48 +01001567static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07001568{
1569 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
1570 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07001571
Ville Syrjälä773538e82014-09-04 14:54:56 +03001572 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03001573 if (!intel_dp->want_panel_vdd)
1574 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03001575 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07001576}
1577
Imre Deakaba86892014-07-30 15:57:31 +03001578static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
1579{
1580 unsigned long delay;
1581
1582 /*
1583 * Queue the timer to fire a long time from now (relative to the power
1584 * down delay) to keep the panel power up across a sequence of
1585 * operations.
1586 */
1587 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
1588 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
1589}
1590
Ville Syrjälä951468f2014-09-04 14:55:31 +03001591/*
1592 * Must be paired with edp_panel_vdd_on().
1593 * Must hold pps_mutex around the whole on/off sequence.
1594 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
1595 */
Daniel Vetter4be73782014-01-17 14:39:48 +01001596static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07001597{
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001598 struct drm_i915_private *dev_priv =
1599 intel_dp_to_dev(intel_dp)->dev_private;
1600
1601 lockdep_assert_held(&dev_priv->pps_mutex);
1602
Keith Packard97af61f572011-09-28 16:23:51 -07001603 if (!is_edp(intel_dp))
1604 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08001605
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001606 WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
1607 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07001608
Keith Packardbd943152011-09-18 23:09:52 -07001609 intel_dp->want_panel_vdd = false;
1610
Imre Deakaba86892014-07-30 15:57:31 +03001611 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01001612 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03001613 else
1614 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001615}
1616
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03001617static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07001618{
Paulo Zanoni30add222012-10-26 19:05:45 -02001619 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07001620 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packard99ea7122011-11-01 19:57:50 -07001621 u32 pp;
Jesse Barnes453c5422013-03-28 09:55:41 -07001622 u32 pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07001623
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03001624 lockdep_assert_held(&dev_priv->pps_mutex);
1625
Keith Packard97af61f572011-09-28 16:23:51 -07001626 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07001627 return;
Keith Packard99ea7122011-11-01 19:57:50 -07001628
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001629 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
1630 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07001631
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03001632 if (WARN(edp_have_panel_power(intel_dp),
1633 "eDP port %c panel power already on\n",
1634 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03001635 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07001636
Daniel Vetter4be73782014-01-17 14:39:48 +01001637 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001638
Jani Nikulabf13e812013-09-06 07:40:05 +03001639 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001640 pp = ironlake_get_pp_control(intel_dp);
Keith Packard05ce1a42011-09-29 16:33:01 -07001641 if (IS_GEN5(dev)) {
1642 /* ILK workaround: disable reset around power sequence */
1643 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03001644 I915_WRITE(pp_ctrl_reg, pp);
1645 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07001646 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001647
Keith Packard1c0ae802011-09-19 13:59:29 -07001648 pp |= POWER_TARGET_ON;
Keith Packard99ea7122011-11-01 19:57:50 -07001649 if (!IS_GEN5(dev))
1650 pp |= PANEL_POWER_RESET;
1651
Jesse Barnes453c5422013-03-28 09:55:41 -07001652 I915_WRITE(pp_ctrl_reg, pp);
1653 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07001654
Daniel Vetter4be73782014-01-17 14:39:48 +01001655 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001656 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07001657
Keith Packard05ce1a42011-09-29 16:33:01 -07001658 if (IS_GEN5(dev)) {
1659 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03001660 I915_WRITE(pp_ctrl_reg, pp);
1661 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07001662 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03001663}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001664
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03001665void intel_edp_panel_on(struct intel_dp *intel_dp)
1666{
1667 if (!is_edp(intel_dp))
1668 return;
1669
1670 pps_lock(intel_dp);
1671 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03001672 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07001673}
1674
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03001675
1676static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07001677{
Imre Deak4e6e1a52014-03-27 17:45:11 +02001678 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1679 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanoni30add222012-10-26 19:05:45 -02001680 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07001681 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deak4e6e1a52014-03-27 17:45:11 +02001682 enum intel_display_power_domain power_domain;
Keith Packard99ea7122011-11-01 19:57:50 -07001683 u32 pp;
Jesse Barnes453c5422013-03-28 09:55:41 -07001684 u32 pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07001685
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03001686 lockdep_assert_held(&dev_priv->pps_mutex);
1687
Keith Packard97af61f572011-09-28 16:23:51 -07001688 if (!is_edp(intel_dp))
1689 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001690
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001691 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
1692 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001693
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001694 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
1695 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02001696
Jesse Barnes453c5422013-03-28 09:55:41 -07001697 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02001698 /* We need to switch off panel power _and_ force vdd, for otherwise some
1699 * panels get very unhappy and cease to work. */
Patrik Jakobssonb3064152014-03-04 00:42:44 +01001700 pp &= ~(POWER_TARGET_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
1701 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07001702
Jani Nikulabf13e812013-09-06 07:40:05 +03001703 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001704
Paulo Zanoni849e39f2014-03-07 20:05:20 -03001705 intel_dp->want_panel_vdd = false;
1706
Jesse Barnes453c5422013-03-28 09:55:41 -07001707 I915_WRITE(pp_ctrl_reg, pp);
1708 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07001709
Paulo Zanonidce56b32013-12-19 14:29:40 -02001710 intel_dp->last_power_cycle = jiffies;
Daniel Vetter4be73782014-01-17 14:39:48 +01001711 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03001712
1713 /* We got a reference when we enabled the VDD. */
Imre Deak4e6e1a52014-03-27 17:45:11 +02001714 power_domain = intel_display_port_power_domain(intel_encoder);
1715 intel_display_power_put(dev_priv, power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03001716}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001717
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03001718void intel_edp_panel_off(struct intel_dp *intel_dp)
1719{
1720 if (!is_edp(intel_dp))
1721 return;
1722
1723 pps_lock(intel_dp);
1724 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03001725 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07001726}
1727
Jani Nikula1250d102014-08-12 17:11:39 +03001728/* Enable backlight in the panel power control. */
1729static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001730{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001731 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1732 struct drm_device *dev = intel_dig_port->base.base.dev;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001733 struct drm_i915_private *dev_priv = dev->dev_private;
1734 u32 pp;
Jesse Barnes453c5422013-03-28 09:55:41 -07001735 u32 pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001736
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001737 /*
1738 * If we enable the backlight right away following a panel power
1739 * on, we may see slight flicker as the panel syncs with the eDP
1740 * link. So delay a bit to make sure the image is solid before
1741 * allowing it to appear.
1742 */
Daniel Vetter4be73782014-01-17 14:39:48 +01001743 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001744
Ville Syrjälä773538e82014-09-04 14:54:56 +03001745 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001746
Jesse Barnes453c5422013-03-28 09:55:41 -07001747 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001748 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07001749
Jani Nikulabf13e812013-09-06 07:40:05 +03001750 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001751
1752 I915_WRITE(pp_ctrl_reg, pp);
1753 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001754
Ville Syrjälä773538e82014-09-04 14:54:56 +03001755 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001756}
1757
Jani Nikula1250d102014-08-12 17:11:39 +03001758/* Enable backlight PWM and backlight PP control. */
1759void intel_edp_backlight_on(struct intel_dp *intel_dp)
1760{
1761 if (!is_edp(intel_dp))
1762 return;
1763
1764 DRM_DEBUG_KMS("\n");
1765
1766 intel_panel_enable_backlight(intel_dp->attached_connector);
1767 _intel_edp_backlight_on(intel_dp);
1768}
1769
1770/* Disable backlight in the panel power control. */
1771static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001772{
Paulo Zanoni30add222012-10-26 19:05:45 -02001773 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001774 struct drm_i915_private *dev_priv = dev->dev_private;
1775 u32 pp;
Jesse Barnes453c5422013-03-28 09:55:41 -07001776 u32 pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001777
Keith Packardf01eca22011-09-28 16:48:10 -07001778 if (!is_edp(intel_dp))
1779 return;
1780
Ville Syrjälä773538e82014-09-04 14:54:56 +03001781 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001782
Jesse Barnes453c5422013-03-28 09:55:41 -07001783 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001784 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07001785
Jani Nikulabf13e812013-09-06 07:40:05 +03001786 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001787
1788 I915_WRITE(pp_ctrl_reg, pp);
1789 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07001790
Ville Syrjälä773538e82014-09-04 14:54:56 +03001791 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001792
Paulo Zanonidce56b32013-12-19 14:29:40 -02001793 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07001794 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03001795}
Jesse Barnesf7d23232014-03-31 11:13:56 -07001796
Jani Nikula1250d102014-08-12 17:11:39 +03001797/* Disable backlight PP control and backlight PWM. */
1798void intel_edp_backlight_off(struct intel_dp *intel_dp)
1799{
1800 if (!is_edp(intel_dp))
1801 return;
1802
1803 DRM_DEBUG_KMS("\n");
1804
1805 _intel_edp_backlight_off(intel_dp);
Jesse Barnesf7d23232014-03-31 11:13:56 -07001806 intel_panel_disable_backlight(intel_dp->attached_connector);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001807}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001808
Jani Nikula73580fb72014-08-12 17:11:41 +03001809/*
1810 * Hook for controlling the panel power control backlight through the bl_power
1811 * sysfs attribute. Take care to handle multiple calls.
1812 */
1813static void intel_edp_backlight_power(struct intel_connector *connector,
1814 bool enable)
1815{
1816 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001817 bool is_enabled;
1818
Ville Syrjälä773538e82014-09-04 14:54:56 +03001819 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001820 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03001821 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03001822
1823 if (is_enabled == enable)
1824 return;
1825
Jani Nikula23ba9372014-08-27 14:08:43 +03001826 DRM_DEBUG_KMS("panel power control backlight %s\n",
1827 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03001828
1829 if (enable)
1830 _intel_edp_backlight_on(intel_dp);
1831 else
1832 _intel_edp_backlight_off(intel_dp);
1833}
1834
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001835static void ironlake_edp_pll_on(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07001836{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001837 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1838 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
1839 struct drm_device *dev = crtc->dev;
Jesse Barnesd240f202010-08-13 15:43:26 -07001840 struct drm_i915_private *dev_priv = dev->dev_private;
1841 u32 dpa_ctl;
1842
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001843 assert_pipe_disabled(dev_priv,
1844 to_intel_crtc(crtc)->pipe);
1845
Jesse Barnesd240f202010-08-13 15:43:26 -07001846 DRM_DEBUG_KMS("\n");
1847 dpa_ctl = I915_READ(DP_A);
Daniel Vetter07679352012-09-06 22:15:42 +02001848 WARN(dpa_ctl & DP_PLL_ENABLE, "dp pll on, should be off\n");
1849 WARN(dpa_ctl & DP_PORT_EN, "dp port still on, should be off\n");
1850
1851 /* We don't adjust intel_dp->DP while tearing down the link, to
1852 * facilitate link retraining (e.g. after hotplug). Hence clear all
1853 * enable bits here to ensure that we don't enable too much. */
1854 intel_dp->DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
1855 intel_dp->DP |= DP_PLL_ENABLE;
1856 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07001857 POSTING_READ(DP_A);
1858 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07001859}
1860
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001861static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07001862{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001863 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1864 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
1865 struct drm_device *dev = crtc->dev;
Jesse Barnesd240f202010-08-13 15:43:26 -07001866 struct drm_i915_private *dev_priv = dev->dev_private;
1867 u32 dpa_ctl;
1868
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001869 assert_pipe_disabled(dev_priv,
1870 to_intel_crtc(crtc)->pipe);
1871
Jesse Barnesd240f202010-08-13 15:43:26 -07001872 dpa_ctl = I915_READ(DP_A);
Daniel Vetter07679352012-09-06 22:15:42 +02001873 WARN((dpa_ctl & DP_PLL_ENABLE) == 0,
1874 "dp pll off, should be on\n");
1875 WARN(dpa_ctl & DP_PORT_EN, "dp port still on, should be off\n");
1876
1877 /* We can't rely on the value tracked for the DP register in
1878 * intel_dp->DP because link_down must not change that (otherwise link
1879 * re-training will fail. */
Jesse Barnes298b0b32010-10-07 16:01:24 -07001880 dpa_ctl &= ~DP_PLL_ENABLE;
Jesse Barnesd240f202010-08-13 15:43:26 -07001881 I915_WRITE(DP_A, dpa_ctl);
Chris Wilson1af5fa12010-09-08 21:07:28 +01001882 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07001883 udelay(200);
1884}
1885
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001886/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03001887void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001888{
1889 int ret, i;
1890
1891 /* Should have a valid DPCD by this point */
1892 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
1893 return;
1894
1895 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02001896 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
1897 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001898 } else {
1899 /*
1900 * When turning on, we need to retry for 1ms to give the sink
1901 * time to wake up.
1902 */
1903 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02001904 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
1905 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001906 if (ret == 1)
1907 break;
1908 msleep(1);
1909 }
1910 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03001911
1912 if (ret != 1)
1913 DRM_DEBUG_KMS("failed to %s sink power state\n",
1914 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001915}
1916
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001917static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
1918 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07001919{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001920 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001921 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001922 struct drm_device *dev = encoder->base.dev;
1923 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deak6d129be2014-03-05 16:20:54 +02001924 enum intel_display_power_domain power_domain;
1925 u32 tmp;
1926
1927 power_domain = intel_display_port_power_domain(encoder);
Daniel Vetterf458ebb2014-09-30 10:56:39 +02001928 if (!intel_display_power_is_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02001929 return false;
1930
1931 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07001932
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001933 if (!(tmp & DP_PORT_EN))
1934 return false;
1935
Imre Deakbc7d38a2013-05-16 14:40:36 +03001936 if (port == PORT_A && IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001937 *pipe = PORT_TO_PIPE_CPT(tmp);
Ville Syrjälä71485e02014-04-09 13:28:55 +03001938 } else if (IS_CHERRYVIEW(dev)) {
1939 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001940 } else if (!HAS_PCH_CPT(dev) || port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001941 *pipe = PORT_TO_PIPE(tmp);
1942 } else {
1943 u32 trans_sel;
1944 u32 trans_dp;
1945 int i;
1946
1947 switch (intel_dp->output_reg) {
1948 case PCH_DP_B:
1949 trans_sel = TRANS_DP_PORT_SEL_B;
1950 break;
1951 case PCH_DP_C:
1952 trans_sel = TRANS_DP_PORT_SEL_C;
1953 break;
1954 case PCH_DP_D:
1955 trans_sel = TRANS_DP_PORT_SEL_D;
1956 break;
1957 default:
1958 return true;
1959 }
1960
Damien Lespiau055e3932014-08-18 13:49:10 +01001961 for_each_pipe(dev_priv, i) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001962 trans_dp = I915_READ(TRANS_DP_CTL(i));
1963 if ((trans_dp & TRANS_DP_PORT_SEL_MASK) == trans_sel) {
1964 *pipe = i;
1965 return true;
1966 }
1967 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001968
Daniel Vetter4a0833e2012-10-26 10:58:11 +02001969 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
1970 intel_dp->output_reg);
1971 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001972
1973 return true;
1974}
1975
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001976static void intel_dp_get_config(struct intel_encoder *encoder,
1977 struct intel_crtc_config *pipe_config)
1978{
1979 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001980 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08001981 struct drm_device *dev = encoder->base.dev;
1982 struct drm_i915_private *dev_priv = dev->dev_private;
1983 enum port port = dp_to_dig_port(intel_dp)->port;
1984 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjälä18442d02013-09-13 16:00:08 +03001985 int dotclock;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001986
Daniel Vetter9ed109a2014-04-24 23:54:52 +02001987 tmp = I915_READ(intel_dp->output_reg);
1988 if (tmp & DP_AUDIO_OUTPUT_ENABLE)
1989 pipe_config->has_audio = true;
1990
Xiong Zhang63000ef2013-06-28 12:59:06 +08001991 if ((port == PORT_A) || !HAS_PCH_CPT(dev)) {
Xiong Zhang63000ef2013-06-28 12:59:06 +08001992 if (tmp & DP_SYNC_HS_HIGH)
1993 flags |= DRM_MODE_FLAG_PHSYNC;
1994 else
1995 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001996
Xiong Zhang63000ef2013-06-28 12:59:06 +08001997 if (tmp & DP_SYNC_VS_HIGH)
1998 flags |= DRM_MODE_FLAG_PVSYNC;
1999 else
2000 flags |= DRM_MODE_FLAG_NVSYNC;
2001 } else {
2002 tmp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2003 if (tmp & TRANS_DP_HSYNC_ACTIVE_HIGH)
2004 flags |= DRM_MODE_FLAG_PHSYNC;
2005 else
2006 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002007
Xiong Zhang63000ef2013-06-28 12:59:06 +08002008 if (tmp & TRANS_DP_VSYNC_ACTIVE_HIGH)
2009 flags |= DRM_MODE_FLAG_PVSYNC;
2010 else
2011 flags |= DRM_MODE_FLAG_NVSYNC;
2012 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002013
2014 pipe_config->adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002015
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002016 if (!HAS_PCH_SPLIT(dev) && !IS_VALLEYVIEW(dev) &&
2017 tmp & DP_COLOR_RANGE_16_235)
2018 pipe_config->limited_color_range = true;
2019
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002020 pipe_config->has_dp_encoder = true;
2021
2022 intel_dp_get_m_n(crtc, pipe_config);
2023
Ville Syrjälä18442d02013-09-13 16:00:08 +03002024 if (port == PORT_A) {
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002025 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_160MHZ)
2026 pipe_config->port_clock = 162000;
2027 else
2028 pipe_config->port_clock = 270000;
2029 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002030
2031 dotclock = intel_dotclock_calculate(pipe_config->port_clock,
2032 &pipe_config->dp_m_n);
2033
2034 if (HAS_PCH_SPLIT(dev_priv->dev) && port != PORT_A)
2035 ironlake_check_encoder_dotclock(pipe_config, dotclock);
2036
Damien Lespiau241bfc32013-09-25 16:45:37 +01002037 pipe_config->adjusted_mode.crtc_clock = dotclock;
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002038
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002039 if (is_edp(intel_dp) && dev_priv->vbt.edp_bpp &&
2040 pipe_config->pipe_bpp > dev_priv->vbt.edp_bpp) {
2041 /*
2042 * This is a big fat ugly hack.
2043 *
2044 * Some machines in UEFI boot mode provide us a VBT that has 18
2045 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2046 * unknown we fail to light up. Yet the same BIOS boots up with
2047 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2048 * max, not what it tells us to use.
2049 *
2050 * Note: This will still be broken if the eDP panel is not lit
2051 * up by the BIOS, and thus we can't get the mode at module
2052 * load.
2053 */
2054 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
2055 pipe_config->pipe_bpp, dev_priv->vbt.edp_bpp);
2056 dev_priv->vbt.edp_bpp = pipe_config->pipe_bpp;
2057 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002058}
2059
Rodrigo Vivi34eb7572014-06-12 10:16:40 -07002060static bool is_edp_psr(struct intel_dp *intel_dp)
Shobhit Kumar2293bb52013-07-11 18:44:56 -03002061{
Rodrigo Vivi34eb7572014-06-12 10:16:40 -07002062 return intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED;
Shobhit Kumar2293bb52013-07-11 18:44:56 -03002063}
2064
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002065static bool intel_edp_is_psr_enabled(struct drm_device *dev)
2066{
2067 struct drm_i915_private *dev_priv = dev->dev_private;
2068
Ben Widawsky18b59922013-09-20 09:35:30 -07002069 if (!HAS_PSR(dev))
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002070 return false;
2071
Ben Widawsky18b59922013-09-20 09:35:30 -07002072 return I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002073}
2074
2075static void intel_edp_psr_write_vsc(struct intel_dp *intel_dp,
2076 struct edp_vsc_psr *vsc_psr)
2077{
2078 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2079 struct drm_device *dev = dig_port->base.base.dev;
2080 struct drm_i915_private *dev_priv = dev->dev_private;
2081 struct intel_crtc *crtc = to_intel_crtc(dig_port->base.base.crtc);
2082 u32 ctl_reg = HSW_TVIDEO_DIP_CTL(crtc->config.cpu_transcoder);
2083 u32 data_reg = HSW_TVIDEO_DIP_VSC_DATA(crtc->config.cpu_transcoder);
2084 uint32_t *data = (uint32_t *) vsc_psr;
2085 unsigned int i;
2086
2087 /* As per BSPec (Pipe Video Data Island Packet), we need to disable
2088 the video DIP being updated before program video DIP data buffer
2089 registers for DIP being updated. */
2090 I915_WRITE(ctl_reg, 0);
2091 POSTING_READ(ctl_reg);
2092
2093 for (i = 0; i < VIDEO_DIP_VSC_DATA_SIZE; i += 4) {
2094 if (i < sizeof(struct edp_vsc_psr))
2095 I915_WRITE(data_reg + i, *data++);
2096 else
2097 I915_WRITE(data_reg + i, 0);
2098 }
2099
2100 I915_WRITE(ctl_reg, VIDEO_DIP_ENABLE_VSC_HSW);
2101 POSTING_READ(ctl_reg);
2102}
2103
Rodrigo Viviba80f4d2014-09-16 19:19:05 -04002104static void intel_edp_psr_setup_vsc(struct intel_dp *intel_dp)
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002105{
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002106 struct edp_vsc_psr psr_vsc;
2107
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002108 /* Prepare VSC packet as per EDP 1.3 spec, Table 3.10 */
2109 memset(&psr_vsc, 0, sizeof(psr_vsc));
2110 psr_vsc.sdp_header.HB0 = 0;
2111 psr_vsc.sdp_header.HB1 = 0x7;
2112 psr_vsc.sdp_header.HB2 = 0x2;
2113 psr_vsc.sdp_header.HB3 = 0x8;
2114 intel_edp_psr_write_vsc(intel_dp, &psr_vsc);
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002115}
2116
2117static void intel_edp_psr_enable_sink(struct intel_dp *intel_dp)
2118{
Rodrigo Vivi0e0ae652014-06-12 10:16:44 -07002119 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2120 struct drm_device *dev = dig_port->base.base.dev;
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002121 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00002122 uint32_t aux_clock_divider;
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002123 int precharge = 0x3;
Rodrigo Vivi0e0ae652014-06-12 10:16:44 -07002124 bool only_standby = false;
Ville Syrjälä5ca476f2014-10-01 16:56:56 +03002125 static const uint8_t aux_msg[] = {
2126 [0] = DP_AUX_NATIVE_WRITE << 4,
2127 [1] = DP_SET_POWER >> 8,
2128 [2] = DP_SET_POWER & 0xff,
2129 [3] = 1 - 1,
2130 [4] = DP_SET_POWER_D0,
2131 };
2132 int i;
2133
2134 BUILD_BUG_ON(sizeof(aux_msg) > 20);
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002135
Damien Lespiauec5b01d2014-01-21 13:35:39 +00002136 aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, 0);
2137
Rodrigo Vivi0e0ae652014-06-12 10:16:44 -07002138 if (IS_BROADWELL(dev) && dig_port->port != PORT_A)
2139 only_standby = true;
2140
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002141 /* Enable PSR in sink */
Rodrigo Vivi0e0ae652014-06-12 10:16:44 -07002142 if (intel_dp->psr_dpcd[1] & DP_PSR_NO_TRAIN_ON_EXIT || only_standby)
Jani Nikula9d1a1032014-03-14 16:51:15 +02002143 drm_dp_dpcd_writeb(&intel_dp->aux, DP_PSR_EN_CFG,
2144 DP_PSR_ENABLE & ~DP_PSR_MAIN_LINK_ACTIVE);
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002145 else
Jani Nikula9d1a1032014-03-14 16:51:15 +02002146 drm_dp_dpcd_writeb(&intel_dp->aux, DP_PSR_EN_CFG,
2147 DP_PSR_ENABLE | DP_PSR_MAIN_LINK_ACTIVE);
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002148
2149 /* Setup AUX registers */
Ville Syrjälä5ca476f2014-10-01 16:56:56 +03002150 for (i = 0; i < sizeof(aux_msg); i += 4)
2151 I915_WRITE(EDP_PSR_AUX_DATA1(dev) + i,
2152 pack_aux(&aux_msg[i], sizeof(aux_msg) - i));
2153
Ben Widawsky18b59922013-09-20 09:35:30 -07002154 I915_WRITE(EDP_PSR_AUX_CTL(dev),
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002155 DP_AUX_CH_CTL_TIME_OUT_400us |
Ville Syrjälä5ca476f2014-10-01 16:56:56 +03002156 (sizeof(aux_msg) << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002157 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
2158 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT));
2159}
2160
2161static void intel_edp_psr_enable_source(struct intel_dp *intel_dp)
2162{
Rodrigo Vivi0e0ae652014-06-12 10:16:44 -07002163 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2164 struct drm_device *dev = dig_port->base.base.dev;
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002165 struct drm_i915_private *dev_priv = dev->dev_private;
2166 uint32_t max_sleep_time = 0x1f;
2167 uint32_t idle_frames = 1;
2168 uint32_t val = 0x0;
Ben Widawskyed8546a2013-11-04 22:45:05 -08002169 const uint32_t link_entry_time = EDP_PSR_MIN_LINK_ENTRY_TIME_8_LINES;
Rodrigo Vivi0e0ae652014-06-12 10:16:44 -07002170 bool only_standby = false;
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002171
Rodrigo Vivi0e0ae652014-06-12 10:16:44 -07002172 if (IS_BROADWELL(dev) && dig_port->port != PORT_A)
2173 only_standby = true;
2174
2175 if (intel_dp->psr_dpcd[1] & DP_PSR_NO_TRAIN_ON_EXIT || only_standby) {
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002176 val |= EDP_PSR_LINK_STANDBY;
2177 val |= EDP_PSR_TP2_TP3_TIME_0us;
2178 val |= EDP_PSR_TP1_TIME_0us;
2179 val |= EDP_PSR_SKIP_AUX_EXIT;
Rodrigo Vivi82c56252014-06-12 10:16:42 -07002180 val |= IS_BROADWELL(dev) ? BDW_PSR_SINGLE_FRAME : 0;
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002181 } else
2182 val |= EDP_PSR_LINK_DISABLE;
2183
Ben Widawsky18b59922013-09-20 09:35:30 -07002184 I915_WRITE(EDP_PSR_CTL(dev), val |
Ben Widawsky24bd9bf2014-03-04 22:38:10 -08002185 (IS_BROADWELL(dev) ? 0 : link_entry_time) |
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002186 max_sleep_time << EDP_PSR_MAX_SLEEP_TIME_SHIFT |
2187 idle_frames << EDP_PSR_IDLE_FRAME_SHIFT |
2188 EDP_PSR_ENABLE);
2189}
2190
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03002191static bool intel_edp_psr_match_conditions(struct intel_dp *intel_dp)
2192{
2193 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2194 struct drm_device *dev = dig_port->base.base.dev;
2195 struct drm_i915_private *dev_priv = dev->dev_private;
2196 struct drm_crtc *crtc = dig_port->base.base.crtc;
2197 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03002198
Daniel Vetterf0355c42014-07-11 10:30:15 -07002199 lockdep_assert_held(&dev_priv->psr.lock);
Daniel Vetterf0355c42014-07-11 10:30:15 -07002200 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
2201 WARN_ON(!drm_modeset_is_locked(&crtc->mutex));
2202
Rodrigo Vivia031d702013-10-03 16:15:06 -03002203 dev_priv->psr.source_ok = false;
2204
Daniel Vetter9ca15302014-07-11 10:30:16 -07002205 if (IS_HASWELL(dev) && dig_port->port != PORT_A) {
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03002206 DRM_DEBUG_KMS("HSW ties PSR to DDI A (eDP)\n");
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03002207 return false;
2208 }
2209
Jani Nikulad330a952014-01-21 11:24:25 +02002210 if (!i915.enable_psr) {
Rodrigo Vivi105b7c12013-07-11 18:45:02 -03002211 DRM_DEBUG_KMS("PSR disable by flag\n");
Rodrigo Vivi105b7c12013-07-11 18:45:02 -03002212 return false;
2213 }
2214
Rodrigo Vivi4c8c7002014-06-12 10:16:43 -07002215 /* Below limitations aren't valid for Broadwell */
2216 if (IS_BROADWELL(dev))
2217 goto out;
2218
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03002219 if (I915_READ(HSW_STEREO_3D_CTL(intel_crtc->config.cpu_transcoder)) &
2220 S3D_ENABLE) {
2221 DRM_DEBUG_KMS("PSR condition failed: Stereo 3D is Enabled\n");
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03002222 return false;
2223 }
2224
Ville Syrjäläca73b4f2013-09-04 18:25:24 +03002225 if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03002226 DRM_DEBUG_KMS("PSR condition failed: Interlaced is Enabled\n");
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03002227 return false;
2228 }
2229
Rodrigo Vivi4c8c7002014-06-12 10:16:43 -07002230 out:
Rodrigo Vivia031d702013-10-03 16:15:06 -03002231 dev_priv->psr.source_ok = true;
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03002232 return true;
2233}
2234
Rodrigo Vivi3d739d92013-07-11 18:45:01 -03002235static void intel_edp_psr_do_enable(struct intel_dp *intel_dp)
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002236{
Rodrigo Vivi7c8f8a72014-06-13 05:10:03 -07002237 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2238 struct drm_device *dev = intel_dig_port->base.base.dev;
2239 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002240
Daniel Vetter36383792014-07-11 10:30:13 -07002241 WARN_ON(I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE);
2242 WARN_ON(dev_priv->psr.active);
Daniel Vetterf0355c42014-07-11 10:30:15 -07002243 lockdep_assert_held(&dev_priv->psr.lock);
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002244
Rodrigo Vivi7ca5a412014-09-16 19:19:07 -04002245 /* Enable/Re-enable PSR on the host */
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002246 intel_edp_psr_enable_source(intel_dp);
Rodrigo Vivi7c8f8a72014-06-13 05:10:03 -07002247
Rodrigo Vivi7c8f8a72014-06-13 05:10:03 -07002248 dev_priv->psr.active = true;
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002249}
2250
Rodrigo Vivi3d739d92013-07-11 18:45:01 -03002251void intel_edp_psr_enable(struct intel_dp *intel_dp)
2252{
2253 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Daniel Vetter109fc2a2014-07-11 10:30:14 -07002254 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivi3d739d92013-07-11 18:45:01 -03002255
Rodrigo Vivi4704c572014-06-12 10:16:38 -07002256 if (!HAS_PSR(dev)) {
2257 DRM_DEBUG_KMS("PSR not supported on this platform\n");
2258 return;
2259 }
2260
Rodrigo Vivi34eb7572014-06-12 10:16:40 -07002261 if (!is_edp_psr(intel_dp)) {
2262 DRM_DEBUG_KMS("PSR not supported by this panel\n");
2263 return;
2264 }
2265
Daniel Vetterf0355c42014-07-11 10:30:15 -07002266 mutex_lock(&dev_priv->psr.lock);
Daniel Vetter109fc2a2014-07-11 10:30:14 -07002267 if (dev_priv->psr.enabled) {
2268 DRM_DEBUG_KMS("PSR already in use\n");
Rodrigo Vivi0aa48782014-09-16 19:19:06 -04002269 goto unlock;
Daniel Vetter109fc2a2014-07-11 10:30:14 -07002270 }
2271
Rodrigo Vivi0aa48782014-09-16 19:19:06 -04002272 if (!intel_edp_psr_match_conditions(intel_dp))
2273 goto unlock;
2274
Daniel Vetter9ca15302014-07-11 10:30:16 -07002275 dev_priv->psr.busy_frontbuffer_bits = 0;
2276
Rodrigo Viviba80f4d2014-09-16 19:19:05 -04002277 intel_edp_psr_setup_vsc(intel_dp);
Rodrigo Vivi16487252014-06-12 10:16:39 -07002278
Rodrigo Viviba80f4d2014-09-16 19:19:05 -04002279 /* Avoid continuous PSR exit by masking memup and hpd */
2280 I915_WRITE(EDP_PSR_DEBUG_CTL(dev), EDP_PSR_DEBUG_MASK_MEMUP |
2281 EDP_PSR_DEBUG_MASK_HPD | EDP_PSR_DEBUG_MASK_LPSP);
Rodrigo Vivi3d739d92013-07-11 18:45:01 -03002282
Rodrigo Vivi7ca5a412014-09-16 19:19:07 -04002283 /* Enable PSR on the panel */
2284 intel_edp_psr_enable_sink(intel_dp);
2285
Rodrigo Vivi0aa48782014-09-16 19:19:06 -04002286 dev_priv->psr.enabled = intel_dp;
2287unlock:
Daniel Vetterf0355c42014-07-11 10:30:15 -07002288 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivi3d739d92013-07-11 18:45:01 -03002289}
2290
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002291void intel_edp_psr_disable(struct intel_dp *intel_dp)
2292{
2293 struct drm_device *dev = intel_dp_to_dev(intel_dp);
2294 struct drm_i915_private *dev_priv = dev->dev_private;
2295
Daniel Vetterf0355c42014-07-11 10:30:15 -07002296 mutex_lock(&dev_priv->psr.lock);
2297 if (!dev_priv->psr.enabled) {
2298 mutex_unlock(&dev_priv->psr.lock);
2299 return;
2300 }
2301
Daniel Vetter36383792014-07-11 10:30:13 -07002302 if (dev_priv->psr.active) {
2303 I915_WRITE(EDP_PSR_CTL(dev),
2304 I915_READ(EDP_PSR_CTL(dev)) & ~EDP_PSR_ENABLE);
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002305
Daniel Vetter36383792014-07-11 10:30:13 -07002306 /* Wait till PSR is idle */
2307 if (_wait_for((I915_READ(EDP_PSR_STATUS_CTL(dev)) &
2308 EDP_PSR_STATUS_STATE_MASK) == 0, 2000, 10))
2309 DRM_ERROR("Timed out waiting for PSR Idle State\n");
2310
2311 dev_priv->psr.active = false;
2312 } else {
2313 WARN_ON(I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE);
2314 }
Rodrigo Vivi7c8f8a72014-06-13 05:10:03 -07002315
Daniel Vetter2807cf62014-07-11 10:30:11 -07002316 dev_priv->psr.enabled = NULL;
Daniel Vetterf0355c42014-07-11 10:30:15 -07002317 mutex_unlock(&dev_priv->psr.lock);
Daniel Vetter9ca15302014-07-11 10:30:16 -07002318
2319 cancel_delayed_work_sync(&dev_priv->psr.work);
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03002320}
2321
Daniel Vetterf02a3262014-06-16 19:51:21 +02002322static void intel_edp_psr_work(struct work_struct *work)
Rodrigo Vivi7c8f8a72014-06-13 05:10:03 -07002323{
2324 struct drm_i915_private *dev_priv =
2325 container_of(work, typeof(*dev_priv), psr.work.work);
Daniel Vetter2807cf62014-07-11 10:30:11 -07002326 struct intel_dp *intel_dp = dev_priv->psr.enabled;
Rodrigo Vivi7c8f8a72014-06-13 05:10:03 -07002327
Rodrigo Vivi8d7f4fe2014-09-24 18:16:58 -04002328 /* We have to make sure PSR is ready for re-enable
2329 * otherwise it keeps disabled until next full enable/disable cycle.
2330 * PSR might take some time to get fully disabled
2331 * and be ready for re-enable.
2332 */
2333 if (wait_for((I915_READ(EDP_PSR_STATUS_CTL(dev_priv->dev)) &
2334 EDP_PSR_STATUS_STATE_MASK) == 0, 50)) {
2335 DRM_ERROR("Timed out waiting for PSR Idle for re-enable\n");
2336 return;
2337 }
2338
Daniel Vetterf0355c42014-07-11 10:30:15 -07002339 mutex_lock(&dev_priv->psr.lock);
2340 intel_dp = dev_priv->psr.enabled;
2341
Daniel Vetter2807cf62014-07-11 10:30:11 -07002342 if (!intel_dp)
Daniel Vetterf0355c42014-07-11 10:30:15 -07002343 goto unlock;
Rodrigo Vivi3d739d92013-07-11 18:45:01 -03002344
Daniel Vetter9ca15302014-07-11 10:30:16 -07002345 /*
2346 * The delayed work can race with an invalidate hence we need to
2347 * recheck. Since psr_flush first clears this and then reschedules we
2348 * won't ever miss a flush when bailing out here.
2349 */
2350 if (dev_priv->psr.busy_frontbuffer_bits)
2351 goto unlock;
2352
2353 intel_edp_psr_do_enable(intel_dp);
Daniel Vetterf0355c42014-07-11 10:30:15 -07002354unlock:
2355 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivi3d739d92013-07-11 18:45:01 -03002356}
2357
Daniel Vetter9ca15302014-07-11 10:30:16 -07002358static void intel_edp_psr_do_exit(struct drm_device *dev)
Rodrigo Vivi7c8f8a72014-06-13 05:10:03 -07002359{
2360 struct drm_i915_private *dev_priv = dev->dev_private;
2361
Daniel Vetter36383792014-07-11 10:30:13 -07002362 if (dev_priv->psr.active) {
2363 u32 val = I915_READ(EDP_PSR_CTL(dev));
2364
2365 WARN_ON(!(val & EDP_PSR_ENABLE));
2366
2367 I915_WRITE(EDP_PSR_CTL(dev), val & ~EDP_PSR_ENABLE);
2368
2369 dev_priv->psr.active = false;
2370 }
Rodrigo Vivi7c8f8a72014-06-13 05:10:03 -07002371
Daniel Vetter9ca15302014-07-11 10:30:16 -07002372}
2373
2374void intel_edp_psr_invalidate(struct drm_device *dev,
2375 unsigned frontbuffer_bits)
2376{
2377 struct drm_i915_private *dev_priv = dev->dev_private;
2378 struct drm_crtc *crtc;
2379 enum pipe pipe;
2380
Daniel Vetter9ca15302014-07-11 10:30:16 -07002381 mutex_lock(&dev_priv->psr.lock);
2382 if (!dev_priv->psr.enabled) {
2383 mutex_unlock(&dev_priv->psr.lock);
2384 return;
2385 }
2386
2387 crtc = dp_to_dig_port(dev_priv->psr.enabled)->base.base.crtc;
2388 pipe = to_intel_crtc(crtc)->pipe;
2389
2390 intel_edp_psr_do_exit(dev);
2391
2392 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
2393
2394 dev_priv->psr.busy_frontbuffer_bits |= frontbuffer_bits;
2395 mutex_unlock(&dev_priv->psr.lock);
2396}
2397
2398void intel_edp_psr_flush(struct drm_device *dev,
2399 unsigned frontbuffer_bits)
2400{
2401 struct drm_i915_private *dev_priv = dev->dev_private;
2402 struct drm_crtc *crtc;
2403 enum pipe pipe;
2404
Daniel Vetter9ca15302014-07-11 10:30:16 -07002405 mutex_lock(&dev_priv->psr.lock);
2406 if (!dev_priv->psr.enabled) {
2407 mutex_unlock(&dev_priv->psr.lock);
2408 return;
2409 }
2410
2411 crtc = dp_to_dig_port(dev_priv->psr.enabled)->base.base.crtc;
2412 pipe = to_intel_crtc(crtc)->pipe;
2413 dev_priv->psr.busy_frontbuffer_bits &= ~frontbuffer_bits;
2414
2415 /*
2416 * On Haswell sprite plane updates don't result in a psr invalidating
2417 * signal in the hardware. Which means we need to manually fake this in
2418 * software for all flushes, not just when we've seen a preceding
2419 * invalidation through frontbuffer rendering.
2420 */
2421 if (IS_HASWELL(dev) &&
2422 (frontbuffer_bits & INTEL_FRONTBUFFER_SPRITE(pipe)))
2423 intel_edp_psr_do_exit(dev);
2424
2425 if (!dev_priv->psr.active && !dev_priv->psr.busy_frontbuffer_bits)
2426 schedule_delayed_work(&dev_priv->psr.work,
2427 msecs_to_jiffies(100));
Daniel Vetterf0355c42014-07-11 10:30:15 -07002428 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivi7c8f8a72014-06-13 05:10:03 -07002429}
2430
2431void intel_edp_psr_init(struct drm_device *dev)
2432{
2433 struct drm_i915_private *dev_priv = dev->dev_private;
2434
Rodrigo Vivi7c8f8a72014-06-13 05:10:03 -07002435 INIT_DELAYED_WORK(&dev_priv->psr.work, intel_edp_psr_work);
Daniel Vetterf0355c42014-07-11 10:30:15 -07002436 mutex_init(&dev_priv->psr.lock);
Rodrigo Vivi7c8f8a72014-06-13 05:10:03 -07002437}
2438
Daniel Vettere8cb4552012-07-01 13:05:48 +02002439static void intel_disable_dp(struct intel_encoder *encoder)
Jesse Barnesd240f202010-08-13 15:43:26 -07002440{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002441 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002442 struct drm_device *dev = encoder->base.dev;
Daniel Vetter6cb49832012-05-20 17:14:50 +02002443
2444 /* Make sure the panel is off before trying to change the mode. But also
2445 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002446 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01002447 intel_edp_backlight_off(intel_dp);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002448 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002449 intel_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02002450
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002451 /* disable the port before the pipe on g4x */
2452 if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter37398502012-09-06 22:15:44 +02002453 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07002454}
2455
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002456static void ilk_post_disable_dp(struct intel_encoder *encoder)
Jesse Barnesd240f202010-08-13 15:43:26 -07002457{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002458 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002459 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002460
Ville Syrjälä49277c32014-03-31 18:21:26 +03002461 intel_dp_link_down(intel_dp);
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002462 if (port == PORT_A)
2463 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002464}
2465
2466static void vlv_post_disable_dp(struct intel_encoder *encoder)
2467{
2468 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2469
2470 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002471}
2472
Ville Syrjälä580d3812014-04-09 13:29:00 +03002473static void chv_post_disable_dp(struct intel_encoder *encoder)
2474{
2475 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2476 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
2477 struct drm_device *dev = encoder->base.dev;
2478 struct drm_i915_private *dev_priv = dev->dev_private;
2479 struct intel_crtc *intel_crtc =
2480 to_intel_crtc(encoder->base.crtc);
2481 enum dpio_channel ch = vlv_dport_to_channel(dport);
2482 enum pipe pipe = intel_crtc->pipe;
2483 u32 val;
2484
2485 intel_dp_link_down(intel_dp);
2486
2487 mutex_lock(&dev_priv->dpio_lock);
2488
2489 /* Propagate soft reset to data lane reset */
Ville Syrjälä97fd4d52014-04-09 13:29:02 +03002490 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW1(ch));
Ville Syrjäläd2152b22014-04-28 14:15:24 +03002491 val |= CHV_PCS_REQ_SOFTRESET_EN;
Ville Syrjälä97fd4d52014-04-09 13:29:02 +03002492 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW1(ch), val);
Ville Syrjäläd2152b22014-04-28 14:15:24 +03002493
Ville Syrjälä97fd4d52014-04-09 13:29:02 +03002494 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW1(ch));
2495 val |= CHV_PCS_REQ_SOFTRESET_EN;
2496 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW1(ch), val);
2497
2498 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW0(ch));
Ville Syrjälä580d3812014-04-09 13:29:00 +03002499 val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
Ville Syrjälä97fd4d52014-04-09 13:29:02 +03002500 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW0(ch), val);
2501
2502 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW0(ch));
2503 val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
2504 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW0(ch), val);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002505
2506 mutex_unlock(&dev_priv->dpio_lock);
2507}
2508
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002509static void
2510_intel_dp_set_link_train(struct intel_dp *intel_dp,
2511 uint32_t *DP,
2512 uint8_t dp_train_pat)
2513{
2514 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2515 struct drm_device *dev = intel_dig_port->base.base.dev;
2516 struct drm_i915_private *dev_priv = dev->dev_private;
2517 enum port port = intel_dig_port->port;
2518
2519 if (HAS_DDI(dev)) {
2520 uint32_t temp = I915_READ(DP_TP_CTL(port));
2521
2522 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2523 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2524 else
2525 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2526
2527 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2528 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2529 case DP_TRAINING_PATTERN_DISABLE:
2530 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2531
2532 break;
2533 case DP_TRAINING_PATTERN_1:
2534 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2535 break;
2536 case DP_TRAINING_PATTERN_2:
2537 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2538 break;
2539 case DP_TRAINING_PATTERN_3:
2540 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2541 break;
2542 }
2543 I915_WRITE(DP_TP_CTL(port), temp);
2544
2545 } else if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || port != PORT_A)) {
2546 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2547
2548 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2549 case DP_TRAINING_PATTERN_DISABLE:
2550 *DP |= DP_LINK_TRAIN_OFF_CPT;
2551 break;
2552 case DP_TRAINING_PATTERN_1:
2553 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2554 break;
2555 case DP_TRAINING_PATTERN_2:
2556 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2557 break;
2558 case DP_TRAINING_PATTERN_3:
2559 DRM_ERROR("DP training pattern 3 not supported\n");
2560 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2561 break;
2562 }
2563
2564 } else {
2565 if (IS_CHERRYVIEW(dev))
2566 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2567 else
2568 *DP &= ~DP_LINK_TRAIN_MASK;
2569
2570 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2571 case DP_TRAINING_PATTERN_DISABLE:
2572 *DP |= DP_LINK_TRAIN_OFF;
2573 break;
2574 case DP_TRAINING_PATTERN_1:
2575 *DP |= DP_LINK_TRAIN_PAT_1;
2576 break;
2577 case DP_TRAINING_PATTERN_2:
2578 *DP |= DP_LINK_TRAIN_PAT_2;
2579 break;
2580 case DP_TRAINING_PATTERN_3:
2581 if (IS_CHERRYVIEW(dev)) {
2582 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2583 } else {
2584 DRM_ERROR("DP training pattern 3 not supported\n");
2585 *DP |= DP_LINK_TRAIN_PAT_2;
2586 }
2587 break;
2588 }
2589 }
2590}
2591
2592static void intel_dp_enable_port(struct intel_dp *intel_dp)
2593{
2594 struct drm_device *dev = intel_dp_to_dev(intel_dp);
2595 struct drm_i915_private *dev_priv = dev->dev_private;
2596
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002597 /* enable with pattern 1 (as per spec) */
2598 _intel_dp_set_link_train(intel_dp, &intel_dp->DP,
2599 DP_TRAINING_PATTERN_1);
2600
2601 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2602 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002603
2604 /*
2605 * Magic for VLV/CHV. We _must_ first set up the register
2606 * without actually enabling the port, and then do another
2607 * write to enable the port. Otherwise link training will
2608 * fail when the power sequencer is freshly used for this port.
2609 */
2610 intel_dp->DP |= DP_PORT_EN;
2611
2612 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2613 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002614}
2615
Daniel Vettere8cb4552012-07-01 13:05:48 +02002616static void intel_enable_dp(struct intel_encoder *encoder)
Jesse Barnesd240f202010-08-13 15:43:26 -07002617{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002618 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2619 struct drm_device *dev = encoder->base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002620 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +01002621 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002622
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002623 if (WARN_ON(dp_reg & DP_PORT_EN))
2624 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002625
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002626 pps_lock(intel_dp);
2627
2628 if (IS_VALLEYVIEW(dev))
2629 vlv_init_panel_power_sequencer(intel_dp);
2630
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002631 intel_dp_enable_port(intel_dp);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002632
2633 edp_panel_vdd_on(intel_dp);
2634 edp_panel_on(intel_dp);
2635 edp_panel_vdd_off(intel_dp, true);
2636
2637 pps_unlock(intel_dp);
2638
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002639 if (IS_VALLEYVIEW(dev))
2640 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp));
2641
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002642 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2643 intel_dp_start_link_train(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002644 intel_dp_complete_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002645 intel_dp_stop_link_train(intel_dp);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002646}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002647
Jani Nikulaecff4f32013-09-06 07:38:29 +03002648static void g4x_enable_dp(struct intel_encoder *encoder)
2649{
Jani Nikula828f5c62013-09-05 16:44:45 +03002650 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2651
Jani Nikulaecff4f32013-09-06 07:38:29 +03002652 intel_enable_dp(encoder);
Daniel Vetter4be73782014-01-17 14:39:48 +01002653 intel_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002654}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002655
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002656static void vlv_enable_dp(struct intel_encoder *encoder)
2657{
Jani Nikula828f5c62013-09-05 16:44:45 +03002658 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2659
Daniel Vetter4be73782014-01-17 14:39:48 +01002660 intel_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002661}
2662
Jani Nikulaecff4f32013-09-06 07:38:29 +03002663static void g4x_pre_enable_dp(struct intel_encoder *encoder)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002664{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002665 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002666 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002667
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002668 intel_dp_prepare(encoder);
2669
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002670 /* Only ilk+ has port A */
2671 if (dport->port == PORT_A) {
2672 ironlake_set_pll_cpu_edp(intel_dp);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002673 ironlake_edp_pll_on(intel_dp);
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002674 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002675}
2676
Ville Syrjälä83b84592014-10-16 21:29:51 +03002677static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2678{
2679 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2680 struct drm_i915_private *dev_priv = intel_dig_port->base.base.dev->dev_private;
2681 enum pipe pipe = intel_dp->pps_pipe;
2682 int pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe);
2683
2684 edp_panel_vdd_off_sync(intel_dp);
2685
2686 /*
2687 * VLV seems to get confused when multiple power seqeuencers
2688 * have the same port selected (even if only one has power/vdd
2689 * enabled). The failure manifests as vlv_wait_port_ready() failing
2690 * CHV on the other hand doesn't seem to mind having the same port
2691 * selected in multiple power seqeuencers, but let's clear the
2692 * port select always when logically disconnecting a power sequencer
2693 * from a port.
2694 */
2695 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2696 pipe_name(pipe), port_name(intel_dig_port->port));
2697 I915_WRITE(pp_on_reg, 0);
2698 POSTING_READ(pp_on_reg);
2699
2700 intel_dp->pps_pipe = INVALID_PIPE;
2701}
2702
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002703static void vlv_steal_power_sequencer(struct drm_device *dev,
2704 enum pipe pipe)
2705{
2706 struct drm_i915_private *dev_priv = dev->dev_private;
2707 struct intel_encoder *encoder;
2708
2709 lockdep_assert_held(&dev_priv->pps_mutex);
2710
Ville Syrjäläac3c12e2014-10-16 21:29:56 +03002711 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2712 return;
2713
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002714 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
2715 base.head) {
2716 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002717 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002718
2719 if (encoder->type != INTEL_OUTPUT_EDP)
2720 continue;
2721
2722 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002723 port = dp_to_dig_port(intel_dp)->port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002724
2725 if (intel_dp->pps_pipe != pipe)
2726 continue;
2727
2728 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03002729 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002730
2731 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002732 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002733 }
2734}
2735
2736static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
2737{
2738 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2739 struct intel_encoder *encoder = &intel_dig_port->base;
2740 struct drm_device *dev = encoder->base.dev;
2741 struct drm_i915_private *dev_priv = dev->dev_private;
2742 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002743
2744 lockdep_assert_held(&dev_priv->pps_mutex);
2745
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002746 if (!is_edp(intel_dp))
2747 return;
2748
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002749 if (intel_dp->pps_pipe == crtc->pipe)
2750 return;
2751
2752 /*
2753 * If another power sequencer was being used on this
2754 * port previously make sure to turn off vdd there while
2755 * we still have control of it.
2756 */
2757 if (intel_dp->pps_pipe != INVALID_PIPE)
Ville Syrjälä83b84592014-10-16 21:29:51 +03002758 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002759
2760 /*
2761 * We may be stealing the power
2762 * sequencer from another port.
2763 */
2764 vlv_steal_power_sequencer(dev, crtc->pipe);
2765
2766 /* now it's all ours */
2767 intel_dp->pps_pipe = crtc->pipe;
2768
2769 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
2770 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
2771
2772 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03002773 intel_dp_init_panel_power_sequencer(dev, intel_dp);
2774 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002775}
2776
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002777static void vlv_pre_enable_dp(struct intel_encoder *encoder)
2778{
2779 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2780 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
Jesse Barnesb2634012013-03-28 09:55:40 -07002781 struct drm_device *dev = encoder->base.dev;
Jesse Barnes89b667f2013-04-18 14:51:36 -07002782 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002783 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
Chon Ming Leee4607fc2013-11-06 14:36:35 +08002784 enum dpio_channel port = vlv_dport_to_channel(dport);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002785 int pipe = intel_crtc->pipe;
2786 u32 val;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002787
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002788 mutex_lock(&dev_priv->dpio_lock);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002789
Chon Ming Leeab3c7592013-11-07 10:43:30 +08002790 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(port));
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002791 val = 0;
2792 if (pipe)
2793 val |= (1<<21);
2794 else
2795 val &= ~(1<<21);
2796 val |= 0x001000c4;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08002797 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW8(port), val);
2798 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW14(port), 0x00760018);
2799 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW23(port), 0x00400888);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002800
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002801 mutex_unlock(&dev_priv->dpio_lock);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002802
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002803 intel_enable_dp(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002804}
2805
Jani Nikulaecff4f32013-09-06 07:38:29 +03002806static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder)
Jesse Barnes89b667f2013-04-18 14:51:36 -07002807{
2808 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
2809 struct drm_device *dev = encoder->base.dev;
2810 struct drm_i915_private *dev_priv = dev->dev_private;
Chon Ming Lee5e69f972013-09-05 20:41:49 +08002811 struct intel_crtc *intel_crtc =
2812 to_intel_crtc(encoder->base.crtc);
Chon Ming Leee4607fc2013-11-06 14:36:35 +08002813 enum dpio_channel port = vlv_dport_to_channel(dport);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08002814 int pipe = intel_crtc->pipe;
Jesse Barnes89b667f2013-04-18 14:51:36 -07002815
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002816 intel_dp_prepare(encoder);
2817
Jesse Barnes89b667f2013-04-18 14:51:36 -07002818 /* Program Tx lane resets to default */
Chris Wilson0980a602013-07-26 19:57:35 +01002819 mutex_lock(&dev_priv->dpio_lock);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08002820 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07002821 DPIO_PCS_TX_LANE2_RESET |
2822 DPIO_PCS_TX_LANE1_RESET);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08002823 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07002824 DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
2825 DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
2826 (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
2827 DPIO_PCS_CLK_SOFT_RESET);
2828
2829 /* Fix up inter-pair skew failure */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08002830 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW12(port), 0x00750f00);
2831 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW11(port), 0x00001500);
2832 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW14(port), 0x40400000);
Chris Wilson0980a602013-07-26 19:57:35 +01002833 mutex_unlock(&dev_priv->dpio_lock);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002834}
2835
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002836static void chv_pre_enable_dp(struct intel_encoder *encoder)
2837{
2838 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2839 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
2840 struct drm_device *dev = encoder->base.dev;
2841 struct drm_i915_private *dev_priv = dev->dev_private;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002842 struct intel_crtc *intel_crtc =
2843 to_intel_crtc(encoder->base.crtc);
2844 enum dpio_channel ch = vlv_dport_to_channel(dport);
2845 int pipe = intel_crtc->pipe;
2846 int data, i;
Ville Syrjälä949c1d42014-04-09 13:28:58 +03002847 u32 val;
2848
2849 mutex_lock(&dev_priv->dpio_lock);
2850
Ville Syrjälä570e2a72014-08-18 14:42:46 +03002851 /* allow hardware to manage TX FIFO reset source */
2852 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
2853 val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
2854 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
2855
2856 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
2857 val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
2858 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
2859
Ville Syrjälä949c1d42014-04-09 13:28:58 +03002860 /* Deassert soft data lane reset*/
Ville Syrjälä97fd4d52014-04-09 13:29:02 +03002861 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW1(ch));
Ville Syrjäläd2152b22014-04-28 14:15:24 +03002862 val |= CHV_PCS_REQ_SOFTRESET_EN;
Ville Syrjälä97fd4d52014-04-09 13:29:02 +03002863 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW1(ch), val);
Ville Syrjäläd2152b22014-04-28 14:15:24 +03002864
Ville Syrjälä97fd4d52014-04-09 13:29:02 +03002865 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW1(ch));
2866 val |= CHV_PCS_REQ_SOFTRESET_EN;
2867 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW1(ch), val);
2868
2869 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW0(ch));
Ville Syrjälä949c1d42014-04-09 13:28:58 +03002870 val |= (DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
Ville Syrjälä97fd4d52014-04-09 13:29:02 +03002871 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW0(ch), val);
2872
2873 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW0(ch));
2874 val |= (DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
2875 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW0(ch), val);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002876
2877 /* Program Tx lane latency optimal setting*/
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002878 for (i = 0; i < 4; i++) {
2879 /* Set the latency optimal bit */
2880 data = (i == 1) ? 0x0 : 0x6;
2881 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW11(ch, i),
2882 data << DPIO_FRC_LATENCY_SHFIT);
2883
2884 /* Set the upar bit */
2885 data = (i == 1) ? 0x0 : 0x1;
2886 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW14(ch, i),
2887 data << DPIO_UPAR_SHIFT);
2888 }
2889
2890 /* Data lane stagger programming */
2891 /* FIXME: Fix up value only after power analysis */
2892
2893 mutex_unlock(&dev_priv->dpio_lock);
2894
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002895 intel_enable_dp(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002896}
2897
Ville Syrjälä9197c882014-04-09 13:29:05 +03002898static void chv_dp_pre_pll_enable(struct intel_encoder *encoder)
2899{
2900 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
2901 struct drm_device *dev = encoder->base.dev;
2902 struct drm_i915_private *dev_priv = dev->dev_private;
2903 struct intel_crtc *intel_crtc =
2904 to_intel_crtc(encoder->base.crtc);
2905 enum dpio_channel ch = vlv_dport_to_channel(dport);
2906 enum pipe pipe = intel_crtc->pipe;
2907 u32 val;
2908
Ville Syrjälä625695f2014-06-28 02:04:02 +03002909 intel_dp_prepare(encoder);
2910
Ville Syrjälä9197c882014-04-09 13:29:05 +03002911 mutex_lock(&dev_priv->dpio_lock);
2912
Ville Syrjäläb9e5ac32014-05-27 16:30:18 +03002913 /* program left/right clock distribution */
2914 if (pipe != PIPE_B) {
2915 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
2916 val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
2917 if (ch == DPIO_CH0)
2918 val |= CHV_BUFLEFTENA1_FORCE;
2919 if (ch == DPIO_CH1)
2920 val |= CHV_BUFRIGHTENA1_FORCE;
2921 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
2922 } else {
2923 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
2924 val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
2925 if (ch == DPIO_CH0)
2926 val |= CHV_BUFLEFTENA2_FORCE;
2927 if (ch == DPIO_CH1)
2928 val |= CHV_BUFRIGHTENA2_FORCE;
2929 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
2930 }
2931
Ville Syrjälä9197c882014-04-09 13:29:05 +03002932 /* program clock channel usage */
2933 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(ch));
2934 val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
2935 if (pipe != PIPE_B)
2936 val &= ~CHV_PCS_USEDCLKCHANNEL;
2937 else
2938 val |= CHV_PCS_USEDCLKCHANNEL;
2939 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW8(ch), val);
2940
2941 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW8(ch));
2942 val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
2943 if (pipe != PIPE_B)
2944 val &= ~CHV_PCS_USEDCLKCHANNEL;
2945 else
2946 val |= CHV_PCS_USEDCLKCHANNEL;
2947 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW8(ch), val);
2948
2949 /*
2950 * This a a bit weird since generally CL
2951 * matches the pipe, but here we need to
2952 * pick the CL based on the port.
2953 */
2954 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW19(ch));
2955 if (pipe != PIPE_B)
2956 val &= ~CHV_CMN_USEDCLKCHANNEL;
2957 else
2958 val |= CHV_CMN_USEDCLKCHANNEL;
2959 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW19(ch), val);
2960
2961 mutex_unlock(&dev_priv->dpio_lock);
2962}
2963
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002964/*
Jesse Barnesdf0c2372011-07-07 11:11:02 -07002965 * Native read with retry for link status and receiver capability reads for
2966 * cases where the sink may still be asleep.
Jani Nikula9d1a1032014-03-14 16:51:15 +02002967 *
2968 * Sinks are *supposed* to come up within 1ms from an off state, but we're also
2969 * supposed to retry 3 times per the spec.
Jesse Barnesdf0c2372011-07-07 11:11:02 -07002970 */
Jani Nikula9d1a1032014-03-14 16:51:15 +02002971static ssize_t
2972intel_dp_dpcd_read_wake(struct drm_dp_aux *aux, unsigned int offset,
2973 void *buffer, size_t size)
Jesse Barnesdf0c2372011-07-07 11:11:02 -07002974{
Jani Nikula9d1a1032014-03-14 16:51:15 +02002975 ssize_t ret;
2976 int i;
Jesse Barnesdf0c2372011-07-07 11:11:02 -07002977
Jesse Barnesdf0c2372011-07-07 11:11:02 -07002978 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002979 ret = drm_dp_dpcd_read(aux, offset, buffer, size);
2980 if (ret == size)
2981 return ret;
Jesse Barnesdf0c2372011-07-07 11:11:02 -07002982 msleep(1);
2983 }
2984
Jani Nikula9d1a1032014-03-14 16:51:15 +02002985 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002986}
2987
2988/*
2989 * Fetch AUX CH registers 0x202 - 0x207 which contain
2990 * link status information
2991 */
2992static bool
Keith Packard93f62da2011-11-01 19:45:03 -07002993intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002994{
Jani Nikula9d1a1032014-03-14 16:51:15 +02002995 return intel_dp_dpcd_read_wake(&intel_dp->aux,
2996 DP_LANE0_1_STATUS,
2997 link_status,
2998 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002999}
3000
Paulo Zanoni11002442014-06-13 18:45:41 -03003001/* These are source-specific values. */
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003002static uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003003intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003004{
Paulo Zanoni30add222012-10-26 19:05:45 -02003005 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003006 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003007
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003008 if (INTEL_INFO(dev)->gen >= 9)
3009 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
3010 else if (IS_VALLEYVIEW(dev))
Sonika Jindalbd600182014-08-08 16:23:41 +05303011 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Imre Deakbc7d38a2013-05-16 14:40:36 +03003012 else if (IS_GEN7(dev) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303013 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Imre Deakbc7d38a2013-05-16 14:40:36 +03003014 else if (HAS_PCH_CPT(dev) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303015 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08003016 else
Sonika Jindalbd600182014-08-08 16:23:41 +05303017 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08003018}
3019
3020static uint8_t
3021intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3022{
Paulo Zanoni30add222012-10-26 19:05:45 -02003023 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003024 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003025
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003026 if (INTEL_INFO(dev)->gen >= 9) {
3027 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3028 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3029 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3030 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3031 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3032 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3033 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3034 default:
3035 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3036 }
3037 } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003038 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303039 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3040 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3041 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3042 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3043 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3044 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3045 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003046 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303047 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003048 }
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003049 } else if (IS_VALLEYVIEW(dev)) {
3050 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303051 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3052 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3053 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3054 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3055 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3056 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3057 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003058 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303059 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003060 }
Imre Deakbc7d38a2013-05-16 14:40:36 +03003061 } else if (IS_GEN7(dev) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003062 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303063 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3064 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3065 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3066 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3067 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003068 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303069 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003070 }
3071 } else {
3072 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303073 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3074 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3075 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3076 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3077 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3078 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3079 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003080 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303081 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003082 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003083 }
3084}
3085
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003086static uint32_t intel_vlv_signal_levels(struct intel_dp *intel_dp)
3087{
3088 struct drm_device *dev = intel_dp_to_dev(intel_dp);
3089 struct drm_i915_private *dev_priv = dev->dev_private;
3090 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08003091 struct intel_crtc *intel_crtc =
3092 to_intel_crtc(dport->base.base.crtc);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003093 unsigned long demph_reg_value, preemph_reg_value,
3094 uniqtranscale_reg_value;
3095 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4607fc2013-11-06 14:36:35 +08003096 enum dpio_channel port = vlv_dport_to_channel(dport);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08003097 int pipe = intel_crtc->pipe;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003098
3099 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303100 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003101 preemph_reg_value = 0x0004000;
3102 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303103 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003104 demph_reg_value = 0x2B405555;
3105 uniqtranscale_reg_value = 0x552AB83A;
3106 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303107 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003108 demph_reg_value = 0x2B404040;
3109 uniqtranscale_reg_value = 0x5548B83A;
3110 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303111 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003112 demph_reg_value = 0x2B245555;
3113 uniqtranscale_reg_value = 0x5560B83A;
3114 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303115 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003116 demph_reg_value = 0x2B405555;
3117 uniqtranscale_reg_value = 0x5598DA3A;
3118 break;
3119 default:
3120 return 0;
3121 }
3122 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303123 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003124 preemph_reg_value = 0x0002000;
3125 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303126 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003127 demph_reg_value = 0x2B404040;
3128 uniqtranscale_reg_value = 0x5552B83A;
3129 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303130 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003131 demph_reg_value = 0x2B404848;
3132 uniqtranscale_reg_value = 0x5580B83A;
3133 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303134 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003135 demph_reg_value = 0x2B404040;
3136 uniqtranscale_reg_value = 0x55ADDA3A;
3137 break;
3138 default:
3139 return 0;
3140 }
3141 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303142 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003143 preemph_reg_value = 0x0000000;
3144 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303145 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003146 demph_reg_value = 0x2B305555;
3147 uniqtranscale_reg_value = 0x5570B83A;
3148 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303149 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003150 demph_reg_value = 0x2B2B4040;
3151 uniqtranscale_reg_value = 0x55ADDA3A;
3152 break;
3153 default:
3154 return 0;
3155 }
3156 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303157 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003158 preemph_reg_value = 0x0006000;
3159 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303160 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003161 demph_reg_value = 0x1B405555;
3162 uniqtranscale_reg_value = 0x55ADDA3A;
3163 break;
3164 default:
3165 return 0;
3166 }
3167 break;
3168 default:
3169 return 0;
3170 }
3171
Chris Wilson0980a602013-07-26 19:57:35 +01003172 mutex_lock(&dev_priv->dpio_lock);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08003173 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0x00000000);
3174 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW4(port), demph_reg_value);
3175 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW2(port),
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003176 uniqtranscale_reg_value);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08003177 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW3(port), 0x0C782040);
3178 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW11(port), 0x00030000);
3179 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW9(port), preemph_reg_value);
3180 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0x80000000);
Chris Wilson0980a602013-07-26 19:57:35 +01003181 mutex_unlock(&dev_priv->dpio_lock);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003182
3183 return 0;
3184}
3185
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003186static uint32_t intel_chv_signal_levels(struct intel_dp *intel_dp)
3187{
3188 struct drm_device *dev = intel_dp_to_dev(intel_dp);
3189 struct drm_i915_private *dev_priv = dev->dev_private;
3190 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
3191 struct intel_crtc *intel_crtc = to_intel_crtc(dport->base.base.crtc);
Ville Syrjäläf72df8d2014-04-09 13:29:03 +03003192 u32 deemph_reg_value, margin_reg_value, val;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003193 uint8_t train_set = intel_dp->train_set[0];
3194 enum dpio_channel ch = vlv_dport_to_channel(dport);
Ville Syrjäläf72df8d2014-04-09 13:29:03 +03003195 enum pipe pipe = intel_crtc->pipe;
3196 int i;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003197
3198 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303199 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003200 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303201 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003202 deemph_reg_value = 128;
3203 margin_reg_value = 52;
3204 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303205 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003206 deemph_reg_value = 128;
3207 margin_reg_value = 77;
3208 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303209 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003210 deemph_reg_value = 128;
3211 margin_reg_value = 102;
3212 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303213 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003214 deemph_reg_value = 128;
3215 margin_reg_value = 154;
3216 /* FIXME extra to set for 1200 */
3217 break;
3218 default:
3219 return 0;
3220 }
3221 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303222 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003223 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303224 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003225 deemph_reg_value = 85;
3226 margin_reg_value = 78;
3227 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303228 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003229 deemph_reg_value = 85;
3230 margin_reg_value = 116;
3231 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303232 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003233 deemph_reg_value = 85;
3234 margin_reg_value = 154;
3235 break;
3236 default:
3237 return 0;
3238 }
3239 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303240 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003241 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303242 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003243 deemph_reg_value = 64;
3244 margin_reg_value = 104;
3245 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303246 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003247 deemph_reg_value = 64;
3248 margin_reg_value = 154;
3249 break;
3250 default:
3251 return 0;
3252 }
3253 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303254 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003255 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303256 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003257 deemph_reg_value = 43;
3258 margin_reg_value = 154;
3259 break;
3260 default:
3261 return 0;
3262 }
3263 break;
3264 default:
3265 return 0;
3266 }
3267
3268 mutex_lock(&dev_priv->dpio_lock);
3269
3270 /* Clear calc init */
Ville Syrjälä1966e592014-04-09 13:29:04 +03003271 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
3272 val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
Ville Syrjäläa02ef3c2014-08-18 14:42:45 +03003273 val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
3274 val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
Ville Syrjälä1966e592014-04-09 13:29:04 +03003275 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
3276
3277 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
3278 val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
Ville Syrjäläa02ef3c2014-08-18 14:42:45 +03003279 val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
3280 val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
Ville Syrjälä1966e592014-04-09 13:29:04 +03003281 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003282
Ville Syrjäläa02ef3c2014-08-18 14:42:45 +03003283 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW9(ch));
3284 val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
3285 val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
3286 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW9(ch), val);
3287
3288 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW9(ch));
3289 val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
3290 val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
3291 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW9(ch), val);
3292
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003293 /* Program swing deemph */
Ville Syrjäläf72df8d2014-04-09 13:29:03 +03003294 for (i = 0; i < 4; i++) {
3295 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW4(ch, i));
3296 val &= ~DPIO_SWING_DEEMPH9P5_MASK;
3297 val |= deemph_reg_value << DPIO_SWING_DEEMPH9P5_SHIFT;
3298 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW4(ch, i), val);
3299 }
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003300
3301 /* Program swing margin */
Ville Syrjäläf72df8d2014-04-09 13:29:03 +03003302 for (i = 0; i < 4; i++) {
3303 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW2(ch, i));
Ville Syrjälä1fb44502014-06-28 02:04:03 +03003304 val &= ~DPIO_SWING_MARGIN000_MASK;
3305 val |= margin_reg_value << DPIO_SWING_MARGIN000_SHIFT;
Ville Syrjäläf72df8d2014-04-09 13:29:03 +03003306 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW2(ch, i), val);
3307 }
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003308
3309 /* Disable unique transition scale */
Ville Syrjäläf72df8d2014-04-09 13:29:03 +03003310 for (i = 0; i < 4; i++) {
3311 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW3(ch, i));
3312 val &= ~DPIO_TX_UNIQ_TRANS_SCALE_EN;
3313 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW3(ch, i), val);
3314 }
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003315
3316 if (((train_set & DP_TRAIN_PRE_EMPHASIS_MASK)
Sonika Jindalbd600182014-08-08 16:23:41 +05303317 == DP_TRAIN_PRE_EMPH_LEVEL_0) &&
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003318 ((train_set & DP_TRAIN_VOLTAGE_SWING_MASK)
Sonika Jindalbd600182014-08-08 16:23:41 +05303319 == DP_TRAIN_VOLTAGE_SWING_LEVEL_3)) {
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003320
3321 /*
3322 * The document said it needs to set bit 27 for ch0 and bit 26
3323 * for ch1. Might be a typo in the doc.
3324 * For now, for this unique transition scale selection, set bit
3325 * 27 for ch0 and ch1.
3326 */
Ville Syrjäläf72df8d2014-04-09 13:29:03 +03003327 for (i = 0; i < 4; i++) {
3328 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW3(ch, i));
3329 val |= DPIO_TX_UNIQ_TRANS_SCALE_EN;
3330 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW3(ch, i), val);
3331 }
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003332
Ville Syrjäläf72df8d2014-04-09 13:29:03 +03003333 for (i = 0; i < 4; i++) {
3334 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW2(ch, i));
3335 val &= ~(0xff << DPIO_UNIQ_TRANS_SCALE_SHIFT);
3336 val |= (0x9a << DPIO_UNIQ_TRANS_SCALE_SHIFT);
3337 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW2(ch, i), val);
3338 }
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003339 }
3340
3341 /* Start swing calculation */
Ville Syrjälä1966e592014-04-09 13:29:04 +03003342 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
3343 val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
3344 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
3345
3346 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
3347 val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
3348 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003349
3350 /* LRC Bypass */
3351 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
3352 val |= DPIO_LRC_BYPASS;
3353 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, val);
3354
3355 mutex_unlock(&dev_priv->dpio_lock);
3356
3357 return 0;
3358}
3359
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003360static void
Jani Nikula0301b3a2013-10-15 09:36:08 +03003361intel_get_adjust_train(struct intel_dp *intel_dp,
3362 const uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003363{
3364 uint8_t v = 0;
3365 uint8_t p = 0;
3366 int lane;
Keith Packard1a2eb462011-11-16 16:26:07 -08003367 uint8_t voltage_max;
3368 uint8_t preemph_max;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003369
Jesse Barnes33a34e42010-09-08 12:42:02 -07003370 for (lane = 0; lane < intel_dp->lane_count; lane++) {
Daniel Vetter0f037bd2012-10-18 10:15:27 +02003371 uint8_t this_v = drm_dp_get_adjust_request_voltage(link_status, lane);
3372 uint8_t this_p = drm_dp_get_adjust_request_pre_emphasis(link_status, lane);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003373
3374 if (this_v > v)
3375 v = this_v;
3376 if (this_p > p)
3377 p = this_p;
3378 }
3379
Keith Packard1a2eb462011-11-16 16:26:07 -08003380 voltage_max = intel_dp_voltage_max(intel_dp);
Keith Packard417e8222011-11-01 19:54:11 -07003381 if (v >= voltage_max)
3382 v = voltage_max | DP_TRAIN_MAX_SWING_REACHED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003383
Keith Packard1a2eb462011-11-16 16:26:07 -08003384 preemph_max = intel_dp_pre_emphasis_max(intel_dp, v);
3385 if (p >= preemph_max)
3386 p = preemph_max | DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003387
3388 for (lane = 0; lane < 4; lane++)
Jesse Barnes33a34e42010-09-08 12:42:02 -07003389 intel_dp->train_set[lane] = v | p;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003390}
3391
3392static uint32_t
Paulo Zanonif0a34242012-12-06 16:51:50 -02003393intel_gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003394{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003395 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003396
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003397 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303398 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003399 default:
3400 signal_levels |= DP_VOLTAGE_0_4;
3401 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303402 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003403 signal_levels |= DP_VOLTAGE_0_6;
3404 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303405 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003406 signal_levels |= DP_VOLTAGE_0_8;
3407 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303408 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003409 signal_levels |= DP_VOLTAGE_1_2;
3410 break;
3411 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003412 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303413 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003414 default:
3415 signal_levels |= DP_PRE_EMPHASIS_0;
3416 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303417 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003418 signal_levels |= DP_PRE_EMPHASIS_3_5;
3419 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303420 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003421 signal_levels |= DP_PRE_EMPHASIS_6;
3422 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303423 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003424 signal_levels |= DP_PRE_EMPHASIS_9_5;
3425 break;
3426 }
3427 return signal_levels;
3428}
3429
Zhenyu Wange3421a12010-04-08 09:43:27 +08003430/* Gen6's DP voltage swing and pre-emphasis control */
3431static uint32_t
3432intel_gen6_edp_signal_levels(uint8_t train_set)
3433{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003434 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3435 DP_TRAIN_PRE_EMPHASIS_MASK);
3436 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303437 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3438 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003439 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303440 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003441 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303442 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3443 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003444 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303445 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3446 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003447 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303448 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3449 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003450 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003451 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003452 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3453 "0x%x\n", signal_levels);
3454 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003455 }
3456}
3457
Keith Packard1a2eb462011-11-16 16:26:07 -08003458/* Gen7's DP voltage swing and pre-emphasis control */
3459static uint32_t
3460intel_gen7_edp_signal_levels(uint8_t train_set)
3461{
3462 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3463 DP_TRAIN_PRE_EMPHASIS_MASK);
3464 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303465 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003466 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303467 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003468 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303469 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003470 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3471
Sonika Jindalbd600182014-08-08 16:23:41 +05303472 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003473 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303474 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003475 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3476
Sonika Jindalbd600182014-08-08 16:23:41 +05303477 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003478 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303479 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003480 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3481
3482 default:
3483 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3484 "0x%x\n", signal_levels);
3485 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3486 }
3487}
3488
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003489/* Gen7.5's (HSW) DP voltage swing and pre-emphasis control */
3490static uint32_t
Paulo Zanonif0a34242012-12-06 16:51:50 -02003491intel_hsw_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003492{
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003493 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3494 DP_TRAIN_PRE_EMPHASIS_MASK);
3495 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303496 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Sonika Jindalc5fe6a02014-08-11 08:57:36 +05303497 return DDI_BUF_TRANS_SELECT(0);
Sonika Jindalbd600182014-08-08 16:23:41 +05303498 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Sonika Jindalc5fe6a02014-08-11 08:57:36 +05303499 return DDI_BUF_TRANS_SELECT(1);
Sonika Jindalbd600182014-08-08 16:23:41 +05303500 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Sonika Jindalc5fe6a02014-08-11 08:57:36 +05303501 return DDI_BUF_TRANS_SELECT(2);
Sonika Jindalbd600182014-08-08 16:23:41 +05303502 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_3:
Sonika Jindalc5fe6a02014-08-11 08:57:36 +05303503 return DDI_BUF_TRANS_SELECT(3);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003504
Sonika Jindalbd600182014-08-08 16:23:41 +05303505 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Sonika Jindalc5fe6a02014-08-11 08:57:36 +05303506 return DDI_BUF_TRANS_SELECT(4);
Sonika Jindalbd600182014-08-08 16:23:41 +05303507 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Sonika Jindalc5fe6a02014-08-11 08:57:36 +05303508 return DDI_BUF_TRANS_SELECT(5);
Sonika Jindalbd600182014-08-08 16:23:41 +05303509 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Sonika Jindalc5fe6a02014-08-11 08:57:36 +05303510 return DDI_BUF_TRANS_SELECT(6);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003511
Sonika Jindalbd600182014-08-08 16:23:41 +05303512 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Sonika Jindalc5fe6a02014-08-11 08:57:36 +05303513 return DDI_BUF_TRANS_SELECT(7);
Sonika Jindalbd600182014-08-08 16:23:41 +05303514 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Sonika Jindalc5fe6a02014-08-11 08:57:36 +05303515 return DDI_BUF_TRANS_SELECT(8);
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003516 default:
3517 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3518 "0x%x\n", signal_levels);
Sonika Jindalc5fe6a02014-08-11 08:57:36 +05303519 return DDI_BUF_TRANS_SELECT(0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003520 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003521}
3522
Paulo Zanonif0a34242012-12-06 16:51:50 -02003523/* Properly updates "DP" with the correct signal levels. */
3524static void
3525intel_dp_set_signal_levels(struct intel_dp *intel_dp, uint32_t *DP)
3526{
3527 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003528 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003529 struct drm_device *dev = intel_dig_port->base.base.dev;
3530 uint32_t signal_levels, mask;
3531 uint8_t train_set = intel_dp->train_set[0];
3532
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003533 if (IS_HASWELL(dev) || IS_BROADWELL(dev) || INTEL_INFO(dev)->gen >= 9) {
Paulo Zanonif0a34242012-12-06 16:51:50 -02003534 signal_levels = intel_hsw_signal_levels(train_set);
3535 mask = DDI_BUF_EMP_MASK;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003536 } else if (IS_CHERRYVIEW(dev)) {
3537 signal_levels = intel_chv_signal_levels(intel_dp);
3538 mask = 0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003539 } else if (IS_VALLEYVIEW(dev)) {
3540 signal_levels = intel_vlv_signal_levels(intel_dp);
3541 mask = 0;
Imre Deakbc7d38a2013-05-16 14:40:36 +03003542 } else if (IS_GEN7(dev) && port == PORT_A) {
Paulo Zanonif0a34242012-12-06 16:51:50 -02003543 signal_levels = intel_gen7_edp_signal_levels(train_set);
3544 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Imre Deakbc7d38a2013-05-16 14:40:36 +03003545 } else if (IS_GEN6(dev) && port == PORT_A) {
Paulo Zanonif0a34242012-12-06 16:51:50 -02003546 signal_levels = intel_gen6_edp_signal_levels(train_set);
3547 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3548 } else {
3549 signal_levels = intel_gen4_signal_levels(train_set);
3550 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3551 }
3552
3553 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3554
3555 *DP = (*DP & ~mask) | signal_levels;
3556}
3557
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003558static bool
Chris Wilsonea5b2132010-08-04 13:50:23 +01003559intel_dp_set_link_train(struct intel_dp *intel_dp,
Jani Nikula70aff662013-09-27 15:10:44 +03003560 uint32_t *DP,
Chris Wilson58e10eb2010-10-03 10:56:11 +01003561 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003562{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003563 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3564 struct drm_device *dev = intel_dig_port->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003565 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula2cdfe6c2013-10-04 15:08:48 +03003566 uint8_t buf[sizeof(intel_dp->train_set) + 1];
3567 int ret, len;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003568
Ville Syrjälä7b13b582014-08-18 22:16:08 +03003569 _intel_dp_set_link_train(intel_dp, DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003570
Jani Nikula70aff662013-09-27 15:10:44 +03003571 I915_WRITE(intel_dp->output_reg, *DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003572 POSTING_READ(intel_dp->output_reg);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003573
Jani Nikula2cdfe6c2013-10-04 15:08:48 +03003574 buf[0] = dp_train_pat;
3575 if ((dp_train_pat & DP_TRAINING_PATTERN_MASK) ==
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003576 DP_TRAINING_PATTERN_DISABLE) {
Jani Nikula2cdfe6c2013-10-04 15:08:48 +03003577 /* don't write DP_TRAINING_LANEx_SET on disable */
3578 len = 1;
3579 } else {
3580 /* DP_TRAINING_LANEx_SET follow DP_TRAINING_PATTERN_SET */
3581 memcpy(buf + 1, intel_dp->train_set, intel_dp->lane_count);
3582 len = intel_dp->lane_count + 1;
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003583 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003584
Jani Nikula9d1a1032014-03-14 16:51:15 +02003585 ret = drm_dp_dpcd_write(&intel_dp->aux, DP_TRAINING_PATTERN_SET,
3586 buf, len);
Jani Nikula2cdfe6c2013-10-04 15:08:48 +03003587
3588 return ret == len;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003589}
3590
Jani Nikula70aff662013-09-27 15:10:44 +03003591static bool
3592intel_dp_reset_link_train(struct intel_dp *intel_dp, uint32_t *DP,
3593 uint8_t dp_train_pat)
3594{
Jani Nikula953d22e2013-10-04 15:08:47 +03003595 memset(intel_dp->train_set, 0, sizeof(intel_dp->train_set));
Jani Nikula70aff662013-09-27 15:10:44 +03003596 intel_dp_set_signal_levels(intel_dp, DP);
3597 return intel_dp_set_link_train(intel_dp, DP, dp_train_pat);
3598}
3599
3600static bool
3601intel_dp_update_link_train(struct intel_dp *intel_dp, uint32_t *DP,
Jani Nikula0301b3a2013-10-15 09:36:08 +03003602 const uint8_t link_status[DP_LINK_STATUS_SIZE])
Jani Nikula70aff662013-09-27 15:10:44 +03003603{
3604 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3605 struct drm_device *dev = intel_dig_port->base.base.dev;
3606 struct drm_i915_private *dev_priv = dev->dev_private;
3607 int ret;
3608
3609 intel_get_adjust_train(intel_dp, link_status);
3610 intel_dp_set_signal_levels(intel_dp, DP);
3611
3612 I915_WRITE(intel_dp->output_reg, *DP);
3613 POSTING_READ(intel_dp->output_reg);
3614
Jani Nikula9d1a1032014-03-14 16:51:15 +02003615 ret = drm_dp_dpcd_write(&intel_dp->aux, DP_TRAINING_LANE0_SET,
3616 intel_dp->train_set, intel_dp->lane_count);
Jani Nikula70aff662013-09-27 15:10:44 +03003617
3618 return ret == intel_dp->lane_count;
3619}
3620
Imre Deak3ab9c632013-05-03 12:57:41 +03003621static void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
3622{
3623 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3624 struct drm_device *dev = intel_dig_port->base.base.dev;
3625 struct drm_i915_private *dev_priv = dev->dev_private;
3626 enum port port = intel_dig_port->port;
3627 uint32_t val;
3628
3629 if (!HAS_DDI(dev))
3630 return;
3631
3632 val = I915_READ(DP_TP_CTL(port));
3633 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3634 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3635 I915_WRITE(DP_TP_CTL(port), val);
3636
3637 /*
3638 * On PORT_A we can have only eDP in SST mode. There the only reason
3639 * we need to set idle transmission mode is to work around a HW issue
3640 * where we enable the pipe while not in idle link-training mode.
3641 * In this case there is requirement to wait for a minimum number of
3642 * idle patterns to be sent.
3643 */
3644 if (port == PORT_A)
3645 return;
3646
3647 if (wait_for((I915_READ(DP_TP_STATUS(port)) & DP_TP_STATUS_IDLE_DONE),
3648 1))
3649 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3650}
3651
Jesse Barnes33a34e42010-09-08 12:42:02 -07003652/* Enable corresponding port and start training pattern 1 */
Paulo Zanonic19b0662012-10-15 15:51:41 -03003653void
Jesse Barnes33a34e42010-09-08 12:42:02 -07003654intel_dp_start_link_train(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003655{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003656 struct drm_encoder *encoder = &dp_to_dig_port(intel_dp)->base.base;
Paulo Zanonic19b0662012-10-15 15:51:41 -03003657 struct drm_device *dev = encoder->dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003658 int i;
3659 uint8_t voltage;
Keith Packardcdb0e952011-11-01 20:00:06 -07003660 int voltage_tries, loop_tries;
Chris Wilsonea5b2132010-08-04 13:50:23 +01003661 uint32_t DP = intel_dp->DP;
Jani Nikula6aba5b62013-10-04 15:08:10 +03003662 uint8_t link_config[2];
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003663
Paulo Zanoniaffa9352012-11-23 15:30:39 -02003664 if (HAS_DDI(dev))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003665 intel_ddi_prepare_link_retrain(encoder);
3666
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003667 /* Write the link configuration data */
Jani Nikula6aba5b62013-10-04 15:08:10 +03003668 link_config[0] = intel_dp->link_bw;
3669 link_config[1] = intel_dp->lane_count;
3670 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
3671 link_config[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
Jani Nikula9d1a1032014-03-14 16:51:15 +02003672 drm_dp_dpcd_write(&intel_dp->aux, DP_LINK_BW_SET, link_config, 2);
Jani Nikula6aba5b62013-10-04 15:08:10 +03003673
3674 link_config[0] = 0;
3675 link_config[1] = DP_SET_ANSI_8B10B;
Jani Nikula9d1a1032014-03-14 16:51:15 +02003676 drm_dp_dpcd_write(&intel_dp->aux, DP_DOWNSPREAD_CTRL, link_config, 2);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003677
3678 DP |= DP_PORT_EN;
Keith Packard1a2eb462011-11-16 16:26:07 -08003679
Jani Nikula70aff662013-09-27 15:10:44 +03003680 /* clock recovery */
3681 if (!intel_dp_reset_link_train(intel_dp, &DP,
3682 DP_TRAINING_PATTERN_1 |
3683 DP_LINK_SCRAMBLING_DISABLE)) {
3684 DRM_ERROR("failed to enable link training\n");
3685 return;
3686 }
3687
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003688 voltage = 0xff;
Keith Packardcdb0e952011-11-01 20:00:06 -07003689 voltage_tries = 0;
3690 loop_tries = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003691 for (;;) {
Jani Nikula70aff662013-09-27 15:10:44 +03003692 uint8_t link_status[DP_LINK_STATUS_SIZE];
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003693
Daniel Vettera7c96552012-10-18 10:15:30 +02003694 drm_dp_link_train_clock_recovery_delay(intel_dp->dpcd);
Keith Packard93f62da2011-11-01 19:45:03 -07003695 if (!intel_dp_get_link_status(intel_dp, link_status)) {
3696 DRM_ERROR("failed to get link status\n");
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003697 break;
Keith Packard93f62da2011-11-01 19:45:03 -07003698 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003699
Daniel Vetter01916272012-10-18 10:15:25 +02003700 if (drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
Keith Packard93f62da2011-11-01 19:45:03 -07003701 DRM_DEBUG_KMS("clock recovery OK\n");
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003702 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003703 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003704
3705 /* Check to see if we've tried the max voltage */
3706 for (i = 0; i < intel_dp->lane_count; i++)
3707 if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
3708 break;
Takashi Iwai3b4f8192013-03-11 18:40:16 +01003709 if (i == intel_dp->lane_count) {
Daniel Vetterb06fbda2012-10-16 09:50:25 +02003710 ++loop_tries;
3711 if (loop_tries == 5) {
Jani Nikula3def84b2013-10-05 16:13:56 +03003712 DRM_ERROR("too many full retries, give up\n");
Keith Packardcdb0e952011-11-01 20:00:06 -07003713 break;
3714 }
Jani Nikula70aff662013-09-27 15:10:44 +03003715 intel_dp_reset_link_train(intel_dp, &DP,
3716 DP_TRAINING_PATTERN_1 |
3717 DP_LINK_SCRAMBLING_DISABLE);
Keith Packardcdb0e952011-11-01 20:00:06 -07003718 voltage_tries = 0;
3719 continue;
3720 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003721
3722 /* Check to see if we've tried the same voltage 5 times */
Daniel Vetterb06fbda2012-10-16 09:50:25 +02003723 if ((intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) == voltage) {
Chris Wilson24773672012-09-26 16:48:30 +01003724 ++voltage_tries;
Daniel Vetterb06fbda2012-10-16 09:50:25 +02003725 if (voltage_tries == 5) {
Jani Nikula3def84b2013-10-05 16:13:56 +03003726 DRM_ERROR("too many voltage retries, give up\n");
Daniel Vetterb06fbda2012-10-16 09:50:25 +02003727 break;
3728 }
3729 } else
3730 voltage_tries = 0;
3731 voltage = intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003732
Jani Nikula70aff662013-09-27 15:10:44 +03003733 /* Update training set as requested by target */
3734 if (!intel_dp_update_link_train(intel_dp, &DP, link_status)) {
3735 DRM_ERROR("failed to update link training\n");
3736 break;
3737 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003738 }
3739
Jesse Barnes33a34e42010-09-08 12:42:02 -07003740 intel_dp->DP = DP;
3741}
3742
Paulo Zanonic19b0662012-10-15 15:51:41 -03003743void
Jesse Barnes33a34e42010-09-08 12:42:02 -07003744intel_dp_complete_link_train(struct intel_dp *intel_dp)
3745{
Jesse Barnes33a34e42010-09-08 12:42:02 -07003746 bool channel_eq = false;
Jesse Barnes37f80972011-01-05 14:45:24 -08003747 int tries, cr_tries;
Jesse Barnes33a34e42010-09-08 12:42:02 -07003748 uint32_t DP = intel_dp->DP;
Todd Previte06ea66b2014-01-20 10:19:39 -07003749 uint32_t training_pattern = DP_TRAINING_PATTERN_2;
3750
3751 /* Training Pattern 3 for HBR2 ot 1.2 devices that support it*/
3752 if (intel_dp->link_bw == DP_LINK_BW_5_4 || intel_dp->use_tps3)
3753 training_pattern = DP_TRAINING_PATTERN_3;
Jesse Barnes33a34e42010-09-08 12:42:02 -07003754
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003755 /* channel equalization */
Jani Nikula70aff662013-09-27 15:10:44 +03003756 if (!intel_dp_set_link_train(intel_dp, &DP,
Todd Previte06ea66b2014-01-20 10:19:39 -07003757 training_pattern |
Jani Nikula70aff662013-09-27 15:10:44 +03003758 DP_LINK_SCRAMBLING_DISABLE)) {
3759 DRM_ERROR("failed to start channel equalization\n");
3760 return;
3761 }
3762
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003763 tries = 0;
Jesse Barnes37f80972011-01-05 14:45:24 -08003764 cr_tries = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003765 channel_eq = false;
3766 for (;;) {
Jani Nikula70aff662013-09-27 15:10:44 +03003767 uint8_t link_status[DP_LINK_STATUS_SIZE];
Zhenyu Wange3421a12010-04-08 09:43:27 +08003768
Jesse Barnes37f80972011-01-05 14:45:24 -08003769 if (cr_tries > 5) {
3770 DRM_ERROR("failed to train DP, aborting\n");
Jesse Barnes37f80972011-01-05 14:45:24 -08003771 break;
3772 }
3773
Daniel Vettera7c96552012-10-18 10:15:30 +02003774 drm_dp_link_train_channel_eq_delay(intel_dp->dpcd);
Jani Nikula70aff662013-09-27 15:10:44 +03003775 if (!intel_dp_get_link_status(intel_dp, link_status)) {
3776 DRM_ERROR("failed to get link status\n");
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003777 break;
Jani Nikula70aff662013-09-27 15:10:44 +03003778 }
Jesse Barnes869184a2010-10-07 16:01:22 -07003779
Jesse Barnes37f80972011-01-05 14:45:24 -08003780 /* Make sure clock is still ok */
Daniel Vetter01916272012-10-18 10:15:25 +02003781 if (!drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
Jesse Barnes37f80972011-01-05 14:45:24 -08003782 intel_dp_start_link_train(intel_dp);
Jani Nikula70aff662013-09-27 15:10:44 +03003783 intel_dp_set_link_train(intel_dp, &DP,
Todd Previte06ea66b2014-01-20 10:19:39 -07003784 training_pattern |
Jani Nikula70aff662013-09-27 15:10:44 +03003785 DP_LINK_SCRAMBLING_DISABLE);
Jesse Barnes37f80972011-01-05 14:45:24 -08003786 cr_tries++;
3787 continue;
3788 }
3789
Daniel Vetter1ffdff12012-10-18 10:15:24 +02003790 if (drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003791 channel_eq = true;
3792 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003793 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003794
Jesse Barnes37f80972011-01-05 14:45:24 -08003795 /* Try 5 times, then try clock recovery if that fails */
3796 if (tries > 5) {
3797 intel_dp_link_down(intel_dp);
3798 intel_dp_start_link_train(intel_dp);
Jani Nikula70aff662013-09-27 15:10:44 +03003799 intel_dp_set_link_train(intel_dp, &DP,
Todd Previte06ea66b2014-01-20 10:19:39 -07003800 training_pattern |
Jani Nikula70aff662013-09-27 15:10:44 +03003801 DP_LINK_SCRAMBLING_DISABLE);
Jesse Barnes37f80972011-01-05 14:45:24 -08003802 tries = 0;
3803 cr_tries++;
3804 continue;
3805 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003806
Jani Nikula70aff662013-09-27 15:10:44 +03003807 /* Update training set as requested by target */
3808 if (!intel_dp_update_link_train(intel_dp, &DP, link_status)) {
3809 DRM_ERROR("failed to update link training\n");
3810 break;
3811 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003812 ++tries;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003813 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003814
Imre Deak3ab9c632013-05-03 12:57:41 +03003815 intel_dp_set_idle_link_train(intel_dp);
3816
3817 intel_dp->DP = DP;
3818
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003819 if (channel_eq)
Masanari Iida07f42252013-03-20 11:00:34 +09003820 DRM_DEBUG_KMS("Channel EQ done. DP Training successful\n");
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003821
Imre Deak3ab9c632013-05-03 12:57:41 +03003822}
3823
3824void intel_dp_stop_link_train(struct intel_dp *intel_dp)
3825{
Jani Nikula70aff662013-09-27 15:10:44 +03003826 intel_dp_set_link_train(intel_dp, &intel_dp->DP,
Imre Deak3ab9c632013-05-03 12:57:41 +03003827 DP_TRAINING_PATTERN_DISABLE);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003828}
3829
3830static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003831intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003832{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003833 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003834 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003835 struct drm_device *dev = intel_dig_port->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003836 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterab527ef2012-11-29 15:59:33 +01003837 struct intel_crtc *intel_crtc =
3838 to_intel_crtc(intel_dig_port->base.base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003839 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003840
Daniel Vetterbc76e322014-05-20 22:46:50 +02003841 if (WARN_ON(HAS_DDI(dev)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003842 return;
3843
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003844 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003845 return;
3846
Zhao Yakui28c97732009-10-09 11:39:41 +08003847 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003848
Imre Deakbc7d38a2013-05-16 14:40:36 +03003849 if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003850 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Chris Wilsonea5b2132010-08-04 13:50:23 +01003851 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT);
Zhenyu Wange3421a12010-04-08 09:43:27 +08003852 } else {
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003853 if (IS_CHERRYVIEW(dev))
3854 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3855 else
3856 DP &= ~DP_LINK_TRAIN_MASK;
Chris Wilsonea5b2132010-08-04 13:50:23 +01003857 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE);
Zhenyu Wange3421a12010-04-08 09:43:27 +08003858 }
Chris Wilsonfe255d02010-09-11 21:37:48 +01003859 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003860
Daniel Vetter493a7082012-05-30 12:31:56 +02003861 if (HAS_PCH_IBX(dev) &&
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003862 I915_READ(intel_dp->output_reg) & DP_PIPEB_SELECT) {
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003863 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
Chris Wilson31acbcc2011-04-17 06:38:35 +01003864
Eric Anholt5bddd172010-11-18 09:32:59 +08003865 /* Hardware workaround: leaving our transcoder select
3866 * set to transcoder B while it's off will prevent the
3867 * corresponding HDMI output on transcoder A.
3868 *
3869 * Combine this with another hardware workaround:
3870 * transcoder select bit can only be cleared while the
3871 * port is enabled.
3872 */
3873 DP &= ~DP_PIPEB_SELECT;
3874 I915_WRITE(intel_dp->output_reg, DP);
3875
3876 /* Changes to enable or select take place the vblank
3877 * after being written.
3878 */
Daniel Vetterff50afe2012-11-29 15:59:34 +01003879 if (WARN_ON(crtc == NULL)) {
3880 /* We should never try to disable a port without a crtc
3881 * attached. For paranoia keep the code around for a
3882 * bit. */
Chris Wilson31acbcc2011-04-17 06:38:35 +01003883 POSTING_READ(intel_dp->output_reg);
3884 msleep(50);
3885 } else
Daniel Vetterab527ef2012-11-29 15:59:33 +01003886 intel_wait_for_vblank(dev, intel_crtc->pipe);
Eric Anholt5bddd172010-11-18 09:32:59 +08003887 }
3888
Wu Fengguang832afda2011-12-09 20:42:21 +08003889 DP &= ~DP_AUDIO_OUTPUT_ENABLE;
Chris Wilsonea5b2132010-08-04 13:50:23 +01003890 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
3891 POSTING_READ(intel_dp->output_reg);
Keith Packardf01eca22011-09-28 16:48:10 -07003892 msleep(intel_dp->panel_power_down_delay);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003893}
3894
Keith Packard26d61aa2011-07-25 20:01:09 -07003895static bool
3896intel_dp_get_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003897{
Rodrigo Vivia031d702013-10-03 16:15:06 -03003898 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
3899 struct drm_device *dev = dig_port->base.base.dev;
3900 struct drm_i915_private *dev_priv = dev->dev_private;
3901
Jani Nikula9d1a1032014-03-14 16:51:15 +02003902 if (intel_dp_dpcd_read_wake(&intel_dp->aux, 0x000, intel_dp->dpcd,
3903 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003904 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003905
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003906 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003907
Adam Jacksonedb39242012-09-18 10:58:49 -04003908 if (intel_dp->dpcd[DP_DPCD_REV] == 0)
3909 return false; /* DPCD not present */
3910
Shobhit Kumar2293bb52013-07-11 18:44:56 -03003911 /* Check if the panel supports PSR */
3912 memset(intel_dp->psr_dpcd, 0, sizeof(intel_dp->psr_dpcd));
Jani Nikula50003932013-09-20 16:42:17 +03003913 if (is_edp(intel_dp)) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02003914 intel_dp_dpcd_read_wake(&intel_dp->aux, DP_PSR_SUPPORT,
3915 intel_dp->psr_dpcd,
3916 sizeof(intel_dp->psr_dpcd));
Rodrigo Vivia031d702013-10-03 16:15:06 -03003917 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3918 dev_priv->psr.sink_support = true;
Jani Nikula50003932013-09-20 16:42:17 +03003919 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
Rodrigo Vivia031d702013-10-03 16:15:06 -03003920 }
Jani Nikula50003932013-09-20 16:42:17 +03003921 }
3922
Todd Previte06ea66b2014-01-20 10:19:39 -07003923 /* Training Pattern 3 support */
3924 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x12 &&
3925 intel_dp->dpcd[DP_MAX_LANE_COUNT] & DP_TPS3_SUPPORTED) {
3926 intel_dp->use_tps3 = true;
Jani Nikulaf8d8a672014-09-05 16:19:18 +03003927 DRM_DEBUG_KMS("Displayport TPS3 supported\n");
Todd Previte06ea66b2014-01-20 10:19:39 -07003928 } else
3929 intel_dp->use_tps3 = false;
3930
Adam Jacksonedb39242012-09-18 10:58:49 -04003931 if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
3932 DP_DWN_STRM_PORT_PRESENT))
3933 return true; /* native DP sink */
3934
3935 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3936 return true; /* no per-port downstream info */
3937
Jani Nikula9d1a1032014-03-14 16:51:15 +02003938 if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3939 intel_dp->downstream_ports,
3940 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003941 return false; /* downstream port status fetch failed */
3942
3943 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003944}
3945
Adam Jackson0d198322012-05-14 16:05:47 -04003946static void
3947intel_dp_probe_oui(struct intel_dp *intel_dp)
3948{
3949 u8 buf[3];
3950
3951 if (!(intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] & DP_OUI_SUPPORT))
3952 return;
3953
Jani Nikula9d1a1032014-03-14 16:51:15 +02003954 if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_SINK_OUI, buf, 3) == 3)
Adam Jackson0d198322012-05-14 16:05:47 -04003955 DRM_DEBUG_KMS("Sink OUI: %02hx%02hx%02hx\n",
3956 buf[0], buf[1], buf[2]);
3957
Jani Nikula9d1a1032014-03-14 16:51:15 +02003958 if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_BRANCH_OUI, buf, 3) == 3)
Adam Jackson0d198322012-05-14 16:05:47 -04003959 DRM_DEBUG_KMS("Branch OUI: %02hx%02hx%02hx\n",
3960 buf[0], buf[1], buf[2]);
3961}
3962
Dave Airlie0e32b392014-05-02 14:02:48 +10003963static bool
3964intel_dp_probe_mst(struct intel_dp *intel_dp)
3965{
3966 u8 buf[1];
3967
3968 if (!intel_dp->can_mst)
3969 return false;
3970
3971 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3972 return false;
3973
Dave Airlie0e32b392014-05-02 14:02:48 +10003974 if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_MSTM_CAP, buf, 1)) {
3975 if (buf[0] & DP_MST_CAP) {
3976 DRM_DEBUG_KMS("Sink is MST capable\n");
3977 intel_dp->is_mst = true;
3978 } else {
3979 DRM_DEBUG_KMS("Sink is not MST capable\n");
3980 intel_dp->is_mst = false;
3981 }
3982 }
Dave Airlie0e32b392014-05-02 14:02:48 +10003983
3984 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
3985 return intel_dp->is_mst;
3986}
3987
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003988int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3989{
3990 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3991 struct drm_device *dev = intel_dig_port->base.base.dev;
3992 struct intel_crtc *intel_crtc =
3993 to_intel_crtc(intel_dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003994 u8 buf;
3995 int test_crc_count;
3996 int attempts = 6;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003997
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003998 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
Rodrigo Vivibda03812014-09-15 19:24:03 -04003999 return -EIO;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004000
Rodrigo Viviad9dc912014-09-16 19:18:12 -04004001 if (!(buf & DP_TEST_CRC_SUPPORTED))
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004002 return -ENOTTY;
4003
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07004004 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
Rodrigo Vivibda03812014-09-15 19:24:03 -04004005 return -EIO;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004006
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004007 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivice31d9f2014-09-29 18:29:52 -04004008 buf | DP_TEST_SINK_START) < 0)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004009 return -EIO;
4010
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07004011 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
4012 return -EIO;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04004013 test_crc_count = buf & DP_TEST_COUNT_MASK;
4014
4015 do {
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07004016 if (drm_dp_dpcd_readb(&intel_dp->aux,
4017 DP_TEST_SINK_MISC, &buf) < 0)
4018 return -EIO;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04004019 intel_wait_for_vblank(dev, intel_crtc->pipe);
4020 } while (--attempts && (buf & DP_TEST_COUNT_MASK) == test_crc_count);
4021
4022 if (attempts == 0) {
4023 DRM_ERROR("Panel is unable to calculate CRC after 6 vblanks\n");
4024 return -EIO;
4025 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004026
Jani Nikula9d1a1032014-03-14 16:51:15 +02004027 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0)
Rodrigo Vivibda03812014-09-15 19:24:03 -04004028 return -EIO;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004029
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07004030 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
4031 return -EIO;
4032 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
4033 buf & ~DP_TEST_SINK_START) < 0)
4034 return -EIO;
Rodrigo Vivice31d9f2014-09-29 18:29:52 -04004035
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004036 return 0;
4037}
4038
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004039static bool
4040intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
4041{
Jani Nikula9d1a1032014-03-14 16:51:15 +02004042 return intel_dp_dpcd_read_wake(&intel_dp->aux,
4043 DP_DEVICE_SERVICE_IRQ_VECTOR,
4044 sink_irq_vector, 1) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004045}
4046
Dave Airlie0e32b392014-05-02 14:02:48 +10004047static bool
4048intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
4049{
4050 int ret;
4051
4052 ret = intel_dp_dpcd_read_wake(&intel_dp->aux,
4053 DP_SINK_COUNT_ESI,
4054 sink_irq_vector, 14);
4055 if (ret != 14)
4056 return false;
4057
4058 return true;
4059}
4060
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004061static void
4062intel_dp_handle_test_request(struct intel_dp *intel_dp)
4063{
4064 /* NAK by default */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004065 drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, DP_TEST_NAK);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004066}
4067
Dave Airlie0e32b392014-05-02 14:02:48 +10004068static int
4069intel_dp_check_mst_status(struct intel_dp *intel_dp)
4070{
4071 bool bret;
4072
4073 if (intel_dp->is_mst) {
4074 u8 esi[16] = { 0 };
4075 int ret = 0;
4076 int retry;
4077 bool handled;
4078 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4079go_again:
4080 if (bret == true) {
4081
4082 /* check link status - esi[10] = 0x200c */
4083 if (intel_dp->active_mst_links && !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
4084 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4085 intel_dp_start_link_train(intel_dp);
4086 intel_dp_complete_link_train(intel_dp);
4087 intel_dp_stop_link_train(intel_dp);
4088 }
4089
4090 DRM_DEBUG_KMS("got esi %02x %02x %02x\n", esi[0], esi[1], esi[2]);
4091 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4092
4093 if (handled) {
4094 for (retry = 0; retry < 3; retry++) {
4095 int wret;
4096 wret = drm_dp_dpcd_write(&intel_dp->aux,
4097 DP_SINK_COUNT_ESI+1,
4098 &esi[1], 3);
4099 if (wret == 3) {
4100 break;
4101 }
4102 }
4103
4104 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4105 if (bret == true) {
4106 DRM_DEBUG_KMS("got esi2 %02x %02x %02x\n", esi[0], esi[1], esi[2]);
4107 goto go_again;
4108 }
4109 } else
4110 ret = 0;
4111
4112 return ret;
4113 } else {
4114 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4115 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4116 intel_dp->is_mst = false;
4117 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4118 /* send a hotplug event */
4119 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4120 }
4121 }
4122 return -EINVAL;
4123}
4124
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004125/*
4126 * According to DP spec
4127 * 5.1.2:
4128 * 1. Read DPCD
4129 * 2. Configure link according to Receiver Capabilities
4130 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4131 * 4. Check link status on receipt of hot-plug interrupt
4132 */
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004133void
Chris Wilsonea5b2132010-08-04 13:50:23 +01004134intel_dp_check_link_status(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004135{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004136 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004137 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004138 u8 sink_irq_vector;
Keith Packard93f62da2011-11-01 19:45:03 -07004139 u8 link_status[DP_LINK_STATUS_SIZE];
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004140
Dave Airlie5b215bc2014-08-05 10:40:20 +10004141 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
4142
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004143 if (!intel_encoder->connectors_active)
Keith Packardd2b996a2011-07-25 22:37:51 -07004144 return;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004145
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004146 if (WARN_ON(!intel_encoder->base.crtc))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004147 return;
4148
Imre Deak1a125d82014-08-18 14:42:46 +03004149 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4150 return;
4151
Keith Packard92fd8fd2011-07-25 19:50:10 -07004152 /* Try to read receiver status if the link appears to be up */
Keith Packard93f62da2011-11-01 19:45:03 -07004153 if (!intel_dp_get_link_status(intel_dp, link_status)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004154 return;
4155 }
4156
Keith Packard92fd8fd2011-07-25 19:50:10 -07004157 /* Now read the DPCD to see if it's actually running */
Keith Packard26d61aa2011-07-25 20:01:09 -07004158 if (!intel_dp_get_dpcd(intel_dp)) {
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004159 return;
4160 }
4161
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004162 /* Try to read the source of the interrupt */
4163 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4164 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector)) {
4165 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004166 drm_dp_dpcd_writeb(&intel_dp->aux,
4167 DP_DEVICE_SERVICE_IRQ_VECTOR,
4168 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004169
4170 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4171 intel_dp_handle_test_request(intel_dp);
4172 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4173 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4174 }
4175
Daniel Vetter1ffdff12012-10-18 10:15:24 +02004176 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Keith Packard92fd8fd2011-07-25 19:50:10 -07004177 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03004178 intel_encoder->base.name);
Jesse Barnes33a34e42010-09-08 12:42:02 -07004179 intel_dp_start_link_train(intel_dp);
4180 intel_dp_complete_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03004181 intel_dp_stop_link_train(intel_dp);
Jesse Barnes33a34e42010-09-08 12:42:02 -07004182 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004183}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004184
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004185/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004186static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004187intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004188{
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004189 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004190 uint8_t type;
4191
4192 if (!intel_dp_get_dpcd(intel_dp))
4193 return connector_status_disconnected;
4194
4195 /* if there's no downstream port, we're done */
4196 if (!(dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT))
Keith Packard26d61aa2011-07-25 20:01:09 -07004197 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004198
4199 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004200 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4201 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Adam Jackson23235172012-09-20 16:42:45 -04004202 uint8_t reg;
Jani Nikula9d1a1032014-03-14 16:51:15 +02004203
4204 if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_SINK_COUNT,
4205 &reg, 1) < 0)
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004206 return connector_status_unknown;
Jani Nikula9d1a1032014-03-14 16:51:15 +02004207
Adam Jackson23235172012-09-20 16:42:45 -04004208 return DP_GET_SINK_COUNT(reg) ? connector_status_connected
4209 : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004210 }
4211
4212 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004213 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004214 return connector_status_connected;
4215
4216 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004217 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4218 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4219 if (type == DP_DS_PORT_TYPE_VGA ||
4220 type == DP_DS_PORT_TYPE_NON_EDID)
4221 return connector_status_unknown;
4222 } else {
4223 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4224 DP_DWN_STRM_PORT_TYPE_MASK;
4225 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4226 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4227 return connector_status_unknown;
4228 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004229
4230 /* Anything else is out of spec, warn and ignore */
4231 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004232 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004233}
4234
4235static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004236edp_detect(struct intel_dp *intel_dp)
4237{
4238 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4239 enum drm_connector_status status;
4240
4241 status = intel_panel_detect(dev);
4242 if (status == connector_status_unknown)
4243 status = connector_status_connected;
4244
4245 return status;
4246}
4247
4248static enum drm_connector_status
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004249ironlake_dp_detect(struct intel_dp *intel_dp)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004250{
Paulo Zanoni30add222012-10-26 19:05:45 -02004251 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Damien Lespiau1b469632012-12-13 16:09:01 +00004252 struct drm_i915_private *dev_priv = dev->dev_private;
4253 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004254
Damien Lespiau1b469632012-12-13 16:09:01 +00004255 if (!ibx_digital_port_connected(dev_priv, intel_dig_port))
4256 return connector_status_disconnected;
4257
Keith Packard26d61aa2011-07-25 20:01:09 -07004258 return intel_dp_detect_dpcd(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004259}
4260
Dave Airlie2a592be2014-09-01 16:58:12 +10004261static int g4x_digital_port_connected(struct drm_device *dev,
4262 struct intel_digital_port *intel_dig_port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004263{
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004264 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson10f76a32012-05-11 18:01:32 +01004265 uint32_t bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004266
Todd Previte232a6ee2014-01-23 00:13:41 -07004267 if (IS_VALLEYVIEW(dev)) {
4268 switch (intel_dig_port->port) {
4269 case PORT_B:
4270 bit = PORTB_HOTPLUG_LIVE_STATUS_VLV;
4271 break;
4272 case PORT_C:
4273 bit = PORTC_HOTPLUG_LIVE_STATUS_VLV;
4274 break;
4275 case PORT_D:
4276 bit = PORTD_HOTPLUG_LIVE_STATUS_VLV;
4277 break;
4278 default:
Dave Airlie2a592be2014-09-01 16:58:12 +10004279 return -EINVAL;
Todd Previte232a6ee2014-01-23 00:13:41 -07004280 }
4281 } else {
4282 switch (intel_dig_port->port) {
4283 case PORT_B:
4284 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4285 break;
4286 case PORT_C:
4287 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4288 break;
4289 case PORT_D:
4290 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4291 break;
4292 default:
Dave Airlie2a592be2014-09-01 16:58:12 +10004293 return -EINVAL;
Todd Previte232a6ee2014-01-23 00:13:41 -07004294 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004295 }
4296
Chris Wilson10f76a32012-05-11 18:01:32 +01004297 if ((I915_READ(PORT_HOTPLUG_STAT) & bit) == 0)
Dave Airlie2a592be2014-09-01 16:58:12 +10004298 return 0;
4299 return 1;
4300}
4301
4302static enum drm_connector_status
4303g4x_dp_detect(struct intel_dp *intel_dp)
4304{
4305 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4306 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4307 int ret;
4308
4309 /* Can't disconnect eDP, but you can close the lid... */
4310 if (is_edp(intel_dp)) {
4311 enum drm_connector_status status;
4312
4313 status = intel_panel_detect(dev);
4314 if (status == connector_status_unknown)
4315 status = connector_status_connected;
4316 return status;
4317 }
4318
4319 ret = g4x_digital_port_connected(dev, intel_dig_port);
4320 if (ret == -EINVAL)
4321 return connector_status_unknown;
4322 else if (ret == 0)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004323 return connector_status_disconnected;
4324
Keith Packard26d61aa2011-07-25 20:01:09 -07004325 return intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004326}
4327
Keith Packard8c241fe2011-09-28 16:38:44 -07004328static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004329intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004330{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004331 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004332
Jani Nikula9cd300e2012-10-19 14:51:52 +03004333 /* use cached edid if we have one */
4334 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004335 /* invalid edid */
4336 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004337 return NULL;
4338
Jani Nikula55e9ede2013-10-01 10:38:54 +03004339 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004340 } else
4341 return drm_get_edid(&intel_connector->base,
4342 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004343}
4344
Chris Wilsonbeb60602014-09-02 20:04:00 +01004345static void
4346intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004347{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004348 struct intel_connector *intel_connector = intel_dp->attached_connector;
4349 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004350
Chris Wilsonbeb60602014-09-02 20:04:00 +01004351 edid = intel_dp_get_edid(intel_dp);
4352 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004353
Chris Wilsonbeb60602014-09-02 20:04:00 +01004354 if (intel_dp->force_audio != HDMI_AUDIO_AUTO)
4355 intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON;
4356 else
4357 intel_dp->has_audio = drm_detect_monitor_audio(edid);
4358}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004359
Chris Wilsonbeb60602014-09-02 20:04:00 +01004360static void
4361intel_dp_unset_edid(struct intel_dp *intel_dp)
4362{
4363 struct intel_connector *intel_connector = intel_dp->attached_connector;
4364
4365 kfree(intel_connector->detect_edid);
4366 intel_connector->detect_edid = NULL;
4367
4368 intel_dp->has_audio = false;
4369}
4370
4371static enum intel_display_power_domain
4372intel_dp_power_get(struct intel_dp *dp)
4373{
4374 struct intel_encoder *encoder = &dp_to_dig_port(dp)->base;
4375 enum intel_display_power_domain power_domain;
4376
4377 power_domain = intel_display_port_power_domain(encoder);
4378 intel_display_power_get(to_i915(encoder->base.dev), power_domain);
4379
4380 return power_domain;
4381}
4382
4383static void
4384intel_dp_power_put(struct intel_dp *dp,
4385 enum intel_display_power_domain power_domain)
4386{
4387 struct intel_encoder *encoder = &dp_to_dig_port(dp)->base;
4388 intel_display_power_put(to_i915(encoder->base.dev), power_domain);
Keith Packard8c241fe2011-09-28 16:38:44 -07004389}
4390
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004391static enum drm_connector_status
4392intel_dp_detect(struct drm_connector *connector, bool force)
4393{
4394 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004395 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4396 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004397 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004398 enum drm_connector_status status;
Imre Deak671dedd2014-03-05 16:20:53 +02004399 enum intel_display_power_domain power_domain;
Dave Airlie0e32b392014-05-02 14:02:48 +10004400 bool ret;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004401
Chris Wilson164c8592013-07-20 20:27:08 +01004402 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03004403 connector->base.id, connector->name);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004404 intel_dp_unset_edid(intel_dp);
Chris Wilson164c8592013-07-20 20:27:08 +01004405
Dave Airlie0e32b392014-05-02 14:02:48 +10004406 if (intel_dp->is_mst) {
4407 /* MST devices are disconnected from a monitor POV */
4408 if (intel_encoder->type != INTEL_OUTPUT_EDP)
4409 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004410 return connector_status_disconnected;
Dave Airlie0e32b392014-05-02 14:02:48 +10004411 }
4412
Chris Wilsonbeb60602014-09-02 20:04:00 +01004413 power_domain = intel_dp_power_get(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004414
Chris Wilsond410b562014-09-02 20:03:59 +01004415 /* Can't disconnect eDP, but you can close the lid... */
4416 if (is_edp(intel_dp))
4417 status = edp_detect(intel_dp);
4418 else if (HAS_PCH_SPLIT(dev))
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004419 status = ironlake_dp_detect(intel_dp);
4420 else
4421 status = g4x_dp_detect(intel_dp);
4422 if (status != connector_status_connected)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004423 goto out;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004424
Adam Jackson0d198322012-05-14 16:05:47 -04004425 intel_dp_probe_oui(intel_dp);
4426
Dave Airlie0e32b392014-05-02 14:02:48 +10004427 ret = intel_dp_probe_mst(intel_dp);
4428 if (ret) {
4429 /* if we are in MST mode then this connector
4430 won't appear connected or have anything with EDID on it */
4431 if (intel_encoder->type != INTEL_OUTPUT_EDP)
4432 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
4433 status = connector_status_disconnected;
4434 goto out;
4435 }
4436
Chris Wilsonbeb60602014-09-02 20:04:00 +01004437 intel_dp_set_edid(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004438
Paulo Zanonid63885d2012-10-26 19:05:49 -02004439 if (intel_encoder->type != INTEL_OUTPUT_EDP)
4440 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004441 status = connector_status_connected;
4442
4443out:
Chris Wilsonbeb60602014-09-02 20:04:00 +01004444 intel_dp_power_put(intel_dp, power_domain);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004445 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004446}
4447
Chris Wilsonbeb60602014-09-02 20:04:00 +01004448static void
4449intel_dp_force(struct drm_connector *connector)
4450{
4451 struct intel_dp *intel_dp = intel_attached_dp(connector);
4452 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4453 enum intel_display_power_domain power_domain;
4454
4455 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4456 connector->base.id, connector->name);
4457 intel_dp_unset_edid(intel_dp);
4458
4459 if (connector->status != connector_status_connected)
4460 return;
4461
4462 power_domain = intel_dp_power_get(intel_dp);
4463
4464 intel_dp_set_edid(intel_dp);
4465
4466 intel_dp_power_put(intel_dp, power_domain);
4467
4468 if (intel_encoder->type != INTEL_OUTPUT_EDP)
4469 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
4470}
4471
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004472static int intel_dp_get_modes(struct drm_connector *connector)
4473{
Jani Nikuladd06f902012-10-19 14:51:50 +03004474 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004475 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004476
Chris Wilsonbeb60602014-09-02 20:04:00 +01004477 edid = intel_connector->detect_edid;
4478 if (edid) {
4479 int ret = intel_connector_update_modes(connector, edid);
4480 if (ret)
4481 return ret;
4482 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004483
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004484 /* if eDP has no EDID, fall back to fixed mode */
Chris Wilsonbeb60602014-09-02 20:04:00 +01004485 if (is_edp(intel_attached_dp(connector)) &&
4486 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004487 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004488
4489 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004490 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004491 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004492 drm_mode_probed_add(connector, mode);
4493 return 1;
4494 }
4495 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004496
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004497 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004498}
4499
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004500static bool
4501intel_dp_detect_audio(struct drm_connector *connector)
4502{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004503 bool has_audio = false;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004504 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004505
Chris Wilsonbeb60602014-09-02 20:04:00 +01004506 edid = to_intel_connector(connector)->detect_edid;
4507 if (edid)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004508 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02004509
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004510 return has_audio;
4511}
4512
Chris Wilsonf6849602010-09-19 09:29:33 +01004513static int
4514intel_dp_set_property(struct drm_connector *connector,
4515 struct drm_property *property,
4516 uint64_t val)
4517{
Chris Wilsone953fd72011-02-21 22:23:52 +00004518 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Yuly Novikov53b41832012-10-26 12:04:00 +03004519 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004520 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
4521 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01004522 int ret;
4523
Rob Clark662595d2012-10-11 20:36:04 -05004524 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01004525 if (ret)
4526 return ret;
4527
Chris Wilson3f43c482011-05-12 22:17:24 +01004528 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004529 int i = val;
4530 bool has_audio;
4531
4532 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004533 return 0;
4534
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004535 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01004536
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004537 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004538 has_audio = intel_dp_detect_audio(connector);
4539 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004540 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004541
4542 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004543 return 0;
4544
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004545 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01004546 goto done;
4547 }
4548
Chris Wilsone953fd72011-02-21 22:23:52 +00004549 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02004550 bool old_auto = intel_dp->color_range_auto;
4551 uint32_t old_range = intel_dp->color_range;
4552
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004553 switch (val) {
4554 case INTEL_BROADCAST_RGB_AUTO:
4555 intel_dp->color_range_auto = true;
4556 break;
4557 case INTEL_BROADCAST_RGB_FULL:
4558 intel_dp->color_range_auto = false;
4559 intel_dp->color_range = 0;
4560 break;
4561 case INTEL_BROADCAST_RGB_LIMITED:
4562 intel_dp->color_range_auto = false;
4563 intel_dp->color_range = DP_COLOR_RANGE_16_235;
4564 break;
4565 default:
4566 return -EINVAL;
4567 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02004568
4569 if (old_auto == intel_dp->color_range_auto &&
4570 old_range == intel_dp->color_range)
4571 return 0;
4572
Chris Wilsone953fd72011-02-21 22:23:52 +00004573 goto done;
4574 }
4575
Yuly Novikov53b41832012-10-26 12:04:00 +03004576 if (is_edp(intel_dp) &&
4577 property == connector->dev->mode_config.scaling_mode_property) {
4578 if (val == DRM_MODE_SCALE_NONE) {
4579 DRM_DEBUG_KMS("no scaling not supported\n");
4580 return -EINVAL;
4581 }
4582
4583 if (intel_connector->panel.fitting_mode == val) {
4584 /* the eDP scaling property is not changed */
4585 return 0;
4586 }
4587 intel_connector->panel.fitting_mode = val;
4588
4589 goto done;
4590 }
4591
Chris Wilsonf6849602010-09-19 09:29:33 +01004592 return -EINVAL;
4593
4594done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00004595 if (intel_encoder->base.crtc)
4596 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01004597
4598 return 0;
4599}
4600
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004601static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004602intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004603{
Jani Nikula1d508702012-10-19 14:51:49 +03004604 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004605
Chris Wilson10e972d2014-09-04 21:43:45 +01004606 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004607
Jani Nikula9cd300e2012-10-19 14:51:52 +03004608 if (!IS_ERR_OR_NULL(intel_connector->edid))
4609 kfree(intel_connector->edid);
4610
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004611 /* Can't call is_edp() since the encoder may have been destroyed
4612 * already. */
4613 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004614 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004615
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004616 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004617 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004618}
4619
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004620void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004621{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004622 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4623 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004624
Dave Airlie4f71d0c2014-06-04 16:02:28 +10004625 drm_dp_aux_unregister(&intel_dp->aux);
Dave Airlie0e32b392014-05-02 14:02:48 +10004626 intel_dp_mst_encoder_cleanup(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004627 drm_encoder_cleanup(encoder);
Keith Packardbd943152011-09-18 23:09:52 -07004628 if (is_edp(intel_dp)) {
4629 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004630 /*
4631 * vdd might still be enabled do to the delayed vdd off.
4632 * Make sure vdd is actually turned off here.
4633 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004634 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004635 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004636 pps_unlock(intel_dp);
4637
Clint Taylor01527b32014-07-07 13:01:46 -07004638 if (intel_dp->edp_notifier.notifier_call) {
4639 unregister_reboot_notifier(&intel_dp->edp_notifier);
4640 intel_dp->edp_notifier.notifier_call = NULL;
4641 }
Keith Packardbd943152011-09-18 23:09:52 -07004642 }
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004643 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004644}
4645
Imre Deak07f9cd02014-08-18 14:42:45 +03004646static void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
4647{
4648 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4649
4650 if (!is_edp(intel_dp))
4651 return;
4652
Ville Syrjälä951468f2014-09-04 14:55:31 +03004653 /*
4654 * vdd might still be enabled do to the delayed vdd off.
4655 * Make sure vdd is actually turned off here.
4656 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004657 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004658 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004659 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004660}
4661
Imre Deak6d93c0c2014-07-31 14:03:36 +03004662static void intel_dp_encoder_reset(struct drm_encoder *encoder)
4663{
4664 intel_edp_panel_vdd_sanitize(to_intel_encoder(encoder));
4665}
4666
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004667static const struct drm_connector_funcs intel_dp_connector_funcs = {
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02004668 .dpms = intel_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004669 .detect = intel_dp_detect,
Chris Wilsonbeb60602014-09-02 20:04:00 +01004670 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004671 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01004672 .set_property = intel_dp_set_property,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004673 .destroy = intel_dp_connector_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004674};
4675
4676static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
4677 .get_modes = intel_dp_get_modes,
4678 .mode_valid = intel_dp_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +01004679 .best_encoder = intel_best_encoder,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004680};
4681
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004682static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03004683 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02004684 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004685};
4686
Dave Airlie0e32b392014-05-02 14:02:48 +10004687void
Eric Anholt21d40d32010-03-25 11:11:14 -07004688intel_dp_hot_plug(struct intel_encoder *intel_encoder)
Keith Packardc8110e52009-05-06 11:51:10 -07004689{
Dave Airlie0e32b392014-05-02 14:02:48 +10004690 return;
Keith Packardc8110e52009-05-06 11:51:10 -07004691}
4692
Dave Airlie13cf5502014-06-18 11:29:35 +10004693bool
4694intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
4695{
4696 struct intel_dp *intel_dp = &intel_dig_port->dp;
Imre Deak1c767b32014-08-18 14:42:42 +03004697 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Dave Airlie0e32b392014-05-02 14:02:48 +10004698 struct drm_device *dev = intel_dig_port->base.base.dev;
4699 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deak1c767b32014-08-18 14:42:42 +03004700 enum intel_display_power_domain power_domain;
4701 bool ret = true;
4702
Dave Airlie0e32b392014-05-02 14:02:48 +10004703 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP)
4704 intel_dig_port->base.type = INTEL_OUTPUT_DISPLAYPORT;
Dave Airlie13cf5502014-06-18 11:29:35 +10004705
Ville Syrjälä26fbb772014-08-11 18:37:37 +03004706 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
4707 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10004708 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10004709
Imre Deak1c767b32014-08-18 14:42:42 +03004710 power_domain = intel_display_port_power_domain(intel_encoder);
4711 intel_display_power_get(dev_priv, power_domain);
4712
Dave Airlie0e32b392014-05-02 14:02:48 +10004713 if (long_hpd) {
Dave Airlie2a592be2014-09-01 16:58:12 +10004714
4715 if (HAS_PCH_SPLIT(dev)) {
4716 if (!ibx_digital_port_connected(dev_priv, intel_dig_port))
4717 goto mst_fail;
4718 } else {
4719 if (g4x_digital_port_connected(dev, intel_dig_port) != 1)
4720 goto mst_fail;
4721 }
Dave Airlie0e32b392014-05-02 14:02:48 +10004722
4723 if (!intel_dp_get_dpcd(intel_dp)) {
4724 goto mst_fail;
4725 }
4726
4727 intel_dp_probe_oui(intel_dp);
4728
4729 if (!intel_dp_probe_mst(intel_dp))
4730 goto mst_fail;
4731
4732 } else {
4733 if (intel_dp->is_mst) {
Imre Deak1c767b32014-08-18 14:42:42 +03004734 if (intel_dp_check_mst_status(intel_dp) == -EINVAL)
Dave Airlie0e32b392014-05-02 14:02:48 +10004735 goto mst_fail;
4736 }
4737
4738 if (!intel_dp->is_mst) {
4739 /*
4740 * we'll check the link status via the normal hot plug path later -
4741 * but for short hpds we should check it now
4742 */
Dave Airlie5b215bc2014-08-05 10:40:20 +10004743 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
Dave Airlie0e32b392014-05-02 14:02:48 +10004744 intel_dp_check_link_status(intel_dp);
Dave Airlie5b215bc2014-08-05 10:40:20 +10004745 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Dave Airlie0e32b392014-05-02 14:02:48 +10004746 }
4747 }
Imre Deak1c767b32014-08-18 14:42:42 +03004748 ret = false;
4749 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10004750mst_fail:
4751 /* if we were in MST mode, and device is not there get out of MST mode */
4752 if (intel_dp->is_mst) {
4753 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n", intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
4754 intel_dp->is_mst = false;
4755 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4756 }
Imre Deak1c767b32014-08-18 14:42:42 +03004757put_power:
4758 intel_display_power_put(dev_priv, power_domain);
4759
4760 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10004761}
4762
Zhenyu Wange3421a12010-04-08 09:43:27 +08004763/* Return which DP Port should be selected for Transcoder DP control */
4764int
Akshay Joshi0206e352011-08-16 15:34:10 -04004765intel_trans_dp_port_sel(struct drm_crtc *crtc)
Zhenyu Wange3421a12010-04-08 09:43:27 +08004766{
4767 struct drm_device *dev = crtc->dev;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004768 struct intel_encoder *intel_encoder;
4769 struct intel_dp *intel_dp;
Zhenyu Wange3421a12010-04-08 09:43:27 +08004770
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004771 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
4772 intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonea5b2132010-08-04 13:50:23 +01004773
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004774 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
4775 intel_encoder->type == INTEL_OUTPUT_EDP)
Chris Wilsonea5b2132010-08-04 13:50:23 +01004776 return intel_dp->output_reg;
Zhenyu Wange3421a12010-04-08 09:43:27 +08004777 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01004778
Zhenyu Wange3421a12010-04-08 09:43:27 +08004779 return -1;
4780}
4781
Zhao Yakui36e83a12010-06-12 14:32:21 +08004782/* check the VBT to see whether the eDP is on DP-D port */
Ville Syrjälä5d8a7752013-11-01 18:22:39 +02004783bool intel_dp_is_edp(struct drm_device *dev, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08004784{
4785 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni768f69c2013-09-11 18:02:47 -03004786 union child_device_config *p_child;
Zhao Yakui36e83a12010-06-12 14:32:21 +08004787 int i;
Ville Syrjälä5d8a7752013-11-01 18:22:39 +02004788 static const short port_mapping[] = {
4789 [PORT_B] = PORT_IDPB,
4790 [PORT_C] = PORT_IDPC,
4791 [PORT_D] = PORT_IDPD,
4792 };
Zhao Yakui36e83a12010-06-12 14:32:21 +08004793
Ville Syrjälä3b32a352013-11-01 18:22:41 +02004794 if (port == PORT_A)
4795 return true;
4796
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03004797 if (!dev_priv->vbt.child_dev_num)
Zhao Yakui36e83a12010-06-12 14:32:21 +08004798 return false;
4799
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03004800 for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
4801 p_child = dev_priv->vbt.child_dev + i;
Zhao Yakui36e83a12010-06-12 14:32:21 +08004802
Ville Syrjälä5d8a7752013-11-01 18:22:39 +02004803 if (p_child->common.dvo_port == port_mapping[port] &&
Ville Syrjäläf02586d2013-11-01 20:32:08 +02004804 (p_child->common.device_type & DEVICE_TYPE_eDP_BITS) ==
4805 (DEVICE_TYPE_eDP & DEVICE_TYPE_eDP_BITS))
Zhao Yakui36e83a12010-06-12 14:32:21 +08004806 return true;
4807 }
4808 return false;
4809}
4810
Dave Airlie0e32b392014-05-02 14:02:48 +10004811void
Chris Wilsonf6849602010-09-19 09:29:33 +01004812intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
4813{
Yuly Novikov53b41832012-10-26 12:04:00 +03004814 struct intel_connector *intel_connector = to_intel_connector(connector);
4815
Chris Wilson3f43c482011-05-12 22:17:24 +01004816 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00004817 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004818 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03004819
4820 if (is_edp(intel_dp)) {
4821 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05004822 drm_object_attach_property(
4823 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03004824 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03004825 DRM_MODE_SCALE_ASPECT);
4826 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03004827 }
Chris Wilsonf6849602010-09-19 09:29:33 +01004828}
4829
Imre Deakdada1a92014-01-29 13:25:41 +02004830static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
4831{
4832 intel_dp->last_power_cycle = jiffies;
4833 intel_dp->last_power_on = jiffies;
4834 intel_dp->last_backlight_off = jiffies;
4835}
4836
Daniel Vetter67a54562012-10-20 20:57:45 +02004837static void
4838intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03004839 struct intel_dp *intel_dp)
Daniel Vetter67a54562012-10-20 20:57:45 +02004840{
4841 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03004842 struct edp_power_seq cur, vbt, spec,
4843 *final = &intel_dp->pps_delays;
Daniel Vetter67a54562012-10-20 20:57:45 +02004844 u32 pp_on, pp_off, pp_div, pp;
Jani Nikulabf13e812013-09-06 07:40:05 +03004845 int pp_ctrl_reg, pp_on_reg, pp_off_reg, pp_div_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07004846
Ville Syrjäläe39b9992014-09-04 14:53:14 +03004847 lockdep_assert_held(&dev_priv->pps_mutex);
4848
Ville Syrjälä81ddbc62014-10-16 21:27:31 +03004849 /* already initialized? */
4850 if (final->t11_t12 != 0)
4851 return;
4852
Jesse Barnes453c5422013-03-28 09:55:41 -07004853 if (HAS_PCH_SPLIT(dev)) {
Jani Nikulabf13e812013-09-06 07:40:05 +03004854 pp_ctrl_reg = PCH_PP_CONTROL;
Jesse Barnes453c5422013-03-28 09:55:41 -07004855 pp_on_reg = PCH_PP_ON_DELAYS;
4856 pp_off_reg = PCH_PP_OFF_DELAYS;
4857 pp_div_reg = PCH_PP_DIVISOR;
4858 } else {
Jani Nikulabf13e812013-09-06 07:40:05 +03004859 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
4860
4861 pp_ctrl_reg = VLV_PIPE_PP_CONTROL(pipe);
4862 pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe);
4863 pp_off_reg = VLV_PIPE_PP_OFF_DELAYS(pipe);
4864 pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe);
Jesse Barnes453c5422013-03-28 09:55:41 -07004865 }
Daniel Vetter67a54562012-10-20 20:57:45 +02004866
4867 /* Workaround: Need to write PP_CONTROL with the unlock key as
4868 * the very first thing. */
Jesse Barnes453c5422013-03-28 09:55:41 -07004869 pp = ironlake_get_pp_control(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +03004870 I915_WRITE(pp_ctrl_reg, pp);
Daniel Vetter67a54562012-10-20 20:57:45 +02004871
Jesse Barnes453c5422013-03-28 09:55:41 -07004872 pp_on = I915_READ(pp_on_reg);
4873 pp_off = I915_READ(pp_off_reg);
4874 pp_div = I915_READ(pp_div_reg);
Daniel Vetter67a54562012-10-20 20:57:45 +02004875
4876 /* Pull timing values out of registers */
4877 cur.t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
4878 PANEL_POWER_UP_DELAY_SHIFT;
4879
4880 cur.t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
4881 PANEL_LIGHT_ON_DELAY_SHIFT;
4882
4883 cur.t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
4884 PANEL_LIGHT_OFF_DELAY_SHIFT;
4885
4886 cur.t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
4887 PANEL_POWER_DOWN_DELAY_SHIFT;
4888
4889 cur.t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
4890 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
4891
4892 DRM_DEBUG_KMS("cur t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
4893 cur.t1_t3, cur.t8, cur.t9, cur.t10, cur.t11_t12);
4894
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03004895 vbt = dev_priv->vbt.edp_pps;
Daniel Vetter67a54562012-10-20 20:57:45 +02004896
4897 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
4898 * our hw here, which are all in 100usec. */
4899 spec.t1_t3 = 210 * 10;
4900 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
4901 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
4902 spec.t10 = 500 * 10;
4903 /* This one is special and actually in units of 100ms, but zero
4904 * based in the hw (so we need to add 100 ms). But the sw vbt
4905 * table multiplies it with 1000 to make it in units of 100usec,
4906 * too. */
4907 spec.t11_t12 = (510 + 100) * 10;
4908
4909 DRM_DEBUG_KMS("vbt t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
4910 vbt.t1_t3, vbt.t8, vbt.t9, vbt.t10, vbt.t11_t12);
4911
4912 /* Use the max of the register settings and vbt. If both are
4913 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03004914#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02004915 spec.field : \
4916 max(cur.field, vbt.field))
4917 assign_final(t1_t3);
4918 assign_final(t8);
4919 assign_final(t9);
4920 assign_final(t10);
4921 assign_final(t11_t12);
4922#undef assign_final
4923
Ville Syrjälä36b5f422014-10-16 21:27:30 +03004924#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02004925 intel_dp->panel_power_up_delay = get_delay(t1_t3);
4926 intel_dp->backlight_on_delay = get_delay(t8);
4927 intel_dp->backlight_off_delay = get_delay(t9);
4928 intel_dp->panel_power_down_delay = get_delay(t10);
4929 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
4930#undef get_delay
4931
Jani Nikulaf30d26e2013-01-16 10:53:40 +02004932 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
4933 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
4934 intel_dp->panel_power_cycle_delay);
4935
4936 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
4937 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Jani Nikulaf30d26e2013-01-16 10:53:40 +02004938}
4939
4940static void
4941intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03004942 struct intel_dp *intel_dp)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02004943{
4944 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes453c5422013-03-28 09:55:41 -07004945 u32 pp_on, pp_off, pp_div, port_sel = 0;
4946 int div = HAS_PCH_SPLIT(dev) ? intel_pch_rawclk(dev) : intel_hrawclk(dev);
4947 int pp_on_reg, pp_off_reg, pp_div_reg;
Ville Syrjäläad933b52014-08-18 22:15:56 +03004948 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03004949 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07004950
Ville Syrjäläe39b9992014-09-04 14:53:14 +03004951 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07004952
4953 if (HAS_PCH_SPLIT(dev)) {
4954 pp_on_reg = PCH_PP_ON_DELAYS;
4955 pp_off_reg = PCH_PP_OFF_DELAYS;
4956 pp_div_reg = PCH_PP_DIVISOR;
4957 } else {
Jani Nikulabf13e812013-09-06 07:40:05 +03004958 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
4959
4960 pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe);
4961 pp_off_reg = VLV_PIPE_PP_OFF_DELAYS(pipe);
4962 pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe);
Jesse Barnes453c5422013-03-28 09:55:41 -07004963 }
4964
Paulo Zanonib2f19d12013-12-19 14:29:44 -02004965 /*
4966 * And finally store the new values in the power sequencer. The
4967 * backlight delays are set to 1 because we do manual waits on them. For
4968 * T8, even BSpec recommends doing it. For T9, if we don't do this,
4969 * we'll end up waiting for the backlight off delay twice: once when we
4970 * do the manual sleep, and once when we disable the panel and wait for
4971 * the PP_STATUS bit to become zero.
4972 */
Jani Nikulaf30d26e2013-01-16 10:53:40 +02004973 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Paulo Zanonib2f19d12013-12-19 14:29:44 -02004974 (1 << PANEL_LIGHT_ON_DELAY_SHIFT);
4975 pp_off = (1 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02004976 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02004977 /* Compute the divisor for the pp clock, simply match the Bspec
4978 * formula. */
Jesse Barnes453c5422013-03-28 09:55:41 -07004979 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02004980 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
Daniel Vetter67a54562012-10-20 20:57:45 +02004981 << PANEL_POWER_CYCLE_DELAY_SHIFT);
4982
4983 /* Haswell doesn't have any port selection bits for the panel
4984 * power sequencer any more. */
Imre Deakbc7d38a2013-05-16 14:40:36 +03004985 if (IS_VALLEYVIEW(dev)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03004986 port_sel = PANEL_PORT_SELECT_VLV(port);
Imre Deakbc7d38a2013-05-16 14:40:36 +03004987 } else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03004988 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03004989 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02004990 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03004991 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02004992 }
4993
Jesse Barnes453c5422013-03-28 09:55:41 -07004994 pp_on |= port_sel;
4995
4996 I915_WRITE(pp_on_reg, pp_on);
4997 I915_WRITE(pp_off_reg, pp_off);
4998 I915_WRITE(pp_div_reg, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02004999
Daniel Vetter67a54562012-10-20 20:57:45 +02005000 DRM_DEBUG_KMS("panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07005001 I915_READ(pp_on_reg),
5002 I915_READ(pp_off_reg),
5003 I915_READ(pp_div_reg));
Keith Packardc8110e52009-05-06 11:51:10 -07005004}
5005
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305006void intel_dp_set_drrs_state(struct drm_device *dev, int refresh_rate)
5007{
5008 struct drm_i915_private *dev_priv = dev->dev_private;
5009 struct intel_encoder *encoder;
5010 struct intel_dp *intel_dp = NULL;
5011 struct intel_crtc_config *config = NULL;
5012 struct intel_crtc *intel_crtc = NULL;
5013 struct intel_connector *intel_connector = dev_priv->drrs.connector;
5014 u32 reg, val;
5015 enum edp_drrs_refresh_rate_type index = DRRS_HIGH_RR;
5016
5017 if (refresh_rate <= 0) {
5018 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5019 return;
5020 }
5021
5022 if (intel_connector == NULL) {
5023 DRM_DEBUG_KMS("DRRS supported for eDP only.\n");
5024 return;
5025 }
5026
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005027 /*
5028 * FIXME: This needs proper synchronization with psr state. But really
5029 * hard to tell without seeing the user of this function of this code.
5030 * Check locking and ordering once that lands.
5031 */
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305032 if (INTEL_INFO(dev)->gen < 8 && intel_edp_is_psr_enabled(dev)) {
5033 DRM_DEBUG_KMS("DRRS is disabled as PSR is enabled\n");
5034 return;
5035 }
5036
5037 encoder = intel_attached_encoder(&intel_connector->base);
5038 intel_dp = enc_to_intel_dp(&encoder->base);
5039 intel_crtc = encoder->new_crtc;
5040
5041 if (!intel_crtc) {
5042 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5043 return;
5044 }
5045
5046 config = &intel_crtc->config;
5047
5048 if (intel_dp->drrs_state.type < SEAMLESS_DRRS_SUPPORT) {
5049 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5050 return;
5051 }
5052
5053 if (intel_connector->panel.downclock_mode->vrefresh == refresh_rate)
5054 index = DRRS_LOW_RR;
5055
5056 if (index == intel_dp->drrs_state.refresh_rate_type) {
5057 DRM_DEBUG_KMS(
5058 "DRRS requested for previously set RR...ignoring\n");
5059 return;
5060 }
5061
5062 if (!intel_crtc->active) {
5063 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5064 return;
5065 }
5066
5067 if (INTEL_INFO(dev)->gen > 6 && INTEL_INFO(dev)->gen < 8) {
5068 reg = PIPECONF(intel_crtc->config.cpu_transcoder);
5069 val = I915_READ(reg);
5070 if (index > DRRS_HIGH_RR) {
5071 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Vandana Kannanf769cd22014-08-05 07:51:22 -07005072 intel_dp_set_m_n(intel_crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305073 } else {
5074 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
5075 }
5076 I915_WRITE(reg, val);
5077 }
5078
5079 /*
5080 * mutex taken to ensure that there is no race between differnt
5081 * drrs calls trying to update refresh rate. This scenario may occur
5082 * in future when idleness detection based DRRS in kernel and
5083 * possible calls from user space to set differnt RR are made.
5084 */
5085
5086 mutex_lock(&intel_dp->drrs_state.mutex);
5087
5088 intel_dp->drrs_state.refresh_rate_type = index;
5089
5090 mutex_unlock(&intel_dp->drrs_state.mutex);
5091
5092 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5093}
5094
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305095static struct drm_display_mode *
5096intel_dp_drrs_init(struct intel_digital_port *intel_dig_port,
5097 struct intel_connector *intel_connector,
5098 struct drm_display_mode *fixed_mode)
5099{
5100 struct drm_connector *connector = &intel_connector->base;
5101 struct intel_dp *intel_dp = &intel_dig_port->dp;
5102 struct drm_device *dev = intel_dig_port->base.base.dev;
5103 struct drm_i915_private *dev_priv = dev->dev_private;
5104 struct drm_display_mode *downclock_mode = NULL;
5105
5106 if (INTEL_INFO(dev)->gen <= 6) {
5107 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5108 return NULL;
5109 }
5110
5111 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005112 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305113 return NULL;
5114 }
5115
5116 downclock_mode = intel_find_panel_downclock
5117 (dev, fixed_mode, connector);
5118
5119 if (!downclock_mode) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005120 DRM_DEBUG_KMS("DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305121 return NULL;
5122 }
5123
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305124 dev_priv->drrs.connector = intel_connector;
5125
5126 mutex_init(&intel_dp->drrs_state.mutex);
5127
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305128 intel_dp->drrs_state.type = dev_priv->vbt.drrs_type;
5129
5130 intel_dp->drrs_state.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005131 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305132 return downclock_mode;
5133}
5134
Imre Deakaba86892014-07-30 15:57:31 +03005135void intel_edp_panel_vdd_sanitize(struct intel_encoder *intel_encoder)
5136{
5137 struct drm_device *dev = intel_encoder->base.dev;
5138 struct drm_i915_private *dev_priv = dev->dev_private;
5139 struct intel_dp *intel_dp;
5140 enum intel_display_power_domain power_domain;
5141
5142 if (intel_encoder->type != INTEL_OUTPUT_EDP)
5143 return;
5144
5145 intel_dp = enc_to_intel_dp(&intel_encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03005146
5147 pps_lock(intel_dp);
5148
Imre Deakaba86892014-07-30 15:57:31 +03005149 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005150 goto out;
Imre Deakaba86892014-07-30 15:57:31 +03005151 /*
5152 * The VDD bit needs a power domain reference, so if the bit is
5153 * already enabled when we boot or resume, grab this reference and
5154 * schedule a vdd off, so we don't hold on to the reference
5155 * indefinitely.
5156 */
5157 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
5158 power_domain = intel_display_port_power_domain(intel_encoder);
5159 intel_display_power_get(dev_priv, power_domain);
5160
5161 edp_panel_vdd_schedule_off(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005162 out:
Ville Syrjälä773538e82014-09-04 14:54:56 +03005163 pps_unlock(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03005164}
5165
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005166static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005167 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005168{
5169 struct drm_connector *connector = &intel_connector->base;
5170 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005171 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5172 struct drm_device *dev = intel_encoder->base.dev;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005173 struct drm_i915_private *dev_priv = dev->dev_private;
5174 struct drm_display_mode *fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305175 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005176 bool has_dpcd;
5177 struct drm_display_mode *scan;
5178 struct edid *edid;
5179
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305180 intel_dp->drrs_state.type = DRRS_NOT_SUPPORTED;
5181
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005182 if (!is_edp(intel_dp))
5183 return true;
5184
Imre Deakaba86892014-07-30 15:57:31 +03005185 intel_edp_panel_vdd_sanitize(intel_encoder);
Paulo Zanoni63635212014-04-22 19:55:42 -03005186
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005187 /* Cache DPCD and EDID for edp. */
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005188 has_dpcd = intel_dp_get_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005189
5190 if (has_dpcd) {
5191 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
5192 dev_priv->no_aux_handshake =
5193 intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
5194 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
5195 } else {
5196 /* if this fails, presume the device is a ghost */
5197 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005198 return false;
5199 }
5200
5201 /* We now know it's not a ghost, init power sequence regs. */
Ville Syrjälä773538e82014-09-04 14:54:56 +03005202 pps_lock(intel_dp);
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005203 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03005204 pps_unlock(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005205
Daniel Vetter060c8772014-03-21 23:22:35 +01005206 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005207 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005208 if (edid) {
5209 if (drm_add_edid_modes(connector, edid)) {
5210 drm_mode_connector_update_edid_property(connector,
5211 edid);
5212 drm_edid_to_eld(connector, edid);
5213 } else {
5214 kfree(edid);
5215 edid = ERR_PTR(-EINVAL);
5216 }
5217 } else {
5218 edid = ERR_PTR(-ENOENT);
5219 }
5220 intel_connector->edid = edid;
5221
5222 /* prefer fixed mode from EDID if available */
5223 list_for_each_entry(scan, &connector->probed_modes, head) {
5224 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5225 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305226 downclock_mode = intel_dp_drrs_init(
5227 intel_dig_port,
5228 intel_connector, fixed_mode);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005229 break;
5230 }
5231 }
5232
5233 /* fallback to VBT if available for eDP */
5234 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5235 fixed_mode = drm_mode_duplicate(dev,
5236 dev_priv->vbt.lfp_lvds_vbt_mode);
5237 if (fixed_mode)
5238 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
5239 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005240 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005241
Clint Taylor01527b32014-07-07 13:01:46 -07005242 if (IS_VALLEYVIEW(dev)) {
5243 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5244 register_reboot_notifier(&intel_dp->edp_notifier);
5245 }
5246
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305247 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
Jani Nikula73580fb72014-08-12 17:11:41 +03005248 intel_connector->panel.backlight_power = intel_edp_backlight_power;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005249 intel_panel_setup_backlight(connector);
5250
5251 return true;
5252}
5253
Paulo Zanoni16c25532013-06-12 17:27:25 -03005254bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005255intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5256 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005257{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005258 struct drm_connector *connector = &intel_connector->base;
5259 struct intel_dp *intel_dp = &intel_dig_port->dp;
5260 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5261 struct drm_device *dev = intel_encoder->base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005262 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -02005263 enum port port = intel_dig_port->port;
Jani Nikula0b998362014-03-14 16:51:17 +02005264 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005265
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005266 intel_dp->pps_pipe = INVALID_PIPE;
5267
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005268 /* intel_dp vfuncs */
Damien Lespiaub6b5e382014-01-20 16:00:59 +00005269 if (INTEL_INFO(dev)->gen >= 9)
5270 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
5271 else if (IS_VALLEYVIEW(dev))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005272 intel_dp->get_aux_clock_divider = vlv_get_aux_clock_divider;
5273 else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
5274 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
5275 else if (HAS_PCH_SPLIT(dev))
5276 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
5277 else
5278 intel_dp->get_aux_clock_divider = i9xx_get_aux_clock_divider;
5279
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00005280 if (INTEL_INFO(dev)->gen >= 9)
5281 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
5282 else
5283 intel_dp->get_aux_send_ctl = i9xx_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00005284
Daniel Vetter07679352012-09-06 22:15:42 +02005285 /* Preserve the current hw state. */
5286 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03005287 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00005288
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005289 if (intel_dp_is_edp(dev, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05305290 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005291 else
5292 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04005293
Imre Deakf7d24902013-05-08 13:14:05 +03005294 /*
5295 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
5296 * for DP the encoder type can be set by the caller to
5297 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
5298 */
5299 if (type == DRM_MODE_CONNECTOR_eDP)
5300 intel_encoder->type = INTEL_OUTPUT_EDP;
5301
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005302 /* eDP only on port B and/or C on vlv/chv */
5303 if (WARN_ON(IS_VALLEYVIEW(dev) && is_edp(intel_dp) &&
5304 port != PORT_B && port != PORT_C))
5305 return false;
5306
Imre Deake7281ea2013-05-08 13:14:08 +03005307 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
5308 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
5309 port_name(port));
5310
Adam Jacksonb3295302010-07-16 14:46:28 -04005311 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005312 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
5313
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005314 connector->interlace_allowed = true;
5315 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08005316
Daniel Vetter66a92782012-07-12 20:08:18 +02005317 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01005318 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08005319
Chris Wilsondf0e9242010-09-09 16:20:55 +01005320 intel_connector_attach_encoder(intel_connector, intel_encoder);
Thomas Wood34ea3d32014-05-29 16:57:41 +01005321 drm_connector_register(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005322
Paulo Zanoniaffa9352012-11-23 15:30:39 -02005323 if (HAS_DDI(dev))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02005324 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
5325 else
5326 intel_connector->get_hw_state = intel_connector_get_hw_state;
Imre Deak80f65de2014-02-11 17:12:49 +02005327 intel_connector->unregister = intel_dp_connector_unregister;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02005328
Jani Nikula0b998362014-03-14 16:51:17 +02005329 /* Set up the hotplug pin. */
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005330 switch (port) {
5331 case PORT_A:
Egbert Eich1d843f92013-02-25 12:06:49 -05005332 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005333 break;
5334 case PORT_B:
Egbert Eich1d843f92013-02-25 12:06:49 -05005335 intel_encoder->hpd_pin = HPD_PORT_B;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005336 break;
5337 case PORT_C:
Egbert Eich1d843f92013-02-25 12:06:49 -05005338 intel_encoder->hpd_pin = HPD_PORT_C;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005339 break;
5340 case PORT_D:
Egbert Eich1d843f92013-02-25 12:06:49 -05005341 intel_encoder->hpd_pin = HPD_PORT_D;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005342 break;
5343 default:
Damien Lespiauad1c0b12013-03-07 15:30:28 +00005344 BUG();
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08005345 }
5346
Imre Deakdada1a92014-01-29 13:25:41 +02005347 if (is_edp(intel_dp)) {
Ville Syrjälä773538e82014-09-04 14:54:56 +03005348 pps_lock(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005349 if (IS_VALLEYVIEW(dev)) {
5350 vlv_initial_power_sequencer_setup(intel_dp);
5351 } else {
5352 intel_dp_init_panel_power_timestamps(intel_dp);
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005353 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005354 }
Ville Syrjälä773538e82014-09-04 14:54:56 +03005355 pps_unlock(intel_dp);
Imre Deakdada1a92014-01-29 13:25:41 +02005356 }
Paulo Zanoni0095e6d2013-12-19 14:29:39 -02005357
Jani Nikula9d1a1032014-03-14 16:51:15 +02005358 intel_dp_aux_init(intel_dp, intel_connector);
Dave Airliec1f05262012-08-30 11:06:18 +10005359
Dave Airlie0e32b392014-05-02 14:02:48 +10005360 /* init MST on ports that can support it */
5361 if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
5362 if (port == PORT_B || port == PORT_C || port == PORT_D) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005363 intel_dp_mst_encoder_init(intel_dig_port,
5364 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10005365 }
5366 }
5367
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005368 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Dave Airlie4f71d0c2014-06-04 16:02:28 +10005369 drm_dp_aux_unregister(&intel_dp->aux);
Paulo Zanoni15b1d172013-06-12 17:27:27 -03005370 if (is_edp(intel_dp)) {
5371 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03005372 /*
5373 * vdd might still be enabled do to the delayed vdd off.
5374 * Make sure vdd is actually turned off here.
5375 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03005376 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01005377 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03005378 pps_unlock(intel_dp);
Paulo Zanoni15b1d172013-06-12 17:27:27 -03005379 }
Thomas Wood34ea3d32014-05-29 16:57:41 +01005380 drm_connector_unregister(connector);
Paulo Zanonib2f246a2013-06-12 17:27:26 -03005381 drm_connector_cleanup(connector);
Paulo Zanoni16c25532013-06-12 17:27:25 -03005382 return false;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03005383 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08005384
Chris Wilsonf6849602010-09-19 09:29:33 +01005385 intel_dp_add_properties(intel_dp, connector);
5386
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005387 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
5388 * 0xd. Failure to do so will result in spurious interrupts being
5389 * generated on the port when a cable is not attached.
5390 */
5391 if (IS_G4X(dev) && !IS_GM45(dev)) {
5392 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
5393 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
5394 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03005395
5396 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005397}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005398
5399void
5400intel_dp_init(struct drm_device *dev, int output_reg, enum port port)
5401{
Dave Airlie13cf5502014-06-18 11:29:35 +10005402 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005403 struct intel_digital_port *intel_dig_port;
5404 struct intel_encoder *intel_encoder;
5405 struct drm_encoder *encoder;
5406 struct intel_connector *intel_connector;
5407
Daniel Vetterb14c5672013-09-19 12:18:32 +02005408 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005409 if (!intel_dig_port)
5410 return;
5411
Daniel Vetterb14c5672013-09-19 12:18:32 +02005412 intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005413 if (!intel_connector) {
5414 kfree(intel_dig_port);
5415 return;
5416 }
5417
5418 intel_encoder = &intel_dig_port->base;
5419 encoder = &intel_encoder->base;
5420
5421 drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
5422 DRM_MODE_ENCODER_TMDS);
5423
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01005424 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005425 intel_encoder->disable = intel_disable_dp;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005426 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07005427 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03005428 intel_encoder->suspend = intel_dp_encoder_suspend;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03005429 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03005430 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03005431 intel_encoder->pre_enable = chv_pre_enable_dp;
5432 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03005433 intel_encoder->post_disable = chv_post_disable_dp;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03005434 } else if (IS_VALLEYVIEW(dev)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03005435 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005436 intel_encoder->pre_enable = vlv_pre_enable_dp;
5437 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03005438 intel_encoder->post_disable = vlv_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005439 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03005440 intel_encoder->pre_enable = g4x_pre_enable_dp;
5441 intel_encoder->enable = g4x_enable_dp;
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03005442 if (INTEL_INFO(dev)->gen >= 5)
5443 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005444 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005445
Paulo Zanoni174edf12012-10-26 19:05:50 -02005446 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005447 intel_dig_port->dp.output_reg = output_reg;
5448
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005449 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
Ville Syrjälä882ec382014-04-28 14:07:43 +03005450 if (IS_CHERRYVIEW(dev)) {
5451 if (port == PORT_D)
5452 intel_encoder->crtc_mask = 1 << 2;
5453 else
5454 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
5455 } else {
5456 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
5457 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02005458 intel_encoder->cloneable = 0;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005459 intel_encoder->hot_plug = intel_dp_hot_plug;
5460
Dave Airlie13cf5502014-06-18 11:29:35 +10005461 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
5462 dev_priv->hpd_irq_port[port] = intel_dig_port;
5463
Paulo Zanoni15b1d172013-06-12 17:27:27 -03005464 if (!intel_dp_init_connector(intel_dig_port, intel_connector)) {
5465 drm_encoder_cleanup(encoder);
5466 kfree(intel_dig_port);
Paulo Zanonib2f246a2013-06-12 17:27:26 -03005467 kfree(intel_connector);
Paulo Zanoni15b1d172013-06-12 17:27:27 -03005468 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005469}
Dave Airlie0e32b392014-05-02 14:02:48 +10005470
5471void intel_dp_mst_suspend(struct drm_device *dev)
5472{
5473 struct drm_i915_private *dev_priv = dev->dev_private;
5474 int i;
5475
5476 /* disable MST */
5477 for (i = 0; i < I915_MAX_PORTS; i++) {
5478 struct intel_digital_port *intel_dig_port = dev_priv->hpd_irq_port[i];
5479 if (!intel_dig_port)
5480 continue;
5481
5482 if (intel_dig_port->base.type == INTEL_OUTPUT_DISPLAYPORT) {
5483 if (!intel_dig_port->dp.can_mst)
5484 continue;
5485 if (intel_dig_port->dp.is_mst)
5486 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
5487 }
5488 }
5489}
5490
5491void intel_dp_mst_resume(struct drm_device *dev)
5492{
5493 struct drm_i915_private *dev_priv = dev->dev_private;
5494 int i;
5495
5496 for (i = 0; i < I915_MAX_PORTS; i++) {
5497 struct intel_digital_port *intel_dig_port = dev_priv->hpd_irq_port[i];
5498 if (!intel_dig_port)
5499 continue;
5500 if (intel_dig_port->base.type == INTEL_OUTPUT_DISPLAYPORT) {
5501 int ret;
5502
5503 if (!intel_dig_port->dp.can_mst)
5504 continue;
5505
5506 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
5507 if (ret != 0) {
5508 intel_dp_check_mst_status(&intel_dig_port->dp);
5509 }
5510 }
5511 }
5512}