blob: f5303e18e791fdfcdb91aced530502193df8aa0e [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 Packardf01eca22011-09-28 16:48:10 -070062 int panel_power_up_delay;
63 int panel_power_down_delay;
64 int panel_power_cycle_delay;
65 int backlight_on_delay;
66 int backlight_off_delay;
Keith Packardd15456d2011-09-18 17:35:47 -070067 struct drm_display_mode *panel_fixed_mode; /* for eDP */
Keith Packardbd943152011-09-18 23:09:52 -070068 struct delayed_work panel_vdd_work;
69 bool want_panel_vdd;
70 unsigned long panel_off_jiffies;
Keith Packarda4fc5ed2009-04-07 16:16:42 -070071};
72
Jesse Barnescfcb0fc2010-10-07 16:01:06 -070073/**
74 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
75 * @intel_dp: DP struct
76 *
77 * If a CPU or PCH DP output is attached to an eDP panel, this function
78 * will return true, and false otherwise.
79 */
80static bool is_edp(struct intel_dp *intel_dp)
81{
82 return intel_dp->base.type == INTEL_OUTPUT_EDP;
83}
84
85/**
86 * is_pch_edp - is the port on the PCH and attached to an eDP panel?
87 * @intel_dp: DP struct
88 *
89 * Returns true if the given DP struct corresponds to a PCH DP port attached
90 * to an eDP panel, false otherwise. Helpful for determining whether we
91 * may need FDI resources for a given DP output or not.
92 */
93static bool is_pch_edp(struct intel_dp *intel_dp)
94{
95 return intel_dp->is_pch_edp;
96}
97
Chris Wilsonea5b2132010-08-04 13:50:23 +010098static struct intel_dp *enc_to_intel_dp(struct drm_encoder *encoder)
99{
Chris Wilson4ef69c72010-09-09 15:14:28 +0100100 return container_of(encoder, struct intel_dp, base.base);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100101}
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700102
Chris Wilsondf0e9242010-09-09 16:20:55 +0100103static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
104{
105 return container_of(intel_attached_encoder(connector),
106 struct intel_dp, base);
107}
108
Jesse Barnes814948a2010-10-07 16:01:09 -0700109/**
110 * intel_encoder_is_pch_edp - is the given encoder a PCH attached eDP?
111 * @encoder: DRM encoder
112 *
113 * Return true if @encoder corresponds to a PCH attached eDP panel. Needed
114 * by intel_display.c.
115 */
116bool intel_encoder_is_pch_edp(struct drm_encoder *encoder)
117{
118 struct intel_dp *intel_dp;
119
120 if (!encoder)
121 return false;
122
123 intel_dp = enc_to_intel_dp(encoder);
124
125 return is_pch_edp(intel_dp);
126}
127
Jesse Barnes33a34e42010-09-08 12:42:02 -0700128static void intel_dp_start_link_train(struct intel_dp *intel_dp);
129static void intel_dp_complete_link_train(struct intel_dp *intel_dp);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100130static void intel_dp_link_down(struct intel_dp *intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700131
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800132void
Eric Anholt21d40d32010-03-25 11:11:14 -0700133intel_edp_link_config (struct intel_encoder *intel_encoder,
Chris Wilsonea5b2132010-08-04 13:50:23 +0100134 int *lane_num, int *link_bw)
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800135{
Chris Wilsonea5b2132010-08-04 13:50:23 +0100136 struct intel_dp *intel_dp = container_of(intel_encoder, struct intel_dp, base);
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800137
Chris Wilsonea5b2132010-08-04 13:50:23 +0100138 *lane_num = intel_dp->lane_count;
139 if (intel_dp->link_bw == DP_LINK_BW_1_62)
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800140 *link_bw = 162000;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100141 else if (intel_dp->link_bw == DP_LINK_BW_2_7)
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800142 *link_bw = 270000;
143}
144
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700145static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100146intel_dp_max_lane_count(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700147{
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700148 int max_lane_count = 4;
149
Jesse Barnes7183dc22011-07-07 11:10:58 -0700150 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
151 max_lane_count = intel_dp->dpcd[DP_MAX_LANE_COUNT] & 0x1f;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700152 switch (max_lane_count) {
153 case 1: case 2: case 4:
154 break;
155 default:
156 max_lane_count = 4;
157 }
158 }
159 return max_lane_count;
160}
161
162static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100163intel_dp_max_link_bw(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700164{
Jesse Barnes7183dc22011-07-07 11:10:58 -0700165 int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700166
167 switch (max_link_bw) {
168 case DP_LINK_BW_1_62:
169 case DP_LINK_BW_2_7:
170 break;
171 default:
172 max_link_bw = DP_LINK_BW_1_62;
173 break;
174 }
175 return max_link_bw;
176}
177
178static int
179intel_dp_link_clock(uint8_t link_bw)
180{
181 if (link_bw == DP_LINK_BW_2_7)
182 return 270000;
183 else
184 return 162000;
185}
186
187/* I think this is a fiction */
188static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100189intel_dp_link_required(struct drm_device *dev, struct intel_dp *intel_dp, int pixel_clock)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700190{
Jesse Barnes89c61432011-06-24 12:19:28 -0700191 struct drm_crtc *crtc = intel_dp->base.base.crtc;
192 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
193 int bpp = 24;
Zhenyu Wang885a5fb2010-01-12 05:38:31 +0800194
Jesse Barnes89c61432011-06-24 12:19:28 -0700195 if (intel_crtc)
196 bpp = intel_crtc->bpp;
197
198 return (pixel_clock * bpp + 7) / 8;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700199}
200
201static int
Dave Airliefe27d532010-06-30 11:46:17 +1000202intel_dp_max_data_rate(int max_link_clock, int max_lanes)
203{
204 return (max_link_clock * max_lanes * 8) / 10;
205}
206
207static int
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700208intel_dp_mode_valid(struct drm_connector *connector,
209 struct drm_display_mode *mode)
210{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100211 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100212 int max_link_clock = intel_dp_link_clock(intel_dp_max_link_bw(intel_dp));
213 int max_lanes = intel_dp_max_lane_count(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700214
Keith Packardd15456d2011-09-18 17:35:47 -0700215 if (is_edp(intel_dp) && intel_dp->panel_fixed_mode) {
216 if (mode->hdisplay > intel_dp->panel_fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100217 return MODE_PANEL;
218
Keith Packardd15456d2011-09-18 17:35:47 -0700219 if (mode->vdisplay > intel_dp->panel_fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100220 return MODE_PANEL;
221 }
222
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300223 /* only refuse the mode on non eDP since we have seen some weird eDP panels
Dave Airliefe27d532010-06-30 11:46:17 +1000224 which are outside spec tolerances but somehow work by magic */
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700225 if (!is_edp(intel_dp) &&
Chris Wilsonea5b2132010-08-04 13:50:23 +0100226 (intel_dp_link_required(connector->dev, intel_dp, mode->clock)
Dave Airliefe27d532010-06-30 11:46:17 +1000227 > intel_dp_max_data_rate(max_link_clock, max_lanes)))
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700228 return MODE_CLOCK_HIGH;
229
230 if (mode->clock < 10000)
231 return MODE_CLOCK_LOW;
232
233 return MODE_OK;
234}
235
236static uint32_t
237pack_aux(uint8_t *src, int src_bytes)
238{
239 int i;
240 uint32_t v = 0;
241
242 if (src_bytes > 4)
243 src_bytes = 4;
244 for (i = 0; i < src_bytes; i++)
245 v |= ((uint32_t) src[i]) << ((3-i) * 8);
246 return v;
247}
248
249static void
250unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
251{
252 int i;
253 if (dst_bytes > 4)
254 dst_bytes = 4;
255 for (i = 0; i < dst_bytes; i++)
256 dst[i] = src >> ((3-i) * 8);
257}
258
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700259/* hrawclock is 1/4 the FSB frequency */
260static int
261intel_hrawclk(struct drm_device *dev)
262{
263 struct drm_i915_private *dev_priv = dev->dev_private;
264 uint32_t clkcfg;
265
266 clkcfg = I915_READ(CLKCFG);
267 switch (clkcfg & CLKCFG_FSB_MASK) {
268 case CLKCFG_FSB_400:
269 return 100;
270 case CLKCFG_FSB_533:
271 return 133;
272 case CLKCFG_FSB_667:
273 return 166;
274 case CLKCFG_FSB_800:
275 return 200;
276 case CLKCFG_FSB_1067:
277 return 266;
278 case CLKCFG_FSB_1333:
279 return 333;
280 /* these two are just a guess; one of them might be right */
281 case CLKCFG_FSB_1600:
282 case CLKCFG_FSB_1600_ALT:
283 return 400;
284 default:
285 return 133;
286 }
287}
288
Keith Packardebf33b12011-09-29 15:53:27 -0700289static bool ironlake_edp_have_panel_power(struct intel_dp *intel_dp)
290{
291 struct drm_device *dev = intel_dp->base.base.dev;
292 struct drm_i915_private *dev_priv = dev->dev_private;
293
294 return (I915_READ(PCH_PP_STATUS) & PP_ON) != 0;
295}
296
297static bool ironlake_edp_have_panel_vdd(struct intel_dp *intel_dp)
298{
299 struct drm_device *dev = intel_dp->base.base.dev;
300 struct drm_i915_private *dev_priv = dev->dev_private;
301
302 return (I915_READ(PCH_PP_CONTROL) & EDP_FORCE_VDD) != 0;
303}
304
Keith Packard9b984da2011-09-19 13:54:47 -0700305static void
306intel_dp_check_edp(struct intel_dp *intel_dp)
307{
308 struct drm_device *dev = intel_dp->base.base.dev;
309 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packardebf33b12011-09-29 15:53:27 -0700310
Keith Packard9b984da2011-09-19 13:54:47 -0700311 if (!is_edp(intel_dp))
312 return;
Keith Packardebf33b12011-09-29 15:53:27 -0700313 if (!ironlake_edp_have_panel_power(intel_dp) && !ironlake_edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700314 WARN(1, "eDP powered off while attempting aux channel communication.\n");
315 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Keith Packardebf33b12011-09-29 15:53:27 -0700316 I915_READ(PCH_PP_STATUS),
Keith Packard9b984da2011-09-19 13:54:47 -0700317 I915_READ(PCH_PP_CONTROL));
318 }
319}
320
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700321static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100322intel_dp_aux_ch(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700323 uint8_t *send, int send_bytes,
324 uint8_t *recv, int recv_size)
325{
Chris Wilsonea5b2132010-08-04 13:50:23 +0100326 uint32_t output_reg = intel_dp->output_reg;
Chris Wilson4ef69c72010-09-09 15:14:28 +0100327 struct drm_device *dev = intel_dp->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700328 struct drm_i915_private *dev_priv = dev->dev_private;
329 uint32_t ch_ctl = output_reg + 0x10;
330 uint32_t ch_data = ch_ctl + 4;
331 int i;
332 int recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700333 uint32_t status;
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700334 uint32_t aux_clock_divider;
Zhenyu Wange3421a12010-04-08 09:43:27 +0800335 int try, precharge;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700336
Keith Packard9b984da2011-09-19 13:54:47 -0700337 intel_dp_check_edp(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700338 /* The clock divider is based off the hrawclk,
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700339 * and would like to run at 2MHz. So, take the
340 * hrawclk value and divide by 2 and use that
Jesse Barnes6176b8f2010-09-08 12:42:00 -0700341 *
342 * Note that PCH attached eDP panels should use a 125MHz input
343 * clock divider.
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700344 */
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700345 if (is_edp(intel_dp) && !is_pch_edp(intel_dp)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +0800346 if (IS_GEN6(dev))
347 aux_clock_divider = 200; /* SNB eDP input clock at 400Mhz */
348 else
349 aux_clock_divider = 225; /* eDP input clock at 450Mhz */
350 } else if (HAS_PCH_SPLIT(dev))
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500351 aux_clock_divider = 62; /* IRL input clock fixed at 125Mhz */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +0800352 else
353 aux_clock_divider = intel_hrawclk(dev) / 2;
354
Zhenyu Wange3421a12010-04-08 09:43:27 +0800355 if (IS_GEN6(dev))
356 precharge = 3;
357 else
358 precharge = 5;
359
Jesse Barnes11bee432011-08-01 15:02:20 -0700360 /* Try to wait for any previous AUX channel activity */
361 for (try = 0; try < 3; try++) {
362 status = I915_READ(ch_ctl);
363 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
364 break;
365 msleep(1);
366 }
367
368 if (try == 3) {
369 WARN(1, "dp_aux_ch not started status 0x%08x\n",
370 I915_READ(ch_ctl));
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100371 return -EBUSY;
372 }
373
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700374 /* Must try at least 3 times according to DP spec */
375 for (try = 0; try < 5; try++) {
376 /* Load the send data into the aux channel data registers */
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100377 for (i = 0; i < send_bytes; i += 4)
378 I915_WRITE(ch_data + i,
379 pack_aux(send + i, send_bytes - i));
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700380
381 /* Send the command and wait for it to complete */
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100382 I915_WRITE(ch_ctl,
383 DP_AUX_CH_CTL_SEND_BUSY |
384 DP_AUX_CH_CTL_TIME_OUT_400us |
385 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
386 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
387 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT) |
388 DP_AUX_CH_CTL_DONE |
389 DP_AUX_CH_CTL_TIME_OUT_ERROR |
390 DP_AUX_CH_CTL_RECEIVE_ERROR);
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700391 for (;;) {
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700392 status = I915_READ(ch_ctl);
393 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
394 break;
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100395 udelay(100);
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700396 }
397
398 /* Clear done status and any errors */
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100399 I915_WRITE(ch_ctl,
400 status |
401 DP_AUX_CH_CTL_DONE |
402 DP_AUX_CH_CTL_TIME_OUT_ERROR |
403 DP_AUX_CH_CTL_RECEIVE_ERROR);
404 if (status & DP_AUX_CH_CTL_DONE)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700405 break;
406 }
407
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700408 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700409 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Keith Packarda5b3da52009-06-11 22:30:32 -0700410 return -EBUSY;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700411 }
412
413 /* Check for timeout or receive error.
414 * Timeouts occur when the sink is not connected
415 */
Keith Packarda5b3da52009-06-11 22:30:32 -0700416 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700417 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Keith Packarda5b3da52009-06-11 22:30:32 -0700418 return -EIO;
419 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700420
421 /* Timeouts occur when the device isn't connected, so they're
422 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -0700423 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Zhao Yakui28c97732009-10-09 11:39:41 +0800424 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Keith Packarda5b3da52009-06-11 22:30:32 -0700425 return -ETIMEDOUT;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700426 }
427
428 /* Unload any bytes sent back from the other side */
429 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
430 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700431 if (recv_bytes > recv_size)
432 recv_bytes = recv_size;
433
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100434 for (i = 0; i < recv_bytes; i += 4)
435 unpack_aux(I915_READ(ch_data + i),
436 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700437
438 return recv_bytes;
439}
440
441/* Write data to the aux channel in native mode */
442static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100443intel_dp_aux_native_write(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700444 uint16_t address, uint8_t *send, int send_bytes)
445{
446 int ret;
447 uint8_t msg[20];
448 int msg_bytes;
449 uint8_t ack;
450
Keith Packard9b984da2011-09-19 13:54:47 -0700451 intel_dp_check_edp(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700452 if (send_bytes > 16)
453 return -1;
454 msg[0] = AUX_NATIVE_WRITE << 4;
455 msg[1] = address >> 8;
Zhenyu Wangeebc8632009-07-24 01:00:30 +0800456 msg[2] = address & 0xff;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700457 msg[3] = send_bytes - 1;
458 memcpy(&msg[4], send, send_bytes);
459 msg_bytes = send_bytes + 4;
460 for (;;) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100461 ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes, &ack, 1);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700462 if (ret < 0)
463 return ret;
464 if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK)
465 break;
466 else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
467 udelay(100);
468 else
Keith Packarda5b3da52009-06-11 22:30:32 -0700469 return -EIO;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700470 }
471 return send_bytes;
472}
473
474/* Write a single byte to the aux channel in native mode */
475static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100476intel_dp_aux_native_write_1(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700477 uint16_t address, uint8_t byte)
478{
Chris Wilsonea5b2132010-08-04 13:50:23 +0100479 return intel_dp_aux_native_write(intel_dp, address, &byte, 1);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700480}
481
482/* read bytes from a native aux channel */
483static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100484intel_dp_aux_native_read(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700485 uint16_t address, uint8_t *recv, int recv_bytes)
486{
487 uint8_t msg[4];
488 int msg_bytes;
489 uint8_t reply[20];
490 int reply_bytes;
491 uint8_t ack;
492 int ret;
493
Keith Packard9b984da2011-09-19 13:54:47 -0700494 intel_dp_check_edp(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700495 msg[0] = AUX_NATIVE_READ << 4;
496 msg[1] = address >> 8;
497 msg[2] = address & 0xff;
498 msg[3] = recv_bytes - 1;
499
500 msg_bytes = 4;
501 reply_bytes = recv_bytes + 1;
502
503 for (;;) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100504 ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700505 reply, reply_bytes);
Keith Packarda5b3da52009-06-11 22:30:32 -0700506 if (ret == 0)
507 return -EPROTO;
508 if (ret < 0)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700509 return ret;
510 ack = reply[0];
511 if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK) {
512 memcpy(recv, reply + 1, ret - 1);
513 return ret - 1;
514 }
515 else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
516 udelay(100);
517 else
Keith Packarda5b3da52009-06-11 22:30:32 -0700518 return -EIO;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700519 }
520}
521
522static int
Dave Airlieab2c0672009-12-04 10:55:24 +1000523intel_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode,
524 uint8_t write_byte, uint8_t *read_byte)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700525{
Dave Airlieab2c0672009-12-04 10:55:24 +1000526 struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100527 struct intel_dp *intel_dp = container_of(adapter,
528 struct intel_dp,
529 adapter);
Dave Airlieab2c0672009-12-04 10:55:24 +1000530 uint16_t address = algo_data->address;
531 uint8_t msg[5];
532 uint8_t reply[2];
David Flynn8316f332010-12-08 16:10:21 +0000533 unsigned retry;
Dave Airlieab2c0672009-12-04 10:55:24 +1000534 int msg_bytes;
535 int reply_bytes;
536 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700537
Keith Packard9b984da2011-09-19 13:54:47 -0700538 intel_dp_check_edp(intel_dp);
Dave Airlieab2c0672009-12-04 10:55:24 +1000539 /* Set up the command byte */
540 if (mode & MODE_I2C_READ)
541 msg[0] = AUX_I2C_READ << 4;
542 else
543 msg[0] = AUX_I2C_WRITE << 4;
544
545 if (!(mode & MODE_I2C_STOP))
546 msg[0] |= AUX_I2C_MOT << 4;
547
548 msg[1] = address >> 8;
549 msg[2] = address;
550
551 switch (mode) {
552 case MODE_I2C_WRITE:
553 msg[3] = 0;
554 msg[4] = write_byte;
555 msg_bytes = 5;
556 reply_bytes = 1;
557 break;
558 case MODE_I2C_READ:
559 msg[3] = 0;
560 msg_bytes = 4;
561 reply_bytes = 2;
562 break;
563 default:
564 msg_bytes = 3;
565 reply_bytes = 1;
566 break;
567 }
568
David Flynn8316f332010-12-08 16:10:21 +0000569 for (retry = 0; retry < 5; retry++) {
570 ret = intel_dp_aux_ch(intel_dp,
571 msg, msg_bytes,
572 reply, reply_bytes);
Dave Airlieab2c0672009-12-04 10:55:24 +1000573 if (ret < 0) {
Dave Airlie3ff99162009-12-08 14:03:47 +1000574 DRM_DEBUG_KMS("aux_ch failed %d\n", ret);
Dave Airlieab2c0672009-12-04 10:55:24 +1000575 return ret;
576 }
David Flynn8316f332010-12-08 16:10:21 +0000577
578 switch (reply[0] & AUX_NATIVE_REPLY_MASK) {
579 case AUX_NATIVE_REPLY_ACK:
580 /* I2C-over-AUX Reply field is only valid
581 * when paired with AUX ACK.
582 */
583 break;
584 case AUX_NATIVE_REPLY_NACK:
585 DRM_DEBUG_KMS("aux_ch native nack\n");
586 return -EREMOTEIO;
587 case AUX_NATIVE_REPLY_DEFER:
588 udelay(100);
589 continue;
590 default:
591 DRM_ERROR("aux_ch invalid native reply 0x%02x\n",
592 reply[0]);
593 return -EREMOTEIO;
594 }
595
Dave Airlieab2c0672009-12-04 10:55:24 +1000596 switch (reply[0] & AUX_I2C_REPLY_MASK) {
597 case AUX_I2C_REPLY_ACK:
598 if (mode == MODE_I2C_READ) {
599 *read_byte = reply[1];
600 }
601 return reply_bytes - 1;
602 case AUX_I2C_REPLY_NACK:
David Flynn8316f332010-12-08 16:10:21 +0000603 DRM_DEBUG_KMS("aux_i2c nack\n");
Dave Airlieab2c0672009-12-04 10:55:24 +1000604 return -EREMOTEIO;
605 case AUX_I2C_REPLY_DEFER:
David Flynn8316f332010-12-08 16:10:21 +0000606 DRM_DEBUG_KMS("aux_i2c defer\n");
Dave Airlieab2c0672009-12-04 10:55:24 +1000607 udelay(100);
608 break;
609 default:
David Flynn8316f332010-12-08 16:10:21 +0000610 DRM_ERROR("aux_i2c invalid reply 0x%02x\n", reply[0]);
Dave Airlieab2c0672009-12-04 10:55:24 +1000611 return -EREMOTEIO;
612 }
613 }
David Flynn8316f332010-12-08 16:10:21 +0000614
615 DRM_ERROR("too many retries, giving up\n");
616 return -EREMOTEIO;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700617}
618
Keith Packard0b5c5412011-09-28 16:41:05 -0700619static void ironlake_edp_panel_vdd_on(struct intel_dp *intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -0700620static void ironlake_edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
Keith Packard0b5c5412011-09-28 16:41:05 -0700621
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700622static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100623intel_dp_i2c_init(struct intel_dp *intel_dp,
Zhenyu Wang55f78c42010-03-29 16:13:57 +0800624 struct intel_connector *intel_connector, const char *name)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700625{
Keith Packard0b5c5412011-09-28 16:41:05 -0700626 int ret;
627
Zhenyu Wangd54e9d22009-10-19 15:43:51 +0800628 DRM_DEBUG_KMS("i2c_init %s\n", name);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100629 intel_dp->algo.running = false;
630 intel_dp->algo.address = 0;
631 intel_dp->algo.aux_ch = intel_dp_i2c_aux_ch;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700632
Chris Wilsonea5b2132010-08-04 13:50:23 +0100633 memset(&intel_dp->adapter, '\0', sizeof (intel_dp->adapter));
634 intel_dp->adapter.owner = THIS_MODULE;
635 intel_dp->adapter.class = I2C_CLASS_DDC;
636 strncpy (intel_dp->adapter.name, name, sizeof(intel_dp->adapter.name) - 1);
637 intel_dp->adapter.name[sizeof(intel_dp->adapter.name) - 1] = '\0';
638 intel_dp->adapter.algo_data = &intel_dp->algo;
639 intel_dp->adapter.dev.parent = &intel_connector->base.kdev;
640
Keith Packard0b5c5412011-09-28 16:41:05 -0700641 ironlake_edp_panel_vdd_on(intel_dp);
642 ret = i2c_dp_aux_add_bus(&intel_dp->adapter);
Keith Packardbd943152011-09-18 23:09:52 -0700643 ironlake_edp_panel_vdd_off(intel_dp, false);
Keith Packard0b5c5412011-09-28 16:41:05 -0700644 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700645}
646
647static bool
648intel_dp_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode,
649 struct drm_display_mode *adjusted_mode)
650{
Zhao Yakui0d3a1be2010-07-19 09:43:13 +0100651 struct drm_device *dev = encoder->dev;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100652 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700653 int lane_count, clock;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100654 int max_lane_count = intel_dp_max_lane_count(intel_dp);
655 int max_clock = intel_dp_max_link_bw(intel_dp) == DP_LINK_BW_2_7 ? 1 : 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700656 static int bws[2] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7 };
657
Keith Packardd15456d2011-09-18 17:35:47 -0700658 if (is_edp(intel_dp) && intel_dp->panel_fixed_mode) {
659 intel_fixed_panel_mode(intel_dp->panel_fixed_mode, adjusted_mode);
Chris Wilson1d8e1c72010-08-07 11:01:28 +0100660 intel_pch_panel_fitting(dev, DRM_MODE_SCALE_FULLSCREEN,
661 mode, adjusted_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +0100662 /*
663 * the mode->clock is used to calculate the Data&Link M/N
664 * of the pipe. For the eDP the fixed clock should be used.
665 */
Keith Packardd15456d2011-09-18 17:35:47 -0700666 mode->clock = intel_dp->panel_fixed_mode->clock;
Zhao Yakui0d3a1be2010-07-19 09:43:13 +0100667 }
668
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700669 for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) {
670 for (clock = 0; clock <= max_clock; clock++) {
Dave Airliefe27d532010-06-30 11:46:17 +1000671 int link_avail = intel_dp_max_data_rate(intel_dp_link_clock(bws[clock]), lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700672
Chris Wilsonea5b2132010-08-04 13:50:23 +0100673 if (intel_dp_link_required(encoder->dev, intel_dp, mode->clock)
Zhenyu Wang885a5fb2010-01-12 05:38:31 +0800674 <= link_avail) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100675 intel_dp->link_bw = bws[clock];
676 intel_dp->lane_count = lane_count;
677 adjusted_mode->clock = intel_dp_link_clock(intel_dp->link_bw);
Zhao Yakui28c97732009-10-09 11:39:41 +0800678 DRM_DEBUG_KMS("Display port link bw %02x lane "
679 "count %d clock %d\n",
Chris Wilsonea5b2132010-08-04 13:50:23 +0100680 intel_dp->link_bw, intel_dp->lane_count,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700681 adjusted_mode->clock);
682 return true;
683 }
684 }
685 }
Dave Airliefe27d532010-06-30 11:46:17 +1000686
Chris Wilson3cf2efb2010-11-29 10:09:55 +0000687 if (is_edp(intel_dp)) {
688 /* okay we failed just pick the highest */
689 intel_dp->lane_count = max_lane_count;
690 intel_dp->link_bw = bws[max_clock];
691 adjusted_mode->clock = intel_dp_link_clock(intel_dp->link_bw);
692 DRM_DEBUG_KMS("Force picking display port link bw %02x lane "
693 "count %d clock %d\n",
694 intel_dp->link_bw, intel_dp->lane_count,
695 adjusted_mode->clock);
696
697 return true;
698 }
699
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700700 return false;
701}
702
703struct intel_dp_m_n {
704 uint32_t tu;
705 uint32_t gmch_m;
706 uint32_t gmch_n;
707 uint32_t link_m;
708 uint32_t link_n;
709};
710
711static void
712intel_reduce_ratio(uint32_t *num, uint32_t *den)
713{
714 while (*num > 0xffffff || *den > 0xffffff) {
715 *num >>= 1;
716 *den >>= 1;
717 }
718}
719
720static void
Zhao Yakui36e83a12010-06-12 14:32:21 +0800721intel_dp_compute_m_n(int bpp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700722 int nlanes,
723 int pixel_clock,
724 int link_clock,
725 struct intel_dp_m_n *m_n)
726{
727 m_n->tu = 64;
Zhao Yakui36e83a12010-06-12 14:32:21 +0800728 m_n->gmch_m = (pixel_clock * bpp) >> 3;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700729 m_n->gmch_n = link_clock * nlanes;
730 intel_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
731 m_n->link_m = pixel_clock;
732 m_n->link_n = link_clock;
733 intel_reduce_ratio(&m_n->link_m, &m_n->link_n);
734}
735
736void
737intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode,
738 struct drm_display_mode *adjusted_mode)
739{
740 struct drm_device *dev = crtc->dev;
741 struct drm_mode_config *mode_config = &dev->mode_config;
Zhenyu Wang55f78c42010-03-29 16:13:57 +0800742 struct drm_encoder *encoder;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700743 struct drm_i915_private *dev_priv = dev->dev_private;
744 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnes858fa0352011-06-24 12:19:24 -0700745 int lane_count = 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700746 struct intel_dp_m_n m_n;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800747 int pipe = intel_crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700748
749 /*
Eric Anholt21d40d32010-03-25 11:11:14 -0700750 * Find the lane count in the intel_encoder private
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700751 */
Zhenyu Wang55f78c42010-03-29 16:13:57 +0800752 list_for_each_entry(encoder, &mode_config->encoder_list, head) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100753 struct intel_dp *intel_dp;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700754
Dan Carpenterd8201ab2010-05-07 10:39:00 +0200755 if (encoder->crtc != crtc)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700756 continue;
757
Chris Wilsonea5b2132010-08-04 13:50:23 +0100758 intel_dp = enc_to_intel_dp(encoder);
759 if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT) {
760 lane_count = intel_dp->lane_count;
Jesse Barnes51190662010-10-07 16:01:08 -0700761 break;
762 } else if (is_edp(intel_dp)) {
763 lane_count = dev_priv->edp.lanes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700764 break;
765 }
766 }
767
768 /*
769 * Compute the GMCH and Link ratios. The '3' here is
770 * the number of bytes_per_pixel post-LUT, which we always
771 * set up for 8-bits of R/G/B, or 3 bytes total.
772 */
Jesse Barnes858fa0352011-06-24 12:19:24 -0700773 intel_dp_compute_m_n(intel_crtc->bpp, lane_count,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700774 mode->clock, adjusted_mode->clock, &m_n);
775
Eric Anholtc619eed2010-01-28 16:45:52 -0800776 if (HAS_PCH_SPLIT(dev)) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800777 I915_WRITE(TRANSDATA_M1(pipe),
778 ((m_n.tu - 1) << PIPE_GMCH_DATA_M_TU_SIZE_SHIFT) |
779 m_n.gmch_m);
780 I915_WRITE(TRANSDATA_N1(pipe), m_n.gmch_n);
781 I915_WRITE(TRANSDPLINK_M1(pipe), m_n.link_m);
782 I915_WRITE(TRANSDPLINK_N1(pipe), m_n.link_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700783 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800784 I915_WRITE(PIPE_GMCH_DATA_M(pipe),
785 ((m_n.tu - 1) << PIPE_GMCH_DATA_M_TU_SIZE_SHIFT) |
786 m_n.gmch_m);
787 I915_WRITE(PIPE_GMCH_DATA_N(pipe), m_n.gmch_n);
788 I915_WRITE(PIPE_DP_LINK_M(pipe), m_n.link_m);
789 I915_WRITE(PIPE_DP_LINK_N(pipe), m_n.link_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700790 }
791}
792
Keith Packardf01eca22011-09-28 16:48:10 -0700793static void ironlake_edp_pll_on(struct drm_encoder *encoder);
794static void ironlake_edp_pll_off(struct drm_encoder *encoder);
795
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700796static void
797intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
798 struct drm_display_mode *adjusted_mode)
799{
Zhenyu Wange3421a12010-04-08 09:43:27 +0800800 struct drm_device *dev = encoder->dev;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100801 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Chris Wilson4ef69c72010-09-09 15:14:28 +0100802 struct drm_crtc *crtc = intel_dp->base.base.crtc;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700803 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
804
Keith Packardf01eca22011-09-28 16:48:10 -0700805 /* Turn on the eDP PLL if needed */
806 if (is_edp(intel_dp)) {
807 if (!is_pch_edp(intel_dp))
808 ironlake_edp_pll_on(encoder);
809 else
810 ironlake_edp_pll_off(encoder);
811 }
812
Chris Wilsone953fd72011-02-21 22:23:52 +0000813 intel_dp->DP = DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
814 intel_dp->DP |= intel_dp->color_range;
Adam Jackson9c9e7922010-04-05 17:57:59 -0400815
816 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
Chris Wilsonea5b2132010-08-04 13:50:23 +0100817 intel_dp->DP |= DP_SYNC_HS_HIGH;
Adam Jackson9c9e7922010-04-05 17:57:59 -0400818 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
Chris Wilsonea5b2132010-08-04 13:50:23 +0100819 intel_dp->DP |= DP_SYNC_VS_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700820
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700821 if (HAS_PCH_CPT(dev) && !is_edp(intel_dp))
Chris Wilsonea5b2132010-08-04 13:50:23 +0100822 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +0800823 else
Chris Wilsonea5b2132010-08-04 13:50:23 +0100824 intel_dp->DP |= DP_LINK_TRAIN_OFF;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700825
Chris Wilsonea5b2132010-08-04 13:50:23 +0100826 switch (intel_dp->lane_count) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700827 case 1:
Chris Wilsonea5b2132010-08-04 13:50:23 +0100828 intel_dp->DP |= DP_PORT_WIDTH_1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700829 break;
830 case 2:
Chris Wilsonea5b2132010-08-04 13:50:23 +0100831 intel_dp->DP |= DP_PORT_WIDTH_2;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700832 break;
833 case 4:
Chris Wilsonea5b2132010-08-04 13:50:23 +0100834 intel_dp->DP |= DP_PORT_WIDTH_4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700835 break;
836 }
Chris Wilsonea5b2132010-08-04 13:50:23 +0100837 if (intel_dp->has_audio)
838 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700839
Chris Wilsonea5b2132010-08-04 13:50:23 +0100840 memset(intel_dp->link_configuration, 0, DP_LINK_CONFIGURATION_SIZE);
841 intel_dp->link_configuration[0] = intel_dp->link_bw;
842 intel_dp->link_configuration[1] = intel_dp->lane_count;
Adam Jacksona2cab1b2011-07-12 17:38:05 -0400843 intel_dp->link_configuration[8] = DP_SET_ANSI_8B10B;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700844
845 /*
Adam Jackson9962c922010-05-13 14:45:42 -0400846 * Check for DPCD version > 1.1 and enhanced framing support
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700847 */
Jesse Barnes7183dc22011-07-07 11:10:58 -0700848 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
849 (intel_dp->dpcd[DP_MAX_LANE_COUNT] & DP_ENHANCED_FRAME_CAP)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100850 intel_dp->link_configuration[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
851 intel_dp->DP |= DP_ENHANCED_FRAMING;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700852 }
853
Zhenyu Wange3421a12010-04-08 09:43:27 +0800854 /* CPT DP's pipe select is decided in TRANS_DP_CTL */
855 if (intel_crtc->pipe == 1 && !HAS_PCH_CPT(dev))
Chris Wilsonea5b2132010-08-04 13:50:23 +0100856 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800857
Jesse Barnes895692b2010-10-07 16:01:23 -0700858 if (is_edp(intel_dp) && !is_pch_edp(intel_dp)) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800859 /* don't miss out required setting for eDP */
Chris Wilsonea5b2132010-08-04 13:50:23 +0100860 intel_dp->DP |= DP_PLL_ENABLE;
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800861 if (adjusted_mode->clock < 200000)
Chris Wilsonea5b2132010-08-04 13:50:23 +0100862 intel_dp->DP |= DP_PLL_FREQ_160MHZ;
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800863 else
Chris Wilsonea5b2132010-08-04 13:50:23 +0100864 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800865 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700866}
867
Keith Packardbd943152011-09-18 23:09:52 -0700868static void ironlake_wait_panel_off(struct intel_dp *intel_dp)
869{
870 unsigned long off_time;
871 unsigned long delay;
872 DRM_DEBUG_KMS("Wait for panel power off time\n");
873 off_time = intel_dp->panel_off_jiffies + msecs_to_jiffies(intel_dp->panel_power_down_delay);
874 if (time_after(jiffies, off_time)) {
875 DRM_DEBUG_KMS("Time already passed");
876 return;
877 }
878 delay = jiffies_to_msecs(off_time - jiffies);
879 if (delay > intel_dp->panel_power_down_delay)
880 delay = intel_dp->panel_power_down_delay;
881 DRM_DEBUG_KMS("Waiting an additional %ld ms\n", delay);
882 msleep(delay);
883}
884
Jesse Barnes5d613502011-01-24 17:10:54 -0800885static void ironlake_edp_panel_vdd_on(struct intel_dp *intel_dp)
886{
887 struct drm_device *dev = intel_dp->base.base.dev;
888 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packardebf33b12011-09-29 15:53:27 -0700889 u32 pp;
Jesse Barnes5d613502011-01-24 17:10:54 -0800890
Keith Packard97af61f572011-09-28 16:23:51 -0700891 if (!is_edp(intel_dp))
892 return;
Keith Packardf01eca22011-09-28 16:48:10 -0700893 DRM_DEBUG_KMS("Turn eDP VDD on\n");
Jesse Barnes5d613502011-01-24 17:10:54 -0800894
Keith Packardbd943152011-09-18 23:09:52 -0700895 WARN(intel_dp->want_panel_vdd,
896 "eDP VDD already requested on\n");
897
898 intel_dp->want_panel_vdd = true;
899 if (ironlake_edp_have_panel_vdd(intel_dp)) {
900 DRM_DEBUG_KMS("eDP VDD already on\n");
901 return;
902 }
903
904 ironlake_wait_panel_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -0800905 pp = I915_READ(PCH_PP_CONTROL);
Keith Packard1c0ae802011-09-19 13:59:29 -0700906 pp &= ~PANEL_UNLOCK_MASK;
907 pp |= PANEL_UNLOCK_REGS;
Jesse Barnes5d613502011-01-24 17:10:54 -0800908 pp |= EDP_FORCE_VDD;
909 I915_WRITE(PCH_PP_CONTROL, pp);
910 POSTING_READ(PCH_PP_CONTROL);
Keith Packardf01eca22011-09-28 16:48:10 -0700911 DRM_DEBUG_KMS("PCH_PP_STATUS: 0x%08x PCH_PP_CONTROL: 0x%08x\n",
912 I915_READ(PCH_PP_STATUS), I915_READ(PCH_PP_CONTROL));
Keith Packardebf33b12011-09-29 15:53:27 -0700913
914 /*
915 * If the panel wasn't on, delay before accessing aux channel
916 */
917 if (!ironlake_edp_have_panel_power(intel_dp)) {
Keith Packardbd943152011-09-18 23:09:52 -0700918 DRM_DEBUG_KMS("eDP was not running\n");
Keith Packardf01eca22011-09-28 16:48:10 -0700919 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -0700920 }
Jesse Barnes5d613502011-01-24 17:10:54 -0800921}
922
Keith Packardbd943152011-09-18 23:09:52 -0700923static void ironlake_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -0800924{
925 struct drm_device *dev = intel_dp->base.base.dev;
926 struct drm_i915_private *dev_priv = dev->dev_private;
927 u32 pp;
928
Keith Packardbd943152011-09-18 23:09:52 -0700929 if (!intel_dp->want_panel_vdd && ironlake_edp_have_panel_vdd(intel_dp)) {
930 pp = I915_READ(PCH_PP_CONTROL);
931 pp &= ~PANEL_UNLOCK_MASK;
932 pp |= PANEL_UNLOCK_REGS;
933 pp &= ~EDP_FORCE_VDD;
934 I915_WRITE(PCH_PP_CONTROL, pp);
935 POSTING_READ(PCH_PP_CONTROL);
936
937 /* Make sure sequencer is idle before allowing subsequent activity */
938 DRM_DEBUG_KMS("PCH_PP_STATUS: 0x%08x PCH_PP_CONTROL: 0x%08x\n",
939 I915_READ(PCH_PP_STATUS), I915_READ(PCH_PP_CONTROL));
940 intel_dp->panel_off_jiffies = jiffies;
941 }
942}
943
944static void ironlake_panel_vdd_work(struct work_struct *__work)
945{
946 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
947 struct intel_dp, panel_vdd_work);
948 struct drm_device *dev = intel_dp->base.base.dev;
949
950 mutex_lock(&dev->struct_mutex);
951 ironlake_panel_vdd_off_sync(intel_dp);
952 mutex_unlock(&dev->struct_mutex);
953}
954
955static void ironlake_edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
956{
Keith Packard97af61f572011-09-28 16:23:51 -0700957 if (!is_edp(intel_dp))
958 return;
Jesse Barnes5d613502011-01-24 17:10:54 -0800959
Keith Packardbd943152011-09-18 23:09:52 -0700960 DRM_DEBUG_KMS("Turn eDP VDD off %d\n", intel_dp->want_panel_vdd);
961 WARN(!intel_dp->want_panel_vdd, "eDP VDD not forced on");
962
963 intel_dp->want_panel_vdd = false;
964
965 if (sync) {
966 ironlake_panel_vdd_off_sync(intel_dp);
967 } else {
968 /*
969 * Queue the timer to fire a long
970 * time from now (relative to the power down delay)
971 * to keep the panel power up across a sequence of operations
972 */
973 schedule_delayed_work(&intel_dp->panel_vdd_work,
974 msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5));
975 }
Jesse Barnes5d613502011-01-24 17:10:54 -0800976}
977
Jesse Barnes7eaf5542010-09-08 12:41:59 -0700978/* Returns true if the panel was already on when called */
Keith Packard7d639f32011-09-29 16:05:34 -0700979static void ironlake_edp_panel_on (struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -0700980{
Jesse Barnes01cb9ea2010-10-07 16:01:12 -0700981 struct drm_device *dev = intel_dp->base.base.dev;
Jesse Barnes9934c132010-07-22 13:18:19 -0700982 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -0700983 u32 pp, idle_on_mask = PP_ON | PP_SEQUENCE_STATE_ON_IDLE;
Jesse Barnes9934c132010-07-22 13:18:19 -0700984
Keith Packard97af61f572011-09-28 16:23:51 -0700985 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -0700986 return;
Keith Packardebf33b12011-09-29 15:53:27 -0700987 if (ironlake_edp_have_panel_power(intel_dp))
Keith Packard7d639f32011-09-29 16:05:34 -0700988 return;
Jesse Barnes9934c132010-07-22 13:18:19 -0700989
Keith Packardbd943152011-09-18 23:09:52 -0700990 ironlake_wait_panel_off(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -0700991 pp = I915_READ(PCH_PP_CONTROL);
Keith Packard1c0ae802011-09-19 13:59:29 -0700992 pp &= ~PANEL_UNLOCK_MASK;
993 pp |= PANEL_UNLOCK_REGS;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -0700994
Keith Packard05ce1a42011-09-29 16:33:01 -0700995 if (IS_GEN5(dev)) {
996 /* ILK workaround: disable reset around power sequence */
997 pp &= ~PANEL_POWER_RESET;
998 I915_WRITE(PCH_PP_CONTROL, pp);
999 POSTING_READ(PCH_PP_CONTROL);
1000 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001001
Keith Packard1c0ae802011-09-19 13:59:29 -07001002 pp |= POWER_TARGET_ON;
Jesse Barnes9934c132010-07-22 13:18:19 -07001003 I915_WRITE(PCH_PP_CONTROL, pp);
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001004 POSTING_READ(PCH_PP_CONTROL);
Jesse Barnes9934c132010-07-22 13:18:19 -07001005
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001006 if (wait_for((I915_READ(PCH_PP_STATUS) & idle_on_mask) == idle_on_mask,
1007 5000))
Chris Wilson913d8d12010-08-07 11:01:35 +01001008 DRM_ERROR("panel on wait timed out: 0x%08x\n",
1009 I915_READ(PCH_PP_STATUS));
Jesse Barnes9934c132010-07-22 13:18:19 -07001010
Keith Packard05ce1a42011-09-29 16:33:01 -07001011 if (IS_GEN5(dev)) {
1012 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
1013 I915_WRITE(PCH_PP_CONTROL, pp);
1014 POSTING_READ(PCH_PP_CONTROL);
1015 }
Jesse Barnes9934c132010-07-22 13:18:19 -07001016}
1017
Keith Packardf01eca22011-09-28 16:48:10 -07001018static void ironlake_edp_panel_off(struct drm_encoder *encoder)
Jesse Barnes9934c132010-07-22 13:18:19 -07001019{
Keith Packardf01eca22011-09-28 16:48:10 -07001020 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1021 struct drm_device *dev = encoder->dev;
Jesse Barnes9934c132010-07-22 13:18:19 -07001022 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001023 u32 pp, idle_off_mask = PP_ON | PP_SEQUENCE_MASK |
1024 PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK;
Jesse Barnes9934c132010-07-22 13:18:19 -07001025
Keith Packard97af61f572011-09-28 16:23:51 -07001026 if (!is_edp(intel_dp))
1027 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07001028 pp = I915_READ(PCH_PP_CONTROL);
Keith Packard1c0ae802011-09-19 13:59:29 -07001029 pp &= ~PANEL_UNLOCK_MASK;
1030 pp |= PANEL_UNLOCK_REGS;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001031
Keith Packard05ce1a42011-09-29 16:33:01 -07001032 if (IS_GEN5(dev)) {
1033 /* ILK workaround: disable reset around power sequence */
1034 pp &= ~PANEL_POWER_RESET;
1035 I915_WRITE(PCH_PP_CONTROL, pp);
1036 POSTING_READ(PCH_PP_CONTROL);
1037 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001038
Keith Packardbd943152011-09-18 23:09:52 -07001039 intel_dp->panel_off_jiffies = jiffies;
Keith Packard05ce1a42011-09-29 16:33:01 -07001040
1041 if (IS_GEN5(dev)) {
1042 pp &= ~POWER_TARGET_ON;
1043 I915_WRITE(PCH_PP_CONTROL, pp);
1044 POSTING_READ(PCH_PP_CONTROL);
1045 pp &= ~POWER_TARGET_ON;
1046 I915_WRITE(PCH_PP_CONTROL, pp);
1047 POSTING_READ(PCH_PP_CONTROL);
1048 msleep(intel_dp->panel_power_cycle_delay);
1049
1050 if (wait_for((I915_READ(PCH_PP_STATUS) & idle_off_mask) == 0, 5000))
1051 DRM_ERROR("panel off wait timed out: 0x%08x\n",
1052 I915_READ(PCH_PP_STATUS));
1053
1054 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
1055 I915_WRITE(PCH_PP_CONTROL, pp);
1056 POSTING_READ(PCH_PP_CONTROL);
1057 }
Jesse Barnes9934c132010-07-22 13:18:19 -07001058}
1059
Keith Packardf01eca22011-09-28 16:48:10 -07001060static void ironlake_edp_backlight_on (struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001061{
Keith Packardf01eca22011-09-28 16:48:10 -07001062 struct drm_device *dev = intel_dp->base.base.dev;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001063 struct drm_i915_private *dev_priv = dev->dev_private;
1064 u32 pp;
1065
Keith Packardf01eca22011-09-28 16:48:10 -07001066 if (!is_edp(intel_dp))
1067 return;
1068
Zhao Yakui28c97732009-10-09 11:39:41 +08001069 DRM_DEBUG_KMS("\n");
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001070 /*
1071 * If we enable the backlight right away following a panel power
1072 * on, we may see slight flicker as the panel syncs with the eDP
1073 * link. So delay a bit to make sure the image is solid before
1074 * allowing it to appear.
1075 */
Keith Packardf01eca22011-09-28 16:48:10 -07001076 msleep(intel_dp->backlight_on_delay);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001077 pp = I915_READ(PCH_PP_CONTROL);
Keith Packard1c0ae802011-09-19 13:59:29 -07001078 pp &= ~PANEL_UNLOCK_MASK;
1079 pp |= PANEL_UNLOCK_REGS;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001080 pp |= EDP_BLC_ENABLE;
1081 I915_WRITE(PCH_PP_CONTROL, pp);
Keith Packardf01eca22011-09-28 16:48:10 -07001082 POSTING_READ(PCH_PP_CONTROL);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001083}
1084
Keith Packardf01eca22011-09-28 16:48:10 -07001085static void ironlake_edp_backlight_off (struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001086{
Keith Packardf01eca22011-09-28 16:48:10 -07001087 struct drm_device *dev = intel_dp->base.base.dev;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001088 struct drm_i915_private *dev_priv = dev->dev_private;
1089 u32 pp;
1090
Keith Packardf01eca22011-09-28 16:48:10 -07001091 if (!is_edp(intel_dp))
1092 return;
1093
Zhao Yakui28c97732009-10-09 11:39:41 +08001094 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001095 pp = I915_READ(PCH_PP_CONTROL);
Keith Packard1c0ae802011-09-19 13:59:29 -07001096 pp &= ~PANEL_UNLOCK_MASK;
1097 pp |= PANEL_UNLOCK_REGS;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001098 pp &= ~EDP_BLC_ENABLE;
1099 I915_WRITE(PCH_PP_CONTROL, pp);
Keith Packardf01eca22011-09-28 16:48:10 -07001100 POSTING_READ(PCH_PP_CONTROL);
1101 msleep(intel_dp->backlight_off_delay);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001102}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001103
Jesse Barnesd240f202010-08-13 15:43:26 -07001104static void ironlake_edp_pll_on(struct drm_encoder *encoder)
1105{
1106 struct drm_device *dev = encoder->dev;
1107 struct drm_i915_private *dev_priv = dev->dev_private;
1108 u32 dpa_ctl;
1109
1110 DRM_DEBUG_KMS("\n");
1111 dpa_ctl = I915_READ(DP_A);
Jesse Barnes298b0b32010-10-07 16:01:24 -07001112 dpa_ctl |= DP_PLL_ENABLE;
Jesse Barnesd240f202010-08-13 15:43:26 -07001113 I915_WRITE(DP_A, dpa_ctl);
Jesse Barnes298b0b32010-10-07 16:01:24 -07001114 POSTING_READ(DP_A);
1115 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07001116}
1117
1118static void ironlake_edp_pll_off(struct drm_encoder *encoder)
1119{
1120 struct drm_device *dev = encoder->dev;
1121 struct drm_i915_private *dev_priv = dev->dev_private;
1122 u32 dpa_ctl;
1123
1124 dpa_ctl = I915_READ(DP_A);
Jesse Barnes298b0b32010-10-07 16:01:24 -07001125 dpa_ctl &= ~DP_PLL_ENABLE;
Jesse Barnesd240f202010-08-13 15:43:26 -07001126 I915_WRITE(DP_A, dpa_ctl);
Chris Wilson1af5fa12010-09-08 21:07:28 +01001127 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07001128 udelay(200);
1129}
1130
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001131/* If the sink supports it, try to set the power state appropriately */
1132static void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
1133{
1134 int ret, i;
1135
1136 /* Should have a valid DPCD by this point */
1137 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
1138 return;
1139
1140 if (mode != DRM_MODE_DPMS_ON) {
1141 ret = intel_dp_aux_native_write_1(intel_dp, DP_SET_POWER,
1142 DP_SET_POWER_D3);
1143 if (ret != 1)
1144 DRM_DEBUG_DRIVER("failed to write sink power state\n");
1145 } else {
1146 /*
1147 * When turning on, we need to retry for 1ms to give the sink
1148 * time to wake up.
1149 */
1150 for (i = 0; i < 3; i++) {
1151 ret = intel_dp_aux_native_write_1(intel_dp,
1152 DP_SET_POWER,
1153 DP_SET_POWER_D0);
1154 if (ret == 1)
1155 break;
1156 msleep(1);
1157 }
1158 }
1159}
1160
Jesse Barnesd240f202010-08-13 15:43:26 -07001161static void intel_dp_prepare(struct drm_encoder *encoder)
1162{
1163 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Jesse Barnesd240f202010-08-13 15:43:26 -07001164
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001165 /* Wake up the sink first */
Keith Packardf58ff852011-09-28 16:44:14 -07001166 ironlake_edp_panel_vdd_on(intel_dp);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001167 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
Keith Packardbd943152011-09-18 23:09:52 -07001168 ironlake_edp_panel_vdd_off(intel_dp, false);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001169
Keith Packardf01eca22011-09-28 16:48:10 -07001170 /* Make sure the panel is off before trying to
1171 * change the mode
1172 */
1173 ironlake_edp_backlight_off(intel_dp);
Jesse Barnes736085b2010-10-08 10:35:55 -07001174 intel_dp_link_down(intel_dp);
Keith Packardf01eca22011-09-28 16:48:10 -07001175 ironlake_edp_panel_off(encoder);
Jesse Barnesd240f202010-08-13 15:43:26 -07001176}
1177
1178static void intel_dp_commit(struct drm_encoder *encoder)
1179{
1180 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Jesse Barnesd240f202010-08-13 15:43:26 -07001181
Keith Packard97af61f572011-09-28 16:23:51 -07001182 ironlake_edp_panel_vdd_on(intel_dp);
Keith Packardf01eca22011-09-28 16:48:10 -07001183 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
Jesse Barnes33a34e42010-09-08 12:42:02 -07001184 intel_dp_start_link_train(intel_dp);
Keith Packard97af61f572011-09-28 16:23:51 -07001185 ironlake_edp_panel_on(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07001186 ironlake_edp_panel_vdd_off(intel_dp, true);
1187
Jesse Barnes33a34e42010-09-08 12:42:02 -07001188 intel_dp_complete_link_train(intel_dp);
Keith Packardf01eca22011-09-28 16:48:10 -07001189 ironlake_edp_backlight_on(intel_dp);
Keith Packardd2b996a2011-07-25 22:37:51 -07001190
1191 intel_dp->dpms_mode = DRM_MODE_DPMS_ON;
Jesse Barnesd240f202010-08-13 15:43:26 -07001192}
1193
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001194static void
1195intel_dp_dpms(struct drm_encoder *encoder, int mode)
1196{
Chris Wilsonea5b2132010-08-04 13:50:23 +01001197 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08001198 struct drm_device *dev = encoder->dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001199 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001200 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001201
1202 if (mode != DRM_MODE_DPMS_ON) {
Keith Packard245e2702011-10-05 19:53:09 -07001203 ironlake_edp_panel_vdd_on(intel_dp);
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001204 if (is_edp(intel_dp))
Keith Packardf01eca22011-09-28 16:48:10 -07001205 ironlake_edp_backlight_off(intel_dp);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001206 intel_dp_sink_dpms(intel_dp, mode);
Jesse Barnes736085b2010-10-08 10:35:55 -07001207 intel_dp_link_down(intel_dp);
Keith Packardf01eca22011-09-28 16:48:10 -07001208 ironlake_edp_panel_off(encoder);
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001209 if (is_edp(intel_dp) && !is_pch_edp(intel_dp))
Jesse Barnesd240f202010-08-13 15:43:26 -07001210 ironlake_edp_pll_off(encoder);
Keith Packardbd943152011-09-18 23:09:52 -07001211 ironlake_edp_panel_vdd_off(intel_dp, false);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001212 } else {
Keith Packard97af61f572011-09-28 16:23:51 -07001213 ironlake_edp_panel_vdd_on(intel_dp);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001214 intel_dp_sink_dpms(intel_dp, mode);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001215 if (!(dp_reg & DP_PORT_EN)) {
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001216 intel_dp_start_link_train(intel_dp);
Keith Packard97af61f572011-09-28 16:23:51 -07001217 ironlake_edp_panel_on(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07001218 ironlake_edp_panel_vdd_off(intel_dp, true);
Jesse Barnes33a34e42010-09-08 12:42:02 -07001219 intel_dp_complete_link_train(intel_dp);
Keith Packardf01eca22011-09-28 16:48:10 -07001220 ironlake_edp_backlight_on(intel_dp);
Keith Packardbee7eb22011-09-28 16:28:00 -07001221 } else
Keith Packardbd943152011-09-18 23:09:52 -07001222 ironlake_edp_panel_vdd_off(intel_dp, false);
1223 ironlake_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001224 }
Keith Packardd2b996a2011-07-25 22:37:51 -07001225 intel_dp->dpms_mode = mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001226}
1227
1228/*
Jesse Barnesdf0c2372011-07-07 11:11:02 -07001229 * Native read with retry for link status and receiver capability reads for
1230 * cases where the sink may still be asleep.
1231 */
1232static bool
1233intel_dp_aux_native_read_retry(struct intel_dp *intel_dp, uint16_t address,
1234 uint8_t *recv, int recv_bytes)
1235{
1236 int ret, i;
1237
1238 /*
1239 * Sinks are *supposed* to come up within 1ms from an off state,
1240 * but we're also supposed to retry 3 times per the spec.
1241 */
1242 for (i = 0; i < 3; i++) {
1243 ret = intel_dp_aux_native_read(intel_dp, address, recv,
1244 recv_bytes);
1245 if (ret == recv_bytes)
1246 return true;
1247 msleep(1);
1248 }
1249
1250 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001251}
1252
1253/*
1254 * Fetch AUX CH registers 0x202 - 0x207 which contain
1255 * link status information
1256 */
1257static bool
Jesse Barnes33a34e42010-09-08 12:42:02 -07001258intel_dp_get_link_status(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001259{
Jesse Barnesdf0c2372011-07-07 11:11:02 -07001260 return intel_dp_aux_native_read_retry(intel_dp,
1261 DP_LANE0_1_STATUS,
1262 intel_dp->link_status,
1263 DP_LINK_STATUS_SIZE);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001264}
1265
1266static uint8_t
1267intel_dp_link_status(uint8_t link_status[DP_LINK_STATUS_SIZE],
1268 int r)
1269{
1270 return link_status[r - DP_LANE0_1_STATUS];
1271}
1272
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001273static uint8_t
1274intel_get_adjust_request_voltage(uint8_t link_status[DP_LINK_STATUS_SIZE],
1275 int lane)
1276{
1277 int i = DP_ADJUST_REQUEST_LANE0_1 + (lane >> 1);
1278 int s = ((lane & 1) ?
1279 DP_ADJUST_VOLTAGE_SWING_LANE1_SHIFT :
1280 DP_ADJUST_VOLTAGE_SWING_LANE0_SHIFT);
1281 uint8_t l = intel_dp_link_status(link_status, i);
1282
1283 return ((l >> s) & 3) << DP_TRAIN_VOLTAGE_SWING_SHIFT;
1284}
1285
1286static uint8_t
1287intel_get_adjust_request_pre_emphasis(uint8_t link_status[DP_LINK_STATUS_SIZE],
1288 int lane)
1289{
1290 int i = DP_ADJUST_REQUEST_LANE0_1 + (lane >> 1);
1291 int s = ((lane & 1) ?
1292 DP_ADJUST_PRE_EMPHASIS_LANE1_SHIFT :
1293 DP_ADJUST_PRE_EMPHASIS_LANE0_SHIFT);
1294 uint8_t l = intel_dp_link_status(link_status, i);
1295
1296 return ((l >> s) & 3) << DP_TRAIN_PRE_EMPHASIS_SHIFT;
1297}
1298
1299
1300#if 0
1301static char *voltage_names[] = {
1302 "0.4V", "0.6V", "0.8V", "1.2V"
1303};
1304static char *pre_emph_names[] = {
1305 "0dB", "3.5dB", "6dB", "9.5dB"
1306};
1307static char *link_train_names[] = {
1308 "pattern 1", "pattern 2", "idle", "off"
1309};
1310#endif
1311
1312/*
1313 * These are source-specific values; current Intel hardware supports
1314 * a maximum voltage of 800mV and a maximum pre-emphasis of 6dB
1315 */
1316#define I830_DP_VOLTAGE_MAX DP_TRAIN_VOLTAGE_SWING_800
1317
1318static uint8_t
1319intel_dp_pre_emphasis_max(uint8_t voltage_swing)
1320{
1321 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
1322 case DP_TRAIN_VOLTAGE_SWING_400:
1323 return DP_TRAIN_PRE_EMPHASIS_6;
1324 case DP_TRAIN_VOLTAGE_SWING_600:
1325 return DP_TRAIN_PRE_EMPHASIS_6;
1326 case DP_TRAIN_VOLTAGE_SWING_800:
1327 return DP_TRAIN_PRE_EMPHASIS_3_5;
1328 case DP_TRAIN_VOLTAGE_SWING_1200:
1329 default:
1330 return DP_TRAIN_PRE_EMPHASIS_0;
1331 }
1332}
1333
1334static void
Jesse Barnes33a34e42010-09-08 12:42:02 -07001335intel_get_adjust_train(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001336{
1337 uint8_t v = 0;
1338 uint8_t p = 0;
1339 int lane;
1340
Jesse Barnes33a34e42010-09-08 12:42:02 -07001341 for (lane = 0; lane < intel_dp->lane_count; lane++) {
1342 uint8_t this_v = intel_get_adjust_request_voltage(intel_dp->link_status, lane);
1343 uint8_t this_p = intel_get_adjust_request_pre_emphasis(intel_dp->link_status, lane);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001344
1345 if (this_v > v)
1346 v = this_v;
1347 if (this_p > p)
1348 p = this_p;
1349 }
1350
1351 if (v >= I830_DP_VOLTAGE_MAX)
1352 v = I830_DP_VOLTAGE_MAX | DP_TRAIN_MAX_SWING_REACHED;
1353
1354 if (p >= intel_dp_pre_emphasis_max(v))
1355 p = intel_dp_pre_emphasis_max(v) | DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
1356
1357 for (lane = 0; lane < 4; lane++)
Jesse Barnes33a34e42010-09-08 12:42:02 -07001358 intel_dp->train_set[lane] = v | p;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001359}
1360
1361static uint32_t
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001362intel_dp_signal_levels(uint8_t train_set, int lane_count)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001363{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001364 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001365
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001366 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001367 case DP_TRAIN_VOLTAGE_SWING_400:
1368 default:
1369 signal_levels |= DP_VOLTAGE_0_4;
1370 break;
1371 case DP_TRAIN_VOLTAGE_SWING_600:
1372 signal_levels |= DP_VOLTAGE_0_6;
1373 break;
1374 case DP_TRAIN_VOLTAGE_SWING_800:
1375 signal_levels |= DP_VOLTAGE_0_8;
1376 break;
1377 case DP_TRAIN_VOLTAGE_SWING_1200:
1378 signal_levels |= DP_VOLTAGE_1_2;
1379 break;
1380 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001381 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001382 case DP_TRAIN_PRE_EMPHASIS_0:
1383 default:
1384 signal_levels |= DP_PRE_EMPHASIS_0;
1385 break;
1386 case DP_TRAIN_PRE_EMPHASIS_3_5:
1387 signal_levels |= DP_PRE_EMPHASIS_3_5;
1388 break;
1389 case DP_TRAIN_PRE_EMPHASIS_6:
1390 signal_levels |= DP_PRE_EMPHASIS_6;
1391 break;
1392 case DP_TRAIN_PRE_EMPHASIS_9_5:
1393 signal_levels |= DP_PRE_EMPHASIS_9_5;
1394 break;
1395 }
1396 return signal_levels;
1397}
1398
Zhenyu Wange3421a12010-04-08 09:43:27 +08001399/* Gen6's DP voltage swing and pre-emphasis control */
1400static uint32_t
1401intel_gen6_edp_signal_levels(uint8_t train_set)
1402{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001403 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
1404 DP_TRAIN_PRE_EMPHASIS_MASK);
1405 switch (signal_levels) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08001406 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001407 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
1408 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
1409 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
1410 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001411 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001412 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
1413 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001414 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001415 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
1416 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001417 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001418 case DP_TRAIN_VOLTAGE_SWING_1200 | DP_TRAIN_PRE_EMPHASIS_0:
1419 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001420 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001421 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
1422 "0x%x\n", signal_levels);
1423 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001424 }
1425}
1426
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001427static uint8_t
1428intel_get_lane_status(uint8_t link_status[DP_LINK_STATUS_SIZE],
1429 int lane)
1430{
1431 int i = DP_LANE0_1_STATUS + (lane >> 1);
1432 int s = (lane & 1) * 4;
1433 uint8_t l = intel_dp_link_status(link_status, i);
1434
1435 return (l >> s) & 0xf;
1436}
1437
1438/* Check for clock recovery is done on all channels */
1439static bool
1440intel_clock_recovery_ok(uint8_t link_status[DP_LINK_STATUS_SIZE], int lane_count)
1441{
1442 int lane;
1443 uint8_t lane_status;
1444
1445 for (lane = 0; lane < lane_count; lane++) {
1446 lane_status = intel_get_lane_status(link_status, lane);
1447 if ((lane_status & DP_LANE_CR_DONE) == 0)
1448 return false;
1449 }
1450 return true;
1451}
1452
1453/* Check to see if channel eq is done on all channels */
1454#define CHANNEL_EQ_BITS (DP_LANE_CR_DONE|\
1455 DP_LANE_CHANNEL_EQ_DONE|\
1456 DP_LANE_SYMBOL_LOCKED)
1457static bool
Jesse Barnes33a34e42010-09-08 12:42:02 -07001458intel_channel_eq_ok(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001459{
1460 uint8_t lane_align;
1461 uint8_t lane_status;
1462 int lane;
1463
Jesse Barnes33a34e42010-09-08 12:42:02 -07001464 lane_align = intel_dp_link_status(intel_dp->link_status,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001465 DP_LANE_ALIGN_STATUS_UPDATED);
1466 if ((lane_align & DP_INTERLANE_ALIGN_DONE) == 0)
1467 return false;
Jesse Barnes33a34e42010-09-08 12:42:02 -07001468 for (lane = 0; lane < intel_dp->lane_count; lane++) {
1469 lane_status = intel_get_lane_status(intel_dp->link_status, lane);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001470 if ((lane_status & CHANNEL_EQ_BITS) != CHANNEL_EQ_BITS)
1471 return false;
1472 }
1473 return true;
1474}
1475
1476static bool
Chris Wilsonea5b2132010-08-04 13:50:23 +01001477intel_dp_set_link_train(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001478 uint32_t dp_reg_value,
Chris Wilson58e10eb2010-10-03 10:56:11 +01001479 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001480{
Chris Wilson4ef69c72010-09-09 15:14:28 +01001481 struct drm_device *dev = intel_dp->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001482 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001483 int ret;
1484
Chris Wilsonea5b2132010-08-04 13:50:23 +01001485 I915_WRITE(intel_dp->output_reg, dp_reg_value);
1486 POSTING_READ(intel_dp->output_reg);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001487
Chris Wilsonea5b2132010-08-04 13:50:23 +01001488 intel_dp_aux_native_write_1(intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001489 DP_TRAINING_PATTERN_SET,
1490 dp_train_pat);
1491
Chris Wilsonea5b2132010-08-04 13:50:23 +01001492 ret = intel_dp_aux_native_write(intel_dp,
Chris Wilson58e10eb2010-10-03 10:56:11 +01001493 DP_TRAINING_LANE0_SET,
1494 intel_dp->train_set, 4);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001495 if (ret != 4)
1496 return false;
1497
1498 return true;
1499}
1500
Jesse Barnes33a34e42010-09-08 12:42:02 -07001501/* Enable corresponding port and start training pattern 1 */
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001502static void
Jesse Barnes33a34e42010-09-08 12:42:02 -07001503intel_dp_start_link_train(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001504{
Chris Wilson4ef69c72010-09-09 15:14:28 +01001505 struct drm_device *dev = intel_dp->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001506 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson58e10eb2010-10-03 10:56:11 +01001507 struct intel_crtc *intel_crtc = to_intel_crtc(intel_dp->base.base.crtc);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001508 int i;
1509 uint8_t voltage;
1510 bool clock_recovery = false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001511 int tries;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001512 u32 reg;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001513 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001514
Adam Jacksone8519462011-07-21 17:48:38 -04001515 /*
1516 * On CPT we have to enable the port in training pattern 1, which
1517 * will happen below in intel_dp_set_link_train. Otherwise, enable
1518 * the port and wait for it to become active.
1519 */
1520 if (!HAS_PCH_CPT(dev)) {
1521 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
1522 POSTING_READ(intel_dp->output_reg);
1523 intel_wait_for_vblank(dev, intel_crtc->pipe);
1524 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001525
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001526 /* Write the link configuration data */
1527 intel_dp_aux_native_write(intel_dp, DP_LINK_BW_SET,
1528 intel_dp->link_configuration,
1529 DP_LINK_CONFIGURATION_SIZE);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001530
1531 DP |= DP_PORT_EN;
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;
1534 else
1535 DP &= ~DP_LINK_TRAIN_MASK;
Jesse Barnes33a34e42010-09-08 12:42:02 -07001536 memset(intel_dp->train_set, 0, 4);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001537 voltage = 0xff;
1538 tries = 0;
1539 clock_recovery = false;
1540 for (;;) {
Jesse Barnes33a34e42010-09-08 12:42:02 -07001541 /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */
Zhenyu Wange3421a12010-04-08 09:43:27 +08001542 uint32_t signal_levels;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001543 if (IS_GEN6(dev) && is_edp(intel_dp)) {
Jesse Barnes33a34e42010-09-08 12:42:02 -07001544 signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001545 DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels;
1546 } else {
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001547 signal_levels = intel_dp_signal_levels(intel_dp->train_set[0], intel_dp->lane_count);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001548 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
1549 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001550
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001551 if (HAS_PCH_CPT(dev) && !is_edp(intel_dp))
Zhenyu Wange3421a12010-04-08 09:43:27 +08001552 reg = DP | DP_LINK_TRAIN_PAT_1_CPT;
1553 else
1554 reg = DP | DP_LINK_TRAIN_PAT_1;
1555
Chris Wilsonea5b2132010-08-04 13:50:23 +01001556 if (!intel_dp_set_link_train(intel_dp, reg,
Adam Jackson81055852011-07-21 17:48:37 -04001557 DP_TRAINING_PATTERN_1 |
1558 DP_LINK_SCRAMBLING_DISABLE))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001559 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001560 /* Set training pattern 1 */
1561
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001562 udelay(100);
1563 if (!intel_dp_get_link_status(intel_dp))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001564 break;
1565
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001566 if (intel_clock_recovery_ok(intel_dp->link_status, intel_dp->lane_count)) {
1567 clock_recovery = true;
1568 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001569 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001570
1571 /* Check to see if we've tried the max voltage */
1572 for (i = 0; i < intel_dp->lane_count; i++)
1573 if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
1574 break;
1575 if (i == intel_dp->lane_count)
1576 break;
1577
1578 /* Check to see if we've tried the same voltage 5 times */
1579 if ((intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) == voltage) {
1580 ++tries;
1581 if (tries == 5)
1582 break;
1583 } else
1584 tries = 0;
1585 voltage = intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
1586
1587 /* Compute new intel_dp->train_set as requested by target */
1588 intel_get_adjust_train(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001589 }
1590
Jesse Barnes33a34e42010-09-08 12:42:02 -07001591 intel_dp->DP = DP;
1592}
1593
1594static void
1595intel_dp_complete_link_train(struct intel_dp *intel_dp)
1596{
Chris Wilson4ef69c72010-09-09 15:14:28 +01001597 struct drm_device *dev = intel_dp->base.base.dev;
Jesse Barnes33a34e42010-09-08 12:42:02 -07001598 struct drm_i915_private *dev_priv = dev->dev_private;
1599 bool channel_eq = false;
Jesse Barnes37f80972011-01-05 14:45:24 -08001600 int tries, cr_tries;
Jesse Barnes33a34e42010-09-08 12:42:02 -07001601 u32 reg;
1602 uint32_t DP = intel_dp->DP;
1603
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001604 /* channel equalization */
1605 tries = 0;
Jesse Barnes37f80972011-01-05 14:45:24 -08001606 cr_tries = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001607 channel_eq = false;
1608 for (;;) {
Jesse Barnes33a34e42010-09-08 12:42:02 -07001609 /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */
Zhenyu Wange3421a12010-04-08 09:43:27 +08001610 uint32_t signal_levels;
1611
Jesse Barnes37f80972011-01-05 14:45:24 -08001612 if (cr_tries > 5) {
1613 DRM_ERROR("failed to train DP, aborting\n");
1614 intel_dp_link_down(intel_dp);
1615 break;
1616 }
1617
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001618 if (IS_GEN6(dev) && is_edp(intel_dp)) {
Jesse Barnes33a34e42010-09-08 12:42:02 -07001619 signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001620 DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels;
1621 } else {
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001622 signal_levels = intel_dp_signal_levels(intel_dp->train_set[0], intel_dp->lane_count);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001623 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
1624 }
1625
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001626 if (HAS_PCH_CPT(dev) && !is_edp(intel_dp))
Zhenyu Wange3421a12010-04-08 09:43:27 +08001627 reg = DP | DP_LINK_TRAIN_PAT_2_CPT;
1628 else
1629 reg = DP | DP_LINK_TRAIN_PAT_2;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001630
1631 /* channel eq pattern */
Chris Wilsonea5b2132010-08-04 13:50:23 +01001632 if (!intel_dp_set_link_train(intel_dp, reg,
Adam Jackson81055852011-07-21 17:48:37 -04001633 DP_TRAINING_PATTERN_2 |
1634 DP_LINK_SCRAMBLING_DISABLE))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001635 break;
1636
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001637 udelay(400);
1638 if (!intel_dp_get_link_status(intel_dp))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001639 break;
Jesse Barnes869184a2010-10-07 16:01:22 -07001640
Jesse Barnes37f80972011-01-05 14:45:24 -08001641 /* Make sure clock is still ok */
1642 if (!intel_clock_recovery_ok(intel_dp->link_status, intel_dp->lane_count)) {
1643 intel_dp_start_link_train(intel_dp);
1644 cr_tries++;
1645 continue;
1646 }
1647
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001648 if (intel_channel_eq_ok(intel_dp)) {
1649 channel_eq = true;
1650 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001651 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001652
Jesse Barnes37f80972011-01-05 14:45:24 -08001653 /* Try 5 times, then try clock recovery if that fails */
1654 if (tries > 5) {
1655 intel_dp_link_down(intel_dp);
1656 intel_dp_start_link_train(intel_dp);
1657 tries = 0;
1658 cr_tries++;
1659 continue;
1660 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001661
1662 /* Compute new intel_dp->train_set as requested by target */
1663 intel_get_adjust_train(intel_dp);
1664 ++tries;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001665 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001666
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001667 if (HAS_PCH_CPT(dev) && !is_edp(intel_dp))
Zhenyu Wange3421a12010-04-08 09:43:27 +08001668 reg = DP | DP_LINK_TRAIN_OFF_CPT;
1669 else
1670 reg = DP | DP_LINK_TRAIN_OFF;
1671
Chris Wilsonea5b2132010-08-04 13:50:23 +01001672 I915_WRITE(intel_dp->output_reg, reg);
1673 POSTING_READ(intel_dp->output_reg);
1674 intel_dp_aux_native_write_1(intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001675 DP_TRAINING_PATTERN_SET, DP_TRAINING_PATTERN_DISABLE);
1676}
1677
1678static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01001679intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001680{
Chris Wilson4ef69c72010-09-09 15:14:28 +01001681 struct drm_device *dev = intel_dp->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001682 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001683 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001684
Chris Wilson1b39d6f2010-12-06 11:20:45 +00001685 if ((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0)
1686 return;
1687
Zhao Yakui28c97732009-10-09 11:39:41 +08001688 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001689
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001690 if (is_edp(intel_dp)) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001691 DP &= ~DP_PLL_ENABLE;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001692 I915_WRITE(intel_dp->output_reg, DP);
1693 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001694 udelay(100);
1695 }
1696
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001697 if (HAS_PCH_CPT(dev) && !is_edp(intel_dp)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08001698 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001699 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001700 } else {
1701 DP &= ~DP_LINK_TRAIN_MASK;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001702 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001703 }
Chris Wilsonfe255d02010-09-11 21:37:48 +01001704 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001705
Chris Wilsonfe255d02010-09-11 21:37:48 +01001706 msleep(17);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001707
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07001708 if (is_edp(intel_dp))
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001709 DP |= DP_LINK_TRAIN_OFF;
Eric Anholt5bddd172010-11-18 09:32:59 +08001710
Chris Wilson1b39d6f2010-12-06 11:20:45 +00001711 if (!HAS_PCH_CPT(dev) &&
1712 I915_READ(intel_dp->output_reg) & DP_PIPEB_SELECT) {
Chris Wilson31acbcc2011-04-17 06:38:35 +01001713 struct drm_crtc *crtc = intel_dp->base.base.crtc;
1714
Eric Anholt5bddd172010-11-18 09:32:59 +08001715 /* Hardware workaround: leaving our transcoder select
1716 * set to transcoder B while it's off will prevent the
1717 * corresponding HDMI output on transcoder A.
1718 *
1719 * Combine this with another hardware workaround:
1720 * transcoder select bit can only be cleared while the
1721 * port is enabled.
1722 */
1723 DP &= ~DP_PIPEB_SELECT;
1724 I915_WRITE(intel_dp->output_reg, DP);
1725
1726 /* Changes to enable or select take place the vblank
1727 * after being written.
1728 */
Chris Wilson31acbcc2011-04-17 06:38:35 +01001729 if (crtc == NULL) {
1730 /* We can arrive here never having been attached
1731 * to a CRTC, for instance, due to inheriting
1732 * random state from the BIOS.
1733 *
1734 * If the pipe is not running, play safe and
1735 * wait for the clocks to stabilise before
1736 * continuing.
1737 */
1738 POSTING_READ(intel_dp->output_reg);
1739 msleep(50);
1740 } else
1741 intel_wait_for_vblank(dev, to_intel_crtc(crtc)->pipe);
Eric Anholt5bddd172010-11-18 09:32:59 +08001742 }
1743
Chris Wilsonea5b2132010-08-04 13:50:23 +01001744 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
1745 POSTING_READ(intel_dp->output_reg);
Keith Packardf01eca22011-09-28 16:48:10 -07001746 msleep(intel_dp->panel_power_down_delay);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001747}
1748
Keith Packard26d61aa2011-07-25 20:01:09 -07001749static bool
1750intel_dp_get_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07001751{
Keith Packard92fd8fd2011-07-25 19:50:10 -07001752 if (intel_dp_aux_native_read_retry(intel_dp, 0x000, intel_dp->dpcd,
1753 sizeof (intel_dp->dpcd)) &&
1754 (intel_dp->dpcd[DP_DPCD_REV] != 0)) {
Keith Packard26d61aa2011-07-25 20:01:09 -07001755 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07001756 }
1757
Keith Packard26d61aa2011-07-25 20:01:09 -07001758 return false;
Keith Packard92fd8fd2011-07-25 19:50:10 -07001759}
1760
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001761/*
1762 * According to DP spec
1763 * 5.1.2:
1764 * 1. Read DPCD
1765 * 2. Configure link according to Receiver Capabilities
1766 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
1767 * 4. Check link status on receipt of hot-plug interrupt
1768 */
1769
1770static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01001771intel_dp_check_link_status(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001772{
Keith Packardd2b996a2011-07-25 22:37:51 -07001773 if (intel_dp->dpms_mode != DRM_MODE_DPMS_ON)
1774 return;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07001775
Chris Wilson4ef69c72010-09-09 15:14:28 +01001776 if (!intel_dp->base.base.crtc)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001777 return;
1778
Keith Packard92fd8fd2011-07-25 19:50:10 -07001779 /* Try to read receiver status if the link appears to be up */
Jesse Barnes33a34e42010-09-08 12:42:02 -07001780 if (!intel_dp_get_link_status(intel_dp)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001781 intel_dp_link_down(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001782 return;
1783 }
1784
Keith Packard92fd8fd2011-07-25 19:50:10 -07001785 /* Now read the DPCD to see if it's actually running */
Keith Packard26d61aa2011-07-25 20:01:09 -07001786 if (!intel_dp_get_dpcd(intel_dp)) {
Jesse Barnes59cd09e2011-07-07 11:10:59 -07001787 intel_dp_link_down(intel_dp);
1788 return;
1789 }
1790
Jesse Barnes33a34e42010-09-08 12:42:02 -07001791 if (!intel_channel_eq_ok(intel_dp)) {
Keith Packard92fd8fd2011-07-25 19:50:10 -07001792 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
1793 drm_get_encoder_name(&intel_dp->base.base));
Jesse Barnes33a34e42010-09-08 12:42:02 -07001794 intel_dp_start_link_train(intel_dp);
1795 intel_dp_complete_link_train(intel_dp);
1796 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001797}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001798
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001799static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07001800intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04001801{
Keith Packard26d61aa2011-07-25 20:01:09 -07001802 if (intel_dp_get_dpcd(intel_dp))
1803 return connector_status_connected;
1804 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04001805}
1806
1807static enum drm_connector_status
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001808ironlake_dp_detect(struct intel_dp *intel_dp)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001809{
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001810 enum drm_connector_status status;
1811
Chris Wilsonfe16d942011-02-12 10:29:38 +00001812 /* Can't disconnect eDP, but you can close the lid... */
1813 if (is_edp(intel_dp)) {
1814 status = intel_panel_detect(intel_dp->base.base.dev);
1815 if (status == connector_status_unknown)
1816 status = connector_status_connected;
1817 return status;
1818 }
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001819
Keith Packard26d61aa2011-07-25 20:01:09 -07001820 return intel_dp_detect_dpcd(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001821}
1822
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001823static enum drm_connector_status
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001824g4x_dp_detect(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001825{
Chris Wilson4ef69c72010-09-09 15:14:28 +01001826 struct drm_device *dev = intel_dp->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001827 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001828 uint32_t temp, bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001829
Chris Wilsonea5b2132010-08-04 13:50:23 +01001830 switch (intel_dp->output_reg) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001831 case DP_B:
1832 bit = DPB_HOTPLUG_INT_STATUS;
1833 break;
1834 case DP_C:
1835 bit = DPC_HOTPLUG_INT_STATUS;
1836 break;
1837 case DP_D:
1838 bit = DPD_HOTPLUG_INT_STATUS;
1839 break;
1840 default:
1841 return connector_status_unknown;
1842 }
1843
1844 temp = I915_READ(PORT_HOTPLUG_STAT);
1845
1846 if ((temp & bit) == 0)
1847 return connector_status_disconnected;
1848
Keith Packard26d61aa2011-07-25 20:01:09 -07001849 return intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001850}
1851
Keith Packard8c241fe2011-09-28 16:38:44 -07001852static struct edid *
1853intel_dp_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
1854{
1855 struct intel_dp *intel_dp = intel_attached_dp(connector);
1856 struct edid *edid;
1857
1858 ironlake_edp_panel_vdd_on(intel_dp);
1859 edid = drm_get_edid(connector, adapter);
Keith Packardbd943152011-09-18 23:09:52 -07001860 ironlake_edp_panel_vdd_off(intel_dp, false);
Keith Packard8c241fe2011-09-28 16:38:44 -07001861 return edid;
1862}
1863
1864static int
1865intel_dp_get_edid_modes(struct drm_connector *connector, struct i2c_adapter *adapter)
1866{
1867 struct intel_dp *intel_dp = intel_attached_dp(connector);
1868 int ret;
1869
1870 ironlake_edp_panel_vdd_on(intel_dp);
1871 ret = intel_ddc_get_modes(connector, adapter);
Keith Packardbd943152011-09-18 23:09:52 -07001872 ironlake_edp_panel_vdd_off(intel_dp, false);
Keith Packard8c241fe2011-09-28 16:38:44 -07001873 return ret;
1874}
1875
1876
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001877/**
1878 * Uses CRT_HOTPLUG_EN and CRT_HOTPLUG_STAT to detect DP connection.
1879 *
1880 * \return true if DP port is connected.
1881 * \return false if DP port is disconnected.
1882 */
1883static enum drm_connector_status
1884intel_dp_detect(struct drm_connector *connector, bool force)
1885{
1886 struct intel_dp *intel_dp = intel_attached_dp(connector);
1887 struct drm_device *dev = intel_dp->base.base.dev;
1888 enum drm_connector_status status;
1889 struct edid *edid = NULL;
1890
1891 intel_dp->has_audio = false;
1892
1893 if (HAS_PCH_SPLIT(dev))
1894 status = ironlake_dp_detect(intel_dp);
1895 else
1896 status = g4x_dp_detect(intel_dp);
Adam Jackson1b9be9d2011-07-12 17:38:01 -04001897
Adam Jacksonac66ae82011-07-12 17:38:03 -04001898 DRM_DEBUG_KMS("DPCD: %02hx%02hx%02hx%02hx%02hx%02hx%02hx%02hx\n",
1899 intel_dp->dpcd[0], intel_dp->dpcd[1], intel_dp->dpcd[2],
1900 intel_dp->dpcd[3], intel_dp->dpcd[4], intel_dp->dpcd[5],
1901 intel_dp->dpcd[6], intel_dp->dpcd[7]);
Adam Jackson1b9be9d2011-07-12 17:38:01 -04001902
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001903 if (status != connector_status_connected)
1904 return status;
1905
Chris Wilsonf6849602010-09-19 09:29:33 +01001906 if (intel_dp->force_audio) {
1907 intel_dp->has_audio = intel_dp->force_audio > 0;
1908 } else {
Keith Packard8c241fe2011-09-28 16:38:44 -07001909 edid = intel_dp_get_edid(connector, &intel_dp->adapter);
Chris Wilsonf6849602010-09-19 09:29:33 +01001910 if (edid) {
1911 intel_dp->has_audio = drm_detect_monitor_audio(edid);
1912 connector->display_info.raw_edid = NULL;
1913 kfree(edid);
1914 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08001915 }
1916
1917 return connector_status_connected;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001918}
1919
1920static int intel_dp_get_modes(struct drm_connector *connector)
1921{
Chris Wilsondf0e9242010-09-09 16:20:55 +01001922 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson4ef69c72010-09-09 15:14:28 +01001923 struct drm_device *dev = intel_dp->base.base.dev;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001924 struct drm_i915_private *dev_priv = dev->dev_private;
1925 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001926
1927 /* We should parse the EDID data and find out if it has an audio sink
1928 */
1929
Keith Packard8c241fe2011-09-28 16:38:44 -07001930 ret = intel_dp_get_edid_modes(connector, &intel_dp->adapter);
Zhao Yakuib9efc482010-07-19 09:43:11 +01001931 if (ret) {
Keith Packardd15456d2011-09-18 17:35:47 -07001932 if (is_edp(intel_dp) && !intel_dp->panel_fixed_mode) {
Zhao Yakuib9efc482010-07-19 09:43:11 +01001933 struct drm_display_mode *newmode;
1934 list_for_each_entry(newmode, &connector->probed_modes,
1935 head) {
Keith Packardd15456d2011-09-18 17:35:47 -07001936 if ((newmode->type & DRM_MODE_TYPE_PREFERRED)) {
1937 intel_dp->panel_fixed_mode =
Zhao Yakuib9efc482010-07-19 09:43:11 +01001938 drm_mode_duplicate(dev, newmode);
1939 break;
1940 }
1941 }
1942 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001943 return ret;
Zhao Yakuib9efc482010-07-19 09:43:11 +01001944 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001945
1946 /* if eDP has no EDID, try to use fixed panel mode from VBT */
Jesse Barnes4d926462010-10-07 16:01:07 -07001947 if (is_edp(intel_dp)) {
Keith Packard47f0eb22011-09-19 14:33:26 -07001948 /* initialize panel mode from VBT if available for eDP */
Keith Packardd15456d2011-09-18 17:35:47 -07001949 if (intel_dp->panel_fixed_mode == NULL && dev_priv->lfp_lvds_vbt_mode != NULL) {
1950 intel_dp->panel_fixed_mode =
Keith Packard47f0eb22011-09-19 14:33:26 -07001951 drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);
Keith Packardd15456d2011-09-18 17:35:47 -07001952 if (intel_dp->panel_fixed_mode) {
1953 intel_dp->panel_fixed_mode->type |=
Keith Packard47f0eb22011-09-19 14:33:26 -07001954 DRM_MODE_TYPE_PREFERRED;
1955 }
1956 }
Keith Packardd15456d2011-09-18 17:35:47 -07001957 if (intel_dp->panel_fixed_mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001958 struct drm_display_mode *mode;
Keith Packardd15456d2011-09-18 17:35:47 -07001959 mode = drm_mode_duplicate(dev, intel_dp->panel_fixed_mode);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001960 drm_mode_probed_add(connector, mode);
1961 return 1;
1962 }
1963 }
1964 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001965}
1966
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001967static bool
1968intel_dp_detect_audio(struct drm_connector *connector)
1969{
1970 struct intel_dp *intel_dp = intel_attached_dp(connector);
1971 struct edid *edid;
1972 bool has_audio = false;
1973
Keith Packard8c241fe2011-09-28 16:38:44 -07001974 edid = intel_dp_get_edid(connector, &intel_dp->adapter);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001975 if (edid) {
1976 has_audio = drm_detect_monitor_audio(edid);
1977
1978 connector->display_info.raw_edid = NULL;
1979 kfree(edid);
1980 }
1981
1982 return has_audio;
1983}
1984
Chris Wilsonf6849602010-09-19 09:29:33 +01001985static int
1986intel_dp_set_property(struct drm_connector *connector,
1987 struct drm_property *property,
1988 uint64_t val)
1989{
Chris Wilsone953fd72011-02-21 22:23:52 +00001990 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Chris Wilsonf6849602010-09-19 09:29:33 +01001991 struct intel_dp *intel_dp = intel_attached_dp(connector);
1992 int ret;
1993
1994 ret = drm_connector_property_set_value(connector, property, val);
1995 if (ret)
1996 return ret;
1997
Chris Wilson3f43c482011-05-12 22:17:24 +01001998 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001999 int i = val;
2000 bool has_audio;
2001
2002 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01002003 return 0;
2004
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002005 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01002006
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002007 if (i == 0)
2008 has_audio = intel_dp_detect_audio(connector);
2009 else
2010 has_audio = i > 0;
2011
2012 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01002013 return 0;
2014
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002015 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01002016 goto done;
2017 }
2018
Chris Wilsone953fd72011-02-21 22:23:52 +00002019 if (property == dev_priv->broadcast_rgb_property) {
2020 if (val == !!intel_dp->color_range)
2021 return 0;
2022
2023 intel_dp->color_range = val ? DP_COLOR_RANGE_16_235 : 0;
2024 goto done;
2025 }
2026
Chris Wilsonf6849602010-09-19 09:29:33 +01002027 return -EINVAL;
2028
2029done:
2030 if (intel_dp->base.base.crtc) {
2031 struct drm_crtc *crtc = intel_dp->base.base.crtc;
2032 drm_crtc_helper_set_mode(crtc, &crtc->mode,
2033 crtc->x, crtc->y,
2034 crtc->fb);
2035 }
2036
2037 return 0;
2038}
2039
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002040static void
2041intel_dp_destroy (struct drm_connector *connector)
2042{
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02002043 struct drm_device *dev = connector->dev;
2044
2045 if (intel_dpd_is_edp(dev))
2046 intel_panel_destroy_backlight(dev);
2047
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002048 drm_sysfs_connector_remove(connector);
2049 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08002050 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002051}
2052
Daniel Vetter24d05922010-08-20 18:08:28 +02002053static void intel_dp_encoder_destroy(struct drm_encoder *encoder)
2054{
2055 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2056
2057 i2c_del_adapter(&intel_dp->adapter);
2058 drm_encoder_cleanup(encoder);
Keith Packardbd943152011-09-18 23:09:52 -07002059 if (is_edp(intel_dp)) {
2060 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
2061 ironlake_panel_vdd_off_sync(intel_dp);
2062 }
Daniel Vetter24d05922010-08-20 18:08:28 +02002063 kfree(intel_dp);
2064}
2065
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002066static const struct drm_encoder_helper_funcs intel_dp_helper_funcs = {
2067 .dpms = intel_dp_dpms,
2068 .mode_fixup = intel_dp_mode_fixup,
Jesse Barnesd240f202010-08-13 15:43:26 -07002069 .prepare = intel_dp_prepare,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002070 .mode_set = intel_dp_mode_set,
Jesse Barnesd240f202010-08-13 15:43:26 -07002071 .commit = intel_dp_commit,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002072};
2073
2074static const struct drm_connector_funcs intel_dp_connector_funcs = {
2075 .dpms = drm_helper_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002076 .detect = intel_dp_detect,
2077 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01002078 .set_property = intel_dp_set_property,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002079 .destroy = intel_dp_destroy,
2080};
2081
2082static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
2083 .get_modes = intel_dp_get_modes,
2084 .mode_valid = intel_dp_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +01002085 .best_encoder = intel_best_encoder,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002086};
2087
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002088static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Daniel Vetter24d05922010-08-20 18:08:28 +02002089 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002090};
2091
Chris Wilson995b6762010-08-20 13:23:26 +01002092static void
Eric Anholt21d40d32010-03-25 11:11:14 -07002093intel_dp_hot_plug(struct intel_encoder *intel_encoder)
Keith Packardc8110e52009-05-06 11:51:10 -07002094{
Chris Wilsonea5b2132010-08-04 13:50:23 +01002095 struct intel_dp *intel_dp = container_of(intel_encoder, struct intel_dp, base);
Keith Packardc8110e52009-05-06 11:51:10 -07002096
Jesse Barnes885a5012011-07-07 11:11:01 -07002097 intel_dp_check_link_status(intel_dp);
Keith Packardc8110e52009-05-06 11:51:10 -07002098}
2099
Zhenyu Wange3421a12010-04-08 09:43:27 +08002100/* Return which DP Port should be selected for Transcoder DP control */
2101int
2102intel_trans_dp_port_sel (struct drm_crtc *crtc)
2103{
2104 struct drm_device *dev = crtc->dev;
2105 struct drm_mode_config *mode_config = &dev->mode_config;
2106 struct drm_encoder *encoder;
Zhenyu Wange3421a12010-04-08 09:43:27 +08002107
2108 list_for_each_entry(encoder, &mode_config->encoder_list, head) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01002109 struct intel_dp *intel_dp;
2110
Dan Carpenterd8201ab2010-05-07 10:39:00 +02002111 if (encoder->crtc != crtc)
Zhenyu Wange3421a12010-04-08 09:43:27 +08002112 continue;
2113
Chris Wilsonea5b2132010-08-04 13:50:23 +01002114 intel_dp = enc_to_intel_dp(encoder);
2115 if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT)
2116 return intel_dp->output_reg;
Zhenyu Wange3421a12010-04-08 09:43:27 +08002117 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002118
Zhenyu Wange3421a12010-04-08 09:43:27 +08002119 return -1;
2120}
2121
Zhao Yakui36e83a12010-06-12 14:32:21 +08002122/* check the VBT to see whether the eDP is on DP-D port */
Adam Jacksoncb0953d2010-07-16 14:46:29 -04002123bool intel_dpd_is_edp(struct drm_device *dev)
Zhao Yakui36e83a12010-06-12 14:32:21 +08002124{
2125 struct drm_i915_private *dev_priv = dev->dev_private;
2126 struct child_device_config *p_child;
2127 int i;
2128
2129 if (!dev_priv->child_dev_num)
2130 return false;
2131
2132 for (i = 0; i < dev_priv->child_dev_num; i++) {
2133 p_child = dev_priv->child_dev + i;
2134
2135 if (p_child->dvo_port == PORT_IDPD &&
2136 p_child->device_type == DEVICE_TYPE_eDP)
2137 return true;
2138 }
2139 return false;
2140}
2141
Chris Wilsonf6849602010-09-19 09:29:33 +01002142static void
2143intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
2144{
Chris Wilson3f43c482011-05-12 22:17:24 +01002145 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00002146 intel_attach_broadcast_rgb_property(connector);
Chris Wilsonf6849602010-09-19 09:29:33 +01002147}
2148
Keith Packardc8110e52009-05-06 11:51:10 -07002149void
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002150intel_dp_init(struct drm_device *dev, int output_reg)
2151{
2152 struct drm_i915_private *dev_priv = dev->dev_private;
2153 struct drm_connector *connector;
Chris Wilsonea5b2132010-08-04 13:50:23 +01002154 struct intel_dp *intel_dp;
Eric Anholt21d40d32010-03-25 11:11:14 -07002155 struct intel_encoder *intel_encoder;
Zhenyu Wang55f78c42010-03-29 16:13:57 +08002156 struct intel_connector *intel_connector;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002157 const char *name = NULL;
Adam Jacksonb3295302010-07-16 14:46:28 -04002158 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002159
Chris Wilsonea5b2132010-08-04 13:50:23 +01002160 intel_dp = kzalloc(sizeof(struct intel_dp), GFP_KERNEL);
2161 if (!intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002162 return;
2163
Chris Wilson3d3dc142011-02-12 10:33:12 +00002164 intel_dp->output_reg = output_reg;
Keith Packardd2b996a2011-07-25 22:37:51 -07002165 intel_dp->dpms_mode = -1;
Chris Wilson3d3dc142011-02-12 10:33:12 +00002166
Zhenyu Wang55f78c42010-03-29 16:13:57 +08002167 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
2168 if (!intel_connector) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01002169 kfree(intel_dp);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08002170 return;
2171 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002172 intel_encoder = &intel_dp->base;
Zhenyu Wang55f78c42010-03-29 16:13:57 +08002173
Chris Wilsonea5b2132010-08-04 13:50:23 +01002174 if (HAS_PCH_SPLIT(dev) && output_reg == PCH_DP_D)
Adam Jacksonb3295302010-07-16 14:46:28 -04002175 if (intel_dpd_is_edp(dev))
Chris Wilsonea5b2132010-08-04 13:50:23 +01002176 intel_dp->is_pch_edp = true;
Adam Jacksonb3295302010-07-16 14:46:28 -04002177
Jesse Barnescfcb0fc2010-10-07 16:01:06 -07002178 if (output_reg == DP_A || is_pch_edp(intel_dp)) {
Adam Jacksonb3295302010-07-16 14:46:28 -04002179 type = DRM_MODE_CONNECTOR_eDP;
2180 intel_encoder->type = INTEL_OUTPUT_EDP;
2181 } else {
2182 type = DRM_MODE_CONNECTOR_DisplayPort;
2183 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
2184 }
2185
Zhenyu Wang55f78c42010-03-29 16:13:57 +08002186 connector = &intel_connector->base;
Adam Jacksonb3295302010-07-16 14:46:28 -04002187 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002188 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
2189
Dave Airlieeb1f8e42010-05-07 06:42:51 +00002190 connector->polled = DRM_CONNECTOR_POLL_HPD;
2191
Zhao Yakui652af9d2009-12-02 10:03:33 +08002192 if (output_reg == DP_B || output_reg == PCH_DP_B)
Eric Anholt21d40d32010-03-25 11:11:14 -07002193 intel_encoder->clone_mask = (1 << INTEL_DP_B_CLONE_BIT);
Zhao Yakui652af9d2009-12-02 10:03:33 +08002194 else if (output_reg == DP_C || output_reg == PCH_DP_C)
Eric Anholt21d40d32010-03-25 11:11:14 -07002195 intel_encoder->clone_mask = (1 << INTEL_DP_C_CLONE_BIT);
Zhao Yakui652af9d2009-12-02 10:03:33 +08002196 else if (output_reg == DP_D || output_reg == PCH_DP_D)
Eric Anholt21d40d32010-03-25 11:11:14 -07002197 intel_encoder->clone_mask = (1 << INTEL_DP_D_CLONE_BIT);
Ma Lingf8aed702009-08-24 13:50:24 +08002198
Keith Packardbd943152011-09-18 23:09:52 -07002199 if (is_edp(intel_dp)) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002200 intel_encoder->clone_mask = (1 << INTEL_EDP_CLONE_BIT);
Keith Packardbd943152011-09-18 23:09:52 -07002201 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
2202 ironlake_panel_vdd_work);
2203 }
Zhenyu Wang6251ec02010-01-12 05:38:32 +08002204
Eric Anholt21d40d32010-03-25 11:11:14 -07002205 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002206 connector->interlace_allowed = true;
2207 connector->doublescan_allowed = 0;
2208
Chris Wilson4ef69c72010-09-09 15:14:28 +01002209 drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002210 DRM_MODE_ENCODER_TMDS);
Chris Wilson4ef69c72010-09-09 15:14:28 +01002211 drm_encoder_helper_add(&intel_encoder->base, &intel_dp_helper_funcs);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002212
Chris Wilsondf0e9242010-09-09 16:20:55 +01002213 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002214 drm_sysfs_connector_add(connector);
2215
2216 /* Set up the DDC bus. */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002217 switch (output_reg) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002218 case DP_A:
2219 name = "DPDDC-A";
2220 break;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002221 case DP_B:
2222 case PCH_DP_B:
Jesse Barnesb01f2c32009-12-11 11:07:17 -08002223 dev_priv->hotplug_supported_mask |=
2224 HDMIB_HOTPLUG_INT_STATUS;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002225 name = "DPDDC-B";
2226 break;
2227 case DP_C:
2228 case PCH_DP_C:
Jesse Barnesb01f2c32009-12-11 11:07:17 -08002229 dev_priv->hotplug_supported_mask |=
2230 HDMIC_HOTPLUG_INT_STATUS;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002231 name = "DPDDC-C";
2232 break;
2233 case DP_D:
2234 case PCH_DP_D:
Jesse Barnesb01f2c32009-12-11 11:07:17 -08002235 dev_priv->hotplug_supported_mask |=
2236 HDMID_HOTPLUG_INT_STATUS;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002237 name = "DPDDC-D";
2238 break;
2239 }
2240
Jesse Barnes89667382010-10-07 16:01:21 -07002241 /* Cache some DPCD data in the eDP case */
2242 if (is_edp(intel_dp)) {
Keith Packard59f3e272011-07-25 20:01:56 -07002243 bool ret;
Keith Packardf01eca22011-09-28 16:48:10 -07002244 struct edp_power_seq cur, vbt;
2245 u32 pp_on, pp_off, pp_div;
Jesse Barnes89667382010-10-07 16:01:21 -07002246
Jesse Barnes5d613502011-01-24 17:10:54 -08002247 pp_on = I915_READ(PCH_PP_ON_DELAYS);
Keith Packardf01eca22011-09-28 16:48:10 -07002248 pp_off = I915_READ(PCH_PP_OFF_DELAYS);
Jesse Barnes5d613502011-01-24 17:10:54 -08002249 pp_div = I915_READ(PCH_PP_DIVISOR);
2250
Keith Packardf01eca22011-09-28 16:48:10 -07002251 /* Pull timing values out of registers */
2252 cur.t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
2253 PANEL_POWER_UP_DELAY_SHIFT;
2254
2255 cur.t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
2256 PANEL_LIGHT_ON_DELAY_SHIFT;
2257
2258 cur.t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
2259 PANEL_LIGHT_OFF_DELAY_SHIFT;
2260
2261 cur.t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
2262 PANEL_POWER_DOWN_DELAY_SHIFT;
2263
2264 cur.t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
2265 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
2266
2267 DRM_DEBUG_KMS("cur t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
2268 cur.t1_t3, cur.t8, cur.t9, cur.t10, cur.t11_t12);
2269
2270 vbt = dev_priv->edp.pps;
2271
2272 DRM_DEBUG_KMS("vbt t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
2273 vbt.t1_t3, vbt.t8, vbt.t9, vbt.t10, vbt.t11_t12);
2274
2275#define get_delay(field) ((max(cur.field, vbt.field) + 9) / 10)
2276
2277 intel_dp->panel_power_up_delay = get_delay(t1_t3);
2278 intel_dp->backlight_on_delay = get_delay(t8);
2279 intel_dp->backlight_off_delay = get_delay(t9);
2280 intel_dp->panel_power_down_delay = get_delay(t10);
2281 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
2282
2283 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
2284 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
2285 intel_dp->panel_power_cycle_delay);
2286
2287 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
2288 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Jesse Barnes5d613502011-01-24 17:10:54 -08002289
Keith Packardbd943152011-09-18 23:09:52 -07002290 intel_dp->panel_off_jiffies = jiffies - intel_dp->panel_power_down_delay;
2291
Jesse Barnes5d613502011-01-24 17:10:54 -08002292 ironlake_edp_panel_vdd_on(intel_dp);
Keith Packard59f3e272011-07-25 20:01:56 -07002293 ret = intel_dp_get_dpcd(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002294 ironlake_edp_panel_vdd_off(intel_dp, false);
Keith Packard59f3e272011-07-25 20:01:56 -07002295 if (ret) {
Jesse Barnes7183dc22011-07-07 11:10:58 -07002296 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
2297 dev_priv->no_aux_handshake =
2298 intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
Jesse Barnes89667382010-10-07 16:01:21 -07002299 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
2300 } else {
Chris Wilson3d3dc142011-02-12 10:33:12 +00002301 /* if this fails, presume the device is a ghost */
Takashi Iwai48898b02011-03-18 09:06:49 +00002302 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Chris Wilson3d3dc142011-02-12 10:33:12 +00002303 intel_dp_encoder_destroy(&intel_dp->base.base);
Takashi Iwai48898b02011-03-18 09:06:49 +00002304 intel_dp_destroy(&intel_connector->base);
Chris Wilson3d3dc142011-02-12 10:33:12 +00002305 return;
Jesse Barnes89667382010-10-07 16:01:21 -07002306 }
Jesse Barnes89667382010-10-07 16:01:21 -07002307 }
2308
Keith Packard552fb0b2011-09-28 16:31:53 -07002309 intel_dp_i2c_init(intel_dp, intel_connector, name);
2310
Eric Anholt21d40d32010-03-25 11:11:14 -07002311 intel_encoder->hot_plug = intel_dp_hot_plug;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002312
Jesse Barnes4d926462010-10-07 16:01:07 -07002313 if (is_edp(intel_dp)) {
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02002314 dev_priv->int_edp_connector = connector;
2315 intel_panel_setup_backlight(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002316 }
2317
Chris Wilsonf6849602010-09-19 09:29:33 +01002318 intel_dp_add_properties(intel_dp, connector);
2319
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002320 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
2321 * 0xd. Failure to do so will result in spurious interrupts being
2322 * generated on the port when a cable is not attached.
2323 */
2324 if (IS_G4X(dev) && !IS_GM45(dev)) {
2325 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
2326 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
2327 }
2328}