blob: c4c5868a8aa07b686c561c1d4076500a7cf0efc5 [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 +010045#define IS_eDP(i) ((i)->base.type == INTEL_OUTPUT_EDP)
46#define IS_PCH_eDP(i) ((i)->is_pch_edp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +080047
Chris Wilsonea5b2132010-08-04 13:50:23 +010048struct intel_dp {
49 struct intel_encoder base;
Keith Packarda4fc5ed2009-04-07 16:16:42 -070050 uint32_t output_reg;
51 uint32_t DP;
52 uint8_t link_configuration[DP_LINK_CONFIGURATION_SIZE];
Keith Packarda4fc5ed2009-04-07 16:16:42 -070053 bool has_audio;
Keith Packardc8110e52009-05-06 11:51:10 -070054 int dpms_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -070055 uint8_t link_bw;
56 uint8_t lane_count;
57 uint8_t dpcd[4];
Keith Packarda4fc5ed2009-04-07 16:16:42 -070058 struct i2c_adapter adapter;
59 struct i2c_algo_dp_aux_data algo;
Adam Jacksonf0917372010-07-16 14:46:27 -040060 bool is_pch_edp;
Keith Packarda4fc5ed2009-04-07 16:16:42 -070061};
62
Chris Wilsonea5b2132010-08-04 13:50:23 +010063static struct intel_dp *enc_to_intel_dp(struct drm_encoder *encoder)
64{
65 return container_of(enc_to_intel_encoder(encoder), struct intel_dp, base);
66}
Keith Packarda4fc5ed2009-04-07 16:16:42 -070067
Chris Wilsonea5b2132010-08-04 13:50:23 +010068static void intel_dp_link_train(struct intel_dp *intel_dp);
69static void intel_dp_link_down(struct intel_dp *intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -070070
Zhenyu Wang32f9d652009-07-24 01:00:32 +080071void
Eric Anholt21d40d32010-03-25 11:11:14 -070072intel_edp_link_config (struct intel_encoder *intel_encoder,
Chris Wilsonea5b2132010-08-04 13:50:23 +010073 int *lane_num, int *link_bw)
Zhenyu Wang32f9d652009-07-24 01:00:32 +080074{
Chris Wilsonea5b2132010-08-04 13:50:23 +010075 struct intel_dp *intel_dp = container_of(intel_encoder, struct intel_dp, base);
Zhenyu Wang32f9d652009-07-24 01:00:32 +080076
Chris Wilsonea5b2132010-08-04 13:50:23 +010077 *lane_num = intel_dp->lane_count;
78 if (intel_dp->link_bw == DP_LINK_BW_1_62)
Zhenyu Wang32f9d652009-07-24 01:00:32 +080079 *link_bw = 162000;
Chris Wilsonea5b2132010-08-04 13:50:23 +010080 else if (intel_dp->link_bw == DP_LINK_BW_2_7)
Zhenyu Wang32f9d652009-07-24 01:00:32 +080081 *link_bw = 270000;
82}
83
Keith Packarda4fc5ed2009-04-07 16:16:42 -070084static int
Chris Wilsonea5b2132010-08-04 13:50:23 +010085intel_dp_max_lane_count(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -070086{
Keith Packarda4fc5ed2009-04-07 16:16:42 -070087 int max_lane_count = 4;
88
Chris Wilsonea5b2132010-08-04 13:50:23 +010089 if (intel_dp->dpcd[0] >= 0x11) {
90 max_lane_count = intel_dp->dpcd[2] & 0x1f;
Keith Packarda4fc5ed2009-04-07 16:16:42 -070091 switch (max_lane_count) {
92 case 1: case 2: case 4:
93 break;
94 default:
95 max_lane_count = 4;
96 }
97 }
98 return max_lane_count;
99}
100
101static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100102intel_dp_max_link_bw(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700103{
Chris Wilsonea5b2132010-08-04 13:50:23 +0100104 int max_link_bw = intel_dp->dpcd[1];
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700105
106 switch (max_link_bw) {
107 case DP_LINK_BW_1_62:
108 case DP_LINK_BW_2_7:
109 break;
110 default:
111 max_link_bw = DP_LINK_BW_1_62;
112 break;
113 }
114 return max_link_bw;
115}
116
117static int
118intel_dp_link_clock(uint8_t link_bw)
119{
120 if (link_bw == DP_LINK_BW_2_7)
121 return 270000;
122 else
123 return 162000;
124}
125
126/* I think this is a fiction */
127static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100128intel_dp_link_required(struct drm_device *dev, struct intel_dp *intel_dp, int pixel_clock)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700129{
Zhenyu Wang885a5fb2010-01-12 05:38:31 +0800130 struct drm_i915_private *dev_priv = dev->dev_private;
131
Chris Wilsonea5b2132010-08-04 13:50:23 +0100132 if (IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp))
Zhenyu Wang885a5fb2010-01-12 05:38:31 +0800133 return (pixel_clock * dev_priv->edp_bpp) / 8;
134 else
135 return pixel_clock * 3;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700136}
137
138static int
Dave Airliefe27d532010-06-30 11:46:17 +1000139intel_dp_max_data_rate(int max_link_clock, int max_lanes)
140{
141 return (max_link_clock * max_lanes * 8) / 10;
142}
143
144static int
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700145intel_dp_mode_valid(struct drm_connector *connector,
146 struct drm_display_mode *mode)
147{
Zhenyu Wang55f78c42010-03-29 16:13:57 +0800148 struct drm_encoder *encoder = intel_attached_encoder(connector);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100149 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Zhao Yakui7de56f42010-07-19 09:43:14 +0100150 struct drm_device *dev = connector->dev;
151 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100152 int max_link_clock = intel_dp_link_clock(intel_dp_max_link_bw(intel_dp));
153 int max_lanes = intel_dp_max_lane_count(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700154
Chris Wilsonea5b2132010-08-04 13:50:23 +0100155 if ((IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) &&
Zhao Yakui7de56f42010-07-19 09:43:14 +0100156 dev_priv->panel_fixed_mode) {
157 if (mode->hdisplay > dev_priv->panel_fixed_mode->hdisplay)
158 return MODE_PANEL;
159
160 if (mode->vdisplay > dev_priv->panel_fixed_mode->vdisplay)
161 return MODE_PANEL;
162 }
163
Dave Airliefe27d532010-06-30 11:46:17 +1000164 /* only refuse the mode on non eDP since we have seen some wierd eDP panels
165 which are outside spec tolerances but somehow work by magic */
Chris Wilsonea5b2132010-08-04 13:50:23 +0100166 if (!IS_eDP(intel_dp) &&
167 (intel_dp_link_required(connector->dev, intel_dp, mode->clock)
Dave Airliefe27d532010-06-30 11:46:17 +1000168 > intel_dp_max_data_rate(max_link_clock, max_lanes)))
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700169 return MODE_CLOCK_HIGH;
170
171 if (mode->clock < 10000)
172 return MODE_CLOCK_LOW;
173
174 return MODE_OK;
175}
176
177static uint32_t
178pack_aux(uint8_t *src, int src_bytes)
179{
180 int i;
181 uint32_t v = 0;
182
183 if (src_bytes > 4)
184 src_bytes = 4;
185 for (i = 0; i < src_bytes; i++)
186 v |= ((uint32_t) src[i]) << ((3-i) * 8);
187 return v;
188}
189
190static void
191unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
192{
193 int i;
194 if (dst_bytes > 4)
195 dst_bytes = 4;
196 for (i = 0; i < dst_bytes; i++)
197 dst[i] = src >> ((3-i) * 8);
198}
199
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700200/* hrawclock is 1/4 the FSB frequency */
201static int
202intel_hrawclk(struct drm_device *dev)
203{
204 struct drm_i915_private *dev_priv = dev->dev_private;
205 uint32_t clkcfg;
206
207 clkcfg = I915_READ(CLKCFG);
208 switch (clkcfg & CLKCFG_FSB_MASK) {
209 case CLKCFG_FSB_400:
210 return 100;
211 case CLKCFG_FSB_533:
212 return 133;
213 case CLKCFG_FSB_667:
214 return 166;
215 case CLKCFG_FSB_800:
216 return 200;
217 case CLKCFG_FSB_1067:
218 return 266;
219 case CLKCFG_FSB_1333:
220 return 333;
221 /* these two are just a guess; one of them might be right */
222 case CLKCFG_FSB_1600:
223 case CLKCFG_FSB_1600_ALT:
224 return 400;
225 default:
226 return 133;
227 }
228}
229
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700230static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100231intel_dp_aux_ch(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700232 uint8_t *send, int send_bytes,
233 uint8_t *recv, int recv_size)
234{
Chris Wilsonea5b2132010-08-04 13:50:23 +0100235 uint32_t output_reg = intel_dp->output_reg;
236 struct drm_device *dev = intel_dp->base.enc.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700237 struct drm_i915_private *dev_priv = dev->dev_private;
238 uint32_t ch_ctl = output_reg + 0x10;
239 uint32_t ch_data = ch_ctl + 4;
240 int i;
241 int recv_bytes;
242 uint32_t ctl;
243 uint32_t status;
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700244 uint32_t aux_clock_divider;
Zhenyu Wange3421a12010-04-08 09:43:27 +0800245 int try, precharge;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700246
247 /* The clock divider is based off the hrawclk,
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700248 * and would like to run at 2MHz. So, take the
249 * hrawclk value and divide by 2 and use that
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700250 */
Chris Wilsonea5b2132010-08-04 13:50:23 +0100251 if (IS_eDP(intel_dp)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +0800252 if (IS_GEN6(dev))
253 aux_clock_divider = 200; /* SNB eDP input clock at 400Mhz */
254 else
255 aux_clock_divider = 225; /* eDP input clock at 450Mhz */
256 } else if (HAS_PCH_SPLIT(dev))
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500257 aux_clock_divider = 62; /* IRL input clock fixed at 125Mhz */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +0800258 else
259 aux_clock_divider = intel_hrawclk(dev) / 2;
260
Zhenyu Wange3421a12010-04-08 09:43:27 +0800261 if (IS_GEN6(dev))
262 precharge = 3;
263 else
264 precharge = 5;
265
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700266 /* Must try at least 3 times according to DP spec */
267 for (try = 0; try < 5; try++) {
268 /* Load the send data into the aux channel data registers */
269 for (i = 0; i < send_bytes; i += 4) {
Joe Perchesa419aef2009-08-18 11:18:35 -0700270 uint32_t d = pack_aux(send + i, send_bytes - i);
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700271
272 I915_WRITE(ch_data + i, d);
273 }
274
275 ctl = (DP_AUX_CH_CTL_SEND_BUSY |
276 DP_AUX_CH_CTL_TIME_OUT_400us |
277 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Zhenyu Wange3421a12010-04-08 09:43:27 +0800278 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700279 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT) |
280 DP_AUX_CH_CTL_DONE |
281 DP_AUX_CH_CTL_TIME_OUT_ERROR |
282 DP_AUX_CH_CTL_RECEIVE_ERROR);
283
284 /* Send the command and wait for it to complete */
285 I915_WRITE(ch_ctl, ctl);
286 (void) I915_READ(ch_ctl);
287 for (;;) {
288 udelay(100);
289 status = I915_READ(ch_ctl);
290 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
291 break;
292 }
293
294 /* Clear done status and any errors */
Zhenyu Wangeebc8632009-07-24 01:00:30 +0800295 I915_WRITE(ch_ctl, (status |
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700296 DP_AUX_CH_CTL_DONE |
297 DP_AUX_CH_CTL_TIME_OUT_ERROR |
298 DP_AUX_CH_CTL_RECEIVE_ERROR));
299 (void) I915_READ(ch_ctl);
300 if ((status & DP_AUX_CH_CTL_TIME_OUT_ERROR) == 0)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700301 break;
302 }
303
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700304 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700305 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Keith Packarda5b3da52009-06-11 22:30:32 -0700306 return -EBUSY;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700307 }
308
309 /* Check for timeout or receive error.
310 * Timeouts occur when the sink is not connected
311 */
Keith Packarda5b3da52009-06-11 22:30:32 -0700312 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700313 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Keith Packarda5b3da52009-06-11 22:30:32 -0700314 return -EIO;
315 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700316
317 /* Timeouts occur when the device isn't connected, so they're
318 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -0700319 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Zhao Yakui28c97732009-10-09 11:39:41 +0800320 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Keith Packarda5b3da52009-06-11 22:30:32 -0700321 return -ETIMEDOUT;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700322 }
323
324 /* Unload any bytes sent back from the other side */
325 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
326 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
327
328 if (recv_bytes > recv_size)
329 recv_bytes = recv_size;
330
331 for (i = 0; i < recv_bytes; i += 4) {
332 uint32_t d = I915_READ(ch_data + i);
333
334 unpack_aux(d, recv + i, recv_bytes - i);
335 }
336
337 return recv_bytes;
338}
339
340/* Write data to the aux channel in native mode */
341static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100342intel_dp_aux_native_write(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700343 uint16_t address, uint8_t *send, int send_bytes)
344{
345 int ret;
346 uint8_t msg[20];
347 int msg_bytes;
348 uint8_t ack;
349
350 if (send_bytes > 16)
351 return -1;
352 msg[0] = AUX_NATIVE_WRITE << 4;
353 msg[1] = address >> 8;
Zhenyu Wangeebc8632009-07-24 01:00:30 +0800354 msg[2] = address & 0xff;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700355 msg[3] = send_bytes - 1;
356 memcpy(&msg[4], send, send_bytes);
357 msg_bytes = send_bytes + 4;
358 for (;;) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100359 ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes, &ack, 1);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700360 if (ret < 0)
361 return ret;
362 if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK)
363 break;
364 else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
365 udelay(100);
366 else
Keith Packarda5b3da52009-06-11 22:30:32 -0700367 return -EIO;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700368 }
369 return send_bytes;
370}
371
372/* Write a single byte to the aux channel in native mode */
373static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100374intel_dp_aux_native_write_1(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700375 uint16_t address, uint8_t byte)
376{
Chris Wilsonea5b2132010-08-04 13:50:23 +0100377 return intel_dp_aux_native_write(intel_dp, address, &byte, 1);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700378}
379
380/* read bytes from a native aux channel */
381static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100382intel_dp_aux_native_read(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700383 uint16_t address, uint8_t *recv, int recv_bytes)
384{
385 uint8_t msg[4];
386 int msg_bytes;
387 uint8_t reply[20];
388 int reply_bytes;
389 uint8_t ack;
390 int ret;
391
392 msg[0] = AUX_NATIVE_READ << 4;
393 msg[1] = address >> 8;
394 msg[2] = address & 0xff;
395 msg[3] = recv_bytes - 1;
396
397 msg_bytes = 4;
398 reply_bytes = recv_bytes + 1;
399
400 for (;;) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100401 ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700402 reply, reply_bytes);
Keith Packarda5b3da52009-06-11 22:30:32 -0700403 if (ret == 0)
404 return -EPROTO;
405 if (ret < 0)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700406 return ret;
407 ack = reply[0];
408 if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK) {
409 memcpy(recv, reply + 1, ret - 1);
410 return ret - 1;
411 }
412 else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
413 udelay(100);
414 else
Keith Packarda5b3da52009-06-11 22:30:32 -0700415 return -EIO;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700416 }
417}
418
419static int
Dave Airlieab2c0672009-12-04 10:55:24 +1000420intel_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode,
421 uint8_t write_byte, uint8_t *read_byte)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700422{
Dave Airlieab2c0672009-12-04 10:55:24 +1000423 struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100424 struct intel_dp *intel_dp = container_of(adapter,
425 struct intel_dp,
426 adapter);
Dave Airlieab2c0672009-12-04 10:55:24 +1000427 uint16_t address = algo_data->address;
428 uint8_t msg[5];
429 uint8_t reply[2];
430 int msg_bytes;
431 int reply_bytes;
432 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700433
Dave Airlieab2c0672009-12-04 10:55:24 +1000434 /* Set up the command byte */
435 if (mode & MODE_I2C_READ)
436 msg[0] = AUX_I2C_READ << 4;
437 else
438 msg[0] = AUX_I2C_WRITE << 4;
439
440 if (!(mode & MODE_I2C_STOP))
441 msg[0] |= AUX_I2C_MOT << 4;
442
443 msg[1] = address >> 8;
444 msg[2] = address;
445
446 switch (mode) {
447 case MODE_I2C_WRITE:
448 msg[3] = 0;
449 msg[4] = write_byte;
450 msg_bytes = 5;
451 reply_bytes = 1;
452 break;
453 case MODE_I2C_READ:
454 msg[3] = 0;
455 msg_bytes = 4;
456 reply_bytes = 2;
457 break;
458 default:
459 msg_bytes = 3;
460 reply_bytes = 1;
461 break;
462 }
463
464 for (;;) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100465 ret = intel_dp_aux_ch(intel_dp,
Dave Airlieab2c0672009-12-04 10:55:24 +1000466 msg, msg_bytes,
467 reply, reply_bytes);
468 if (ret < 0) {
Dave Airlie3ff99162009-12-08 14:03:47 +1000469 DRM_DEBUG_KMS("aux_ch failed %d\n", ret);
Dave Airlieab2c0672009-12-04 10:55:24 +1000470 return ret;
471 }
472 switch (reply[0] & AUX_I2C_REPLY_MASK) {
473 case AUX_I2C_REPLY_ACK:
474 if (mode == MODE_I2C_READ) {
475 *read_byte = reply[1];
476 }
477 return reply_bytes - 1;
478 case AUX_I2C_REPLY_NACK:
Dave Airlie3ff99162009-12-08 14:03:47 +1000479 DRM_DEBUG_KMS("aux_ch nack\n");
Dave Airlieab2c0672009-12-04 10:55:24 +1000480 return -EREMOTEIO;
481 case AUX_I2C_REPLY_DEFER:
Dave Airlie3ff99162009-12-08 14:03:47 +1000482 DRM_DEBUG_KMS("aux_ch defer\n");
Dave Airlieab2c0672009-12-04 10:55:24 +1000483 udelay(100);
484 break;
485 default:
486 DRM_ERROR("aux_ch invalid reply 0x%02x\n", reply[0]);
487 return -EREMOTEIO;
488 }
489 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700490}
491
492static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100493intel_dp_i2c_init(struct intel_dp *intel_dp,
Zhenyu Wang55f78c42010-03-29 16:13:57 +0800494 struct intel_connector *intel_connector, const char *name)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700495{
Zhenyu Wangd54e9d22009-10-19 15:43:51 +0800496 DRM_DEBUG_KMS("i2c_init %s\n", name);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100497 intel_dp->algo.running = false;
498 intel_dp->algo.address = 0;
499 intel_dp->algo.aux_ch = intel_dp_i2c_aux_ch;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700500
Chris Wilsonea5b2132010-08-04 13:50:23 +0100501 memset(&intel_dp->adapter, '\0', sizeof (intel_dp->adapter));
502 intel_dp->adapter.owner = THIS_MODULE;
503 intel_dp->adapter.class = I2C_CLASS_DDC;
504 strncpy (intel_dp->adapter.name, name, sizeof(intel_dp->adapter.name) - 1);
505 intel_dp->adapter.name[sizeof(intel_dp->adapter.name) - 1] = '\0';
506 intel_dp->adapter.algo_data = &intel_dp->algo;
507 intel_dp->adapter.dev.parent = &intel_connector->base.kdev;
508
509 return i2c_dp_aux_add_bus(&intel_dp->adapter);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700510}
511
512static bool
513intel_dp_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode,
514 struct drm_display_mode *adjusted_mode)
515{
Zhao Yakui0d3a1be2010-07-19 09:43:13 +0100516 struct drm_device *dev = encoder->dev;
517 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100518 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700519 int lane_count, clock;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100520 int max_lane_count = intel_dp_max_lane_count(intel_dp);
521 int max_clock = intel_dp_max_link_bw(intel_dp) == DP_LINK_BW_2_7 ? 1 : 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700522 static int bws[2] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7 };
523
Chris Wilsonea5b2132010-08-04 13:50:23 +0100524 if ((IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) &&
Zhao Yakui0d3a1be2010-07-19 09:43:13 +0100525 dev_priv->panel_fixed_mode) {
526 struct drm_display_mode *fixed_mode = dev_priv->panel_fixed_mode;
527
528 adjusted_mode->hdisplay = fixed_mode->hdisplay;
529 adjusted_mode->hsync_start = fixed_mode->hsync_start;
530 adjusted_mode->hsync_end = fixed_mode->hsync_end;
531 adjusted_mode->htotal = fixed_mode->htotal;
532
533 adjusted_mode->vdisplay = fixed_mode->vdisplay;
534 adjusted_mode->vsync_start = fixed_mode->vsync_start;
535 adjusted_mode->vsync_end = fixed_mode->vsync_end;
536 adjusted_mode->vtotal = fixed_mode->vtotal;
537
538 adjusted_mode->clock = fixed_mode->clock;
539 drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V);
540
541 /*
542 * the mode->clock is used to calculate the Data&Link M/N
543 * of the pipe. For the eDP the fixed clock should be used.
544 */
545 mode->clock = dev_priv->panel_fixed_mode->clock;
546 }
547
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700548 for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) {
549 for (clock = 0; clock <= max_clock; clock++) {
Dave Airliefe27d532010-06-30 11:46:17 +1000550 int link_avail = intel_dp_max_data_rate(intel_dp_link_clock(bws[clock]), lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700551
Chris Wilsonea5b2132010-08-04 13:50:23 +0100552 if (intel_dp_link_required(encoder->dev, intel_dp, mode->clock)
Zhenyu Wang885a5fb2010-01-12 05:38:31 +0800553 <= link_avail) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100554 intel_dp->link_bw = bws[clock];
555 intel_dp->lane_count = lane_count;
556 adjusted_mode->clock = intel_dp_link_clock(intel_dp->link_bw);
Zhao Yakui28c97732009-10-09 11:39:41 +0800557 DRM_DEBUG_KMS("Display port link bw %02x lane "
558 "count %d clock %d\n",
Chris Wilsonea5b2132010-08-04 13:50:23 +0100559 intel_dp->link_bw, intel_dp->lane_count,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700560 adjusted_mode->clock);
561 return true;
562 }
563 }
564 }
Dave Airliefe27d532010-06-30 11:46:17 +1000565
Chris Wilsonea5b2132010-08-04 13:50:23 +0100566 if (IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) {
Dave Airliefe27d532010-06-30 11:46:17 +1000567 /* okay we failed just pick the highest */
Chris Wilsonea5b2132010-08-04 13:50:23 +0100568 intel_dp->lane_count = max_lane_count;
569 intel_dp->link_bw = bws[max_clock];
570 adjusted_mode->clock = intel_dp_link_clock(intel_dp->link_bw);
Dave Airliefe27d532010-06-30 11:46:17 +1000571 DRM_DEBUG_KMS("Force picking display port link bw %02x lane "
572 "count %d clock %d\n",
Chris Wilsonea5b2132010-08-04 13:50:23 +0100573 intel_dp->link_bw, intel_dp->lane_count,
Dave Airliefe27d532010-06-30 11:46:17 +1000574 adjusted_mode->clock);
575 return true;
576 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700577 return false;
578}
579
580struct intel_dp_m_n {
581 uint32_t tu;
582 uint32_t gmch_m;
583 uint32_t gmch_n;
584 uint32_t link_m;
585 uint32_t link_n;
586};
587
588static void
589intel_reduce_ratio(uint32_t *num, uint32_t *den)
590{
591 while (*num > 0xffffff || *den > 0xffffff) {
592 *num >>= 1;
593 *den >>= 1;
594 }
595}
596
597static void
Zhao Yakui36e83a12010-06-12 14:32:21 +0800598intel_dp_compute_m_n(int bpp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700599 int nlanes,
600 int pixel_clock,
601 int link_clock,
602 struct intel_dp_m_n *m_n)
603{
604 m_n->tu = 64;
Zhao Yakui36e83a12010-06-12 14:32:21 +0800605 m_n->gmch_m = (pixel_clock * bpp) >> 3;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700606 m_n->gmch_n = link_clock * nlanes;
607 intel_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
608 m_n->link_m = pixel_clock;
609 m_n->link_n = link_clock;
610 intel_reduce_ratio(&m_n->link_m, &m_n->link_n);
611}
612
Zhao Yakui36e83a12010-06-12 14:32:21 +0800613bool intel_pch_has_edp(struct drm_crtc *crtc)
614{
615 struct drm_device *dev = crtc->dev;
616 struct drm_mode_config *mode_config = &dev->mode_config;
617 struct drm_encoder *encoder;
618
619 list_for_each_entry(encoder, &mode_config->encoder_list, head) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100620 struct intel_dp *intel_dp;
Zhao Yakui36e83a12010-06-12 14:32:21 +0800621
Chris Wilsonea5b2132010-08-04 13:50:23 +0100622 if (encoder->crtc != crtc)
Zhao Yakui36e83a12010-06-12 14:32:21 +0800623 continue;
624
Chris Wilsonea5b2132010-08-04 13:50:23 +0100625 intel_dp = enc_to_intel_dp(encoder);
626 if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT)
627 return intel_dp->is_pch_edp;
Zhao Yakui36e83a12010-06-12 14:32:21 +0800628 }
629 return false;
630}
631
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700632void
633intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode,
634 struct drm_display_mode *adjusted_mode)
635{
636 struct drm_device *dev = crtc->dev;
637 struct drm_mode_config *mode_config = &dev->mode_config;
Zhenyu Wang55f78c42010-03-29 16:13:57 +0800638 struct drm_encoder *encoder;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700639 struct drm_i915_private *dev_priv = dev->dev_private;
640 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Zhao Yakui36e83a12010-06-12 14:32:21 +0800641 int lane_count = 4, bpp = 24;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700642 struct intel_dp_m_n m_n;
643
644 /*
Eric Anholt21d40d32010-03-25 11:11:14 -0700645 * Find the lane count in the intel_encoder private
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700646 */
Zhenyu Wang55f78c42010-03-29 16:13:57 +0800647 list_for_each_entry(encoder, &mode_config->encoder_list, head) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100648 struct intel_dp *intel_dp;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700649
Dan Carpenterd8201ab2010-05-07 10:39:00 +0200650 if (encoder->crtc != crtc)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700651 continue;
652
Chris Wilsonea5b2132010-08-04 13:50:23 +0100653 intel_dp = enc_to_intel_dp(encoder);
654 if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT) {
655 lane_count = intel_dp->lane_count;
656 if (IS_PCH_eDP(intel_dp))
Zhao Yakui36e83a12010-06-12 14:32:21 +0800657 bpp = dev_priv->edp_bpp;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700658 break;
659 }
660 }
661
662 /*
663 * Compute the GMCH and Link ratios. The '3' here is
664 * the number of bytes_per_pixel post-LUT, which we always
665 * set up for 8-bits of R/G/B, or 3 bytes total.
666 */
Zhao Yakui36e83a12010-06-12 14:32:21 +0800667 intel_dp_compute_m_n(bpp, lane_count,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700668 mode->clock, adjusted_mode->clock, &m_n);
669
Eric Anholtc619eed2010-01-28 16:45:52 -0800670 if (HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5eb08b62009-07-24 01:00:31 +0800671 if (intel_crtc->pipe == 0) {
672 I915_WRITE(TRANSA_DATA_M1,
673 ((m_n.tu - 1) << PIPE_GMCH_DATA_M_TU_SIZE_SHIFT) |
674 m_n.gmch_m);
675 I915_WRITE(TRANSA_DATA_N1, m_n.gmch_n);
676 I915_WRITE(TRANSA_DP_LINK_M1, m_n.link_m);
677 I915_WRITE(TRANSA_DP_LINK_N1, m_n.link_n);
678 } else {
679 I915_WRITE(TRANSB_DATA_M1,
680 ((m_n.tu - 1) << PIPE_GMCH_DATA_M_TU_SIZE_SHIFT) |
681 m_n.gmch_m);
682 I915_WRITE(TRANSB_DATA_N1, m_n.gmch_n);
683 I915_WRITE(TRANSB_DP_LINK_M1, m_n.link_m);
684 I915_WRITE(TRANSB_DP_LINK_N1, m_n.link_n);
685 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700686 } else {
Zhenyu Wang5eb08b62009-07-24 01:00:31 +0800687 if (intel_crtc->pipe == 0) {
688 I915_WRITE(PIPEA_GMCH_DATA_M,
689 ((m_n.tu - 1) << PIPE_GMCH_DATA_M_TU_SIZE_SHIFT) |
690 m_n.gmch_m);
691 I915_WRITE(PIPEA_GMCH_DATA_N,
692 m_n.gmch_n);
693 I915_WRITE(PIPEA_DP_LINK_M, m_n.link_m);
694 I915_WRITE(PIPEA_DP_LINK_N, m_n.link_n);
695 } else {
696 I915_WRITE(PIPEB_GMCH_DATA_M,
697 ((m_n.tu - 1) << PIPE_GMCH_DATA_M_TU_SIZE_SHIFT) |
698 m_n.gmch_m);
699 I915_WRITE(PIPEB_GMCH_DATA_N,
700 m_n.gmch_n);
701 I915_WRITE(PIPEB_DP_LINK_M, m_n.link_m);
702 I915_WRITE(PIPEB_DP_LINK_N, m_n.link_n);
703 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700704 }
705}
706
707static void
708intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
709 struct drm_display_mode *adjusted_mode)
710{
Zhenyu Wange3421a12010-04-08 09:43:27 +0800711 struct drm_device *dev = encoder->dev;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100712 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
713 struct drm_crtc *crtc = intel_dp->base.enc.crtc;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700714 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
715
Chris Wilsonea5b2132010-08-04 13:50:23 +0100716 intel_dp->DP = (DP_VOLTAGE_0_4 |
Adam Jackson9c9e7922010-04-05 17:57:59 -0400717 DP_PRE_EMPHASIS_0);
718
719 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
Chris Wilsonea5b2132010-08-04 13:50:23 +0100720 intel_dp->DP |= DP_SYNC_HS_HIGH;
Adam Jackson9c9e7922010-04-05 17:57:59 -0400721 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
Chris Wilsonea5b2132010-08-04 13:50:23 +0100722 intel_dp->DP |= DP_SYNC_VS_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700723
Chris Wilsonea5b2132010-08-04 13:50:23 +0100724 if (HAS_PCH_CPT(dev) && !IS_eDP(intel_dp))
725 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +0800726 else
Chris Wilsonea5b2132010-08-04 13:50:23 +0100727 intel_dp->DP |= DP_LINK_TRAIN_OFF;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700728
Chris Wilsonea5b2132010-08-04 13:50:23 +0100729 switch (intel_dp->lane_count) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700730 case 1:
Chris Wilsonea5b2132010-08-04 13:50:23 +0100731 intel_dp->DP |= DP_PORT_WIDTH_1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700732 break;
733 case 2:
Chris Wilsonea5b2132010-08-04 13:50:23 +0100734 intel_dp->DP |= DP_PORT_WIDTH_2;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700735 break;
736 case 4:
Chris Wilsonea5b2132010-08-04 13:50:23 +0100737 intel_dp->DP |= DP_PORT_WIDTH_4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700738 break;
739 }
Chris Wilsonea5b2132010-08-04 13:50:23 +0100740 if (intel_dp->has_audio)
741 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700742
Chris Wilsonea5b2132010-08-04 13:50:23 +0100743 memset(intel_dp->link_configuration, 0, DP_LINK_CONFIGURATION_SIZE);
744 intel_dp->link_configuration[0] = intel_dp->link_bw;
745 intel_dp->link_configuration[1] = intel_dp->lane_count;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700746
747 /*
Adam Jackson9962c922010-05-13 14:45:42 -0400748 * Check for DPCD version > 1.1 and enhanced framing support
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700749 */
Chris Wilsonea5b2132010-08-04 13:50:23 +0100750 if (intel_dp->dpcd[0] >= 0x11 && (intel_dp->dpcd[2] & DP_ENHANCED_FRAME_CAP)) {
751 intel_dp->link_configuration[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
752 intel_dp->DP |= DP_ENHANCED_FRAMING;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700753 }
754
Zhenyu Wange3421a12010-04-08 09:43:27 +0800755 /* CPT DP's pipe select is decided in TRANS_DP_CTL */
756 if (intel_crtc->pipe == 1 && !HAS_PCH_CPT(dev))
Chris Wilsonea5b2132010-08-04 13:50:23 +0100757 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800758
Chris Wilsonea5b2132010-08-04 13:50:23 +0100759 if (IS_eDP(intel_dp)) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800760 /* don't miss out required setting for eDP */
Chris Wilsonea5b2132010-08-04 13:50:23 +0100761 intel_dp->DP |= DP_PLL_ENABLE;
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800762 if (adjusted_mode->clock < 200000)
Chris Wilsonea5b2132010-08-04 13:50:23 +0100763 intel_dp->DP |= DP_PLL_FREQ_160MHZ;
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800764 else
Chris Wilsonea5b2132010-08-04 13:50:23 +0100765 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800766 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700767}
768
Jesse Barnes9934c132010-07-22 13:18:19 -0700769static void ironlake_edp_panel_on (struct drm_device *dev)
770{
771 struct drm_i915_private *dev_priv = dev->dev_private;
772 unsigned long timeout = jiffies + msecs_to_jiffies(5000);
773 u32 pp, pp_status;
774
775 pp_status = I915_READ(PCH_PP_STATUS);
776 if (pp_status & PP_ON)
777 return;
778
779 pp = I915_READ(PCH_PP_CONTROL);
780 pp |= PANEL_UNLOCK_REGS | POWER_TARGET_ON;
781 I915_WRITE(PCH_PP_CONTROL, pp);
782 do {
783 pp_status = I915_READ(PCH_PP_STATUS);
784 } while (((pp_status & PP_ON) == 0) && !time_after(jiffies, timeout));
785
786 if (time_after(jiffies, timeout))
787 DRM_DEBUG_KMS("panel on wait timed out: 0x%08x\n", pp_status);
788
789 pp &= ~(PANEL_UNLOCK_REGS | EDP_FORCE_VDD);
790 I915_WRITE(PCH_PP_CONTROL, pp);
791}
792
793static void ironlake_edp_panel_off (struct drm_device *dev)
794{
795 struct drm_i915_private *dev_priv = dev->dev_private;
796 unsigned long timeout = jiffies + msecs_to_jiffies(5000);
797 u32 pp, pp_status;
798
799 pp = I915_READ(PCH_PP_CONTROL);
800 pp &= ~POWER_TARGET_ON;
801 I915_WRITE(PCH_PP_CONTROL, pp);
802 do {
803 pp_status = I915_READ(PCH_PP_STATUS);
804 } while ((pp_status & PP_ON) && !time_after(jiffies, timeout));
805
806 if (time_after(jiffies, timeout))
807 DRM_DEBUG_KMS("panel off wait timed out\n");
808
809 /* Make sure VDD is enabled so DP AUX will work */
810 pp |= EDP_FORCE_VDD;
811 I915_WRITE(PCH_PP_CONTROL, pp);
812}
813
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500814static void ironlake_edp_backlight_on (struct drm_device *dev)
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800815{
816 struct drm_i915_private *dev_priv = dev->dev_private;
817 u32 pp;
818
Zhao Yakui28c97732009-10-09 11:39:41 +0800819 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800820 pp = I915_READ(PCH_PP_CONTROL);
821 pp |= EDP_BLC_ENABLE;
822 I915_WRITE(PCH_PP_CONTROL, pp);
823}
824
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500825static void ironlake_edp_backlight_off (struct drm_device *dev)
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800826{
827 struct drm_i915_private *dev_priv = dev->dev_private;
828 u32 pp;
829
Zhao Yakui28c97732009-10-09 11:39:41 +0800830 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800831 pp = I915_READ(PCH_PP_CONTROL);
832 pp &= ~EDP_BLC_ENABLE;
833 I915_WRITE(PCH_PP_CONTROL, pp);
834}
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700835
836static void
837intel_dp_dpms(struct drm_encoder *encoder, int mode)
838{
Chris Wilsonea5b2132010-08-04 13:50:23 +0100839 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Zhenyu Wang55f78c42010-03-29 16:13:57 +0800840 struct drm_device *dev = encoder->dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700841 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100842 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700843
844 if (mode != DRM_MODE_DPMS_ON) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800845 if (dp_reg & DP_PORT_EN) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100846 intel_dp_link_down(intel_dp);
847 if (IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) {
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500848 ironlake_edp_backlight_off(dev);
Jesse Barnes5620ae22010-07-26 13:51:22 -0700849 ironlake_edp_panel_off(dev);
Jesse Barnes9934c132010-07-22 13:18:19 -0700850 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800851 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700852 } else {
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800853 if (!(dp_reg & DP_PORT_EN)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100854 intel_dp_link_train(intel_dp);
855 if (IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) {
Jesse Barnes9934c132010-07-22 13:18:19 -0700856 ironlake_edp_panel_on(dev);
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500857 ironlake_edp_backlight_on(dev);
Jesse Barnes9934c132010-07-22 13:18:19 -0700858 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800859 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700860 }
Chris Wilsonea5b2132010-08-04 13:50:23 +0100861 intel_dp->dpms_mode = mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700862}
863
864/*
865 * Fetch AUX CH registers 0x202 - 0x207 which contain
866 * link status information
867 */
868static bool
Chris Wilsonea5b2132010-08-04 13:50:23 +0100869intel_dp_get_link_status(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700870 uint8_t link_status[DP_LINK_STATUS_SIZE])
871{
872 int ret;
873
Chris Wilsonea5b2132010-08-04 13:50:23 +0100874 ret = intel_dp_aux_native_read(intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700875 DP_LANE0_1_STATUS,
876 link_status, DP_LINK_STATUS_SIZE);
877 if (ret != DP_LINK_STATUS_SIZE)
878 return false;
879 return true;
880}
881
882static uint8_t
883intel_dp_link_status(uint8_t link_status[DP_LINK_STATUS_SIZE],
884 int r)
885{
886 return link_status[r - DP_LANE0_1_STATUS];
887}
888
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700889static uint8_t
890intel_get_adjust_request_voltage(uint8_t link_status[DP_LINK_STATUS_SIZE],
891 int lane)
892{
893 int i = DP_ADJUST_REQUEST_LANE0_1 + (lane >> 1);
894 int s = ((lane & 1) ?
895 DP_ADJUST_VOLTAGE_SWING_LANE1_SHIFT :
896 DP_ADJUST_VOLTAGE_SWING_LANE0_SHIFT);
897 uint8_t l = intel_dp_link_status(link_status, i);
898
899 return ((l >> s) & 3) << DP_TRAIN_VOLTAGE_SWING_SHIFT;
900}
901
902static uint8_t
903intel_get_adjust_request_pre_emphasis(uint8_t link_status[DP_LINK_STATUS_SIZE],
904 int lane)
905{
906 int i = DP_ADJUST_REQUEST_LANE0_1 + (lane >> 1);
907 int s = ((lane & 1) ?
908 DP_ADJUST_PRE_EMPHASIS_LANE1_SHIFT :
909 DP_ADJUST_PRE_EMPHASIS_LANE0_SHIFT);
910 uint8_t l = intel_dp_link_status(link_status, i);
911
912 return ((l >> s) & 3) << DP_TRAIN_PRE_EMPHASIS_SHIFT;
913}
914
915
916#if 0
917static char *voltage_names[] = {
918 "0.4V", "0.6V", "0.8V", "1.2V"
919};
920static char *pre_emph_names[] = {
921 "0dB", "3.5dB", "6dB", "9.5dB"
922};
923static char *link_train_names[] = {
924 "pattern 1", "pattern 2", "idle", "off"
925};
926#endif
927
928/*
929 * These are source-specific values; current Intel hardware supports
930 * a maximum voltage of 800mV and a maximum pre-emphasis of 6dB
931 */
932#define I830_DP_VOLTAGE_MAX DP_TRAIN_VOLTAGE_SWING_800
933
934static uint8_t
935intel_dp_pre_emphasis_max(uint8_t voltage_swing)
936{
937 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
938 case DP_TRAIN_VOLTAGE_SWING_400:
939 return DP_TRAIN_PRE_EMPHASIS_6;
940 case DP_TRAIN_VOLTAGE_SWING_600:
941 return DP_TRAIN_PRE_EMPHASIS_6;
942 case DP_TRAIN_VOLTAGE_SWING_800:
943 return DP_TRAIN_PRE_EMPHASIS_3_5;
944 case DP_TRAIN_VOLTAGE_SWING_1200:
945 default:
946 return DP_TRAIN_PRE_EMPHASIS_0;
947 }
948}
949
950static void
Chris Wilsonea5b2132010-08-04 13:50:23 +0100951intel_get_adjust_train(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700952 uint8_t link_status[DP_LINK_STATUS_SIZE],
953 int lane_count,
954 uint8_t train_set[4])
955{
956 uint8_t v = 0;
957 uint8_t p = 0;
958 int lane;
959
960 for (lane = 0; lane < lane_count; lane++) {
961 uint8_t this_v = intel_get_adjust_request_voltage(link_status, lane);
962 uint8_t this_p = intel_get_adjust_request_pre_emphasis(link_status, lane);
963
964 if (this_v > v)
965 v = this_v;
966 if (this_p > p)
967 p = this_p;
968 }
969
970 if (v >= I830_DP_VOLTAGE_MAX)
971 v = I830_DP_VOLTAGE_MAX | DP_TRAIN_MAX_SWING_REACHED;
972
973 if (p >= intel_dp_pre_emphasis_max(v))
974 p = intel_dp_pre_emphasis_max(v) | DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
975
976 for (lane = 0; lane < 4; lane++)
977 train_set[lane] = v | p;
978}
979
980static uint32_t
981intel_dp_signal_levels(uint8_t train_set, int lane_count)
982{
983 uint32_t signal_levels = 0;
984
985 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
986 case DP_TRAIN_VOLTAGE_SWING_400:
987 default:
988 signal_levels |= DP_VOLTAGE_0_4;
989 break;
990 case DP_TRAIN_VOLTAGE_SWING_600:
991 signal_levels |= DP_VOLTAGE_0_6;
992 break;
993 case DP_TRAIN_VOLTAGE_SWING_800:
994 signal_levels |= DP_VOLTAGE_0_8;
995 break;
996 case DP_TRAIN_VOLTAGE_SWING_1200:
997 signal_levels |= DP_VOLTAGE_1_2;
998 break;
999 }
1000 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
1001 case DP_TRAIN_PRE_EMPHASIS_0:
1002 default:
1003 signal_levels |= DP_PRE_EMPHASIS_0;
1004 break;
1005 case DP_TRAIN_PRE_EMPHASIS_3_5:
1006 signal_levels |= DP_PRE_EMPHASIS_3_5;
1007 break;
1008 case DP_TRAIN_PRE_EMPHASIS_6:
1009 signal_levels |= DP_PRE_EMPHASIS_6;
1010 break;
1011 case DP_TRAIN_PRE_EMPHASIS_9_5:
1012 signal_levels |= DP_PRE_EMPHASIS_9_5;
1013 break;
1014 }
1015 return signal_levels;
1016}
1017
Zhenyu Wange3421a12010-04-08 09:43:27 +08001018/* Gen6's DP voltage swing and pre-emphasis control */
1019static uint32_t
1020intel_gen6_edp_signal_levels(uint8_t train_set)
1021{
1022 switch (train_set & (DP_TRAIN_VOLTAGE_SWING_MASK|DP_TRAIN_PRE_EMPHASIS_MASK)) {
1023 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
1024 return EDP_LINK_TRAIN_400MV_0DB_SNB_B;
1025 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
1026 return EDP_LINK_TRAIN_400MV_6DB_SNB_B;
1027 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
1028 return EDP_LINK_TRAIN_600MV_3_5DB_SNB_B;
1029 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
1030 return EDP_LINK_TRAIN_800MV_0DB_SNB_B;
1031 default:
1032 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level\n");
1033 return EDP_LINK_TRAIN_400MV_0DB_SNB_B;
1034 }
1035}
1036
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001037static uint8_t
1038intel_get_lane_status(uint8_t link_status[DP_LINK_STATUS_SIZE],
1039 int lane)
1040{
1041 int i = DP_LANE0_1_STATUS + (lane >> 1);
1042 int s = (lane & 1) * 4;
1043 uint8_t l = intel_dp_link_status(link_status, i);
1044
1045 return (l >> s) & 0xf;
1046}
1047
1048/* Check for clock recovery is done on all channels */
1049static bool
1050intel_clock_recovery_ok(uint8_t link_status[DP_LINK_STATUS_SIZE], int lane_count)
1051{
1052 int lane;
1053 uint8_t lane_status;
1054
1055 for (lane = 0; lane < lane_count; lane++) {
1056 lane_status = intel_get_lane_status(link_status, lane);
1057 if ((lane_status & DP_LANE_CR_DONE) == 0)
1058 return false;
1059 }
1060 return true;
1061}
1062
1063/* Check to see if channel eq is done on all channels */
1064#define CHANNEL_EQ_BITS (DP_LANE_CR_DONE|\
1065 DP_LANE_CHANNEL_EQ_DONE|\
1066 DP_LANE_SYMBOL_LOCKED)
1067static bool
1068intel_channel_eq_ok(uint8_t link_status[DP_LINK_STATUS_SIZE], int lane_count)
1069{
1070 uint8_t lane_align;
1071 uint8_t lane_status;
1072 int lane;
1073
1074 lane_align = intel_dp_link_status(link_status,
1075 DP_LANE_ALIGN_STATUS_UPDATED);
1076 if ((lane_align & DP_INTERLANE_ALIGN_DONE) == 0)
1077 return false;
1078 for (lane = 0; lane < lane_count; lane++) {
1079 lane_status = intel_get_lane_status(link_status, lane);
1080 if ((lane_status & CHANNEL_EQ_BITS) != CHANNEL_EQ_BITS)
1081 return false;
1082 }
1083 return true;
1084}
1085
1086static bool
Chris Wilsonea5b2132010-08-04 13:50:23 +01001087intel_dp_set_link_train(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001088 uint32_t dp_reg_value,
1089 uint8_t dp_train_pat,
1090 uint8_t train_set[4],
1091 bool first)
1092{
Chris Wilsonea5b2132010-08-04 13:50:23 +01001093 struct drm_device *dev = intel_dp->base.enc.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001094 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001095 int ret;
1096
Chris Wilsonea5b2132010-08-04 13:50:23 +01001097 I915_WRITE(intel_dp->output_reg, dp_reg_value);
1098 POSTING_READ(intel_dp->output_reg);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001099 if (first)
1100 intel_wait_for_vblank(dev);
1101
Chris Wilsonea5b2132010-08-04 13:50:23 +01001102 intel_dp_aux_native_write_1(intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001103 DP_TRAINING_PATTERN_SET,
1104 dp_train_pat);
1105
Chris Wilsonea5b2132010-08-04 13:50:23 +01001106 ret = intel_dp_aux_native_write(intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001107 DP_TRAINING_LANE0_SET, train_set, 4);
1108 if (ret != 4)
1109 return false;
1110
1111 return true;
1112}
1113
1114static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01001115intel_dp_link_train(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001116{
Chris Wilsonea5b2132010-08-04 13:50:23 +01001117 struct drm_device *dev = intel_dp->base.enc.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001118 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001119 uint8_t train_set[4];
1120 uint8_t link_status[DP_LINK_STATUS_SIZE];
1121 int i;
1122 uint8_t voltage;
1123 bool clock_recovery = false;
1124 bool channel_eq = false;
1125 bool first = true;
1126 int tries;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001127 u32 reg;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001128 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001129
1130 /* Write the link configuration data */
Chris Wilsonea5b2132010-08-04 13:50:23 +01001131 intel_dp_aux_native_write(intel_dp, DP_LINK_BW_SET,
1132 intel_dp->link_configuration,
1133 DP_LINK_CONFIGURATION_SIZE);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001134
1135 DP |= DP_PORT_EN;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001136 if (HAS_PCH_CPT(dev) && !IS_eDP(intel_dp))
Zhenyu Wange3421a12010-04-08 09:43:27 +08001137 DP &= ~DP_LINK_TRAIN_MASK_CPT;
1138 else
1139 DP &= ~DP_LINK_TRAIN_MASK;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001140 memset(train_set, 0, 4);
1141 voltage = 0xff;
1142 tries = 0;
1143 clock_recovery = false;
1144 for (;;) {
1145 /* Use train_set[0] to set the voltage and pre emphasis values */
Zhenyu Wange3421a12010-04-08 09:43:27 +08001146 uint32_t signal_levels;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001147 if (IS_GEN6(dev) && IS_eDP(intel_dp)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08001148 signal_levels = intel_gen6_edp_signal_levels(train_set[0]);
1149 DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels;
1150 } else {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001151 signal_levels = intel_dp_signal_levels(train_set[0], intel_dp->lane_count);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001152 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
1153 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001154
Chris Wilsonea5b2132010-08-04 13:50:23 +01001155 if (HAS_PCH_CPT(dev) && !IS_eDP(intel_dp))
Zhenyu Wange3421a12010-04-08 09:43:27 +08001156 reg = DP | DP_LINK_TRAIN_PAT_1_CPT;
1157 else
1158 reg = DP | DP_LINK_TRAIN_PAT_1;
1159
Chris Wilsonea5b2132010-08-04 13:50:23 +01001160 if (!intel_dp_set_link_train(intel_dp, reg,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001161 DP_TRAINING_PATTERN_1, train_set, first))
1162 break;
1163 first = false;
1164 /* Set training pattern 1 */
1165
1166 udelay(100);
Chris Wilsonea5b2132010-08-04 13:50:23 +01001167 if (!intel_dp_get_link_status(intel_dp, link_status))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001168 break;
1169
Chris Wilsonea5b2132010-08-04 13:50:23 +01001170 if (intel_clock_recovery_ok(link_status, intel_dp->lane_count)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001171 clock_recovery = true;
1172 break;
1173 }
1174
1175 /* Check to see if we've tried the max voltage */
Chris Wilsonea5b2132010-08-04 13:50:23 +01001176 for (i = 0; i < intel_dp->lane_count; i++)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001177 if ((train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
1178 break;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001179 if (i == intel_dp->lane_count)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001180 break;
1181
1182 /* Check to see if we've tried the same voltage 5 times */
1183 if ((train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) == voltage) {
1184 ++tries;
1185 if (tries == 5)
1186 break;
1187 } else
1188 tries = 0;
1189 voltage = train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
1190
1191 /* Compute new train_set as requested by target */
Chris Wilsonea5b2132010-08-04 13:50:23 +01001192 intel_get_adjust_train(intel_dp, link_status, intel_dp->lane_count, train_set);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001193 }
1194
1195 /* channel equalization */
1196 tries = 0;
1197 channel_eq = false;
1198 for (;;) {
1199 /* Use train_set[0] to set the voltage and pre emphasis values */
Zhenyu Wange3421a12010-04-08 09:43:27 +08001200 uint32_t signal_levels;
1201
Chris Wilsonea5b2132010-08-04 13:50:23 +01001202 if (IS_GEN6(dev) && IS_eDP(intel_dp)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08001203 signal_levels = intel_gen6_edp_signal_levels(train_set[0]);
1204 DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels;
1205 } else {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001206 signal_levels = intel_dp_signal_levels(train_set[0], intel_dp->lane_count);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001207 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
1208 }
1209
Chris Wilsonea5b2132010-08-04 13:50:23 +01001210 if (HAS_PCH_CPT(dev) && !IS_eDP(intel_dp))
Zhenyu Wange3421a12010-04-08 09:43:27 +08001211 reg = DP | DP_LINK_TRAIN_PAT_2_CPT;
1212 else
1213 reg = DP | DP_LINK_TRAIN_PAT_2;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001214
1215 /* channel eq pattern */
Chris Wilsonea5b2132010-08-04 13:50:23 +01001216 if (!intel_dp_set_link_train(intel_dp, reg,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001217 DP_TRAINING_PATTERN_2, train_set,
1218 false))
1219 break;
1220
1221 udelay(400);
Chris Wilsonea5b2132010-08-04 13:50:23 +01001222 if (!intel_dp_get_link_status(intel_dp, link_status))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001223 break;
1224
Chris Wilsonea5b2132010-08-04 13:50:23 +01001225 if (intel_channel_eq_ok(link_status, intel_dp->lane_count)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001226 channel_eq = true;
1227 break;
1228 }
1229
1230 /* Try 5 times */
1231 if (tries > 5)
1232 break;
1233
1234 /* Compute new train_set as requested by target */
Chris Wilsonea5b2132010-08-04 13:50:23 +01001235 intel_get_adjust_train(intel_dp, link_status, intel_dp->lane_count, train_set);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001236 ++tries;
1237 }
1238
Chris Wilsonea5b2132010-08-04 13:50:23 +01001239 if (HAS_PCH_CPT(dev) && !IS_eDP(intel_dp))
Zhenyu Wange3421a12010-04-08 09:43:27 +08001240 reg = DP | DP_LINK_TRAIN_OFF_CPT;
1241 else
1242 reg = DP | DP_LINK_TRAIN_OFF;
1243
Chris Wilsonea5b2132010-08-04 13:50:23 +01001244 I915_WRITE(intel_dp->output_reg, reg);
1245 POSTING_READ(intel_dp->output_reg);
1246 intel_dp_aux_native_write_1(intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001247 DP_TRAINING_PATTERN_SET, DP_TRAINING_PATTERN_DISABLE);
1248}
1249
1250static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01001251intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001252{
Chris Wilsonea5b2132010-08-04 13:50:23 +01001253 struct drm_device *dev = intel_dp->base.enc.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001254 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001255 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001256
Zhao Yakui28c97732009-10-09 11:39:41 +08001257 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001258
Chris Wilsonea5b2132010-08-04 13:50:23 +01001259 if (IS_eDP(intel_dp)) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001260 DP &= ~DP_PLL_ENABLE;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001261 I915_WRITE(intel_dp->output_reg, DP);
1262 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001263 udelay(100);
1264 }
1265
Chris Wilsonea5b2132010-08-04 13:50:23 +01001266 if (HAS_PCH_CPT(dev) && !IS_eDP(intel_dp)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08001267 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001268 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT);
1269 POSTING_READ(intel_dp->output_reg);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001270 } else {
1271 DP &= ~DP_LINK_TRAIN_MASK;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001272 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE);
1273 POSTING_READ(intel_dp->output_reg);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001274 }
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001275
1276 udelay(17000);
1277
Chris Wilsonea5b2132010-08-04 13:50:23 +01001278 if (IS_eDP(intel_dp))
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001279 DP |= DP_LINK_TRAIN_OFF;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001280 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
1281 POSTING_READ(intel_dp->output_reg);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001282}
1283
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001284/*
1285 * According to DP spec
1286 * 5.1.2:
1287 * 1. Read DPCD
1288 * 2. Configure link according to Receiver Capabilities
1289 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
1290 * 4. Check link status on receipt of hot-plug interrupt
1291 */
1292
1293static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01001294intel_dp_check_link_status(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001295{
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001296 uint8_t link_status[DP_LINK_STATUS_SIZE];
1297
Chris Wilsonea5b2132010-08-04 13:50:23 +01001298 if (!intel_dp->base.enc.crtc)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001299 return;
1300
Chris Wilsonea5b2132010-08-04 13:50:23 +01001301 if (!intel_dp_get_link_status(intel_dp, link_status)) {
1302 intel_dp_link_down(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001303 return;
1304 }
1305
Chris Wilsonea5b2132010-08-04 13:50:23 +01001306 if (!intel_channel_eq_ok(link_status, intel_dp->lane_count))
1307 intel_dp_link_train(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001308}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001309
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001310static enum drm_connector_status
Adam Jacksonf2b115e2009-12-03 17:14:42 -05001311ironlake_dp_detect(struct drm_connector *connector)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001312{
Zhenyu Wang55f78c42010-03-29 16:13:57 +08001313 struct drm_encoder *encoder = intel_attached_encoder(connector);
Chris Wilsonea5b2132010-08-04 13:50:23 +01001314 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001315 enum drm_connector_status status;
1316
1317 status = connector_status_disconnected;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001318 if (intel_dp_aux_native_read(intel_dp,
1319 0x000, intel_dp->dpcd,
1320 sizeof (intel_dp->dpcd)) == sizeof (intel_dp->dpcd))
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001321 {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001322 if (intel_dp->dpcd[0] != 0)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001323 status = connector_status_connected;
1324 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01001325 DRM_DEBUG_KMS("DPCD: %hx%hx%hx%hx\n", intel_dp->dpcd[0],
1326 intel_dp->dpcd[1], intel_dp->dpcd[2], intel_dp->dpcd[3]);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001327 return status;
1328}
1329
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001330/**
1331 * Uses CRT_HOTPLUG_EN and CRT_HOTPLUG_STAT to detect DP connection.
1332 *
1333 * \return true if DP port is connected.
1334 * \return false if DP port is disconnected.
1335 */
1336static enum drm_connector_status
1337intel_dp_detect(struct drm_connector *connector)
1338{
Zhenyu Wang55f78c42010-03-29 16:13:57 +08001339 struct drm_encoder *encoder = intel_attached_encoder(connector);
Chris Wilsonea5b2132010-08-04 13:50:23 +01001340 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1341 struct drm_device *dev = intel_dp->base.enc.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001342 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001343 uint32_t temp, bit;
1344 enum drm_connector_status status;
1345
Chris Wilsonea5b2132010-08-04 13:50:23 +01001346 intel_dp->has_audio = false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001347
Eric Anholtc619eed2010-01-28 16:45:52 -08001348 if (HAS_PCH_SPLIT(dev))
Adam Jacksonf2b115e2009-12-03 17:14:42 -05001349 return ironlake_dp_detect(connector);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001350
Chris Wilsonea5b2132010-08-04 13:50:23 +01001351 switch (intel_dp->output_reg) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001352 case DP_B:
1353 bit = DPB_HOTPLUG_INT_STATUS;
1354 break;
1355 case DP_C:
1356 bit = DPC_HOTPLUG_INT_STATUS;
1357 break;
1358 case DP_D:
1359 bit = DPD_HOTPLUG_INT_STATUS;
1360 break;
1361 default:
1362 return connector_status_unknown;
1363 }
1364
1365 temp = I915_READ(PORT_HOTPLUG_STAT);
1366
1367 if ((temp & bit) == 0)
1368 return connector_status_disconnected;
1369
1370 status = connector_status_disconnected;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001371 if (intel_dp_aux_native_read(intel_dp,
1372 0x000, intel_dp->dpcd,
1373 sizeof (intel_dp->dpcd)) == sizeof (intel_dp->dpcd))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001374 {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001375 if (intel_dp->dpcd[0] != 0)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001376 status = connector_status_connected;
1377 }
1378 return status;
1379}
1380
1381static int intel_dp_get_modes(struct drm_connector *connector)
1382{
Zhenyu Wang55f78c42010-03-29 16:13:57 +08001383 struct drm_encoder *encoder = intel_attached_encoder(connector);
Chris Wilsonea5b2132010-08-04 13:50:23 +01001384 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1385 struct drm_device *dev = intel_dp->base.enc.dev;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001386 struct drm_i915_private *dev_priv = dev->dev_private;
1387 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001388
1389 /* We should parse the EDID data and find out if it has an audio sink
1390 */
1391
Chris Wilsonea5b2132010-08-04 13:50:23 +01001392 ret = intel_ddc_get_modes(connector, intel_dp->base.ddc_bus);
Zhao Yakuib9efc482010-07-19 09:43:11 +01001393 if (ret) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001394 if ((IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) &&
Zhao Yakuib9efc482010-07-19 09:43:11 +01001395 !dev_priv->panel_fixed_mode) {
1396 struct drm_display_mode *newmode;
1397 list_for_each_entry(newmode, &connector->probed_modes,
1398 head) {
1399 if (newmode->type & DRM_MODE_TYPE_PREFERRED) {
1400 dev_priv->panel_fixed_mode =
1401 drm_mode_duplicate(dev, newmode);
1402 break;
1403 }
1404 }
1405 }
1406
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001407 return ret;
Zhao Yakuib9efc482010-07-19 09:43:11 +01001408 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001409
1410 /* if eDP has no EDID, try to use fixed panel mode from VBT */
Chris Wilsonea5b2132010-08-04 13:50:23 +01001411 if (IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001412 if (dev_priv->panel_fixed_mode != NULL) {
1413 struct drm_display_mode *mode;
1414 mode = drm_mode_duplicate(dev, dev_priv->panel_fixed_mode);
1415 drm_mode_probed_add(connector, mode);
1416 return 1;
1417 }
1418 }
1419 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001420}
1421
1422static void
1423intel_dp_destroy (struct drm_connector *connector)
1424{
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001425 drm_sysfs_connector_remove(connector);
1426 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08001427 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001428}
1429
1430static const struct drm_encoder_helper_funcs intel_dp_helper_funcs = {
1431 .dpms = intel_dp_dpms,
1432 .mode_fixup = intel_dp_mode_fixup,
1433 .prepare = intel_encoder_prepare,
1434 .mode_set = intel_dp_mode_set,
1435 .commit = intel_encoder_commit,
1436};
1437
1438static const struct drm_connector_funcs intel_dp_connector_funcs = {
1439 .dpms = drm_helper_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001440 .detect = intel_dp_detect,
1441 .fill_modes = drm_helper_probe_single_connector_modes,
1442 .destroy = intel_dp_destroy,
1443};
1444
1445static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
1446 .get_modes = intel_dp_get_modes,
1447 .mode_valid = intel_dp_mode_valid,
Zhenyu Wang55f78c42010-03-29 16:13:57 +08001448 .best_encoder = intel_attached_encoder,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001449};
1450
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001451static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001452 .destroy = intel_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001453};
1454
1455void
Eric Anholt21d40d32010-03-25 11:11:14 -07001456intel_dp_hot_plug(struct intel_encoder *intel_encoder)
Keith Packardc8110e52009-05-06 11:51:10 -07001457{
Chris Wilsonea5b2132010-08-04 13:50:23 +01001458 struct intel_dp *intel_dp = container_of(intel_encoder, struct intel_dp, base);
Keith Packardc8110e52009-05-06 11:51:10 -07001459
Chris Wilsonea5b2132010-08-04 13:50:23 +01001460 if (intel_dp->dpms_mode == DRM_MODE_DPMS_ON)
1461 intel_dp_check_link_status(intel_dp);
Keith Packardc8110e52009-05-06 11:51:10 -07001462}
1463
Zhenyu Wange3421a12010-04-08 09:43:27 +08001464/* Return which DP Port should be selected for Transcoder DP control */
1465int
1466intel_trans_dp_port_sel (struct drm_crtc *crtc)
1467{
1468 struct drm_device *dev = crtc->dev;
1469 struct drm_mode_config *mode_config = &dev->mode_config;
1470 struct drm_encoder *encoder;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001471
1472 list_for_each_entry(encoder, &mode_config->encoder_list, head) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001473 struct intel_dp *intel_dp;
1474
Dan Carpenterd8201ab2010-05-07 10:39:00 +02001475 if (encoder->crtc != crtc)
Zhenyu Wange3421a12010-04-08 09:43:27 +08001476 continue;
1477
Chris Wilsonea5b2132010-08-04 13:50:23 +01001478 intel_dp = enc_to_intel_dp(encoder);
1479 if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT)
1480 return intel_dp->output_reg;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001481 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01001482
Zhenyu Wange3421a12010-04-08 09:43:27 +08001483 return -1;
1484}
1485
Zhao Yakui36e83a12010-06-12 14:32:21 +08001486/* check the VBT to see whether the eDP is on DP-D port */
Adam Jacksoncb0953d2010-07-16 14:46:29 -04001487bool intel_dpd_is_edp(struct drm_device *dev)
Zhao Yakui36e83a12010-06-12 14:32:21 +08001488{
1489 struct drm_i915_private *dev_priv = dev->dev_private;
1490 struct child_device_config *p_child;
1491 int i;
1492
1493 if (!dev_priv->child_dev_num)
1494 return false;
1495
1496 for (i = 0; i < dev_priv->child_dev_num; i++) {
1497 p_child = dev_priv->child_dev + i;
1498
1499 if (p_child->dvo_port == PORT_IDPD &&
1500 p_child->device_type == DEVICE_TYPE_eDP)
1501 return true;
1502 }
1503 return false;
1504}
1505
Keith Packardc8110e52009-05-06 11:51:10 -07001506void
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001507intel_dp_init(struct drm_device *dev, int output_reg)
1508{
1509 struct drm_i915_private *dev_priv = dev->dev_private;
1510 struct drm_connector *connector;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001511 struct intel_dp *intel_dp;
Eric Anholt21d40d32010-03-25 11:11:14 -07001512 struct intel_encoder *intel_encoder;
Zhenyu Wang55f78c42010-03-29 16:13:57 +08001513 struct intel_connector *intel_connector;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001514 const char *name = NULL;
Adam Jacksonb3295302010-07-16 14:46:28 -04001515 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001516
Chris Wilsonea5b2132010-08-04 13:50:23 +01001517 intel_dp = kzalloc(sizeof(struct intel_dp), GFP_KERNEL);
1518 if (!intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001519 return;
1520
Zhenyu Wang55f78c42010-03-29 16:13:57 +08001521 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
1522 if (!intel_connector) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001523 kfree(intel_dp);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08001524 return;
1525 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01001526 intel_encoder = &intel_dp->base;
Zhenyu Wang55f78c42010-03-29 16:13:57 +08001527
Chris Wilsonea5b2132010-08-04 13:50:23 +01001528 if (HAS_PCH_SPLIT(dev) && output_reg == PCH_DP_D)
Adam Jacksonb3295302010-07-16 14:46:28 -04001529 if (intel_dpd_is_edp(dev))
Chris Wilsonea5b2132010-08-04 13:50:23 +01001530 intel_dp->is_pch_edp = true;
Adam Jacksonb3295302010-07-16 14:46:28 -04001531
Chris Wilsonea5b2132010-08-04 13:50:23 +01001532 if (output_reg == DP_A || IS_PCH_eDP(intel_dp)) {
Adam Jacksonb3295302010-07-16 14:46:28 -04001533 type = DRM_MODE_CONNECTOR_eDP;
1534 intel_encoder->type = INTEL_OUTPUT_EDP;
1535 } else {
1536 type = DRM_MODE_CONNECTOR_DisplayPort;
1537 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
1538 }
1539
Zhenyu Wang55f78c42010-03-29 16:13:57 +08001540 connector = &intel_connector->base;
Adam Jacksonb3295302010-07-16 14:46:28 -04001541 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001542 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
1543
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001544 connector->polled = DRM_CONNECTOR_POLL_HPD;
1545
Zhao Yakui652af9d2009-12-02 10:03:33 +08001546 if (output_reg == DP_B || output_reg == PCH_DP_B)
Eric Anholt21d40d32010-03-25 11:11:14 -07001547 intel_encoder->clone_mask = (1 << INTEL_DP_B_CLONE_BIT);
Zhao Yakui652af9d2009-12-02 10:03:33 +08001548 else if (output_reg == DP_C || output_reg == PCH_DP_C)
Eric Anholt21d40d32010-03-25 11:11:14 -07001549 intel_encoder->clone_mask = (1 << INTEL_DP_C_CLONE_BIT);
Zhao Yakui652af9d2009-12-02 10:03:33 +08001550 else if (output_reg == DP_D || output_reg == PCH_DP_D)
Eric Anholt21d40d32010-03-25 11:11:14 -07001551 intel_encoder->clone_mask = (1 << INTEL_DP_D_CLONE_BIT);
Ma Lingf8aed702009-08-24 13:50:24 +08001552
Chris Wilsonea5b2132010-08-04 13:50:23 +01001553 if (IS_eDP(intel_dp))
Eric Anholt21d40d32010-03-25 11:11:14 -07001554 intel_encoder->clone_mask = (1 << INTEL_EDP_CLONE_BIT);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08001555
Eric Anholt21d40d32010-03-25 11:11:14 -07001556 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001557 connector->interlace_allowed = true;
1558 connector->doublescan_allowed = 0;
1559
Chris Wilsonea5b2132010-08-04 13:50:23 +01001560 intel_dp->output_reg = output_reg;
1561 intel_dp->has_audio = false;
1562 intel_dp->dpms_mode = DRM_MODE_DPMS_ON;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001563
Eric Anholt21d40d32010-03-25 11:11:14 -07001564 drm_encoder_init(dev, &intel_encoder->enc, &intel_dp_enc_funcs,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001565 DRM_MODE_ENCODER_TMDS);
Eric Anholt21d40d32010-03-25 11:11:14 -07001566 drm_encoder_helper_add(&intel_encoder->enc, &intel_dp_helper_funcs);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001567
Zhenyu Wang55f78c42010-03-29 16:13:57 +08001568 drm_mode_connector_attach_encoder(&intel_connector->base,
Eric Anholt21d40d32010-03-25 11:11:14 -07001569 &intel_encoder->enc);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001570 drm_sysfs_connector_add(connector);
1571
1572 /* Set up the DDC bus. */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001573 switch (output_reg) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001574 case DP_A:
1575 name = "DPDDC-A";
1576 break;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001577 case DP_B:
1578 case PCH_DP_B:
Jesse Barnesb01f2c32009-12-11 11:07:17 -08001579 dev_priv->hotplug_supported_mask |=
1580 HDMIB_HOTPLUG_INT_STATUS;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001581 name = "DPDDC-B";
1582 break;
1583 case DP_C:
1584 case PCH_DP_C:
Jesse Barnesb01f2c32009-12-11 11:07:17 -08001585 dev_priv->hotplug_supported_mask |=
1586 HDMIC_HOTPLUG_INT_STATUS;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001587 name = "DPDDC-C";
1588 break;
1589 case DP_D:
1590 case PCH_DP_D:
Jesse Barnesb01f2c32009-12-11 11:07:17 -08001591 dev_priv->hotplug_supported_mask |=
1592 HDMID_HOTPLUG_INT_STATUS;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001593 name = "DPDDC-D";
1594 break;
1595 }
1596
Chris Wilsonea5b2132010-08-04 13:50:23 +01001597 intel_dp_i2c_init(intel_dp, intel_connector, name);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001598
Chris Wilsonea5b2132010-08-04 13:50:23 +01001599 intel_encoder->ddc_bus = &intel_dp->adapter;
Eric Anholt21d40d32010-03-25 11:11:14 -07001600 intel_encoder->hot_plug = intel_dp_hot_plug;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001601
Chris Wilsonea5b2132010-08-04 13:50:23 +01001602 if (output_reg == DP_A || IS_PCH_eDP(intel_dp)) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001603 /* initialize panel mode from VBT if available for eDP */
1604 if (dev_priv->lfp_lvds_vbt_mode) {
1605 dev_priv->panel_fixed_mode =
1606 drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);
1607 if (dev_priv->panel_fixed_mode) {
1608 dev_priv->panel_fixed_mode->type |=
1609 DRM_MODE_TYPE_PREFERRED;
1610 }
1611 }
1612 }
1613
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001614 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
1615 * 0xd. Failure to do so will result in spurious interrupts being
1616 * generated on the port when a cable is not attached.
1617 */
1618 if (IS_G4X(dev) && !IS_GM45(dev)) {
1619 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
1620 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
1621 }
1622}