blob: a4d80314e7f8cf5edb13bce97328a60f1f26f6ce [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
Zhao Yakuiae266c92009-11-24 09:48:46 +080039
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 Packardc8110e52009-05-06 11:51:10 -070053 int dpms_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -070054 uint8_t link_bw;
55 uint8_t lane_count;
56 uint8_t dpcd[4];
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];
Chris Wilsonf6849602010-09-19 09:29:33 +010062
63 struct drm_property *force_audio_property;
Keith Packarda4fc5ed2009-04-07 16:16:42 -070064};
65
Jesse Barnescfcb0fc2010-10-07 16:01:06 -070066/**
67 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
68 * @intel_dp: DP struct
69 *
70 * If a CPU or PCH DP output is attached to an eDP panel, this function
71 * will return true, and false otherwise.
72 */
73static bool is_edp(struct intel_dp *intel_dp)
74{
75 return intel_dp->base.type == INTEL_OUTPUT_EDP;
76}
77
78/**
79 * is_pch_edp - is the port on the PCH and attached to an eDP panel?
80 * @intel_dp: DP struct
81 *
82 * Returns true if the given DP struct corresponds to a PCH DP port attached
83 * to an eDP panel, false otherwise. Helpful for determining whether we
84 * may need FDI resources for a given DP output or not.
85 */
86static bool is_pch_edp(struct intel_dp *intel_dp)
87{
88 return intel_dp->is_pch_edp;
89}
90
Chris Wilsonea5b2132010-08-04 13:50:23 +010091static struct intel_dp *enc_to_intel_dp(struct drm_encoder *encoder)
92{
Chris Wilson4ef69c72010-09-09 15:14:28 +010093 return container_of(encoder, struct intel_dp, base.base);
Chris Wilsonea5b2132010-08-04 13:50:23 +010094}
Keith Packarda4fc5ed2009-04-07 16:16:42 -070095
Chris Wilsondf0e9242010-09-09 16:20:55 +010096static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
97{
98 return container_of(intel_attached_encoder(connector),
99 struct intel_dp, base);
100}
101
Jesse Barnes814948a2010-10-07 16:01:09 -0700102/**
103 * intel_encoder_is_pch_edp - is the given encoder a PCH attached eDP?
104 * @encoder: DRM encoder
105 *
106 * Return true if @encoder corresponds to a PCH attached eDP panel. Needed
107 * by intel_display.c.
108 */
109bool intel_encoder_is_pch_edp(struct drm_encoder *encoder)
110{
111 struct intel_dp *intel_dp;
112
113 if (!encoder)
114 return false;
115
116 intel_dp = enc_to_intel_dp(encoder);
117
118 return is_pch_edp(intel_dp);
119}
120
Jesse Barnes33a34e42010-09-08 12:42:02 -0700121static void intel_dp_start_link_train(struct intel_dp *intel_dp);
122static void intel_dp_complete_link_train(struct intel_dp *intel_dp);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100123static void intel_dp_link_down(struct intel_dp *intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700124
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800125void
Eric Anholt21d40d32010-03-25 11:11:14 -0700126intel_edp_link_config (struct intel_encoder *intel_encoder,
Chris Wilsonea5b2132010-08-04 13:50:23 +0100127 int *lane_num, int *link_bw)
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800128{
Chris Wilsonea5b2132010-08-04 13:50:23 +0100129 struct intel_dp *intel_dp = container_of(intel_encoder, struct intel_dp, base);
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800130
Chris Wilsonea5b2132010-08-04 13:50:23 +0100131 *lane_num = intel_dp->lane_count;
132 if (intel_dp->link_bw == DP_LINK_BW_1_62)
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800133 *link_bw = 162000;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100134 else if (intel_dp->link_bw == DP_LINK_BW_2_7)
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800135 *link_bw = 270000;
136}
137
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700138static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100139intel_dp_max_lane_count(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700140{
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700141 int max_lane_count = 4;
142
Chris Wilsonea5b2132010-08-04 13:50:23 +0100143 if (intel_dp->dpcd[0] >= 0x11) {
144 max_lane_count = intel_dp->dpcd[2] & 0x1f;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700145 switch (max_lane_count) {
146 case 1: case 2: case 4:
147 break;
148 default:
149 max_lane_count = 4;
150 }
151 }
152 return max_lane_count;
153}
154
155static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100156intel_dp_max_link_bw(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700157{
Chris Wilsonea5b2132010-08-04 13:50:23 +0100158 int max_link_bw = intel_dp->dpcd[1];
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700159
160 switch (max_link_bw) {
161 case DP_LINK_BW_1_62:
162 case DP_LINK_BW_2_7:
163 break;
164 default:
165 max_link_bw = DP_LINK_BW_1_62;
166 break;
167 }
168 return max_link_bw;
169}
170
171static int
172intel_dp_link_clock(uint8_t link_bw)
173{
174 if (link_bw == DP_LINK_BW_2_7)
175 return 270000;
176 else
177 return 162000;
178}
179
180/* I think this is a fiction */
181static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100182intel_dp_link_required(struct drm_device *dev, struct intel_dp *intel_dp, int pixel_clock)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700183{
Zhenyu Wang885a5fb2010-01-12 05:38:31 +0800184 struct drm_i915_private *dev_priv = dev->dev_private;
185
Jesse Barnes4d926462010-10-07 16:01:07 -0700186 if (is_edp(intel_dp))
Chris Wilson5ceb0f92010-09-24 10:24:28 +0100187 return (pixel_clock * dev_priv->edp.bpp + 7) / 8;
Zhenyu Wang885a5fb2010-01-12 05:38:31 +0800188 else
189 return pixel_clock * 3;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700190}
191
192static int
Dave Airliefe27d532010-06-30 11:46:17 +1000193intel_dp_max_data_rate(int max_link_clock, int max_lanes)
194{
195 return (max_link_clock * max_lanes * 8) / 10;
196}
197
198static int
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700199intel_dp_mode_valid(struct drm_connector *connector,
200 struct drm_display_mode *mode)
201{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100202 struct intel_dp *intel_dp = intel_attached_dp(connector);
Zhao Yakui7de56f42010-07-19 09:43:14 +0100203 struct drm_device *dev = connector->dev;
204 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100205 int max_link_clock = intel_dp_link_clock(intel_dp_max_link_bw(intel_dp));
206 int max_lanes = intel_dp_max_lane_count(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700207
Jesse Barnes4d926462010-10-07 16:01:07 -0700208 if (is_edp(intel_dp) && dev_priv->panel_fixed_mode) {
Zhao Yakui7de56f42010-07-19 09:43:14 +0100209 if (mode->hdisplay > dev_priv->panel_fixed_mode->hdisplay)
210 return MODE_PANEL;
211
212 if (mode->vdisplay > dev_priv->panel_fixed_mode->vdisplay)
213 return MODE_PANEL;
214 }
215
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300216 /* only refuse the mode on non eDP since we have seen some weird eDP panels
Dave Airliefe27d532010-06-30 11:46:17 +1000217 which are outside spec tolerances but somehow work by magic */
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700218 if (!is_edp(intel_dp) &&
Chris Wilsonea5b2132010-08-04 13:50:23 +0100219 (intel_dp_link_required(connector->dev, intel_dp, mode->clock)
Dave Airliefe27d532010-06-30 11:46:17 +1000220 > intel_dp_max_data_rate(max_link_clock, max_lanes)))
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700221 return MODE_CLOCK_HIGH;
222
223 if (mode->clock < 10000)
224 return MODE_CLOCK_LOW;
225
226 return MODE_OK;
227}
228
229static uint32_t
230pack_aux(uint8_t *src, int src_bytes)
231{
232 int i;
233 uint32_t v = 0;
234
235 if (src_bytes > 4)
236 src_bytes = 4;
237 for (i = 0; i < src_bytes; i++)
238 v |= ((uint32_t) src[i]) << ((3-i) * 8);
239 return v;
240}
241
242static void
243unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
244{
245 int i;
246 if (dst_bytes > 4)
247 dst_bytes = 4;
248 for (i = 0; i < dst_bytes; i++)
249 dst[i] = src >> ((3-i) * 8);
250}
251
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700252/* hrawclock is 1/4 the FSB frequency */
253static int
254intel_hrawclk(struct drm_device *dev)
255{
256 struct drm_i915_private *dev_priv = dev->dev_private;
257 uint32_t clkcfg;
258
259 clkcfg = I915_READ(CLKCFG);
260 switch (clkcfg & CLKCFG_FSB_MASK) {
261 case CLKCFG_FSB_400:
262 return 100;
263 case CLKCFG_FSB_533:
264 return 133;
265 case CLKCFG_FSB_667:
266 return 166;
267 case CLKCFG_FSB_800:
268 return 200;
269 case CLKCFG_FSB_1067:
270 return 266;
271 case CLKCFG_FSB_1333:
272 return 333;
273 /* these two are just a guess; one of them might be right */
274 case CLKCFG_FSB_1600:
275 case CLKCFG_FSB_1600_ALT:
276 return 400;
277 default:
278 return 133;
279 }
280}
281
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700282static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100283intel_dp_aux_ch(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700284 uint8_t *send, int send_bytes,
285 uint8_t *recv, int recv_size)
286{
Chris Wilsonea5b2132010-08-04 13:50:23 +0100287 uint32_t output_reg = intel_dp->output_reg;
Chris Wilson4ef69c72010-09-09 15:14:28 +0100288 struct drm_device *dev = intel_dp->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700289 struct drm_i915_private *dev_priv = dev->dev_private;
290 uint32_t ch_ctl = output_reg + 0x10;
291 uint32_t ch_data = ch_ctl + 4;
292 int i;
293 int recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700294 uint32_t status;
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700295 uint32_t aux_clock_divider;
Zhenyu Wange3421a12010-04-08 09:43:27 +0800296 int try, precharge;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700297
298 /* The clock divider is based off the hrawclk,
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700299 * and would like to run at 2MHz. So, take the
300 * hrawclk value and divide by 2 and use that
Jesse Barnes6176b8f2010-09-08 12:42:00 -0700301 *
302 * Note that PCH attached eDP panels should use a 125MHz input
303 * clock divider.
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700304 */
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700305 if (is_edp(intel_dp) && !is_pch_edp(intel_dp)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +0800306 if (IS_GEN6(dev))
307 aux_clock_divider = 200; /* SNB eDP input clock at 400Mhz */
308 else
309 aux_clock_divider = 225; /* eDP input clock at 450Mhz */
310 } else if (HAS_PCH_SPLIT(dev))
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500311 aux_clock_divider = 62; /* IRL input clock fixed at 125Mhz */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +0800312 else
313 aux_clock_divider = intel_hrawclk(dev) / 2;
314
Zhenyu Wange3421a12010-04-08 09:43:27 +0800315 if (IS_GEN6(dev))
316 precharge = 3;
317 else
318 precharge = 5;
319
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100320 if (I915_READ(ch_ctl) & DP_AUX_CH_CTL_SEND_BUSY) {
321 DRM_ERROR("dp_aux_ch not started status 0x%08x\n",
322 I915_READ(ch_ctl));
323 return -EBUSY;
324 }
325
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700326 /* Must try at least 3 times according to DP spec */
327 for (try = 0; try < 5; try++) {
328 /* Load the send data into the aux channel data registers */
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100329 for (i = 0; i < send_bytes; i += 4)
330 I915_WRITE(ch_data + i,
331 pack_aux(send + i, send_bytes - i));
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700332
333 /* Send the command and wait for it to complete */
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100334 I915_WRITE(ch_ctl,
335 DP_AUX_CH_CTL_SEND_BUSY |
336 DP_AUX_CH_CTL_TIME_OUT_400us |
337 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
338 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
339 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT) |
340 DP_AUX_CH_CTL_DONE |
341 DP_AUX_CH_CTL_TIME_OUT_ERROR |
342 DP_AUX_CH_CTL_RECEIVE_ERROR);
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700343 for (;;) {
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700344 status = I915_READ(ch_ctl);
345 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
346 break;
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100347 udelay(100);
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700348 }
349
350 /* Clear done status and any errors */
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100351 I915_WRITE(ch_ctl,
352 status |
353 DP_AUX_CH_CTL_DONE |
354 DP_AUX_CH_CTL_TIME_OUT_ERROR |
355 DP_AUX_CH_CTL_RECEIVE_ERROR);
356 if (status & DP_AUX_CH_CTL_DONE)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700357 break;
358 }
359
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700360 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700361 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Keith Packarda5b3da52009-06-11 22:30:32 -0700362 return -EBUSY;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700363 }
364
365 /* Check for timeout or receive error.
366 * Timeouts occur when the sink is not connected
367 */
Keith Packarda5b3da52009-06-11 22:30:32 -0700368 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700369 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Keith Packarda5b3da52009-06-11 22:30:32 -0700370 return -EIO;
371 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700372
373 /* Timeouts occur when the device isn't connected, so they're
374 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -0700375 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Zhao Yakui28c97732009-10-09 11:39:41 +0800376 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Keith Packarda5b3da52009-06-11 22:30:32 -0700377 return -ETIMEDOUT;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700378 }
379
380 /* Unload any bytes sent back from the other side */
381 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
382 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700383 if (recv_bytes > recv_size)
384 recv_bytes = recv_size;
385
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100386 for (i = 0; i < recv_bytes; i += 4)
387 unpack_aux(I915_READ(ch_data + i),
388 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700389
390 return recv_bytes;
391}
392
393/* Write data to the aux channel in native mode */
394static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100395intel_dp_aux_native_write(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700396 uint16_t address, uint8_t *send, int send_bytes)
397{
398 int ret;
399 uint8_t msg[20];
400 int msg_bytes;
401 uint8_t ack;
402
403 if (send_bytes > 16)
404 return -1;
405 msg[0] = AUX_NATIVE_WRITE << 4;
406 msg[1] = address >> 8;
Zhenyu Wangeebc8632009-07-24 01:00:30 +0800407 msg[2] = address & 0xff;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700408 msg[3] = send_bytes - 1;
409 memcpy(&msg[4], send, send_bytes);
410 msg_bytes = send_bytes + 4;
411 for (;;) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100412 ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes, &ack, 1);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700413 if (ret < 0)
414 return ret;
415 if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK)
416 break;
417 else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
418 udelay(100);
419 else
Keith Packarda5b3da52009-06-11 22:30:32 -0700420 return -EIO;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700421 }
422 return send_bytes;
423}
424
425/* Write a single byte to the aux channel in native mode */
426static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100427intel_dp_aux_native_write_1(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700428 uint16_t address, uint8_t byte)
429{
Chris Wilsonea5b2132010-08-04 13:50:23 +0100430 return intel_dp_aux_native_write(intel_dp, address, &byte, 1);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700431}
432
433/* read bytes from a native aux channel */
434static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100435intel_dp_aux_native_read(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700436 uint16_t address, uint8_t *recv, int recv_bytes)
437{
438 uint8_t msg[4];
439 int msg_bytes;
440 uint8_t reply[20];
441 int reply_bytes;
442 uint8_t ack;
443 int ret;
444
445 msg[0] = AUX_NATIVE_READ << 4;
446 msg[1] = address >> 8;
447 msg[2] = address & 0xff;
448 msg[3] = recv_bytes - 1;
449
450 msg_bytes = 4;
451 reply_bytes = recv_bytes + 1;
452
453 for (;;) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100454 ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700455 reply, reply_bytes);
Keith Packarda5b3da52009-06-11 22:30:32 -0700456 if (ret == 0)
457 return -EPROTO;
458 if (ret < 0)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700459 return ret;
460 ack = reply[0];
461 if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK) {
462 memcpy(recv, reply + 1, ret - 1);
463 return ret - 1;
464 }
465 else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
466 udelay(100);
467 else
Keith Packarda5b3da52009-06-11 22:30:32 -0700468 return -EIO;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700469 }
470}
471
472static int
Dave Airlieab2c0672009-12-04 10:55:24 +1000473intel_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode,
474 uint8_t write_byte, uint8_t *read_byte)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700475{
Dave Airlieab2c0672009-12-04 10:55:24 +1000476 struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100477 struct intel_dp *intel_dp = container_of(adapter,
478 struct intel_dp,
479 adapter);
Dave Airlieab2c0672009-12-04 10:55:24 +1000480 uint16_t address = algo_data->address;
481 uint8_t msg[5];
482 uint8_t reply[2];
David Flynn8316f332010-12-08 16:10:21 +0000483 unsigned retry;
Dave Airlieab2c0672009-12-04 10:55:24 +1000484 int msg_bytes;
485 int reply_bytes;
486 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700487
Dave Airlieab2c0672009-12-04 10:55:24 +1000488 /* Set up the command byte */
489 if (mode & MODE_I2C_READ)
490 msg[0] = AUX_I2C_READ << 4;
491 else
492 msg[0] = AUX_I2C_WRITE << 4;
493
494 if (!(mode & MODE_I2C_STOP))
495 msg[0] |= AUX_I2C_MOT << 4;
496
497 msg[1] = address >> 8;
498 msg[2] = address;
499
500 switch (mode) {
501 case MODE_I2C_WRITE:
502 msg[3] = 0;
503 msg[4] = write_byte;
504 msg_bytes = 5;
505 reply_bytes = 1;
506 break;
507 case MODE_I2C_READ:
508 msg[3] = 0;
509 msg_bytes = 4;
510 reply_bytes = 2;
511 break;
512 default:
513 msg_bytes = 3;
514 reply_bytes = 1;
515 break;
516 }
517
David Flynn8316f332010-12-08 16:10:21 +0000518 for (retry = 0; retry < 5; retry++) {
519 ret = intel_dp_aux_ch(intel_dp,
520 msg, msg_bytes,
521 reply, reply_bytes);
Dave Airlieab2c0672009-12-04 10:55:24 +1000522 if (ret < 0) {
Dave Airlie3ff99162009-12-08 14:03:47 +1000523 DRM_DEBUG_KMS("aux_ch failed %d\n", ret);
Dave Airlieab2c0672009-12-04 10:55:24 +1000524 return ret;
525 }
David Flynn8316f332010-12-08 16:10:21 +0000526
527 switch (reply[0] & AUX_NATIVE_REPLY_MASK) {
528 case AUX_NATIVE_REPLY_ACK:
529 /* I2C-over-AUX Reply field is only valid
530 * when paired with AUX ACK.
531 */
532 break;
533 case AUX_NATIVE_REPLY_NACK:
534 DRM_DEBUG_KMS("aux_ch native nack\n");
535 return -EREMOTEIO;
536 case AUX_NATIVE_REPLY_DEFER:
537 udelay(100);
538 continue;
539 default:
540 DRM_ERROR("aux_ch invalid native reply 0x%02x\n",
541 reply[0]);
542 return -EREMOTEIO;
543 }
544
Dave Airlieab2c0672009-12-04 10:55:24 +1000545 switch (reply[0] & AUX_I2C_REPLY_MASK) {
546 case AUX_I2C_REPLY_ACK:
547 if (mode == MODE_I2C_READ) {
548 *read_byte = reply[1];
549 }
550 return reply_bytes - 1;
551 case AUX_I2C_REPLY_NACK:
David Flynn8316f332010-12-08 16:10:21 +0000552 DRM_DEBUG_KMS("aux_i2c nack\n");
Dave Airlieab2c0672009-12-04 10:55:24 +1000553 return -EREMOTEIO;
554 case AUX_I2C_REPLY_DEFER:
David Flynn8316f332010-12-08 16:10:21 +0000555 DRM_DEBUG_KMS("aux_i2c defer\n");
Dave Airlieab2c0672009-12-04 10:55:24 +1000556 udelay(100);
557 break;
558 default:
David Flynn8316f332010-12-08 16:10:21 +0000559 DRM_ERROR("aux_i2c invalid reply 0x%02x\n", reply[0]);
Dave Airlieab2c0672009-12-04 10:55:24 +1000560 return -EREMOTEIO;
561 }
562 }
David Flynn8316f332010-12-08 16:10:21 +0000563
564 DRM_ERROR("too many retries, giving up\n");
565 return -EREMOTEIO;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700566}
567
568static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100569intel_dp_i2c_init(struct intel_dp *intel_dp,
Zhenyu Wang55f78c42010-03-29 16:13:57 +0800570 struct intel_connector *intel_connector, const char *name)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700571{
Zhenyu Wangd54e9d22009-10-19 15:43:51 +0800572 DRM_DEBUG_KMS("i2c_init %s\n", name);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100573 intel_dp->algo.running = false;
574 intel_dp->algo.address = 0;
575 intel_dp->algo.aux_ch = intel_dp_i2c_aux_ch;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700576
Chris Wilsonea5b2132010-08-04 13:50:23 +0100577 memset(&intel_dp->adapter, '\0', sizeof (intel_dp->adapter));
578 intel_dp->adapter.owner = THIS_MODULE;
579 intel_dp->adapter.class = I2C_CLASS_DDC;
580 strncpy (intel_dp->adapter.name, name, sizeof(intel_dp->adapter.name) - 1);
581 intel_dp->adapter.name[sizeof(intel_dp->adapter.name) - 1] = '\0';
582 intel_dp->adapter.algo_data = &intel_dp->algo;
583 intel_dp->adapter.dev.parent = &intel_connector->base.kdev;
584
585 return i2c_dp_aux_add_bus(&intel_dp->adapter);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700586}
587
588static bool
589intel_dp_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode,
590 struct drm_display_mode *adjusted_mode)
591{
Zhao Yakui0d3a1be2010-07-19 09:43:13 +0100592 struct drm_device *dev = encoder->dev;
593 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100594 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700595 int lane_count, clock;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100596 int max_lane_count = intel_dp_max_lane_count(intel_dp);
597 int max_clock = intel_dp_max_link_bw(intel_dp) == DP_LINK_BW_2_7 ? 1 : 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700598 static int bws[2] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7 };
599
Jesse Barnes4d926462010-10-07 16:01:07 -0700600 if (is_edp(intel_dp) && dev_priv->panel_fixed_mode) {
Chris Wilson1d8e1c72010-08-07 11:01:28 +0100601 intel_fixed_panel_mode(dev_priv->panel_fixed_mode, adjusted_mode);
602 intel_pch_panel_fitting(dev, DRM_MODE_SCALE_FULLSCREEN,
603 mode, adjusted_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +0100604 /*
605 * the mode->clock is used to calculate the Data&Link M/N
606 * of the pipe. For the eDP the fixed clock should be used.
607 */
608 mode->clock = dev_priv->panel_fixed_mode->clock;
609 }
610
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700611 for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) {
612 for (clock = 0; clock <= max_clock; clock++) {
Dave Airliefe27d532010-06-30 11:46:17 +1000613 int link_avail = intel_dp_max_data_rate(intel_dp_link_clock(bws[clock]), lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700614
Chris Wilsonea5b2132010-08-04 13:50:23 +0100615 if (intel_dp_link_required(encoder->dev, intel_dp, mode->clock)
Zhenyu Wang885a5fb2010-01-12 05:38:31 +0800616 <= link_avail) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100617 intel_dp->link_bw = bws[clock];
618 intel_dp->lane_count = lane_count;
619 adjusted_mode->clock = intel_dp_link_clock(intel_dp->link_bw);
Zhao Yakui28c97732009-10-09 11:39:41 +0800620 DRM_DEBUG_KMS("Display port link bw %02x lane "
621 "count %d clock %d\n",
Chris Wilsonea5b2132010-08-04 13:50:23 +0100622 intel_dp->link_bw, intel_dp->lane_count,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700623 adjusted_mode->clock);
624 return true;
625 }
626 }
627 }
Dave Airliefe27d532010-06-30 11:46:17 +1000628
Chris Wilson3cf2efb2010-11-29 10:09:55 +0000629 if (is_edp(intel_dp)) {
630 /* okay we failed just pick the highest */
631 intel_dp->lane_count = max_lane_count;
632 intel_dp->link_bw = bws[max_clock];
633 adjusted_mode->clock = intel_dp_link_clock(intel_dp->link_bw);
634 DRM_DEBUG_KMS("Force picking display port link bw %02x lane "
635 "count %d clock %d\n",
636 intel_dp->link_bw, intel_dp->lane_count,
637 adjusted_mode->clock);
638
639 return true;
640 }
641
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700642 return false;
643}
644
645struct intel_dp_m_n {
646 uint32_t tu;
647 uint32_t gmch_m;
648 uint32_t gmch_n;
649 uint32_t link_m;
650 uint32_t link_n;
651};
652
653static void
654intel_reduce_ratio(uint32_t *num, uint32_t *den)
655{
656 while (*num > 0xffffff || *den > 0xffffff) {
657 *num >>= 1;
658 *den >>= 1;
659 }
660}
661
662static void
Zhao Yakui36e83a12010-06-12 14:32:21 +0800663intel_dp_compute_m_n(int bpp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700664 int nlanes,
665 int pixel_clock,
666 int link_clock,
667 struct intel_dp_m_n *m_n)
668{
669 m_n->tu = 64;
Zhao Yakui36e83a12010-06-12 14:32:21 +0800670 m_n->gmch_m = (pixel_clock * bpp) >> 3;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700671 m_n->gmch_n = link_clock * nlanes;
672 intel_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
673 m_n->link_m = pixel_clock;
674 m_n->link_n = link_clock;
675 intel_reduce_ratio(&m_n->link_m, &m_n->link_n);
676}
677
678void
679intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode,
680 struct drm_display_mode *adjusted_mode)
681{
682 struct drm_device *dev = crtc->dev;
683 struct drm_mode_config *mode_config = &dev->mode_config;
Zhenyu Wang55f78c42010-03-29 16:13:57 +0800684 struct drm_encoder *encoder;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700685 struct drm_i915_private *dev_priv = dev->dev_private;
686 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Zhao Yakui36e83a12010-06-12 14:32:21 +0800687 int lane_count = 4, bpp = 24;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700688 struct intel_dp_m_n m_n;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800689 int pipe = intel_crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700690
691 /*
Eric Anholt21d40d32010-03-25 11:11:14 -0700692 * Find the lane count in the intel_encoder private
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700693 */
Zhenyu Wang55f78c42010-03-29 16:13:57 +0800694 list_for_each_entry(encoder, &mode_config->encoder_list, head) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100695 struct intel_dp *intel_dp;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700696
Dan Carpenterd8201ab2010-05-07 10:39:00 +0200697 if (encoder->crtc != crtc)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700698 continue;
699
Chris Wilsonea5b2132010-08-04 13:50:23 +0100700 intel_dp = enc_to_intel_dp(encoder);
701 if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT) {
702 lane_count = intel_dp->lane_count;
Jesse Barnes51190662010-10-07 16:01:08 -0700703 break;
704 } else if (is_edp(intel_dp)) {
705 lane_count = dev_priv->edp.lanes;
706 bpp = dev_priv->edp.bpp;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700707 break;
708 }
709 }
710
711 /*
712 * Compute the GMCH and Link ratios. The '3' here is
713 * the number of bytes_per_pixel post-LUT, which we always
714 * set up for 8-bits of R/G/B, or 3 bytes total.
715 */
Zhao Yakui36e83a12010-06-12 14:32:21 +0800716 intel_dp_compute_m_n(bpp, lane_count,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700717 mode->clock, adjusted_mode->clock, &m_n);
718
Eric Anholtc619eed2010-01-28 16:45:52 -0800719 if (HAS_PCH_SPLIT(dev)) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800720 I915_WRITE(TRANSDATA_M1(pipe),
721 ((m_n.tu - 1) << PIPE_GMCH_DATA_M_TU_SIZE_SHIFT) |
722 m_n.gmch_m);
723 I915_WRITE(TRANSDATA_N1(pipe), m_n.gmch_n);
724 I915_WRITE(TRANSDPLINK_M1(pipe), m_n.link_m);
725 I915_WRITE(TRANSDPLINK_N1(pipe), m_n.link_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700726 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800727 I915_WRITE(PIPE_GMCH_DATA_M(pipe),
728 ((m_n.tu - 1) << PIPE_GMCH_DATA_M_TU_SIZE_SHIFT) |
729 m_n.gmch_m);
730 I915_WRITE(PIPE_GMCH_DATA_N(pipe), m_n.gmch_n);
731 I915_WRITE(PIPE_DP_LINK_M(pipe), m_n.link_m);
732 I915_WRITE(PIPE_DP_LINK_N(pipe), m_n.link_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700733 }
734}
735
736static void
737intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
738 struct drm_display_mode *adjusted_mode)
739{
Zhenyu Wange3421a12010-04-08 09:43:27 +0800740 struct drm_device *dev = encoder->dev;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100741 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Chris Wilson4ef69c72010-09-09 15:14:28 +0100742 struct drm_crtc *crtc = intel_dp->base.base.crtc;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700743 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
744
Chris Wilsone953fd72011-02-21 22:23:52 +0000745 intel_dp->DP = DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
746 intel_dp->DP |= intel_dp->color_range;
Adam Jackson9c9e7922010-04-05 17:57:59 -0400747
748 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
Chris Wilsonea5b2132010-08-04 13:50:23 +0100749 intel_dp->DP |= DP_SYNC_HS_HIGH;
Adam Jackson9c9e7922010-04-05 17:57:59 -0400750 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
Chris Wilsonea5b2132010-08-04 13:50:23 +0100751 intel_dp->DP |= DP_SYNC_VS_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700752
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700753 if (HAS_PCH_CPT(dev) && !is_edp(intel_dp))
Chris Wilsonea5b2132010-08-04 13:50:23 +0100754 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +0800755 else
Chris Wilsonea5b2132010-08-04 13:50:23 +0100756 intel_dp->DP |= DP_LINK_TRAIN_OFF;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700757
Chris Wilsonea5b2132010-08-04 13:50:23 +0100758 switch (intel_dp->lane_count) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700759 case 1:
Chris Wilsonea5b2132010-08-04 13:50:23 +0100760 intel_dp->DP |= DP_PORT_WIDTH_1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700761 break;
762 case 2:
Chris Wilsonea5b2132010-08-04 13:50:23 +0100763 intel_dp->DP |= DP_PORT_WIDTH_2;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700764 break;
765 case 4:
Chris Wilsonea5b2132010-08-04 13:50:23 +0100766 intel_dp->DP |= DP_PORT_WIDTH_4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700767 break;
768 }
Chris Wilsonea5b2132010-08-04 13:50:23 +0100769 if (intel_dp->has_audio)
770 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700771
Chris Wilsonea5b2132010-08-04 13:50:23 +0100772 memset(intel_dp->link_configuration, 0, DP_LINK_CONFIGURATION_SIZE);
773 intel_dp->link_configuration[0] = intel_dp->link_bw;
774 intel_dp->link_configuration[1] = intel_dp->lane_count;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700775
776 /*
Adam Jackson9962c922010-05-13 14:45:42 -0400777 * Check for DPCD version > 1.1 and enhanced framing support
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700778 */
Chris Wilsonea5b2132010-08-04 13:50:23 +0100779 if (intel_dp->dpcd[0] >= 0x11 && (intel_dp->dpcd[2] & DP_ENHANCED_FRAME_CAP)) {
780 intel_dp->link_configuration[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
781 intel_dp->DP |= DP_ENHANCED_FRAMING;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700782 }
783
Zhenyu Wange3421a12010-04-08 09:43:27 +0800784 /* CPT DP's pipe select is decided in TRANS_DP_CTL */
785 if (intel_crtc->pipe == 1 && !HAS_PCH_CPT(dev))
Chris Wilsonea5b2132010-08-04 13:50:23 +0100786 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800787
Jesse Barnes895692b2010-10-07 16:01:23 -0700788 if (is_edp(intel_dp) && !is_pch_edp(intel_dp)) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800789 /* don't miss out required setting for eDP */
Chris Wilsonea5b2132010-08-04 13:50:23 +0100790 intel_dp->DP |= DP_PLL_ENABLE;
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800791 if (adjusted_mode->clock < 200000)
Chris Wilsonea5b2132010-08-04 13:50:23 +0100792 intel_dp->DP |= DP_PLL_FREQ_160MHZ;
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800793 else
Chris Wilsonea5b2132010-08-04 13:50:23 +0100794 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800795 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700796}
797
Jesse Barnes5d613502011-01-24 17:10:54 -0800798static void ironlake_edp_panel_vdd_on(struct intel_dp *intel_dp)
799{
800 struct drm_device *dev = intel_dp->base.base.dev;
801 struct drm_i915_private *dev_priv = dev->dev_private;
802 u32 pp;
803
804 /*
805 * If the panel wasn't on, make sure there's not a currently
806 * active PP sequence before enabling AUX VDD.
807 */
808 if (!(I915_READ(PCH_PP_STATUS) & PP_ON))
809 msleep(dev_priv->panel_t3);
810
811 pp = I915_READ(PCH_PP_CONTROL);
812 pp |= EDP_FORCE_VDD;
813 I915_WRITE(PCH_PP_CONTROL, pp);
814 POSTING_READ(PCH_PP_CONTROL);
815}
816
817static void ironlake_edp_panel_vdd_off(struct intel_dp *intel_dp)
818{
819 struct drm_device *dev = intel_dp->base.base.dev;
820 struct drm_i915_private *dev_priv = dev->dev_private;
821 u32 pp;
822
823 pp = I915_READ(PCH_PP_CONTROL);
824 pp &= ~EDP_FORCE_VDD;
825 I915_WRITE(PCH_PP_CONTROL, pp);
826 POSTING_READ(PCH_PP_CONTROL);
827
828 /* Make sure sequencer is idle before allowing subsequent activity */
829 msleep(dev_priv->panel_t12);
830}
831
Jesse Barnes7eaf5542010-09-08 12:41:59 -0700832/* Returns true if the panel was already on when called */
Jesse Barnes01cb9ea2010-10-07 16:01:12 -0700833static bool ironlake_edp_panel_on (struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -0700834{
Jesse Barnes01cb9ea2010-10-07 16:01:12 -0700835 struct drm_device *dev = intel_dp->base.base.dev;
Jesse Barnes9934c132010-07-22 13:18:19 -0700836 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -0700837 u32 pp, idle_on_mask = PP_ON | PP_SEQUENCE_STATE_ON_IDLE;
Jesse Barnes9934c132010-07-22 13:18:19 -0700838
Chris Wilson913d8d12010-08-07 11:01:35 +0100839 if (I915_READ(PCH_PP_STATUS) & PP_ON)
Jesse Barnes7eaf5542010-09-08 12:41:59 -0700840 return true;
Jesse Barnes9934c132010-07-22 13:18:19 -0700841
842 pp = I915_READ(PCH_PP_CONTROL);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -0700843
844 /* ILK workaround: disable reset around power sequence */
845 pp &= ~PANEL_POWER_RESET;
846 I915_WRITE(PCH_PP_CONTROL, pp);
847 POSTING_READ(PCH_PP_CONTROL);
848
Jesse Barnes01cb9ea2010-10-07 16:01:12 -0700849 pp |= PANEL_UNLOCK_REGS | POWER_TARGET_ON;
Jesse Barnes9934c132010-07-22 13:18:19 -0700850 I915_WRITE(PCH_PP_CONTROL, pp);
Jesse Barnes01cb9ea2010-10-07 16:01:12 -0700851 POSTING_READ(PCH_PP_CONTROL);
Jesse Barnes9934c132010-07-22 13:18:19 -0700852
Jesse Barnes01cb9ea2010-10-07 16:01:12 -0700853 if (wait_for((I915_READ(PCH_PP_STATUS) & idle_on_mask) == idle_on_mask,
854 5000))
Chris Wilson913d8d12010-08-07 11:01:35 +0100855 DRM_ERROR("panel on wait timed out: 0x%08x\n",
856 I915_READ(PCH_PP_STATUS));
Jesse Barnes9934c132010-07-22 13:18:19 -0700857
Jesse Barnes37c6c9b2010-08-11 10:04:43 -0700858 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jesse Barnes9934c132010-07-22 13:18:19 -0700859 I915_WRITE(PCH_PP_CONTROL, pp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -0700860 POSTING_READ(PCH_PP_CONTROL);
Jesse Barnes7eaf5542010-09-08 12:41:59 -0700861
862 return false;
Jesse Barnes9934c132010-07-22 13:18:19 -0700863}
864
865static void ironlake_edp_panel_off (struct drm_device *dev)
866{
867 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -0700868 u32 pp, idle_off_mask = PP_ON | PP_SEQUENCE_MASK |
869 PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK;
Jesse Barnes9934c132010-07-22 13:18:19 -0700870
871 pp = I915_READ(PCH_PP_CONTROL);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -0700872
873 /* ILK workaround: disable reset around power sequence */
874 pp &= ~PANEL_POWER_RESET;
875 I915_WRITE(PCH_PP_CONTROL, pp);
876 POSTING_READ(PCH_PP_CONTROL);
877
Jesse Barnes9934c132010-07-22 13:18:19 -0700878 pp &= ~POWER_TARGET_ON;
879 I915_WRITE(PCH_PP_CONTROL, pp);
Jesse Barnes01cb9ea2010-10-07 16:01:12 -0700880 POSTING_READ(PCH_PP_CONTROL);
Jesse Barnes9934c132010-07-22 13:18:19 -0700881
Jesse Barnes01cb9ea2010-10-07 16:01:12 -0700882 if (wait_for((I915_READ(PCH_PP_STATUS) & idle_off_mask) == 0, 5000))
Chris Wilson913d8d12010-08-07 11:01:35 +0100883 DRM_ERROR("panel off wait timed out: 0x%08x\n",
884 I915_READ(PCH_PP_STATUS));
Jesse Barnes9934c132010-07-22 13:18:19 -0700885
Jesse Barnes3969c9c92010-09-08 12:42:03 -0700886 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jesse Barnes9934c132010-07-22 13:18:19 -0700887 I915_WRITE(PCH_PP_CONTROL, pp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -0700888 POSTING_READ(PCH_PP_CONTROL);
Jesse Barnes9934c132010-07-22 13:18:19 -0700889}
890
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500891static void ironlake_edp_backlight_on (struct drm_device *dev)
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800892{
893 struct drm_i915_private *dev_priv = dev->dev_private;
894 u32 pp;
895
Zhao Yakui28c97732009-10-09 11:39:41 +0800896 DRM_DEBUG_KMS("\n");
Jesse Barnes01cb9ea2010-10-07 16:01:12 -0700897 /*
898 * If we enable the backlight right away following a panel power
899 * on, we may see slight flicker as the panel syncs with the eDP
900 * link. So delay a bit to make sure the image is solid before
901 * allowing it to appear.
902 */
903 msleep(300);
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800904 pp = I915_READ(PCH_PP_CONTROL);
905 pp |= EDP_BLC_ENABLE;
906 I915_WRITE(PCH_PP_CONTROL, pp);
907}
908
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500909static void ironlake_edp_backlight_off (struct drm_device *dev)
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800910{
911 struct drm_i915_private *dev_priv = dev->dev_private;
912 u32 pp;
913
Zhao Yakui28c97732009-10-09 11:39:41 +0800914 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800915 pp = I915_READ(PCH_PP_CONTROL);
916 pp &= ~EDP_BLC_ENABLE;
917 I915_WRITE(PCH_PP_CONTROL, pp);
918}
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700919
Jesse Barnesd240f202010-08-13 15:43:26 -0700920static void ironlake_edp_pll_on(struct drm_encoder *encoder)
921{
922 struct drm_device *dev = encoder->dev;
923 struct drm_i915_private *dev_priv = dev->dev_private;
924 u32 dpa_ctl;
925
926 DRM_DEBUG_KMS("\n");
927 dpa_ctl = I915_READ(DP_A);
Jesse Barnes298b0b32010-10-07 16:01:24 -0700928 dpa_ctl |= DP_PLL_ENABLE;
Jesse Barnesd240f202010-08-13 15:43:26 -0700929 I915_WRITE(DP_A, dpa_ctl);
Jesse Barnes298b0b32010-10-07 16:01:24 -0700930 POSTING_READ(DP_A);
931 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -0700932}
933
934static void ironlake_edp_pll_off(struct drm_encoder *encoder)
935{
936 struct drm_device *dev = encoder->dev;
937 struct drm_i915_private *dev_priv = dev->dev_private;
938 u32 dpa_ctl;
939
940 dpa_ctl = I915_READ(DP_A);
Jesse Barnes298b0b32010-10-07 16:01:24 -0700941 dpa_ctl &= ~DP_PLL_ENABLE;
Jesse Barnesd240f202010-08-13 15:43:26 -0700942 I915_WRITE(DP_A, dpa_ctl);
Chris Wilson1af5fa12010-09-08 21:07:28 +0100943 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -0700944 udelay(200);
945}
946
947static void intel_dp_prepare(struct drm_encoder *encoder)
948{
949 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
950 struct drm_device *dev = encoder->dev;
Jesse Barnesd240f202010-08-13 15:43:26 -0700951
Jesse Barnes4d926462010-10-07 16:01:07 -0700952 if (is_edp(intel_dp)) {
Jesse Barnesd240f202010-08-13 15:43:26 -0700953 ironlake_edp_backlight_off(dev);
Jesse Barnes5d613502011-01-24 17:10:54 -0800954 ironlake_edp_panel_off(dev);
Jesse Barnes01cb9ea2010-10-07 16:01:12 -0700955 if (!is_pch_edp(intel_dp))
956 ironlake_edp_pll_on(encoder);
957 else
958 ironlake_edp_pll_off(encoder);
Jesse Barnesd240f202010-08-13 15:43:26 -0700959 }
Jesse Barnes736085b2010-10-08 10:35:55 -0700960 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -0700961}
962
963static void intel_dp_commit(struct drm_encoder *encoder)
964{
965 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
966 struct drm_device *dev = encoder->dev;
Jesse Barnesd240f202010-08-13 15:43:26 -0700967
Jesse Barnes5d613502011-01-24 17:10:54 -0800968 if (is_edp(intel_dp))
969 ironlake_edp_panel_vdd_on(intel_dp);
970
Jesse Barnes33a34e42010-09-08 12:42:02 -0700971 intel_dp_start_link_train(intel_dp);
972
Jesse Barnes5d613502011-01-24 17:10:54 -0800973 if (is_edp(intel_dp)) {
Jesse Barnes01cb9ea2010-10-07 16:01:12 -0700974 ironlake_edp_panel_on(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -0800975 ironlake_edp_panel_vdd_off(intel_dp);
976 }
Jesse Barnes33a34e42010-09-08 12:42:02 -0700977
978 intel_dp_complete_link_train(intel_dp);
979
Jesse Barnes4d926462010-10-07 16:01:07 -0700980 if (is_edp(intel_dp))
Jesse Barnesd240f202010-08-13 15:43:26 -0700981 ironlake_edp_backlight_on(dev);
982}
983
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700984static void
985intel_dp_dpms(struct drm_encoder *encoder, int mode)
986{
Chris Wilsonea5b2132010-08-04 13:50:23 +0100987 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Zhenyu Wang55f78c42010-03-29 16:13:57 +0800988 struct drm_device *dev = encoder->dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700989 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100990 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700991
992 if (mode != DRM_MODE_DPMS_ON) {
Jesse Barnes01cb9ea2010-10-07 16:01:12 -0700993 if (is_edp(intel_dp))
Jesse Barnes7643a7f2010-08-11 10:06:44 -0700994 ironlake_edp_backlight_off(dev);
Jesse Barnes736085b2010-10-08 10:35:55 -0700995 intel_dp_link_down(intel_dp);
Jesse Barnes4d926462010-10-07 16:01:07 -0700996 if (is_edp(intel_dp))
Jesse Barnes01cb9ea2010-10-07 16:01:12 -0700997 ironlake_edp_panel_off(dev);
998 if (is_edp(intel_dp) && !is_pch_edp(intel_dp))
Jesse Barnesd240f202010-08-13 15:43:26 -0700999 ironlake_edp_pll_off(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001000 } else {
Jesse Barnes736085b2010-10-08 10:35:55 -07001001 if (is_edp(intel_dp))
Jesse Barnes5d613502011-01-24 17:10:54 -08001002 ironlake_edp_panel_vdd_on(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001003 if (!(dp_reg & DP_PORT_EN)) {
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001004 intel_dp_start_link_train(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001005 if (is_edp(intel_dp)) {
1006 ironlake_edp_panel_on(intel_dp);
1007 ironlake_edp_panel_vdd_off(intel_dp);
1008 }
Jesse Barnes33a34e42010-09-08 12:42:02 -07001009 intel_dp_complete_link_train(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001010 }
Jesse Barnes736085b2010-10-08 10:35:55 -07001011 if (is_edp(intel_dp))
1012 ironlake_edp_backlight_on(dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001013 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01001014 intel_dp->dpms_mode = mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001015}
1016
1017/*
1018 * Fetch AUX CH registers 0x202 - 0x207 which contain
1019 * link status information
1020 */
1021static bool
Jesse Barnes33a34e42010-09-08 12:42:02 -07001022intel_dp_get_link_status(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001023{
1024 int ret;
1025
Chris Wilsonea5b2132010-08-04 13:50:23 +01001026 ret = intel_dp_aux_native_read(intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001027 DP_LANE0_1_STATUS,
Jesse Barnes33a34e42010-09-08 12:42:02 -07001028 intel_dp->link_status, DP_LINK_STATUS_SIZE);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001029 if (ret != DP_LINK_STATUS_SIZE)
1030 return false;
1031 return true;
1032}
1033
1034static uint8_t
1035intel_dp_link_status(uint8_t link_status[DP_LINK_STATUS_SIZE],
1036 int r)
1037{
1038 return link_status[r - DP_LANE0_1_STATUS];
1039}
1040
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001041static uint8_t
1042intel_get_adjust_request_voltage(uint8_t link_status[DP_LINK_STATUS_SIZE],
1043 int lane)
1044{
1045 int i = DP_ADJUST_REQUEST_LANE0_1 + (lane >> 1);
1046 int s = ((lane & 1) ?
1047 DP_ADJUST_VOLTAGE_SWING_LANE1_SHIFT :
1048 DP_ADJUST_VOLTAGE_SWING_LANE0_SHIFT);
1049 uint8_t l = intel_dp_link_status(link_status, i);
1050
1051 return ((l >> s) & 3) << DP_TRAIN_VOLTAGE_SWING_SHIFT;
1052}
1053
1054static uint8_t
1055intel_get_adjust_request_pre_emphasis(uint8_t link_status[DP_LINK_STATUS_SIZE],
1056 int lane)
1057{
1058 int i = DP_ADJUST_REQUEST_LANE0_1 + (lane >> 1);
1059 int s = ((lane & 1) ?
1060 DP_ADJUST_PRE_EMPHASIS_LANE1_SHIFT :
1061 DP_ADJUST_PRE_EMPHASIS_LANE0_SHIFT);
1062 uint8_t l = intel_dp_link_status(link_status, i);
1063
1064 return ((l >> s) & 3) << DP_TRAIN_PRE_EMPHASIS_SHIFT;
1065}
1066
1067
1068#if 0
1069static char *voltage_names[] = {
1070 "0.4V", "0.6V", "0.8V", "1.2V"
1071};
1072static char *pre_emph_names[] = {
1073 "0dB", "3.5dB", "6dB", "9.5dB"
1074};
1075static char *link_train_names[] = {
1076 "pattern 1", "pattern 2", "idle", "off"
1077};
1078#endif
1079
1080/*
1081 * These are source-specific values; current Intel hardware supports
1082 * a maximum voltage of 800mV and a maximum pre-emphasis of 6dB
1083 */
1084#define I830_DP_VOLTAGE_MAX DP_TRAIN_VOLTAGE_SWING_800
1085
1086static uint8_t
1087intel_dp_pre_emphasis_max(uint8_t voltage_swing)
1088{
1089 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
1090 case DP_TRAIN_VOLTAGE_SWING_400:
1091 return DP_TRAIN_PRE_EMPHASIS_6;
1092 case DP_TRAIN_VOLTAGE_SWING_600:
1093 return DP_TRAIN_PRE_EMPHASIS_6;
1094 case DP_TRAIN_VOLTAGE_SWING_800:
1095 return DP_TRAIN_PRE_EMPHASIS_3_5;
1096 case DP_TRAIN_VOLTAGE_SWING_1200:
1097 default:
1098 return DP_TRAIN_PRE_EMPHASIS_0;
1099 }
1100}
1101
1102static void
Jesse Barnes33a34e42010-09-08 12:42:02 -07001103intel_get_adjust_train(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001104{
1105 uint8_t v = 0;
1106 uint8_t p = 0;
1107 int lane;
1108
Jesse Barnes33a34e42010-09-08 12:42:02 -07001109 for (lane = 0; lane < intel_dp->lane_count; lane++) {
1110 uint8_t this_v = intel_get_adjust_request_voltage(intel_dp->link_status, lane);
1111 uint8_t this_p = intel_get_adjust_request_pre_emphasis(intel_dp->link_status, lane);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001112
1113 if (this_v > v)
1114 v = this_v;
1115 if (this_p > p)
1116 p = this_p;
1117 }
1118
1119 if (v >= I830_DP_VOLTAGE_MAX)
1120 v = I830_DP_VOLTAGE_MAX | DP_TRAIN_MAX_SWING_REACHED;
1121
1122 if (p >= intel_dp_pre_emphasis_max(v))
1123 p = intel_dp_pre_emphasis_max(v) | DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
1124
1125 for (lane = 0; lane < 4; lane++)
Jesse Barnes33a34e42010-09-08 12:42:02 -07001126 intel_dp->train_set[lane] = v | p;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001127}
1128
1129static uint32_t
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001130intel_dp_signal_levels(uint8_t train_set, int lane_count)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001131{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001132 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001133
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001134 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001135 case DP_TRAIN_VOLTAGE_SWING_400:
1136 default:
1137 signal_levels |= DP_VOLTAGE_0_4;
1138 break;
1139 case DP_TRAIN_VOLTAGE_SWING_600:
1140 signal_levels |= DP_VOLTAGE_0_6;
1141 break;
1142 case DP_TRAIN_VOLTAGE_SWING_800:
1143 signal_levels |= DP_VOLTAGE_0_8;
1144 break;
1145 case DP_TRAIN_VOLTAGE_SWING_1200:
1146 signal_levels |= DP_VOLTAGE_1_2;
1147 break;
1148 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001149 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001150 case DP_TRAIN_PRE_EMPHASIS_0:
1151 default:
1152 signal_levels |= DP_PRE_EMPHASIS_0;
1153 break;
1154 case DP_TRAIN_PRE_EMPHASIS_3_5:
1155 signal_levels |= DP_PRE_EMPHASIS_3_5;
1156 break;
1157 case DP_TRAIN_PRE_EMPHASIS_6:
1158 signal_levels |= DP_PRE_EMPHASIS_6;
1159 break;
1160 case DP_TRAIN_PRE_EMPHASIS_9_5:
1161 signal_levels |= DP_PRE_EMPHASIS_9_5;
1162 break;
1163 }
1164 return signal_levels;
1165}
1166
Zhenyu Wange3421a12010-04-08 09:43:27 +08001167/* Gen6's DP voltage swing and pre-emphasis control */
1168static uint32_t
1169intel_gen6_edp_signal_levels(uint8_t train_set)
1170{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001171 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
1172 DP_TRAIN_PRE_EMPHASIS_MASK);
1173 switch (signal_levels) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08001174 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001175 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
1176 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
1177 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
1178 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001179 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001180 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
1181 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001182 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001183 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
1184 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001185 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001186 case DP_TRAIN_VOLTAGE_SWING_1200 | DP_TRAIN_PRE_EMPHASIS_0:
1187 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001188 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001189 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
1190 "0x%x\n", signal_levels);
1191 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001192 }
1193}
1194
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001195static uint8_t
1196intel_get_lane_status(uint8_t link_status[DP_LINK_STATUS_SIZE],
1197 int lane)
1198{
1199 int i = DP_LANE0_1_STATUS + (lane >> 1);
1200 int s = (lane & 1) * 4;
1201 uint8_t l = intel_dp_link_status(link_status, i);
1202
1203 return (l >> s) & 0xf;
1204}
1205
1206/* Check for clock recovery is done on all channels */
1207static bool
1208intel_clock_recovery_ok(uint8_t link_status[DP_LINK_STATUS_SIZE], int lane_count)
1209{
1210 int lane;
1211 uint8_t lane_status;
1212
1213 for (lane = 0; lane < lane_count; lane++) {
1214 lane_status = intel_get_lane_status(link_status, lane);
1215 if ((lane_status & DP_LANE_CR_DONE) == 0)
1216 return false;
1217 }
1218 return true;
1219}
1220
1221/* Check to see if channel eq is done on all channels */
1222#define CHANNEL_EQ_BITS (DP_LANE_CR_DONE|\
1223 DP_LANE_CHANNEL_EQ_DONE|\
1224 DP_LANE_SYMBOL_LOCKED)
1225static bool
Jesse Barnes33a34e42010-09-08 12:42:02 -07001226intel_channel_eq_ok(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001227{
1228 uint8_t lane_align;
1229 uint8_t lane_status;
1230 int lane;
1231
Jesse Barnes33a34e42010-09-08 12:42:02 -07001232 lane_align = intel_dp_link_status(intel_dp->link_status,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001233 DP_LANE_ALIGN_STATUS_UPDATED);
1234 if ((lane_align & DP_INTERLANE_ALIGN_DONE) == 0)
1235 return false;
Jesse Barnes33a34e42010-09-08 12:42:02 -07001236 for (lane = 0; lane < intel_dp->lane_count; lane++) {
1237 lane_status = intel_get_lane_status(intel_dp->link_status, lane);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001238 if ((lane_status & CHANNEL_EQ_BITS) != CHANNEL_EQ_BITS)
1239 return false;
1240 }
1241 return true;
1242}
1243
1244static bool
Chris Wilsonea5b2132010-08-04 13:50:23 +01001245intel_dp_set_link_train(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001246 uint32_t dp_reg_value,
Chris Wilson58e10eb2010-10-03 10:56:11 +01001247 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001248{
Chris Wilson4ef69c72010-09-09 15:14:28 +01001249 struct drm_device *dev = intel_dp->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001250 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001251 int ret;
1252
Chris Wilsonea5b2132010-08-04 13:50:23 +01001253 I915_WRITE(intel_dp->output_reg, dp_reg_value);
1254 POSTING_READ(intel_dp->output_reg);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001255
Chris Wilsonea5b2132010-08-04 13:50:23 +01001256 intel_dp_aux_native_write_1(intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001257 DP_TRAINING_PATTERN_SET,
1258 dp_train_pat);
1259
Chris Wilsonea5b2132010-08-04 13:50:23 +01001260 ret = intel_dp_aux_native_write(intel_dp,
Chris Wilson58e10eb2010-10-03 10:56:11 +01001261 DP_TRAINING_LANE0_SET,
1262 intel_dp->train_set, 4);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001263 if (ret != 4)
1264 return false;
1265
1266 return true;
1267}
1268
Jesse Barnes33a34e42010-09-08 12:42:02 -07001269/* Enable corresponding port and start training pattern 1 */
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001270static void
Jesse Barnes33a34e42010-09-08 12:42:02 -07001271intel_dp_start_link_train(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001272{
Chris Wilson4ef69c72010-09-09 15:14:28 +01001273 struct drm_device *dev = intel_dp->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001274 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson58e10eb2010-10-03 10:56:11 +01001275 struct intel_crtc *intel_crtc = to_intel_crtc(intel_dp->base.base.crtc);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001276 int i;
1277 uint8_t voltage;
1278 bool clock_recovery = false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001279 int tries;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001280 u32 reg;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001281 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001282
Keith Packardb99a9d92010-10-03 00:33:05 -07001283 /* Enable output, wait for it to become active */
1284 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
1285 POSTING_READ(intel_dp->output_reg);
1286 intel_wait_for_vblank(dev, intel_crtc->pipe);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001287
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001288 /* Write the link configuration data */
1289 intel_dp_aux_native_write(intel_dp, DP_LINK_BW_SET,
1290 intel_dp->link_configuration,
1291 DP_LINK_CONFIGURATION_SIZE);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001292
1293 DP |= DP_PORT_EN;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001294 if (HAS_PCH_CPT(dev) && !is_edp(intel_dp))
Zhenyu Wange3421a12010-04-08 09:43:27 +08001295 DP &= ~DP_LINK_TRAIN_MASK_CPT;
1296 else
1297 DP &= ~DP_LINK_TRAIN_MASK;
Jesse Barnes33a34e42010-09-08 12:42:02 -07001298 memset(intel_dp->train_set, 0, 4);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001299 voltage = 0xff;
1300 tries = 0;
1301 clock_recovery = false;
1302 for (;;) {
Jesse Barnes33a34e42010-09-08 12:42:02 -07001303 /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */
Zhenyu Wange3421a12010-04-08 09:43:27 +08001304 uint32_t signal_levels;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001305 if (IS_GEN6(dev) && is_edp(intel_dp)) {
Jesse Barnes33a34e42010-09-08 12:42:02 -07001306 signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001307 DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels;
1308 } else {
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001309 signal_levels = intel_dp_signal_levels(intel_dp->train_set[0], intel_dp->lane_count);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001310 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
1311 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001312
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001313 if (HAS_PCH_CPT(dev) && !is_edp(intel_dp))
Zhenyu Wange3421a12010-04-08 09:43:27 +08001314 reg = DP | DP_LINK_TRAIN_PAT_1_CPT;
1315 else
1316 reg = DP | DP_LINK_TRAIN_PAT_1;
1317
Chris Wilsonea5b2132010-08-04 13:50:23 +01001318 if (!intel_dp_set_link_train(intel_dp, reg,
Chris Wilson58e10eb2010-10-03 10:56:11 +01001319 DP_TRAINING_PATTERN_1))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001320 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001321 /* Set training pattern 1 */
1322
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001323 udelay(100);
1324 if (!intel_dp_get_link_status(intel_dp))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001325 break;
1326
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001327 if (intel_clock_recovery_ok(intel_dp->link_status, intel_dp->lane_count)) {
1328 clock_recovery = true;
1329 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001330 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001331
1332 /* Check to see if we've tried the max voltage */
1333 for (i = 0; i < intel_dp->lane_count; i++)
1334 if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
1335 break;
1336 if (i == intel_dp->lane_count)
1337 break;
1338
1339 /* Check to see if we've tried the same voltage 5 times */
1340 if ((intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) == voltage) {
1341 ++tries;
1342 if (tries == 5)
1343 break;
1344 } else
1345 tries = 0;
1346 voltage = intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
1347
1348 /* Compute new intel_dp->train_set as requested by target */
1349 intel_get_adjust_train(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001350 }
1351
Jesse Barnes33a34e42010-09-08 12:42:02 -07001352 intel_dp->DP = DP;
1353}
1354
1355static void
1356intel_dp_complete_link_train(struct intel_dp *intel_dp)
1357{
Chris Wilson4ef69c72010-09-09 15:14:28 +01001358 struct drm_device *dev = intel_dp->base.base.dev;
Jesse Barnes33a34e42010-09-08 12:42:02 -07001359 struct drm_i915_private *dev_priv = dev->dev_private;
1360 bool channel_eq = false;
Jesse Barnes37f80972011-01-05 14:45:24 -08001361 int tries, cr_tries;
Jesse Barnes33a34e42010-09-08 12:42:02 -07001362 u32 reg;
1363 uint32_t DP = intel_dp->DP;
1364
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001365 /* channel equalization */
1366 tries = 0;
Jesse Barnes37f80972011-01-05 14:45:24 -08001367 cr_tries = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001368 channel_eq = false;
1369 for (;;) {
Jesse Barnes33a34e42010-09-08 12:42:02 -07001370 /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */
Zhenyu Wange3421a12010-04-08 09:43:27 +08001371 uint32_t signal_levels;
1372
Jesse Barnes37f80972011-01-05 14:45:24 -08001373 if (cr_tries > 5) {
1374 DRM_ERROR("failed to train DP, aborting\n");
1375 intel_dp_link_down(intel_dp);
1376 break;
1377 }
1378
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001379 if (IS_GEN6(dev) && is_edp(intel_dp)) {
Jesse Barnes33a34e42010-09-08 12:42:02 -07001380 signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001381 DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels;
1382 } else {
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001383 signal_levels = intel_dp_signal_levels(intel_dp->train_set[0], intel_dp->lane_count);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001384 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
1385 }
1386
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001387 if (HAS_PCH_CPT(dev) && !is_edp(intel_dp))
Zhenyu Wange3421a12010-04-08 09:43:27 +08001388 reg = DP | DP_LINK_TRAIN_PAT_2_CPT;
1389 else
1390 reg = DP | DP_LINK_TRAIN_PAT_2;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001391
1392 /* channel eq pattern */
Chris Wilsonea5b2132010-08-04 13:50:23 +01001393 if (!intel_dp_set_link_train(intel_dp, reg,
Chris Wilson58e10eb2010-10-03 10:56:11 +01001394 DP_TRAINING_PATTERN_2))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001395 break;
1396
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001397 udelay(400);
1398 if (!intel_dp_get_link_status(intel_dp))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001399 break;
Jesse Barnes869184a2010-10-07 16:01:22 -07001400
Jesse Barnes37f80972011-01-05 14:45:24 -08001401 /* Make sure clock is still ok */
1402 if (!intel_clock_recovery_ok(intel_dp->link_status, intel_dp->lane_count)) {
1403 intel_dp_start_link_train(intel_dp);
1404 cr_tries++;
1405 continue;
1406 }
1407
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001408 if (intel_channel_eq_ok(intel_dp)) {
1409 channel_eq = true;
1410 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001411 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001412
Jesse Barnes37f80972011-01-05 14:45:24 -08001413 /* Try 5 times, then try clock recovery if that fails */
1414 if (tries > 5) {
1415 intel_dp_link_down(intel_dp);
1416 intel_dp_start_link_train(intel_dp);
1417 tries = 0;
1418 cr_tries++;
1419 continue;
1420 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001421
1422 /* Compute new intel_dp->train_set as requested by target */
1423 intel_get_adjust_train(intel_dp);
1424 ++tries;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001425 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001426
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001427 if (HAS_PCH_CPT(dev) && !is_edp(intel_dp))
Zhenyu Wange3421a12010-04-08 09:43:27 +08001428 reg = DP | DP_LINK_TRAIN_OFF_CPT;
1429 else
1430 reg = DP | DP_LINK_TRAIN_OFF;
1431
Chris Wilsonea5b2132010-08-04 13:50:23 +01001432 I915_WRITE(intel_dp->output_reg, reg);
1433 POSTING_READ(intel_dp->output_reg);
1434 intel_dp_aux_native_write_1(intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001435 DP_TRAINING_PATTERN_SET, DP_TRAINING_PATTERN_DISABLE);
1436}
1437
1438static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01001439intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001440{
Chris Wilson4ef69c72010-09-09 15:14:28 +01001441 struct drm_device *dev = intel_dp->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001442 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001443 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001444
Chris Wilson1b39d6f2010-12-06 11:20:45 +00001445 if ((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0)
1446 return;
1447
Zhao Yakui28c97732009-10-09 11:39:41 +08001448 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001449
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001450 if (is_edp(intel_dp)) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001451 DP &= ~DP_PLL_ENABLE;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001452 I915_WRITE(intel_dp->output_reg, DP);
1453 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001454 udelay(100);
1455 }
1456
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001457 if (HAS_PCH_CPT(dev) && !is_edp(intel_dp)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08001458 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001459 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001460 } else {
1461 DP &= ~DP_LINK_TRAIN_MASK;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001462 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001463 }
Chris Wilsonfe255d02010-09-11 21:37:48 +01001464 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001465
Chris Wilsonfe255d02010-09-11 21:37:48 +01001466 msleep(17);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001467
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001468 if (is_edp(intel_dp))
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001469 DP |= DP_LINK_TRAIN_OFF;
Eric Anholt5bddd172010-11-18 09:32:59 +08001470
Chris Wilson1b39d6f2010-12-06 11:20:45 +00001471 if (!HAS_PCH_CPT(dev) &&
1472 I915_READ(intel_dp->output_reg) & DP_PIPEB_SELECT) {
Chris Wilson31acbcc2011-04-17 06:38:35 +01001473 struct drm_crtc *crtc = intel_dp->base.base.crtc;
1474
Eric Anholt5bddd172010-11-18 09:32:59 +08001475 /* Hardware workaround: leaving our transcoder select
1476 * set to transcoder B while it's off will prevent the
1477 * corresponding HDMI output on transcoder A.
1478 *
1479 * Combine this with another hardware workaround:
1480 * transcoder select bit can only be cleared while the
1481 * port is enabled.
1482 */
1483 DP &= ~DP_PIPEB_SELECT;
1484 I915_WRITE(intel_dp->output_reg, DP);
1485
1486 /* Changes to enable or select take place the vblank
1487 * after being written.
1488 */
Chris Wilson31acbcc2011-04-17 06:38:35 +01001489 if (crtc == NULL) {
1490 /* We can arrive here never having been attached
1491 * to a CRTC, for instance, due to inheriting
1492 * random state from the BIOS.
1493 *
1494 * If the pipe is not running, play safe and
1495 * wait for the clocks to stabilise before
1496 * continuing.
1497 */
1498 POSTING_READ(intel_dp->output_reg);
1499 msleep(50);
1500 } else
1501 intel_wait_for_vblank(dev, to_intel_crtc(crtc)->pipe);
Eric Anholt5bddd172010-11-18 09:32:59 +08001502 }
1503
Chris Wilsonea5b2132010-08-04 13:50:23 +01001504 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
1505 POSTING_READ(intel_dp->output_reg);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001506}
1507
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001508/*
1509 * According to DP spec
1510 * 5.1.2:
1511 * 1. Read DPCD
1512 * 2. Configure link according to Receiver Capabilities
1513 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
1514 * 4. Check link status on receipt of hot-plug interrupt
1515 */
1516
1517static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01001518intel_dp_check_link_status(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001519{
Chris Wilson4ef69c72010-09-09 15:14:28 +01001520 if (!intel_dp->base.base.crtc)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001521 return;
1522
Jesse Barnes33a34e42010-09-08 12:42:02 -07001523 if (!intel_dp_get_link_status(intel_dp)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001524 intel_dp_link_down(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001525 return;
1526 }
1527
Jesse Barnes33a34e42010-09-08 12:42:02 -07001528 if (!intel_channel_eq_ok(intel_dp)) {
1529 intel_dp_start_link_train(intel_dp);
1530 intel_dp_complete_link_train(intel_dp);
1531 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001532}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001533
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001534static enum drm_connector_status
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001535ironlake_dp_detect(struct intel_dp *intel_dp)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001536{
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001537 enum drm_connector_status status;
1538
Chris Wilsonfe16d942011-02-12 10:29:38 +00001539 /* Can't disconnect eDP, but you can close the lid... */
1540 if (is_edp(intel_dp)) {
1541 status = intel_panel_detect(intel_dp->base.base.dev);
1542 if (status == connector_status_unknown)
1543 status = connector_status_connected;
1544 return status;
1545 }
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001546
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001547 status = connector_status_disconnected;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001548 if (intel_dp_aux_native_read(intel_dp,
1549 0x000, intel_dp->dpcd,
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001550 sizeof (intel_dp->dpcd))
1551 == sizeof(intel_dp->dpcd)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001552 if (intel_dp->dpcd[0] != 0)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001553 status = connector_status_connected;
1554 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01001555 DRM_DEBUG_KMS("DPCD: %hx%hx%hx%hx\n", intel_dp->dpcd[0],
1556 intel_dp->dpcd[1], intel_dp->dpcd[2], intel_dp->dpcd[3]);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001557 return status;
1558}
1559
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001560static enum drm_connector_status
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001561g4x_dp_detect(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001562{
Chris Wilson4ef69c72010-09-09 15:14:28 +01001563 struct drm_device *dev = intel_dp->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001564 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001565 enum drm_connector_status status;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001566 uint32_t temp, bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001567
Chris Wilsonea5b2132010-08-04 13:50:23 +01001568 switch (intel_dp->output_reg) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001569 case DP_B:
1570 bit = DPB_HOTPLUG_INT_STATUS;
1571 break;
1572 case DP_C:
1573 bit = DPC_HOTPLUG_INT_STATUS;
1574 break;
1575 case DP_D:
1576 bit = DPD_HOTPLUG_INT_STATUS;
1577 break;
1578 default:
1579 return connector_status_unknown;
1580 }
1581
1582 temp = I915_READ(PORT_HOTPLUG_STAT);
1583
1584 if ((temp & bit) == 0)
1585 return connector_status_disconnected;
1586
1587 status = connector_status_disconnected;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001588 if (intel_dp_aux_native_read(intel_dp, 0x000, intel_dp->dpcd,
Chris Wilsonea5b2132010-08-04 13:50:23 +01001589 sizeof (intel_dp->dpcd)) == sizeof (intel_dp->dpcd))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001590 {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001591 if (intel_dp->dpcd[0] != 0)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001592 status = connector_status_connected;
1593 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001594
Takashi Iwaidd2b3792010-10-26 17:14:36 +01001595 return status;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001596}
1597
1598/**
1599 * Uses CRT_HOTPLUG_EN and CRT_HOTPLUG_STAT to detect DP connection.
1600 *
1601 * \return true if DP port is connected.
1602 * \return false if DP port is disconnected.
1603 */
1604static enum drm_connector_status
1605intel_dp_detect(struct drm_connector *connector, bool force)
1606{
1607 struct intel_dp *intel_dp = intel_attached_dp(connector);
1608 struct drm_device *dev = intel_dp->base.base.dev;
1609 enum drm_connector_status status;
1610 struct edid *edid = NULL;
1611
1612 intel_dp->has_audio = false;
1613
1614 if (HAS_PCH_SPLIT(dev))
1615 status = ironlake_dp_detect(intel_dp);
1616 else
1617 status = g4x_dp_detect(intel_dp);
1618 if (status != connector_status_connected)
1619 return status;
1620
Chris Wilsonf6849602010-09-19 09:29:33 +01001621 if (intel_dp->force_audio) {
1622 intel_dp->has_audio = intel_dp->force_audio > 0;
1623 } else {
1624 edid = drm_get_edid(connector, &intel_dp->adapter);
1625 if (edid) {
1626 intel_dp->has_audio = drm_detect_monitor_audio(edid);
1627 connector->display_info.raw_edid = NULL;
1628 kfree(edid);
1629 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001630 }
1631
1632 return connector_status_connected;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001633}
1634
1635static int intel_dp_get_modes(struct drm_connector *connector)
1636{
Chris Wilsondf0e9242010-09-09 16:20:55 +01001637 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson4ef69c72010-09-09 15:14:28 +01001638 struct drm_device *dev = intel_dp->base.base.dev;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001639 struct drm_i915_private *dev_priv = dev->dev_private;
1640 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001641
1642 /* We should parse the EDID data and find out if it has an audio sink
1643 */
1644
Chris Wilsonf899fc62010-07-20 15:44:45 -07001645 ret = intel_ddc_get_modes(connector, &intel_dp->adapter);
Zhao Yakuib9efc482010-07-19 09:43:11 +01001646 if (ret) {
Jesse Barnes4d926462010-10-07 16:01:07 -07001647 if (is_edp(intel_dp) && !dev_priv->panel_fixed_mode) {
Zhao Yakuib9efc482010-07-19 09:43:11 +01001648 struct drm_display_mode *newmode;
1649 list_for_each_entry(newmode, &connector->probed_modes,
1650 head) {
1651 if (newmode->type & DRM_MODE_TYPE_PREFERRED) {
1652 dev_priv->panel_fixed_mode =
1653 drm_mode_duplicate(dev, newmode);
1654 break;
1655 }
1656 }
1657 }
1658
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001659 return ret;
Zhao Yakuib9efc482010-07-19 09:43:11 +01001660 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001661
1662 /* if eDP has no EDID, try to use fixed panel mode from VBT */
Jesse Barnes4d926462010-10-07 16:01:07 -07001663 if (is_edp(intel_dp)) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001664 if (dev_priv->panel_fixed_mode != NULL) {
1665 struct drm_display_mode *mode;
1666 mode = drm_mode_duplicate(dev, dev_priv->panel_fixed_mode);
1667 drm_mode_probed_add(connector, mode);
1668 return 1;
1669 }
1670 }
1671 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001672}
1673
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001674static bool
1675intel_dp_detect_audio(struct drm_connector *connector)
1676{
1677 struct intel_dp *intel_dp = intel_attached_dp(connector);
1678 struct edid *edid;
1679 bool has_audio = false;
1680
1681 edid = drm_get_edid(connector, &intel_dp->adapter);
1682 if (edid) {
1683 has_audio = drm_detect_monitor_audio(edid);
1684
1685 connector->display_info.raw_edid = NULL;
1686 kfree(edid);
1687 }
1688
1689 return has_audio;
1690}
1691
Chris Wilsonf6849602010-09-19 09:29:33 +01001692static int
1693intel_dp_set_property(struct drm_connector *connector,
1694 struct drm_property *property,
1695 uint64_t val)
1696{
Chris Wilsone953fd72011-02-21 22:23:52 +00001697 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Chris Wilsonf6849602010-09-19 09:29:33 +01001698 struct intel_dp *intel_dp = intel_attached_dp(connector);
1699 int ret;
1700
1701 ret = drm_connector_property_set_value(connector, property, val);
1702 if (ret)
1703 return ret;
1704
1705 if (property == intel_dp->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001706 int i = val;
1707 bool has_audio;
1708
1709 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01001710 return 0;
1711
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001712 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01001713
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001714 if (i == 0)
1715 has_audio = intel_dp_detect_audio(connector);
1716 else
1717 has_audio = i > 0;
1718
1719 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01001720 return 0;
1721
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001722 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01001723 goto done;
1724 }
1725
Chris Wilsone953fd72011-02-21 22:23:52 +00001726 if (property == dev_priv->broadcast_rgb_property) {
1727 if (val == !!intel_dp->color_range)
1728 return 0;
1729
1730 intel_dp->color_range = val ? DP_COLOR_RANGE_16_235 : 0;
1731 goto done;
1732 }
1733
Chris Wilsonf6849602010-09-19 09:29:33 +01001734 return -EINVAL;
1735
1736done:
1737 if (intel_dp->base.base.crtc) {
1738 struct drm_crtc *crtc = intel_dp->base.base.crtc;
1739 drm_crtc_helper_set_mode(crtc, &crtc->mode,
1740 crtc->x, crtc->y,
1741 crtc->fb);
1742 }
1743
1744 return 0;
1745}
1746
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001747static void
1748intel_dp_destroy (struct drm_connector *connector)
1749{
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001750 drm_sysfs_connector_remove(connector);
1751 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08001752 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001753}
1754
Daniel Vetter24d05922010-08-20 18:08:28 +02001755static void intel_dp_encoder_destroy(struct drm_encoder *encoder)
1756{
1757 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1758
1759 i2c_del_adapter(&intel_dp->adapter);
1760 drm_encoder_cleanup(encoder);
1761 kfree(intel_dp);
1762}
1763
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001764static const struct drm_encoder_helper_funcs intel_dp_helper_funcs = {
1765 .dpms = intel_dp_dpms,
1766 .mode_fixup = intel_dp_mode_fixup,
Jesse Barnesd240f202010-08-13 15:43:26 -07001767 .prepare = intel_dp_prepare,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001768 .mode_set = intel_dp_mode_set,
Jesse Barnesd240f202010-08-13 15:43:26 -07001769 .commit = intel_dp_commit,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001770};
1771
1772static const struct drm_connector_funcs intel_dp_connector_funcs = {
1773 .dpms = drm_helper_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001774 .detect = intel_dp_detect,
1775 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01001776 .set_property = intel_dp_set_property,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001777 .destroy = intel_dp_destroy,
1778};
1779
1780static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
1781 .get_modes = intel_dp_get_modes,
1782 .mode_valid = intel_dp_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +01001783 .best_encoder = intel_best_encoder,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001784};
1785
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001786static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Daniel Vetter24d05922010-08-20 18:08:28 +02001787 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001788};
1789
Chris Wilson995b6762010-08-20 13:23:26 +01001790static void
Eric Anholt21d40d32010-03-25 11:11:14 -07001791intel_dp_hot_plug(struct intel_encoder *intel_encoder)
Keith Packardc8110e52009-05-06 11:51:10 -07001792{
Chris Wilsonea5b2132010-08-04 13:50:23 +01001793 struct intel_dp *intel_dp = container_of(intel_encoder, struct intel_dp, base);
Keith Packardc8110e52009-05-06 11:51:10 -07001794
Chris Wilsonea5b2132010-08-04 13:50:23 +01001795 if (intel_dp->dpms_mode == DRM_MODE_DPMS_ON)
1796 intel_dp_check_link_status(intel_dp);
Keith Packardc8110e52009-05-06 11:51:10 -07001797}
1798
Zhenyu Wange3421a12010-04-08 09:43:27 +08001799/* Return which DP Port should be selected for Transcoder DP control */
1800int
1801intel_trans_dp_port_sel (struct drm_crtc *crtc)
1802{
1803 struct drm_device *dev = crtc->dev;
1804 struct drm_mode_config *mode_config = &dev->mode_config;
1805 struct drm_encoder *encoder;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001806
1807 list_for_each_entry(encoder, &mode_config->encoder_list, head) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001808 struct intel_dp *intel_dp;
1809
Dan Carpenterd8201ab2010-05-07 10:39:00 +02001810 if (encoder->crtc != crtc)
Zhenyu Wange3421a12010-04-08 09:43:27 +08001811 continue;
1812
Chris Wilsonea5b2132010-08-04 13:50:23 +01001813 intel_dp = enc_to_intel_dp(encoder);
1814 if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT)
1815 return intel_dp->output_reg;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001816 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01001817
Zhenyu Wange3421a12010-04-08 09:43:27 +08001818 return -1;
1819}
1820
Zhao Yakui36e83a12010-06-12 14:32:21 +08001821/* check the VBT to see whether the eDP is on DP-D port */
Adam Jacksoncb0953d2010-07-16 14:46:29 -04001822bool intel_dpd_is_edp(struct drm_device *dev)
Zhao Yakui36e83a12010-06-12 14:32:21 +08001823{
1824 struct drm_i915_private *dev_priv = dev->dev_private;
1825 struct child_device_config *p_child;
1826 int i;
1827
1828 if (!dev_priv->child_dev_num)
1829 return false;
1830
1831 for (i = 0; i < dev_priv->child_dev_num; i++) {
1832 p_child = dev_priv->child_dev + i;
1833
1834 if (p_child->dvo_port == PORT_IDPD &&
1835 p_child->device_type == DEVICE_TYPE_eDP)
1836 return true;
1837 }
1838 return false;
1839}
1840
Chris Wilsonf6849602010-09-19 09:29:33 +01001841static void
1842intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
1843{
1844 struct drm_device *dev = connector->dev;
1845
1846 intel_dp->force_audio_property =
1847 drm_property_create(dev, DRM_MODE_PROP_RANGE, "force_audio", 2);
1848 if (intel_dp->force_audio_property) {
1849 intel_dp->force_audio_property->values[0] = -1;
1850 intel_dp->force_audio_property->values[1] = 1;
1851 drm_connector_attach_property(connector, intel_dp->force_audio_property, 0);
1852 }
Chris Wilsone953fd72011-02-21 22:23:52 +00001853
1854 intel_attach_broadcast_rgb_property(connector);
Chris Wilsonf6849602010-09-19 09:29:33 +01001855}
1856
Keith Packardc8110e52009-05-06 11:51:10 -07001857void
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001858intel_dp_init(struct drm_device *dev, int output_reg)
1859{
1860 struct drm_i915_private *dev_priv = dev->dev_private;
1861 struct drm_connector *connector;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001862 struct intel_dp *intel_dp;
Eric Anholt21d40d32010-03-25 11:11:14 -07001863 struct intel_encoder *intel_encoder;
Zhenyu Wang55f78c42010-03-29 16:13:57 +08001864 struct intel_connector *intel_connector;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001865 const char *name = NULL;
Adam Jacksonb3295302010-07-16 14:46:28 -04001866 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001867
Chris Wilsonea5b2132010-08-04 13:50:23 +01001868 intel_dp = kzalloc(sizeof(struct intel_dp), GFP_KERNEL);
1869 if (!intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001870 return;
1871
Chris Wilson3d3dc142011-02-12 10:33:12 +00001872 intel_dp->output_reg = output_reg;
1873 intel_dp->dpms_mode = -1;
1874
Zhenyu Wang55f78c42010-03-29 16:13:57 +08001875 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
1876 if (!intel_connector) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001877 kfree(intel_dp);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08001878 return;
1879 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01001880 intel_encoder = &intel_dp->base;
Zhenyu Wang55f78c42010-03-29 16:13:57 +08001881
Chris Wilsonea5b2132010-08-04 13:50:23 +01001882 if (HAS_PCH_SPLIT(dev) && output_reg == PCH_DP_D)
Adam Jacksonb3295302010-07-16 14:46:28 -04001883 if (intel_dpd_is_edp(dev))
Chris Wilsonea5b2132010-08-04 13:50:23 +01001884 intel_dp->is_pch_edp = true;
Adam Jacksonb3295302010-07-16 14:46:28 -04001885
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001886 if (output_reg == DP_A || is_pch_edp(intel_dp)) {
Adam Jacksonb3295302010-07-16 14:46:28 -04001887 type = DRM_MODE_CONNECTOR_eDP;
1888 intel_encoder->type = INTEL_OUTPUT_EDP;
1889 } else {
1890 type = DRM_MODE_CONNECTOR_DisplayPort;
1891 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
1892 }
1893
Zhenyu Wang55f78c42010-03-29 16:13:57 +08001894 connector = &intel_connector->base;
Adam Jacksonb3295302010-07-16 14:46:28 -04001895 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001896 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
1897
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001898 connector->polled = DRM_CONNECTOR_POLL_HPD;
1899
Zhao Yakui652af9d2009-12-02 10:03:33 +08001900 if (output_reg == DP_B || output_reg == PCH_DP_B)
Eric Anholt21d40d32010-03-25 11:11:14 -07001901 intel_encoder->clone_mask = (1 << INTEL_DP_B_CLONE_BIT);
Zhao Yakui652af9d2009-12-02 10:03:33 +08001902 else if (output_reg == DP_C || output_reg == PCH_DP_C)
Eric Anholt21d40d32010-03-25 11:11:14 -07001903 intel_encoder->clone_mask = (1 << INTEL_DP_C_CLONE_BIT);
Zhao Yakui652af9d2009-12-02 10:03:33 +08001904 else if (output_reg == DP_D || output_reg == PCH_DP_D)
Eric Anholt21d40d32010-03-25 11:11:14 -07001905 intel_encoder->clone_mask = (1 << INTEL_DP_D_CLONE_BIT);
Ma Lingf8aed702009-08-24 13:50:24 +08001906
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001907 if (is_edp(intel_dp))
Eric Anholt21d40d32010-03-25 11:11:14 -07001908 intel_encoder->clone_mask = (1 << INTEL_EDP_CLONE_BIT);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08001909
Eric Anholt21d40d32010-03-25 11:11:14 -07001910 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001911 connector->interlace_allowed = true;
1912 connector->doublescan_allowed = 0;
1913
Chris Wilson4ef69c72010-09-09 15:14:28 +01001914 drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001915 DRM_MODE_ENCODER_TMDS);
Chris Wilson4ef69c72010-09-09 15:14:28 +01001916 drm_encoder_helper_add(&intel_encoder->base, &intel_dp_helper_funcs);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001917
Chris Wilsondf0e9242010-09-09 16:20:55 +01001918 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001919 drm_sysfs_connector_add(connector);
1920
1921 /* Set up the DDC bus. */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001922 switch (output_reg) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001923 case DP_A:
1924 name = "DPDDC-A";
1925 break;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001926 case DP_B:
1927 case PCH_DP_B:
Jesse Barnesb01f2c32009-12-11 11:07:17 -08001928 dev_priv->hotplug_supported_mask |=
1929 HDMIB_HOTPLUG_INT_STATUS;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001930 name = "DPDDC-B";
1931 break;
1932 case DP_C:
1933 case PCH_DP_C:
Jesse Barnesb01f2c32009-12-11 11:07:17 -08001934 dev_priv->hotplug_supported_mask |=
1935 HDMIC_HOTPLUG_INT_STATUS;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001936 name = "DPDDC-C";
1937 break;
1938 case DP_D:
1939 case PCH_DP_D:
Jesse Barnesb01f2c32009-12-11 11:07:17 -08001940 dev_priv->hotplug_supported_mask |=
1941 HDMID_HOTPLUG_INT_STATUS;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001942 name = "DPDDC-D";
1943 break;
1944 }
1945
Chris Wilsonea5b2132010-08-04 13:50:23 +01001946 intel_dp_i2c_init(intel_dp, intel_connector, name);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001947
Jesse Barnes89667382010-10-07 16:01:21 -07001948 /* Cache some DPCD data in the eDP case */
1949 if (is_edp(intel_dp)) {
1950 int ret;
Jesse Barnes5d613502011-01-24 17:10:54 -08001951 u32 pp_on, pp_div;
Jesse Barnes89667382010-10-07 16:01:21 -07001952
Jesse Barnes5d613502011-01-24 17:10:54 -08001953 pp_on = I915_READ(PCH_PP_ON_DELAYS);
1954 pp_div = I915_READ(PCH_PP_DIVISOR);
1955
1956 /* Get T3 & T12 values (note: VESA not bspec terminology) */
1957 dev_priv->panel_t3 = (pp_on & 0x1fff0000) >> 16;
1958 dev_priv->panel_t3 /= 10; /* t3 in 100us units */
1959 dev_priv->panel_t12 = pp_div & 0xf;
1960 dev_priv->panel_t12 *= 100; /* t12 in 100ms units */
1961
1962 ironlake_edp_panel_vdd_on(intel_dp);
Jesse Barnes89667382010-10-07 16:01:21 -07001963 ret = intel_dp_aux_native_read(intel_dp, DP_DPCD_REV,
1964 intel_dp->dpcd,
1965 sizeof(intel_dp->dpcd));
Chris Wilson3d3dc142011-02-12 10:33:12 +00001966 ironlake_edp_panel_vdd_off(intel_dp);
Jesse Barnes89667382010-10-07 16:01:21 -07001967 if (ret == sizeof(intel_dp->dpcd)) {
1968 if (intel_dp->dpcd[0] >= 0x11)
1969 dev_priv->no_aux_handshake = intel_dp->dpcd[3] &
1970 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
1971 } else {
Chris Wilson3d3dc142011-02-12 10:33:12 +00001972 /* if this fails, presume the device is a ghost */
Takashi Iwai48898b02011-03-18 09:06:49 +00001973 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Chris Wilson3d3dc142011-02-12 10:33:12 +00001974 intel_dp_encoder_destroy(&intel_dp->base.base);
Takashi Iwai48898b02011-03-18 09:06:49 +00001975 intel_dp_destroy(&intel_connector->base);
Chris Wilson3d3dc142011-02-12 10:33:12 +00001976 return;
Jesse Barnes89667382010-10-07 16:01:21 -07001977 }
Jesse Barnes89667382010-10-07 16:01:21 -07001978 }
1979
Eric Anholt21d40d32010-03-25 11:11:14 -07001980 intel_encoder->hot_plug = intel_dp_hot_plug;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001981
Jesse Barnes4d926462010-10-07 16:01:07 -07001982 if (is_edp(intel_dp)) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001983 /* initialize panel mode from VBT if available for eDP */
1984 if (dev_priv->lfp_lvds_vbt_mode) {
1985 dev_priv->panel_fixed_mode =
1986 drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);
1987 if (dev_priv->panel_fixed_mode) {
1988 dev_priv->panel_fixed_mode->type |=
1989 DRM_MODE_TYPE_PREFERRED;
1990 }
1991 }
1992 }
1993
Chris Wilsonf6849602010-09-19 09:29:33 +01001994 intel_dp_add_properties(intel_dp, connector);
1995
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001996 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
1997 * 0xd. Failure to do so will result in spurious interrupts being
1998 * generated on the port when a cable is not attached.
1999 */
2000 if (IS_G4X(dev) && !IS_GM45(dev)) {
2001 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
2002 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
2003 }
2004}