blob: f7b7bfc455e2b33143651e40da32128585e1a8df [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>
David Howells760285e2012-10-02 18:01:07 +010031#include <drm/drmP.h>
32#include <drm/drm_crtc.h>
33#include <drm/drm_crtc_helper.h>
34#include <drm/drm_edid.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070035#include "intel_drv.h"
David Howells760285e2012-10-02 18:01:07 +010036#include <drm/i915_drm.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070037#include "i915_drv.h"
Keith Packarda4fc5ed2009-04-07 16:16:42 -070038
Keith Packarda4fc5ed2009-04-07 16:16:42 -070039#define DP_LINK_CHECK_TIMEOUT (10 * 1000)
40
Jesse Barnescfcb0fc2010-10-07 16:01:06 -070041/**
42 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
43 * @intel_dp: DP struct
44 *
45 * If a CPU or PCH DP output is attached to an eDP panel, this function
46 * will return true, and false otherwise.
47 */
48static bool is_edp(struct intel_dp *intel_dp)
49{
50 return intel_dp->base.type == INTEL_OUTPUT_EDP;
51}
52
53/**
54 * is_pch_edp - is the port on the PCH and attached to an eDP panel?
55 * @intel_dp: DP struct
56 *
57 * Returns true if the given DP struct corresponds to a PCH DP port attached
58 * to an eDP panel, false otherwise. Helpful for determining whether we
59 * may need FDI resources for a given DP output or not.
60 */
61static bool is_pch_edp(struct intel_dp *intel_dp)
62{
63 return intel_dp->is_pch_edp;
64}
65
Adam Jackson1c958222011-10-14 17:22:25 -040066/**
67 * is_cpu_edp - is the port on the CPU and attached to an eDP panel?
68 * @intel_dp: DP struct
69 *
70 * Returns true if the given DP struct corresponds to a CPU eDP port.
71 */
72static bool is_cpu_edp(struct intel_dp *intel_dp)
73{
74 return is_edp(intel_dp) && !is_pch_edp(intel_dp);
75}
76
Chris Wilsondf0e9242010-09-09 16:20:55 +010077static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
78{
79 return container_of(intel_attached_encoder(connector),
80 struct intel_dp, base);
81}
82
Jesse Barnes814948a2010-10-07 16:01:09 -070083/**
84 * intel_encoder_is_pch_edp - is the given encoder a PCH attached eDP?
85 * @encoder: DRM encoder
86 *
87 * Return true if @encoder corresponds to a PCH attached eDP panel. Needed
88 * by intel_display.c.
89 */
90bool intel_encoder_is_pch_edp(struct drm_encoder *encoder)
91{
92 struct intel_dp *intel_dp;
93
94 if (!encoder)
95 return false;
96
97 intel_dp = enc_to_intel_dp(encoder);
98
99 return is_pch_edp(intel_dp);
100}
101
Chris Wilsonea5b2132010-08-04 13:50:23 +0100102static void intel_dp_link_down(struct intel_dp *intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700103
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800104void
Akshay Joshi0206e352011-08-16 15:34:10 -0400105intel_edp_link_config(struct intel_encoder *intel_encoder,
Chris Wilsonea5b2132010-08-04 13:50:23 +0100106 int *lane_num, int *link_bw)
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800107{
Chris Wilsonea5b2132010-08-04 13:50:23 +0100108 struct intel_dp *intel_dp = container_of(intel_encoder, struct intel_dp, base);
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800109
Chris Wilsonea5b2132010-08-04 13:50:23 +0100110 *lane_num = intel_dp->lane_count;
Daniel Vetter3b5c6622012-10-18 10:15:31 +0200111 *link_bw = drm_dp_bw_code_to_link_rate(intel_dp->link_bw);
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800112}
113
Daniel Vetter94bf2ce2012-06-04 18:39:19 +0200114int
115intel_edp_target_clock(struct intel_encoder *intel_encoder,
116 struct drm_display_mode *mode)
117{
118 struct intel_dp *intel_dp = container_of(intel_encoder, struct intel_dp, base);
Jani Nikuladd06f902012-10-19 14:51:50 +0300119 struct intel_connector *intel_connector = intel_dp->attached_connector;
Daniel Vetter94bf2ce2012-06-04 18:39:19 +0200120
Jani Nikuladd06f902012-10-19 14:51:50 +0300121 if (intel_connector->panel.fixed_mode)
122 return intel_connector->panel.fixed_mode->clock;
Daniel Vetter94bf2ce2012-06-04 18:39:19 +0200123 else
124 return mode->clock;
125}
126
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700127static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100128intel_dp_max_lane_count(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700129{
Keith Packard9a10f402011-11-02 13:03:47 -0700130 int max_lane_count = intel_dp->dpcd[DP_MAX_LANE_COUNT] & 0x1f;
131 switch (max_lane_count) {
132 case 1: case 2: case 4:
133 break;
134 default:
135 max_lane_count = 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700136 }
137 return max_lane_count;
138}
139
140static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100141intel_dp_max_link_bw(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700142{
Jesse Barnes7183dc22011-07-07 11:10:58 -0700143 int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700144
145 switch (max_link_bw) {
146 case DP_LINK_BW_1_62:
147 case DP_LINK_BW_2_7:
148 break;
149 default:
150 max_link_bw = DP_LINK_BW_1_62;
151 break;
152 }
153 return max_link_bw;
154}
155
156static int
157intel_dp_link_clock(uint8_t link_bw)
158{
159 if (link_bw == DP_LINK_BW_2_7)
160 return 270000;
161 else
162 return 162000;
163}
164
Adam Jacksoncd9dde42011-10-14 12:43:49 -0400165/*
166 * The units on the numbers in the next two are... bizarre. Examples will
167 * make it clearer; this one parallels an example in the eDP spec.
168 *
169 * intel_dp_max_data_rate for one lane of 2.7GHz evaluates as:
170 *
171 * 270000 * 1 * 8 / 10 == 216000
172 *
173 * The actual data capacity of that configuration is 2.16Gbit/s, so the
174 * units are decakilobits. ->clock in a drm_display_mode is in kilohertz -
175 * or equivalently, kilopixels per second - so for 1680x1050R it'd be
176 * 119000. At 18bpp that's 2142000 kilobits per second.
177 *
178 * Thus the strange-looking division by 10 in intel_dp_link_required, to
179 * get the result in decakilobits instead of kilobits.
180 */
181
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700182static int
Keith Packardc8982612012-01-25 08:16:25 -0800183intel_dp_link_required(int pixel_clock, int bpp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700184{
Adam Jacksoncd9dde42011-10-14 12:43:49 -0400185 return (pixel_clock * bpp + 9) / 10;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700186}
187
188static int
Dave Airliefe27d532010-06-30 11:46:17 +1000189intel_dp_max_data_rate(int max_link_clock, int max_lanes)
190{
191 return (max_link_clock * max_lanes * 8) / 10;
192}
193
Daniel Vetterc4867932012-04-10 10:42:36 +0200194static bool
195intel_dp_adjust_dithering(struct intel_dp *intel_dp,
196 struct drm_display_mode *mode,
Daniel Vettercb1793c2012-06-04 18:39:21 +0200197 bool adjust_mode)
Daniel Vetterc4867932012-04-10 10:42:36 +0200198{
199 int max_link_clock = intel_dp_link_clock(intel_dp_max_link_bw(intel_dp));
200 int max_lanes = intel_dp_max_lane_count(intel_dp);
201 int max_rate, mode_rate;
202
203 mode_rate = intel_dp_link_required(mode->clock, 24);
204 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
205
206 if (mode_rate > max_rate) {
207 mode_rate = intel_dp_link_required(mode->clock, 18);
208 if (mode_rate > max_rate)
209 return false;
210
Daniel Vettercb1793c2012-06-04 18:39:21 +0200211 if (adjust_mode)
212 mode->private_flags
Daniel Vetterc4867932012-04-10 10:42:36 +0200213 |= INTEL_MODE_DP_FORCE_6BPC;
214
215 return true;
216 }
217
218 return true;
219}
220
Dave Airliefe27d532010-06-30 11:46:17 +1000221static int
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700222intel_dp_mode_valid(struct drm_connector *connector,
223 struct drm_display_mode *mode)
224{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100225 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300226 struct intel_connector *intel_connector = to_intel_connector(connector);
227 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700228
Jani Nikuladd06f902012-10-19 14:51:50 +0300229 if (is_edp(intel_dp) && fixed_mode) {
230 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100231 return MODE_PANEL;
232
Jani Nikuladd06f902012-10-19 14:51:50 +0300233 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100234 return MODE_PANEL;
235 }
236
Daniel Vettercb1793c2012-06-04 18:39:21 +0200237 if (!intel_dp_adjust_dithering(intel_dp, mode, false))
Daniel Vetterc4867932012-04-10 10:42:36 +0200238 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700239
240 if (mode->clock < 10000)
241 return MODE_CLOCK_LOW;
242
Daniel Vetter0af78a22012-05-23 11:30:55 +0200243 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
244 return MODE_H_ILLEGAL;
245
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700246 return MODE_OK;
247}
248
249static uint32_t
250pack_aux(uint8_t *src, int src_bytes)
251{
252 int i;
253 uint32_t v = 0;
254
255 if (src_bytes > 4)
256 src_bytes = 4;
257 for (i = 0; i < src_bytes; i++)
258 v |= ((uint32_t) src[i]) << ((3-i) * 8);
259 return v;
260}
261
262static void
263unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
264{
265 int i;
266 if (dst_bytes > 4)
267 dst_bytes = 4;
268 for (i = 0; i < dst_bytes; i++)
269 dst[i] = src >> ((3-i) * 8);
270}
271
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700272/* hrawclock is 1/4 the FSB frequency */
273static int
274intel_hrawclk(struct drm_device *dev)
275{
276 struct drm_i915_private *dev_priv = dev->dev_private;
277 uint32_t clkcfg;
278
Vijay Purushothaman9473c8f2012-09-27 19:13:01 +0530279 /* There is no CLKCFG reg in Valleyview. VLV hrawclk is 200 MHz */
280 if (IS_VALLEYVIEW(dev))
281 return 200;
282
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700283 clkcfg = I915_READ(CLKCFG);
284 switch (clkcfg & CLKCFG_FSB_MASK) {
285 case CLKCFG_FSB_400:
286 return 100;
287 case CLKCFG_FSB_533:
288 return 133;
289 case CLKCFG_FSB_667:
290 return 166;
291 case CLKCFG_FSB_800:
292 return 200;
293 case CLKCFG_FSB_1067:
294 return 266;
295 case CLKCFG_FSB_1333:
296 return 333;
297 /* these two are just a guess; one of them might be right */
298 case CLKCFG_FSB_1600:
299 case CLKCFG_FSB_1600_ALT:
300 return 400;
301 default:
302 return 133;
303 }
304}
305
Keith Packardebf33b12011-09-29 15:53:27 -0700306static bool ironlake_edp_have_panel_power(struct intel_dp *intel_dp)
307{
308 struct drm_device *dev = intel_dp->base.base.dev;
309 struct drm_i915_private *dev_priv = dev->dev_private;
310
311 return (I915_READ(PCH_PP_STATUS) & PP_ON) != 0;
312}
313
314static bool ironlake_edp_have_panel_vdd(struct intel_dp *intel_dp)
315{
316 struct drm_device *dev = intel_dp->base.base.dev;
317 struct drm_i915_private *dev_priv = dev->dev_private;
318
319 return (I915_READ(PCH_PP_CONTROL) & EDP_FORCE_VDD) != 0;
320}
321
Keith Packard9b984da2011-09-19 13:54:47 -0700322static void
323intel_dp_check_edp(struct intel_dp *intel_dp)
324{
325 struct drm_device *dev = intel_dp->base.base.dev;
326 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packardebf33b12011-09-29 15:53:27 -0700327
Keith Packard9b984da2011-09-19 13:54:47 -0700328 if (!is_edp(intel_dp))
329 return;
Keith Packardebf33b12011-09-29 15:53:27 -0700330 if (!ironlake_edp_have_panel_power(intel_dp) && !ironlake_edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700331 WARN(1, "eDP powered off while attempting aux channel communication.\n");
332 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Keith Packardebf33b12011-09-29 15:53:27 -0700333 I915_READ(PCH_PP_STATUS),
Keith Packard9b984da2011-09-19 13:54:47 -0700334 I915_READ(PCH_PP_CONTROL));
335 }
336}
337
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700338static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100339intel_dp_aux_ch(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700340 uint8_t *send, int send_bytes,
341 uint8_t *recv, int recv_size)
342{
Chris Wilsonea5b2132010-08-04 13:50:23 +0100343 uint32_t output_reg = intel_dp->output_reg;
Chris Wilson4ef69c72010-09-09 15:14:28 +0100344 struct drm_device *dev = intel_dp->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700345 struct drm_i915_private *dev_priv = dev->dev_private;
346 uint32_t ch_ctl = output_reg + 0x10;
347 uint32_t ch_data = ch_ctl + 4;
348 int i;
349 int recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700350 uint32_t status;
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700351 uint32_t aux_clock_divider;
Daniel Vetter6b4e0a92012-06-14 22:15:00 +0200352 int try, precharge;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700353
Paulo Zanoni750eb992012-10-18 16:25:08 +0200354 if (IS_HASWELL(dev)) {
355 switch (intel_dp->port) {
356 case PORT_A:
357 ch_ctl = DPA_AUX_CH_CTL;
358 ch_data = DPA_AUX_CH_DATA1;
359 break;
360 case PORT_B:
361 ch_ctl = PCH_DPB_AUX_CH_CTL;
362 ch_data = PCH_DPB_AUX_CH_DATA1;
363 break;
364 case PORT_C:
365 ch_ctl = PCH_DPC_AUX_CH_CTL;
366 ch_data = PCH_DPC_AUX_CH_DATA1;
367 break;
368 case PORT_D:
369 ch_ctl = PCH_DPD_AUX_CH_CTL;
370 ch_data = PCH_DPD_AUX_CH_DATA1;
371 break;
372 default:
373 BUG();
374 }
375 }
376
Keith Packard9b984da2011-09-19 13:54:47 -0700377 intel_dp_check_edp(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700378 /* The clock divider is based off the hrawclk,
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700379 * and would like to run at 2MHz. So, take the
380 * hrawclk value and divide by 2 and use that
Jesse Barnes6176b8f2010-09-08 12:42:00 -0700381 *
382 * Note that PCH attached eDP panels should use a 125MHz input
383 * clock divider.
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700384 */
Adam Jackson1c958222011-10-14 17:22:25 -0400385 if (is_cpu_edp(intel_dp)) {
Vijay Purushothaman9473c8f2012-09-27 19:13:01 +0530386 if (IS_VALLEYVIEW(dev))
387 aux_clock_divider = 100;
388 else if (IS_GEN6(dev) || IS_GEN7(dev))
Keith Packard1a2eb462011-11-16 16:26:07 -0800389 aux_clock_divider = 200; /* SNB & IVB eDP input clock at 400Mhz */
Zhenyu Wange3421a12010-04-08 09:43:27 +0800390 else
391 aux_clock_divider = 225; /* eDP input clock at 450Mhz */
392 } else if (HAS_PCH_SPLIT(dev))
Adam Jackson69191322011-07-26 15:39:44 -0400393 aux_clock_divider = 63; /* IRL input clock fixed at 125Mhz */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +0800394 else
395 aux_clock_divider = intel_hrawclk(dev) / 2;
396
Daniel Vetter6b4e0a92012-06-14 22:15:00 +0200397 if (IS_GEN6(dev))
398 precharge = 3;
399 else
400 precharge = 5;
401
Jesse Barnes11bee432011-08-01 15:02:20 -0700402 /* Try to wait for any previous AUX channel activity */
403 for (try = 0; try < 3; try++) {
404 status = I915_READ(ch_ctl);
405 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
406 break;
407 msleep(1);
408 }
409
410 if (try == 3) {
411 WARN(1, "dp_aux_ch not started status 0x%08x\n",
412 I915_READ(ch_ctl));
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100413 return -EBUSY;
414 }
415
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700416 /* Must try at least 3 times according to DP spec */
417 for (try = 0; try < 5; try++) {
418 /* Load the send data into the aux channel data registers */
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100419 for (i = 0; i < send_bytes; i += 4)
420 I915_WRITE(ch_data + i,
421 pack_aux(send + i, send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -0400422
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700423 /* Send the command and wait for it to complete */
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100424 I915_WRITE(ch_ctl,
425 DP_AUX_CH_CTL_SEND_BUSY |
426 DP_AUX_CH_CTL_TIME_OUT_400us |
427 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
428 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
429 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT) |
430 DP_AUX_CH_CTL_DONE |
431 DP_AUX_CH_CTL_TIME_OUT_ERROR |
432 DP_AUX_CH_CTL_RECEIVE_ERROR);
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700433 for (;;) {
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700434 status = I915_READ(ch_ctl);
435 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
436 break;
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100437 udelay(100);
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700438 }
Akshay Joshi0206e352011-08-16 15:34:10 -0400439
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700440 /* Clear done status and any errors */
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100441 I915_WRITE(ch_ctl,
442 status |
443 DP_AUX_CH_CTL_DONE |
444 DP_AUX_CH_CTL_TIME_OUT_ERROR |
445 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -0400446
447 if (status & (DP_AUX_CH_CTL_TIME_OUT_ERROR |
448 DP_AUX_CH_CTL_RECEIVE_ERROR))
449 continue;
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100450 if (status & DP_AUX_CH_CTL_DONE)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700451 break;
452 }
453
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700454 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700455 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Keith Packarda5b3da52009-06-11 22:30:32 -0700456 return -EBUSY;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700457 }
458
459 /* Check for timeout or receive error.
460 * Timeouts occur when the sink is not connected
461 */
Keith Packarda5b3da52009-06-11 22:30:32 -0700462 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700463 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Keith Packarda5b3da52009-06-11 22:30:32 -0700464 return -EIO;
465 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700466
467 /* Timeouts occur when the device isn't connected, so they're
468 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -0700469 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Zhao Yakui28c97732009-10-09 11:39:41 +0800470 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Keith Packarda5b3da52009-06-11 22:30:32 -0700471 return -ETIMEDOUT;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700472 }
473
474 /* Unload any bytes sent back from the other side */
475 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
476 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700477 if (recv_bytes > recv_size)
478 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -0400479
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100480 for (i = 0; i < recv_bytes; i += 4)
481 unpack_aux(I915_READ(ch_data + i),
482 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700483
484 return recv_bytes;
485}
486
487/* Write data to the aux channel in native mode */
488static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100489intel_dp_aux_native_write(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700490 uint16_t address, uint8_t *send, int send_bytes)
491{
492 int ret;
493 uint8_t msg[20];
494 int msg_bytes;
495 uint8_t ack;
496
Keith Packard9b984da2011-09-19 13:54:47 -0700497 intel_dp_check_edp(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700498 if (send_bytes > 16)
499 return -1;
500 msg[0] = AUX_NATIVE_WRITE << 4;
501 msg[1] = address >> 8;
Zhenyu Wangeebc8632009-07-24 01:00:30 +0800502 msg[2] = address & 0xff;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700503 msg[3] = send_bytes - 1;
504 memcpy(&msg[4], send, send_bytes);
505 msg_bytes = send_bytes + 4;
506 for (;;) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100507 ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes, &ack, 1);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700508 if (ret < 0)
509 return ret;
510 if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK)
511 break;
512 else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
513 udelay(100);
514 else
Keith Packarda5b3da52009-06-11 22:30:32 -0700515 return -EIO;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700516 }
517 return send_bytes;
518}
519
520/* Write a single byte to the aux channel in native mode */
521static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100522intel_dp_aux_native_write_1(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700523 uint16_t address, uint8_t byte)
524{
Chris Wilsonea5b2132010-08-04 13:50:23 +0100525 return intel_dp_aux_native_write(intel_dp, address, &byte, 1);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700526}
527
528/* read bytes from a native aux channel */
529static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100530intel_dp_aux_native_read(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700531 uint16_t address, uint8_t *recv, int recv_bytes)
532{
533 uint8_t msg[4];
534 int msg_bytes;
535 uint8_t reply[20];
536 int reply_bytes;
537 uint8_t ack;
538 int ret;
539
Keith Packard9b984da2011-09-19 13:54:47 -0700540 intel_dp_check_edp(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700541 msg[0] = AUX_NATIVE_READ << 4;
542 msg[1] = address >> 8;
543 msg[2] = address & 0xff;
544 msg[3] = recv_bytes - 1;
545
546 msg_bytes = 4;
547 reply_bytes = recv_bytes + 1;
548
549 for (;;) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100550 ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700551 reply, reply_bytes);
Keith Packarda5b3da52009-06-11 22:30:32 -0700552 if (ret == 0)
553 return -EPROTO;
554 if (ret < 0)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700555 return ret;
556 ack = reply[0];
557 if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK) {
558 memcpy(recv, reply + 1, ret - 1);
559 return ret - 1;
560 }
561 else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
562 udelay(100);
563 else
Keith Packarda5b3da52009-06-11 22:30:32 -0700564 return -EIO;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700565 }
566}
567
568static int
Dave Airlieab2c0672009-12-04 10:55:24 +1000569intel_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode,
570 uint8_t write_byte, uint8_t *read_byte)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700571{
Dave Airlieab2c0672009-12-04 10:55:24 +1000572 struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100573 struct intel_dp *intel_dp = container_of(adapter,
574 struct intel_dp,
575 adapter);
Dave Airlieab2c0672009-12-04 10:55:24 +1000576 uint16_t address = algo_data->address;
577 uint8_t msg[5];
578 uint8_t reply[2];
David Flynn8316f332010-12-08 16:10:21 +0000579 unsigned retry;
Dave Airlieab2c0672009-12-04 10:55:24 +1000580 int msg_bytes;
581 int reply_bytes;
582 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700583
Keith Packard9b984da2011-09-19 13:54:47 -0700584 intel_dp_check_edp(intel_dp);
Dave Airlieab2c0672009-12-04 10:55:24 +1000585 /* Set up the command byte */
586 if (mode & MODE_I2C_READ)
587 msg[0] = AUX_I2C_READ << 4;
588 else
589 msg[0] = AUX_I2C_WRITE << 4;
590
591 if (!(mode & MODE_I2C_STOP))
592 msg[0] |= AUX_I2C_MOT << 4;
593
594 msg[1] = address >> 8;
595 msg[2] = address;
596
597 switch (mode) {
598 case MODE_I2C_WRITE:
599 msg[3] = 0;
600 msg[4] = write_byte;
601 msg_bytes = 5;
602 reply_bytes = 1;
603 break;
604 case MODE_I2C_READ:
605 msg[3] = 0;
606 msg_bytes = 4;
607 reply_bytes = 2;
608 break;
609 default:
610 msg_bytes = 3;
611 reply_bytes = 1;
612 break;
613 }
614
David Flynn8316f332010-12-08 16:10:21 +0000615 for (retry = 0; retry < 5; retry++) {
616 ret = intel_dp_aux_ch(intel_dp,
617 msg, msg_bytes,
618 reply, reply_bytes);
Dave Airlieab2c0672009-12-04 10:55:24 +1000619 if (ret < 0) {
Dave Airlie3ff99162009-12-08 14:03:47 +1000620 DRM_DEBUG_KMS("aux_ch failed %d\n", ret);
Dave Airlieab2c0672009-12-04 10:55:24 +1000621 return ret;
622 }
David Flynn8316f332010-12-08 16:10:21 +0000623
624 switch (reply[0] & AUX_NATIVE_REPLY_MASK) {
625 case AUX_NATIVE_REPLY_ACK:
626 /* I2C-over-AUX Reply field is only valid
627 * when paired with AUX ACK.
628 */
629 break;
630 case AUX_NATIVE_REPLY_NACK:
631 DRM_DEBUG_KMS("aux_ch native nack\n");
632 return -EREMOTEIO;
633 case AUX_NATIVE_REPLY_DEFER:
634 udelay(100);
635 continue;
636 default:
637 DRM_ERROR("aux_ch invalid native reply 0x%02x\n",
638 reply[0]);
639 return -EREMOTEIO;
640 }
641
Dave Airlieab2c0672009-12-04 10:55:24 +1000642 switch (reply[0] & AUX_I2C_REPLY_MASK) {
643 case AUX_I2C_REPLY_ACK:
644 if (mode == MODE_I2C_READ) {
645 *read_byte = reply[1];
646 }
647 return reply_bytes - 1;
648 case AUX_I2C_REPLY_NACK:
David Flynn8316f332010-12-08 16:10:21 +0000649 DRM_DEBUG_KMS("aux_i2c nack\n");
Dave Airlieab2c0672009-12-04 10:55:24 +1000650 return -EREMOTEIO;
651 case AUX_I2C_REPLY_DEFER:
David Flynn8316f332010-12-08 16:10:21 +0000652 DRM_DEBUG_KMS("aux_i2c defer\n");
Dave Airlieab2c0672009-12-04 10:55:24 +1000653 udelay(100);
654 break;
655 default:
David Flynn8316f332010-12-08 16:10:21 +0000656 DRM_ERROR("aux_i2c invalid reply 0x%02x\n", reply[0]);
Dave Airlieab2c0672009-12-04 10:55:24 +1000657 return -EREMOTEIO;
658 }
659 }
David Flynn8316f332010-12-08 16:10:21 +0000660
661 DRM_ERROR("too many retries, giving up\n");
662 return -EREMOTEIO;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700663}
664
Keith Packard0b5c5412011-09-28 16:41:05 -0700665static void ironlake_edp_panel_vdd_on(struct intel_dp *intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -0700666static void ironlake_edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
Keith Packard0b5c5412011-09-28 16:41:05 -0700667
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700668static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100669intel_dp_i2c_init(struct intel_dp *intel_dp,
Zhenyu Wang55f78c42010-03-29 16:13:57 +0800670 struct intel_connector *intel_connector, const char *name)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700671{
Keith Packard0b5c5412011-09-28 16:41:05 -0700672 int ret;
673
Zhenyu Wangd54e9d22009-10-19 15:43:51 +0800674 DRM_DEBUG_KMS("i2c_init %s\n", name);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100675 intel_dp->algo.running = false;
676 intel_dp->algo.address = 0;
677 intel_dp->algo.aux_ch = intel_dp_i2c_aux_ch;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700678
Akshay Joshi0206e352011-08-16 15:34:10 -0400679 memset(&intel_dp->adapter, '\0', sizeof(intel_dp->adapter));
Chris Wilsonea5b2132010-08-04 13:50:23 +0100680 intel_dp->adapter.owner = THIS_MODULE;
681 intel_dp->adapter.class = I2C_CLASS_DDC;
Akshay Joshi0206e352011-08-16 15:34:10 -0400682 strncpy(intel_dp->adapter.name, name, sizeof(intel_dp->adapter.name) - 1);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100683 intel_dp->adapter.name[sizeof(intel_dp->adapter.name) - 1] = '\0';
684 intel_dp->adapter.algo_data = &intel_dp->algo;
685 intel_dp->adapter.dev.parent = &intel_connector->base.kdev;
686
Keith Packard0b5c5412011-09-28 16:41:05 -0700687 ironlake_edp_panel_vdd_on(intel_dp);
688 ret = i2c_dp_aux_add_bus(&intel_dp->adapter);
Keith Packardbd943152011-09-18 23:09:52 -0700689 ironlake_edp_panel_vdd_off(intel_dp, false);
Keith Packard0b5c5412011-09-28 16:41:05 -0700690 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700691}
692
693static bool
Laurent Pincharte811f5a2012-07-17 17:56:50 +0200694intel_dp_mode_fixup(struct drm_encoder *encoder,
695 const struct drm_display_mode *mode,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700696 struct drm_display_mode *adjusted_mode)
697{
Zhao Yakui0d3a1bee2010-07-19 09:43:13 +0100698 struct drm_device *dev = encoder->dev;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100699 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Jani Nikuladd06f902012-10-19 14:51:50 +0300700 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700701 int lane_count, clock;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100702 int max_lane_count = intel_dp_max_lane_count(intel_dp);
703 int max_clock = intel_dp_max_link_bw(intel_dp) == DP_LINK_BW_2_7 ? 1 : 0;
Daniel Vetter083f9562012-04-20 20:23:49 +0200704 int bpp, mode_rate;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700705 static int bws[2] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7 };
706
Jani Nikuladd06f902012-10-19 14:51:50 +0300707 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
708 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
709 adjusted_mode);
Chris Wilson1d8e1c72010-08-07 11:01:28 +0100710 intel_pch_panel_fitting(dev, DRM_MODE_SCALE_FULLSCREEN,
711 mode, adjusted_mode);
Zhao Yakui0d3a1bee2010-07-19 09:43:13 +0100712 }
713
Daniel Vettercb1793c2012-06-04 18:39:21 +0200714 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +0200715 return false;
716
Daniel Vetter083f9562012-04-20 20:23:49 +0200717 DRM_DEBUG_KMS("DP link computation with max lane count %i "
718 "max bw %02x pixel clock %iKHz\n",
Daniel Vetter71244652012-06-04 18:39:20 +0200719 max_lane_count, bws[max_clock], adjusted_mode->clock);
Daniel Vetter083f9562012-04-20 20:23:49 +0200720
Daniel Vettercb1793c2012-06-04 18:39:21 +0200721 if (!intel_dp_adjust_dithering(intel_dp, adjusted_mode, true))
Daniel Vetterc4867932012-04-10 10:42:36 +0200722 return false;
723
724 bpp = adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC ? 18 : 24;
Daniel Vetter71244652012-06-04 18:39:20 +0200725 mode_rate = intel_dp_link_required(adjusted_mode->clock, bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +0200726
Jesse Barnes2514bc52012-06-21 15:13:50 -0700727 for (clock = 0; clock <= max_clock; clock++) {
728 for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) {
Dave Airliefe27d532010-06-30 11:46:17 +1000729 int link_avail = intel_dp_max_data_rate(intel_dp_link_clock(bws[clock]), lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700730
Daniel Vetter083f9562012-04-20 20:23:49 +0200731 if (mode_rate <= link_avail) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100732 intel_dp->link_bw = bws[clock];
733 intel_dp->lane_count = lane_count;
734 adjusted_mode->clock = intel_dp_link_clock(intel_dp->link_bw);
Daniel Vetter083f9562012-04-20 20:23:49 +0200735 DRM_DEBUG_KMS("DP link bw %02x lane "
736 "count %d clock %d bpp %d\n",
Chris Wilsonea5b2132010-08-04 13:50:23 +0100737 intel_dp->link_bw, intel_dp->lane_count,
Daniel Vetter083f9562012-04-20 20:23:49 +0200738 adjusted_mode->clock, bpp);
739 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
740 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700741 return true;
742 }
743 }
744 }
Dave Airliefe27d532010-06-30 11:46:17 +1000745
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700746 return false;
747}
748
749struct intel_dp_m_n {
750 uint32_t tu;
751 uint32_t gmch_m;
752 uint32_t gmch_n;
753 uint32_t link_m;
754 uint32_t link_n;
755};
756
757static void
758intel_reduce_ratio(uint32_t *num, uint32_t *den)
759{
760 while (*num > 0xffffff || *den > 0xffffff) {
761 *num >>= 1;
762 *den >>= 1;
763 }
764}
765
766static void
Zhao Yakui36e83a12010-06-12 14:32:21 +0800767intel_dp_compute_m_n(int bpp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700768 int nlanes,
769 int pixel_clock,
770 int link_clock,
771 struct intel_dp_m_n *m_n)
772{
773 m_n->tu = 64;
Zhao Yakui36e83a12010-06-12 14:32:21 +0800774 m_n->gmch_m = (pixel_clock * bpp) >> 3;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700775 m_n->gmch_n = link_clock * nlanes;
776 intel_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
777 m_n->link_m = pixel_clock;
778 m_n->link_n = link_clock;
779 intel_reduce_ratio(&m_n->link_m, &m_n->link_n);
780}
781
782void
783intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode,
784 struct drm_display_mode *adjusted_mode)
785{
786 struct drm_device *dev = crtc->dev;
Daniel Vetter6c2b7c12012-07-05 09:50:24 +0200787 struct intel_encoder *encoder;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700788 struct drm_i915_private *dev_priv = dev->dev_private;
789 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnes858fa0352011-06-24 12:19:24 -0700790 int lane_count = 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700791 struct intel_dp_m_n m_n;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800792 int pipe = intel_crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700793
794 /*
Eric Anholt21d40d32010-03-25 11:11:14 -0700795 * Find the lane count in the intel_encoder private
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700796 */
Daniel Vetter6c2b7c12012-07-05 09:50:24 +0200797 for_each_encoder_on_crtc(dev, crtc, encoder) {
798 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700799
Keith Packard9a10f402011-11-02 13:03:47 -0700800 if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT ||
801 intel_dp->base.type == INTEL_OUTPUT_EDP)
802 {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100803 lane_count = intel_dp->lane_count;
Jesse Barnes51190662010-10-07 16:01:08 -0700804 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700805 }
806 }
807
808 /*
809 * Compute the GMCH and Link ratios. The '3' here is
810 * the number of bytes_per_pixel post-LUT, which we always
811 * set up for 8-bits of R/G/B, or 3 bytes total.
812 */
Jesse Barnes858fa0352011-06-24 12:19:24 -0700813 intel_dp_compute_m_n(intel_crtc->bpp, lane_count,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700814 mode->clock, adjusted_mode->clock, &m_n);
815
Paulo Zanoni1eb8dfe2012-10-18 12:42:10 -0300816 if (IS_HASWELL(dev)) {
817 I915_WRITE(PIPE_DATA_M1(pipe), TU_SIZE(m_n.tu) | m_n.gmch_m);
818 I915_WRITE(PIPE_DATA_N1(pipe), m_n.gmch_n);
819 I915_WRITE(PIPE_LINK_M1(pipe), m_n.link_m);
820 I915_WRITE(PIPE_LINK_N1(pipe), m_n.link_n);
821 } else if (HAS_PCH_SPLIT(dev)) {
Paulo Zanoni7346bfa2012-10-15 15:51:35 -0300822 I915_WRITE(TRANSDATA_M1(pipe), TU_SIZE(m_n.tu) | m_n.gmch_m);
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800823 I915_WRITE(TRANSDATA_N1(pipe), m_n.gmch_n);
824 I915_WRITE(TRANSDPLINK_M1(pipe), m_n.link_m);
825 I915_WRITE(TRANSDPLINK_N1(pipe), m_n.link_n);
Vijay Purushothaman74a4dd22012-09-27 19:13:04 +0530826 } else if (IS_VALLEYVIEW(dev)) {
827 I915_WRITE(PIPE_DATA_M1(pipe), TU_SIZE(m_n.tu) | m_n.gmch_m);
828 I915_WRITE(PIPE_DATA_N1(pipe), m_n.gmch_n);
829 I915_WRITE(PIPE_LINK_M1(pipe), m_n.link_m);
830 I915_WRITE(PIPE_LINK_N1(pipe), m_n.link_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700831 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800832 I915_WRITE(PIPE_GMCH_DATA_M(pipe),
Paulo Zanoni7346bfa2012-10-15 15:51:35 -0300833 TU_SIZE(m_n.tu) | m_n.gmch_m);
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800834 I915_WRITE(PIPE_GMCH_DATA_N(pipe), m_n.gmch_n);
835 I915_WRITE(PIPE_DP_LINK_M(pipe), m_n.link_m);
836 I915_WRITE(PIPE_DP_LINK_N(pipe), m_n.link_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700837 }
838}
839
Paulo Zanoni247d89f2012-10-15 15:51:33 -0300840void intel_dp_init_link_config(struct intel_dp *intel_dp)
841{
842 memset(intel_dp->link_configuration, 0, DP_LINK_CONFIGURATION_SIZE);
843 intel_dp->link_configuration[0] = intel_dp->link_bw;
844 intel_dp->link_configuration[1] = intel_dp->lane_count;
845 intel_dp->link_configuration[8] = DP_SET_ANSI_8B10B;
846 /*
847 * Check for DPCD version > 1.1 and enhanced framing support
848 */
849 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
850 (intel_dp->dpcd[DP_MAX_LANE_COUNT] & DP_ENHANCED_FRAME_CAP)) {
851 intel_dp->link_configuration[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
852 }
853}
854
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700855static void
856intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
857 struct drm_display_mode *adjusted_mode)
858{
Zhenyu Wange3421a12010-04-08 09:43:27 +0800859 struct drm_device *dev = encoder->dev;
Keith Packard417e8222011-11-01 19:54:11 -0700860 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100861 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Chris Wilson4ef69c72010-09-09 15:14:28 +0100862 struct drm_crtc *crtc = intel_dp->base.base.crtc;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700863 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
864
Keith Packard417e8222011-11-01 19:54:11 -0700865 /*
Keith Packard1a2eb462011-11-16 16:26:07 -0800866 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -0700867 *
868 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -0800869 * SNB CPU
870 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -0700871 * CPT PCH
872 *
873 * IBX PCH and CPU are the same for almost everything,
874 * except that the CPU DP PLL is configured in this
875 * register
876 *
877 * CPT PCH is quite different, having many bits moved
878 * to the TRANS_DP_CTL register instead. That
879 * configuration happens (oddly) in ironlake_pch_enable
880 */
Adam Jackson9c9e7922010-04-05 17:57:59 -0400881
Keith Packard417e8222011-11-01 19:54:11 -0700882 /* Preserve the BIOS-computed detected bit. This is
883 * supposed to be read-only.
884 */
885 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700886
Keith Packard417e8222011-11-01 19:54:11 -0700887 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -0700888 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700889
Chris Wilsonea5b2132010-08-04 13:50:23 +0100890 switch (intel_dp->lane_count) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700891 case 1:
Chris Wilsonea5b2132010-08-04 13:50:23 +0100892 intel_dp->DP |= DP_PORT_WIDTH_1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700893 break;
894 case 2:
Chris Wilsonea5b2132010-08-04 13:50:23 +0100895 intel_dp->DP |= DP_PORT_WIDTH_2;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700896 break;
897 case 4:
Chris Wilsonea5b2132010-08-04 13:50:23 +0100898 intel_dp->DP |= DP_PORT_WIDTH_4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700899 break;
900 }
Wu Fengguange0dac652011-09-05 14:25:34 +0800901 if (intel_dp->has_audio) {
902 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
903 pipe_name(intel_crtc->pipe));
Chris Wilsonea5b2132010-08-04 13:50:23 +0100904 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Wu Fengguange0dac652011-09-05 14:25:34 +0800905 intel_write_eld(encoder, adjusted_mode);
906 }
Paulo Zanoni247d89f2012-10-15 15:51:33 -0300907
908 intel_dp_init_link_config(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700909
Keith Packard417e8222011-11-01 19:54:11 -0700910 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800911
Gajanan Bhat19c03922012-09-27 19:13:07 +0530912 if (is_cpu_edp(intel_dp) && IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) {
Keith Packard1a2eb462011-11-16 16:26:07 -0800913 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
914 intel_dp->DP |= DP_SYNC_HS_HIGH;
915 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
916 intel_dp->DP |= DP_SYNC_VS_HIGH;
917 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
918
919 if (intel_dp->link_configuration[1] & DP_LANE_COUNT_ENHANCED_FRAME_EN)
920 intel_dp->DP |= DP_ENHANCED_FRAMING;
921
922 intel_dp->DP |= intel_crtc->pipe << 29;
923
924 /* don't miss out required setting for eDP */
Keith Packard1a2eb462011-11-16 16:26:07 -0800925 if (adjusted_mode->clock < 200000)
926 intel_dp->DP |= DP_PLL_FREQ_160MHZ;
927 else
928 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
929 } else if (!HAS_PCH_CPT(dev) || is_cpu_edp(intel_dp)) {
Keith Packard417e8222011-11-01 19:54:11 -0700930 intel_dp->DP |= intel_dp->color_range;
931
932 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
933 intel_dp->DP |= DP_SYNC_HS_HIGH;
934 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
935 intel_dp->DP |= DP_SYNC_VS_HIGH;
936 intel_dp->DP |= DP_LINK_TRAIN_OFF;
937
938 if (intel_dp->link_configuration[1] & DP_LANE_COUNT_ENHANCED_FRAME_EN)
939 intel_dp->DP |= DP_ENHANCED_FRAMING;
940
941 if (intel_crtc->pipe == 1)
942 intel_dp->DP |= DP_PIPEB_SELECT;
943
944 if (is_cpu_edp(intel_dp)) {
945 /* don't miss out required setting for eDP */
Keith Packard417e8222011-11-01 19:54:11 -0700946 if (adjusted_mode->clock < 200000)
947 intel_dp->DP |= DP_PLL_FREQ_160MHZ;
948 else
949 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
950 }
951 } else {
952 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800953 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700954}
955
Keith Packard99ea7122011-11-01 19:57:50 -0700956#define IDLE_ON_MASK (PP_ON | 0 | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
957#define IDLE_ON_VALUE (PP_ON | 0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
958
959#define IDLE_OFF_MASK (PP_ON | 0 | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
960#define IDLE_OFF_VALUE (0 | 0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
961
962#define IDLE_CYCLE_MASK (PP_ON | 0 | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
963#define IDLE_CYCLE_VALUE (0 | 0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
964
965static void ironlake_wait_panel_status(struct intel_dp *intel_dp,
966 u32 mask,
967 u32 value)
968{
969 struct drm_device *dev = intel_dp->base.base.dev;
970 struct drm_i915_private *dev_priv = dev->dev_private;
971
972 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
973 mask, value,
974 I915_READ(PCH_PP_STATUS),
975 I915_READ(PCH_PP_CONTROL));
976
977 if (_wait_for((I915_READ(PCH_PP_STATUS) & mask) == value, 5000, 10)) {
978 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
979 I915_READ(PCH_PP_STATUS),
980 I915_READ(PCH_PP_CONTROL));
981 }
982}
983
984static void ironlake_wait_panel_on(struct intel_dp *intel_dp)
985{
986 DRM_DEBUG_KMS("Wait for panel power on\n");
987 ironlake_wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
988}
989
Keith Packardbd943152011-09-18 23:09:52 -0700990static void ironlake_wait_panel_off(struct intel_dp *intel_dp)
991{
Keith Packardbd943152011-09-18 23:09:52 -0700992 DRM_DEBUG_KMS("Wait for panel power off time\n");
Keith Packard99ea7122011-11-01 19:57:50 -0700993 ironlake_wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -0700994}
Keith Packardbd943152011-09-18 23:09:52 -0700995
Keith Packard99ea7122011-11-01 19:57:50 -0700996static void ironlake_wait_panel_power_cycle(struct intel_dp *intel_dp)
997{
998 DRM_DEBUG_KMS("Wait for panel power cycle\n");
999 ironlake_wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
1000}
Keith Packardbd943152011-09-18 23:09:52 -07001001
Keith Packard99ea7122011-11-01 19:57:50 -07001002
Keith Packard832dd3c2011-11-01 19:34:06 -07001003/* Read the current pp_control value, unlocking the register if it
1004 * is locked
1005 */
1006
1007static u32 ironlake_get_pp_control(struct drm_i915_private *dev_priv)
1008{
1009 u32 control = I915_READ(PCH_PP_CONTROL);
1010
1011 control &= ~PANEL_UNLOCK_MASK;
1012 control |= PANEL_UNLOCK_REGS;
1013 return control;
Keith Packardbd943152011-09-18 23:09:52 -07001014}
1015
Jesse Barnes5d613502011-01-24 17:10:54 -08001016static void ironlake_edp_panel_vdd_on(struct intel_dp *intel_dp)
1017{
1018 struct drm_device *dev = intel_dp->base.base.dev;
1019 struct drm_i915_private *dev_priv = dev->dev_private;
1020 u32 pp;
1021
Keith Packard97af61f572011-09-28 16:23:51 -07001022 if (!is_edp(intel_dp))
1023 return;
Keith Packardf01eca22011-09-28 16:48:10 -07001024 DRM_DEBUG_KMS("Turn eDP VDD on\n");
Jesse Barnes5d613502011-01-24 17:10:54 -08001025
Keith Packardbd943152011-09-18 23:09:52 -07001026 WARN(intel_dp->want_panel_vdd,
1027 "eDP VDD already requested on\n");
1028
1029 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07001030
Keith Packardbd943152011-09-18 23:09:52 -07001031 if (ironlake_edp_have_panel_vdd(intel_dp)) {
1032 DRM_DEBUG_KMS("eDP VDD already on\n");
1033 return;
1034 }
1035
Keith Packard99ea7122011-11-01 19:57:50 -07001036 if (!ironlake_edp_have_panel_power(intel_dp))
1037 ironlake_wait_panel_power_cycle(intel_dp);
1038
Keith Packard832dd3c2011-11-01 19:34:06 -07001039 pp = ironlake_get_pp_control(dev_priv);
Jesse Barnes5d613502011-01-24 17:10:54 -08001040 pp |= EDP_FORCE_VDD;
1041 I915_WRITE(PCH_PP_CONTROL, pp);
1042 POSTING_READ(PCH_PP_CONTROL);
Keith Packardf01eca22011-09-28 16:48:10 -07001043 DRM_DEBUG_KMS("PCH_PP_STATUS: 0x%08x PCH_PP_CONTROL: 0x%08x\n",
1044 I915_READ(PCH_PP_STATUS), I915_READ(PCH_PP_CONTROL));
Keith Packardebf33b12011-09-29 15:53:27 -07001045
1046 /*
1047 * If the panel wasn't on, delay before accessing aux channel
1048 */
1049 if (!ironlake_edp_have_panel_power(intel_dp)) {
Keith Packardbd943152011-09-18 23:09:52 -07001050 DRM_DEBUG_KMS("eDP was not running\n");
Keith Packardf01eca22011-09-28 16:48:10 -07001051 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07001052 }
Jesse Barnes5d613502011-01-24 17:10:54 -08001053}
1054
Keith Packardbd943152011-09-18 23:09:52 -07001055static void ironlake_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001056{
1057 struct drm_device *dev = intel_dp->base.base.dev;
1058 struct drm_i915_private *dev_priv = dev->dev_private;
1059 u32 pp;
1060
Keith Packardbd943152011-09-18 23:09:52 -07001061 if (!intel_dp->want_panel_vdd && ironlake_edp_have_panel_vdd(intel_dp)) {
Keith Packard832dd3c2011-11-01 19:34:06 -07001062 pp = ironlake_get_pp_control(dev_priv);
Keith Packardbd943152011-09-18 23:09:52 -07001063 pp &= ~EDP_FORCE_VDD;
1064 I915_WRITE(PCH_PP_CONTROL, pp);
1065 POSTING_READ(PCH_PP_CONTROL);
Jesse Barnes5d613502011-01-24 17:10:54 -08001066
Keith Packardbd943152011-09-18 23:09:52 -07001067 /* Make sure sequencer is idle before allowing subsequent activity */
1068 DRM_DEBUG_KMS("PCH_PP_STATUS: 0x%08x PCH_PP_CONTROL: 0x%08x\n",
1069 I915_READ(PCH_PP_STATUS), I915_READ(PCH_PP_CONTROL));
Keith Packard99ea7122011-11-01 19:57:50 -07001070
1071 msleep(intel_dp->panel_power_down_delay);
Keith Packardbd943152011-09-18 23:09:52 -07001072 }
1073}
1074
1075static void ironlake_panel_vdd_work(struct work_struct *__work)
1076{
1077 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
1078 struct intel_dp, panel_vdd_work);
1079 struct drm_device *dev = intel_dp->base.base.dev;
1080
Keith Packard627f7672011-10-31 11:30:10 -07001081 mutex_lock(&dev->mode_config.mutex);
Keith Packardbd943152011-09-18 23:09:52 -07001082 ironlake_panel_vdd_off_sync(intel_dp);
Keith Packard627f7672011-10-31 11:30:10 -07001083 mutex_unlock(&dev->mode_config.mutex);
Keith Packardbd943152011-09-18 23:09:52 -07001084}
1085
1086static void ironlake_edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
1087{
Keith Packard97af61f572011-09-28 16:23:51 -07001088 if (!is_edp(intel_dp))
1089 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08001090
Keith Packardbd943152011-09-18 23:09:52 -07001091 DRM_DEBUG_KMS("Turn eDP VDD off %d\n", intel_dp->want_panel_vdd);
1092 WARN(!intel_dp->want_panel_vdd, "eDP VDD not forced on");
Keith Packardf2e8b182011-11-01 20:01:35 -07001093
Keith Packardbd943152011-09-18 23:09:52 -07001094 intel_dp->want_panel_vdd = false;
1095
1096 if (sync) {
1097 ironlake_panel_vdd_off_sync(intel_dp);
1098 } else {
1099 /*
1100 * Queue the timer to fire a long
1101 * time from now (relative to the power down delay)
1102 * to keep the panel power up across a sequence of operations
1103 */
1104 schedule_delayed_work(&intel_dp->panel_vdd_work,
1105 msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5));
1106 }
Jesse Barnes5d613502011-01-24 17:10:54 -08001107}
1108
Keith Packard86a30732011-10-20 13:40:33 -07001109static void ironlake_edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07001110{
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001111 struct drm_device *dev = intel_dp->base.base.dev;
Jesse Barnes9934c132010-07-22 13:18:19 -07001112 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packard99ea7122011-11-01 19:57:50 -07001113 u32 pp;
Jesse Barnes9934c132010-07-22 13:18:19 -07001114
Keith Packard97af61f572011-09-28 16:23:51 -07001115 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07001116 return;
Keith Packard99ea7122011-11-01 19:57:50 -07001117
1118 DRM_DEBUG_KMS("Turn eDP power on\n");
1119
1120 if (ironlake_edp_have_panel_power(intel_dp)) {
1121 DRM_DEBUG_KMS("eDP power already on\n");
Keith Packard7d639f32011-09-29 16:05:34 -07001122 return;
Keith Packard99ea7122011-11-01 19:57:50 -07001123 }
Jesse Barnes9934c132010-07-22 13:18:19 -07001124
Keith Packard99ea7122011-11-01 19:57:50 -07001125 ironlake_wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001126
Keith Packard832dd3c2011-11-01 19:34:06 -07001127 pp = ironlake_get_pp_control(dev_priv);
Keith Packard05ce1a42011-09-29 16:33:01 -07001128 if (IS_GEN5(dev)) {
1129 /* ILK workaround: disable reset around power sequence */
1130 pp &= ~PANEL_POWER_RESET;
1131 I915_WRITE(PCH_PP_CONTROL, pp);
1132 POSTING_READ(PCH_PP_CONTROL);
1133 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001134
Keith Packard1c0ae802011-09-19 13:59:29 -07001135 pp |= POWER_TARGET_ON;
Keith Packard99ea7122011-11-01 19:57:50 -07001136 if (!IS_GEN5(dev))
1137 pp |= PANEL_POWER_RESET;
1138
Jesse Barnes9934c132010-07-22 13:18:19 -07001139 I915_WRITE(PCH_PP_CONTROL, pp);
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001140 POSTING_READ(PCH_PP_CONTROL);
Jesse Barnes9934c132010-07-22 13:18:19 -07001141
Keith Packard99ea7122011-11-01 19:57:50 -07001142 ironlake_wait_panel_on(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07001143
Keith Packard05ce1a42011-09-29 16:33:01 -07001144 if (IS_GEN5(dev)) {
1145 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
1146 I915_WRITE(PCH_PP_CONTROL, pp);
1147 POSTING_READ(PCH_PP_CONTROL);
1148 }
Jesse Barnes9934c132010-07-22 13:18:19 -07001149}
1150
Keith Packard99ea7122011-11-01 19:57:50 -07001151static void ironlake_edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07001152{
Keith Packard99ea7122011-11-01 19:57:50 -07001153 struct drm_device *dev = intel_dp->base.base.dev;
Jesse Barnes9934c132010-07-22 13:18:19 -07001154 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packard99ea7122011-11-01 19:57:50 -07001155 u32 pp;
Jesse Barnes9934c132010-07-22 13:18:19 -07001156
Keith Packard97af61f572011-09-28 16:23:51 -07001157 if (!is_edp(intel_dp))
1158 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001159
Keith Packard99ea7122011-11-01 19:57:50 -07001160 DRM_DEBUG_KMS("Turn eDP power off\n");
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001161
Daniel Vetter6cb49832012-05-20 17:14:50 +02001162 WARN(!intel_dp->want_panel_vdd, "Need VDD to turn off panel\n");
Jesse Barnes9934c132010-07-22 13:18:19 -07001163
Keith Packard832dd3c2011-11-01 19:34:06 -07001164 pp = ironlake_get_pp_control(dev_priv);
Daniel Vetter35a38552012-08-12 22:17:14 +02001165 /* We need to switch off panel power _and_ force vdd, for otherwise some
1166 * panels get very unhappy and cease to work. */
1167 pp &= ~(POWER_TARGET_ON | EDP_FORCE_VDD | PANEL_POWER_RESET | EDP_BLC_ENABLE);
Keith Packard99ea7122011-11-01 19:57:50 -07001168 I915_WRITE(PCH_PP_CONTROL, pp);
1169 POSTING_READ(PCH_PP_CONTROL);
Jesse Barnes9934c132010-07-22 13:18:19 -07001170
Daniel Vetter35a38552012-08-12 22:17:14 +02001171 intel_dp->want_panel_vdd = false;
1172
Keith Packard99ea7122011-11-01 19:57:50 -07001173 ironlake_wait_panel_off(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07001174}
1175
Keith Packard86a30732011-10-20 13:40:33 -07001176static void ironlake_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001177{
Keith Packardf01eca22011-09-28 16:48:10 -07001178 struct drm_device *dev = intel_dp->base.base.dev;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001179 struct drm_i915_private *dev_priv = dev->dev_private;
1180 u32 pp;
1181
Keith Packardf01eca22011-09-28 16:48:10 -07001182 if (!is_edp(intel_dp))
1183 return;
1184
Zhao Yakui28c97732009-10-09 11:39:41 +08001185 DRM_DEBUG_KMS("\n");
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001186 /*
1187 * If we enable the backlight right away following a panel power
1188 * on, we may see slight flicker as the panel syncs with the eDP
1189 * link. So delay a bit to make sure the image is solid before
1190 * allowing it to appear.
1191 */
Keith Packardf01eca22011-09-28 16:48:10 -07001192 msleep(intel_dp->backlight_on_delay);
Keith Packard832dd3c2011-11-01 19:34:06 -07001193 pp = ironlake_get_pp_control(dev_priv);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001194 pp |= EDP_BLC_ENABLE;
1195 I915_WRITE(PCH_PP_CONTROL, pp);
Keith Packardf01eca22011-09-28 16:48:10 -07001196 POSTING_READ(PCH_PP_CONTROL);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001197}
1198
Keith Packard86a30732011-10-20 13:40:33 -07001199static void ironlake_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001200{
Keith Packardf01eca22011-09-28 16:48:10 -07001201 struct drm_device *dev = intel_dp->base.base.dev;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001202 struct drm_i915_private *dev_priv = dev->dev_private;
1203 u32 pp;
1204
Keith Packardf01eca22011-09-28 16:48:10 -07001205 if (!is_edp(intel_dp))
1206 return;
1207
Zhao Yakui28c97732009-10-09 11:39:41 +08001208 DRM_DEBUG_KMS("\n");
Keith Packard832dd3c2011-11-01 19:34:06 -07001209 pp = ironlake_get_pp_control(dev_priv);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001210 pp &= ~EDP_BLC_ENABLE;
1211 I915_WRITE(PCH_PP_CONTROL, pp);
Keith Packardf01eca22011-09-28 16:48:10 -07001212 POSTING_READ(PCH_PP_CONTROL);
1213 msleep(intel_dp->backlight_off_delay);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001214}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001215
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001216static void ironlake_edp_pll_on(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07001217{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001218 struct drm_device *dev = intel_dp->base.base.dev;
1219 struct drm_crtc *crtc = intel_dp->base.base.crtc;
Jesse Barnesd240f202010-08-13 15:43:26 -07001220 struct drm_i915_private *dev_priv = dev->dev_private;
1221 u32 dpa_ctl;
1222
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001223 assert_pipe_disabled(dev_priv,
1224 to_intel_crtc(crtc)->pipe);
1225
Jesse Barnesd240f202010-08-13 15:43:26 -07001226 DRM_DEBUG_KMS("\n");
1227 dpa_ctl = I915_READ(DP_A);
Daniel Vetter07679352012-09-06 22:15:42 +02001228 WARN(dpa_ctl & DP_PLL_ENABLE, "dp pll on, should be off\n");
1229 WARN(dpa_ctl & DP_PORT_EN, "dp port still on, should be off\n");
1230
1231 /* We don't adjust intel_dp->DP while tearing down the link, to
1232 * facilitate link retraining (e.g. after hotplug). Hence clear all
1233 * enable bits here to ensure that we don't enable too much. */
1234 intel_dp->DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
1235 intel_dp->DP |= DP_PLL_ENABLE;
1236 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07001237 POSTING_READ(DP_A);
1238 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07001239}
1240
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001241static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07001242{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001243 struct drm_device *dev = intel_dp->base.base.dev;
1244 struct drm_crtc *crtc = intel_dp->base.base.crtc;
Jesse Barnesd240f202010-08-13 15:43:26 -07001245 struct drm_i915_private *dev_priv = dev->dev_private;
1246 u32 dpa_ctl;
1247
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001248 assert_pipe_disabled(dev_priv,
1249 to_intel_crtc(crtc)->pipe);
1250
Jesse Barnesd240f202010-08-13 15:43:26 -07001251 dpa_ctl = I915_READ(DP_A);
Daniel Vetter07679352012-09-06 22:15:42 +02001252 WARN((dpa_ctl & DP_PLL_ENABLE) == 0,
1253 "dp pll off, should be on\n");
1254 WARN(dpa_ctl & DP_PORT_EN, "dp port still on, should be off\n");
1255
1256 /* We can't rely on the value tracked for the DP register in
1257 * intel_dp->DP because link_down must not change that (otherwise link
1258 * re-training will fail. */
Jesse Barnes298b0b32010-10-07 16:01:24 -07001259 dpa_ctl &= ~DP_PLL_ENABLE;
Jesse Barnesd240f202010-08-13 15:43:26 -07001260 I915_WRITE(DP_A, dpa_ctl);
Chris Wilson1af5fa12010-09-08 21:07:28 +01001261 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07001262 udelay(200);
1263}
1264
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001265/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03001266void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001267{
1268 int ret, i;
1269
1270 /* Should have a valid DPCD by this point */
1271 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
1272 return;
1273
1274 if (mode != DRM_MODE_DPMS_ON) {
1275 ret = intel_dp_aux_native_write_1(intel_dp, DP_SET_POWER,
1276 DP_SET_POWER_D3);
1277 if (ret != 1)
1278 DRM_DEBUG_DRIVER("failed to write sink power state\n");
1279 } else {
1280 /*
1281 * When turning on, we need to retry for 1ms to give the sink
1282 * time to wake up.
1283 */
1284 for (i = 0; i < 3; i++) {
1285 ret = intel_dp_aux_native_write_1(intel_dp,
1286 DP_SET_POWER,
1287 DP_SET_POWER_D0);
1288 if (ret == 1)
1289 break;
1290 msleep(1);
1291 }
1292 }
1293}
1294
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001295static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
1296 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07001297{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001298 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1299 struct drm_device *dev = encoder->base.dev;
1300 struct drm_i915_private *dev_priv = dev->dev_private;
1301 u32 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07001302
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001303 if (!(tmp & DP_PORT_EN))
1304 return false;
1305
1306 if (is_cpu_edp(intel_dp) && IS_GEN7(dev)) {
1307 *pipe = PORT_TO_PIPE_CPT(tmp);
1308 } else if (!HAS_PCH_CPT(dev) || is_cpu_edp(intel_dp)) {
1309 *pipe = PORT_TO_PIPE(tmp);
1310 } else {
1311 u32 trans_sel;
1312 u32 trans_dp;
1313 int i;
1314
1315 switch (intel_dp->output_reg) {
1316 case PCH_DP_B:
1317 trans_sel = TRANS_DP_PORT_SEL_B;
1318 break;
1319 case PCH_DP_C:
1320 trans_sel = TRANS_DP_PORT_SEL_C;
1321 break;
1322 case PCH_DP_D:
1323 trans_sel = TRANS_DP_PORT_SEL_D;
1324 break;
1325 default:
1326 return true;
1327 }
1328
1329 for_each_pipe(i) {
1330 trans_dp = I915_READ(TRANS_DP_CTL(i));
1331 if ((trans_dp & TRANS_DP_PORT_SEL_MASK) == trans_sel) {
1332 *pipe = i;
1333 return true;
1334 }
1335 }
1336 }
1337
1338 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n", intel_dp->output_reg);
1339
1340 return true;
1341}
1342
Daniel Vettere8cb4552012-07-01 13:05:48 +02001343static void intel_disable_dp(struct intel_encoder *encoder)
Jesse Barnesd240f202010-08-13 15:43:26 -07001344{
Daniel Vettere8cb4552012-07-01 13:05:48 +02001345 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Daniel Vetter6cb49832012-05-20 17:14:50 +02001346
1347 /* Make sure the panel is off before trying to change the mode. But also
1348 * ensure that we have vdd while we switch off the panel. */
1349 ironlake_edp_panel_vdd_on(intel_dp);
Keith Packard21264c62011-11-01 20:25:21 -07001350 ironlake_edp_backlight_off(intel_dp);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001351 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
Daniel Vetter35a38552012-08-12 22:17:14 +02001352 ironlake_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02001353
1354 /* cpu edp my only be disable _after_ the cpu pipe/plane is disabled. */
1355 if (!is_cpu_edp(intel_dp))
1356 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07001357}
1358
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001359static void intel_post_disable_dp(struct intel_encoder *encoder)
1360{
1361 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1362
Daniel Vetter37398502012-09-06 22:15:44 +02001363 if (is_cpu_edp(intel_dp)) {
1364 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001365 ironlake_edp_pll_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02001366 }
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001367}
1368
Daniel Vettere8cb4552012-07-01 13:05:48 +02001369static void intel_enable_dp(struct intel_encoder *encoder)
Jesse Barnesd240f202010-08-13 15:43:26 -07001370{
Daniel Vettere8cb4552012-07-01 13:05:48 +02001371 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1372 struct drm_device *dev = encoder->base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001373 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001374 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001375
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02001376 if (WARN_ON(dp_reg & DP_PORT_EN))
1377 return;
1378
Daniel Vettere8cb4552012-07-01 13:05:48 +02001379 ironlake_edp_panel_vdd_on(intel_dp);
1380 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02001381 intel_dp_start_link_train(intel_dp);
1382 ironlake_edp_panel_on(intel_dp);
1383 ironlake_edp_panel_vdd_off(intel_dp, true);
1384 intel_dp_complete_link_train(intel_dp);
Daniel Vettere8cb4552012-07-01 13:05:48 +02001385 ironlake_edp_backlight_on(intel_dp);
Daniel Vettere8cb4552012-07-01 13:05:48 +02001386}
1387
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001388static void intel_pre_enable_dp(struct intel_encoder *encoder)
Daniel Vettere8cb4552012-07-01 13:05:48 +02001389{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001390 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Daniel Vettere8cb4552012-07-01 13:05:48 +02001391
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001392 if (is_cpu_edp(intel_dp))
1393 ironlake_edp_pll_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001394}
1395
1396/*
Jesse Barnesdf0c2372011-07-07 11:11:02 -07001397 * Native read with retry for link status and receiver capability reads for
1398 * cases where the sink may still be asleep.
1399 */
1400static bool
1401intel_dp_aux_native_read_retry(struct intel_dp *intel_dp, uint16_t address,
1402 uint8_t *recv, int recv_bytes)
1403{
1404 int ret, i;
1405
1406 /*
1407 * Sinks are *supposed* to come up within 1ms from an off state,
1408 * but we're also supposed to retry 3 times per the spec.
1409 */
1410 for (i = 0; i < 3; i++) {
1411 ret = intel_dp_aux_native_read(intel_dp, address, recv,
1412 recv_bytes);
1413 if (ret == recv_bytes)
1414 return true;
1415 msleep(1);
1416 }
1417
1418 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001419}
1420
1421/*
1422 * Fetch AUX CH registers 0x202 - 0x207 which contain
1423 * link status information
1424 */
1425static bool
Keith Packard93f62da2011-11-01 19:45:03 -07001426intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001427{
Jesse Barnesdf0c2372011-07-07 11:11:02 -07001428 return intel_dp_aux_native_read_retry(intel_dp,
1429 DP_LANE0_1_STATUS,
Keith Packard93f62da2011-11-01 19:45:03 -07001430 link_status,
Jesse Barnesdf0c2372011-07-07 11:11:02 -07001431 DP_LINK_STATUS_SIZE);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001432}
1433
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001434#if 0
1435static char *voltage_names[] = {
1436 "0.4V", "0.6V", "0.8V", "1.2V"
1437};
1438static char *pre_emph_names[] = {
1439 "0dB", "3.5dB", "6dB", "9.5dB"
1440};
1441static char *link_train_names[] = {
1442 "pattern 1", "pattern 2", "idle", "off"
1443};
1444#endif
1445
1446/*
1447 * These are source-specific values; current Intel hardware supports
1448 * a maximum voltage of 800mV and a maximum pre-emphasis of 6dB
1449 */
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001450
1451static uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08001452intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001453{
Keith Packard1a2eb462011-11-16 16:26:07 -08001454 struct drm_device *dev = intel_dp->base.base.dev;
1455
1456 if (IS_GEN7(dev) && is_cpu_edp(intel_dp))
1457 return DP_TRAIN_VOLTAGE_SWING_800;
1458 else if (HAS_PCH_CPT(dev) && !is_cpu_edp(intel_dp))
1459 return DP_TRAIN_VOLTAGE_SWING_1200;
1460 else
1461 return DP_TRAIN_VOLTAGE_SWING_800;
1462}
1463
1464static uint8_t
1465intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
1466{
1467 struct drm_device *dev = intel_dp->base.base.dev;
1468
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001469 if (IS_HASWELL(dev)) {
1470 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
1471 case DP_TRAIN_VOLTAGE_SWING_400:
1472 return DP_TRAIN_PRE_EMPHASIS_9_5;
1473 case DP_TRAIN_VOLTAGE_SWING_600:
1474 return DP_TRAIN_PRE_EMPHASIS_6;
1475 case DP_TRAIN_VOLTAGE_SWING_800:
1476 return DP_TRAIN_PRE_EMPHASIS_3_5;
1477 case DP_TRAIN_VOLTAGE_SWING_1200:
1478 default:
1479 return DP_TRAIN_PRE_EMPHASIS_0;
1480 }
1481 } else if (IS_GEN7(dev) && is_cpu_edp(intel_dp) && !IS_VALLEYVIEW(dev)) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001482 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
1483 case DP_TRAIN_VOLTAGE_SWING_400:
1484 return DP_TRAIN_PRE_EMPHASIS_6;
1485 case DP_TRAIN_VOLTAGE_SWING_600:
1486 case DP_TRAIN_VOLTAGE_SWING_800:
1487 return DP_TRAIN_PRE_EMPHASIS_3_5;
1488 default:
1489 return DP_TRAIN_PRE_EMPHASIS_0;
1490 }
1491 } else {
1492 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
1493 case DP_TRAIN_VOLTAGE_SWING_400:
1494 return DP_TRAIN_PRE_EMPHASIS_6;
1495 case DP_TRAIN_VOLTAGE_SWING_600:
1496 return DP_TRAIN_PRE_EMPHASIS_6;
1497 case DP_TRAIN_VOLTAGE_SWING_800:
1498 return DP_TRAIN_PRE_EMPHASIS_3_5;
1499 case DP_TRAIN_VOLTAGE_SWING_1200:
1500 default:
1501 return DP_TRAIN_PRE_EMPHASIS_0;
1502 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001503 }
1504}
1505
1506static void
Keith Packard93f62da2011-11-01 19:45:03 -07001507intel_get_adjust_train(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001508{
1509 uint8_t v = 0;
1510 uint8_t p = 0;
1511 int lane;
Keith Packard1a2eb462011-11-16 16:26:07 -08001512 uint8_t voltage_max;
1513 uint8_t preemph_max;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001514
Jesse Barnes33a34e42010-09-08 12:42:02 -07001515 for (lane = 0; lane < intel_dp->lane_count; lane++) {
Daniel Vetter0f037bd2012-10-18 10:15:27 +02001516 uint8_t this_v = drm_dp_get_adjust_request_voltage(link_status, lane);
1517 uint8_t this_p = drm_dp_get_adjust_request_pre_emphasis(link_status, lane);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001518
1519 if (this_v > v)
1520 v = this_v;
1521 if (this_p > p)
1522 p = this_p;
1523 }
1524
Keith Packard1a2eb462011-11-16 16:26:07 -08001525 voltage_max = intel_dp_voltage_max(intel_dp);
Keith Packard417e8222011-11-01 19:54:11 -07001526 if (v >= voltage_max)
1527 v = voltage_max | DP_TRAIN_MAX_SWING_REACHED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001528
Keith Packard1a2eb462011-11-16 16:26:07 -08001529 preemph_max = intel_dp_pre_emphasis_max(intel_dp, v);
1530 if (p >= preemph_max)
1531 p = preemph_max | DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001532
1533 for (lane = 0; lane < 4; lane++)
Jesse Barnes33a34e42010-09-08 12:42:02 -07001534 intel_dp->train_set[lane] = v | p;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001535}
1536
1537static uint32_t
Keith Packard93f62da2011-11-01 19:45:03 -07001538intel_dp_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001539{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001540 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001541
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001542 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001543 case DP_TRAIN_VOLTAGE_SWING_400:
1544 default:
1545 signal_levels |= DP_VOLTAGE_0_4;
1546 break;
1547 case DP_TRAIN_VOLTAGE_SWING_600:
1548 signal_levels |= DP_VOLTAGE_0_6;
1549 break;
1550 case DP_TRAIN_VOLTAGE_SWING_800:
1551 signal_levels |= DP_VOLTAGE_0_8;
1552 break;
1553 case DP_TRAIN_VOLTAGE_SWING_1200:
1554 signal_levels |= DP_VOLTAGE_1_2;
1555 break;
1556 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001557 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001558 case DP_TRAIN_PRE_EMPHASIS_0:
1559 default:
1560 signal_levels |= DP_PRE_EMPHASIS_0;
1561 break;
1562 case DP_TRAIN_PRE_EMPHASIS_3_5:
1563 signal_levels |= DP_PRE_EMPHASIS_3_5;
1564 break;
1565 case DP_TRAIN_PRE_EMPHASIS_6:
1566 signal_levels |= DP_PRE_EMPHASIS_6;
1567 break;
1568 case DP_TRAIN_PRE_EMPHASIS_9_5:
1569 signal_levels |= DP_PRE_EMPHASIS_9_5;
1570 break;
1571 }
1572 return signal_levels;
1573}
1574
Zhenyu Wange3421a12010-04-08 09:43:27 +08001575/* Gen6's DP voltage swing and pre-emphasis control */
1576static uint32_t
1577intel_gen6_edp_signal_levels(uint8_t train_set)
1578{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001579 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
1580 DP_TRAIN_PRE_EMPHASIS_MASK);
1581 switch (signal_levels) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08001582 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001583 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
1584 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
1585 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
1586 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001587 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001588 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
1589 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001590 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001591 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
1592 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001593 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001594 case DP_TRAIN_VOLTAGE_SWING_1200 | DP_TRAIN_PRE_EMPHASIS_0:
1595 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001596 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001597 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
1598 "0x%x\n", signal_levels);
1599 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001600 }
1601}
1602
Keith Packard1a2eb462011-11-16 16:26:07 -08001603/* Gen7's DP voltage swing and pre-emphasis control */
1604static uint32_t
1605intel_gen7_edp_signal_levels(uint8_t train_set)
1606{
1607 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
1608 DP_TRAIN_PRE_EMPHASIS_MASK);
1609 switch (signal_levels) {
1610 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
1611 return EDP_LINK_TRAIN_400MV_0DB_IVB;
1612 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
1613 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
1614 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
1615 return EDP_LINK_TRAIN_400MV_6DB_IVB;
1616
1617 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
1618 return EDP_LINK_TRAIN_600MV_0DB_IVB;
1619 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
1620 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
1621
1622 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
1623 return EDP_LINK_TRAIN_800MV_0DB_IVB;
1624 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
1625 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
1626
1627 default:
1628 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
1629 "0x%x\n", signal_levels);
1630 return EDP_LINK_TRAIN_500MV_0DB_IVB;
1631 }
1632}
1633
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001634/* Gen7.5's (HSW) DP voltage swing and pre-emphasis control */
1635static uint32_t
1636intel_dp_signal_levels_hsw(uint8_t train_set)
1637{
1638 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
1639 DP_TRAIN_PRE_EMPHASIS_MASK);
1640 switch (signal_levels) {
1641 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
1642 return DDI_BUF_EMP_400MV_0DB_HSW;
1643 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
1644 return DDI_BUF_EMP_400MV_3_5DB_HSW;
1645 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
1646 return DDI_BUF_EMP_400MV_6DB_HSW;
1647 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_9_5:
1648 return DDI_BUF_EMP_400MV_9_5DB_HSW;
1649
1650 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
1651 return DDI_BUF_EMP_600MV_0DB_HSW;
1652 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
1653 return DDI_BUF_EMP_600MV_3_5DB_HSW;
1654 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
1655 return DDI_BUF_EMP_600MV_6DB_HSW;
1656
1657 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
1658 return DDI_BUF_EMP_800MV_0DB_HSW;
1659 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
1660 return DDI_BUF_EMP_800MV_3_5DB_HSW;
1661 default:
1662 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
1663 "0x%x\n", signal_levels);
1664 return DDI_BUF_EMP_400MV_0DB_HSW;
1665 }
1666}
1667
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001668static bool
Chris Wilsonea5b2132010-08-04 13:50:23 +01001669intel_dp_set_link_train(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001670 uint32_t dp_reg_value,
Chris Wilson58e10eb2010-10-03 10:56:11 +01001671 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001672{
Chris Wilson4ef69c72010-09-09 15:14:28 +01001673 struct drm_device *dev = intel_dp->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001674 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001675 int ret;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001676 uint32_t temp;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001677
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001678 if (IS_HASWELL(dev)) {
1679 temp = I915_READ(DP_TP_CTL(intel_dp->port));
1680
1681 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
1682 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
1683 else
1684 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
1685
1686 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
1687 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
1688 case DP_TRAINING_PATTERN_DISABLE:
1689 temp |= DP_TP_CTL_LINK_TRAIN_IDLE;
1690 I915_WRITE(DP_TP_CTL(intel_dp->port), temp);
1691
1692 if (wait_for((I915_READ(DP_TP_STATUS(intel_dp->port)) &
1693 DP_TP_STATUS_IDLE_DONE), 1))
1694 DRM_ERROR("Timed out waiting for DP idle patterns\n");
1695
1696 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
1697 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
1698
1699 break;
1700 case DP_TRAINING_PATTERN_1:
1701 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
1702 break;
1703 case DP_TRAINING_PATTERN_2:
1704 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
1705 break;
1706 case DP_TRAINING_PATTERN_3:
1707 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
1708 break;
1709 }
1710 I915_WRITE(DP_TP_CTL(intel_dp->port), temp);
1711
1712 } else if (HAS_PCH_CPT(dev) &&
1713 (IS_GEN7(dev) || !is_cpu_edp(intel_dp))) {
Paulo Zanoni47ea7542012-07-17 16:55:16 -03001714 dp_reg_value &= ~DP_LINK_TRAIN_MASK_CPT;
1715
1716 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
1717 case DP_TRAINING_PATTERN_DISABLE:
1718 dp_reg_value |= DP_LINK_TRAIN_OFF_CPT;
1719 break;
1720 case DP_TRAINING_PATTERN_1:
1721 dp_reg_value |= DP_LINK_TRAIN_PAT_1_CPT;
1722 break;
1723 case DP_TRAINING_PATTERN_2:
1724 dp_reg_value |= DP_LINK_TRAIN_PAT_2_CPT;
1725 break;
1726 case DP_TRAINING_PATTERN_3:
1727 DRM_ERROR("DP training pattern 3 not supported\n");
1728 dp_reg_value |= DP_LINK_TRAIN_PAT_2_CPT;
1729 break;
1730 }
1731
1732 } else {
1733 dp_reg_value &= ~DP_LINK_TRAIN_MASK;
1734
1735 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
1736 case DP_TRAINING_PATTERN_DISABLE:
1737 dp_reg_value |= DP_LINK_TRAIN_OFF;
1738 break;
1739 case DP_TRAINING_PATTERN_1:
1740 dp_reg_value |= DP_LINK_TRAIN_PAT_1;
1741 break;
1742 case DP_TRAINING_PATTERN_2:
1743 dp_reg_value |= DP_LINK_TRAIN_PAT_2;
1744 break;
1745 case DP_TRAINING_PATTERN_3:
1746 DRM_ERROR("DP training pattern 3 not supported\n");
1747 dp_reg_value |= DP_LINK_TRAIN_PAT_2;
1748 break;
1749 }
1750 }
1751
Chris Wilsonea5b2132010-08-04 13:50:23 +01001752 I915_WRITE(intel_dp->output_reg, dp_reg_value);
1753 POSTING_READ(intel_dp->output_reg);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001754
Chris Wilsonea5b2132010-08-04 13:50:23 +01001755 intel_dp_aux_native_write_1(intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001756 DP_TRAINING_PATTERN_SET,
1757 dp_train_pat);
1758
Paulo Zanoni47ea7542012-07-17 16:55:16 -03001759 if ((dp_train_pat & DP_TRAINING_PATTERN_MASK) !=
1760 DP_TRAINING_PATTERN_DISABLE) {
1761 ret = intel_dp_aux_native_write(intel_dp,
1762 DP_TRAINING_LANE0_SET,
1763 intel_dp->train_set,
1764 intel_dp->lane_count);
1765 if (ret != intel_dp->lane_count)
1766 return false;
1767 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001768
1769 return true;
1770}
1771
Jesse Barnes33a34e42010-09-08 12:42:02 -07001772/* Enable corresponding port and start training pattern 1 */
Paulo Zanonic19b0662012-10-15 15:51:41 -03001773void
Jesse Barnes33a34e42010-09-08 12:42:02 -07001774intel_dp_start_link_train(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001775{
Paulo Zanonic19b0662012-10-15 15:51:41 -03001776 struct drm_encoder *encoder = &intel_dp->base.base;
1777 struct drm_device *dev = encoder->dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001778 int i;
1779 uint8_t voltage;
1780 bool clock_recovery = false;
Keith Packardcdb0e952011-11-01 20:00:06 -07001781 int voltage_tries, loop_tries;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001782 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001783
Paulo Zanonic19b0662012-10-15 15:51:41 -03001784 if (IS_HASWELL(dev))
1785 intel_ddi_prepare_link_retrain(encoder);
1786
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001787 /* Write the link configuration data */
1788 intel_dp_aux_native_write(intel_dp, DP_LINK_BW_SET,
1789 intel_dp->link_configuration,
1790 DP_LINK_CONFIGURATION_SIZE);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001791
1792 DP |= DP_PORT_EN;
Keith Packard1a2eb462011-11-16 16:26:07 -08001793
Jesse Barnes33a34e42010-09-08 12:42:02 -07001794 memset(intel_dp->train_set, 0, 4);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001795 voltage = 0xff;
Keith Packardcdb0e952011-11-01 20:00:06 -07001796 voltage_tries = 0;
1797 loop_tries = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001798 clock_recovery = false;
1799 for (;;) {
Jesse Barnes33a34e42010-09-08 12:42:02 -07001800 /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */
Keith Packard93f62da2011-11-01 19:45:03 -07001801 uint8_t link_status[DP_LINK_STATUS_SIZE];
Zhenyu Wange3421a12010-04-08 09:43:27 +08001802 uint32_t signal_levels;
Keith Packard417e8222011-11-01 19:54:11 -07001803
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001804 if (IS_HASWELL(dev)) {
1805 signal_levels = intel_dp_signal_levels_hsw(
1806 intel_dp->train_set[0]);
1807 DP = (DP & ~DDI_BUF_EMP_MASK) | signal_levels;
1808 } else if (IS_GEN7(dev) && is_cpu_edp(intel_dp) && !IS_VALLEYVIEW(dev)) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001809 signal_levels = intel_gen7_edp_signal_levels(intel_dp->train_set[0]);
1810 DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_IVB) | signal_levels;
1811 } else if (IS_GEN6(dev) && is_cpu_edp(intel_dp)) {
Jesse Barnes33a34e42010-09-08 12:42:02 -07001812 signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001813 DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels;
1814 } else {
Keith Packard93f62da2011-11-01 19:45:03 -07001815 signal_levels = intel_dp_signal_levels(intel_dp->train_set[0]);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001816 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
1817 }
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001818 DRM_DEBUG_KMS("training pattern 1 signal levels %08x\n",
1819 signal_levels);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001820
Daniel Vettera7c96552012-10-18 10:15:30 +02001821 /* Set training pattern 1 */
Paulo Zanoni47ea7542012-07-17 16:55:16 -03001822 if (!intel_dp_set_link_train(intel_dp, DP,
Adam Jackson81055852011-07-21 17:48:37 -04001823 DP_TRAINING_PATTERN_1 |
1824 DP_LINK_SCRAMBLING_DISABLE))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001825 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001826
Daniel Vettera7c96552012-10-18 10:15:30 +02001827 drm_dp_link_train_clock_recovery_delay(intel_dp->dpcd);
Keith Packard93f62da2011-11-01 19:45:03 -07001828 if (!intel_dp_get_link_status(intel_dp, link_status)) {
1829 DRM_ERROR("failed to get link status\n");
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001830 break;
Keith Packard93f62da2011-11-01 19:45:03 -07001831 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001832
Daniel Vetter01916272012-10-18 10:15:25 +02001833 if (drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
Keith Packard93f62da2011-11-01 19:45:03 -07001834 DRM_DEBUG_KMS("clock recovery OK\n");
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001835 clock_recovery = true;
1836 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001837 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001838
1839 /* Check to see if we've tried the max voltage */
1840 for (i = 0; i < intel_dp->lane_count; i++)
1841 if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
1842 break;
Paulo Zanoni0d710682012-06-29 16:03:34 -03001843 if (i == intel_dp->lane_count && voltage_tries == 5) {
Chris Wilson24773672012-09-26 16:48:30 +01001844 if (++loop_tries == 5) {
Keith Packardcdb0e952011-11-01 20:00:06 -07001845 DRM_DEBUG_KMS("too many full retries, give up\n");
1846 break;
1847 }
1848 memset(intel_dp->train_set, 0, 4);
1849 voltage_tries = 0;
1850 continue;
1851 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001852
1853 /* Check to see if we've tried the same voltage 5 times */
Chris Wilson24773672012-09-26 16:48:30 +01001854 if ((intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) != voltage) {
1855 voltage = intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
Keith Packardcdb0e952011-11-01 20:00:06 -07001856 voltage_tries = 0;
Chris Wilson24773672012-09-26 16:48:30 +01001857 } else
1858 ++voltage_tries;
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001859
1860 /* Compute new intel_dp->train_set as requested by target */
Keith Packard93f62da2011-11-01 19:45:03 -07001861 intel_get_adjust_train(intel_dp, link_status);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001862 }
1863
Jesse Barnes33a34e42010-09-08 12:42:02 -07001864 intel_dp->DP = DP;
1865}
1866
Paulo Zanonic19b0662012-10-15 15:51:41 -03001867void
Jesse Barnes33a34e42010-09-08 12:42:02 -07001868intel_dp_complete_link_train(struct intel_dp *intel_dp)
1869{
Chris Wilson4ef69c72010-09-09 15:14:28 +01001870 struct drm_device *dev = intel_dp->base.base.dev;
Jesse Barnes33a34e42010-09-08 12:42:02 -07001871 bool channel_eq = false;
Jesse Barnes37f80972011-01-05 14:45:24 -08001872 int tries, cr_tries;
Jesse Barnes33a34e42010-09-08 12:42:02 -07001873 uint32_t DP = intel_dp->DP;
1874
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001875 /* channel equalization */
1876 tries = 0;
Jesse Barnes37f80972011-01-05 14:45:24 -08001877 cr_tries = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001878 channel_eq = false;
1879 for (;;) {
Jesse Barnes33a34e42010-09-08 12:42:02 -07001880 /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */
Zhenyu Wange3421a12010-04-08 09:43:27 +08001881 uint32_t signal_levels;
Keith Packard93f62da2011-11-01 19:45:03 -07001882 uint8_t link_status[DP_LINK_STATUS_SIZE];
Zhenyu Wange3421a12010-04-08 09:43:27 +08001883
Jesse Barnes37f80972011-01-05 14:45:24 -08001884 if (cr_tries > 5) {
1885 DRM_ERROR("failed to train DP, aborting\n");
1886 intel_dp_link_down(intel_dp);
1887 break;
1888 }
1889
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001890 if (IS_HASWELL(dev)) {
1891 signal_levels = intel_dp_signal_levels_hsw(intel_dp->train_set[0]);
1892 DP = (DP & ~DDI_BUF_EMP_MASK) | signal_levels;
1893 } else if (IS_GEN7(dev) && is_cpu_edp(intel_dp) && !IS_VALLEYVIEW(dev)) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001894 signal_levels = intel_gen7_edp_signal_levels(intel_dp->train_set[0]);
1895 DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_IVB) | signal_levels;
1896 } else if (IS_GEN6(dev) && is_cpu_edp(intel_dp)) {
Jesse Barnes33a34e42010-09-08 12:42:02 -07001897 signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001898 DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels;
1899 } else {
Keith Packard93f62da2011-11-01 19:45:03 -07001900 signal_levels = intel_dp_signal_levels(intel_dp->train_set[0]);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001901 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
1902 }
1903
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001904 /* channel eq pattern */
Paulo Zanoni47ea7542012-07-17 16:55:16 -03001905 if (!intel_dp_set_link_train(intel_dp, DP,
Adam Jackson81055852011-07-21 17:48:37 -04001906 DP_TRAINING_PATTERN_2 |
1907 DP_LINK_SCRAMBLING_DISABLE))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001908 break;
1909
Daniel Vettera7c96552012-10-18 10:15:30 +02001910 drm_dp_link_train_channel_eq_delay(intel_dp->dpcd);
Keith Packard93f62da2011-11-01 19:45:03 -07001911 if (!intel_dp_get_link_status(intel_dp, link_status))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001912 break;
Jesse Barnes869184a2010-10-07 16:01:22 -07001913
Jesse Barnes37f80972011-01-05 14:45:24 -08001914 /* Make sure clock is still ok */
Daniel Vetter01916272012-10-18 10:15:25 +02001915 if (!drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
Jesse Barnes37f80972011-01-05 14:45:24 -08001916 intel_dp_start_link_train(intel_dp);
1917 cr_tries++;
1918 continue;
1919 }
1920
Daniel Vetter1ffdff12012-10-18 10:15:24 +02001921 if (drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001922 channel_eq = true;
1923 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001924 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001925
Jesse Barnes37f80972011-01-05 14:45:24 -08001926 /* Try 5 times, then try clock recovery if that fails */
1927 if (tries > 5) {
1928 intel_dp_link_down(intel_dp);
1929 intel_dp_start_link_train(intel_dp);
1930 tries = 0;
1931 cr_tries++;
1932 continue;
1933 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001934
1935 /* Compute new intel_dp->train_set as requested by target */
Keith Packard93f62da2011-11-01 19:45:03 -07001936 intel_get_adjust_train(intel_dp, link_status);
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001937 ++tries;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001938 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001939
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001940 if (channel_eq)
1941 DRM_DEBUG_KMS("Channel EQ done. DP Training successfull\n");
1942
Paulo Zanoni47ea7542012-07-17 16:55:16 -03001943 intel_dp_set_link_train(intel_dp, DP, DP_TRAINING_PATTERN_DISABLE);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001944}
1945
1946static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01001947intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001948{
Chris Wilson4ef69c72010-09-09 15:14:28 +01001949 struct drm_device *dev = intel_dp->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001950 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001951 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001952
Paulo Zanonic19b0662012-10-15 15:51:41 -03001953 /*
1954 * DDI code has a strict mode set sequence and we should try to respect
1955 * it, otherwise we might hang the machine in many different ways. So we
1956 * really should be disabling the port only on a complete crtc_disable
1957 * sequence. This function is just called under two conditions on DDI
1958 * code:
1959 * - Link train failed while doing crtc_enable, and on this case we
1960 * really should respect the mode set sequence and wait for a
1961 * crtc_disable.
1962 * - Someone turned the monitor off and intel_dp_check_link_status
1963 * called us. We don't need to disable the whole port on this case, so
1964 * when someone turns the monitor on again,
1965 * intel_ddi_prepare_link_retrain will take care of redoing the link
1966 * train.
1967 */
1968 if (IS_HASWELL(dev))
1969 return;
1970
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02001971 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00001972 return;
1973
Zhao Yakui28c97732009-10-09 11:39:41 +08001974 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001975
Keith Packard1a2eb462011-11-16 16:26:07 -08001976 if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || !is_cpu_edp(intel_dp))) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08001977 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001978 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001979 } else {
1980 DP &= ~DP_LINK_TRAIN_MASK;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001981 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001982 }
Chris Wilsonfe255d02010-09-11 21:37:48 +01001983 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001984
Chris Wilsonfe255d02010-09-11 21:37:48 +01001985 msleep(17);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001986
Daniel Vetter493a7082012-05-30 12:31:56 +02001987 if (HAS_PCH_IBX(dev) &&
Chris Wilson1b39d6f2010-12-06 11:20:45 +00001988 I915_READ(intel_dp->output_reg) & DP_PIPEB_SELECT) {
Chris Wilson31acbcc2011-04-17 06:38:35 +01001989 struct drm_crtc *crtc = intel_dp->base.base.crtc;
1990
Eric Anholt5bddd172010-11-18 09:32:59 +08001991 /* Hardware workaround: leaving our transcoder select
1992 * set to transcoder B while it's off will prevent the
1993 * corresponding HDMI output on transcoder A.
1994 *
1995 * Combine this with another hardware workaround:
1996 * transcoder select bit can only be cleared while the
1997 * port is enabled.
1998 */
1999 DP &= ~DP_PIPEB_SELECT;
2000 I915_WRITE(intel_dp->output_reg, DP);
2001
2002 /* Changes to enable or select take place the vblank
2003 * after being written.
2004 */
Chris Wilson31acbcc2011-04-17 06:38:35 +01002005 if (crtc == NULL) {
2006 /* We can arrive here never having been attached
2007 * to a CRTC, for instance, due to inheriting
2008 * random state from the BIOS.
2009 *
2010 * If the pipe is not running, play safe and
2011 * wait for the clocks to stabilise before
2012 * continuing.
2013 */
2014 POSTING_READ(intel_dp->output_reg);
2015 msleep(50);
2016 } else
2017 intel_wait_for_vblank(dev, to_intel_crtc(crtc)->pipe);
Eric Anholt5bddd172010-11-18 09:32:59 +08002018 }
2019
Wu Fengguang832afda2011-12-09 20:42:21 +08002020 DP &= ~DP_AUDIO_OUTPUT_ENABLE;
Chris Wilsonea5b2132010-08-04 13:50:23 +01002021 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
2022 POSTING_READ(intel_dp->output_reg);
Keith Packardf01eca22011-09-28 16:48:10 -07002023 msleep(intel_dp->panel_power_down_delay);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002024}
2025
Keith Packard26d61aa2011-07-25 20:01:09 -07002026static bool
2027intel_dp_get_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07002028{
Keith Packard92fd8fd2011-07-25 19:50:10 -07002029 if (intel_dp_aux_native_read_retry(intel_dp, 0x000, intel_dp->dpcd,
Adam Jacksonb091cd92012-09-18 10:58:49 -04002030 sizeof(intel_dp->dpcd)) == 0)
2031 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07002032
Adam Jacksonb091cd92012-09-18 10:58:49 -04002033 if (intel_dp->dpcd[DP_DPCD_REV] == 0)
2034 return false; /* DPCD not present */
2035
2036 if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
2037 DP_DWN_STRM_PORT_PRESENT))
2038 return true; /* native DP sink */
2039
2040 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
2041 return true; /* no per-port downstream info */
2042
2043 if (intel_dp_aux_native_read_retry(intel_dp, DP_DOWNSTREAM_PORT_0,
2044 intel_dp->downstream_ports,
2045 DP_MAX_DOWNSTREAM_PORTS) == 0)
2046 return false; /* downstream port status fetch failed */
2047
2048 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07002049}
2050
Adam Jackson0d198322012-05-14 16:05:47 -04002051static void
2052intel_dp_probe_oui(struct intel_dp *intel_dp)
2053{
2054 u8 buf[3];
2055
2056 if (!(intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] & DP_OUI_SUPPORT))
2057 return;
2058
Daniel Vetter351cfc32012-06-12 13:20:47 +02002059 ironlake_edp_panel_vdd_on(intel_dp);
2060
Adam Jackson0d198322012-05-14 16:05:47 -04002061 if (intel_dp_aux_native_read_retry(intel_dp, DP_SINK_OUI, buf, 3))
2062 DRM_DEBUG_KMS("Sink OUI: %02hx%02hx%02hx\n",
2063 buf[0], buf[1], buf[2]);
2064
2065 if (intel_dp_aux_native_read_retry(intel_dp, DP_BRANCH_OUI, buf, 3))
2066 DRM_DEBUG_KMS("Branch OUI: %02hx%02hx%02hx\n",
2067 buf[0], buf[1], buf[2]);
Daniel Vetter351cfc32012-06-12 13:20:47 +02002068
2069 ironlake_edp_panel_vdd_off(intel_dp, false);
Adam Jackson0d198322012-05-14 16:05:47 -04002070}
2071
Jesse Barnesa60f0e32011-10-20 15:09:17 -07002072static bool
2073intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
2074{
2075 int ret;
2076
2077 ret = intel_dp_aux_native_read_retry(intel_dp,
2078 DP_DEVICE_SERVICE_IRQ_VECTOR,
2079 sink_irq_vector, 1);
2080 if (!ret)
2081 return false;
2082
2083 return true;
2084}
2085
2086static void
2087intel_dp_handle_test_request(struct intel_dp *intel_dp)
2088{
2089 /* NAK by default */
2090 intel_dp_aux_native_write_1(intel_dp, DP_TEST_RESPONSE, DP_TEST_ACK);
2091}
2092
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002093/*
2094 * According to DP spec
2095 * 5.1.2:
2096 * 1. Read DPCD
2097 * 2. Configure link according to Receiver Capabilities
2098 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
2099 * 4. Check link status on receipt of hot-plug interrupt
2100 */
2101
2102static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01002103intel_dp_check_link_status(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002104{
Jesse Barnesa60f0e32011-10-20 15:09:17 -07002105 u8 sink_irq_vector;
Keith Packard93f62da2011-11-01 19:45:03 -07002106 u8 link_status[DP_LINK_STATUS_SIZE];
Jesse Barnesa60f0e32011-10-20 15:09:17 -07002107
Daniel Vetter24e804b2012-07-26 19:25:46 +02002108 if (!intel_dp->base.connectors_active)
Keith Packardd2b996a2011-07-25 22:37:51 -07002109 return;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07002110
Daniel Vetter24e804b2012-07-26 19:25:46 +02002111 if (WARN_ON(!intel_dp->base.base.crtc))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002112 return;
2113
Keith Packard92fd8fd2011-07-25 19:50:10 -07002114 /* Try to read receiver status if the link appears to be up */
Keith Packard93f62da2011-11-01 19:45:03 -07002115 if (!intel_dp_get_link_status(intel_dp, link_status)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01002116 intel_dp_link_down(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002117 return;
2118 }
2119
Keith Packard92fd8fd2011-07-25 19:50:10 -07002120 /* Now read the DPCD to see if it's actually running */
Keith Packard26d61aa2011-07-25 20:01:09 -07002121 if (!intel_dp_get_dpcd(intel_dp)) {
Jesse Barnes59cd09e2011-07-07 11:10:59 -07002122 intel_dp_link_down(intel_dp);
2123 return;
2124 }
2125
Jesse Barnesa60f0e32011-10-20 15:09:17 -07002126 /* Try to read the source of the interrupt */
2127 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
2128 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector)) {
2129 /* Clear interrupt source */
2130 intel_dp_aux_native_write_1(intel_dp,
2131 DP_DEVICE_SERVICE_IRQ_VECTOR,
2132 sink_irq_vector);
2133
2134 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
2135 intel_dp_handle_test_request(intel_dp);
2136 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
2137 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
2138 }
2139
Daniel Vetter1ffdff12012-10-18 10:15:24 +02002140 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Keith Packard92fd8fd2011-07-25 19:50:10 -07002141 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
2142 drm_get_encoder_name(&intel_dp->base.base));
Jesse Barnes33a34e42010-09-08 12:42:02 -07002143 intel_dp_start_link_train(intel_dp);
2144 intel_dp_complete_link_train(intel_dp);
2145 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002146}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002147
Adam Jackson07d3dc12012-09-18 10:58:50 -04002148/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002149static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07002150intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04002151{
Adam Jackson07d3dc12012-09-18 10:58:50 -04002152 uint8_t *dpcd = intel_dp->dpcd;
2153 bool hpd;
2154 uint8_t type;
2155
2156 if (!intel_dp_get_dpcd(intel_dp))
2157 return connector_status_disconnected;
2158
2159 /* if there's no downstream port, we're done */
2160 if (!(dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT))
Keith Packard26d61aa2011-07-25 20:01:09 -07002161 return connector_status_connected;
Adam Jackson07d3dc12012-09-18 10:58:50 -04002162
2163 /* If we're HPD-aware, SINK_COUNT changes dynamically */
2164 hpd = !!(intel_dp->downstream_ports[0] & DP_DS_PORT_HPD);
2165 if (hpd) {
Adam Jacksonda131a42012-09-20 16:42:45 -04002166 uint8_t reg;
Adam Jackson07d3dc12012-09-18 10:58:50 -04002167 if (!intel_dp_aux_native_read_retry(intel_dp, DP_SINK_COUNT,
Adam Jacksonda131a42012-09-20 16:42:45 -04002168 &reg, 1))
Adam Jackson07d3dc12012-09-18 10:58:50 -04002169 return connector_status_unknown;
Adam Jacksonda131a42012-09-20 16:42:45 -04002170 return DP_GET_SINK_COUNT(reg) ? connector_status_connected
2171 : connector_status_disconnected;
Adam Jackson07d3dc12012-09-18 10:58:50 -04002172 }
2173
2174 /* If no HPD, poke DDC gently */
2175 if (drm_probe_ddc(&intel_dp->adapter))
2176 return connector_status_connected;
2177
2178 /* Well we tried, say unknown for unreliable port types */
2179 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
2180 if (type == DP_DS_PORT_TYPE_VGA || type == DP_DS_PORT_TYPE_NON_EDID)
2181 return connector_status_unknown;
2182
2183 /* Anything else is out of spec, warn and ignore */
2184 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07002185 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04002186}
2187
2188static enum drm_connector_status
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002189ironlake_dp_detect(struct intel_dp *intel_dp)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002190{
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002191 enum drm_connector_status status;
2192
Chris Wilsonfe16d942011-02-12 10:29:38 +00002193 /* Can't disconnect eDP, but you can close the lid... */
2194 if (is_edp(intel_dp)) {
2195 status = intel_panel_detect(intel_dp->base.base.dev);
2196 if (status == connector_status_unknown)
2197 status = connector_status_connected;
2198 return status;
2199 }
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002200
Keith Packard26d61aa2011-07-25 20:01:09 -07002201 return intel_dp_detect_dpcd(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002202}
2203
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002204static enum drm_connector_status
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002205g4x_dp_detect(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002206{
Chris Wilson4ef69c72010-09-09 15:14:28 +01002207 struct drm_device *dev = intel_dp->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002208 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson10f76a32012-05-11 18:01:32 +01002209 uint32_t bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002210
Chris Wilsonea5b2132010-08-04 13:50:23 +01002211 switch (intel_dp->output_reg) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002212 case DP_B:
Chris Wilson10f76a32012-05-11 18:01:32 +01002213 bit = DPB_HOTPLUG_LIVE_STATUS;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002214 break;
2215 case DP_C:
Chris Wilson10f76a32012-05-11 18:01:32 +01002216 bit = DPC_HOTPLUG_LIVE_STATUS;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002217 break;
2218 case DP_D:
Chris Wilson10f76a32012-05-11 18:01:32 +01002219 bit = DPD_HOTPLUG_LIVE_STATUS;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002220 break;
2221 default:
2222 return connector_status_unknown;
2223 }
2224
Chris Wilson10f76a32012-05-11 18:01:32 +01002225 if ((I915_READ(PORT_HOTPLUG_STAT) & bit) == 0)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002226 return connector_status_disconnected;
2227
Keith Packard26d61aa2011-07-25 20:01:09 -07002228 return intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002229}
2230
Keith Packard8c241fe2011-09-28 16:38:44 -07002231static struct edid *
2232intel_dp_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
2233{
Jani Nikula9cd300e2012-10-19 14:51:52 +03002234 struct intel_connector *intel_connector = to_intel_connector(connector);
Keith Packard8c241fe2011-09-28 16:38:44 -07002235
Jani Nikula9cd300e2012-10-19 14:51:52 +03002236 /* use cached edid if we have one */
2237 if (intel_connector->edid) {
2238 struct edid *edid;
2239 int size;
2240
2241 /* invalid edid */
2242 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04002243 return NULL;
2244
Jani Nikula9cd300e2012-10-19 14:51:52 +03002245 size = (intel_connector->edid->extensions + 1) * EDID_LENGTH;
Jesse Barnesd6f24d02012-06-14 15:28:33 -04002246 edid = kmalloc(size, GFP_KERNEL);
2247 if (!edid)
2248 return NULL;
2249
Jani Nikula9cd300e2012-10-19 14:51:52 +03002250 memcpy(edid, intel_connector->edid, size);
Jesse Barnesd6f24d02012-06-14 15:28:33 -04002251 return edid;
2252 }
2253
Jani Nikula9cd300e2012-10-19 14:51:52 +03002254 return drm_get_edid(connector, adapter);
Keith Packard8c241fe2011-09-28 16:38:44 -07002255}
2256
2257static int
2258intel_dp_get_edid_modes(struct drm_connector *connector, struct i2c_adapter *adapter)
2259{
Jani Nikula9cd300e2012-10-19 14:51:52 +03002260 struct intel_connector *intel_connector = to_intel_connector(connector);
Keith Packard8c241fe2011-09-28 16:38:44 -07002261
Jani Nikula9cd300e2012-10-19 14:51:52 +03002262 /* use cached edid if we have one */
2263 if (intel_connector->edid) {
2264 /* invalid edid */
2265 if (IS_ERR(intel_connector->edid))
2266 return 0;
2267
2268 return intel_connector_update_modes(connector,
2269 intel_connector->edid);
Jesse Barnesd6f24d02012-06-14 15:28:33 -04002270 }
2271
Jani Nikula9cd300e2012-10-19 14:51:52 +03002272 return intel_ddc_get_modes(connector, adapter);
Keith Packard8c241fe2011-09-28 16:38:44 -07002273}
2274
2275
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002276/**
2277 * Uses CRT_HOTPLUG_EN and CRT_HOTPLUG_STAT to detect DP connection.
2278 *
2279 * \return true if DP port is connected.
2280 * \return false if DP port is disconnected.
2281 */
2282static enum drm_connector_status
2283intel_dp_detect(struct drm_connector *connector, bool force)
2284{
2285 struct intel_dp *intel_dp = intel_attached_dp(connector);
2286 struct drm_device *dev = intel_dp->base.base.dev;
2287 enum drm_connector_status status;
2288 struct edid *edid = NULL;
2289
2290 intel_dp->has_audio = false;
2291
2292 if (HAS_PCH_SPLIT(dev))
2293 status = ironlake_dp_detect(intel_dp);
2294 else
2295 status = g4x_dp_detect(intel_dp);
Adam Jackson1b9be9d2011-07-12 17:38:01 -04002296
Adam Jacksonac66ae82011-07-12 17:38:03 -04002297 DRM_DEBUG_KMS("DPCD: %02hx%02hx%02hx%02hx%02hx%02hx%02hx%02hx\n",
2298 intel_dp->dpcd[0], intel_dp->dpcd[1], intel_dp->dpcd[2],
2299 intel_dp->dpcd[3], intel_dp->dpcd[4], intel_dp->dpcd[5],
2300 intel_dp->dpcd[6], intel_dp->dpcd[7]);
Adam Jackson1b9be9d2011-07-12 17:38:01 -04002301
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002302 if (status != connector_status_connected)
2303 return status;
2304
Adam Jackson0d198322012-05-14 16:05:47 -04002305 intel_dp_probe_oui(intel_dp);
2306
Daniel Vetterc3e5f672012-02-23 17:14:47 +01002307 if (intel_dp->force_audio != HDMI_AUDIO_AUTO) {
2308 intel_dp->has_audio = (intel_dp->force_audio == HDMI_AUDIO_ON);
Chris Wilsonf6849602010-09-19 09:29:33 +01002309 } else {
Keith Packard8c241fe2011-09-28 16:38:44 -07002310 edid = intel_dp_get_edid(connector, &intel_dp->adapter);
Chris Wilsonf6849602010-09-19 09:29:33 +01002311 if (edid) {
2312 intel_dp->has_audio = drm_detect_monitor_audio(edid);
Chris Wilsonf6849602010-09-19 09:29:33 +01002313 kfree(edid);
2314 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002315 }
2316
2317 return connector_status_connected;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002318}
2319
2320static int intel_dp_get_modes(struct drm_connector *connector)
2321{
Chris Wilsondf0e9242010-09-09 16:20:55 +01002322 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +03002323 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilson4ef69c72010-09-09 15:14:28 +01002324 struct drm_device *dev = intel_dp->base.base.dev;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002325 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002326
2327 /* We should parse the EDID data and find out if it has an audio sink
2328 */
2329
Keith Packard8c241fe2011-09-28 16:38:44 -07002330 ret = intel_dp_get_edid_modes(connector, &intel_dp->adapter);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002331 if (ret)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002332 return ret;
2333
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002334 /* if eDP has no EDID, fall back to fixed mode */
Jani Nikuladd06f902012-10-19 14:51:50 +03002335 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002336 struct drm_display_mode *mode;
Jani Nikuladd06f902012-10-19 14:51:50 +03002337 mode = drm_mode_duplicate(dev,
2338 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002339 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002340 drm_mode_probed_add(connector, mode);
2341 return 1;
2342 }
2343 }
2344 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002345}
2346
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002347static bool
2348intel_dp_detect_audio(struct drm_connector *connector)
2349{
2350 struct intel_dp *intel_dp = intel_attached_dp(connector);
2351 struct edid *edid;
2352 bool has_audio = false;
2353
Keith Packard8c241fe2011-09-28 16:38:44 -07002354 edid = intel_dp_get_edid(connector, &intel_dp->adapter);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002355 if (edid) {
2356 has_audio = drm_detect_monitor_audio(edid);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002357 kfree(edid);
2358 }
2359
2360 return has_audio;
2361}
2362
Chris Wilsonf6849602010-09-19 09:29:33 +01002363static int
2364intel_dp_set_property(struct drm_connector *connector,
2365 struct drm_property *property,
2366 uint64_t val)
2367{
Chris Wilsone953fd72011-02-21 22:23:52 +00002368 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Chris Wilsonf6849602010-09-19 09:29:33 +01002369 struct intel_dp *intel_dp = intel_attached_dp(connector);
2370 int ret;
2371
2372 ret = drm_connector_property_set_value(connector, property, val);
2373 if (ret)
2374 return ret;
2375
Chris Wilson3f43c482011-05-12 22:17:24 +01002376 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002377 int i = val;
2378 bool has_audio;
2379
2380 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01002381 return 0;
2382
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002383 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01002384
Daniel Vetterc3e5f672012-02-23 17:14:47 +01002385 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002386 has_audio = intel_dp_detect_audio(connector);
2387 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01002388 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002389
2390 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01002391 return 0;
2392
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002393 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01002394 goto done;
2395 }
2396
Chris Wilsone953fd72011-02-21 22:23:52 +00002397 if (property == dev_priv->broadcast_rgb_property) {
2398 if (val == !!intel_dp->color_range)
2399 return 0;
2400
2401 intel_dp->color_range = val ? DP_COLOR_RANGE_16_235 : 0;
2402 goto done;
2403 }
2404
Chris Wilsonf6849602010-09-19 09:29:33 +01002405 return -EINVAL;
2406
2407done:
2408 if (intel_dp->base.base.crtc) {
2409 struct drm_crtc *crtc = intel_dp->base.base.crtc;
Daniel Vettera6778b32012-07-02 09:56:42 +02002410 intel_set_mode(crtc, &crtc->mode,
2411 crtc->x, crtc->y, crtc->fb);
Chris Wilsonf6849602010-09-19 09:29:33 +01002412 }
2413
2414 return 0;
2415}
2416
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002417static void
Akshay Joshi0206e352011-08-16 15:34:10 -04002418intel_dp_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002419{
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02002420 struct drm_device *dev = connector->dev;
Jani Nikulabe3cd5e2012-10-12 10:33:05 +03002421 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikula1d508702012-10-19 14:51:49 +03002422 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02002423
Jani Nikula9cd300e2012-10-19 14:51:52 +03002424 if (!IS_ERR_OR_NULL(intel_connector->edid))
2425 kfree(intel_connector->edid);
2426
Jani Nikula1d508702012-10-19 14:51:49 +03002427 if (is_edp(intel_dp)) {
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02002428 intel_panel_destroy_backlight(dev);
Jani Nikula1d508702012-10-19 14:51:49 +03002429 intel_panel_fini(&intel_connector->panel);
2430 }
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02002431
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002432 drm_sysfs_connector_remove(connector);
2433 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08002434 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002435}
2436
Daniel Vetter24d05922010-08-20 18:08:28 +02002437static void intel_dp_encoder_destroy(struct drm_encoder *encoder)
2438{
2439 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2440
2441 i2c_del_adapter(&intel_dp->adapter);
2442 drm_encoder_cleanup(encoder);
Keith Packardbd943152011-09-18 23:09:52 -07002443 if (is_edp(intel_dp)) {
2444 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
2445 ironlake_panel_vdd_off_sync(intel_dp);
2446 }
Daniel Vetter24d05922010-08-20 18:08:28 +02002447 kfree(intel_dp);
2448}
2449
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002450static const struct drm_encoder_helper_funcs intel_dp_helper_funcs = {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002451 .mode_fixup = intel_dp_mode_fixup,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002452 .mode_set = intel_dp_mode_set,
Daniel Vetter1f703852012-07-11 16:51:39 +02002453 .disable = intel_encoder_noop,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002454};
2455
Paulo Zanonia7902ac52012-10-15 15:51:42 -03002456static const struct drm_encoder_helper_funcs intel_dp_helper_funcs_hsw = {
2457 .mode_fixup = intel_dp_mode_fixup,
2458 .mode_set = intel_ddi_mode_set,
2459 .disable = intel_encoder_noop,
2460};
2461
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002462static const struct drm_connector_funcs intel_dp_connector_funcs = {
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002463 .dpms = intel_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002464 .detect = intel_dp_detect,
2465 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01002466 .set_property = intel_dp_set_property,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002467 .destroy = intel_dp_destroy,
2468};
2469
2470static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
2471 .get_modes = intel_dp_get_modes,
2472 .mode_valid = intel_dp_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +01002473 .best_encoder = intel_best_encoder,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002474};
2475
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002476static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Daniel Vetter24d05922010-08-20 18:08:28 +02002477 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002478};
2479
Chris Wilson995b6762010-08-20 13:23:26 +01002480static void
Eric Anholt21d40d32010-03-25 11:11:14 -07002481intel_dp_hot_plug(struct intel_encoder *intel_encoder)
Keith Packardc8110e52009-05-06 11:51:10 -07002482{
Chris Wilsonea5b2132010-08-04 13:50:23 +01002483 struct intel_dp *intel_dp = container_of(intel_encoder, struct intel_dp, base);
Keith Packardc8110e52009-05-06 11:51:10 -07002484
Jesse Barnes885a5012011-07-07 11:11:01 -07002485 intel_dp_check_link_status(intel_dp);
Keith Packardc8110e52009-05-06 11:51:10 -07002486}
2487
Zhenyu Wange3421a12010-04-08 09:43:27 +08002488/* Return which DP Port should be selected for Transcoder DP control */
2489int
Akshay Joshi0206e352011-08-16 15:34:10 -04002490intel_trans_dp_port_sel(struct drm_crtc *crtc)
Zhenyu Wange3421a12010-04-08 09:43:27 +08002491{
2492 struct drm_device *dev = crtc->dev;
Daniel Vetter6c2b7c12012-07-05 09:50:24 +02002493 struct intel_encoder *encoder;
Zhenyu Wange3421a12010-04-08 09:43:27 +08002494
Daniel Vetter6c2b7c12012-07-05 09:50:24 +02002495 for_each_encoder_on_crtc(dev, crtc, encoder) {
2496 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002497
Keith Packard417e8222011-11-01 19:54:11 -07002498 if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT ||
2499 intel_dp->base.type == INTEL_OUTPUT_EDP)
Chris Wilsonea5b2132010-08-04 13:50:23 +01002500 return intel_dp->output_reg;
Zhenyu Wange3421a12010-04-08 09:43:27 +08002501 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002502
Zhenyu Wange3421a12010-04-08 09:43:27 +08002503 return -1;
2504}
2505
Zhao Yakui36e83a12010-06-12 14:32:21 +08002506/* check the VBT to see whether the eDP is on DP-D port */
Adam Jacksoncb0953d2010-07-16 14:46:29 -04002507bool intel_dpd_is_edp(struct drm_device *dev)
Zhao Yakui36e83a12010-06-12 14:32:21 +08002508{
2509 struct drm_i915_private *dev_priv = dev->dev_private;
2510 struct child_device_config *p_child;
2511 int i;
2512
2513 if (!dev_priv->child_dev_num)
2514 return false;
2515
2516 for (i = 0; i < dev_priv->child_dev_num; i++) {
2517 p_child = dev_priv->child_dev + i;
2518
2519 if (p_child->dvo_port == PORT_IDPD &&
2520 p_child->device_type == DEVICE_TYPE_eDP)
2521 return true;
2522 }
2523 return false;
2524}
2525
Chris Wilsonf6849602010-09-19 09:29:33 +01002526static void
2527intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
2528{
Chris Wilson3f43c482011-05-12 22:17:24 +01002529 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00002530 intel_attach_broadcast_rgb_property(connector);
Chris Wilsonf6849602010-09-19 09:29:33 +01002531}
2532
Keith Packardc8110e52009-05-06 11:51:10 -07002533void
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03002534intel_dp_init(struct drm_device *dev, int output_reg, enum port port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002535{
2536 struct drm_i915_private *dev_priv = dev->dev_private;
2537 struct drm_connector *connector;
Chris Wilsonea5b2132010-08-04 13:50:23 +01002538 struct intel_dp *intel_dp;
Eric Anholt21d40d32010-03-25 11:11:14 -07002539 struct intel_encoder *intel_encoder;
Zhenyu Wang55f78c42010-03-29 16:13:57 +08002540 struct intel_connector *intel_connector;
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002541 struct drm_display_mode *fixed_mode = NULL;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002542 const char *name = NULL;
Adam Jacksonb3295302010-07-16 14:46:28 -04002543 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002544
Chris Wilsonea5b2132010-08-04 13:50:23 +01002545 intel_dp = kzalloc(sizeof(struct intel_dp), GFP_KERNEL);
2546 if (!intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002547 return;
2548
Chris Wilson3d3dc142011-02-12 10:33:12 +00002549 intel_dp->output_reg = output_reg;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03002550 intel_dp->port = port;
Daniel Vetter07679352012-09-06 22:15:42 +02002551 /* Preserve the current hw state. */
2552 intel_dp->DP = I915_READ(intel_dp->output_reg);
Chris Wilson3d3dc142011-02-12 10:33:12 +00002553
Zhenyu Wang55f78c42010-03-29 16:13:57 +08002554 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
2555 if (!intel_connector) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01002556 kfree(intel_dp);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08002557 return;
2558 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002559 intel_encoder = &intel_dp->base;
Jani Nikuladd06f902012-10-19 14:51:50 +03002560 intel_dp->attached_connector = intel_connector;
Zhenyu Wang55f78c42010-03-29 16:13:57 +08002561
Chris Wilsonea5b2132010-08-04 13:50:23 +01002562 if (HAS_PCH_SPLIT(dev) && output_reg == PCH_DP_D)
Adam Jacksonb3295302010-07-16 14:46:28 -04002563 if (intel_dpd_is_edp(dev))
Chris Wilsonea5b2132010-08-04 13:50:23 +01002564 intel_dp->is_pch_edp = true;
Adam Jacksonb3295302010-07-16 14:46:28 -04002565
Gajanan Bhat19c03922012-09-27 19:13:07 +05302566 /*
2567 * FIXME : We need to initialize built-in panels before external panels.
2568 * For X0, DP_C is fixed as eDP. Revisit this as part of VLV eDP cleanup
2569 */
2570 if (IS_VALLEYVIEW(dev) && output_reg == DP_C) {
2571 type = DRM_MODE_CONNECTOR_eDP;
2572 intel_encoder->type = INTEL_OUTPUT_EDP;
2573 } else if (output_reg == DP_A || is_pch_edp(intel_dp)) {
Adam Jacksonb3295302010-07-16 14:46:28 -04002574 type = DRM_MODE_CONNECTOR_eDP;
2575 intel_encoder->type = INTEL_OUTPUT_EDP;
2576 } else {
2577 type = DRM_MODE_CONNECTOR_DisplayPort;
2578 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
2579 }
2580
Zhenyu Wang55f78c42010-03-29 16:13:57 +08002581 connector = &intel_connector->base;
Adam Jacksonb3295302010-07-16 14:46:28 -04002582 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002583 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
2584
Dave Airlieeb1f8e42010-05-07 06:42:51 +00002585 connector->polled = DRM_CONNECTOR_POLL_HPD;
2586
Daniel Vetter66a92782012-07-12 20:08:18 +02002587 intel_encoder->cloneable = false;
Ma Lingf8aed702009-08-24 13:50:24 +08002588
Daniel Vetter66a92782012-07-12 20:08:18 +02002589 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
2590 ironlake_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08002591
Jesse Barnes27f82272011-09-02 12:54:37 -07002592 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
Jesse Barnesee7b9f92012-04-20 17:11:53 +01002593
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002594 connector->interlace_allowed = true;
2595 connector->doublescan_allowed = 0;
2596
Chris Wilson4ef69c72010-09-09 15:14:28 +01002597 drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002598 DRM_MODE_ENCODER_TMDS);
Paulo Zanonia7902ac52012-10-15 15:51:42 -03002599
2600 if (IS_HASWELL(dev))
2601 drm_encoder_helper_add(&intel_encoder->base,
2602 &intel_dp_helper_funcs_hsw);
2603 else
2604 drm_encoder_helper_add(&intel_encoder->base,
2605 &intel_dp_helper_funcs);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002606
Chris Wilsondf0e9242010-09-09 16:20:55 +01002607 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002608 drm_sysfs_connector_add(connector);
2609
Paulo Zanonia7902ac52012-10-15 15:51:42 -03002610 if (IS_HASWELL(dev)) {
2611 intel_encoder->enable = intel_enable_ddi;
2612 intel_encoder->pre_enable = intel_ddi_pre_enable;
2613 intel_encoder->disable = intel_disable_ddi;
2614 intel_encoder->post_disable = intel_ddi_post_disable;
2615 intel_encoder->get_hw_state = intel_ddi_get_hw_state;
2616 } else {
2617 intel_encoder->enable = intel_enable_dp;
2618 intel_encoder->pre_enable = intel_pre_enable_dp;
2619 intel_encoder->disable = intel_disable_dp;
2620 intel_encoder->post_disable = intel_post_disable_dp;
2621 intel_encoder->get_hw_state = intel_dp_get_hw_state;
2622 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002623 intel_connector->get_hw_state = intel_connector_get_hw_state;
Daniel Vettere8cb4552012-07-01 13:05:48 +02002624
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002625 /* Set up the DDC bus. */
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03002626 switch (port) {
2627 case PORT_A:
2628 name = "DPDDC-A";
2629 break;
2630 case PORT_B:
2631 dev_priv->hotplug_supported_mask |= DPB_HOTPLUG_INT_STATUS;
2632 name = "DPDDC-B";
2633 break;
2634 case PORT_C:
2635 dev_priv->hotplug_supported_mask |= DPC_HOTPLUG_INT_STATUS;
2636 name = "DPDDC-C";
2637 break;
2638 case PORT_D:
2639 dev_priv->hotplug_supported_mask |= DPD_HOTPLUG_INT_STATUS;
2640 name = "DPDDC-D";
2641 break;
2642 default:
2643 WARN(1, "Invalid port %c\n", port_name(port));
2644 break;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002645 }
2646
Jesse Barnes89667382010-10-07 16:01:21 -07002647 /* Cache some DPCD data in the eDP case */
2648 if (is_edp(intel_dp)) {
Keith Packardf01eca22011-09-28 16:48:10 -07002649 struct edp_power_seq cur, vbt;
2650 u32 pp_on, pp_off, pp_div;
Jesse Barnes89667382010-10-07 16:01:21 -07002651
Jesse Barnes5d613502011-01-24 17:10:54 -08002652 pp_on = I915_READ(PCH_PP_ON_DELAYS);
Keith Packardf01eca22011-09-28 16:48:10 -07002653 pp_off = I915_READ(PCH_PP_OFF_DELAYS);
Jesse Barnes5d613502011-01-24 17:10:54 -08002654 pp_div = I915_READ(PCH_PP_DIVISOR);
2655
Jesse Barnesbfa33842012-04-10 11:58:04 -07002656 if (!pp_on || !pp_off || !pp_div) {
2657 DRM_INFO("bad panel power sequencing delays, disabling panel\n");
2658 intel_dp_encoder_destroy(&intel_dp->base.base);
2659 intel_dp_destroy(&intel_connector->base);
2660 return;
2661 }
2662
Keith Packardf01eca22011-09-28 16:48:10 -07002663 /* Pull timing values out of registers */
2664 cur.t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
2665 PANEL_POWER_UP_DELAY_SHIFT;
2666
2667 cur.t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
2668 PANEL_LIGHT_ON_DELAY_SHIFT;
Keith Packardf2e8b182011-11-01 20:01:35 -07002669
Keith Packardf01eca22011-09-28 16:48:10 -07002670 cur.t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
2671 PANEL_LIGHT_OFF_DELAY_SHIFT;
2672
2673 cur.t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
2674 PANEL_POWER_DOWN_DELAY_SHIFT;
2675
2676 cur.t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
2677 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
2678
2679 DRM_DEBUG_KMS("cur t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
2680 cur.t1_t3, cur.t8, cur.t9, cur.t10, cur.t11_t12);
2681
2682 vbt = dev_priv->edp.pps;
2683
2684 DRM_DEBUG_KMS("vbt t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
2685 vbt.t1_t3, vbt.t8, vbt.t9, vbt.t10, vbt.t11_t12);
2686
2687#define get_delay(field) ((max(cur.field, vbt.field) + 9) / 10)
2688
2689 intel_dp->panel_power_up_delay = get_delay(t1_t3);
2690 intel_dp->backlight_on_delay = get_delay(t8);
2691 intel_dp->backlight_off_delay = get_delay(t9);
2692 intel_dp->panel_power_down_delay = get_delay(t10);
2693 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
2694
2695 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
2696 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
2697 intel_dp->panel_power_cycle_delay);
2698
2699 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
2700 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Dave Airliec1f05262012-08-30 11:06:18 +10002701 }
2702
2703 intel_dp_i2c_init(intel_dp, intel_connector, name);
2704
2705 if (is_edp(intel_dp)) {
2706 bool ret;
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002707 struct drm_display_mode *scan;
Dave Airliec1f05262012-08-30 11:06:18 +10002708 struct edid *edid;
Jesse Barnes5d613502011-01-24 17:10:54 -08002709
2710 ironlake_edp_panel_vdd_on(intel_dp);
Keith Packard59f3e272011-07-25 20:01:56 -07002711 ret = intel_dp_get_dpcd(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002712 ironlake_edp_panel_vdd_off(intel_dp, false);
Keith Packard99ea7122011-11-01 19:57:50 -07002713
Keith Packard59f3e272011-07-25 20:01:56 -07002714 if (ret) {
Jesse Barnes7183dc22011-07-07 11:10:58 -07002715 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
2716 dev_priv->no_aux_handshake =
2717 intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
Jesse Barnes89667382010-10-07 16:01:21 -07002718 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
2719 } else {
Chris Wilson3d3dc142011-02-12 10:33:12 +00002720 /* if this fails, presume the device is a ghost */
Takashi Iwai48898b02011-03-18 09:06:49 +00002721 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Chris Wilson3d3dc142011-02-12 10:33:12 +00002722 intel_dp_encoder_destroy(&intel_dp->base.base);
Takashi Iwai48898b02011-03-18 09:06:49 +00002723 intel_dp_destroy(&intel_connector->base);
Chris Wilson3d3dc142011-02-12 10:33:12 +00002724 return;
Jesse Barnes89667382010-10-07 16:01:21 -07002725 }
Jesse Barnes89667382010-10-07 16:01:21 -07002726
Jesse Barnesd6f24d02012-06-14 15:28:33 -04002727 ironlake_edp_panel_vdd_on(intel_dp);
2728 edid = drm_get_edid(connector, &intel_dp->adapter);
2729 if (edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03002730 if (drm_add_edid_modes(connector, edid)) {
2731 drm_mode_connector_update_edid_property(connector, edid);
2732 drm_edid_to_eld(connector, edid);
2733 } else {
2734 kfree(edid);
2735 edid = ERR_PTR(-EINVAL);
2736 }
2737 } else {
2738 edid = ERR_PTR(-ENOENT);
Jesse Barnesd6f24d02012-06-14 15:28:33 -04002739 }
Jani Nikula9cd300e2012-10-19 14:51:52 +03002740 intel_connector->edid = edid;
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002741
2742 /* prefer fixed mode from EDID if available */
2743 list_for_each_entry(scan, &connector->probed_modes, head) {
2744 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
2745 fixed_mode = drm_mode_duplicate(dev, scan);
2746 break;
2747 }
2748 }
2749
2750 /* fallback to VBT if available for eDP */
2751 if (!fixed_mode && dev_priv->lfp_lvds_vbt_mode) {
2752 fixed_mode = drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);
2753 if (fixed_mode)
2754 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
2755 }
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002756
Jesse Barnesd6f24d02012-06-14 15:28:33 -04002757 ironlake_edp_panel_vdd_off(intel_dp, false);
2758 }
Keith Packard552fb0b2011-09-28 16:31:53 -07002759
Eric Anholt21d40d32010-03-25 11:11:14 -07002760 intel_encoder->hot_plug = intel_dp_hot_plug;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002761
Jani Nikula1d508702012-10-19 14:51:49 +03002762 if (is_edp(intel_dp)) {
Jani Nikuladd06f902012-10-19 14:51:50 +03002763 intel_panel_init(&intel_connector->panel, fixed_mode);
Jani Nikula0657b6b2012-10-19 14:51:46 +03002764 intel_panel_setup_backlight(connector);
Jani Nikula1d508702012-10-19 14:51:49 +03002765 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002766
Chris Wilsonf6849602010-09-19 09:29:33 +01002767 intel_dp_add_properties(intel_dp, connector);
2768
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002769 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
2770 * 0xd. Failure to do so will result in spurious interrupts being
2771 * generated on the port when a cable is not attached.
2772 */
2773 if (IS_G4X(dev) && !IS_GM45(dev)) {
2774 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
2775 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
2776 }
2777}