blob: 0feae908bb37f7bc8cbc642ea12f96a6cabf467a [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 Packardd2b996a2011-07-25 22:37:51 -070053 int dpms_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -070054 uint8_t link_bw;
55 uint8_t lane_count;
Adam Jackson9de88e62011-07-12 17:38:02 -040056 uint8_t dpcd[8];
Keith Packarda4fc5ed2009-04-07 16:16:42 -070057 struct i2c_adapter adapter;
58 struct i2c_algo_dp_aux_data algo;
Adam Jacksonf0917372010-07-16 14:46:27 -040059 bool is_pch_edp;
Jesse Barnes33a34e42010-09-08 12:42:02 -070060 uint8_t train_set[4];
61 uint8_t link_status[DP_LINK_STATUS_SIZE];
Keith Packarda4fc5ed2009-04-07 16:16:42 -070062};
63
Jesse Barnescfcb0fc2010-10-07 16:01:06 -070064/**
65 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
66 * @intel_dp: DP struct
67 *
68 * If a CPU or PCH DP output is attached to an eDP panel, this function
69 * will return true, and false otherwise.
70 */
71static bool is_edp(struct intel_dp *intel_dp)
72{
73 return intel_dp->base.type == INTEL_OUTPUT_EDP;
74}
75
76/**
77 * is_pch_edp - is the port on the PCH and attached to an eDP panel?
78 * @intel_dp: DP struct
79 *
80 * Returns true if the given DP struct corresponds to a PCH DP port attached
81 * to an eDP panel, false otherwise. Helpful for determining whether we
82 * may need FDI resources for a given DP output or not.
83 */
84static bool is_pch_edp(struct intel_dp *intel_dp)
85{
86 return intel_dp->is_pch_edp;
87}
88
Chris Wilsonea5b2132010-08-04 13:50:23 +010089static struct intel_dp *enc_to_intel_dp(struct drm_encoder *encoder)
90{
Chris Wilson4ef69c72010-09-09 15:14:28 +010091 return container_of(encoder, struct intel_dp, base.base);
Chris Wilsonea5b2132010-08-04 13:50:23 +010092}
Keith Packarda4fc5ed2009-04-07 16:16:42 -070093
Chris Wilsondf0e9242010-09-09 16:20:55 +010094static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
95{
96 return container_of(intel_attached_encoder(connector),
97 struct intel_dp, base);
98}
99
Jesse Barnes814948a2010-10-07 16:01:09 -0700100/**
101 * intel_encoder_is_pch_edp - is the given encoder a PCH attached eDP?
102 * @encoder: DRM encoder
103 *
104 * Return true if @encoder corresponds to a PCH attached eDP panel. Needed
105 * by intel_display.c.
106 */
107bool intel_encoder_is_pch_edp(struct drm_encoder *encoder)
108{
109 struct intel_dp *intel_dp;
110
111 if (!encoder)
112 return false;
113
114 intel_dp = enc_to_intel_dp(encoder);
115
116 return is_pch_edp(intel_dp);
117}
118
Jesse Barnes33a34e42010-09-08 12:42:02 -0700119static void intel_dp_start_link_train(struct intel_dp *intel_dp);
120static void intel_dp_complete_link_train(struct intel_dp *intel_dp);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100121static void intel_dp_link_down(struct intel_dp *intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700122
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800123void
Eric Anholt21d40d32010-03-25 11:11:14 -0700124intel_edp_link_config (struct intel_encoder *intel_encoder,
Chris Wilsonea5b2132010-08-04 13:50:23 +0100125 int *lane_num, int *link_bw)
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800126{
Chris Wilsonea5b2132010-08-04 13:50:23 +0100127 struct intel_dp *intel_dp = container_of(intel_encoder, struct intel_dp, base);
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800128
Chris Wilsonea5b2132010-08-04 13:50:23 +0100129 *lane_num = intel_dp->lane_count;
130 if (intel_dp->link_bw == DP_LINK_BW_1_62)
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800131 *link_bw = 162000;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100132 else if (intel_dp->link_bw == DP_LINK_BW_2_7)
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800133 *link_bw = 270000;
134}
135
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700136static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100137intel_dp_max_lane_count(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700138{
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700139 int max_lane_count = 4;
140
Jesse Barnes7183dc22011-07-07 11:10:58 -0700141 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
142 max_lane_count = intel_dp->dpcd[DP_MAX_LANE_COUNT] & 0x1f;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700143 switch (max_lane_count) {
144 case 1: case 2: case 4:
145 break;
146 default:
147 max_lane_count = 4;
148 }
149 }
150 return max_lane_count;
151}
152
153static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100154intel_dp_max_link_bw(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700155{
Jesse Barnes7183dc22011-07-07 11:10:58 -0700156 int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700157
158 switch (max_link_bw) {
159 case DP_LINK_BW_1_62:
160 case DP_LINK_BW_2_7:
161 break;
162 default:
163 max_link_bw = DP_LINK_BW_1_62;
164 break;
165 }
166 return max_link_bw;
167}
168
169static int
170intel_dp_link_clock(uint8_t link_bw)
171{
172 if (link_bw == DP_LINK_BW_2_7)
173 return 270000;
174 else
175 return 162000;
176}
177
178/* I think this is a fiction */
179static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100180intel_dp_link_required(struct drm_device *dev, struct intel_dp *intel_dp, int pixel_clock)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700181{
Jesse Barnes89c61432011-06-24 12:19:28 -0700182 struct drm_crtc *crtc = intel_dp->base.base.crtc;
183 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
184 int bpp = 24;
Zhenyu Wang885a5fb2010-01-12 05:38:31 +0800185
Jesse Barnes89c61432011-06-24 12:19:28 -0700186 if (intel_crtc)
187 bpp = intel_crtc->bpp;
188
189 return (pixel_clock * bpp + 7) / 8;
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
Jesse Barnes11bee432011-08-01 15:02:20 -0700320 /* Try to wait for any previous AUX channel activity */
321 for (try = 0; try < 3; try++) {
322 status = I915_READ(ch_ctl);
323 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
324 break;
325 msleep(1);
326 }
327
328 if (try == 3) {
329 WARN(1, "dp_aux_ch not started status 0x%08x\n",
330 I915_READ(ch_ctl));
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100331 return -EBUSY;
332 }
333
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700334 /* Must try at least 3 times according to DP spec */
335 for (try = 0; try < 5; try++) {
336 /* Load the send data into the aux channel data registers */
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100337 for (i = 0; i < send_bytes; i += 4)
338 I915_WRITE(ch_data + i,
339 pack_aux(send + i, send_bytes - i));
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700340
341 /* Send the command and wait for it to complete */
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100342 I915_WRITE(ch_ctl,
343 DP_AUX_CH_CTL_SEND_BUSY |
344 DP_AUX_CH_CTL_TIME_OUT_400us |
345 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
346 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
347 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT) |
348 DP_AUX_CH_CTL_DONE |
349 DP_AUX_CH_CTL_TIME_OUT_ERROR |
350 DP_AUX_CH_CTL_RECEIVE_ERROR);
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700351 for (;;) {
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700352 status = I915_READ(ch_ctl);
353 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
354 break;
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100355 udelay(100);
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700356 }
357
358 /* Clear done status and any errors */
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100359 I915_WRITE(ch_ctl,
360 status |
361 DP_AUX_CH_CTL_DONE |
362 DP_AUX_CH_CTL_TIME_OUT_ERROR |
363 DP_AUX_CH_CTL_RECEIVE_ERROR);
364 if (status & DP_AUX_CH_CTL_DONE)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700365 break;
366 }
367
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700368 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700369 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Keith Packarda5b3da52009-06-11 22:30:32 -0700370 return -EBUSY;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700371 }
372
373 /* Check for timeout or receive error.
374 * Timeouts occur when the sink is not connected
375 */
Keith Packarda5b3da52009-06-11 22:30:32 -0700376 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700377 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Keith Packarda5b3da52009-06-11 22:30:32 -0700378 return -EIO;
379 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700380
381 /* Timeouts occur when the device isn't connected, so they're
382 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -0700383 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Zhao Yakui28c97732009-10-09 11:39:41 +0800384 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Keith Packarda5b3da52009-06-11 22:30:32 -0700385 return -ETIMEDOUT;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700386 }
387
388 /* Unload any bytes sent back from the other side */
389 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
390 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700391 if (recv_bytes > recv_size)
392 recv_bytes = recv_size;
393
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100394 for (i = 0; i < recv_bytes; i += 4)
395 unpack_aux(I915_READ(ch_data + i),
396 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700397
398 return recv_bytes;
399}
400
401/* Write data to the aux channel in native mode */
402static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100403intel_dp_aux_native_write(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700404 uint16_t address, uint8_t *send, int send_bytes)
405{
406 int ret;
407 uint8_t msg[20];
408 int msg_bytes;
409 uint8_t ack;
410
411 if (send_bytes > 16)
412 return -1;
413 msg[0] = AUX_NATIVE_WRITE << 4;
414 msg[1] = address >> 8;
Zhenyu Wangeebc8632009-07-24 01:00:30 +0800415 msg[2] = address & 0xff;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700416 msg[3] = send_bytes - 1;
417 memcpy(&msg[4], send, send_bytes);
418 msg_bytes = send_bytes + 4;
419 for (;;) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100420 ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes, &ack, 1);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700421 if (ret < 0)
422 return ret;
423 if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK)
424 break;
425 else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
426 udelay(100);
427 else
Keith Packarda5b3da52009-06-11 22:30:32 -0700428 return -EIO;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700429 }
430 return send_bytes;
431}
432
433/* Write a single byte to the aux channel in native mode */
434static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100435intel_dp_aux_native_write_1(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700436 uint16_t address, uint8_t byte)
437{
Chris Wilsonea5b2132010-08-04 13:50:23 +0100438 return intel_dp_aux_native_write(intel_dp, address, &byte, 1);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700439}
440
441/* read bytes from a native aux channel */
442static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100443intel_dp_aux_native_read(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700444 uint16_t address, uint8_t *recv, int recv_bytes)
445{
446 uint8_t msg[4];
447 int msg_bytes;
448 uint8_t reply[20];
449 int reply_bytes;
450 uint8_t ack;
451 int ret;
452
453 msg[0] = AUX_NATIVE_READ << 4;
454 msg[1] = address >> 8;
455 msg[2] = address & 0xff;
456 msg[3] = recv_bytes - 1;
457
458 msg_bytes = 4;
459 reply_bytes = recv_bytes + 1;
460
461 for (;;) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100462 ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700463 reply, reply_bytes);
Keith Packarda5b3da52009-06-11 22:30:32 -0700464 if (ret == 0)
465 return -EPROTO;
466 if (ret < 0)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700467 return ret;
468 ack = reply[0];
469 if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK) {
470 memcpy(recv, reply + 1, ret - 1);
471 return ret - 1;
472 }
473 else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
474 udelay(100);
475 else
Keith Packarda5b3da52009-06-11 22:30:32 -0700476 return -EIO;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700477 }
478}
479
480static int
Dave Airlieab2c0672009-12-04 10:55:24 +1000481intel_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode,
482 uint8_t write_byte, uint8_t *read_byte)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700483{
Dave Airlieab2c0672009-12-04 10:55:24 +1000484 struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100485 struct intel_dp *intel_dp = container_of(adapter,
486 struct intel_dp,
487 adapter);
Dave Airlieab2c0672009-12-04 10:55:24 +1000488 uint16_t address = algo_data->address;
489 uint8_t msg[5];
490 uint8_t reply[2];
David Flynn8316f332010-12-08 16:10:21 +0000491 unsigned retry;
Dave Airlieab2c0672009-12-04 10:55:24 +1000492 int msg_bytes;
493 int reply_bytes;
494 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700495
Dave Airlieab2c0672009-12-04 10:55:24 +1000496 /* Set up the command byte */
497 if (mode & MODE_I2C_READ)
498 msg[0] = AUX_I2C_READ << 4;
499 else
500 msg[0] = AUX_I2C_WRITE << 4;
501
502 if (!(mode & MODE_I2C_STOP))
503 msg[0] |= AUX_I2C_MOT << 4;
504
505 msg[1] = address >> 8;
506 msg[2] = address;
507
508 switch (mode) {
509 case MODE_I2C_WRITE:
510 msg[3] = 0;
511 msg[4] = write_byte;
512 msg_bytes = 5;
513 reply_bytes = 1;
514 break;
515 case MODE_I2C_READ:
516 msg[3] = 0;
517 msg_bytes = 4;
518 reply_bytes = 2;
519 break;
520 default:
521 msg_bytes = 3;
522 reply_bytes = 1;
523 break;
524 }
525
David Flynn8316f332010-12-08 16:10:21 +0000526 for (retry = 0; retry < 5; retry++) {
527 ret = intel_dp_aux_ch(intel_dp,
528 msg, msg_bytes,
529 reply, reply_bytes);
Dave Airlieab2c0672009-12-04 10:55:24 +1000530 if (ret < 0) {
Dave Airlie3ff99162009-12-08 14:03:47 +1000531 DRM_DEBUG_KMS("aux_ch failed %d\n", ret);
Dave Airlieab2c0672009-12-04 10:55:24 +1000532 return ret;
533 }
David Flynn8316f332010-12-08 16:10:21 +0000534
535 switch (reply[0] & AUX_NATIVE_REPLY_MASK) {
536 case AUX_NATIVE_REPLY_ACK:
537 /* I2C-over-AUX Reply field is only valid
538 * when paired with AUX ACK.
539 */
540 break;
541 case AUX_NATIVE_REPLY_NACK:
542 DRM_DEBUG_KMS("aux_ch native nack\n");
543 return -EREMOTEIO;
544 case AUX_NATIVE_REPLY_DEFER:
545 udelay(100);
546 continue;
547 default:
548 DRM_ERROR("aux_ch invalid native reply 0x%02x\n",
549 reply[0]);
550 return -EREMOTEIO;
551 }
552
Dave Airlieab2c0672009-12-04 10:55:24 +1000553 switch (reply[0] & AUX_I2C_REPLY_MASK) {
554 case AUX_I2C_REPLY_ACK:
555 if (mode == MODE_I2C_READ) {
556 *read_byte = reply[1];
557 }
558 return reply_bytes - 1;
559 case AUX_I2C_REPLY_NACK:
David Flynn8316f332010-12-08 16:10:21 +0000560 DRM_DEBUG_KMS("aux_i2c nack\n");
Dave Airlieab2c0672009-12-04 10:55:24 +1000561 return -EREMOTEIO;
562 case AUX_I2C_REPLY_DEFER:
David Flynn8316f332010-12-08 16:10:21 +0000563 DRM_DEBUG_KMS("aux_i2c defer\n");
Dave Airlieab2c0672009-12-04 10:55:24 +1000564 udelay(100);
565 break;
566 default:
David Flynn8316f332010-12-08 16:10:21 +0000567 DRM_ERROR("aux_i2c invalid reply 0x%02x\n", reply[0]);
Dave Airlieab2c0672009-12-04 10:55:24 +1000568 return -EREMOTEIO;
569 }
570 }
David Flynn8316f332010-12-08 16:10:21 +0000571
572 DRM_ERROR("too many retries, giving up\n");
573 return -EREMOTEIO;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700574}
575
576static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100577intel_dp_i2c_init(struct intel_dp *intel_dp,
Zhenyu Wang55f78c42010-03-29 16:13:57 +0800578 struct intel_connector *intel_connector, const char *name)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700579{
Zhenyu Wangd54e9d22009-10-19 15:43:51 +0800580 DRM_DEBUG_KMS("i2c_init %s\n", name);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100581 intel_dp->algo.running = false;
582 intel_dp->algo.address = 0;
583 intel_dp->algo.aux_ch = intel_dp_i2c_aux_ch;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700584
Chris Wilsonea5b2132010-08-04 13:50:23 +0100585 memset(&intel_dp->adapter, '\0', sizeof (intel_dp->adapter));
586 intel_dp->adapter.owner = THIS_MODULE;
587 intel_dp->adapter.class = I2C_CLASS_DDC;
588 strncpy (intel_dp->adapter.name, name, sizeof(intel_dp->adapter.name) - 1);
589 intel_dp->adapter.name[sizeof(intel_dp->adapter.name) - 1] = '\0';
590 intel_dp->adapter.algo_data = &intel_dp->algo;
591 intel_dp->adapter.dev.parent = &intel_connector->base.kdev;
592
593 return i2c_dp_aux_add_bus(&intel_dp->adapter);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700594}
595
596static bool
597intel_dp_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode,
598 struct drm_display_mode *adjusted_mode)
599{
Zhao Yakui0d3a1be2010-07-19 09:43:13 +0100600 struct drm_device *dev = encoder->dev;
601 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100602 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700603 int lane_count, clock;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100604 int max_lane_count = intel_dp_max_lane_count(intel_dp);
605 int max_clock = intel_dp_max_link_bw(intel_dp) == DP_LINK_BW_2_7 ? 1 : 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700606 static int bws[2] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7 };
607
Jesse Barnes4d926462010-10-07 16:01:07 -0700608 if (is_edp(intel_dp) && dev_priv->panel_fixed_mode) {
Chris Wilson1d8e1c72010-08-07 11:01:28 +0100609 intel_fixed_panel_mode(dev_priv->panel_fixed_mode, adjusted_mode);
610 intel_pch_panel_fitting(dev, DRM_MODE_SCALE_FULLSCREEN,
611 mode, adjusted_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +0100612 /*
613 * the mode->clock is used to calculate the Data&Link M/N
614 * of the pipe. For the eDP the fixed clock should be used.
615 */
616 mode->clock = dev_priv->panel_fixed_mode->clock;
617 }
618
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700619 for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) {
620 for (clock = 0; clock <= max_clock; clock++) {
Dave Airliefe27d532010-06-30 11:46:17 +1000621 int link_avail = intel_dp_max_data_rate(intel_dp_link_clock(bws[clock]), lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700622
Chris Wilsonea5b2132010-08-04 13:50:23 +0100623 if (intel_dp_link_required(encoder->dev, intel_dp, mode->clock)
Zhenyu Wang885a5fb2010-01-12 05:38:31 +0800624 <= link_avail) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100625 intel_dp->link_bw = bws[clock];
626 intel_dp->lane_count = lane_count;
627 adjusted_mode->clock = intel_dp_link_clock(intel_dp->link_bw);
Zhao Yakui28c97732009-10-09 11:39:41 +0800628 DRM_DEBUG_KMS("Display port link bw %02x lane "
629 "count %d clock %d\n",
Chris Wilsonea5b2132010-08-04 13:50:23 +0100630 intel_dp->link_bw, intel_dp->lane_count,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700631 adjusted_mode->clock);
632 return true;
633 }
634 }
635 }
Dave Airliefe27d532010-06-30 11:46:17 +1000636
Chris Wilson3cf2efb2010-11-29 10:09:55 +0000637 if (is_edp(intel_dp)) {
638 /* okay we failed just pick the highest */
639 intel_dp->lane_count = max_lane_count;
640 intel_dp->link_bw = bws[max_clock];
641 adjusted_mode->clock = intel_dp_link_clock(intel_dp->link_bw);
642 DRM_DEBUG_KMS("Force picking display port link bw %02x lane "
643 "count %d clock %d\n",
644 intel_dp->link_bw, intel_dp->lane_count,
645 adjusted_mode->clock);
646
647 return true;
648 }
649
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700650 return false;
651}
652
653struct intel_dp_m_n {
654 uint32_t tu;
655 uint32_t gmch_m;
656 uint32_t gmch_n;
657 uint32_t link_m;
658 uint32_t link_n;
659};
660
661static void
662intel_reduce_ratio(uint32_t *num, uint32_t *den)
663{
664 while (*num > 0xffffff || *den > 0xffffff) {
665 *num >>= 1;
666 *den >>= 1;
667 }
668}
669
670static void
Zhao Yakui36e83a12010-06-12 14:32:21 +0800671intel_dp_compute_m_n(int bpp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700672 int nlanes,
673 int pixel_clock,
674 int link_clock,
675 struct intel_dp_m_n *m_n)
676{
677 m_n->tu = 64;
Zhao Yakui36e83a12010-06-12 14:32:21 +0800678 m_n->gmch_m = (pixel_clock * bpp) >> 3;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700679 m_n->gmch_n = link_clock * nlanes;
680 intel_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
681 m_n->link_m = pixel_clock;
682 m_n->link_n = link_clock;
683 intel_reduce_ratio(&m_n->link_m, &m_n->link_n);
684}
685
686void
687intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode,
688 struct drm_display_mode *adjusted_mode)
689{
690 struct drm_device *dev = crtc->dev;
691 struct drm_mode_config *mode_config = &dev->mode_config;
Zhenyu Wang55f78c42010-03-29 16:13:57 +0800692 struct drm_encoder *encoder;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700693 struct drm_i915_private *dev_priv = dev->dev_private;
694 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnes858fa0352011-06-24 12:19:24 -0700695 int lane_count = 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700696 struct intel_dp_m_n m_n;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800697 int pipe = intel_crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700698
699 /*
Eric Anholt21d40d32010-03-25 11:11:14 -0700700 * Find the lane count in the intel_encoder private
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700701 */
Zhenyu Wang55f78c42010-03-29 16:13:57 +0800702 list_for_each_entry(encoder, &mode_config->encoder_list, head) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100703 struct intel_dp *intel_dp;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700704
Dan Carpenterd8201ab2010-05-07 10:39:00 +0200705 if (encoder->crtc != crtc)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700706 continue;
707
Chris Wilsonea5b2132010-08-04 13:50:23 +0100708 intel_dp = enc_to_intel_dp(encoder);
709 if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT) {
710 lane_count = intel_dp->lane_count;
Jesse Barnes51190662010-10-07 16:01:08 -0700711 break;
712 } else if (is_edp(intel_dp)) {
713 lane_count = dev_priv->edp.lanes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700714 break;
715 }
716 }
717
718 /*
719 * Compute the GMCH and Link ratios. The '3' here is
720 * the number of bytes_per_pixel post-LUT, which we always
721 * set up for 8-bits of R/G/B, or 3 bytes total.
722 */
Jesse Barnes858fa0352011-06-24 12:19:24 -0700723 intel_dp_compute_m_n(intel_crtc->bpp, lane_count,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700724 mode->clock, adjusted_mode->clock, &m_n);
725
Eric Anholtc619eed2010-01-28 16:45:52 -0800726 if (HAS_PCH_SPLIT(dev)) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800727 I915_WRITE(TRANSDATA_M1(pipe),
728 ((m_n.tu - 1) << PIPE_GMCH_DATA_M_TU_SIZE_SHIFT) |
729 m_n.gmch_m);
730 I915_WRITE(TRANSDATA_N1(pipe), m_n.gmch_n);
731 I915_WRITE(TRANSDPLINK_M1(pipe), m_n.link_m);
732 I915_WRITE(TRANSDPLINK_N1(pipe), m_n.link_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700733 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800734 I915_WRITE(PIPE_GMCH_DATA_M(pipe),
735 ((m_n.tu - 1) << PIPE_GMCH_DATA_M_TU_SIZE_SHIFT) |
736 m_n.gmch_m);
737 I915_WRITE(PIPE_GMCH_DATA_N(pipe), m_n.gmch_n);
738 I915_WRITE(PIPE_DP_LINK_M(pipe), m_n.link_m);
739 I915_WRITE(PIPE_DP_LINK_N(pipe), m_n.link_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700740 }
741}
742
743static void
744intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
745 struct drm_display_mode *adjusted_mode)
746{
Zhenyu Wange3421a12010-04-08 09:43:27 +0800747 struct drm_device *dev = encoder->dev;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100748 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Chris Wilson4ef69c72010-09-09 15:14:28 +0100749 struct drm_crtc *crtc = intel_dp->base.base.crtc;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700750 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
751
Chris Wilsone953fd72011-02-21 22:23:52 +0000752 intel_dp->DP = DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
753 intel_dp->DP |= intel_dp->color_range;
Adam Jackson9c9e7922010-04-05 17:57:59 -0400754
755 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
Chris Wilsonea5b2132010-08-04 13:50:23 +0100756 intel_dp->DP |= DP_SYNC_HS_HIGH;
Adam Jackson9c9e7922010-04-05 17:57:59 -0400757 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
Chris Wilsonea5b2132010-08-04 13:50:23 +0100758 intel_dp->DP |= DP_SYNC_VS_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700759
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700760 if (HAS_PCH_CPT(dev) && !is_edp(intel_dp))
Chris Wilsonea5b2132010-08-04 13:50:23 +0100761 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +0800762 else
Chris Wilsonea5b2132010-08-04 13:50:23 +0100763 intel_dp->DP |= DP_LINK_TRAIN_OFF;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700764
Chris Wilsonea5b2132010-08-04 13:50:23 +0100765 switch (intel_dp->lane_count) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700766 case 1:
Chris Wilsonea5b2132010-08-04 13:50:23 +0100767 intel_dp->DP |= DP_PORT_WIDTH_1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700768 break;
769 case 2:
Chris Wilsonea5b2132010-08-04 13:50:23 +0100770 intel_dp->DP |= DP_PORT_WIDTH_2;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700771 break;
772 case 4:
Chris Wilsonea5b2132010-08-04 13:50:23 +0100773 intel_dp->DP |= DP_PORT_WIDTH_4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700774 break;
775 }
Chris Wilsonea5b2132010-08-04 13:50:23 +0100776 if (intel_dp->has_audio)
777 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700778
Chris Wilsonea5b2132010-08-04 13:50:23 +0100779 memset(intel_dp->link_configuration, 0, DP_LINK_CONFIGURATION_SIZE);
780 intel_dp->link_configuration[0] = intel_dp->link_bw;
781 intel_dp->link_configuration[1] = intel_dp->lane_count;
Adam Jacksona2cab1b2011-07-12 17:38:05 -0400782 intel_dp->link_configuration[8] = DP_SET_ANSI_8B10B;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700783
784 /*
Adam Jackson9962c922010-05-13 14:45:42 -0400785 * Check for DPCD version > 1.1 and enhanced framing support
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700786 */
Jesse Barnes7183dc22011-07-07 11:10:58 -0700787 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
788 (intel_dp->dpcd[DP_MAX_LANE_COUNT] & DP_ENHANCED_FRAME_CAP)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100789 intel_dp->link_configuration[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
790 intel_dp->DP |= DP_ENHANCED_FRAMING;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700791 }
792
Zhenyu Wange3421a12010-04-08 09:43:27 +0800793 /* CPT DP's pipe select is decided in TRANS_DP_CTL */
794 if (intel_crtc->pipe == 1 && !HAS_PCH_CPT(dev))
Chris Wilsonea5b2132010-08-04 13:50:23 +0100795 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800796
Jesse Barnes895692b2010-10-07 16:01:23 -0700797 if (is_edp(intel_dp) && !is_pch_edp(intel_dp)) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800798 /* don't miss out required setting for eDP */
Chris Wilsonea5b2132010-08-04 13:50:23 +0100799 intel_dp->DP |= DP_PLL_ENABLE;
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800800 if (adjusted_mode->clock < 200000)
Chris Wilsonea5b2132010-08-04 13:50:23 +0100801 intel_dp->DP |= DP_PLL_FREQ_160MHZ;
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800802 else
Chris Wilsonea5b2132010-08-04 13:50:23 +0100803 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800804 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700805}
806
Jesse Barnes5d613502011-01-24 17:10:54 -0800807static void ironlake_edp_panel_vdd_on(struct intel_dp *intel_dp)
808{
809 struct drm_device *dev = intel_dp->base.base.dev;
810 struct drm_i915_private *dev_priv = dev->dev_private;
811 u32 pp;
812
813 /*
814 * If the panel wasn't on, make sure there's not a currently
815 * active PP sequence before enabling AUX VDD.
816 */
817 if (!(I915_READ(PCH_PP_STATUS) & PP_ON))
818 msleep(dev_priv->panel_t3);
819
820 pp = I915_READ(PCH_PP_CONTROL);
821 pp |= EDP_FORCE_VDD;
822 I915_WRITE(PCH_PP_CONTROL, pp);
823 POSTING_READ(PCH_PP_CONTROL);
824}
825
826static void ironlake_edp_panel_vdd_off(struct intel_dp *intel_dp)
827{
828 struct drm_device *dev = intel_dp->base.base.dev;
829 struct drm_i915_private *dev_priv = dev->dev_private;
830 u32 pp;
831
832 pp = I915_READ(PCH_PP_CONTROL);
833 pp &= ~EDP_FORCE_VDD;
834 I915_WRITE(PCH_PP_CONTROL, pp);
835 POSTING_READ(PCH_PP_CONTROL);
836
837 /* Make sure sequencer is idle before allowing subsequent activity */
838 msleep(dev_priv->panel_t12);
839}
840
Jesse Barnes7eaf5542010-09-08 12:41:59 -0700841/* Returns true if the panel was already on when called */
Jesse Barnes01cb9ea2010-10-07 16:01:12 -0700842static bool ironlake_edp_panel_on (struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -0700843{
Jesse Barnes01cb9ea2010-10-07 16:01:12 -0700844 struct drm_device *dev = intel_dp->base.base.dev;
Jesse Barnes9934c132010-07-22 13:18:19 -0700845 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -0700846 u32 pp, idle_on_mask = PP_ON | PP_SEQUENCE_STATE_ON_IDLE;
Jesse Barnes9934c132010-07-22 13:18:19 -0700847
Chris Wilson913d8d12010-08-07 11:01:35 +0100848 if (I915_READ(PCH_PP_STATUS) & PP_ON)
Jesse Barnes7eaf5542010-09-08 12:41:59 -0700849 return true;
Jesse Barnes9934c132010-07-22 13:18:19 -0700850
851 pp = I915_READ(PCH_PP_CONTROL);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -0700852
853 /* ILK workaround: disable reset around power sequence */
854 pp &= ~PANEL_POWER_RESET;
855 I915_WRITE(PCH_PP_CONTROL, pp);
856 POSTING_READ(PCH_PP_CONTROL);
857
Jesse Barnes01cb9ea2010-10-07 16:01:12 -0700858 pp |= PANEL_UNLOCK_REGS | POWER_TARGET_ON;
Jesse Barnes9934c132010-07-22 13:18:19 -0700859 I915_WRITE(PCH_PP_CONTROL, pp);
Jesse Barnes01cb9ea2010-10-07 16:01:12 -0700860 POSTING_READ(PCH_PP_CONTROL);
Jesse Barnes9934c132010-07-22 13:18:19 -0700861
Jesse Barnes01cb9ea2010-10-07 16:01:12 -0700862 if (wait_for((I915_READ(PCH_PP_STATUS) & idle_on_mask) == idle_on_mask,
863 5000))
Chris Wilson913d8d12010-08-07 11:01:35 +0100864 DRM_ERROR("panel on wait timed out: 0x%08x\n",
865 I915_READ(PCH_PP_STATUS));
Jesse Barnes9934c132010-07-22 13:18:19 -0700866
Jesse Barnes37c6c9b2010-08-11 10:04:43 -0700867 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jesse Barnes9934c132010-07-22 13:18:19 -0700868 I915_WRITE(PCH_PP_CONTROL, pp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -0700869 POSTING_READ(PCH_PP_CONTROL);
Jesse Barnes7eaf5542010-09-08 12:41:59 -0700870
871 return false;
Jesse Barnes9934c132010-07-22 13:18:19 -0700872}
873
874static void ironlake_edp_panel_off (struct drm_device *dev)
875{
876 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -0700877 u32 pp, idle_off_mask = PP_ON | PP_SEQUENCE_MASK |
878 PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK;
Jesse Barnes9934c132010-07-22 13:18:19 -0700879
880 pp = I915_READ(PCH_PP_CONTROL);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -0700881
882 /* ILK workaround: disable reset around power sequence */
883 pp &= ~PANEL_POWER_RESET;
884 I915_WRITE(PCH_PP_CONTROL, pp);
885 POSTING_READ(PCH_PP_CONTROL);
886
Jesse Barnes9934c132010-07-22 13:18:19 -0700887 pp &= ~POWER_TARGET_ON;
888 I915_WRITE(PCH_PP_CONTROL, pp);
Jesse Barnes01cb9ea2010-10-07 16:01:12 -0700889 POSTING_READ(PCH_PP_CONTROL);
Jesse Barnes9934c132010-07-22 13:18:19 -0700890
Jesse Barnes01cb9ea2010-10-07 16:01:12 -0700891 if (wait_for((I915_READ(PCH_PP_STATUS) & idle_off_mask) == 0, 5000))
Chris Wilson913d8d12010-08-07 11:01:35 +0100892 DRM_ERROR("panel off wait timed out: 0x%08x\n",
893 I915_READ(PCH_PP_STATUS));
Jesse Barnes9934c132010-07-22 13:18:19 -0700894
Jesse Barnes3969c9c92010-09-08 12:42:03 -0700895 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jesse Barnes9934c132010-07-22 13:18:19 -0700896 I915_WRITE(PCH_PP_CONTROL, pp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -0700897 POSTING_READ(PCH_PP_CONTROL);
Jesse Barnes9934c132010-07-22 13:18:19 -0700898}
899
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500900static void ironlake_edp_backlight_on (struct drm_device *dev)
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800901{
902 struct drm_i915_private *dev_priv = dev->dev_private;
903 u32 pp;
904
Zhao Yakui28c97732009-10-09 11:39:41 +0800905 DRM_DEBUG_KMS("\n");
Jesse Barnes01cb9ea2010-10-07 16:01:12 -0700906 /*
907 * If we enable the backlight right away following a panel power
908 * on, we may see slight flicker as the panel syncs with the eDP
909 * link. So delay a bit to make sure the image is solid before
910 * allowing it to appear.
911 */
912 msleep(300);
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800913 pp = I915_READ(PCH_PP_CONTROL);
914 pp |= EDP_BLC_ENABLE;
915 I915_WRITE(PCH_PP_CONTROL, pp);
916}
917
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500918static void ironlake_edp_backlight_off (struct drm_device *dev)
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800919{
920 struct drm_i915_private *dev_priv = dev->dev_private;
921 u32 pp;
922
Zhao Yakui28c97732009-10-09 11:39:41 +0800923 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800924 pp = I915_READ(PCH_PP_CONTROL);
925 pp &= ~EDP_BLC_ENABLE;
926 I915_WRITE(PCH_PP_CONTROL, pp);
927}
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700928
Jesse Barnesd240f202010-08-13 15:43:26 -0700929static void ironlake_edp_pll_on(struct drm_encoder *encoder)
930{
931 struct drm_device *dev = encoder->dev;
932 struct drm_i915_private *dev_priv = dev->dev_private;
933 u32 dpa_ctl;
934
935 DRM_DEBUG_KMS("\n");
936 dpa_ctl = I915_READ(DP_A);
Jesse Barnes298b0b32010-10-07 16:01:24 -0700937 dpa_ctl |= DP_PLL_ENABLE;
Jesse Barnesd240f202010-08-13 15:43:26 -0700938 I915_WRITE(DP_A, dpa_ctl);
Jesse Barnes298b0b32010-10-07 16:01:24 -0700939 POSTING_READ(DP_A);
940 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -0700941}
942
943static void ironlake_edp_pll_off(struct drm_encoder *encoder)
944{
945 struct drm_device *dev = encoder->dev;
946 struct drm_i915_private *dev_priv = dev->dev_private;
947 u32 dpa_ctl;
948
949 dpa_ctl = I915_READ(DP_A);
Jesse Barnes298b0b32010-10-07 16:01:24 -0700950 dpa_ctl &= ~DP_PLL_ENABLE;
Jesse Barnesd240f202010-08-13 15:43:26 -0700951 I915_WRITE(DP_A, dpa_ctl);
Chris Wilson1af5fa12010-09-08 21:07:28 +0100952 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -0700953 udelay(200);
954}
955
Jesse Barnesc7ad3812011-07-07 11:11:03 -0700956/* If the sink supports it, try to set the power state appropriately */
957static void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
958{
959 int ret, i;
960
961 /* Should have a valid DPCD by this point */
962 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
963 return;
964
965 if (mode != DRM_MODE_DPMS_ON) {
966 ret = intel_dp_aux_native_write_1(intel_dp, DP_SET_POWER,
967 DP_SET_POWER_D3);
968 if (ret != 1)
969 DRM_DEBUG_DRIVER("failed to write sink power state\n");
970 } else {
971 /*
972 * When turning on, we need to retry for 1ms to give the sink
973 * time to wake up.
974 */
975 for (i = 0; i < 3; i++) {
976 ret = intel_dp_aux_native_write_1(intel_dp,
977 DP_SET_POWER,
978 DP_SET_POWER_D0);
979 if (ret == 1)
980 break;
981 msleep(1);
982 }
983 }
984}
985
Jesse Barnesd240f202010-08-13 15:43:26 -0700986static void intel_dp_prepare(struct drm_encoder *encoder)
987{
988 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
989 struct drm_device *dev = encoder->dev;
Jesse Barnesd240f202010-08-13 15:43:26 -0700990
Jesse Barnesc7ad3812011-07-07 11:11:03 -0700991 /* Wake up the sink first */
992 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
993
Jesse Barnes4d926462010-10-07 16:01:07 -0700994 if (is_edp(intel_dp)) {
Jesse Barnesd240f202010-08-13 15:43:26 -0700995 ironlake_edp_backlight_off(dev);
Jesse Barnes5d613502011-01-24 17:10:54 -0800996 ironlake_edp_panel_off(dev);
Jesse Barnes01cb9ea2010-10-07 16:01:12 -0700997 if (!is_pch_edp(intel_dp))
998 ironlake_edp_pll_on(encoder);
999 else
1000 ironlake_edp_pll_off(encoder);
Jesse Barnesd240f202010-08-13 15:43:26 -07001001 }
Jesse Barnes736085b2010-10-08 10:35:55 -07001002 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07001003}
1004
1005static void intel_dp_commit(struct drm_encoder *encoder)
1006{
1007 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1008 struct drm_device *dev = encoder->dev;
Jesse Barnesd240f202010-08-13 15:43:26 -07001009
Jesse Barnes5d613502011-01-24 17:10:54 -08001010 if (is_edp(intel_dp))
1011 ironlake_edp_panel_vdd_on(intel_dp);
1012
Jesse Barnes33a34e42010-09-08 12:42:02 -07001013 intel_dp_start_link_train(intel_dp);
1014
Jesse Barnes5d613502011-01-24 17:10:54 -08001015 if (is_edp(intel_dp)) {
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001016 ironlake_edp_panel_on(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001017 ironlake_edp_panel_vdd_off(intel_dp);
1018 }
Jesse Barnes33a34e42010-09-08 12:42:02 -07001019
1020 intel_dp_complete_link_train(intel_dp);
1021
Jesse Barnes4d926462010-10-07 16:01:07 -07001022 if (is_edp(intel_dp))
Jesse Barnesd240f202010-08-13 15:43:26 -07001023 ironlake_edp_backlight_on(dev);
Keith Packardd2b996a2011-07-25 22:37:51 -07001024
1025 intel_dp->dpms_mode = DRM_MODE_DPMS_ON;
Jesse Barnesd240f202010-08-13 15:43:26 -07001026}
1027
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001028static void
1029intel_dp_dpms(struct drm_encoder *encoder, int mode)
1030{
Chris Wilsonea5b2132010-08-04 13:50:23 +01001031 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08001032 struct drm_device *dev = encoder->dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001033 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001034 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001035
1036 if (mode != DRM_MODE_DPMS_ON) {
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001037 if (is_edp(intel_dp))
Jesse Barnes7643a7f2010-08-11 10:06:44 -07001038 ironlake_edp_backlight_off(dev);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001039 intel_dp_sink_dpms(intel_dp, mode);
Jesse Barnes736085b2010-10-08 10:35:55 -07001040 intel_dp_link_down(intel_dp);
Jesse Barnes4d926462010-10-07 16:01:07 -07001041 if (is_edp(intel_dp))
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001042 ironlake_edp_panel_off(dev);
1043 if (is_edp(intel_dp) && !is_pch_edp(intel_dp))
Jesse Barnesd240f202010-08-13 15:43:26 -07001044 ironlake_edp_pll_off(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001045 } else {
Jesse Barnes736085b2010-10-08 10:35:55 -07001046 if (is_edp(intel_dp))
Jesse Barnes5d613502011-01-24 17:10:54 -08001047 ironlake_edp_panel_vdd_on(intel_dp);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001048 intel_dp_sink_dpms(intel_dp, mode);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001049 if (!(dp_reg & DP_PORT_EN)) {
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001050 intel_dp_start_link_train(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001051 if (is_edp(intel_dp)) {
1052 ironlake_edp_panel_on(intel_dp);
1053 ironlake_edp_panel_vdd_off(intel_dp);
1054 }
Jesse Barnes33a34e42010-09-08 12:42:02 -07001055 intel_dp_complete_link_train(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001056 }
Jesse Barnes736085b2010-10-08 10:35:55 -07001057 if (is_edp(intel_dp))
1058 ironlake_edp_backlight_on(dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001059 }
Keith Packardd2b996a2011-07-25 22:37:51 -07001060 intel_dp->dpms_mode = mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001061}
1062
1063/*
Jesse Barnesdf0c2372011-07-07 11:11:02 -07001064 * Native read with retry for link status and receiver capability reads for
1065 * cases where the sink may still be asleep.
1066 */
1067static bool
1068intel_dp_aux_native_read_retry(struct intel_dp *intel_dp, uint16_t address,
1069 uint8_t *recv, int recv_bytes)
1070{
1071 int ret, i;
1072
1073 /*
1074 * Sinks are *supposed* to come up within 1ms from an off state,
1075 * but we're also supposed to retry 3 times per the spec.
1076 */
1077 for (i = 0; i < 3; i++) {
1078 ret = intel_dp_aux_native_read(intel_dp, address, recv,
1079 recv_bytes);
1080 if (ret == recv_bytes)
1081 return true;
1082 msleep(1);
1083 }
1084
1085 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001086}
1087
1088/*
1089 * Fetch AUX CH registers 0x202 - 0x207 which contain
1090 * link status information
1091 */
1092static bool
Jesse Barnes33a34e42010-09-08 12:42:02 -07001093intel_dp_get_link_status(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001094{
Jesse Barnesdf0c2372011-07-07 11:11:02 -07001095 return intel_dp_aux_native_read_retry(intel_dp,
1096 DP_LANE0_1_STATUS,
1097 intel_dp->link_status,
1098 DP_LINK_STATUS_SIZE);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001099}
1100
1101static uint8_t
1102intel_dp_link_status(uint8_t link_status[DP_LINK_STATUS_SIZE],
1103 int r)
1104{
1105 return link_status[r - DP_LANE0_1_STATUS];
1106}
1107
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001108static uint8_t
1109intel_get_adjust_request_voltage(uint8_t link_status[DP_LINK_STATUS_SIZE],
1110 int lane)
1111{
1112 int i = DP_ADJUST_REQUEST_LANE0_1 + (lane >> 1);
1113 int s = ((lane & 1) ?
1114 DP_ADJUST_VOLTAGE_SWING_LANE1_SHIFT :
1115 DP_ADJUST_VOLTAGE_SWING_LANE0_SHIFT);
1116 uint8_t l = intel_dp_link_status(link_status, i);
1117
1118 return ((l >> s) & 3) << DP_TRAIN_VOLTAGE_SWING_SHIFT;
1119}
1120
1121static uint8_t
1122intel_get_adjust_request_pre_emphasis(uint8_t link_status[DP_LINK_STATUS_SIZE],
1123 int lane)
1124{
1125 int i = DP_ADJUST_REQUEST_LANE0_1 + (lane >> 1);
1126 int s = ((lane & 1) ?
1127 DP_ADJUST_PRE_EMPHASIS_LANE1_SHIFT :
1128 DP_ADJUST_PRE_EMPHASIS_LANE0_SHIFT);
1129 uint8_t l = intel_dp_link_status(link_status, i);
1130
1131 return ((l >> s) & 3) << DP_TRAIN_PRE_EMPHASIS_SHIFT;
1132}
1133
1134
1135#if 0
1136static char *voltage_names[] = {
1137 "0.4V", "0.6V", "0.8V", "1.2V"
1138};
1139static char *pre_emph_names[] = {
1140 "0dB", "3.5dB", "6dB", "9.5dB"
1141};
1142static char *link_train_names[] = {
1143 "pattern 1", "pattern 2", "idle", "off"
1144};
1145#endif
1146
1147/*
1148 * These are source-specific values; current Intel hardware supports
1149 * a maximum voltage of 800mV and a maximum pre-emphasis of 6dB
1150 */
1151#define I830_DP_VOLTAGE_MAX DP_TRAIN_VOLTAGE_SWING_800
1152
1153static uint8_t
1154intel_dp_pre_emphasis_max(uint8_t voltage_swing)
1155{
1156 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
1157 case DP_TRAIN_VOLTAGE_SWING_400:
1158 return DP_TRAIN_PRE_EMPHASIS_6;
1159 case DP_TRAIN_VOLTAGE_SWING_600:
1160 return DP_TRAIN_PRE_EMPHASIS_6;
1161 case DP_TRAIN_VOLTAGE_SWING_800:
1162 return DP_TRAIN_PRE_EMPHASIS_3_5;
1163 case DP_TRAIN_VOLTAGE_SWING_1200:
1164 default:
1165 return DP_TRAIN_PRE_EMPHASIS_0;
1166 }
1167}
1168
1169static void
Jesse Barnes33a34e42010-09-08 12:42:02 -07001170intel_get_adjust_train(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001171{
1172 uint8_t v = 0;
1173 uint8_t p = 0;
1174 int lane;
1175
Jesse Barnes33a34e42010-09-08 12:42:02 -07001176 for (lane = 0; lane < intel_dp->lane_count; lane++) {
1177 uint8_t this_v = intel_get_adjust_request_voltage(intel_dp->link_status, lane);
1178 uint8_t this_p = intel_get_adjust_request_pre_emphasis(intel_dp->link_status, lane);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001179
1180 if (this_v > v)
1181 v = this_v;
1182 if (this_p > p)
1183 p = this_p;
1184 }
1185
1186 if (v >= I830_DP_VOLTAGE_MAX)
1187 v = I830_DP_VOLTAGE_MAX | DP_TRAIN_MAX_SWING_REACHED;
1188
1189 if (p >= intel_dp_pre_emphasis_max(v))
1190 p = intel_dp_pre_emphasis_max(v) | DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
1191
1192 for (lane = 0; lane < 4; lane++)
Jesse Barnes33a34e42010-09-08 12:42:02 -07001193 intel_dp->train_set[lane] = v | p;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001194}
1195
1196static uint32_t
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001197intel_dp_signal_levels(uint8_t train_set, int lane_count)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001198{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001199 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001200
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001201 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001202 case DP_TRAIN_VOLTAGE_SWING_400:
1203 default:
1204 signal_levels |= DP_VOLTAGE_0_4;
1205 break;
1206 case DP_TRAIN_VOLTAGE_SWING_600:
1207 signal_levels |= DP_VOLTAGE_0_6;
1208 break;
1209 case DP_TRAIN_VOLTAGE_SWING_800:
1210 signal_levels |= DP_VOLTAGE_0_8;
1211 break;
1212 case DP_TRAIN_VOLTAGE_SWING_1200:
1213 signal_levels |= DP_VOLTAGE_1_2;
1214 break;
1215 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001216 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001217 case DP_TRAIN_PRE_EMPHASIS_0:
1218 default:
1219 signal_levels |= DP_PRE_EMPHASIS_0;
1220 break;
1221 case DP_TRAIN_PRE_EMPHASIS_3_5:
1222 signal_levels |= DP_PRE_EMPHASIS_3_5;
1223 break;
1224 case DP_TRAIN_PRE_EMPHASIS_6:
1225 signal_levels |= DP_PRE_EMPHASIS_6;
1226 break;
1227 case DP_TRAIN_PRE_EMPHASIS_9_5:
1228 signal_levels |= DP_PRE_EMPHASIS_9_5;
1229 break;
1230 }
1231 return signal_levels;
1232}
1233
Zhenyu Wange3421a12010-04-08 09:43:27 +08001234/* Gen6's DP voltage swing and pre-emphasis control */
1235static uint32_t
1236intel_gen6_edp_signal_levels(uint8_t train_set)
1237{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001238 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
1239 DP_TRAIN_PRE_EMPHASIS_MASK);
1240 switch (signal_levels) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08001241 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001242 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
1243 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
1244 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
1245 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001246 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001247 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
1248 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001249 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001250 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
1251 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001252 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001253 case DP_TRAIN_VOLTAGE_SWING_1200 | DP_TRAIN_PRE_EMPHASIS_0:
1254 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001255 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001256 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
1257 "0x%x\n", signal_levels);
1258 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001259 }
1260}
1261
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001262static uint8_t
1263intel_get_lane_status(uint8_t link_status[DP_LINK_STATUS_SIZE],
1264 int lane)
1265{
1266 int i = DP_LANE0_1_STATUS + (lane >> 1);
1267 int s = (lane & 1) * 4;
1268 uint8_t l = intel_dp_link_status(link_status, i);
1269
1270 return (l >> s) & 0xf;
1271}
1272
1273/* Check for clock recovery is done on all channels */
1274static bool
1275intel_clock_recovery_ok(uint8_t link_status[DP_LINK_STATUS_SIZE], int lane_count)
1276{
1277 int lane;
1278 uint8_t lane_status;
1279
1280 for (lane = 0; lane < lane_count; lane++) {
1281 lane_status = intel_get_lane_status(link_status, lane);
1282 if ((lane_status & DP_LANE_CR_DONE) == 0)
1283 return false;
1284 }
1285 return true;
1286}
1287
1288/* Check to see if channel eq is done on all channels */
1289#define CHANNEL_EQ_BITS (DP_LANE_CR_DONE|\
1290 DP_LANE_CHANNEL_EQ_DONE|\
1291 DP_LANE_SYMBOL_LOCKED)
1292static bool
Jesse Barnes33a34e42010-09-08 12:42:02 -07001293intel_channel_eq_ok(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001294{
1295 uint8_t lane_align;
1296 uint8_t lane_status;
1297 int lane;
1298
Jesse Barnes33a34e42010-09-08 12:42:02 -07001299 lane_align = intel_dp_link_status(intel_dp->link_status,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001300 DP_LANE_ALIGN_STATUS_UPDATED);
1301 if ((lane_align & DP_INTERLANE_ALIGN_DONE) == 0)
1302 return false;
Jesse Barnes33a34e42010-09-08 12:42:02 -07001303 for (lane = 0; lane < intel_dp->lane_count; lane++) {
1304 lane_status = intel_get_lane_status(intel_dp->link_status, lane);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001305 if ((lane_status & CHANNEL_EQ_BITS) != CHANNEL_EQ_BITS)
1306 return false;
1307 }
1308 return true;
1309}
1310
1311static bool
Chris Wilsonea5b2132010-08-04 13:50:23 +01001312intel_dp_set_link_train(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001313 uint32_t dp_reg_value,
Chris Wilson58e10eb2010-10-03 10:56:11 +01001314 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001315{
Chris Wilson4ef69c72010-09-09 15:14:28 +01001316 struct drm_device *dev = intel_dp->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001317 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001318 int ret;
1319
Chris Wilsonea5b2132010-08-04 13:50:23 +01001320 I915_WRITE(intel_dp->output_reg, dp_reg_value);
1321 POSTING_READ(intel_dp->output_reg);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001322
Chris Wilsonea5b2132010-08-04 13:50:23 +01001323 intel_dp_aux_native_write_1(intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001324 DP_TRAINING_PATTERN_SET,
1325 dp_train_pat);
1326
Chris Wilsonea5b2132010-08-04 13:50:23 +01001327 ret = intel_dp_aux_native_write(intel_dp,
Chris Wilson58e10eb2010-10-03 10:56:11 +01001328 DP_TRAINING_LANE0_SET,
1329 intel_dp->train_set, 4);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001330 if (ret != 4)
1331 return false;
1332
1333 return true;
1334}
1335
Jesse Barnes33a34e42010-09-08 12:42:02 -07001336/* Enable corresponding port and start training pattern 1 */
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001337static void
Jesse Barnes33a34e42010-09-08 12:42:02 -07001338intel_dp_start_link_train(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001339{
Chris Wilson4ef69c72010-09-09 15:14:28 +01001340 struct drm_device *dev = intel_dp->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001341 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson58e10eb2010-10-03 10:56:11 +01001342 struct intel_crtc *intel_crtc = to_intel_crtc(intel_dp->base.base.crtc);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001343 int i;
1344 uint8_t voltage;
1345 bool clock_recovery = false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001346 int tries;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001347 u32 reg;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001348 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001349
Adam Jacksone8519462011-07-21 17:48:38 -04001350 /*
1351 * On CPT we have to enable the port in training pattern 1, which
1352 * will happen below in intel_dp_set_link_train. Otherwise, enable
1353 * the port and wait for it to become active.
1354 */
1355 if (!HAS_PCH_CPT(dev)) {
1356 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
1357 POSTING_READ(intel_dp->output_reg);
1358 intel_wait_for_vblank(dev, intel_crtc->pipe);
1359 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001360
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001361 /* Write the link configuration data */
1362 intel_dp_aux_native_write(intel_dp, DP_LINK_BW_SET,
1363 intel_dp->link_configuration,
1364 DP_LINK_CONFIGURATION_SIZE);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001365
1366 DP |= DP_PORT_EN;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001367 if (HAS_PCH_CPT(dev) && !is_edp(intel_dp))
Zhenyu Wange3421a12010-04-08 09:43:27 +08001368 DP &= ~DP_LINK_TRAIN_MASK_CPT;
1369 else
1370 DP &= ~DP_LINK_TRAIN_MASK;
Jesse Barnes33a34e42010-09-08 12:42:02 -07001371 memset(intel_dp->train_set, 0, 4);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001372 voltage = 0xff;
1373 tries = 0;
1374 clock_recovery = false;
1375 for (;;) {
Jesse Barnes33a34e42010-09-08 12:42:02 -07001376 /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */
Zhenyu Wange3421a12010-04-08 09:43:27 +08001377 uint32_t signal_levels;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001378 if (IS_GEN6(dev) && is_edp(intel_dp)) {
Jesse Barnes33a34e42010-09-08 12:42:02 -07001379 signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001380 DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels;
1381 } else {
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001382 signal_levels = intel_dp_signal_levels(intel_dp->train_set[0], intel_dp->lane_count);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001383 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
1384 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001385
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001386 if (HAS_PCH_CPT(dev) && !is_edp(intel_dp))
Zhenyu Wange3421a12010-04-08 09:43:27 +08001387 reg = DP | DP_LINK_TRAIN_PAT_1_CPT;
1388 else
1389 reg = DP | DP_LINK_TRAIN_PAT_1;
1390
Chris Wilsonea5b2132010-08-04 13:50:23 +01001391 if (!intel_dp_set_link_train(intel_dp, reg,
Adam Jackson81055852011-07-21 17:48:37 -04001392 DP_TRAINING_PATTERN_1 |
1393 DP_LINK_SCRAMBLING_DISABLE))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001394 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001395 /* Set training pattern 1 */
1396
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001397 udelay(100);
1398 if (!intel_dp_get_link_status(intel_dp))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001399 break;
1400
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001401 if (intel_clock_recovery_ok(intel_dp->link_status, intel_dp->lane_count)) {
1402 clock_recovery = true;
1403 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001404 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001405
1406 /* Check to see if we've tried the max voltage */
1407 for (i = 0; i < intel_dp->lane_count; i++)
1408 if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
1409 break;
1410 if (i == intel_dp->lane_count)
1411 break;
1412
1413 /* Check to see if we've tried the same voltage 5 times */
1414 if ((intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) == voltage) {
1415 ++tries;
1416 if (tries == 5)
1417 break;
1418 } else
1419 tries = 0;
1420 voltage = intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
1421
1422 /* Compute new intel_dp->train_set as requested by target */
1423 intel_get_adjust_train(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001424 }
1425
Jesse Barnes33a34e42010-09-08 12:42:02 -07001426 intel_dp->DP = DP;
1427}
1428
1429static void
1430intel_dp_complete_link_train(struct intel_dp *intel_dp)
1431{
Chris Wilson4ef69c72010-09-09 15:14:28 +01001432 struct drm_device *dev = intel_dp->base.base.dev;
Jesse Barnes33a34e42010-09-08 12:42:02 -07001433 struct drm_i915_private *dev_priv = dev->dev_private;
1434 bool channel_eq = false;
Jesse Barnes37f80972011-01-05 14:45:24 -08001435 int tries, cr_tries;
Jesse Barnes33a34e42010-09-08 12:42:02 -07001436 u32 reg;
1437 uint32_t DP = intel_dp->DP;
1438
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001439 /* channel equalization */
1440 tries = 0;
Jesse Barnes37f80972011-01-05 14:45:24 -08001441 cr_tries = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001442 channel_eq = false;
1443 for (;;) {
Jesse Barnes33a34e42010-09-08 12:42:02 -07001444 /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */
Zhenyu Wange3421a12010-04-08 09:43:27 +08001445 uint32_t signal_levels;
1446
Jesse Barnes37f80972011-01-05 14:45:24 -08001447 if (cr_tries > 5) {
1448 DRM_ERROR("failed to train DP, aborting\n");
1449 intel_dp_link_down(intel_dp);
1450 break;
1451 }
1452
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001453 if (IS_GEN6(dev) && is_edp(intel_dp)) {
Jesse Barnes33a34e42010-09-08 12:42:02 -07001454 signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001455 DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels;
1456 } else {
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001457 signal_levels = intel_dp_signal_levels(intel_dp->train_set[0], intel_dp->lane_count);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001458 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
1459 }
1460
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001461 if (HAS_PCH_CPT(dev) && !is_edp(intel_dp))
Zhenyu Wange3421a12010-04-08 09:43:27 +08001462 reg = DP | DP_LINK_TRAIN_PAT_2_CPT;
1463 else
1464 reg = DP | DP_LINK_TRAIN_PAT_2;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001465
1466 /* channel eq pattern */
Chris Wilsonea5b2132010-08-04 13:50:23 +01001467 if (!intel_dp_set_link_train(intel_dp, reg,
Adam Jackson81055852011-07-21 17:48:37 -04001468 DP_TRAINING_PATTERN_2 |
1469 DP_LINK_SCRAMBLING_DISABLE))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001470 break;
1471
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001472 udelay(400);
1473 if (!intel_dp_get_link_status(intel_dp))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001474 break;
Jesse Barnes869184a2010-10-07 16:01:22 -07001475
Jesse Barnes37f80972011-01-05 14:45:24 -08001476 /* Make sure clock is still ok */
1477 if (!intel_clock_recovery_ok(intel_dp->link_status, intel_dp->lane_count)) {
1478 intel_dp_start_link_train(intel_dp);
1479 cr_tries++;
1480 continue;
1481 }
1482
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001483 if (intel_channel_eq_ok(intel_dp)) {
1484 channel_eq = true;
1485 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001486 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001487
Jesse Barnes37f80972011-01-05 14:45:24 -08001488 /* Try 5 times, then try clock recovery if that fails */
1489 if (tries > 5) {
1490 intel_dp_link_down(intel_dp);
1491 intel_dp_start_link_train(intel_dp);
1492 tries = 0;
1493 cr_tries++;
1494 continue;
1495 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001496
1497 /* Compute new intel_dp->train_set as requested by target */
1498 intel_get_adjust_train(intel_dp);
1499 ++tries;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001500 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001501
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001502 if (HAS_PCH_CPT(dev) && !is_edp(intel_dp))
Zhenyu Wange3421a12010-04-08 09:43:27 +08001503 reg = DP | DP_LINK_TRAIN_OFF_CPT;
1504 else
1505 reg = DP | DP_LINK_TRAIN_OFF;
1506
Chris Wilsonea5b2132010-08-04 13:50:23 +01001507 I915_WRITE(intel_dp->output_reg, reg);
1508 POSTING_READ(intel_dp->output_reg);
1509 intel_dp_aux_native_write_1(intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001510 DP_TRAINING_PATTERN_SET, DP_TRAINING_PATTERN_DISABLE);
1511}
1512
1513static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01001514intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001515{
Chris Wilson4ef69c72010-09-09 15:14:28 +01001516 struct drm_device *dev = intel_dp->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001517 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001518 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001519
Chris Wilson1b39d6f2010-12-06 11:20:45 +00001520 if ((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0)
1521 return;
1522
Zhao Yakui28c97732009-10-09 11:39:41 +08001523 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001524
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001525 if (is_edp(intel_dp)) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001526 DP &= ~DP_PLL_ENABLE;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001527 I915_WRITE(intel_dp->output_reg, DP);
1528 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001529 udelay(100);
1530 }
1531
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001532 if (HAS_PCH_CPT(dev) && !is_edp(intel_dp)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08001533 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001534 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001535 } else {
1536 DP &= ~DP_LINK_TRAIN_MASK;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001537 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001538 }
Chris Wilsonfe255d02010-09-11 21:37:48 +01001539 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001540
Chris Wilsonfe255d02010-09-11 21:37:48 +01001541 msleep(17);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001542
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001543 if (is_edp(intel_dp))
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001544 DP |= DP_LINK_TRAIN_OFF;
Eric Anholt5bddd172010-11-18 09:32:59 +08001545
Chris Wilson1b39d6f2010-12-06 11:20:45 +00001546 if (!HAS_PCH_CPT(dev) &&
1547 I915_READ(intel_dp->output_reg) & DP_PIPEB_SELECT) {
Chris Wilson31acbcc2011-04-17 06:38:35 +01001548 struct drm_crtc *crtc = intel_dp->base.base.crtc;
1549
Eric Anholt5bddd172010-11-18 09:32:59 +08001550 /* Hardware workaround: leaving our transcoder select
1551 * set to transcoder B while it's off will prevent the
1552 * corresponding HDMI output on transcoder A.
1553 *
1554 * Combine this with another hardware workaround:
1555 * transcoder select bit can only be cleared while the
1556 * port is enabled.
1557 */
1558 DP &= ~DP_PIPEB_SELECT;
1559 I915_WRITE(intel_dp->output_reg, DP);
1560
1561 /* Changes to enable or select take place the vblank
1562 * after being written.
1563 */
Chris Wilson31acbcc2011-04-17 06:38:35 +01001564 if (crtc == NULL) {
1565 /* We can arrive here never having been attached
1566 * to a CRTC, for instance, due to inheriting
1567 * random state from the BIOS.
1568 *
1569 * If the pipe is not running, play safe and
1570 * wait for the clocks to stabilise before
1571 * continuing.
1572 */
1573 POSTING_READ(intel_dp->output_reg);
1574 msleep(50);
1575 } else
1576 intel_wait_for_vblank(dev, to_intel_crtc(crtc)->pipe);
Eric Anholt5bddd172010-11-18 09:32:59 +08001577 }
1578
Chris Wilsonea5b2132010-08-04 13:50:23 +01001579 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
1580 POSTING_READ(intel_dp->output_reg);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001581}
1582
Keith Packard26d61aa2011-07-25 20:01:09 -07001583static bool
1584intel_dp_get_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07001585{
Keith Packard92fd8fd2011-07-25 19:50:10 -07001586 if (intel_dp_aux_native_read_retry(intel_dp, 0x000, intel_dp->dpcd,
1587 sizeof (intel_dp->dpcd)) &&
1588 (intel_dp->dpcd[DP_DPCD_REV] != 0)) {
Keith Packard26d61aa2011-07-25 20:01:09 -07001589 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07001590 }
1591
Keith Packard26d61aa2011-07-25 20:01:09 -07001592 return false;
Keith Packard92fd8fd2011-07-25 19:50:10 -07001593}
1594
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001595/*
1596 * According to DP spec
1597 * 5.1.2:
1598 * 1. Read DPCD
1599 * 2. Configure link according to Receiver Capabilities
1600 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
1601 * 4. Check link status on receipt of hot-plug interrupt
1602 */
1603
1604static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01001605intel_dp_check_link_status(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001606{
Keith Packardd2b996a2011-07-25 22:37:51 -07001607 if (intel_dp->dpms_mode != DRM_MODE_DPMS_ON)
1608 return;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07001609
Chris Wilson4ef69c72010-09-09 15:14:28 +01001610 if (!intel_dp->base.base.crtc)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001611 return;
1612
Keith Packard92fd8fd2011-07-25 19:50:10 -07001613 /* Try to read receiver status if the link appears to be up */
Jesse Barnes33a34e42010-09-08 12:42:02 -07001614 if (!intel_dp_get_link_status(intel_dp)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001615 intel_dp_link_down(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001616 return;
1617 }
1618
Keith Packard92fd8fd2011-07-25 19:50:10 -07001619 /* Now read the DPCD to see if it's actually running */
Keith Packard26d61aa2011-07-25 20:01:09 -07001620 if (!intel_dp_get_dpcd(intel_dp)) {
Jesse Barnes59cd09e2011-07-07 11:10:59 -07001621 intel_dp_link_down(intel_dp);
1622 return;
1623 }
1624
Jesse Barnes33a34e42010-09-08 12:42:02 -07001625 if (!intel_channel_eq_ok(intel_dp)) {
Keith Packard92fd8fd2011-07-25 19:50:10 -07001626 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
1627 drm_get_encoder_name(&intel_dp->base.base));
Jesse Barnes33a34e42010-09-08 12:42:02 -07001628 intel_dp_start_link_train(intel_dp);
1629 intel_dp_complete_link_train(intel_dp);
1630 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001631}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001632
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001633static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07001634intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba9002011-07-12 17:38:04 -04001635{
Keith Packard26d61aa2011-07-25 20:01:09 -07001636 if (intel_dp_get_dpcd(intel_dp))
1637 return connector_status_connected;
1638 return connector_status_disconnected;
Adam Jackson71ba9002011-07-12 17:38:04 -04001639}
1640
1641static enum drm_connector_status
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001642ironlake_dp_detect(struct intel_dp *intel_dp)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001643{
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001644 enum drm_connector_status status;
1645
Chris Wilsonfe16d942011-02-12 10:29:38 +00001646 /* Can't disconnect eDP, but you can close the lid... */
1647 if (is_edp(intel_dp)) {
1648 status = intel_panel_detect(intel_dp->base.base.dev);
1649 if (status == connector_status_unknown)
1650 status = connector_status_connected;
1651 return status;
1652 }
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001653
Keith Packard26d61aa2011-07-25 20:01:09 -07001654 return intel_dp_detect_dpcd(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001655}
1656
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001657static enum drm_connector_status
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001658g4x_dp_detect(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001659{
Chris Wilson4ef69c72010-09-09 15:14:28 +01001660 struct drm_device *dev = intel_dp->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001661 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001662 uint32_t temp, bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001663
Chris Wilsonea5b2132010-08-04 13:50:23 +01001664 switch (intel_dp->output_reg) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001665 case DP_B:
1666 bit = DPB_HOTPLUG_INT_STATUS;
1667 break;
1668 case DP_C:
1669 bit = DPC_HOTPLUG_INT_STATUS;
1670 break;
1671 case DP_D:
1672 bit = DPD_HOTPLUG_INT_STATUS;
1673 break;
1674 default:
1675 return connector_status_unknown;
1676 }
1677
1678 temp = I915_READ(PORT_HOTPLUG_STAT);
1679
1680 if ((temp & bit) == 0)
1681 return connector_status_disconnected;
1682
Keith Packard26d61aa2011-07-25 20:01:09 -07001683 return intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001684}
1685
1686/**
1687 * Uses CRT_HOTPLUG_EN and CRT_HOTPLUG_STAT to detect DP connection.
1688 *
1689 * \return true if DP port is connected.
1690 * \return false if DP port is disconnected.
1691 */
1692static enum drm_connector_status
1693intel_dp_detect(struct drm_connector *connector, bool force)
1694{
1695 struct intel_dp *intel_dp = intel_attached_dp(connector);
1696 struct drm_device *dev = intel_dp->base.base.dev;
1697 enum drm_connector_status status;
1698 struct edid *edid = NULL;
1699
1700 intel_dp->has_audio = false;
1701
1702 if (HAS_PCH_SPLIT(dev))
1703 status = ironlake_dp_detect(intel_dp);
1704 else
1705 status = g4x_dp_detect(intel_dp);
Adam Jackson1b9be9d2011-07-12 17:38:01 -04001706
Adam Jacksonac66ae82011-07-12 17:38:03 -04001707 DRM_DEBUG_KMS("DPCD: %02hx%02hx%02hx%02hx%02hx%02hx%02hx%02hx\n",
1708 intel_dp->dpcd[0], intel_dp->dpcd[1], intel_dp->dpcd[2],
1709 intel_dp->dpcd[3], intel_dp->dpcd[4], intel_dp->dpcd[5],
1710 intel_dp->dpcd[6], intel_dp->dpcd[7]);
Adam Jackson1b9be9d2011-07-12 17:38:01 -04001711
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001712 if (status != connector_status_connected)
1713 return status;
1714
Chris Wilsonf6849602010-09-19 09:29:33 +01001715 if (intel_dp->force_audio) {
1716 intel_dp->has_audio = intel_dp->force_audio > 0;
1717 } else {
1718 edid = drm_get_edid(connector, &intel_dp->adapter);
1719 if (edid) {
1720 intel_dp->has_audio = drm_detect_monitor_audio(edid);
1721 connector->display_info.raw_edid = NULL;
1722 kfree(edid);
1723 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001724 }
1725
1726 return connector_status_connected;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001727}
1728
1729static int intel_dp_get_modes(struct drm_connector *connector)
1730{
Chris Wilsondf0e9242010-09-09 16:20:55 +01001731 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson4ef69c72010-09-09 15:14:28 +01001732 struct drm_device *dev = intel_dp->base.base.dev;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001733 struct drm_i915_private *dev_priv = dev->dev_private;
1734 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001735
1736 /* We should parse the EDID data and find out if it has an audio sink
1737 */
1738
Chris Wilsonf899fc62010-07-20 15:44:45 -07001739 ret = intel_ddc_get_modes(connector, &intel_dp->adapter);
Zhao Yakuib9efc482010-07-19 09:43:11 +01001740 if (ret) {
Jesse Barnes4d926462010-10-07 16:01:07 -07001741 if (is_edp(intel_dp) && !dev_priv->panel_fixed_mode) {
Zhao Yakuib9efc482010-07-19 09:43:11 +01001742 struct drm_display_mode *newmode;
1743 list_for_each_entry(newmode, &connector->probed_modes,
1744 head) {
1745 if (newmode->type & DRM_MODE_TYPE_PREFERRED) {
1746 dev_priv->panel_fixed_mode =
1747 drm_mode_duplicate(dev, newmode);
1748 break;
1749 }
1750 }
1751 }
1752
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001753 return ret;
Zhao Yakuib9efc482010-07-19 09:43:11 +01001754 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001755
1756 /* if eDP has no EDID, try to use fixed panel mode from VBT */
Jesse Barnes4d926462010-10-07 16:01:07 -07001757 if (is_edp(intel_dp)) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001758 if (dev_priv->panel_fixed_mode != NULL) {
1759 struct drm_display_mode *mode;
1760 mode = drm_mode_duplicate(dev, dev_priv->panel_fixed_mode);
1761 drm_mode_probed_add(connector, mode);
1762 return 1;
1763 }
1764 }
1765 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001766}
1767
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001768static bool
1769intel_dp_detect_audio(struct drm_connector *connector)
1770{
1771 struct intel_dp *intel_dp = intel_attached_dp(connector);
1772 struct edid *edid;
1773 bool has_audio = false;
1774
1775 edid = drm_get_edid(connector, &intel_dp->adapter);
1776 if (edid) {
1777 has_audio = drm_detect_monitor_audio(edid);
1778
1779 connector->display_info.raw_edid = NULL;
1780 kfree(edid);
1781 }
1782
1783 return has_audio;
1784}
1785
Chris Wilsonf6849602010-09-19 09:29:33 +01001786static int
1787intel_dp_set_property(struct drm_connector *connector,
1788 struct drm_property *property,
1789 uint64_t val)
1790{
Chris Wilsone953fd72011-02-21 22:23:52 +00001791 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Chris Wilsonf6849602010-09-19 09:29:33 +01001792 struct intel_dp *intel_dp = intel_attached_dp(connector);
1793 int ret;
1794
1795 ret = drm_connector_property_set_value(connector, property, val);
1796 if (ret)
1797 return ret;
1798
Chris Wilson3f43c482011-05-12 22:17:24 +01001799 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001800 int i = val;
1801 bool has_audio;
1802
1803 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01001804 return 0;
1805
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001806 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01001807
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001808 if (i == 0)
1809 has_audio = intel_dp_detect_audio(connector);
1810 else
1811 has_audio = i > 0;
1812
1813 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01001814 return 0;
1815
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001816 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01001817 goto done;
1818 }
1819
Chris Wilsone953fd72011-02-21 22:23:52 +00001820 if (property == dev_priv->broadcast_rgb_property) {
1821 if (val == !!intel_dp->color_range)
1822 return 0;
1823
1824 intel_dp->color_range = val ? DP_COLOR_RANGE_16_235 : 0;
1825 goto done;
1826 }
1827
Chris Wilsonf6849602010-09-19 09:29:33 +01001828 return -EINVAL;
1829
1830done:
1831 if (intel_dp->base.base.crtc) {
1832 struct drm_crtc *crtc = intel_dp->base.base.crtc;
1833 drm_crtc_helper_set_mode(crtc, &crtc->mode,
1834 crtc->x, crtc->y,
1835 crtc->fb);
1836 }
1837
1838 return 0;
1839}
1840
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001841static void
1842intel_dp_destroy (struct drm_connector *connector)
1843{
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001844 drm_sysfs_connector_remove(connector);
1845 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08001846 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001847}
1848
Daniel Vetter24d05922010-08-20 18:08:28 +02001849static void intel_dp_encoder_destroy(struct drm_encoder *encoder)
1850{
1851 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1852
1853 i2c_del_adapter(&intel_dp->adapter);
1854 drm_encoder_cleanup(encoder);
1855 kfree(intel_dp);
1856}
1857
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001858static const struct drm_encoder_helper_funcs intel_dp_helper_funcs = {
1859 .dpms = intel_dp_dpms,
1860 .mode_fixup = intel_dp_mode_fixup,
Jesse Barnesd240f202010-08-13 15:43:26 -07001861 .prepare = intel_dp_prepare,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001862 .mode_set = intel_dp_mode_set,
Jesse Barnesd240f202010-08-13 15:43:26 -07001863 .commit = intel_dp_commit,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001864};
1865
1866static const struct drm_connector_funcs intel_dp_connector_funcs = {
1867 .dpms = drm_helper_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001868 .detect = intel_dp_detect,
1869 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01001870 .set_property = intel_dp_set_property,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001871 .destroy = intel_dp_destroy,
1872};
1873
1874static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
1875 .get_modes = intel_dp_get_modes,
1876 .mode_valid = intel_dp_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +01001877 .best_encoder = intel_best_encoder,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001878};
1879
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001880static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Daniel Vetter24d05922010-08-20 18:08:28 +02001881 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001882};
1883
Chris Wilson995b6762010-08-20 13:23:26 +01001884static void
Eric Anholt21d40d32010-03-25 11:11:14 -07001885intel_dp_hot_plug(struct intel_encoder *intel_encoder)
Keith Packardc8110e52009-05-06 11:51:10 -07001886{
Chris Wilsonea5b2132010-08-04 13:50:23 +01001887 struct intel_dp *intel_dp = container_of(intel_encoder, struct intel_dp, base);
Keith Packardc8110e52009-05-06 11:51:10 -07001888
Jesse Barnes885a5012011-07-07 11:11:01 -07001889 intel_dp_check_link_status(intel_dp);
Keith Packardc8110e52009-05-06 11:51:10 -07001890}
1891
Zhenyu Wange3421a12010-04-08 09:43:27 +08001892/* Return which DP Port should be selected for Transcoder DP control */
1893int
1894intel_trans_dp_port_sel (struct drm_crtc *crtc)
1895{
1896 struct drm_device *dev = crtc->dev;
1897 struct drm_mode_config *mode_config = &dev->mode_config;
1898 struct drm_encoder *encoder;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001899
1900 list_for_each_entry(encoder, &mode_config->encoder_list, head) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001901 struct intel_dp *intel_dp;
1902
Dan Carpenterd8201ab2010-05-07 10:39:00 +02001903 if (encoder->crtc != crtc)
Zhenyu Wange3421a12010-04-08 09:43:27 +08001904 continue;
1905
Chris Wilsonea5b2132010-08-04 13:50:23 +01001906 intel_dp = enc_to_intel_dp(encoder);
1907 if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT)
1908 return intel_dp->output_reg;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001909 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01001910
Zhenyu Wange3421a12010-04-08 09:43:27 +08001911 return -1;
1912}
1913
Zhao Yakui36e83a12010-06-12 14:32:21 +08001914/* check the VBT to see whether the eDP is on DP-D port */
Adam Jacksoncb0953d2010-07-16 14:46:29 -04001915bool intel_dpd_is_edp(struct drm_device *dev)
Zhao Yakui36e83a12010-06-12 14:32:21 +08001916{
1917 struct drm_i915_private *dev_priv = dev->dev_private;
1918 struct child_device_config *p_child;
1919 int i;
1920
1921 if (!dev_priv->child_dev_num)
1922 return false;
1923
1924 for (i = 0; i < dev_priv->child_dev_num; i++) {
1925 p_child = dev_priv->child_dev + i;
1926
1927 if (p_child->dvo_port == PORT_IDPD &&
1928 p_child->device_type == DEVICE_TYPE_eDP)
1929 return true;
1930 }
1931 return false;
1932}
1933
Chris Wilsonf6849602010-09-19 09:29:33 +01001934static void
1935intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
1936{
Chris Wilson3f43c482011-05-12 22:17:24 +01001937 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00001938 intel_attach_broadcast_rgb_property(connector);
Chris Wilsonf6849602010-09-19 09:29:33 +01001939}
1940
Keith Packardc8110e52009-05-06 11:51:10 -07001941void
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001942intel_dp_init(struct drm_device *dev, int output_reg)
1943{
1944 struct drm_i915_private *dev_priv = dev->dev_private;
1945 struct drm_connector *connector;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001946 struct intel_dp *intel_dp;
Eric Anholt21d40d32010-03-25 11:11:14 -07001947 struct intel_encoder *intel_encoder;
Zhenyu Wang55f78c42010-03-29 16:13:57 +08001948 struct intel_connector *intel_connector;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001949 const char *name = NULL;
Adam Jacksonb3295302010-07-16 14:46:28 -04001950 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001951
Chris Wilsonea5b2132010-08-04 13:50:23 +01001952 intel_dp = kzalloc(sizeof(struct intel_dp), GFP_KERNEL);
1953 if (!intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001954 return;
1955
Chris Wilson3d3dc142011-02-12 10:33:12 +00001956 intel_dp->output_reg = output_reg;
Keith Packardd2b996a2011-07-25 22:37:51 -07001957 intel_dp->dpms_mode = -1;
Chris Wilson3d3dc142011-02-12 10:33:12 +00001958
Zhenyu Wang55f78c42010-03-29 16:13:57 +08001959 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
1960 if (!intel_connector) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001961 kfree(intel_dp);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08001962 return;
1963 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01001964 intel_encoder = &intel_dp->base;
Zhenyu Wang55f78c42010-03-29 16:13:57 +08001965
Chris Wilsonea5b2132010-08-04 13:50:23 +01001966 if (HAS_PCH_SPLIT(dev) && output_reg == PCH_DP_D)
Adam Jacksonb3295302010-07-16 14:46:28 -04001967 if (intel_dpd_is_edp(dev))
Chris Wilsonea5b2132010-08-04 13:50:23 +01001968 intel_dp->is_pch_edp = true;
Adam Jacksonb3295302010-07-16 14:46:28 -04001969
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001970 if (output_reg == DP_A || is_pch_edp(intel_dp)) {
Adam Jacksonb3295302010-07-16 14:46:28 -04001971 type = DRM_MODE_CONNECTOR_eDP;
1972 intel_encoder->type = INTEL_OUTPUT_EDP;
1973 } else {
1974 type = DRM_MODE_CONNECTOR_DisplayPort;
1975 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
1976 }
1977
Zhenyu Wang55f78c42010-03-29 16:13:57 +08001978 connector = &intel_connector->base;
Adam Jacksonb3295302010-07-16 14:46:28 -04001979 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001980 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
1981
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001982 connector->polled = DRM_CONNECTOR_POLL_HPD;
1983
Zhao Yakui652af9d2009-12-02 10:03:33 +08001984 if (output_reg == DP_B || output_reg == PCH_DP_B)
Eric Anholt21d40d32010-03-25 11:11:14 -07001985 intel_encoder->clone_mask = (1 << INTEL_DP_B_CLONE_BIT);
Zhao Yakui652af9d2009-12-02 10:03:33 +08001986 else if (output_reg == DP_C || output_reg == PCH_DP_C)
Eric Anholt21d40d32010-03-25 11:11:14 -07001987 intel_encoder->clone_mask = (1 << INTEL_DP_C_CLONE_BIT);
Zhao Yakui652af9d2009-12-02 10:03:33 +08001988 else if (output_reg == DP_D || output_reg == PCH_DP_D)
Eric Anholt21d40d32010-03-25 11:11:14 -07001989 intel_encoder->clone_mask = (1 << INTEL_DP_D_CLONE_BIT);
Ma Lingf8aed702009-08-24 13:50:24 +08001990
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001991 if (is_edp(intel_dp))
Eric Anholt21d40d32010-03-25 11:11:14 -07001992 intel_encoder->clone_mask = (1 << INTEL_EDP_CLONE_BIT);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08001993
Eric Anholt21d40d32010-03-25 11:11:14 -07001994 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001995 connector->interlace_allowed = true;
1996 connector->doublescan_allowed = 0;
1997
Chris Wilson4ef69c72010-09-09 15:14:28 +01001998 drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001999 DRM_MODE_ENCODER_TMDS);
Chris Wilson4ef69c72010-09-09 15:14:28 +01002000 drm_encoder_helper_add(&intel_encoder->base, &intel_dp_helper_funcs);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002001
Chris Wilsondf0e9242010-09-09 16:20:55 +01002002 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002003 drm_sysfs_connector_add(connector);
2004
2005 /* Set up the DDC bus. */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002006 switch (output_reg) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002007 case DP_A:
2008 name = "DPDDC-A";
2009 break;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002010 case DP_B:
2011 case PCH_DP_B:
Jesse Barnesb01f2c32009-12-11 11:07:17 -08002012 dev_priv->hotplug_supported_mask |=
2013 HDMIB_HOTPLUG_INT_STATUS;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002014 name = "DPDDC-B";
2015 break;
2016 case DP_C:
2017 case PCH_DP_C:
Jesse Barnesb01f2c32009-12-11 11:07:17 -08002018 dev_priv->hotplug_supported_mask |=
2019 HDMIC_HOTPLUG_INT_STATUS;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002020 name = "DPDDC-C";
2021 break;
2022 case DP_D:
2023 case PCH_DP_D:
Jesse Barnesb01f2c32009-12-11 11:07:17 -08002024 dev_priv->hotplug_supported_mask |=
2025 HDMID_HOTPLUG_INT_STATUS;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002026 name = "DPDDC-D";
2027 break;
2028 }
2029
Chris Wilsonea5b2132010-08-04 13:50:23 +01002030 intel_dp_i2c_init(intel_dp, intel_connector, name);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002031
Jesse Barnes89667382010-10-07 16:01:21 -07002032 /* Cache some DPCD data in the eDP case */
2033 if (is_edp(intel_dp)) {
Keith Packard59f3e272011-07-25 20:01:56 -07002034 bool ret;
Jesse Barnes5d613502011-01-24 17:10:54 -08002035 u32 pp_on, pp_div;
Jesse Barnes89667382010-10-07 16:01:21 -07002036
Jesse Barnes5d613502011-01-24 17:10:54 -08002037 pp_on = I915_READ(PCH_PP_ON_DELAYS);
2038 pp_div = I915_READ(PCH_PP_DIVISOR);
2039
2040 /* Get T3 & T12 values (note: VESA not bspec terminology) */
2041 dev_priv->panel_t3 = (pp_on & 0x1fff0000) >> 16;
2042 dev_priv->panel_t3 /= 10; /* t3 in 100us units */
2043 dev_priv->panel_t12 = pp_div & 0xf;
2044 dev_priv->panel_t12 *= 100; /* t12 in 100ms units */
2045
2046 ironlake_edp_panel_vdd_on(intel_dp);
Keith Packard59f3e272011-07-25 20:01:56 -07002047 ret = intel_dp_get_dpcd(intel_dp);
Chris Wilson3d3dc142011-02-12 10:33:12 +00002048 ironlake_edp_panel_vdd_off(intel_dp);
Keith Packard59f3e272011-07-25 20:01:56 -07002049 if (ret) {
Jesse Barnes7183dc22011-07-07 11:10:58 -07002050 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
2051 dev_priv->no_aux_handshake =
2052 intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
Jesse Barnes89667382010-10-07 16:01:21 -07002053 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
2054 } else {
Chris Wilson3d3dc142011-02-12 10:33:12 +00002055 /* if this fails, presume the device is a ghost */
Takashi Iwai48898b02011-03-18 09:06:49 +00002056 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Chris Wilson3d3dc142011-02-12 10:33:12 +00002057 intel_dp_encoder_destroy(&intel_dp->base.base);
Takashi Iwai48898b02011-03-18 09:06:49 +00002058 intel_dp_destroy(&intel_connector->base);
Chris Wilson3d3dc142011-02-12 10:33:12 +00002059 return;
Jesse Barnes89667382010-10-07 16:01:21 -07002060 }
Jesse Barnes89667382010-10-07 16:01:21 -07002061 }
2062
Eric Anholt21d40d32010-03-25 11:11:14 -07002063 intel_encoder->hot_plug = intel_dp_hot_plug;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002064
Jesse Barnes4d926462010-10-07 16:01:07 -07002065 if (is_edp(intel_dp)) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002066 /* initialize panel mode from VBT if available for eDP */
2067 if (dev_priv->lfp_lvds_vbt_mode) {
2068 dev_priv->panel_fixed_mode =
2069 drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);
2070 if (dev_priv->panel_fixed_mode) {
2071 dev_priv->panel_fixed_mode->type |=
2072 DRM_MODE_TYPE_PREFERRED;
2073 }
2074 }
2075 }
2076
Chris Wilsonf6849602010-09-19 09:29:33 +01002077 intel_dp_add_properties(intel_dp, connector);
2078
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002079 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
2080 * 0xd. Failure to do so will result in spurious interrupts being
2081 * generated on the port when a cable is not attached.
2082 */
2083 if (IS_G4X(dev) && !IS_GM45(dev)) {
2084 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
2085 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
2086 }
2087}