blob: efe5f9e0de9e133d4d00ee76b6715e0de446180a [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>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070030#include "drmP.h"
31#include "drm.h"
32#include "drm_crtc.h"
33#include "drm_crtc_helper.h"
34#include "intel_drv.h"
35#include "i915_drm.h"
36#include "i915_drv.h"
Dave Airlieab2c0672009-12-04 10:55:24 +100037#include "drm_dp_helper.h"
Keith Packarda4fc5ed2009-04-07 16:16:42 -070038
Jesse Barnesa2006cf2011-09-22 11:15:58 +053039#define DP_RECEIVER_CAP_SIZE 0xf
Keith Packarda4fc5ed2009-04-07 16:16:42 -070040#define DP_LINK_STATUS_SIZE 6
41#define DP_LINK_CHECK_TIMEOUT (10 * 1000)
42
43#define DP_LINK_CONFIGURATION_SIZE 9
44
Chris Wilsonea5b2132010-08-04 13:50:23 +010045struct intel_dp {
46 struct intel_encoder base;
Keith Packarda4fc5ed2009-04-07 16:16:42 -070047 uint32_t output_reg;
48 uint32_t DP;
49 uint8_t link_configuration[DP_LINK_CONFIGURATION_SIZE];
Keith Packarda4fc5ed2009-04-07 16:16:42 -070050 bool has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +010051 int force_audio;
Chris Wilsone953fd72011-02-21 22:23:52 +000052 uint32_t color_range;
Keith Packardd2b996a2011-07-25 22:37:51 -070053 int dpms_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -070054 uint8_t link_bw;
55 uint8_t lane_count;
Jesse Barnesa2006cf2011-09-22 11:15:58 +053056 uint8_t dpcd[DP_RECEIVER_CAP_SIZE];
Keith Packarda4fc5ed2009-04-07 16:16:42 -070057 struct i2c_adapter adapter;
58 struct i2c_algo_dp_aux_data algo;
Adam Jacksonf0917372010-07-16 14:46:27 -040059 bool is_pch_edp;
Jesse Barnes33a34e42010-09-08 12:42:02 -070060 uint8_t train_set[4];
61 uint8_t link_status[DP_LINK_STATUS_SIZE];
Keith Packardf01eca22011-09-28 16:48:10 -070062 int panel_power_up_delay;
63 int panel_power_down_delay;
64 int panel_power_cycle_delay;
65 int backlight_on_delay;
66 int backlight_off_delay;
Keith Packardd15456d2011-09-18 17:35:47 -070067 struct drm_display_mode *panel_fixed_mode; /* for eDP */
Keith Packardbd943152011-09-18 23:09:52 -070068 struct delayed_work panel_vdd_work;
69 bool want_panel_vdd;
70 unsigned long panel_off_jiffies;
Keith Packarda4fc5ed2009-04-07 16:16:42 -070071};
72
Jesse Barnescfcb0fc2010-10-07 16:01:06 -070073/**
74 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
75 * @intel_dp: DP struct
76 *
77 * If a CPU or PCH DP output is attached to an eDP panel, this function
78 * will return true, and false otherwise.
79 */
80static bool is_edp(struct intel_dp *intel_dp)
81{
82 return intel_dp->base.type == INTEL_OUTPUT_EDP;
83}
84
85/**
86 * is_pch_edp - is the port on the PCH and attached to an eDP panel?
87 * @intel_dp: DP struct
88 *
89 * Returns true if the given DP struct corresponds to a PCH DP port attached
90 * to an eDP panel, false otherwise. Helpful for determining whether we
91 * may need FDI resources for a given DP output or not.
92 */
93static bool is_pch_edp(struct intel_dp *intel_dp)
94{
95 return intel_dp->is_pch_edp;
96}
97
Adam Jackson1c958222011-10-14 17:22:25 -040098/**
99 * is_cpu_edp - is the port on the CPU and attached to an eDP panel?
100 * @intel_dp: DP struct
101 *
102 * Returns true if the given DP struct corresponds to a CPU eDP port.
103 */
104static bool is_cpu_edp(struct intel_dp *intel_dp)
105{
106 return is_edp(intel_dp) && !is_pch_edp(intel_dp);
107}
108
Chris Wilsonea5b2132010-08-04 13:50:23 +0100109static struct intel_dp *enc_to_intel_dp(struct drm_encoder *encoder)
110{
Chris Wilson4ef69c72010-09-09 15:14:28 +0100111 return container_of(encoder, struct intel_dp, base.base);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100112}
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700113
Chris Wilsondf0e9242010-09-09 16:20:55 +0100114static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
115{
116 return container_of(intel_attached_encoder(connector),
117 struct intel_dp, base);
118}
119
Jesse Barnes814948a2010-10-07 16:01:09 -0700120/**
121 * intel_encoder_is_pch_edp - is the given encoder a PCH attached eDP?
122 * @encoder: DRM encoder
123 *
124 * Return true if @encoder corresponds to a PCH attached eDP panel. Needed
125 * by intel_display.c.
126 */
127bool intel_encoder_is_pch_edp(struct drm_encoder *encoder)
128{
129 struct intel_dp *intel_dp;
130
131 if (!encoder)
132 return false;
133
134 intel_dp = enc_to_intel_dp(encoder);
135
136 return is_pch_edp(intel_dp);
137}
138
Jesse Barnes33a34e42010-09-08 12:42:02 -0700139static void intel_dp_start_link_train(struct intel_dp *intel_dp);
140static void intel_dp_complete_link_train(struct intel_dp *intel_dp);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100141static void intel_dp_link_down(struct intel_dp *intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700142
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800143void
Akshay Joshi0206e352011-08-16 15:34:10 -0400144intel_edp_link_config(struct intel_encoder *intel_encoder,
Chris Wilsonea5b2132010-08-04 13:50:23 +0100145 int *lane_num, int *link_bw)
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800146{
Chris Wilsonea5b2132010-08-04 13:50:23 +0100147 struct intel_dp *intel_dp = container_of(intel_encoder, struct intel_dp, base);
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800148
Chris Wilsonea5b2132010-08-04 13:50:23 +0100149 *lane_num = intel_dp->lane_count;
150 if (intel_dp->link_bw == DP_LINK_BW_1_62)
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800151 *link_bw = 162000;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100152 else if (intel_dp->link_bw == DP_LINK_BW_2_7)
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800153 *link_bw = 270000;
154}
155
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700156static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100157intel_dp_max_lane_count(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700158{
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700159 int max_lane_count = 4;
160
Jesse Barnes7183dc22011-07-07 11:10:58 -0700161 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
162 max_lane_count = intel_dp->dpcd[DP_MAX_LANE_COUNT] & 0x1f;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700163 switch (max_lane_count) {
164 case 1: case 2: case 4:
165 break;
166 default:
167 max_lane_count = 4;
168 }
169 }
170 return max_lane_count;
171}
172
173static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100174intel_dp_max_link_bw(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700175{
Jesse Barnes7183dc22011-07-07 11:10:58 -0700176 int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700177
178 switch (max_link_bw) {
179 case DP_LINK_BW_1_62:
180 case DP_LINK_BW_2_7:
181 break;
182 default:
183 max_link_bw = DP_LINK_BW_1_62;
184 break;
185 }
186 return max_link_bw;
187}
188
189static int
190intel_dp_link_clock(uint8_t link_bw)
191{
192 if (link_bw == DP_LINK_BW_2_7)
193 return 270000;
194 else
195 return 162000;
196}
197
Adam Jacksoncd9dde42011-10-14 12:43:49 -0400198/*
199 * The units on the numbers in the next two are... bizarre. Examples will
200 * make it clearer; this one parallels an example in the eDP spec.
201 *
202 * intel_dp_max_data_rate for one lane of 2.7GHz evaluates as:
203 *
204 * 270000 * 1 * 8 / 10 == 216000
205 *
206 * The actual data capacity of that configuration is 2.16Gbit/s, so the
207 * units are decakilobits. ->clock in a drm_display_mode is in kilohertz -
208 * or equivalently, kilopixels per second - so for 1680x1050R it'd be
209 * 119000. At 18bpp that's 2142000 kilobits per second.
210 *
211 * Thus the strange-looking division by 10 in intel_dp_link_required, to
212 * get the result in decakilobits instead of kilobits.
213 */
214
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700215static int
Adam Jacksoncd9dde42011-10-14 12:43:49 -0400216intel_dp_link_required(struct intel_dp *intel_dp, int pixel_clock)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700217{
Jesse Barnes89c61432011-06-24 12:19:28 -0700218 struct drm_crtc *crtc = intel_dp->base.base.crtc;
219 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
220 int bpp = 24;
Zhenyu Wang885a5fb2010-01-12 05:38:31 +0800221
Jesse Barnes89c61432011-06-24 12:19:28 -0700222 if (intel_crtc)
223 bpp = intel_crtc->bpp;
224
Adam Jacksoncd9dde42011-10-14 12:43:49 -0400225 return (pixel_clock * bpp + 9) / 10;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700226}
227
228static int
Dave Airliefe27d532010-06-30 11:46:17 +1000229intel_dp_max_data_rate(int max_link_clock, int max_lanes)
230{
231 return (max_link_clock * max_lanes * 8) / 10;
232}
233
234static int
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700235intel_dp_mode_valid(struct drm_connector *connector,
236 struct drm_display_mode *mode)
237{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100238 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100239 int max_link_clock = intel_dp_link_clock(intel_dp_max_link_bw(intel_dp));
240 int max_lanes = intel_dp_max_lane_count(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700241
Keith Packardd15456d2011-09-18 17:35:47 -0700242 if (is_edp(intel_dp) && intel_dp->panel_fixed_mode) {
243 if (mode->hdisplay > intel_dp->panel_fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100244 return MODE_PANEL;
245
Keith Packardd15456d2011-09-18 17:35:47 -0700246 if (mode->vdisplay > intel_dp->panel_fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100247 return MODE_PANEL;
248 }
249
Adam Jacksondc22ee62011-10-14 12:43:50 -0400250 if (intel_dp_link_required(intel_dp, mode->clock)
251 > intel_dp_max_data_rate(max_link_clock, max_lanes))
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700252 return MODE_CLOCK_HIGH;
253
254 if (mode->clock < 10000)
255 return MODE_CLOCK_LOW;
256
257 return MODE_OK;
258}
259
260static uint32_t
261pack_aux(uint8_t *src, int src_bytes)
262{
263 int i;
264 uint32_t v = 0;
265
266 if (src_bytes > 4)
267 src_bytes = 4;
268 for (i = 0; i < src_bytes; i++)
269 v |= ((uint32_t) src[i]) << ((3-i) * 8);
270 return v;
271}
272
273static void
274unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
275{
276 int i;
277 if (dst_bytes > 4)
278 dst_bytes = 4;
279 for (i = 0; i < dst_bytes; i++)
280 dst[i] = src >> ((3-i) * 8);
281}
282
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700283/* hrawclock is 1/4 the FSB frequency */
284static int
285intel_hrawclk(struct drm_device *dev)
286{
287 struct drm_i915_private *dev_priv = dev->dev_private;
288 uint32_t clkcfg;
289
290 clkcfg = I915_READ(CLKCFG);
291 switch (clkcfg & CLKCFG_FSB_MASK) {
292 case CLKCFG_FSB_400:
293 return 100;
294 case CLKCFG_FSB_533:
295 return 133;
296 case CLKCFG_FSB_667:
297 return 166;
298 case CLKCFG_FSB_800:
299 return 200;
300 case CLKCFG_FSB_1067:
301 return 266;
302 case CLKCFG_FSB_1333:
303 return 333;
304 /* these two are just a guess; one of them might be right */
305 case CLKCFG_FSB_1600:
306 case CLKCFG_FSB_1600_ALT:
307 return 400;
308 default:
309 return 133;
310 }
311}
312
Keith Packardebf33b12011-09-29 15:53:27 -0700313static bool ironlake_edp_have_panel_power(struct intel_dp *intel_dp)
314{
315 struct drm_device *dev = intel_dp->base.base.dev;
316 struct drm_i915_private *dev_priv = dev->dev_private;
317
318 return (I915_READ(PCH_PP_STATUS) & PP_ON) != 0;
319}
320
321static bool ironlake_edp_have_panel_vdd(struct intel_dp *intel_dp)
322{
323 struct drm_device *dev = intel_dp->base.base.dev;
324 struct drm_i915_private *dev_priv = dev->dev_private;
325
326 return (I915_READ(PCH_PP_CONTROL) & EDP_FORCE_VDD) != 0;
327}
328
Keith Packard9b984da2011-09-19 13:54:47 -0700329static void
330intel_dp_check_edp(struct intel_dp *intel_dp)
331{
332 struct drm_device *dev = intel_dp->base.base.dev;
333 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packardebf33b12011-09-29 15:53:27 -0700334
Keith Packard9b984da2011-09-19 13:54:47 -0700335 if (!is_edp(intel_dp))
336 return;
Keith Packardebf33b12011-09-29 15:53:27 -0700337 if (!ironlake_edp_have_panel_power(intel_dp) && !ironlake_edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700338 WARN(1, "eDP powered off while attempting aux channel communication.\n");
339 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Keith Packardebf33b12011-09-29 15:53:27 -0700340 I915_READ(PCH_PP_STATUS),
Keith Packard9b984da2011-09-19 13:54:47 -0700341 I915_READ(PCH_PP_CONTROL));
342 }
343}
344
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700345static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100346intel_dp_aux_ch(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700347 uint8_t *send, int send_bytes,
348 uint8_t *recv, int recv_size)
349{
Chris Wilsonea5b2132010-08-04 13:50:23 +0100350 uint32_t output_reg = intel_dp->output_reg;
Chris Wilson4ef69c72010-09-09 15:14:28 +0100351 struct drm_device *dev = intel_dp->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700352 struct drm_i915_private *dev_priv = dev->dev_private;
353 uint32_t ch_ctl = output_reg + 0x10;
354 uint32_t ch_data = ch_ctl + 4;
355 int i;
356 int recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700357 uint32_t status;
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700358 uint32_t aux_clock_divider;
Zhenyu Wange3421a12010-04-08 09:43:27 +0800359 int try, precharge;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700360
Keith Packard9b984da2011-09-19 13:54:47 -0700361 intel_dp_check_edp(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700362 /* The clock divider is based off the hrawclk,
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700363 * and would like to run at 2MHz. So, take the
364 * hrawclk value and divide by 2 and use that
Jesse Barnes6176b8f2010-09-08 12:42:00 -0700365 *
366 * Note that PCH attached eDP panels should use a 125MHz input
367 * clock divider.
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700368 */
Adam Jackson1c958222011-10-14 17:22:25 -0400369 if (is_cpu_edp(intel_dp)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +0800370 if (IS_GEN6(dev))
371 aux_clock_divider = 200; /* SNB eDP input clock at 400Mhz */
372 else
373 aux_clock_divider = 225; /* eDP input clock at 450Mhz */
374 } else if (HAS_PCH_SPLIT(dev))
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500375 aux_clock_divider = 62; /* IRL input clock fixed at 125Mhz */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +0800376 else
377 aux_clock_divider = intel_hrawclk(dev) / 2;
378
Zhenyu Wange3421a12010-04-08 09:43:27 +0800379 if (IS_GEN6(dev))
380 precharge = 3;
381 else
382 precharge = 5;
383
Jesse Barnes11bee432011-08-01 15:02:20 -0700384 /* Try to wait for any previous AUX channel activity */
385 for (try = 0; try < 3; try++) {
386 status = I915_READ(ch_ctl);
387 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
388 break;
389 msleep(1);
390 }
391
392 if (try == 3) {
393 WARN(1, "dp_aux_ch not started status 0x%08x\n",
394 I915_READ(ch_ctl));
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100395 return -EBUSY;
396 }
397
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700398 /* Must try at least 3 times according to DP spec */
399 for (try = 0; try < 5; try++) {
400 /* Load the send data into the aux channel data registers */
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100401 for (i = 0; i < send_bytes; i += 4)
402 I915_WRITE(ch_data + i,
403 pack_aux(send + i, send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -0400404
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700405 /* Send the command and wait for it to complete */
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100406 I915_WRITE(ch_ctl,
407 DP_AUX_CH_CTL_SEND_BUSY |
408 DP_AUX_CH_CTL_TIME_OUT_400us |
409 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
410 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
411 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT) |
412 DP_AUX_CH_CTL_DONE |
413 DP_AUX_CH_CTL_TIME_OUT_ERROR |
414 DP_AUX_CH_CTL_RECEIVE_ERROR);
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700415 for (;;) {
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700416 status = I915_READ(ch_ctl);
417 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
418 break;
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100419 udelay(100);
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700420 }
Akshay Joshi0206e352011-08-16 15:34:10 -0400421
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700422 /* Clear done status and any errors */
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100423 I915_WRITE(ch_ctl,
424 status |
425 DP_AUX_CH_CTL_DONE |
426 DP_AUX_CH_CTL_TIME_OUT_ERROR |
427 DP_AUX_CH_CTL_RECEIVE_ERROR);
428 if (status & DP_AUX_CH_CTL_DONE)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700429 break;
430 }
431
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700432 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700433 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Keith Packarda5b3da52009-06-11 22:30:32 -0700434 return -EBUSY;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700435 }
436
437 /* Check for timeout or receive error.
438 * Timeouts occur when the sink is not connected
439 */
Keith Packarda5b3da52009-06-11 22:30:32 -0700440 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700441 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Keith Packarda5b3da52009-06-11 22:30:32 -0700442 return -EIO;
443 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700444
445 /* Timeouts occur when the device isn't connected, so they're
446 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -0700447 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Zhao Yakui28c97732009-10-09 11:39:41 +0800448 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Keith Packarda5b3da52009-06-11 22:30:32 -0700449 return -ETIMEDOUT;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700450 }
451
452 /* Unload any bytes sent back from the other side */
453 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
454 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700455 if (recv_bytes > recv_size)
456 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -0400457
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100458 for (i = 0; i < recv_bytes; i += 4)
459 unpack_aux(I915_READ(ch_data + i),
460 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700461
462 return recv_bytes;
463}
464
465/* Write data to the aux channel in native mode */
466static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100467intel_dp_aux_native_write(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700468 uint16_t address, uint8_t *send, int send_bytes)
469{
470 int ret;
471 uint8_t msg[20];
472 int msg_bytes;
473 uint8_t ack;
474
Keith Packard9b984da2011-09-19 13:54:47 -0700475 intel_dp_check_edp(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700476 if (send_bytes > 16)
477 return -1;
478 msg[0] = AUX_NATIVE_WRITE << 4;
479 msg[1] = address >> 8;
Zhenyu Wangeebc8632009-07-24 01:00:30 +0800480 msg[2] = address & 0xff;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700481 msg[3] = send_bytes - 1;
482 memcpy(&msg[4], send, send_bytes);
483 msg_bytes = send_bytes + 4;
484 for (;;) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100485 ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes, &ack, 1);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700486 if (ret < 0)
487 return ret;
488 if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK)
489 break;
490 else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
491 udelay(100);
492 else
Keith Packarda5b3da52009-06-11 22:30:32 -0700493 return -EIO;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700494 }
495 return send_bytes;
496}
497
498/* Write a single byte to the aux channel in native mode */
499static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100500intel_dp_aux_native_write_1(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700501 uint16_t address, uint8_t byte)
502{
Chris Wilsonea5b2132010-08-04 13:50:23 +0100503 return intel_dp_aux_native_write(intel_dp, address, &byte, 1);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700504}
505
506/* read bytes from a native aux channel */
507static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100508intel_dp_aux_native_read(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700509 uint16_t address, uint8_t *recv, int recv_bytes)
510{
511 uint8_t msg[4];
512 int msg_bytes;
513 uint8_t reply[20];
514 int reply_bytes;
515 uint8_t ack;
516 int ret;
517
Keith Packard9b984da2011-09-19 13:54:47 -0700518 intel_dp_check_edp(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700519 msg[0] = AUX_NATIVE_READ << 4;
520 msg[1] = address >> 8;
521 msg[2] = address & 0xff;
522 msg[3] = recv_bytes - 1;
523
524 msg_bytes = 4;
525 reply_bytes = recv_bytes + 1;
526
527 for (;;) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100528 ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700529 reply, reply_bytes);
Keith Packarda5b3da52009-06-11 22:30:32 -0700530 if (ret == 0)
531 return -EPROTO;
532 if (ret < 0)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700533 return ret;
534 ack = reply[0];
535 if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK) {
536 memcpy(recv, reply + 1, ret - 1);
537 return ret - 1;
538 }
539 else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
540 udelay(100);
541 else
Keith Packarda5b3da52009-06-11 22:30:32 -0700542 return -EIO;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700543 }
544}
545
546static int
Dave Airlieab2c0672009-12-04 10:55:24 +1000547intel_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode,
548 uint8_t write_byte, uint8_t *read_byte)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700549{
Dave Airlieab2c0672009-12-04 10:55:24 +1000550 struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100551 struct intel_dp *intel_dp = container_of(adapter,
552 struct intel_dp,
553 adapter);
Dave Airlieab2c0672009-12-04 10:55:24 +1000554 uint16_t address = algo_data->address;
555 uint8_t msg[5];
556 uint8_t reply[2];
David Flynn8316f332010-12-08 16:10:21 +0000557 unsigned retry;
Dave Airlieab2c0672009-12-04 10:55:24 +1000558 int msg_bytes;
559 int reply_bytes;
560 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700561
Keith Packard9b984da2011-09-19 13:54:47 -0700562 intel_dp_check_edp(intel_dp);
Dave Airlieab2c0672009-12-04 10:55:24 +1000563 /* Set up the command byte */
564 if (mode & MODE_I2C_READ)
565 msg[0] = AUX_I2C_READ << 4;
566 else
567 msg[0] = AUX_I2C_WRITE << 4;
568
569 if (!(mode & MODE_I2C_STOP))
570 msg[0] |= AUX_I2C_MOT << 4;
571
572 msg[1] = address >> 8;
573 msg[2] = address;
574
575 switch (mode) {
576 case MODE_I2C_WRITE:
577 msg[3] = 0;
578 msg[4] = write_byte;
579 msg_bytes = 5;
580 reply_bytes = 1;
581 break;
582 case MODE_I2C_READ:
583 msg[3] = 0;
584 msg_bytes = 4;
585 reply_bytes = 2;
586 break;
587 default:
588 msg_bytes = 3;
589 reply_bytes = 1;
590 break;
591 }
592
David Flynn8316f332010-12-08 16:10:21 +0000593 for (retry = 0; retry < 5; retry++) {
594 ret = intel_dp_aux_ch(intel_dp,
595 msg, msg_bytes,
596 reply, reply_bytes);
Dave Airlieab2c0672009-12-04 10:55:24 +1000597 if (ret < 0) {
Dave Airlie3ff99162009-12-08 14:03:47 +1000598 DRM_DEBUG_KMS("aux_ch failed %d\n", ret);
Dave Airlieab2c0672009-12-04 10:55:24 +1000599 return ret;
600 }
David Flynn8316f332010-12-08 16:10:21 +0000601
602 switch (reply[0] & AUX_NATIVE_REPLY_MASK) {
603 case AUX_NATIVE_REPLY_ACK:
604 /* I2C-over-AUX Reply field is only valid
605 * when paired with AUX ACK.
606 */
607 break;
608 case AUX_NATIVE_REPLY_NACK:
609 DRM_DEBUG_KMS("aux_ch native nack\n");
610 return -EREMOTEIO;
611 case AUX_NATIVE_REPLY_DEFER:
612 udelay(100);
613 continue;
614 default:
615 DRM_ERROR("aux_ch invalid native reply 0x%02x\n",
616 reply[0]);
617 return -EREMOTEIO;
618 }
619
Dave Airlieab2c0672009-12-04 10:55:24 +1000620 switch (reply[0] & AUX_I2C_REPLY_MASK) {
621 case AUX_I2C_REPLY_ACK:
622 if (mode == MODE_I2C_READ) {
623 *read_byte = reply[1];
624 }
625 return reply_bytes - 1;
626 case AUX_I2C_REPLY_NACK:
David Flynn8316f332010-12-08 16:10:21 +0000627 DRM_DEBUG_KMS("aux_i2c nack\n");
Dave Airlieab2c0672009-12-04 10:55:24 +1000628 return -EREMOTEIO;
629 case AUX_I2C_REPLY_DEFER:
David Flynn8316f332010-12-08 16:10:21 +0000630 DRM_DEBUG_KMS("aux_i2c defer\n");
Dave Airlieab2c0672009-12-04 10:55:24 +1000631 udelay(100);
632 break;
633 default:
David Flynn8316f332010-12-08 16:10:21 +0000634 DRM_ERROR("aux_i2c invalid reply 0x%02x\n", reply[0]);
Dave Airlieab2c0672009-12-04 10:55:24 +1000635 return -EREMOTEIO;
636 }
637 }
David Flynn8316f332010-12-08 16:10:21 +0000638
639 DRM_ERROR("too many retries, giving up\n");
640 return -EREMOTEIO;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700641}
642
Keith Packard0b5c5412011-09-28 16:41:05 -0700643static void ironlake_edp_panel_vdd_on(struct intel_dp *intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -0700644static void ironlake_edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
Keith Packard0b5c5412011-09-28 16:41:05 -0700645
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700646static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100647intel_dp_i2c_init(struct intel_dp *intel_dp,
Zhenyu Wang55f78c42010-03-29 16:13:57 +0800648 struct intel_connector *intel_connector, const char *name)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700649{
Keith Packard0b5c5412011-09-28 16:41:05 -0700650 int ret;
651
Zhenyu Wangd54e9d22009-10-19 15:43:51 +0800652 DRM_DEBUG_KMS("i2c_init %s\n", name);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100653 intel_dp->algo.running = false;
654 intel_dp->algo.address = 0;
655 intel_dp->algo.aux_ch = intel_dp_i2c_aux_ch;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700656
Akshay Joshi0206e352011-08-16 15:34:10 -0400657 memset(&intel_dp->adapter, '\0', sizeof(intel_dp->adapter));
Chris Wilsonea5b2132010-08-04 13:50:23 +0100658 intel_dp->adapter.owner = THIS_MODULE;
659 intel_dp->adapter.class = I2C_CLASS_DDC;
Akshay Joshi0206e352011-08-16 15:34:10 -0400660 strncpy(intel_dp->adapter.name, name, sizeof(intel_dp->adapter.name) - 1);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100661 intel_dp->adapter.name[sizeof(intel_dp->adapter.name) - 1] = '\0';
662 intel_dp->adapter.algo_data = &intel_dp->algo;
663 intel_dp->adapter.dev.parent = &intel_connector->base.kdev;
664
Keith Packard0b5c5412011-09-28 16:41:05 -0700665 ironlake_edp_panel_vdd_on(intel_dp);
666 ret = i2c_dp_aux_add_bus(&intel_dp->adapter);
Keith Packardbd943152011-09-18 23:09:52 -0700667 ironlake_edp_panel_vdd_off(intel_dp, false);
Keith Packard0b5c5412011-09-28 16:41:05 -0700668 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700669}
670
671static bool
672intel_dp_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode,
673 struct drm_display_mode *adjusted_mode)
674{
Zhao Yakui0d3a1bee2010-07-19 09:43:13 +0100675 struct drm_device *dev = encoder->dev;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100676 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700677 int lane_count, clock;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100678 int max_lane_count = intel_dp_max_lane_count(intel_dp);
679 int max_clock = intel_dp_max_link_bw(intel_dp) == DP_LINK_BW_2_7 ? 1 : 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700680 static int bws[2] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7 };
681
Keith Packardd15456d2011-09-18 17:35:47 -0700682 if (is_edp(intel_dp) && intel_dp->panel_fixed_mode) {
683 intel_fixed_panel_mode(intel_dp->panel_fixed_mode, adjusted_mode);
Chris Wilson1d8e1c72010-08-07 11:01:28 +0100684 intel_pch_panel_fitting(dev, DRM_MODE_SCALE_FULLSCREEN,
685 mode, adjusted_mode);
Zhao Yakui0d3a1bee2010-07-19 09:43:13 +0100686 /*
687 * the mode->clock is used to calculate the Data&Link M/N
688 * of the pipe. For the eDP the fixed clock should be used.
689 */
Keith Packardd15456d2011-09-18 17:35:47 -0700690 mode->clock = intel_dp->panel_fixed_mode->clock;
Zhao Yakui0d3a1bee2010-07-19 09:43:13 +0100691 }
692
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700693 for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) {
694 for (clock = 0; clock <= max_clock; clock++) {
Dave Airliefe27d532010-06-30 11:46:17 +1000695 int link_avail = intel_dp_max_data_rate(intel_dp_link_clock(bws[clock]), lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700696
Adam Jacksoncd9dde42011-10-14 12:43:49 -0400697 if (intel_dp_link_required(intel_dp, mode->clock)
Zhenyu Wang885a5fb2010-01-12 05:38:31 +0800698 <= link_avail) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100699 intel_dp->link_bw = bws[clock];
700 intel_dp->lane_count = lane_count;
701 adjusted_mode->clock = intel_dp_link_clock(intel_dp->link_bw);
Zhao Yakui28c97732009-10-09 11:39:41 +0800702 DRM_DEBUG_KMS("Display port link bw %02x lane "
703 "count %d clock %d\n",
Chris Wilsonea5b2132010-08-04 13:50:23 +0100704 intel_dp->link_bw, intel_dp->lane_count,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700705 adjusted_mode->clock);
706 return true;
707 }
708 }
709 }
Dave Airliefe27d532010-06-30 11:46:17 +1000710
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700711 return false;
712}
713
714struct intel_dp_m_n {
715 uint32_t tu;
716 uint32_t gmch_m;
717 uint32_t gmch_n;
718 uint32_t link_m;
719 uint32_t link_n;
720};
721
722static void
723intel_reduce_ratio(uint32_t *num, uint32_t *den)
724{
725 while (*num > 0xffffff || *den > 0xffffff) {
726 *num >>= 1;
727 *den >>= 1;
728 }
729}
730
731static void
Zhao Yakui36e83a12010-06-12 14:32:21 +0800732intel_dp_compute_m_n(int bpp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700733 int nlanes,
734 int pixel_clock,
735 int link_clock,
736 struct intel_dp_m_n *m_n)
737{
738 m_n->tu = 64;
Zhao Yakui36e83a12010-06-12 14:32:21 +0800739 m_n->gmch_m = (pixel_clock * bpp) >> 3;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700740 m_n->gmch_n = link_clock * nlanes;
741 intel_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
742 m_n->link_m = pixel_clock;
743 m_n->link_n = link_clock;
744 intel_reduce_ratio(&m_n->link_m, &m_n->link_n);
745}
746
747void
748intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode,
749 struct drm_display_mode *adjusted_mode)
750{
751 struct drm_device *dev = crtc->dev;
752 struct drm_mode_config *mode_config = &dev->mode_config;
Zhenyu Wang55f78c42010-03-29 16:13:57 +0800753 struct drm_encoder *encoder;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700754 struct drm_i915_private *dev_priv = dev->dev_private;
755 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnes858fa0352011-06-24 12:19:24 -0700756 int lane_count = 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700757 struct intel_dp_m_n m_n;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800758 int pipe = intel_crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700759
760 /*
Eric Anholt21d40d32010-03-25 11:11:14 -0700761 * Find the lane count in the intel_encoder private
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700762 */
Zhenyu Wang55f78c42010-03-29 16:13:57 +0800763 list_for_each_entry(encoder, &mode_config->encoder_list, head) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100764 struct intel_dp *intel_dp;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700765
Dan Carpenterd8201ab2010-05-07 10:39:00 +0200766 if (encoder->crtc != crtc)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700767 continue;
768
Chris Wilsonea5b2132010-08-04 13:50:23 +0100769 intel_dp = enc_to_intel_dp(encoder);
770 if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT) {
771 lane_count = intel_dp->lane_count;
Jesse Barnes51190662010-10-07 16:01:08 -0700772 break;
773 } else if (is_edp(intel_dp)) {
774 lane_count = dev_priv->edp.lanes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700775 break;
776 }
777 }
778
779 /*
780 * Compute the GMCH and Link ratios. The '3' here is
781 * the number of bytes_per_pixel post-LUT, which we always
782 * set up for 8-bits of R/G/B, or 3 bytes total.
783 */
Jesse Barnes858fa0352011-06-24 12:19:24 -0700784 intel_dp_compute_m_n(intel_crtc->bpp, lane_count,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700785 mode->clock, adjusted_mode->clock, &m_n);
786
Eric Anholtc619eed2010-01-28 16:45:52 -0800787 if (HAS_PCH_SPLIT(dev)) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800788 I915_WRITE(TRANSDATA_M1(pipe),
789 ((m_n.tu - 1) << PIPE_GMCH_DATA_M_TU_SIZE_SHIFT) |
790 m_n.gmch_m);
791 I915_WRITE(TRANSDATA_N1(pipe), m_n.gmch_n);
792 I915_WRITE(TRANSDPLINK_M1(pipe), m_n.link_m);
793 I915_WRITE(TRANSDPLINK_N1(pipe), m_n.link_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700794 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800795 I915_WRITE(PIPE_GMCH_DATA_M(pipe),
796 ((m_n.tu - 1) << PIPE_GMCH_DATA_M_TU_SIZE_SHIFT) |
797 m_n.gmch_m);
798 I915_WRITE(PIPE_GMCH_DATA_N(pipe), m_n.gmch_n);
799 I915_WRITE(PIPE_DP_LINK_M(pipe), m_n.link_m);
800 I915_WRITE(PIPE_DP_LINK_N(pipe), m_n.link_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700801 }
802}
803
Keith Packardf01eca22011-09-28 16:48:10 -0700804static void ironlake_edp_pll_on(struct drm_encoder *encoder);
805static void ironlake_edp_pll_off(struct drm_encoder *encoder);
806
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700807static void
808intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
809 struct drm_display_mode *adjusted_mode)
810{
Zhenyu Wange3421a12010-04-08 09:43:27 +0800811 struct drm_device *dev = encoder->dev;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100812 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Chris Wilson4ef69c72010-09-09 15:14:28 +0100813 struct drm_crtc *crtc = intel_dp->base.base.crtc;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700814 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
815
Keith Packardf01eca22011-09-28 16:48:10 -0700816 /* Turn on the eDP PLL if needed */
817 if (is_edp(intel_dp)) {
818 if (!is_pch_edp(intel_dp))
819 ironlake_edp_pll_on(encoder);
820 else
821 ironlake_edp_pll_off(encoder);
822 }
823
Chris Wilsone953fd72011-02-21 22:23:52 +0000824 intel_dp->DP = DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
825 intel_dp->DP |= intel_dp->color_range;
Adam Jackson9c9e7922010-04-05 17:57:59 -0400826
827 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
Chris Wilsonea5b2132010-08-04 13:50:23 +0100828 intel_dp->DP |= DP_SYNC_HS_HIGH;
Adam Jackson9c9e7922010-04-05 17:57:59 -0400829 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
Chris Wilsonea5b2132010-08-04 13:50:23 +0100830 intel_dp->DP |= DP_SYNC_VS_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700831
Adam Jackson82d16552011-10-14 17:22:26 -0400832 if (HAS_PCH_CPT(dev) && !is_cpu_edp(intel_dp))
Chris Wilsonea5b2132010-08-04 13:50:23 +0100833 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +0800834 else
Chris Wilsonea5b2132010-08-04 13:50:23 +0100835 intel_dp->DP |= DP_LINK_TRAIN_OFF;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700836
Chris Wilsonea5b2132010-08-04 13:50:23 +0100837 switch (intel_dp->lane_count) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700838 case 1:
Chris Wilsonea5b2132010-08-04 13:50:23 +0100839 intel_dp->DP |= DP_PORT_WIDTH_1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700840 break;
841 case 2:
Chris Wilsonea5b2132010-08-04 13:50:23 +0100842 intel_dp->DP |= DP_PORT_WIDTH_2;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700843 break;
844 case 4:
Chris Wilsonea5b2132010-08-04 13:50:23 +0100845 intel_dp->DP |= DP_PORT_WIDTH_4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700846 break;
847 }
Wu Fengguange0dac652011-09-05 14:25:34 +0800848 if (intel_dp->has_audio) {
849 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
850 pipe_name(intel_crtc->pipe));
Chris Wilsonea5b2132010-08-04 13:50:23 +0100851 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Wu Fengguange0dac652011-09-05 14:25:34 +0800852 intel_write_eld(encoder, adjusted_mode);
853 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700854
Chris Wilsonea5b2132010-08-04 13:50:23 +0100855 memset(intel_dp->link_configuration, 0, DP_LINK_CONFIGURATION_SIZE);
856 intel_dp->link_configuration[0] = intel_dp->link_bw;
857 intel_dp->link_configuration[1] = intel_dp->lane_count;
Adam Jacksona2cab1b2011-07-12 17:38:05 -0400858 intel_dp->link_configuration[8] = DP_SET_ANSI_8B10B;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700859
860 /*
Adam Jackson9962c922010-05-13 14:45:42 -0400861 * Check for DPCD version > 1.1 and enhanced framing support
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700862 */
Jesse Barnes7183dc22011-07-07 11:10:58 -0700863 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
864 (intel_dp->dpcd[DP_MAX_LANE_COUNT] & DP_ENHANCED_FRAME_CAP)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100865 intel_dp->link_configuration[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
866 intel_dp->DP |= DP_ENHANCED_FRAMING;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700867 }
868
Zhenyu Wange3421a12010-04-08 09:43:27 +0800869 /* CPT DP's pipe select is decided in TRANS_DP_CTL */
870 if (intel_crtc->pipe == 1 && !HAS_PCH_CPT(dev))
Chris Wilsonea5b2132010-08-04 13:50:23 +0100871 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800872
Adam Jackson1c958222011-10-14 17:22:25 -0400873 if (is_cpu_edp(intel_dp)) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800874 /* don't miss out required setting for eDP */
Chris Wilsonea5b2132010-08-04 13:50:23 +0100875 intel_dp->DP |= DP_PLL_ENABLE;
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800876 if (adjusted_mode->clock < 200000)
Chris Wilsonea5b2132010-08-04 13:50:23 +0100877 intel_dp->DP |= DP_PLL_FREQ_160MHZ;
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800878 else
Chris Wilsonea5b2132010-08-04 13:50:23 +0100879 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800880 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700881}
882
Keith Packardbd943152011-09-18 23:09:52 -0700883static void ironlake_wait_panel_off(struct intel_dp *intel_dp)
884{
885 unsigned long off_time;
886 unsigned long delay;
Keith Packard32ce6972011-09-29 16:51:26 -0700887
Keith Packardbd943152011-09-18 23:09:52 -0700888 DRM_DEBUG_KMS("Wait for panel power off time\n");
Keith Packard32ce6972011-09-29 16:51:26 -0700889
890 if (ironlake_edp_have_panel_power(intel_dp) ||
891 ironlake_edp_have_panel_vdd(intel_dp))
892 {
893 DRM_DEBUG_KMS("Panel still on, no delay needed\n");
894 return;
895 }
896
Keith Packardbd943152011-09-18 23:09:52 -0700897 off_time = intel_dp->panel_off_jiffies + msecs_to_jiffies(intel_dp->panel_power_down_delay);
898 if (time_after(jiffies, off_time)) {
899 DRM_DEBUG_KMS("Time already passed");
900 return;
901 }
902 delay = jiffies_to_msecs(off_time - jiffies);
903 if (delay > intel_dp->panel_power_down_delay)
904 delay = intel_dp->panel_power_down_delay;
905 DRM_DEBUG_KMS("Waiting an additional %ld ms\n", delay);
906 msleep(delay);
907}
908
Keith Packard832dd3c2011-11-01 19:34:06 -0700909/* Read the current pp_control value, unlocking the register if it
910 * is locked
911 */
912
913static u32 ironlake_get_pp_control(struct drm_i915_private *dev_priv)
914{
915 u32 control = I915_READ(PCH_PP_CONTROL);
916
917 control &= ~PANEL_UNLOCK_MASK;
918 control |= PANEL_UNLOCK_REGS;
919 return control;
920}
921
Jesse Barnes5d613502011-01-24 17:10:54 -0800922static void ironlake_edp_panel_vdd_on(struct intel_dp *intel_dp)
923{
924 struct drm_device *dev = intel_dp->base.base.dev;
925 struct drm_i915_private *dev_priv = dev->dev_private;
926 u32 pp;
927
Keith Packard97af61f572011-09-28 16:23:51 -0700928 if (!is_edp(intel_dp))
929 return;
Keith Packardf01eca22011-09-28 16:48:10 -0700930 DRM_DEBUG_KMS("Turn eDP VDD on\n");
Jesse Barnes5d613502011-01-24 17:10:54 -0800931
Keith Packardbd943152011-09-18 23:09:52 -0700932 WARN(intel_dp->want_panel_vdd,
933 "eDP VDD already requested on\n");
934
935 intel_dp->want_panel_vdd = true;
936 if (ironlake_edp_have_panel_vdd(intel_dp)) {
937 DRM_DEBUG_KMS("eDP VDD already on\n");
938 return;
939 }
940
941 ironlake_wait_panel_off(intel_dp);
Keith Packard832dd3c2011-11-01 19:34:06 -0700942 pp = ironlake_get_pp_control(dev_priv);
Jesse Barnes5d613502011-01-24 17:10:54 -0800943 pp |= EDP_FORCE_VDD;
944 I915_WRITE(PCH_PP_CONTROL, pp);
945 POSTING_READ(PCH_PP_CONTROL);
Keith Packardf01eca22011-09-28 16:48:10 -0700946 DRM_DEBUG_KMS("PCH_PP_STATUS: 0x%08x PCH_PP_CONTROL: 0x%08x\n",
947 I915_READ(PCH_PP_STATUS), I915_READ(PCH_PP_CONTROL));
Keith Packardebf33b12011-09-29 15:53:27 -0700948
949 /*
950 * If the panel wasn't on, delay before accessing aux channel
951 */
952 if (!ironlake_edp_have_panel_power(intel_dp)) {
Keith Packardbd943152011-09-18 23:09:52 -0700953 DRM_DEBUG_KMS("eDP was not running\n");
Keith Packardf01eca22011-09-28 16:48:10 -0700954 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -0700955 }
Jesse Barnes5d613502011-01-24 17:10:54 -0800956}
957
Keith Packardbd943152011-09-18 23:09:52 -0700958static void ironlake_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -0800959{
960 struct drm_device *dev = intel_dp->base.base.dev;
961 struct drm_i915_private *dev_priv = dev->dev_private;
962 u32 pp;
963
Keith Packardbd943152011-09-18 23:09:52 -0700964 if (!intel_dp->want_panel_vdd && ironlake_edp_have_panel_vdd(intel_dp)) {
Keith Packard832dd3c2011-11-01 19:34:06 -0700965 pp = ironlake_get_pp_control(dev_priv);
Keith Packardbd943152011-09-18 23:09:52 -0700966 pp &= ~EDP_FORCE_VDD;
967 I915_WRITE(PCH_PP_CONTROL, pp);
968 POSTING_READ(PCH_PP_CONTROL);
Jesse Barnes5d613502011-01-24 17:10:54 -0800969
Keith Packardbd943152011-09-18 23:09:52 -0700970 /* Make sure sequencer is idle before allowing subsequent activity */
971 DRM_DEBUG_KMS("PCH_PP_STATUS: 0x%08x PCH_PP_CONTROL: 0x%08x\n",
972 I915_READ(PCH_PP_STATUS), I915_READ(PCH_PP_CONTROL));
973 intel_dp->panel_off_jiffies = jiffies;
974 }
975}
976
977static void ironlake_panel_vdd_work(struct work_struct *__work)
978{
979 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
980 struct intel_dp, panel_vdd_work);
981 struct drm_device *dev = intel_dp->base.base.dev;
982
Keith Packard627f7672011-10-31 11:30:10 -0700983 mutex_lock(&dev->mode_config.mutex);
Keith Packardbd943152011-09-18 23:09:52 -0700984 ironlake_panel_vdd_off_sync(intel_dp);
Keith Packard627f7672011-10-31 11:30:10 -0700985 mutex_unlock(&dev->mode_config.mutex);
Keith Packardbd943152011-09-18 23:09:52 -0700986}
987
988static void ironlake_edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
989{
Keith Packard97af61f572011-09-28 16:23:51 -0700990 if (!is_edp(intel_dp))
991 return;
Jesse Barnes5d613502011-01-24 17:10:54 -0800992
Keith Packardbd943152011-09-18 23:09:52 -0700993 DRM_DEBUG_KMS("Turn eDP VDD off %d\n", intel_dp->want_panel_vdd);
994 WARN(!intel_dp->want_panel_vdd, "eDP VDD not forced on");
995
996 intel_dp->want_panel_vdd = false;
997
998 if (sync) {
999 ironlake_panel_vdd_off_sync(intel_dp);
1000 } else {
1001 /*
1002 * Queue the timer to fire a long
1003 * time from now (relative to the power down delay)
1004 * to keep the panel power up across a sequence of operations
1005 */
1006 schedule_delayed_work(&intel_dp->panel_vdd_work,
1007 msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5));
1008 }
Jesse Barnes5d613502011-01-24 17:10:54 -08001009}
1010
Jesse Barnes7eaf5542010-09-08 12:41:59 -07001011/* Returns true if the panel was already on when called */
Keith Packard86a30732011-10-20 13:40:33 -07001012static void ironlake_edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07001013{
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001014 struct drm_device *dev = intel_dp->base.base.dev;
Jesse Barnes9934c132010-07-22 13:18:19 -07001015 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001016 u32 pp, idle_on_mask = PP_ON | PP_SEQUENCE_STATE_ON_IDLE;
Jesse Barnes9934c132010-07-22 13:18:19 -07001017
Keith Packard97af61f572011-09-28 16:23:51 -07001018 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07001019 return;
Keith Packardebf33b12011-09-29 15:53:27 -07001020 if (ironlake_edp_have_panel_power(intel_dp))
Keith Packard7d639f32011-09-29 16:05:34 -07001021 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07001022
Keith Packardbd943152011-09-18 23:09:52 -07001023 ironlake_wait_panel_off(intel_dp);
Keith Packard832dd3c2011-11-01 19:34:06 -07001024 pp = ironlake_get_pp_control(dev_priv);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001025
Keith Packard05ce1a42011-09-29 16:33:01 -07001026 if (IS_GEN5(dev)) {
1027 /* ILK workaround: disable reset around power sequence */
1028 pp &= ~PANEL_POWER_RESET;
1029 I915_WRITE(PCH_PP_CONTROL, pp);
1030 POSTING_READ(PCH_PP_CONTROL);
1031 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001032
Keith Packard1c0ae802011-09-19 13:59:29 -07001033 pp |= POWER_TARGET_ON;
Jesse Barnes9934c132010-07-22 13:18:19 -07001034 I915_WRITE(PCH_PP_CONTROL, pp);
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001035 POSTING_READ(PCH_PP_CONTROL);
Jesse Barnes9934c132010-07-22 13:18:19 -07001036
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001037 if (wait_for((I915_READ(PCH_PP_STATUS) & idle_on_mask) == idle_on_mask,
1038 5000))
Chris Wilson913d8d12010-08-07 11:01:35 +01001039 DRM_ERROR("panel on wait timed out: 0x%08x\n",
1040 I915_READ(PCH_PP_STATUS));
Jesse Barnes9934c132010-07-22 13:18:19 -07001041
Keith Packard05ce1a42011-09-29 16:33:01 -07001042 if (IS_GEN5(dev)) {
1043 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
1044 I915_WRITE(PCH_PP_CONTROL, pp);
1045 POSTING_READ(PCH_PP_CONTROL);
1046 }
Jesse Barnes9934c132010-07-22 13:18:19 -07001047}
1048
Keith Packardf01eca22011-09-28 16:48:10 -07001049static void ironlake_edp_panel_off(struct drm_encoder *encoder)
Jesse Barnes9934c132010-07-22 13:18:19 -07001050{
Keith Packardf01eca22011-09-28 16:48:10 -07001051 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1052 struct drm_device *dev = encoder->dev;
Jesse Barnes9934c132010-07-22 13:18:19 -07001053 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001054 u32 pp, idle_off_mask = PP_ON | PP_SEQUENCE_MASK |
1055 PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK;
Jesse Barnes9934c132010-07-22 13:18:19 -07001056
Keith Packard97af61f572011-09-28 16:23:51 -07001057 if (!is_edp(intel_dp))
1058 return;
Keith Packard832dd3c2011-11-01 19:34:06 -07001059 pp = ironlake_get_pp_control(dev_priv);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001060
Keith Packard05ce1a42011-09-29 16:33:01 -07001061 if (IS_GEN5(dev)) {
1062 /* ILK workaround: disable reset around power sequence */
1063 pp &= ~PANEL_POWER_RESET;
1064 I915_WRITE(PCH_PP_CONTROL, pp);
1065 POSTING_READ(PCH_PP_CONTROL);
1066 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001067
Keith Packardbd943152011-09-18 23:09:52 -07001068 intel_dp->panel_off_jiffies = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07001069
Keith Packard05ce1a42011-09-29 16:33:01 -07001070 if (IS_GEN5(dev)) {
1071 pp &= ~POWER_TARGET_ON;
1072 I915_WRITE(PCH_PP_CONTROL, pp);
1073 POSTING_READ(PCH_PP_CONTROL);
1074 pp &= ~POWER_TARGET_ON;
1075 I915_WRITE(PCH_PP_CONTROL, pp);
1076 POSTING_READ(PCH_PP_CONTROL);
1077 msleep(intel_dp->panel_power_cycle_delay);
Jesse Barnes9934c132010-07-22 13:18:19 -07001078
Keith Packard05ce1a42011-09-29 16:33:01 -07001079 if (wait_for((I915_READ(PCH_PP_STATUS) & idle_off_mask) == 0, 5000))
1080 DRM_ERROR("panel off wait timed out: 0x%08x\n",
1081 I915_READ(PCH_PP_STATUS));
1082
1083 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
1084 I915_WRITE(PCH_PP_CONTROL, pp);
1085 POSTING_READ(PCH_PP_CONTROL);
1086 }
Jesse Barnes9934c132010-07-22 13:18:19 -07001087}
1088
Keith Packard86a30732011-10-20 13:40:33 -07001089static void ironlake_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001090{
Keith Packardf01eca22011-09-28 16:48:10 -07001091 struct drm_device *dev = intel_dp->base.base.dev;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001092 struct drm_i915_private *dev_priv = dev->dev_private;
1093 u32 pp;
1094
Keith Packardf01eca22011-09-28 16:48:10 -07001095 if (!is_edp(intel_dp))
1096 return;
1097
Zhao Yakui28c97732009-10-09 11:39:41 +08001098 DRM_DEBUG_KMS("\n");
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001099 /*
1100 * If we enable the backlight right away following a panel power
1101 * on, we may see slight flicker as the panel syncs with the eDP
1102 * link. So delay a bit to make sure the image is solid before
1103 * allowing it to appear.
1104 */
Keith Packardf01eca22011-09-28 16:48:10 -07001105 msleep(intel_dp->backlight_on_delay);
Keith Packard832dd3c2011-11-01 19:34:06 -07001106 pp = ironlake_get_pp_control(dev_priv);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001107 pp |= EDP_BLC_ENABLE;
1108 I915_WRITE(PCH_PP_CONTROL, pp);
Keith Packardf01eca22011-09-28 16:48:10 -07001109 POSTING_READ(PCH_PP_CONTROL);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001110}
1111
Keith Packard86a30732011-10-20 13:40:33 -07001112static void ironlake_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001113{
Keith Packardf01eca22011-09-28 16:48:10 -07001114 struct drm_device *dev = intel_dp->base.base.dev;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001115 struct drm_i915_private *dev_priv = dev->dev_private;
1116 u32 pp;
1117
Keith Packardf01eca22011-09-28 16:48:10 -07001118 if (!is_edp(intel_dp))
1119 return;
1120
Zhao Yakui28c97732009-10-09 11:39:41 +08001121 DRM_DEBUG_KMS("\n");
Keith Packard832dd3c2011-11-01 19:34:06 -07001122 pp = ironlake_get_pp_control(dev_priv);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001123 pp &= ~EDP_BLC_ENABLE;
1124 I915_WRITE(PCH_PP_CONTROL, pp);
Keith Packardf01eca22011-09-28 16:48:10 -07001125 POSTING_READ(PCH_PP_CONTROL);
1126 msleep(intel_dp->backlight_off_delay);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001127}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001128
Jesse Barnesd240f202010-08-13 15:43:26 -07001129static void ironlake_edp_pll_on(struct drm_encoder *encoder)
1130{
1131 struct drm_device *dev = encoder->dev;
1132 struct drm_i915_private *dev_priv = dev->dev_private;
1133 u32 dpa_ctl;
1134
1135 DRM_DEBUG_KMS("\n");
1136 dpa_ctl = I915_READ(DP_A);
Jesse Barnes298b0b32010-10-07 16:01:24 -07001137 dpa_ctl |= DP_PLL_ENABLE;
Jesse Barnesd240f202010-08-13 15:43:26 -07001138 I915_WRITE(DP_A, dpa_ctl);
Jesse Barnes298b0b32010-10-07 16:01:24 -07001139 POSTING_READ(DP_A);
1140 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07001141}
1142
1143static void ironlake_edp_pll_off(struct drm_encoder *encoder)
1144{
1145 struct drm_device *dev = encoder->dev;
1146 struct drm_i915_private *dev_priv = dev->dev_private;
1147 u32 dpa_ctl;
1148
1149 dpa_ctl = I915_READ(DP_A);
Jesse Barnes298b0b32010-10-07 16:01:24 -07001150 dpa_ctl &= ~DP_PLL_ENABLE;
Jesse Barnesd240f202010-08-13 15:43:26 -07001151 I915_WRITE(DP_A, dpa_ctl);
Chris Wilson1af5fa12010-09-08 21:07:28 +01001152 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07001153 udelay(200);
1154}
1155
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001156/* If the sink supports it, try to set the power state appropriately */
1157static void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
1158{
1159 int ret, i;
1160
1161 /* Should have a valid DPCD by this point */
1162 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
1163 return;
1164
1165 if (mode != DRM_MODE_DPMS_ON) {
1166 ret = intel_dp_aux_native_write_1(intel_dp, DP_SET_POWER,
1167 DP_SET_POWER_D3);
1168 if (ret != 1)
1169 DRM_DEBUG_DRIVER("failed to write sink power state\n");
1170 } else {
1171 /*
1172 * When turning on, we need to retry for 1ms to give the sink
1173 * time to wake up.
1174 */
1175 for (i = 0; i < 3; i++) {
1176 ret = intel_dp_aux_native_write_1(intel_dp,
1177 DP_SET_POWER,
1178 DP_SET_POWER_D0);
1179 if (ret == 1)
1180 break;
1181 msleep(1);
1182 }
1183 }
1184}
1185
Jesse Barnesd240f202010-08-13 15:43:26 -07001186static void intel_dp_prepare(struct drm_encoder *encoder)
1187{
1188 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Jesse Barnesd240f202010-08-13 15:43:26 -07001189
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001190 /* Wake up the sink first */
Keith Packardf58ff852011-09-28 16:44:14 -07001191 ironlake_edp_panel_vdd_on(intel_dp);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001192 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
Keith Packardbd943152011-09-18 23:09:52 -07001193 ironlake_edp_panel_vdd_off(intel_dp, false);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001194
Keith Packardf01eca22011-09-28 16:48:10 -07001195 /* Make sure the panel is off before trying to
1196 * change the mode
1197 */
1198 ironlake_edp_backlight_off(intel_dp);
Jesse Barnes736085b2010-10-08 10:35:55 -07001199 intel_dp_link_down(intel_dp);
Keith Packardf01eca22011-09-28 16:48:10 -07001200 ironlake_edp_panel_off(encoder);
Jesse Barnesd240f202010-08-13 15:43:26 -07001201}
1202
1203static void intel_dp_commit(struct drm_encoder *encoder)
1204{
1205 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Jesse Barnesd4270e52011-10-11 10:43:02 -07001206 struct drm_device *dev = encoder->dev;
1207 struct intel_crtc *intel_crtc = to_intel_crtc(intel_dp->base.base.crtc);
Jesse Barnesd240f202010-08-13 15:43:26 -07001208
Keith Packard97af61f572011-09-28 16:23:51 -07001209 ironlake_edp_panel_vdd_on(intel_dp);
Keith Packardf01eca22011-09-28 16:48:10 -07001210 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
Jesse Barnes33a34e42010-09-08 12:42:02 -07001211 intel_dp_start_link_train(intel_dp);
Keith Packard97af61f572011-09-28 16:23:51 -07001212 ironlake_edp_panel_on(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07001213 ironlake_edp_panel_vdd_off(intel_dp, true);
Jesse Barnes33a34e42010-09-08 12:42:02 -07001214
1215 intel_dp_complete_link_train(intel_dp);
Keith Packardf01eca22011-09-28 16:48:10 -07001216 ironlake_edp_backlight_on(intel_dp);
Keith Packardd2b996a2011-07-25 22:37:51 -07001217
1218 intel_dp->dpms_mode = DRM_MODE_DPMS_ON;
Jesse Barnesd4270e52011-10-11 10:43:02 -07001219
1220 if (HAS_PCH_CPT(dev))
1221 intel_cpt_verify_modeset(dev, intel_crtc->pipe);
Jesse Barnesd240f202010-08-13 15:43:26 -07001222}
1223
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001224static void
1225intel_dp_dpms(struct drm_encoder *encoder, int mode)
1226{
Chris Wilsonea5b2132010-08-04 13:50:23 +01001227 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08001228 struct drm_device *dev = encoder->dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001229 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001230 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001231
1232 if (mode != DRM_MODE_DPMS_ON) {
Keith Packard245e2702011-10-05 19:53:09 -07001233 ironlake_edp_panel_vdd_on(intel_dp);
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001234 if (is_edp(intel_dp))
Keith Packardf01eca22011-09-28 16:48:10 -07001235 ironlake_edp_backlight_off(intel_dp);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001236 intel_dp_sink_dpms(intel_dp, mode);
Jesse Barnes736085b2010-10-08 10:35:55 -07001237 intel_dp_link_down(intel_dp);
Keith Packardf01eca22011-09-28 16:48:10 -07001238 ironlake_edp_panel_off(encoder);
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001239 if (is_edp(intel_dp) && !is_pch_edp(intel_dp))
Jesse Barnesd240f202010-08-13 15:43:26 -07001240 ironlake_edp_pll_off(encoder);
Keith Packardbd943152011-09-18 23:09:52 -07001241 ironlake_edp_panel_vdd_off(intel_dp, false);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001242 } else {
Keith Packard97af61f572011-09-28 16:23:51 -07001243 ironlake_edp_panel_vdd_on(intel_dp);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001244 intel_dp_sink_dpms(intel_dp, mode);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001245 if (!(dp_reg & DP_PORT_EN)) {
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001246 intel_dp_start_link_train(intel_dp);
Keith Packard97af61f572011-09-28 16:23:51 -07001247 ironlake_edp_panel_on(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07001248 ironlake_edp_panel_vdd_off(intel_dp, true);
Jesse Barnes33a34e42010-09-08 12:42:02 -07001249 intel_dp_complete_link_train(intel_dp);
Keith Packardf01eca22011-09-28 16:48:10 -07001250 ironlake_edp_backlight_on(intel_dp);
Keith Packardbee7eb22011-09-28 16:28:00 -07001251 } else
Keith Packardbd943152011-09-18 23:09:52 -07001252 ironlake_edp_panel_vdd_off(intel_dp, false);
1253 ironlake_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001254 }
Keith Packardd2b996a2011-07-25 22:37:51 -07001255 intel_dp->dpms_mode = mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001256}
1257
1258/*
Jesse Barnesdf0c2372011-07-07 11:11:02 -07001259 * Native read with retry for link status and receiver capability reads for
1260 * cases where the sink may still be asleep.
1261 */
1262static bool
1263intel_dp_aux_native_read_retry(struct intel_dp *intel_dp, uint16_t address,
1264 uint8_t *recv, int recv_bytes)
1265{
1266 int ret, i;
1267
1268 /*
1269 * Sinks are *supposed* to come up within 1ms from an off state,
1270 * but we're also supposed to retry 3 times per the spec.
1271 */
1272 for (i = 0; i < 3; i++) {
1273 ret = intel_dp_aux_native_read(intel_dp, address, recv,
1274 recv_bytes);
1275 if (ret == recv_bytes)
1276 return true;
1277 msleep(1);
1278 }
1279
1280 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001281}
1282
1283/*
1284 * Fetch AUX CH registers 0x202 - 0x207 which contain
1285 * link status information
1286 */
1287static bool
Jesse Barnes33a34e42010-09-08 12:42:02 -07001288intel_dp_get_link_status(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001289{
Jesse Barnesdf0c2372011-07-07 11:11:02 -07001290 return intel_dp_aux_native_read_retry(intel_dp,
1291 DP_LANE0_1_STATUS,
1292 intel_dp->link_status,
1293 DP_LINK_STATUS_SIZE);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001294}
1295
1296static uint8_t
1297intel_dp_link_status(uint8_t link_status[DP_LINK_STATUS_SIZE],
1298 int r)
1299{
1300 return link_status[r - DP_LANE0_1_STATUS];
1301}
1302
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001303static uint8_t
1304intel_get_adjust_request_voltage(uint8_t link_status[DP_LINK_STATUS_SIZE],
1305 int lane)
1306{
1307 int i = DP_ADJUST_REQUEST_LANE0_1 + (lane >> 1);
1308 int s = ((lane & 1) ?
1309 DP_ADJUST_VOLTAGE_SWING_LANE1_SHIFT :
1310 DP_ADJUST_VOLTAGE_SWING_LANE0_SHIFT);
1311 uint8_t l = intel_dp_link_status(link_status, i);
1312
1313 return ((l >> s) & 3) << DP_TRAIN_VOLTAGE_SWING_SHIFT;
1314}
1315
1316static uint8_t
1317intel_get_adjust_request_pre_emphasis(uint8_t link_status[DP_LINK_STATUS_SIZE],
1318 int lane)
1319{
1320 int i = DP_ADJUST_REQUEST_LANE0_1 + (lane >> 1);
1321 int s = ((lane & 1) ?
1322 DP_ADJUST_PRE_EMPHASIS_LANE1_SHIFT :
1323 DP_ADJUST_PRE_EMPHASIS_LANE0_SHIFT);
1324 uint8_t l = intel_dp_link_status(link_status, i);
1325
1326 return ((l >> s) & 3) << DP_TRAIN_PRE_EMPHASIS_SHIFT;
1327}
1328
1329
1330#if 0
1331static char *voltage_names[] = {
1332 "0.4V", "0.6V", "0.8V", "1.2V"
1333};
1334static char *pre_emph_names[] = {
1335 "0dB", "3.5dB", "6dB", "9.5dB"
1336};
1337static char *link_train_names[] = {
1338 "pattern 1", "pattern 2", "idle", "off"
1339};
1340#endif
1341
1342/*
1343 * These are source-specific values; current Intel hardware supports
1344 * a maximum voltage of 800mV and a maximum pre-emphasis of 6dB
1345 */
1346#define I830_DP_VOLTAGE_MAX DP_TRAIN_VOLTAGE_SWING_800
1347
1348static uint8_t
1349intel_dp_pre_emphasis_max(uint8_t voltage_swing)
1350{
1351 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
1352 case DP_TRAIN_VOLTAGE_SWING_400:
1353 return DP_TRAIN_PRE_EMPHASIS_6;
1354 case DP_TRAIN_VOLTAGE_SWING_600:
1355 return DP_TRAIN_PRE_EMPHASIS_6;
1356 case DP_TRAIN_VOLTAGE_SWING_800:
1357 return DP_TRAIN_PRE_EMPHASIS_3_5;
1358 case DP_TRAIN_VOLTAGE_SWING_1200:
1359 default:
1360 return DP_TRAIN_PRE_EMPHASIS_0;
1361 }
1362}
1363
1364static void
Jesse Barnes33a34e42010-09-08 12:42:02 -07001365intel_get_adjust_train(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001366{
1367 uint8_t v = 0;
1368 uint8_t p = 0;
1369 int lane;
1370
Jesse Barnes33a34e42010-09-08 12:42:02 -07001371 for (lane = 0; lane < intel_dp->lane_count; lane++) {
1372 uint8_t this_v = intel_get_adjust_request_voltage(intel_dp->link_status, lane);
1373 uint8_t this_p = intel_get_adjust_request_pre_emphasis(intel_dp->link_status, lane);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001374
1375 if (this_v > v)
1376 v = this_v;
1377 if (this_p > p)
1378 p = this_p;
1379 }
1380
1381 if (v >= I830_DP_VOLTAGE_MAX)
1382 v = I830_DP_VOLTAGE_MAX | DP_TRAIN_MAX_SWING_REACHED;
1383
1384 if (p >= intel_dp_pre_emphasis_max(v))
1385 p = intel_dp_pre_emphasis_max(v) | DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
1386
1387 for (lane = 0; lane < 4; lane++)
Jesse Barnes33a34e42010-09-08 12:42:02 -07001388 intel_dp->train_set[lane] = v | p;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001389}
1390
1391static uint32_t
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001392intel_dp_signal_levels(uint8_t train_set, int lane_count)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001393{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001394 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001395
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001396 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001397 case DP_TRAIN_VOLTAGE_SWING_400:
1398 default:
1399 signal_levels |= DP_VOLTAGE_0_4;
1400 break;
1401 case DP_TRAIN_VOLTAGE_SWING_600:
1402 signal_levels |= DP_VOLTAGE_0_6;
1403 break;
1404 case DP_TRAIN_VOLTAGE_SWING_800:
1405 signal_levels |= DP_VOLTAGE_0_8;
1406 break;
1407 case DP_TRAIN_VOLTAGE_SWING_1200:
1408 signal_levels |= DP_VOLTAGE_1_2;
1409 break;
1410 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001411 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001412 case DP_TRAIN_PRE_EMPHASIS_0:
1413 default:
1414 signal_levels |= DP_PRE_EMPHASIS_0;
1415 break;
1416 case DP_TRAIN_PRE_EMPHASIS_3_5:
1417 signal_levels |= DP_PRE_EMPHASIS_3_5;
1418 break;
1419 case DP_TRAIN_PRE_EMPHASIS_6:
1420 signal_levels |= DP_PRE_EMPHASIS_6;
1421 break;
1422 case DP_TRAIN_PRE_EMPHASIS_9_5:
1423 signal_levels |= DP_PRE_EMPHASIS_9_5;
1424 break;
1425 }
1426 return signal_levels;
1427}
1428
Zhenyu Wange3421a12010-04-08 09:43:27 +08001429/* Gen6's DP voltage swing and pre-emphasis control */
1430static uint32_t
1431intel_gen6_edp_signal_levels(uint8_t train_set)
1432{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001433 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
1434 DP_TRAIN_PRE_EMPHASIS_MASK);
1435 switch (signal_levels) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08001436 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001437 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
1438 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
1439 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
1440 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001441 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001442 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
1443 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001444 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001445 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
1446 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001447 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001448 case DP_TRAIN_VOLTAGE_SWING_1200 | DP_TRAIN_PRE_EMPHASIS_0:
1449 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001450 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001451 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
1452 "0x%x\n", signal_levels);
1453 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001454 }
1455}
1456
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001457static uint8_t
1458intel_get_lane_status(uint8_t link_status[DP_LINK_STATUS_SIZE],
1459 int lane)
1460{
1461 int i = DP_LANE0_1_STATUS + (lane >> 1);
1462 int s = (lane & 1) * 4;
1463 uint8_t l = intel_dp_link_status(link_status, i);
1464
1465 return (l >> s) & 0xf;
1466}
1467
1468/* Check for clock recovery is done on all channels */
1469static bool
1470intel_clock_recovery_ok(uint8_t link_status[DP_LINK_STATUS_SIZE], int lane_count)
1471{
1472 int lane;
1473 uint8_t lane_status;
1474
1475 for (lane = 0; lane < lane_count; lane++) {
1476 lane_status = intel_get_lane_status(link_status, lane);
1477 if ((lane_status & DP_LANE_CR_DONE) == 0)
1478 return false;
1479 }
1480 return true;
1481}
1482
1483/* Check to see if channel eq is done on all channels */
1484#define CHANNEL_EQ_BITS (DP_LANE_CR_DONE|\
1485 DP_LANE_CHANNEL_EQ_DONE|\
1486 DP_LANE_SYMBOL_LOCKED)
1487static bool
Jesse Barnes33a34e42010-09-08 12:42:02 -07001488intel_channel_eq_ok(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001489{
1490 uint8_t lane_align;
1491 uint8_t lane_status;
1492 int lane;
1493
Jesse Barnes33a34e42010-09-08 12:42:02 -07001494 lane_align = intel_dp_link_status(intel_dp->link_status,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001495 DP_LANE_ALIGN_STATUS_UPDATED);
1496 if ((lane_align & DP_INTERLANE_ALIGN_DONE) == 0)
1497 return false;
Jesse Barnes33a34e42010-09-08 12:42:02 -07001498 for (lane = 0; lane < intel_dp->lane_count; lane++) {
1499 lane_status = intel_get_lane_status(intel_dp->link_status, lane);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001500 if ((lane_status & CHANNEL_EQ_BITS) != CHANNEL_EQ_BITS)
1501 return false;
1502 }
1503 return true;
1504}
1505
1506static bool
Chris Wilsonea5b2132010-08-04 13:50:23 +01001507intel_dp_set_link_train(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001508 uint32_t dp_reg_value,
Chris Wilson58e10eb2010-10-03 10:56:11 +01001509 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001510{
Chris Wilson4ef69c72010-09-09 15:14:28 +01001511 struct drm_device *dev = intel_dp->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001512 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001513 int ret;
1514
Chris Wilsonea5b2132010-08-04 13:50:23 +01001515 I915_WRITE(intel_dp->output_reg, dp_reg_value);
1516 POSTING_READ(intel_dp->output_reg);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001517
Chris Wilsonea5b2132010-08-04 13:50:23 +01001518 intel_dp_aux_native_write_1(intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001519 DP_TRAINING_PATTERN_SET,
1520 dp_train_pat);
1521
Chris Wilsonea5b2132010-08-04 13:50:23 +01001522 ret = intel_dp_aux_native_write(intel_dp,
Chris Wilson58e10eb2010-10-03 10:56:11 +01001523 DP_TRAINING_LANE0_SET,
1524 intel_dp->train_set, 4);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001525 if (ret != 4)
1526 return false;
1527
1528 return true;
1529}
1530
Jesse Barnes33a34e42010-09-08 12:42:02 -07001531/* Enable corresponding port and start training pattern 1 */
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001532static void
Jesse Barnes33a34e42010-09-08 12:42:02 -07001533intel_dp_start_link_train(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001534{
Chris Wilson4ef69c72010-09-09 15:14:28 +01001535 struct drm_device *dev = intel_dp->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001536 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson58e10eb2010-10-03 10:56:11 +01001537 struct intel_crtc *intel_crtc = to_intel_crtc(intel_dp->base.base.crtc);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001538 int i;
1539 uint8_t voltage;
1540 bool clock_recovery = false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001541 int tries;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001542 u32 reg;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001543 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001544
Adam Jacksone8519462011-07-21 17:48:38 -04001545 /*
1546 * On CPT we have to enable the port in training pattern 1, which
1547 * will happen below in intel_dp_set_link_train. Otherwise, enable
1548 * the port and wait for it to become active.
1549 */
1550 if (!HAS_PCH_CPT(dev)) {
1551 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
1552 POSTING_READ(intel_dp->output_reg);
1553 intel_wait_for_vblank(dev, intel_crtc->pipe);
1554 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001555
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001556 /* Write the link configuration data */
1557 intel_dp_aux_native_write(intel_dp, DP_LINK_BW_SET,
1558 intel_dp->link_configuration,
1559 DP_LINK_CONFIGURATION_SIZE);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001560
1561 DP |= DP_PORT_EN;
Adam Jackson82d16552011-10-14 17:22:26 -04001562 if (HAS_PCH_CPT(dev) && !is_cpu_edp(intel_dp))
Zhenyu Wange3421a12010-04-08 09:43:27 +08001563 DP &= ~DP_LINK_TRAIN_MASK_CPT;
1564 else
1565 DP &= ~DP_LINK_TRAIN_MASK;
Jesse Barnes33a34e42010-09-08 12:42:02 -07001566 memset(intel_dp->train_set, 0, 4);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001567 voltage = 0xff;
1568 tries = 0;
1569 clock_recovery = false;
1570 for (;;) {
Jesse Barnes33a34e42010-09-08 12:42:02 -07001571 /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */
Zhenyu Wange3421a12010-04-08 09:43:27 +08001572 uint32_t signal_levels;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001573 if (IS_GEN6(dev) && is_edp(intel_dp)) {
Jesse Barnes33a34e42010-09-08 12:42:02 -07001574 signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001575 DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels;
1576 } else {
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001577 signal_levels = intel_dp_signal_levels(intel_dp->train_set[0], intel_dp->lane_count);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001578 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
1579 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001580
Adam Jackson82d16552011-10-14 17:22:26 -04001581 if (HAS_PCH_CPT(dev) && !is_cpu_edp(intel_dp))
Zhenyu Wange3421a12010-04-08 09:43:27 +08001582 reg = DP | DP_LINK_TRAIN_PAT_1_CPT;
1583 else
1584 reg = DP | DP_LINK_TRAIN_PAT_1;
1585
Chris Wilsonea5b2132010-08-04 13:50:23 +01001586 if (!intel_dp_set_link_train(intel_dp, reg,
Adam Jackson81055852011-07-21 17:48:37 -04001587 DP_TRAINING_PATTERN_1 |
1588 DP_LINK_SCRAMBLING_DISABLE))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001589 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001590 /* Set training pattern 1 */
1591
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001592 udelay(100);
1593 if (!intel_dp_get_link_status(intel_dp))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001594 break;
1595
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001596 if (intel_clock_recovery_ok(intel_dp->link_status, intel_dp->lane_count)) {
1597 clock_recovery = true;
1598 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001599 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001600
1601 /* Check to see if we've tried the max voltage */
1602 for (i = 0; i < intel_dp->lane_count; i++)
1603 if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
1604 break;
1605 if (i == intel_dp->lane_count)
1606 break;
1607
1608 /* Check to see if we've tried the same voltage 5 times */
1609 if ((intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) == voltage) {
1610 ++tries;
1611 if (tries == 5)
1612 break;
1613 } else
1614 tries = 0;
1615 voltage = intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
1616
1617 /* Compute new intel_dp->train_set as requested by target */
1618 intel_get_adjust_train(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001619 }
1620
Jesse Barnes33a34e42010-09-08 12:42:02 -07001621 intel_dp->DP = DP;
1622}
1623
1624static void
1625intel_dp_complete_link_train(struct intel_dp *intel_dp)
1626{
Chris Wilson4ef69c72010-09-09 15:14:28 +01001627 struct drm_device *dev = intel_dp->base.base.dev;
Jesse Barnes33a34e42010-09-08 12:42:02 -07001628 struct drm_i915_private *dev_priv = dev->dev_private;
1629 bool channel_eq = false;
Jesse Barnes37f80972011-01-05 14:45:24 -08001630 int tries, cr_tries;
Jesse Barnes33a34e42010-09-08 12:42:02 -07001631 u32 reg;
1632 uint32_t DP = intel_dp->DP;
1633
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001634 /* channel equalization */
1635 tries = 0;
Jesse Barnes37f80972011-01-05 14:45:24 -08001636 cr_tries = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001637 channel_eq = false;
1638 for (;;) {
Jesse Barnes33a34e42010-09-08 12:42:02 -07001639 /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */
Zhenyu Wange3421a12010-04-08 09:43:27 +08001640 uint32_t signal_levels;
1641
Jesse Barnes37f80972011-01-05 14:45:24 -08001642 if (cr_tries > 5) {
1643 DRM_ERROR("failed to train DP, aborting\n");
1644 intel_dp_link_down(intel_dp);
1645 break;
1646 }
1647
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001648 if (IS_GEN6(dev) && is_edp(intel_dp)) {
Jesse Barnes33a34e42010-09-08 12:42:02 -07001649 signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001650 DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels;
1651 } else {
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001652 signal_levels = intel_dp_signal_levels(intel_dp->train_set[0], intel_dp->lane_count);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001653 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
1654 }
1655
Adam Jackson82d16552011-10-14 17:22:26 -04001656 if (HAS_PCH_CPT(dev) && !is_cpu_edp(intel_dp))
Zhenyu Wange3421a12010-04-08 09:43:27 +08001657 reg = DP | DP_LINK_TRAIN_PAT_2_CPT;
1658 else
1659 reg = DP | DP_LINK_TRAIN_PAT_2;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001660
1661 /* channel eq pattern */
Chris Wilsonea5b2132010-08-04 13:50:23 +01001662 if (!intel_dp_set_link_train(intel_dp, reg,
Adam Jackson81055852011-07-21 17:48:37 -04001663 DP_TRAINING_PATTERN_2 |
1664 DP_LINK_SCRAMBLING_DISABLE))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001665 break;
1666
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001667 udelay(400);
1668 if (!intel_dp_get_link_status(intel_dp))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001669 break;
Jesse Barnes869184a2010-10-07 16:01:22 -07001670
Jesse Barnes37f80972011-01-05 14:45:24 -08001671 /* Make sure clock is still ok */
1672 if (!intel_clock_recovery_ok(intel_dp->link_status, intel_dp->lane_count)) {
1673 intel_dp_start_link_train(intel_dp);
1674 cr_tries++;
1675 continue;
1676 }
1677
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001678 if (intel_channel_eq_ok(intel_dp)) {
1679 channel_eq = true;
1680 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001681 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001682
Jesse Barnes37f80972011-01-05 14:45:24 -08001683 /* Try 5 times, then try clock recovery if that fails */
1684 if (tries > 5) {
1685 intel_dp_link_down(intel_dp);
1686 intel_dp_start_link_train(intel_dp);
1687 tries = 0;
1688 cr_tries++;
1689 continue;
1690 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001691
1692 /* Compute new intel_dp->train_set as requested by target */
1693 intel_get_adjust_train(intel_dp);
1694 ++tries;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001695 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001696
Adam Jackson82d16552011-10-14 17:22:26 -04001697 if (HAS_PCH_CPT(dev) && !is_cpu_edp(intel_dp))
Zhenyu Wange3421a12010-04-08 09:43:27 +08001698 reg = DP | DP_LINK_TRAIN_OFF_CPT;
1699 else
1700 reg = DP | DP_LINK_TRAIN_OFF;
1701
Chris Wilsonea5b2132010-08-04 13:50:23 +01001702 I915_WRITE(intel_dp->output_reg, reg);
1703 POSTING_READ(intel_dp->output_reg);
1704 intel_dp_aux_native_write_1(intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001705 DP_TRAINING_PATTERN_SET, DP_TRAINING_PATTERN_DISABLE);
1706}
1707
1708static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01001709intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001710{
Chris Wilson4ef69c72010-09-09 15:14:28 +01001711 struct drm_device *dev = intel_dp->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001712 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001713 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001714
Chris Wilson1b39d6f2010-12-06 11:20:45 +00001715 if ((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0)
1716 return;
1717
Zhao Yakui28c97732009-10-09 11:39:41 +08001718 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001719
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001720 if (is_edp(intel_dp)) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001721 DP &= ~DP_PLL_ENABLE;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001722 I915_WRITE(intel_dp->output_reg, DP);
1723 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001724 udelay(100);
1725 }
1726
Adam Jackson82d16552011-10-14 17:22:26 -04001727 if (HAS_PCH_CPT(dev) && !is_cpu_edp(intel_dp)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08001728 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001729 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001730 } else {
1731 DP &= ~DP_LINK_TRAIN_MASK;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001732 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001733 }
Chris Wilsonfe255d02010-09-11 21:37:48 +01001734 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001735
Chris Wilsonfe255d02010-09-11 21:37:48 +01001736 msleep(17);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001737
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001738 if (is_edp(intel_dp))
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001739 DP |= DP_LINK_TRAIN_OFF;
Eric Anholt5bddd172010-11-18 09:32:59 +08001740
Chris Wilson1b39d6f2010-12-06 11:20:45 +00001741 if (!HAS_PCH_CPT(dev) &&
1742 I915_READ(intel_dp->output_reg) & DP_PIPEB_SELECT) {
Chris Wilson31acbcc2011-04-17 06:38:35 +01001743 struct drm_crtc *crtc = intel_dp->base.base.crtc;
1744
Eric Anholt5bddd172010-11-18 09:32:59 +08001745 /* Hardware workaround: leaving our transcoder select
1746 * set to transcoder B while it's off will prevent the
1747 * corresponding HDMI output on transcoder A.
1748 *
1749 * Combine this with another hardware workaround:
1750 * transcoder select bit can only be cleared while the
1751 * port is enabled.
1752 */
1753 DP &= ~DP_PIPEB_SELECT;
1754 I915_WRITE(intel_dp->output_reg, DP);
1755
1756 /* Changes to enable or select take place the vblank
1757 * after being written.
1758 */
Chris Wilson31acbcc2011-04-17 06:38:35 +01001759 if (crtc == NULL) {
1760 /* We can arrive here never having been attached
1761 * to a CRTC, for instance, due to inheriting
1762 * random state from the BIOS.
1763 *
1764 * If the pipe is not running, play safe and
1765 * wait for the clocks to stabilise before
1766 * continuing.
1767 */
1768 POSTING_READ(intel_dp->output_reg);
1769 msleep(50);
1770 } else
1771 intel_wait_for_vblank(dev, to_intel_crtc(crtc)->pipe);
Eric Anholt5bddd172010-11-18 09:32:59 +08001772 }
1773
Chris Wilsonea5b2132010-08-04 13:50:23 +01001774 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
1775 POSTING_READ(intel_dp->output_reg);
Keith Packardf01eca22011-09-28 16:48:10 -07001776 msleep(intel_dp->panel_power_down_delay);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001777}
1778
Keith Packard26d61aa2011-07-25 20:01:09 -07001779static bool
1780intel_dp_get_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07001781{
Keith Packard92fd8fd2011-07-25 19:50:10 -07001782 if (intel_dp_aux_native_read_retry(intel_dp, 0x000, intel_dp->dpcd,
Akshay Joshi0206e352011-08-16 15:34:10 -04001783 sizeof(intel_dp->dpcd)) &&
Keith Packard92fd8fd2011-07-25 19:50:10 -07001784 (intel_dp->dpcd[DP_DPCD_REV] != 0)) {
Keith Packard26d61aa2011-07-25 20:01:09 -07001785 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07001786 }
1787
Keith Packard26d61aa2011-07-25 20:01:09 -07001788 return false;
Keith Packard92fd8fd2011-07-25 19:50:10 -07001789}
1790
Jesse Barnesa60f0e32011-10-20 15:09:17 -07001791static bool
1792intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
1793{
1794 int ret;
1795
1796 ret = intel_dp_aux_native_read_retry(intel_dp,
1797 DP_DEVICE_SERVICE_IRQ_VECTOR,
1798 sink_irq_vector, 1);
1799 if (!ret)
1800 return false;
1801
1802 return true;
1803}
1804
1805static void
1806intel_dp_handle_test_request(struct intel_dp *intel_dp)
1807{
1808 /* NAK by default */
1809 intel_dp_aux_native_write_1(intel_dp, DP_TEST_RESPONSE, DP_TEST_ACK);
1810}
1811
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001812/*
1813 * According to DP spec
1814 * 5.1.2:
1815 * 1. Read DPCD
1816 * 2. Configure link according to Receiver Capabilities
1817 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
1818 * 4. Check link status on receipt of hot-plug interrupt
1819 */
1820
1821static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01001822intel_dp_check_link_status(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001823{
Jesse Barnesa60f0e32011-10-20 15:09:17 -07001824 u8 sink_irq_vector;
1825
Keith Packardd2b996a2011-07-25 22:37:51 -07001826 if (intel_dp->dpms_mode != DRM_MODE_DPMS_ON)
1827 return;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07001828
Chris Wilson4ef69c72010-09-09 15:14:28 +01001829 if (!intel_dp->base.base.crtc)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001830 return;
1831
Keith Packard92fd8fd2011-07-25 19:50:10 -07001832 /* Try to read receiver status if the link appears to be up */
Jesse Barnes33a34e42010-09-08 12:42:02 -07001833 if (!intel_dp_get_link_status(intel_dp)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001834 intel_dp_link_down(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001835 return;
1836 }
1837
Keith Packard92fd8fd2011-07-25 19:50:10 -07001838 /* Now read the DPCD to see if it's actually running */
Keith Packard26d61aa2011-07-25 20:01:09 -07001839 if (!intel_dp_get_dpcd(intel_dp)) {
Jesse Barnes59cd09e2011-07-07 11:10:59 -07001840 intel_dp_link_down(intel_dp);
1841 return;
1842 }
1843
Jesse Barnesa60f0e32011-10-20 15:09:17 -07001844 /* Try to read the source of the interrupt */
1845 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
1846 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector)) {
1847 /* Clear interrupt source */
1848 intel_dp_aux_native_write_1(intel_dp,
1849 DP_DEVICE_SERVICE_IRQ_VECTOR,
1850 sink_irq_vector);
1851
1852 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
1853 intel_dp_handle_test_request(intel_dp);
1854 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
1855 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
1856 }
1857
Jesse Barnes33a34e42010-09-08 12:42:02 -07001858 if (!intel_channel_eq_ok(intel_dp)) {
Keith Packard92fd8fd2011-07-25 19:50:10 -07001859 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
1860 drm_get_encoder_name(&intel_dp->base.base));
Jesse Barnes33a34e42010-09-08 12:42:02 -07001861 intel_dp_start_link_train(intel_dp);
1862 intel_dp_complete_link_train(intel_dp);
1863 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001864}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001865
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001866static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07001867intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04001868{
Keith Packard26d61aa2011-07-25 20:01:09 -07001869 if (intel_dp_get_dpcd(intel_dp))
1870 return connector_status_connected;
1871 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04001872}
1873
1874static enum drm_connector_status
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001875ironlake_dp_detect(struct intel_dp *intel_dp)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001876{
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001877 enum drm_connector_status status;
1878
Chris Wilsonfe16d942011-02-12 10:29:38 +00001879 /* Can't disconnect eDP, but you can close the lid... */
1880 if (is_edp(intel_dp)) {
1881 status = intel_panel_detect(intel_dp->base.base.dev);
1882 if (status == connector_status_unknown)
1883 status = connector_status_connected;
1884 return status;
1885 }
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001886
Keith Packard26d61aa2011-07-25 20:01:09 -07001887 return intel_dp_detect_dpcd(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001888}
1889
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001890static enum drm_connector_status
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001891g4x_dp_detect(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001892{
Chris Wilson4ef69c72010-09-09 15:14:28 +01001893 struct drm_device *dev = intel_dp->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001894 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001895 uint32_t temp, bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001896
Chris Wilsonea5b2132010-08-04 13:50:23 +01001897 switch (intel_dp->output_reg) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001898 case DP_B:
1899 bit = DPB_HOTPLUG_INT_STATUS;
1900 break;
1901 case DP_C:
1902 bit = DPC_HOTPLUG_INT_STATUS;
1903 break;
1904 case DP_D:
1905 bit = DPD_HOTPLUG_INT_STATUS;
1906 break;
1907 default:
1908 return connector_status_unknown;
1909 }
1910
1911 temp = I915_READ(PORT_HOTPLUG_STAT);
1912
1913 if ((temp & bit) == 0)
1914 return connector_status_disconnected;
1915
Keith Packard26d61aa2011-07-25 20:01:09 -07001916 return intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001917}
1918
Keith Packard8c241fe2011-09-28 16:38:44 -07001919static struct edid *
1920intel_dp_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
1921{
1922 struct intel_dp *intel_dp = intel_attached_dp(connector);
1923 struct edid *edid;
1924
1925 ironlake_edp_panel_vdd_on(intel_dp);
1926 edid = drm_get_edid(connector, adapter);
Keith Packardbd943152011-09-18 23:09:52 -07001927 ironlake_edp_panel_vdd_off(intel_dp, false);
Keith Packard8c241fe2011-09-28 16:38:44 -07001928 return edid;
1929}
1930
1931static int
1932intel_dp_get_edid_modes(struct drm_connector *connector, struct i2c_adapter *adapter)
1933{
1934 struct intel_dp *intel_dp = intel_attached_dp(connector);
1935 int ret;
1936
1937 ironlake_edp_panel_vdd_on(intel_dp);
1938 ret = intel_ddc_get_modes(connector, adapter);
Keith Packardbd943152011-09-18 23:09:52 -07001939 ironlake_edp_panel_vdd_off(intel_dp, false);
Keith Packard8c241fe2011-09-28 16:38:44 -07001940 return ret;
1941}
1942
1943
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001944/**
1945 * Uses CRT_HOTPLUG_EN and CRT_HOTPLUG_STAT to detect DP connection.
1946 *
1947 * \return true if DP port is connected.
1948 * \return false if DP port is disconnected.
1949 */
1950static enum drm_connector_status
1951intel_dp_detect(struct drm_connector *connector, bool force)
1952{
1953 struct intel_dp *intel_dp = intel_attached_dp(connector);
1954 struct drm_device *dev = intel_dp->base.base.dev;
1955 enum drm_connector_status status;
1956 struct edid *edid = NULL;
1957
1958 intel_dp->has_audio = false;
1959
1960 if (HAS_PCH_SPLIT(dev))
1961 status = ironlake_dp_detect(intel_dp);
1962 else
1963 status = g4x_dp_detect(intel_dp);
Adam Jackson1b9be9d2011-07-12 17:38:01 -04001964
Adam Jacksonac66ae82011-07-12 17:38:03 -04001965 DRM_DEBUG_KMS("DPCD: %02hx%02hx%02hx%02hx%02hx%02hx%02hx%02hx\n",
1966 intel_dp->dpcd[0], intel_dp->dpcd[1], intel_dp->dpcd[2],
1967 intel_dp->dpcd[3], intel_dp->dpcd[4], intel_dp->dpcd[5],
1968 intel_dp->dpcd[6], intel_dp->dpcd[7]);
Adam Jackson1b9be9d2011-07-12 17:38:01 -04001969
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001970 if (status != connector_status_connected)
1971 return status;
1972
Chris Wilsonf6849602010-09-19 09:29:33 +01001973 if (intel_dp->force_audio) {
1974 intel_dp->has_audio = intel_dp->force_audio > 0;
1975 } else {
Keith Packard8c241fe2011-09-28 16:38:44 -07001976 edid = intel_dp_get_edid(connector, &intel_dp->adapter);
Chris Wilsonf6849602010-09-19 09:29:33 +01001977 if (edid) {
1978 intel_dp->has_audio = drm_detect_monitor_audio(edid);
1979 connector->display_info.raw_edid = NULL;
1980 kfree(edid);
1981 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001982 }
1983
1984 return connector_status_connected;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001985}
1986
1987static int intel_dp_get_modes(struct drm_connector *connector)
1988{
Chris Wilsondf0e9242010-09-09 16:20:55 +01001989 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson4ef69c72010-09-09 15:14:28 +01001990 struct drm_device *dev = intel_dp->base.base.dev;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001991 struct drm_i915_private *dev_priv = dev->dev_private;
1992 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001993
1994 /* We should parse the EDID data and find out if it has an audio sink
1995 */
1996
Keith Packard8c241fe2011-09-28 16:38:44 -07001997 ret = intel_dp_get_edid_modes(connector, &intel_dp->adapter);
Zhao Yakuib9efc482010-07-19 09:43:11 +01001998 if (ret) {
Keith Packardd15456d2011-09-18 17:35:47 -07001999 if (is_edp(intel_dp) && !intel_dp->panel_fixed_mode) {
Zhao Yakuib9efc482010-07-19 09:43:11 +01002000 struct drm_display_mode *newmode;
2001 list_for_each_entry(newmode, &connector->probed_modes,
2002 head) {
Keith Packardd15456d2011-09-18 17:35:47 -07002003 if ((newmode->type & DRM_MODE_TYPE_PREFERRED)) {
2004 intel_dp->panel_fixed_mode =
Zhao Yakuib9efc482010-07-19 09:43:11 +01002005 drm_mode_duplicate(dev, newmode);
2006 break;
2007 }
2008 }
2009 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002010 return ret;
Zhao Yakuib9efc482010-07-19 09:43:11 +01002011 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002012
2013 /* if eDP has no EDID, try to use fixed panel mode from VBT */
Jesse Barnes4d926462010-10-07 16:01:07 -07002014 if (is_edp(intel_dp)) {
Keith Packard47f0eb22011-09-19 14:33:26 -07002015 /* initialize panel mode from VBT if available for eDP */
Keith Packardd15456d2011-09-18 17:35:47 -07002016 if (intel_dp->panel_fixed_mode == NULL && dev_priv->lfp_lvds_vbt_mode != NULL) {
2017 intel_dp->panel_fixed_mode =
Keith Packard47f0eb22011-09-19 14:33:26 -07002018 drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);
Keith Packardd15456d2011-09-18 17:35:47 -07002019 if (intel_dp->panel_fixed_mode) {
2020 intel_dp->panel_fixed_mode->type |=
Keith Packard47f0eb22011-09-19 14:33:26 -07002021 DRM_MODE_TYPE_PREFERRED;
2022 }
2023 }
Keith Packardd15456d2011-09-18 17:35:47 -07002024 if (intel_dp->panel_fixed_mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002025 struct drm_display_mode *mode;
Keith Packardd15456d2011-09-18 17:35:47 -07002026 mode = drm_mode_duplicate(dev, intel_dp->panel_fixed_mode);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002027 drm_mode_probed_add(connector, mode);
2028 return 1;
2029 }
2030 }
2031 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002032}
2033
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002034static bool
2035intel_dp_detect_audio(struct drm_connector *connector)
2036{
2037 struct intel_dp *intel_dp = intel_attached_dp(connector);
2038 struct edid *edid;
2039 bool has_audio = false;
2040
Keith Packard8c241fe2011-09-28 16:38:44 -07002041 edid = intel_dp_get_edid(connector, &intel_dp->adapter);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002042 if (edid) {
2043 has_audio = drm_detect_monitor_audio(edid);
2044
2045 connector->display_info.raw_edid = NULL;
2046 kfree(edid);
2047 }
2048
2049 return has_audio;
2050}
2051
Chris Wilsonf6849602010-09-19 09:29:33 +01002052static int
2053intel_dp_set_property(struct drm_connector *connector,
2054 struct drm_property *property,
2055 uint64_t val)
2056{
Chris Wilsone953fd72011-02-21 22:23:52 +00002057 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Chris Wilsonf6849602010-09-19 09:29:33 +01002058 struct intel_dp *intel_dp = intel_attached_dp(connector);
2059 int ret;
2060
2061 ret = drm_connector_property_set_value(connector, property, val);
2062 if (ret)
2063 return ret;
2064
Chris Wilson3f43c482011-05-12 22:17:24 +01002065 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002066 int i = val;
2067 bool has_audio;
2068
2069 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01002070 return 0;
2071
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002072 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01002073
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002074 if (i == 0)
2075 has_audio = intel_dp_detect_audio(connector);
2076 else
2077 has_audio = i > 0;
2078
2079 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01002080 return 0;
2081
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002082 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01002083 goto done;
2084 }
2085
Chris Wilsone953fd72011-02-21 22:23:52 +00002086 if (property == dev_priv->broadcast_rgb_property) {
2087 if (val == !!intel_dp->color_range)
2088 return 0;
2089
2090 intel_dp->color_range = val ? DP_COLOR_RANGE_16_235 : 0;
2091 goto done;
2092 }
2093
Chris Wilsonf6849602010-09-19 09:29:33 +01002094 return -EINVAL;
2095
2096done:
2097 if (intel_dp->base.base.crtc) {
2098 struct drm_crtc *crtc = intel_dp->base.base.crtc;
2099 drm_crtc_helper_set_mode(crtc, &crtc->mode,
2100 crtc->x, crtc->y,
2101 crtc->fb);
2102 }
2103
2104 return 0;
2105}
2106
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002107static void
Akshay Joshi0206e352011-08-16 15:34:10 -04002108intel_dp_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002109{
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02002110 struct drm_device *dev = connector->dev;
2111
2112 if (intel_dpd_is_edp(dev))
2113 intel_panel_destroy_backlight(dev);
2114
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002115 drm_sysfs_connector_remove(connector);
2116 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08002117 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002118}
2119
Daniel Vetter24d05922010-08-20 18:08:28 +02002120static void intel_dp_encoder_destroy(struct drm_encoder *encoder)
2121{
2122 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2123
2124 i2c_del_adapter(&intel_dp->adapter);
2125 drm_encoder_cleanup(encoder);
Keith Packardbd943152011-09-18 23:09:52 -07002126 if (is_edp(intel_dp)) {
2127 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
2128 ironlake_panel_vdd_off_sync(intel_dp);
2129 }
Daniel Vetter24d05922010-08-20 18:08:28 +02002130 kfree(intel_dp);
2131}
2132
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002133static const struct drm_encoder_helper_funcs intel_dp_helper_funcs = {
2134 .dpms = intel_dp_dpms,
2135 .mode_fixup = intel_dp_mode_fixup,
Jesse Barnesd240f202010-08-13 15:43:26 -07002136 .prepare = intel_dp_prepare,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002137 .mode_set = intel_dp_mode_set,
Jesse Barnesd240f202010-08-13 15:43:26 -07002138 .commit = intel_dp_commit,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002139};
2140
2141static const struct drm_connector_funcs intel_dp_connector_funcs = {
2142 .dpms = drm_helper_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002143 .detect = intel_dp_detect,
2144 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01002145 .set_property = intel_dp_set_property,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002146 .destroy = intel_dp_destroy,
2147};
2148
2149static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
2150 .get_modes = intel_dp_get_modes,
2151 .mode_valid = intel_dp_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +01002152 .best_encoder = intel_best_encoder,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002153};
2154
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002155static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Daniel Vetter24d05922010-08-20 18:08:28 +02002156 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002157};
2158
Chris Wilson995b6762010-08-20 13:23:26 +01002159static void
Eric Anholt21d40d32010-03-25 11:11:14 -07002160intel_dp_hot_plug(struct intel_encoder *intel_encoder)
Keith Packardc8110e52009-05-06 11:51:10 -07002161{
Chris Wilsonea5b2132010-08-04 13:50:23 +01002162 struct intel_dp *intel_dp = container_of(intel_encoder, struct intel_dp, base);
Keith Packardc8110e52009-05-06 11:51:10 -07002163
Jesse Barnes885a5012011-07-07 11:11:01 -07002164 intel_dp_check_link_status(intel_dp);
Keith Packardc8110e52009-05-06 11:51:10 -07002165}
2166
Zhenyu Wange3421a12010-04-08 09:43:27 +08002167/* Return which DP Port should be selected for Transcoder DP control */
2168int
Akshay Joshi0206e352011-08-16 15:34:10 -04002169intel_trans_dp_port_sel(struct drm_crtc *crtc)
Zhenyu Wange3421a12010-04-08 09:43:27 +08002170{
2171 struct drm_device *dev = crtc->dev;
2172 struct drm_mode_config *mode_config = &dev->mode_config;
2173 struct drm_encoder *encoder;
Zhenyu Wange3421a12010-04-08 09:43:27 +08002174
2175 list_for_each_entry(encoder, &mode_config->encoder_list, head) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01002176 struct intel_dp *intel_dp;
2177
Dan Carpenterd8201ab2010-05-07 10:39:00 +02002178 if (encoder->crtc != crtc)
Zhenyu Wange3421a12010-04-08 09:43:27 +08002179 continue;
2180
Chris Wilsonea5b2132010-08-04 13:50:23 +01002181 intel_dp = enc_to_intel_dp(encoder);
2182 if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT)
2183 return intel_dp->output_reg;
Zhenyu Wange3421a12010-04-08 09:43:27 +08002184 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002185
Zhenyu Wange3421a12010-04-08 09:43:27 +08002186 return -1;
2187}
2188
Zhao Yakui36e83a12010-06-12 14:32:21 +08002189/* check the VBT to see whether the eDP is on DP-D port */
Adam Jacksoncb0953d2010-07-16 14:46:29 -04002190bool intel_dpd_is_edp(struct drm_device *dev)
Zhao Yakui36e83a12010-06-12 14:32:21 +08002191{
2192 struct drm_i915_private *dev_priv = dev->dev_private;
2193 struct child_device_config *p_child;
2194 int i;
2195
2196 if (!dev_priv->child_dev_num)
2197 return false;
2198
2199 for (i = 0; i < dev_priv->child_dev_num; i++) {
2200 p_child = dev_priv->child_dev + i;
2201
2202 if (p_child->dvo_port == PORT_IDPD &&
2203 p_child->device_type == DEVICE_TYPE_eDP)
2204 return true;
2205 }
2206 return false;
2207}
2208
Chris Wilsonf6849602010-09-19 09:29:33 +01002209static void
2210intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
2211{
Chris Wilson3f43c482011-05-12 22:17:24 +01002212 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00002213 intel_attach_broadcast_rgb_property(connector);
Chris Wilsonf6849602010-09-19 09:29:33 +01002214}
2215
Keith Packardc8110e52009-05-06 11:51:10 -07002216void
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002217intel_dp_init(struct drm_device *dev, int output_reg)
2218{
2219 struct drm_i915_private *dev_priv = dev->dev_private;
2220 struct drm_connector *connector;
Chris Wilsonea5b2132010-08-04 13:50:23 +01002221 struct intel_dp *intel_dp;
Eric Anholt21d40d32010-03-25 11:11:14 -07002222 struct intel_encoder *intel_encoder;
Zhenyu Wang55f78c42010-03-29 16:13:57 +08002223 struct intel_connector *intel_connector;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002224 const char *name = NULL;
Adam Jacksonb3295302010-07-16 14:46:28 -04002225 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002226
Chris Wilsonea5b2132010-08-04 13:50:23 +01002227 intel_dp = kzalloc(sizeof(struct intel_dp), GFP_KERNEL);
2228 if (!intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002229 return;
2230
Chris Wilson3d3dc142011-02-12 10:33:12 +00002231 intel_dp->output_reg = output_reg;
Keith Packardd2b996a2011-07-25 22:37:51 -07002232 intel_dp->dpms_mode = -1;
Chris Wilson3d3dc142011-02-12 10:33:12 +00002233
Zhenyu Wang55f78c42010-03-29 16:13:57 +08002234 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
2235 if (!intel_connector) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01002236 kfree(intel_dp);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08002237 return;
2238 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002239 intel_encoder = &intel_dp->base;
Zhenyu Wang55f78c42010-03-29 16:13:57 +08002240
Chris Wilsonea5b2132010-08-04 13:50:23 +01002241 if (HAS_PCH_SPLIT(dev) && output_reg == PCH_DP_D)
Adam Jacksonb3295302010-07-16 14:46:28 -04002242 if (intel_dpd_is_edp(dev))
Chris Wilsonea5b2132010-08-04 13:50:23 +01002243 intel_dp->is_pch_edp = true;
Adam Jacksonb3295302010-07-16 14:46:28 -04002244
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07002245 if (output_reg == DP_A || is_pch_edp(intel_dp)) {
Adam Jacksonb3295302010-07-16 14:46:28 -04002246 type = DRM_MODE_CONNECTOR_eDP;
2247 intel_encoder->type = INTEL_OUTPUT_EDP;
2248 } else {
2249 type = DRM_MODE_CONNECTOR_DisplayPort;
2250 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
2251 }
2252
Zhenyu Wang55f78c42010-03-29 16:13:57 +08002253 connector = &intel_connector->base;
Adam Jacksonb3295302010-07-16 14:46:28 -04002254 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002255 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
2256
Dave Airlieeb1f8e42010-05-07 06:42:51 +00002257 connector->polled = DRM_CONNECTOR_POLL_HPD;
2258
Zhao Yakui652af9d2009-12-02 10:03:33 +08002259 if (output_reg == DP_B || output_reg == PCH_DP_B)
Eric Anholt21d40d32010-03-25 11:11:14 -07002260 intel_encoder->clone_mask = (1 << INTEL_DP_B_CLONE_BIT);
Zhao Yakui652af9d2009-12-02 10:03:33 +08002261 else if (output_reg == DP_C || output_reg == PCH_DP_C)
Eric Anholt21d40d32010-03-25 11:11:14 -07002262 intel_encoder->clone_mask = (1 << INTEL_DP_C_CLONE_BIT);
Zhao Yakui652af9d2009-12-02 10:03:33 +08002263 else if (output_reg == DP_D || output_reg == PCH_DP_D)
Eric Anholt21d40d32010-03-25 11:11:14 -07002264 intel_encoder->clone_mask = (1 << INTEL_DP_D_CLONE_BIT);
Ma Lingf8aed702009-08-24 13:50:24 +08002265
Keith Packardbd943152011-09-18 23:09:52 -07002266 if (is_edp(intel_dp)) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002267 intel_encoder->clone_mask = (1 << INTEL_EDP_CLONE_BIT);
Keith Packardbd943152011-09-18 23:09:52 -07002268 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
2269 ironlake_panel_vdd_work);
2270 }
Zhenyu Wang6251ec02010-01-12 05:38:32 +08002271
Jesse Barnes27f82272011-09-02 12:54:37 -07002272 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002273 connector->interlace_allowed = true;
2274 connector->doublescan_allowed = 0;
2275
Chris Wilson4ef69c72010-09-09 15:14:28 +01002276 drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002277 DRM_MODE_ENCODER_TMDS);
Chris Wilson4ef69c72010-09-09 15:14:28 +01002278 drm_encoder_helper_add(&intel_encoder->base, &intel_dp_helper_funcs);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002279
Chris Wilsondf0e9242010-09-09 16:20:55 +01002280 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002281 drm_sysfs_connector_add(connector);
2282
2283 /* Set up the DDC bus. */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002284 switch (output_reg) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002285 case DP_A:
2286 name = "DPDDC-A";
2287 break;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002288 case DP_B:
2289 case PCH_DP_B:
Jesse Barnesb01f2c32009-12-11 11:07:17 -08002290 dev_priv->hotplug_supported_mask |=
2291 HDMIB_HOTPLUG_INT_STATUS;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002292 name = "DPDDC-B";
2293 break;
2294 case DP_C:
2295 case PCH_DP_C:
Jesse Barnesb01f2c32009-12-11 11:07:17 -08002296 dev_priv->hotplug_supported_mask |=
2297 HDMIC_HOTPLUG_INT_STATUS;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002298 name = "DPDDC-C";
2299 break;
2300 case DP_D:
2301 case PCH_DP_D:
Jesse Barnesb01f2c32009-12-11 11:07:17 -08002302 dev_priv->hotplug_supported_mask |=
2303 HDMID_HOTPLUG_INT_STATUS;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002304 name = "DPDDC-D";
2305 break;
2306 }
2307
Jesse Barnes89667382010-10-07 16:01:21 -07002308 /* Cache some DPCD data in the eDP case */
2309 if (is_edp(intel_dp)) {
Keith Packard59f3e272011-07-25 20:01:56 -07002310 bool ret;
Keith Packardf01eca22011-09-28 16:48:10 -07002311 struct edp_power_seq cur, vbt;
2312 u32 pp_on, pp_off, pp_div;
Jesse Barnes89667382010-10-07 16:01:21 -07002313
Jesse Barnes5d613502011-01-24 17:10:54 -08002314 pp_on = I915_READ(PCH_PP_ON_DELAYS);
Keith Packardf01eca22011-09-28 16:48:10 -07002315 pp_off = I915_READ(PCH_PP_OFF_DELAYS);
Jesse Barnes5d613502011-01-24 17:10:54 -08002316 pp_div = I915_READ(PCH_PP_DIVISOR);
2317
Keith Packardf01eca22011-09-28 16:48:10 -07002318 /* Pull timing values out of registers */
2319 cur.t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
2320 PANEL_POWER_UP_DELAY_SHIFT;
2321
2322 cur.t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
2323 PANEL_LIGHT_ON_DELAY_SHIFT;
2324
2325 cur.t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
2326 PANEL_LIGHT_OFF_DELAY_SHIFT;
2327
2328 cur.t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
2329 PANEL_POWER_DOWN_DELAY_SHIFT;
2330
2331 cur.t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
2332 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
2333
2334 DRM_DEBUG_KMS("cur t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
2335 cur.t1_t3, cur.t8, cur.t9, cur.t10, cur.t11_t12);
2336
2337 vbt = dev_priv->edp.pps;
2338
2339 DRM_DEBUG_KMS("vbt t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
2340 vbt.t1_t3, vbt.t8, vbt.t9, vbt.t10, vbt.t11_t12);
2341
2342#define get_delay(field) ((max(cur.field, vbt.field) + 9) / 10)
2343
2344 intel_dp->panel_power_up_delay = get_delay(t1_t3);
2345 intel_dp->backlight_on_delay = get_delay(t8);
2346 intel_dp->backlight_off_delay = get_delay(t9);
2347 intel_dp->panel_power_down_delay = get_delay(t10);
2348 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
2349
2350 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
2351 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
2352 intel_dp->panel_power_cycle_delay);
2353
2354 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
2355 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Jesse Barnes5d613502011-01-24 17:10:54 -08002356
Keith Packardbd943152011-09-18 23:09:52 -07002357 intel_dp->panel_off_jiffies = jiffies - intel_dp->panel_power_down_delay;
Jesse Barnes5d613502011-01-24 17:10:54 -08002358
2359 ironlake_edp_panel_vdd_on(intel_dp);
Keith Packard59f3e272011-07-25 20:01:56 -07002360 ret = intel_dp_get_dpcd(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002361 ironlake_edp_panel_vdd_off(intel_dp, false);
Keith Packard59f3e272011-07-25 20:01:56 -07002362 if (ret) {
Jesse Barnes7183dc22011-07-07 11:10:58 -07002363 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
2364 dev_priv->no_aux_handshake =
2365 intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
Jesse Barnes89667382010-10-07 16:01:21 -07002366 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
2367 } else {
Chris Wilson3d3dc142011-02-12 10:33:12 +00002368 /* if this fails, presume the device is a ghost */
Takashi Iwai48898b02011-03-18 09:06:49 +00002369 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Chris Wilson3d3dc142011-02-12 10:33:12 +00002370 intel_dp_encoder_destroy(&intel_dp->base.base);
Takashi Iwai48898b02011-03-18 09:06:49 +00002371 intel_dp_destroy(&intel_connector->base);
Chris Wilson3d3dc142011-02-12 10:33:12 +00002372 return;
Jesse Barnes89667382010-10-07 16:01:21 -07002373 }
Jesse Barnes89667382010-10-07 16:01:21 -07002374 }
2375
Keith Packard552fb0b2011-09-28 16:31:53 -07002376 intel_dp_i2c_init(intel_dp, intel_connector, name);
2377
Eric Anholt21d40d32010-03-25 11:11:14 -07002378 intel_encoder->hot_plug = intel_dp_hot_plug;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002379
Jesse Barnes4d926462010-10-07 16:01:07 -07002380 if (is_edp(intel_dp)) {
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02002381 dev_priv->int_edp_connector = connector;
2382 intel_panel_setup_backlight(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002383 }
2384
Chris Wilsonf6849602010-09-19 09:29:33 +01002385 intel_dp_add_properties(intel_dp, connector);
2386
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002387 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
2388 * 0xd. Failure to do so will result in spurious interrupts being
2389 * generated on the port when a cable is not attached.
2390 */
2391 if (IS_G4X(dev) && !IS_GM45(dev)) {
2392 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
2393 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
2394 }
2395}