blob: 879aff26ca126743922c053ae72fc22e3cf939cf [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>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040030#include <linux/export.h>
David Howells760285e2012-10-02 18:01:07 +010031#include <drm/drmP.h>
32#include <drm/drm_crtc.h>
33#include <drm/drm_crtc_helper.h>
34#include <drm/drm_edid.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070035#include "intel_drv.h"
David Howells760285e2012-10-02 18:01:07 +010036#include <drm/i915_drm.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070037#include "i915_drv.h"
Keith Packarda4fc5ed2009-04-07 16:16:42 -070038
Keith Packarda4fc5ed2009-04-07 16:16:42 -070039#define DP_LINK_CHECK_TIMEOUT (10 * 1000)
40
Jesse Barnescfcb0fc2010-10-07 16:01:06 -070041/**
42 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
43 * @intel_dp: DP struct
44 *
45 * If a CPU or PCH DP output is attached to an eDP panel, this function
46 * will return true, and false otherwise.
47 */
48static bool is_edp(struct intel_dp *intel_dp)
49{
Paulo Zanonida63a9f2012-10-26 19:05:46 -020050 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
51
52 return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -070053}
54
55/**
56 * is_pch_edp - is the port on the PCH and attached to an eDP panel?
57 * @intel_dp: DP struct
58 *
59 * Returns true if the given DP struct corresponds to a PCH DP port attached
60 * to an eDP panel, false otherwise. Helpful for determining whether we
61 * may need FDI resources for a given DP output or not.
62 */
63static bool is_pch_edp(struct intel_dp *intel_dp)
64{
65 return intel_dp->is_pch_edp;
66}
67
Adam Jackson1c958222011-10-14 17:22:25 -040068/**
69 * is_cpu_edp - is the port on the CPU and attached to an eDP panel?
70 * @intel_dp: DP struct
71 *
72 * Returns true if the given DP struct corresponds to a CPU eDP port.
73 */
74static bool is_cpu_edp(struct intel_dp *intel_dp)
75{
76 return is_edp(intel_dp) && !is_pch_edp(intel_dp);
77}
78
Paulo Zanoni30add222012-10-26 19:05:45 -020079static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp)
Chris Wilsonea5b2132010-08-04 13:50:23 +010080{
Paulo Zanonida63a9f2012-10-26 19:05:46 -020081 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
82
83 return intel_dig_port->base.base.dev;
Chris Wilsonea5b2132010-08-04 13:50:23 +010084}
Keith Packarda4fc5ed2009-04-07 16:16:42 -070085
Chris Wilsondf0e9242010-09-09 16:20:55 +010086static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
87{
Paulo Zanonifa90ece2012-10-26 19:05:44 -020088 return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
Chris Wilsondf0e9242010-09-09 16:20:55 +010089}
90
Jesse Barnes814948a2010-10-07 16:01:09 -070091/**
92 * intel_encoder_is_pch_edp - is the given encoder a PCH attached eDP?
93 * @encoder: DRM encoder
94 *
95 * Return true if @encoder corresponds to a PCH attached eDP panel. Needed
96 * by intel_display.c.
97 */
98bool intel_encoder_is_pch_edp(struct drm_encoder *encoder)
99{
100 struct intel_dp *intel_dp;
101
102 if (!encoder)
103 return false;
104
105 intel_dp = enc_to_intel_dp(encoder);
106
107 return is_pch_edp(intel_dp);
108}
109
Chris Wilsonea5b2132010-08-04 13:50:23 +0100110static void intel_dp_link_down(struct intel_dp *intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700111
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800112void
Akshay Joshi0206e352011-08-16 15:34:10 -0400113intel_edp_link_config(struct intel_encoder *intel_encoder,
Chris Wilsonea5b2132010-08-04 13:50:23 +0100114 int *lane_num, int *link_bw)
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800115{
Paulo Zanonifa90ece2012-10-26 19:05:44 -0200116 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800117
Chris Wilsonea5b2132010-08-04 13:50:23 +0100118 *lane_num = intel_dp->lane_count;
Daniel Vetter3b5c6622012-10-18 10:15:31 +0200119 *link_bw = drm_dp_bw_code_to_link_rate(intel_dp->link_bw);
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800120}
121
Daniel Vetter94bf2ce2012-06-04 18:39:19 +0200122int
123intel_edp_target_clock(struct intel_encoder *intel_encoder,
124 struct drm_display_mode *mode)
125{
Paulo Zanonifa90ece2012-10-26 19:05:44 -0200126 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Jani Nikuladd06f902012-10-19 14:51:50 +0300127 struct intel_connector *intel_connector = intel_dp->attached_connector;
Daniel Vetter94bf2ce2012-06-04 18:39:19 +0200128
Jani Nikuladd06f902012-10-19 14:51:50 +0300129 if (intel_connector->panel.fixed_mode)
130 return intel_connector->panel.fixed_mode->clock;
Daniel Vetter94bf2ce2012-06-04 18:39:19 +0200131 else
132 return mode->clock;
133}
134
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700135static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100136intel_dp_max_link_bw(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700137{
Jesse Barnes7183dc22011-07-07 11:10:58 -0700138 int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700139
140 switch (max_link_bw) {
141 case DP_LINK_BW_1_62:
142 case DP_LINK_BW_2_7:
143 break;
144 default:
145 max_link_bw = DP_LINK_BW_1_62;
146 break;
147 }
148 return max_link_bw;
149}
150
Adam Jacksoncd9dde42011-10-14 12:43:49 -0400151/*
152 * The units on the numbers in the next two are... bizarre. Examples will
153 * make it clearer; this one parallels an example in the eDP spec.
154 *
155 * intel_dp_max_data_rate for one lane of 2.7GHz evaluates as:
156 *
157 * 270000 * 1 * 8 / 10 == 216000
158 *
159 * The actual data capacity of that configuration is 2.16Gbit/s, so the
160 * units are decakilobits. ->clock in a drm_display_mode is in kilohertz -
161 * or equivalently, kilopixels per second - so for 1680x1050R it'd be
162 * 119000. At 18bpp that's 2142000 kilobits per second.
163 *
164 * Thus the strange-looking division by 10 in intel_dp_link_required, to
165 * get the result in decakilobits instead of kilobits.
166 */
167
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700168static int
Keith Packardc8982612012-01-25 08:16:25 -0800169intel_dp_link_required(int pixel_clock, int bpp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700170{
Adam Jacksoncd9dde42011-10-14 12:43:49 -0400171 return (pixel_clock * bpp + 9) / 10;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700172}
173
174static int
Dave Airliefe27d532010-06-30 11:46:17 +1000175intel_dp_max_data_rate(int max_link_clock, int max_lanes)
176{
177 return (max_link_clock * max_lanes * 8) / 10;
178}
179
180static int
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700181intel_dp_mode_valid(struct drm_connector *connector,
182 struct drm_display_mode *mode)
183{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100184 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300185 struct intel_connector *intel_connector = to_intel_connector(connector);
186 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Daniel Vetter36008362013-03-27 00:44:59 +0100187 int target_clock = mode->clock;
188 int max_rate, mode_rate, max_lanes, max_link_clock;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700189
Jani Nikuladd06f902012-10-19 14:51:50 +0300190 if (is_edp(intel_dp) && fixed_mode) {
191 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100192 return MODE_PANEL;
193
Jani Nikuladd06f902012-10-19 14:51:50 +0300194 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100195 return MODE_PANEL;
196 }
197
Daniel Vetter36008362013-03-27 00:44:59 +0100198 max_link_clock = drm_dp_bw_code_to_link_rate(intel_dp_max_link_bw(intel_dp));
199 max_lanes = drm_dp_max_lane_count(intel_dp->dpcd);
200
201 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
202 mode_rate = intel_dp_link_required(target_clock, 18);
203
204 if (mode_rate > max_rate)
Daniel Vetterc4867932012-04-10 10:42:36 +0200205 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700206
207 if (mode->clock < 10000)
208 return MODE_CLOCK_LOW;
209
Daniel Vetter0af78a22012-05-23 11:30:55 +0200210 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
211 return MODE_H_ILLEGAL;
212
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700213 return MODE_OK;
214}
215
216static uint32_t
217pack_aux(uint8_t *src, int src_bytes)
218{
219 int i;
220 uint32_t v = 0;
221
222 if (src_bytes > 4)
223 src_bytes = 4;
224 for (i = 0; i < src_bytes; i++)
225 v |= ((uint32_t) src[i]) << ((3-i) * 8);
226 return v;
227}
228
229static void
230unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
231{
232 int i;
233 if (dst_bytes > 4)
234 dst_bytes = 4;
235 for (i = 0; i < dst_bytes; i++)
236 dst[i] = src >> ((3-i) * 8);
237}
238
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700239/* hrawclock is 1/4 the FSB frequency */
240static int
241intel_hrawclk(struct drm_device *dev)
242{
243 struct drm_i915_private *dev_priv = dev->dev_private;
244 uint32_t clkcfg;
245
Vijay Purushothaman9473c8f2012-09-27 19:13:01 +0530246 /* There is no CLKCFG reg in Valleyview. VLV hrawclk is 200 MHz */
247 if (IS_VALLEYVIEW(dev))
248 return 200;
249
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700250 clkcfg = I915_READ(CLKCFG);
251 switch (clkcfg & CLKCFG_FSB_MASK) {
252 case CLKCFG_FSB_400:
253 return 100;
254 case CLKCFG_FSB_533:
255 return 133;
256 case CLKCFG_FSB_667:
257 return 166;
258 case CLKCFG_FSB_800:
259 return 200;
260 case CLKCFG_FSB_1067:
261 return 266;
262 case CLKCFG_FSB_1333:
263 return 333;
264 /* these two are just a guess; one of them might be right */
265 case CLKCFG_FSB_1600:
266 case CLKCFG_FSB_1600_ALT:
267 return 400;
268 default:
269 return 133;
270 }
271}
272
Keith Packardebf33b12011-09-29 15:53:27 -0700273static bool ironlake_edp_have_panel_power(struct intel_dp *intel_dp)
274{
Paulo Zanoni30add222012-10-26 19:05:45 -0200275 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packardebf33b12011-09-29 15:53:27 -0700276 struct drm_i915_private *dev_priv = dev->dev_private;
277
278 return (I915_READ(PCH_PP_STATUS) & PP_ON) != 0;
279}
280
281static bool ironlake_edp_have_panel_vdd(struct intel_dp *intel_dp)
282{
Paulo Zanoni30add222012-10-26 19:05:45 -0200283 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packardebf33b12011-09-29 15:53:27 -0700284 struct drm_i915_private *dev_priv = dev->dev_private;
285
286 return (I915_READ(PCH_PP_CONTROL) & EDP_FORCE_VDD) != 0;
287}
288
Keith Packard9b984da2011-09-19 13:54:47 -0700289static void
290intel_dp_check_edp(struct intel_dp *intel_dp)
291{
Paulo Zanoni30add222012-10-26 19:05:45 -0200292 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packard9b984da2011-09-19 13:54:47 -0700293 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packardebf33b12011-09-29 15:53:27 -0700294
Keith Packard9b984da2011-09-19 13:54:47 -0700295 if (!is_edp(intel_dp))
296 return;
Keith Packardebf33b12011-09-29 15:53:27 -0700297 if (!ironlake_edp_have_panel_power(intel_dp) && !ironlake_edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700298 WARN(1, "eDP powered off while attempting aux channel communication.\n");
299 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Keith Packardebf33b12011-09-29 15:53:27 -0700300 I915_READ(PCH_PP_STATUS),
Keith Packard9b984da2011-09-19 13:54:47 -0700301 I915_READ(PCH_PP_CONTROL));
302 }
303}
304
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100305static uint32_t
306intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
307{
308 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
309 struct drm_device *dev = intel_dig_port->base.base.dev;
310 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni9ed35ab2013-02-18 19:00:25 -0300311 uint32_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100312 uint32_t status;
313 bool done;
314
Daniel Vetteref04f002012-12-01 21:03:59 +0100315#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100316 if (has_aux_irq)
Paulo Zanonib90f5172013-02-18 19:00:24 -0300317 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
318 msecs_to_jiffies(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100319 else
320 done = wait_for_atomic(C, 10) == 0;
321 if (!done)
322 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
323 has_aux_irq);
324#undef C
325
326 return status;
327}
328
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700329static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100330intel_dp_aux_ch(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700331 uint8_t *send, int send_bytes,
332 uint8_t *recv, int recv_size)
333{
Paulo Zanoni174edf12012-10-26 19:05:50 -0200334 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
335 struct drm_device *dev = intel_dig_port->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700336 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni9ed35ab2013-02-18 19:00:25 -0300337 uint32_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700338 uint32_t ch_data = ch_ctl + 4;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100339 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700340 uint32_t status;
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700341 uint32_t aux_clock_divider;
Daniel Vetter6b4e0a92012-06-14 22:15:00 +0200342 int try, precharge;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100343 bool has_aux_irq = INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev);
344
345 /* dp aux is extremely sensitive to irq latency, hence request the
346 * lowest possible wakeup latency and so prevent the cpu from going into
347 * deep sleep states.
348 */
349 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700350
Keith Packard9b984da2011-09-19 13:54:47 -0700351 intel_dp_check_edp(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700352 /* The clock divider is based off the hrawclk,
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700353 * and would like to run at 2MHz. So, take the
354 * hrawclk value and divide by 2 and use that
Jesse Barnes6176b8f2010-09-08 12:42:00 -0700355 *
356 * Note that PCH attached eDP panels should use a 125MHz input
357 * clock divider.
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700358 */
Adam Jackson1c958222011-10-14 17:22:25 -0400359 if (is_cpu_edp(intel_dp)) {
Paulo Zanoniaffa9352012-11-23 15:30:39 -0200360 if (HAS_DDI(dev))
Paulo Zanonib8fc2f62012-10-23 18:30:05 -0200361 aux_clock_divider = intel_ddi_get_cdclk_freq(dev_priv) >> 1;
362 else if (IS_VALLEYVIEW(dev))
Vijay Purushothaman9473c8f2012-09-27 19:13:01 +0530363 aux_clock_divider = 100;
364 else if (IS_GEN6(dev) || IS_GEN7(dev))
Keith Packard1a2eb462011-11-16 16:26:07 -0800365 aux_clock_divider = 200; /* SNB & IVB eDP input clock at 400Mhz */
Zhenyu Wange3421a12010-04-08 09:43:27 +0800366 else
367 aux_clock_divider = 225; /* eDP input clock at 450Mhz */
368 } else if (HAS_PCH_SPLIT(dev))
Daniel Vetter6b3ec1c2012-10-20 20:57:44 +0200369 aux_clock_divider = DIV_ROUND_UP(intel_pch_rawclk(dev), 2);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +0800370 else
371 aux_clock_divider = intel_hrawclk(dev) / 2;
372
Daniel Vetter6b4e0a92012-06-14 22:15:00 +0200373 if (IS_GEN6(dev))
374 precharge = 3;
375 else
376 precharge = 5;
377
Jesse Barnes11bee432011-08-01 15:02:20 -0700378 /* Try to wait for any previous AUX channel activity */
379 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +0100380 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -0700381 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
382 break;
383 msleep(1);
384 }
385
386 if (try == 3) {
387 WARN(1, "dp_aux_ch not started status 0x%08x\n",
388 I915_READ(ch_ctl));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100389 ret = -EBUSY;
390 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100391 }
392
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700393 /* Must try at least 3 times according to DP spec */
394 for (try = 0; try < 5; try++) {
395 /* Load the send data into the aux channel data registers */
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100396 for (i = 0; i < send_bytes; i += 4)
397 I915_WRITE(ch_data + i,
398 pack_aux(send + i, send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -0400399
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700400 /* Send the command and wait for it to complete */
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100401 I915_WRITE(ch_ctl,
402 DP_AUX_CH_CTL_SEND_BUSY |
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100403 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100404 DP_AUX_CH_CTL_TIME_OUT_400us |
405 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
406 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
407 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT) |
408 DP_AUX_CH_CTL_DONE |
409 DP_AUX_CH_CTL_TIME_OUT_ERROR |
410 DP_AUX_CH_CTL_RECEIVE_ERROR);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100411
412 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -0400413
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700414 /* Clear done status and any errors */
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100415 I915_WRITE(ch_ctl,
416 status |
417 DP_AUX_CH_CTL_DONE |
418 DP_AUX_CH_CTL_TIME_OUT_ERROR |
419 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -0400420
421 if (status & (DP_AUX_CH_CTL_TIME_OUT_ERROR |
422 DP_AUX_CH_CTL_RECEIVE_ERROR))
423 continue;
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100424 if (status & DP_AUX_CH_CTL_DONE)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700425 break;
426 }
427
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700428 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700429 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100430 ret = -EBUSY;
431 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700432 }
433
434 /* Check for timeout or receive error.
435 * Timeouts occur when the sink is not connected
436 */
Keith Packarda5b3da52009-06-11 22:30:32 -0700437 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700438 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100439 ret = -EIO;
440 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -0700441 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700442
443 /* Timeouts occur when the device isn't connected, so they're
444 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -0700445 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Zhao Yakui28c97732009-10-09 11:39:41 +0800446 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100447 ret = -ETIMEDOUT;
448 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700449 }
450
451 /* Unload any bytes sent back from the other side */
452 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
453 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700454 if (recv_bytes > recv_size)
455 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -0400456
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100457 for (i = 0; i < recv_bytes; i += 4)
458 unpack_aux(I915_READ(ch_data + i),
459 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700460
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100461 ret = recv_bytes;
462out:
463 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
464
465 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700466}
467
468/* Write data to the aux channel in native mode */
469static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100470intel_dp_aux_native_write(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700471 uint16_t address, uint8_t *send, int send_bytes)
472{
473 int ret;
474 uint8_t msg[20];
475 int msg_bytes;
476 uint8_t ack;
477
Keith Packard9b984da2011-09-19 13:54:47 -0700478 intel_dp_check_edp(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700479 if (send_bytes > 16)
480 return -1;
481 msg[0] = AUX_NATIVE_WRITE << 4;
482 msg[1] = address >> 8;
Zhenyu Wangeebc8632009-07-24 01:00:30 +0800483 msg[2] = address & 0xff;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700484 msg[3] = send_bytes - 1;
485 memcpy(&msg[4], send, send_bytes);
486 msg_bytes = send_bytes + 4;
487 for (;;) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100488 ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes, &ack, 1);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700489 if (ret < 0)
490 return ret;
491 if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK)
492 break;
493 else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
494 udelay(100);
495 else
Keith Packarda5b3da52009-06-11 22:30:32 -0700496 return -EIO;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700497 }
498 return send_bytes;
499}
500
501/* Write a single byte to the aux channel in native mode */
502static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100503intel_dp_aux_native_write_1(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700504 uint16_t address, uint8_t byte)
505{
Chris Wilsonea5b2132010-08-04 13:50:23 +0100506 return intel_dp_aux_native_write(intel_dp, address, &byte, 1);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700507}
508
509/* read bytes from a native aux channel */
510static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100511intel_dp_aux_native_read(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700512 uint16_t address, uint8_t *recv, int recv_bytes)
513{
514 uint8_t msg[4];
515 int msg_bytes;
516 uint8_t reply[20];
517 int reply_bytes;
518 uint8_t ack;
519 int ret;
520
Keith Packard9b984da2011-09-19 13:54:47 -0700521 intel_dp_check_edp(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700522 msg[0] = AUX_NATIVE_READ << 4;
523 msg[1] = address >> 8;
524 msg[2] = address & 0xff;
525 msg[3] = recv_bytes - 1;
526
527 msg_bytes = 4;
528 reply_bytes = recv_bytes + 1;
529
530 for (;;) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100531 ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700532 reply, reply_bytes);
Keith Packarda5b3da52009-06-11 22:30:32 -0700533 if (ret == 0)
534 return -EPROTO;
535 if (ret < 0)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700536 return ret;
537 ack = reply[0];
538 if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK) {
539 memcpy(recv, reply + 1, ret - 1);
540 return ret - 1;
541 }
542 else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
543 udelay(100);
544 else
Keith Packarda5b3da52009-06-11 22:30:32 -0700545 return -EIO;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700546 }
547}
548
549static int
Dave Airlieab2c0672009-12-04 10:55:24 +1000550intel_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode,
551 uint8_t write_byte, uint8_t *read_byte)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700552{
Dave Airlieab2c0672009-12-04 10:55:24 +1000553 struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100554 struct intel_dp *intel_dp = container_of(adapter,
555 struct intel_dp,
556 adapter);
Dave Airlieab2c0672009-12-04 10:55:24 +1000557 uint16_t address = algo_data->address;
558 uint8_t msg[5];
559 uint8_t reply[2];
David Flynn8316f332010-12-08 16:10:21 +0000560 unsigned retry;
Dave Airlieab2c0672009-12-04 10:55:24 +1000561 int msg_bytes;
562 int reply_bytes;
563 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700564
Keith Packard9b984da2011-09-19 13:54:47 -0700565 intel_dp_check_edp(intel_dp);
Dave Airlieab2c0672009-12-04 10:55:24 +1000566 /* Set up the command byte */
567 if (mode & MODE_I2C_READ)
568 msg[0] = AUX_I2C_READ << 4;
569 else
570 msg[0] = AUX_I2C_WRITE << 4;
571
572 if (!(mode & MODE_I2C_STOP))
573 msg[0] |= AUX_I2C_MOT << 4;
574
575 msg[1] = address >> 8;
576 msg[2] = address;
577
578 switch (mode) {
579 case MODE_I2C_WRITE:
580 msg[3] = 0;
581 msg[4] = write_byte;
582 msg_bytes = 5;
583 reply_bytes = 1;
584 break;
585 case MODE_I2C_READ:
586 msg[3] = 0;
587 msg_bytes = 4;
588 reply_bytes = 2;
589 break;
590 default:
591 msg_bytes = 3;
592 reply_bytes = 1;
593 break;
594 }
595
David Flynn8316f332010-12-08 16:10:21 +0000596 for (retry = 0; retry < 5; retry++) {
597 ret = intel_dp_aux_ch(intel_dp,
598 msg, msg_bytes,
599 reply, reply_bytes);
Dave Airlieab2c0672009-12-04 10:55:24 +1000600 if (ret < 0) {
Dave Airlie3ff99162009-12-08 14:03:47 +1000601 DRM_DEBUG_KMS("aux_ch failed %d\n", ret);
Dave Airlieab2c0672009-12-04 10:55:24 +1000602 return ret;
603 }
David Flynn8316f332010-12-08 16:10:21 +0000604
605 switch (reply[0] & AUX_NATIVE_REPLY_MASK) {
606 case AUX_NATIVE_REPLY_ACK:
607 /* I2C-over-AUX Reply field is only valid
608 * when paired with AUX ACK.
609 */
610 break;
611 case AUX_NATIVE_REPLY_NACK:
612 DRM_DEBUG_KMS("aux_ch native nack\n");
613 return -EREMOTEIO;
614 case AUX_NATIVE_REPLY_DEFER:
615 udelay(100);
616 continue;
617 default:
618 DRM_ERROR("aux_ch invalid native reply 0x%02x\n",
619 reply[0]);
620 return -EREMOTEIO;
621 }
622
Dave Airlieab2c0672009-12-04 10:55:24 +1000623 switch (reply[0] & AUX_I2C_REPLY_MASK) {
624 case AUX_I2C_REPLY_ACK:
625 if (mode == MODE_I2C_READ) {
626 *read_byte = reply[1];
627 }
628 return reply_bytes - 1;
629 case AUX_I2C_REPLY_NACK:
David Flynn8316f332010-12-08 16:10:21 +0000630 DRM_DEBUG_KMS("aux_i2c nack\n");
Dave Airlieab2c0672009-12-04 10:55:24 +1000631 return -EREMOTEIO;
632 case AUX_I2C_REPLY_DEFER:
David Flynn8316f332010-12-08 16:10:21 +0000633 DRM_DEBUG_KMS("aux_i2c defer\n");
Dave Airlieab2c0672009-12-04 10:55:24 +1000634 udelay(100);
635 break;
636 default:
David Flynn8316f332010-12-08 16:10:21 +0000637 DRM_ERROR("aux_i2c invalid reply 0x%02x\n", reply[0]);
Dave Airlieab2c0672009-12-04 10:55:24 +1000638 return -EREMOTEIO;
639 }
640 }
David Flynn8316f332010-12-08 16:10:21 +0000641
642 DRM_ERROR("too many retries, giving up\n");
643 return -EREMOTEIO;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700644}
645
646static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100647intel_dp_i2c_init(struct intel_dp *intel_dp,
Zhenyu Wang55f78c42010-03-29 16:13:57 +0800648 struct intel_connector *intel_connector, const char *name)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700649{
Keith Packard0b5c5412011-09-28 16:41:05 -0700650 int ret;
651
Zhenyu Wangd54e9d22009-10-19 15:43:51 +0800652 DRM_DEBUG_KMS("i2c_init %s\n", name);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100653 intel_dp->algo.running = false;
654 intel_dp->algo.address = 0;
655 intel_dp->algo.aux_ch = intel_dp_i2c_aux_ch;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700656
Akshay Joshi0206e352011-08-16 15:34:10 -0400657 memset(&intel_dp->adapter, '\0', sizeof(intel_dp->adapter));
Chris Wilsonea5b2132010-08-04 13:50:23 +0100658 intel_dp->adapter.owner = THIS_MODULE;
659 intel_dp->adapter.class = I2C_CLASS_DDC;
Akshay Joshi0206e352011-08-16 15:34:10 -0400660 strncpy(intel_dp->adapter.name, name, sizeof(intel_dp->adapter.name) - 1);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100661 intel_dp->adapter.name[sizeof(intel_dp->adapter.name) - 1] = '\0';
662 intel_dp->adapter.algo_data = &intel_dp->algo;
663 intel_dp->adapter.dev.parent = &intel_connector->base.kdev;
664
Keith Packard0b5c5412011-09-28 16:41:05 -0700665 ironlake_edp_panel_vdd_on(intel_dp);
666 ret = i2c_dp_aux_add_bus(&intel_dp->adapter);
Keith Packardbd943152011-09-18 23:09:52 -0700667 ironlake_edp_panel_vdd_off(intel_dp, false);
Keith Packard0b5c5412011-09-28 16:41:05 -0700668 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700669}
670
Paulo Zanoni00c09d72012-10-26 19:05:52 -0200671bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100672intel_dp_compute_config(struct intel_encoder *encoder,
673 struct intel_crtc_config *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700674{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100675 struct drm_device *dev = encoder->base.dev;
Daniel Vetter36008362013-03-27 00:44:59 +0100676 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100677 struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
678 struct drm_display_mode *mode = &pipe_config->requested_mode;
679 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jani Nikuladd06f902012-10-19 14:51:50 +0300680 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700681 int lane_count, clock;
Daniel Vetter397fe152012-10-22 22:56:43 +0200682 int max_lane_count = drm_dp_max_lane_count(intel_dp->dpcd);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100683 int max_clock = intel_dp_max_link_bw(intel_dp) == DP_LINK_BW_2_7 ? 1 : 0;
Daniel Vetter083f9562012-04-20 20:23:49 +0200684 int bpp, mode_rate;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700685 static int bws[2] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7 };
Daniel Vetter36008362013-03-27 00:44:59 +0100686 int target_clock, link_avail, link_clock;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700687
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100688 if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev) && !is_cpu_edp(intel_dp))
689 pipe_config->has_pch_encoder = true;
690
Jani Nikuladd06f902012-10-19 14:51:50 +0300691 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
692 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
693 adjusted_mode);
Yuly Novikov53b41832012-10-26 12:04:00 +0300694 intel_pch_panel_fitting(dev,
695 intel_connector->panel.fitting_mode,
Chris Wilson1d8e1c72010-08-07 11:01:28 +0100696 mode, adjusted_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +0100697 }
Daniel Vetter36008362013-03-27 00:44:59 +0100698 /* We need to take the panel's fixed mode into account. */
699 target_clock = adjusted_mode->clock;
Zhao Yakui0d3a1be2010-07-19 09:43:13 +0100700
Daniel Vettercb1793c2012-06-04 18:39:21 +0200701 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +0200702 return false;
703
Daniel Vetter083f9562012-04-20 20:23:49 +0200704 DRM_DEBUG_KMS("DP link computation with max lane count %i "
705 "max bw %02x pixel clock %iKHz\n",
Daniel Vetter71244652012-06-04 18:39:20 +0200706 max_lane_count, bws[max_clock], adjusted_mode->clock);
Daniel Vetter083f9562012-04-20 20:23:49 +0200707
Daniel Vetter36008362013-03-27 00:44:59 +0100708 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
709 * bpc in between. */
710 bpp = 8*3;
711 if (is_edp(intel_dp) && dev_priv->edp.bpp)
712 bpp = min_t(int, bpp, dev_priv->edp.bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +0200713
Daniel Vetter36008362013-03-27 00:44:59 +0100714 for (; bpp >= 6*3; bpp -= 2*3) {
715 mode_rate = intel_dp_link_required(target_clock, bpp);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200716
Daniel Vetter36008362013-03-27 00:44:59 +0100717 for (clock = 0; clock <= max_clock; clock++) {
718 for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) {
719 link_clock = drm_dp_bw_code_to_link_rate(bws[clock]);
720 link_avail = intel_dp_max_data_rate(link_clock,
721 lane_count);
722
723 if (mode_rate <= link_avail) {
724 goto found;
725 }
726 }
727 }
728 }
729
730 return false;
731
732found:
Ville Syrjälä55bc60d2013-01-17 16:31:29 +0200733 if (intel_dp->color_range_auto) {
734 /*
735 * See:
736 * CEA-861-E - 5.1 Default Encoding Parameters
737 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
738 */
Thierry Reding18316c82012-12-20 15:41:44 +0100739 if (bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1)
Ville Syrjälä55bc60d2013-01-17 16:31:29 +0200740 intel_dp->color_range = DP_COLOR_RANGE_16_235;
741 else
742 intel_dp->color_range = 0;
743 }
744
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200745 if (intel_dp->color_range)
Daniel Vetter50f3b012013-03-27 00:44:56 +0100746 pipe_config->limited_color_range = true;
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200747
Daniel Vetter36008362013-03-27 00:44:59 +0100748 intel_dp->link_bw = bws[clock];
749 intel_dp->lane_count = lane_count;
750 adjusted_mode->clock = drm_dp_bw_code_to_link_rate(intel_dp->link_bw);
751 pipe_config->pipe_bpp = bpp;
Daniel Vetterc4867932012-04-10 10:42:36 +0200752
Daniel Vetter36008362013-03-27 00:44:59 +0100753 DRM_DEBUG_KMS("DP link bw %02x lane count %d clock %d bpp %d\n",
754 intel_dp->link_bw, intel_dp->lane_count,
755 adjusted_mode->clock, bpp);
756 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
757 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700758
Daniel Vetter36008362013-03-27 00:44:59 +0100759 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700760}
761
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700762void
763intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode,
764 struct drm_display_mode *adjusted_mode)
765{
766 struct drm_device *dev = crtc->dev;
Paulo Zanonifa90ece2012-10-26 19:05:44 -0200767 struct intel_encoder *intel_encoder;
768 struct intel_dp *intel_dp;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700769 struct drm_i915_private *dev_priv = dev->dev_private;
770 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnes858fa0352011-06-24 12:19:24 -0700771 int lane_count = 4;
Daniel Vettere69d0bc2012-11-29 15:59:36 +0100772 struct intel_link_m_n m_n;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800773 int pipe = intel_crtc->pipe;
Paulo Zanoniafe2fcf2012-10-23 18:30:01 -0200774 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700775
776 /*
Eric Anholt21d40d32010-03-25 11:11:14 -0700777 * Find the lane count in the intel_encoder private
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700778 */
Paulo Zanonifa90ece2012-10-26 19:05:44 -0200779 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
780 intel_dp = enc_to_intel_dp(&intel_encoder->base);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700781
Paulo Zanonifa90ece2012-10-26 19:05:44 -0200782 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
783 intel_encoder->type == INTEL_OUTPUT_EDP)
Keith Packard9a10f402011-11-02 13:03:47 -0700784 {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100785 lane_count = intel_dp->lane_count;
Jesse Barnes51190662010-10-07 16:01:08 -0700786 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700787 }
788 }
789
790 /*
791 * Compute the GMCH and Link ratios. The '3' here is
792 * the number of bytes_per_pixel post-LUT, which we always
793 * set up for 8-bits of R/G/B, or 3 bytes total.
794 */
Daniel Vetter965e0c42013-03-27 00:44:57 +0100795 intel_link_compute_m_n(intel_crtc->config.pipe_bpp, lane_count,
Daniel Vettere69d0bc2012-11-29 15:59:36 +0100796 mode->clock, adjusted_mode->clock, &m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700797
Paulo Zanoni22b8bf12013-02-18 19:00:23 -0300798 if (HAS_DDI(dev)) {
Paulo Zanoniafe2fcf2012-10-23 18:30:01 -0200799 I915_WRITE(PIPE_DATA_M1(cpu_transcoder),
800 TU_SIZE(m_n.tu) | m_n.gmch_m);
801 I915_WRITE(PIPE_DATA_N1(cpu_transcoder), m_n.gmch_n);
802 I915_WRITE(PIPE_LINK_M1(cpu_transcoder), m_n.link_m);
803 I915_WRITE(PIPE_LINK_N1(cpu_transcoder), m_n.link_n);
Paulo Zanoni1eb8dfe2012-10-18 12:42:10 -0300804 } else if (HAS_PCH_SPLIT(dev)) {
Paulo Zanoni7346bfa2012-10-15 15:51:35 -0300805 I915_WRITE(TRANSDATA_M1(pipe), TU_SIZE(m_n.tu) | m_n.gmch_m);
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800806 I915_WRITE(TRANSDATA_N1(pipe), m_n.gmch_n);
807 I915_WRITE(TRANSDPLINK_M1(pipe), m_n.link_m);
808 I915_WRITE(TRANSDPLINK_N1(pipe), m_n.link_n);
Vijay Purushothaman74a4dd22012-09-27 19:13:04 +0530809 } else if (IS_VALLEYVIEW(dev)) {
810 I915_WRITE(PIPE_DATA_M1(pipe), TU_SIZE(m_n.tu) | m_n.gmch_m);
811 I915_WRITE(PIPE_DATA_N1(pipe), m_n.gmch_n);
812 I915_WRITE(PIPE_LINK_M1(pipe), m_n.link_m);
813 I915_WRITE(PIPE_LINK_N1(pipe), m_n.link_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700814 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800815 I915_WRITE(PIPE_GMCH_DATA_M(pipe),
Paulo Zanoni7346bfa2012-10-15 15:51:35 -0300816 TU_SIZE(m_n.tu) | m_n.gmch_m);
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800817 I915_WRITE(PIPE_GMCH_DATA_N(pipe), m_n.gmch_n);
818 I915_WRITE(PIPE_DP_LINK_M(pipe), m_n.link_m);
819 I915_WRITE(PIPE_DP_LINK_N(pipe), m_n.link_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700820 }
821}
822
Paulo Zanoni247d89f2012-10-15 15:51:33 -0300823void intel_dp_init_link_config(struct intel_dp *intel_dp)
824{
825 memset(intel_dp->link_configuration, 0, DP_LINK_CONFIGURATION_SIZE);
826 intel_dp->link_configuration[0] = intel_dp->link_bw;
827 intel_dp->link_configuration[1] = intel_dp->lane_count;
828 intel_dp->link_configuration[8] = DP_SET_ANSI_8B10B;
829 /*
830 * Check for DPCD version > 1.1 and enhanced framing support
831 */
832 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
833 (intel_dp->dpcd[DP_MAX_LANE_COUNT] & DP_ENHANCED_FRAME_CAP)) {
834 intel_dp->link_configuration[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
835 }
836}
837
Daniel Vetterea9b6002012-11-29 15:59:31 +0100838static void ironlake_set_pll_edp(struct drm_crtc *crtc, int clock)
839{
840 struct drm_device *dev = crtc->dev;
841 struct drm_i915_private *dev_priv = dev->dev_private;
842 u32 dpa_ctl;
843
844 DRM_DEBUG_KMS("eDP PLL enable for clock %d\n", clock);
845 dpa_ctl = I915_READ(DP_A);
846 dpa_ctl &= ~DP_PLL_FREQ_MASK;
847
848 if (clock < 200000) {
Daniel Vetter1ce17032012-11-29 15:59:32 +0100849 /* For a long time we've carried around a ILK-DevA w/a for the
850 * 160MHz clock. If we're really unlucky, it's still required.
851 */
852 DRM_DEBUG_KMS("160MHz cpu eDP clock, might need ilk devA w/a\n");
Daniel Vetterea9b6002012-11-29 15:59:31 +0100853 dpa_ctl |= DP_PLL_FREQ_160MHZ;
Daniel Vetterea9b6002012-11-29 15:59:31 +0100854 } else {
855 dpa_ctl |= DP_PLL_FREQ_270MHZ;
856 }
Daniel Vetter1ce17032012-11-29 15:59:32 +0100857
Daniel Vetterea9b6002012-11-29 15:59:31 +0100858 I915_WRITE(DP_A, dpa_ctl);
859
860 POSTING_READ(DP_A);
861 udelay(500);
862}
863
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700864static void
865intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
866 struct drm_display_mode *adjusted_mode)
867{
Zhenyu Wange3421a12010-04-08 09:43:27 +0800868 struct drm_device *dev = encoder->dev;
Keith Packard417e8222011-11-01 19:54:11 -0700869 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100870 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Paulo Zanonifa90ece2012-10-26 19:05:44 -0200871 struct drm_crtc *crtc = encoder->crtc;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700872 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
873
Keith Packard417e8222011-11-01 19:54:11 -0700874 /*
Keith Packard1a2eb462011-11-16 16:26:07 -0800875 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -0700876 *
877 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -0800878 * SNB CPU
879 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -0700880 * CPT PCH
881 *
882 * IBX PCH and CPU are the same for almost everything,
883 * except that the CPU DP PLL is configured in this
884 * register
885 *
886 * CPT PCH is quite different, having many bits moved
887 * to the TRANS_DP_CTL register instead. That
888 * configuration happens (oddly) in ironlake_pch_enable
889 */
Adam Jackson9c9e7922010-04-05 17:57:59 -0400890
Keith Packard417e8222011-11-01 19:54:11 -0700891 /* Preserve the BIOS-computed detected bit. This is
892 * supposed to be read-only.
893 */
894 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700895
Keith Packard417e8222011-11-01 19:54:11 -0700896 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -0700897 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700898
Chris Wilsonea5b2132010-08-04 13:50:23 +0100899 switch (intel_dp->lane_count) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700900 case 1:
Chris Wilsonea5b2132010-08-04 13:50:23 +0100901 intel_dp->DP |= DP_PORT_WIDTH_1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700902 break;
903 case 2:
Chris Wilsonea5b2132010-08-04 13:50:23 +0100904 intel_dp->DP |= DP_PORT_WIDTH_2;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700905 break;
906 case 4:
Chris Wilsonea5b2132010-08-04 13:50:23 +0100907 intel_dp->DP |= DP_PORT_WIDTH_4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700908 break;
909 }
Wu Fengguange0dac652011-09-05 14:25:34 +0800910 if (intel_dp->has_audio) {
911 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
912 pipe_name(intel_crtc->pipe));
Chris Wilsonea5b2132010-08-04 13:50:23 +0100913 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Wu Fengguange0dac652011-09-05 14:25:34 +0800914 intel_write_eld(encoder, adjusted_mode);
915 }
Paulo Zanoni247d89f2012-10-15 15:51:33 -0300916
917 intel_dp_init_link_config(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700918
Keith Packard417e8222011-11-01 19:54:11 -0700919 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800920
Gajanan Bhat19c03922012-09-27 19:13:07 +0530921 if (is_cpu_edp(intel_dp) && IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) {
Keith Packard1a2eb462011-11-16 16:26:07 -0800922 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
923 intel_dp->DP |= DP_SYNC_HS_HIGH;
924 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
925 intel_dp->DP |= DP_SYNC_VS_HIGH;
926 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
927
928 if (intel_dp->link_configuration[1] & DP_LANE_COUNT_ENHANCED_FRAME_EN)
929 intel_dp->DP |= DP_ENHANCED_FRAMING;
930
931 intel_dp->DP |= intel_crtc->pipe << 29;
932
933 /* don't miss out required setting for eDP */
Keith Packard1a2eb462011-11-16 16:26:07 -0800934 if (adjusted_mode->clock < 200000)
935 intel_dp->DP |= DP_PLL_FREQ_160MHZ;
936 else
937 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
938 } else if (!HAS_PCH_CPT(dev) || is_cpu_edp(intel_dp)) {
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200939 if (!HAS_PCH_SPLIT(dev))
940 intel_dp->DP |= intel_dp->color_range;
Keith Packard417e8222011-11-01 19:54:11 -0700941
942 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
943 intel_dp->DP |= DP_SYNC_HS_HIGH;
944 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
945 intel_dp->DP |= DP_SYNC_VS_HIGH;
946 intel_dp->DP |= DP_LINK_TRAIN_OFF;
947
948 if (intel_dp->link_configuration[1] & DP_LANE_COUNT_ENHANCED_FRAME_EN)
949 intel_dp->DP |= DP_ENHANCED_FRAMING;
950
951 if (intel_crtc->pipe == 1)
952 intel_dp->DP |= DP_PIPEB_SELECT;
953
954 if (is_cpu_edp(intel_dp)) {
955 /* don't miss out required setting for eDP */
Keith Packard417e8222011-11-01 19:54:11 -0700956 if (adjusted_mode->clock < 200000)
957 intel_dp->DP |= DP_PLL_FREQ_160MHZ;
958 else
959 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
960 }
961 } else {
962 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800963 }
Daniel Vetterea9b6002012-11-29 15:59:31 +0100964
Jesse Barnes5d66d5b2013-03-01 13:14:30 -0800965 if (is_cpu_edp(intel_dp) && !IS_VALLEYVIEW(dev))
Daniel Vetterea9b6002012-11-29 15:59:31 +0100966 ironlake_set_pll_edp(crtc, adjusted_mode->clock);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700967}
968
Keith Packard99ea7122011-11-01 19:57:50 -0700969#define IDLE_ON_MASK (PP_ON | 0 | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
970#define IDLE_ON_VALUE (PP_ON | 0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
971
972#define IDLE_OFF_MASK (PP_ON | 0 | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
973#define IDLE_OFF_VALUE (0 | 0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
974
975#define IDLE_CYCLE_MASK (PP_ON | 0 | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
976#define IDLE_CYCLE_VALUE (0 | 0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
977
978static void ironlake_wait_panel_status(struct intel_dp *intel_dp,
979 u32 mask,
980 u32 value)
981{
Paulo Zanoni30add222012-10-26 19:05:45 -0200982 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -0700983 struct drm_i915_private *dev_priv = dev->dev_private;
984
985 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
986 mask, value,
987 I915_READ(PCH_PP_STATUS),
988 I915_READ(PCH_PP_CONTROL));
989
990 if (_wait_for((I915_READ(PCH_PP_STATUS) & mask) == value, 5000, 10)) {
991 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
992 I915_READ(PCH_PP_STATUS),
993 I915_READ(PCH_PP_CONTROL));
994 }
995}
996
997static void ironlake_wait_panel_on(struct intel_dp *intel_dp)
998{
999 DRM_DEBUG_KMS("Wait for panel power on\n");
1000 ironlake_wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
1001}
1002
Keith Packardbd943152011-09-18 23:09:52 -07001003static void ironlake_wait_panel_off(struct intel_dp *intel_dp)
1004{
Keith Packardbd943152011-09-18 23:09:52 -07001005 DRM_DEBUG_KMS("Wait for panel power off time\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001006 ironlake_wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001007}
Keith Packardbd943152011-09-18 23:09:52 -07001008
Keith Packard99ea7122011-11-01 19:57:50 -07001009static void ironlake_wait_panel_power_cycle(struct intel_dp *intel_dp)
1010{
1011 DRM_DEBUG_KMS("Wait for panel power cycle\n");
1012 ironlake_wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
1013}
Keith Packardbd943152011-09-18 23:09:52 -07001014
Keith Packard99ea7122011-11-01 19:57:50 -07001015
Keith Packard832dd3c2011-11-01 19:34:06 -07001016/* Read the current pp_control value, unlocking the register if it
1017 * is locked
1018 */
1019
1020static u32 ironlake_get_pp_control(struct drm_i915_private *dev_priv)
1021{
1022 u32 control = I915_READ(PCH_PP_CONTROL);
1023
1024 control &= ~PANEL_UNLOCK_MASK;
1025 control |= PANEL_UNLOCK_REGS;
1026 return control;
Keith Packardbd943152011-09-18 23:09:52 -07001027}
1028
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001029void ironlake_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001030{
Paulo Zanoni30add222012-10-26 19:05:45 -02001031 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001032 struct drm_i915_private *dev_priv = dev->dev_private;
1033 u32 pp;
1034
Keith Packard97af61f572011-09-28 16:23:51 -07001035 if (!is_edp(intel_dp))
1036 return;
Keith Packardf01eca22011-09-28 16:48:10 -07001037 DRM_DEBUG_KMS("Turn eDP VDD on\n");
Jesse Barnes5d613502011-01-24 17:10:54 -08001038
Keith Packardbd943152011-09-18 23:09:52 -07001039 WARN(intel_dp->want_panel_vdd,
1040 "eDP VDD already requested on\n");
1041
1042 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07001043
Keith Packardbd943152011-09-18 23:09:52 -07001044 if (ironlake_edp_have_panel_vdd(intel_dp)) {
1045 DRM_DEBUG_KMS("eDP VDD already on\n");
1046 return;
1047 }
1048
Keith Packard99ea7122011-11-01 19:57:50 -07001049 if (!ironlake_edp_have_panel_power(intel_dp))
1050 ironlake_wait_panel_power_cycle(intel_dp);
1051
Keith Packard832dd3c2011-11-01 19:34:06 -07001052 pp = ironlake_get_pp_control(dev_priv);
Jesse Barnes5d613502011-01-24 17:10:54 -08001053 pp |= EDP_FORCE_VDD;
1054 I915_WRITE(PCH_PP_CONTROL, pp);
1055 POSTING_READ(PCH_PP_CONTROL);
Keith Packardf01eca22011-09-28 16:48:10 -07001056 DRM_DEBUG_KMS("PCH_PP_STATUS: 0x%08x PCH_PP_CONTROL: 0x%08x\n",
1057 I915_READ(PCH_PP_STATUS), I915_READ(PCH_PP_CONTROL));
Keith Packardebf33b12011-09-29 15:53:27 -07001058
1059 /*
1060 * If the panel wasn't on, delay before accessing aux channel
1061 */
1062 if (!ironlake_edp_have_panel_power(intel_dp)) {
Keith Packardbd943152011-09-18 23:09:52 -07001063 DRM_DEBUG_KMS("eDP was not running\n");
Keith Packardf01eca22011-09-28 16:48:10 -07001064 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07001065 }
Jesse Barnes5d613502011-01-24 17:10:54 -08001066}
1067
Keith Packardbd943152011-09-18 23:09:52 -07001068static void ironlake_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001069{
Paulo Zanoni30add222012-10-26 19:05:45 -02001070 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001071 struct drm_i915_private *dev_priv = dev->dev_private;
1072 u32 pp;
1073
Daniel Vettera0e99e62012-12-02 01:05:46 +01001074 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
1075
Keith Packardbd943152011-09-18 23:09:52 -07001076 if (!intel_dp->want_panel_vdd && ironlake_edp_have_panel_vdd(intel_dp)) {
Keith Packard832dd3c2011-11-01 19:34:06 -07001077 pp = ironlake_get_pp_control(dev_priv);
Keith Packardbd943152011-09-18 23:09:52 -07001078 pp &= ~EDP_FORCE_VDD;
1079 I915_WRITE(PCH_PP_CONTROL, pp);
1080 POSTING_READ(PCH_PP_CONTROL);
Jesse Barnes5d613502011-01-24 17:10:54 -08001081
Keith Packardbd943152011-09-18 23:09:52 -07001082 /* Make sure sequencer is idle before allowing subsequent activity */
1083 DRM_DEBUG_KMS("PCH_PP_STATUS: 0x%08x PCH_PP_CONTROL: 0x%08x\n",
1084 I915_READ(PCH_PP_STATUS), I915_READ(PCH_PP_CONTROL));
Keith Packard99ea7122011-11-01 19:57:50 -07001085
1086 msleep(intel_dp->panel_power_down_delay);
Keith Packardbd943152011-09-18 23:09:52 -07001087 }
1088}
1089
1090static void ironlake_panel_vdd_work(struct work_struct *__work)
1091{
1092 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
1093 struct intel_dp, panel_vdd_work);
Paulo Zanoni30add222012-10-26 19:05:45 -02001094 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07001095
Keith Packard627f7672011-10-31 11:30:10 -07001096 mutex_lock(&dev->mode_config.mutex);
Keith Packardbd943152011-09-18 23:09:52 -07001097 ironlake_panel_vdd_off_sync(intel_dp);
Keith Packard627f7672011-10-31 11:30:10 -07001098 mutex_unlock(&dev->mode_config.mutex);
Keith Packardbd943152011-09-18 23:09:52 -07001099}
1100
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001101void ironlake_edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07001102{
Keith Packard97af61f572011-09-28 16:23:51 -07001103 if (!is_edp(intel_dp))
1104 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08001105
Keith Packardbd943152011-09-18 23:09:52 -07001106 DRM_DEBUG_KMS("Turn eDP VDD off %d\n", intel_dp->want_panel_vdd);
1107 WARN(!intel_dp->want_panel_vdd, "eDP VDD not forced on");
Keith Packardf2e8b182011-11-01 20:01:35 -07001108
Keith Packardbd943152011-09-18 23:09:52 -07001109 intel_dp->want_panel_vdd = false;
1110
1111 if (sync) {
1112 ironlake_panel_vdd_off_sync(intel_dp);
1113 } else {
1114 /*
1115 * Queue the timer to fire a long
1116 * time from now (relative to the power down delay)
1117 * to keep the panel power up across a sequence of operations
1118 */
1119 schedule_delayed_work(&intel_dp->panel_vdd_work,
1120 msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5));
1121 }
Jesse Barnes5d613502011-01-24 17:10:54 -08001122}
1123
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001124void ironlake_edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07001125{
Paulo Zanoni30add222012-10-26 19:05:45 -02001126 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07001127 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packard99ea7122011-11-01 19:57:50 -07001128 u32 pp;
Jesse Barnes9934c132010-07-22 13:18:19 -07001129
Keith Packard97af61f572011-09-28 16:23:51 -07001130 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07001131 return;
Keith Packard99ea7122011-11-01 19:57:50 -07001132
1133 DRM_DEBUG_KMS("Turn eDP power on\n");
1134
1135 if (ironlake_edp_have_panel_power(intel_dp)) {
1136 DRM_DEBUG_KMS("eDP power already on\n");
Keith Packard7d639f32011-09-29 16:05:34 -07001137 return;
Keith Packard99ea7122011-11-01 19:57:50 -07001138 }
Jesse Barnes9934c132010-07-22 13:18:19 -07001139
Keith Packard99ea7122011-11-01 19:57:50 -07001140 ironlake_wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001141
Keith Packard832dd3c2011-11-01 19:34:06 -07001142 pp = ironlake_get_pp_control(dev_priv);
Keith Packard05ce1a42011-09-29 16:33:01 -07001143 if (IS_GEN5(dev)) {
1144 /* ILK workaround: disable reset around power sequence */
1145 pp &= ~PANEL_POWER_RESET;
1146 I915_WRITE(PCH_PP_CONTROL, pp);
1147 POSTING_READ(PCH_PP_CONTROL);
1148 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001149
Keith Packard1c0ae802011-09-19 13:59:29 -07001150 pp |= POWER_TARGET_ON;
Keith Packard99ea7122011-11-01 19:57:50 -07001151 if (!IS_GEN5(dev))
1152 pp |= PANEL_POWER_RESET;
1153
Jesse Barnes9934c132010-07-22 13:18:19 -07001154 I915_WRITE(PCH_PP_CONTROL, pp);
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001155 POSTING_READ(PCH_PP_CONTROL);
Jesse Barnes9934c132010-07-22 13:18:19 -07001156
Keith Packard99ea7122011-11-01 19:57:50 -07001157 ironlake_wait_panel_on(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07001158
Keith Packard05ce1a42011-09-29 16:33:01 -07001159 if (IS_GEN5(dev)) {
1160 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
1161 I915_WRITE(PCH_PP_CONTROL, pp);
1162 POSTING_READ(PCH_PP_CONTROL);
1163 }
Jesse Barnes9934c132010-07-22 13:18:19 -07001164}
1165
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001166void ironlake_edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07001167{
Paulo Zanoni30add222012-10-26 19:05:45 -02001168 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07001169 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packard99ea7122011-11-01 19:57:50 -07001170 u32 pp;
Jesse Barnes9934c132010-07-22 13:18:19 -07001171
Keith Packard97af61f572011-09-28 16:23:51 -07001172 if (!is_edp(intel_dp))
1173 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001174
Keith Packard99ea7122011-11-01 19:57:50 -07001175 DRM_DEBUG_KMS("Turn eDP power off\n");
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001176
Daniel Vetter6cb49832012-05-20 17:14:50 +02001177 WARN(!intel_dp->want_panel_vdd, "Need VDD to turn off panel\n");
Jesse Barnes9934c132010-07-22 13:18:19 -07001178
Keith Packard832dd3c2011-11-01 19:34:06 -07001179 pp = ironlake_get_pp_control(dev_priv);
Daniel Vetter35a38552012-08-12 22:17:14 +02001180 /* We need to switch off panel power _and_ force vdd, for otherwise some
1181 * panels get very unhappy and cease to work. */
1182 pp &= ~(POWER_TARGET_ON | EDP_FORCE_VDD | PANEL_POWER_RESET | EDP_BLC_ENABLE);
Keith Packard99ea7122011-11-01 19:57:50 -07001183 I915_WRITE(PCH_PP_CONTROL, pp);
1184 POSTING_READ(PCH_PP_CONTROL);
Jesse Barnes9934c132010-07-22 13:18:19 -07001185
Daniel Vetter35a38552012-08-12 22:17:14 +02001186 intel_dp->want_panel_vdd = false;
1187
Keith Packard99ea7122011-11-01 19:57:50 -07001188 ironlake_wait_panel_off(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07001189}
1190
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001191void ironlake_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001192{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001193 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1194 struct drm_device *dev = intel_dig_port->base.base.dev;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001195 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001196 int pipe = to_intel_crtc(intel_dig_port->base.base.crtc)->pipe;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001197 u32 pp;
1198
Keith Packardf01eca22011-09-28 16:48:10 -07001199 if (!is_edp(intel_dp))
1200 return;
1201
Zhao Yakui28c97732009-10-09 11:39:41 +08001202 DRM_DEBUG_KMS("\n");
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001203 /*
1204 * If we enable the backlight right away following a panel power
1205 * on, we may see slight flicker as the panel syncs with the eDP
1206 * link. So delay a bit to make sure the image is solid before
1207 * allowing it to appear.
1208 */
Keith Packardf01eca22011-09-28 16:48:10 -07001209 msleep(intel_dp->backlight_on_delay);
Keith Packard832dd3c2011-11-01 19:34:06 -07001210 pp = ironlake_get_pp_control(dev_priv);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001211 pp |= EDP_BLC_ENABLE;
1212 I915_WRITE(PCH_PP_CONTROL, pp);
Keith Packardf01eca22011-09-28 16:48:10 -07001213 POSTING_READ(PCH_PP_CONTROL);
Daniel Vetter035aa3d2012-10-20 20:57:42 +02001214
1215 intel_panel_enable_backlight(dev, pipe);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001216}
1217
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001218void ironlake_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001219{
Paulo Zanoni30add222012-10-26 19:05:45 -02001220 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001221 struct drm_i915_private *dev_priv = dev->dev_private;
1222 u32 pp;
1223
Keith Packardf01eca22011-09-28 16:48:10 -07001224 if (!is_edp(intel_dp))
1225 return;
1226
Daniel Vetter035aa3d2012-10-20 20:57:42 +02001227 intel_panel_disable_backlight(dev);
1228
Zhao Yakui28c97732009-10-09 11:39:41 +08001229 DRM_DEBUG_KMS("\n");
Keith Packard832dd3c2011-11-01 19:34:06 -07001230 pp = ironlake_get_pp_control(dev_priv);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001231 pp &= ~EDP_BLC_ENABLE;
1232 I915_WRITE(PCH_PP_CONTROL, pp);
Keith Packardf01eca22011-09-28 16:48:10 -07001233 POSTING_READ(PCH_PP_CONTROL);
1234 msleep(intel_dp->backlight_off_delay);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001235}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001236
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001237static void ironlake_edp_pll_on(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07001238{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001239 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1240 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
1241 struct drm_device *dev = crtc->dev;
Jesse Barnesd240f202010-08-13 15:43:26 -07001242 struct drm_i915_private *dev_priv = dev->dev_private;
1243 u32 dpa_ctl;
1244
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001245 assert_pipe_disabled(dev_priv,
1246 to_intel_crtc(crtc)->pipe);
1247
Jesse Barnesd240f202010-08-13 15:43:26 -07001248 DRM_DEBUG_KMS("\n");
1249 dpa_ctl = I915_READ(DP_A);
Daniel Vetter07679352012-09-06 22:15:42 +02001250 WARN(dpa_ctl & DP_PLL_ENABLE, "dp pll on, should be off\n");
1251 WARN(dpa_ctl & DP_PORT_EN, "dp port still on, should be off\n");
1252
1253 /* We don't adjust intel_dp->DP while tearing down the link, to
1254 * facilitate link retraining (e.g. after hotplug). Hence clear all
1255 * enable bits here to ensure that we don't enable too much. */
1256 intel_dp->DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
1257 intel_dp->DP |= DP_PLL_ENABLE;
1258 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07001259 POSTING_READ(DP_A);
1260 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07001261}
1262
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001263static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07001264{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001265 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1266 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
1267 struct drm_device *dev = crtc->dev;
Jesse Barnesd240f202010-08-13 15:43:26 -07001268 struct drm_i915_private *dev_priv = dev->dev_private;
1269 u32 dpa_ctl;
1270
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001271 assert_pipe_disabled(dev_priv,
1272 to_intel_crtc(crtc)->pipe);
1273
Jesse Barnesd240f202010-08-13 15:43:26 -07001274 dpa_ctl = I915_READ(DP_A);
Daniel Vetter07679352012-09-06 22:15:42 +02001275 WARN((dpa_ctl & DP_PLL_ENABLE) == 0,
1276 "dp pll off, should be on\n");
1277 WARN(dpa_ctl & DP_PORT_EN, "dp port still on, should be off\n");
1278
1279 /* We can't rely on the value tracked for the DP register in
1280 * intel_dp->DP because link_down must not change that (otherwise link
1281 * re-training will fail. */
Jesse Barnes298b0b32010-10-07 16:01:24 -07001282 dpa_ctl &= ~DP_PLL_ENABLE;
Jesse Barnesd240f202010-08-13 15:43:26 -07001283 I915_WRITE(DP_A, dpa_ctl);
Chris Wilson1af5fa12010-09-08 21:07:28 +01001284 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07001285 udelay(200);
1286}
1287
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001288/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03001289void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001290{
1291 int ret, i;
1292
1293 /* Should have a valid DPCD by this point */
1294 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
1295 return;
1296
1297 if (mode != DRM_MODE_DPMS_ON) {
1298 ret = intel_dp_aux_native_write_1(intel_dp, DP_SET_POWER,
1299 DP_SET_POWER_D3);
1300 if (ret != 1)
1301 DRM_DEBUG_DRIVER("failed to write sink power state\n");
1302 } else {
1303 /*
1304 * When turning on, we need to retry for 1ms to give the sink
1305 * time to wake up.
1306 */
1307 for (i = 0; i < 3; i++) {
1308 ret = intel_dp_aux_native_write_1(intel_dp,
1309 DP_SET_POWER,
1310 DP_SET_POWER_D0);
1311 if (ret == 1)
1312 break;
1313 msleep(1);
1314 }
1315 }
1316}
1317
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001318static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
1319 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07001320{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001321 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1322 struct drm_device *dev = encoder->base.dev;
1323 struct drm_i915_private *dev_priv = dev->dev_private;
1324 u32 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07001325
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001326 if (!(tmp & DP_PORT_EN))
1327 return false;
1328
Jesse Barnes5d66d5b2013-03-01 13:14:30 -08001329 if (is_cpu_edp(intel_dp) && IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001330 *pipe = PORT_TO_PIPE_CPT(tmp);
1331 } else if (!HAS_PCH_CPT(dev) || is_cpu_edp(intel_dp)) {
1332 *pipe = PORT_TO_PIPE(tmp);
1333 } else {
1334 u32 trans_sel;
1335 u32 trans_dp;
1336 int i;
1337
1338 switch (intel_dp->output_reg) {
1339 case PCH_DP_B:
1340 trans_sel = TRANS_DP_PORT_SEL_B;
1341 break;
1342 case PCH_DP_C:
1343 trans_sel = TRANS_DP_PORT_SEL_C;
1344 break;
1345 case PCH_DP_D:
1346 trans_sel = TRANS_DP_PORT_SEL_D;
1347 break;
1348 default:
1349 return true;
1350 }
1351
1352 for_each_pipe(i) {
1353 trans_dp = I915_READ(TRANS_DP_CTL(i));
1354 if ((trans_dp & TRANS_DP_PORT_SEL_MASK) == trans_sel) {
1355 *pipe = i;
1356 return true;
1357 }
1358 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001359
Daniel Vetter4a0833e2012-10-26 10:58:11 +02001360 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
1361 intel_dp->output_reg);
1362 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001363
Jesse Barnesdeb18212013-04-02 10:03:56 -07001364 return false;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001365}
1366
Daniel Vettere8cb4552012-07-01 13:05:48 +02001367static void intel_disable_dp(struct intel_encoder *encoder)
Jesse Barnesd240f202010-08-13 15:43:26 -07001368{
Daniel Vettere8cb4552012-07-01 13:05:48 +02001369 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Daniel Vetter6cb49832012-05-20 17:14:50 +02001370
1371 /* Make sure the panel is off before trying to change the mode. But also
1372 * ensure that we have vdd while we switch off the panel. */
1373 ironlake_edp_panel_vdd_on(intel_dp);
Keith Packard21264c62011-11-01 20:25:21 -07001374 ironlake_edp_backlight_off(intel_dp);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001375 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
Daniel Vetter35a38552012-08-12 22:17:14 +02001376 ironlake_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02001377
1378 /* cpu edp my only be disable _after_ the cpu pipe/plane is disabled. */
1379 if (!is_cpu_edp(intel_dp))
1380 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07001381}
1382
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001383static void intel_post_disable_dp(struct intel_encoder *encoder)
Jesse Barnesd240f202010-08-13 15:43:26 -07001384{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001385 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1386
Daniel Vetter37398502012-09-06 22:15:44 +02001387 if (is_cpu_edp(intel_dp)) {
1388 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001389 ironlake_edp_pll_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02001390 }
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001391}
1392
Daniel Vettere8cb4552012-07-01 13:05:48 +02001393static void intel_enable_dp(struct intel_encoder *encoder)
Jesse Barnesd240f202010-08-13 15:43:26 -07001394{
Daniel Vettere8cb4552012-07-01 13:05:48 +02001395 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1396 struct drm_device *dev = encoder->base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001397 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001398 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001399
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02001400 if (WARN_ON(dp_reg & DP_PORT_EN))
1401 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001402
1403 ironlake_edp_panel_vdd_on(intel_dp);
1404 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1405 intel_dp_start_link_train(intel_dp);
1406 ironlake_edp_panel_on(intel_dp);
1407 ironlake_edp_panel_vdd_off(intel_dp, true);
1408 intel_dp_complete_link_train(intel_dp);
1409 ironlake_edp_backlight_on(intel_dp);
1410}
1411
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001412static void intel_pre_enable_dp(struct intel_encoder *encoder)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001413{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001414 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001415
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001416 if (is_cpu_edp(intel_dp))
1417 ironlake_edp_pll_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001418}
1419
1420/*
Jesse Barnesdf0c2372011-07-07 11:11:02 -07001421 * Native read with retry for link status and receiver capability reads for
1422 * cases where the sink may still be asleep.
1423 */
1424static bool
1425intel_dp_aux_native_read_retry(struct intel_dp *intel_dp, uint16_t address,
1426 uint8_t *recv, int recv_bytes)
1427{
1428 int ret, i;
1429
1430 /*
1431 * Sinks are *supposed* to come up within 1ms from an off state,
1432 * but we're also supposed to retry 3 times per the spec.
1433 */
1434 for (i = 0; i < 3; i++) {
1435 ret = intel_dp_aux_native_read(intel_dp, address, recv,
1436 recv_bytes);
1437 if (ret == recv_bytes)
1438 return true;
1439 msleep(1);
1440 }
1441
1442 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001443}
1444
1445/*
1446 * Fetch AUX CH registers 0x202 - 0x207 which contain
1447 * link status information
1448 */
1449static bool
Keith Packard93f62da2011-11-01 19:45:03 -07001450intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001451{
Jesse Barnesdf0c2372011-07-07 11:11:02 -07001452 return intel_dp_aux_native_read_retry(intel_dp,
1453 DP_LANE0_1_STATUS,
Keith Packard93f62da2011-11-01 19:45:03 -07001454 link_status,
Jesse Barnesdf0c2372011-07-07 11:11:02 -07001455 DP_LINK_STATUS_SIZE);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001456}
1457
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001458#if 0
1459static char *voltage_names[] = {
1460 "0.4V", "0.6V", "0.8V", "1.2V"
1461};
1462static char *pre_emph_names[] = {
1463 "0dB", "3.5dB", "6dB", "9.5dB"
1464};
1465static char *link_train_names[] = {
1466 "pattern 1", "pattern 2", "idle", "off"
1467};
1468#endif
1469
1470/*
1471 * These are source-specific values; current Intel hardware supports
1472 * a maximum voltage of 800mV and a maximum pre-emphasis of 6dB
1473 */
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001474
1475static uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08001476intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001477{
Paulo Zanoni30add222012-10-26 19:05:45 -02001478 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packard1a2eb462011-11-16 16:26:07 -08001479
1480 if (IS_GEN7(dev) && is_cpu_edp(intel_dp))
1481 return DP_TRAIN_VOLTAGE_SWING_800;
1482 else if (HAS_PCH_CPT(dev) && !is_cpu_edp(intel_dp))
1483 return DP_TRAIN_VOLTAGE_SWING_1200;
1484 else
1485 return DP_TRAIN_VOLTAGE_SWING_800;
1486}
1487
1488static uint8_t
1489intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
1490{
Paulo Zanoni30add222012-10-26 19:05:45 -02001491 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packard1a2eb462011-11-16 16:26:07 -08001492
Paulo Zanoni22b8bf12013-02-18 19:00:23 -03001493 if (HAS_DDI(dev)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001494 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
1495 case DP_TRAIN_VOLTAGE_SWING_400:
1496 return DP_TRAIN_PRE_EMPHASIS_9_5;
1497 case DP_TRAIN_VOLTAGE_SWING_600:
1498 return DP_TRAIN_PRE_EMPHASIS_6;
1499 case DP_TRAIN_VOLTAGE_SWING_800:
1500 return DP_TRAIN_PRE_EMPHASIS_3_5;
1501 case DP_TRAIN_VOLTAGE_SWING_1200:
1502 default:
1503 return DP_TRAIN_PRE_EMPHASIS_0;
1504 }
1505 } else if (IS_GEN7(dev) && is_cpu_edp(intel_dp) && !IS_VALLEYVIEW(dev)) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001506 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
1507 case DP_TRAIN_VOLTAGE_SWING_400:
1508 return DP_TRAIN_PRE_EMPHASIS_6;
1509 case DP_TRAIN_VOLTAGE_SWING_600:
1510 case DP_TRAIN_VOLTAGE_SWING_800:
1511 return DP_TRAIN_PRE_EMPHASIS_3_5;
1512 default:
1513 return DP_TRAIN_PRE_EMPHASIS_0;
1514 }
1515 } else {
1516 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
1517 case DP_TRAIN_VOLTAGE_SWING_400:
1518 return DP_TRAIN_PRE_EMPHASIS_6;
1519 case DP_TRAIN_VOLTAGE_SWING_600:
1520 return DP_TRAIN_PRE_EMPHASIS_6;
1521 case DP_TRAIN_VOLTAGE_SWING_800:
1522 return DP_TRAIN_PRE_EMPHASIS_3_5;
1523 case DP_TRAIN_VOLTAGE_SWING_1200:
1524 default:
1525 return DP_TRAIN_PRE_EMPHASIS_0;
1526 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001527 }
1528}
1529
1530static void
Keith Packard93f62da2011-11-01 19:45:03 -07001531intel_get_adjust_train(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001532{
1533 uint8_t v = 0;
1534 uint8_t p = 0;
1535 int lane;
Keith Packard1a2eb462011-11-16 16:26:07 -08001536 uint8_t voltage_max;
1537 uint8_t preemph_max;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001538
Jesse Barnes33a34e42010-09-08 12:42:02 -07001539 for (lane = 0; lane < intel_dp->lane_count; lane++) {
Daniel Vetter0f037bd2012-10-18 10:15:27 +02001540 uint8_t this_v = drm_dp_get_adjust_request_voltage(link_status, lane);
1541 uint8_t this_p = drm_dp_get_adjust_request_pre_emphasis(link_status, lane);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001542
1543 if (this_v > v)
1544 v = this_v;
1545 if (this_p > p)
1546 p = this_p;
1547 }
1548
Keith Packard1a2eb462011-11-16 16:26:07 -08001549 voltage_max = intel_dp_voltage_max(intel_dp);
Keith Packard417e8222011-11-01 19:54:11 -07001550 if (v >= voltage_max)
1551 v = voltage_max | DP_TRAIN_MAX_SWING_REACHED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001552
Keith Packard1a2eb462011-11-16 16:26:07 -08001553 preemph_max = intel_dp_pre_emphasis_max(intel_dp, v);
1554 if (p >= preemph_max)
1555 p = preemph_max | DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001556
1557 for (lane = 0; lane < 4; lane++)
Jesse Barnes33a34e42010-09-08 12:42:02 -07001558 intel_dp->train_set[lane] = v | p;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001559}
1560
1561static uint32_t
Paulo Zanonif0a34242012-12-06 16:51:50 -02001562intel_gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001563{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001564 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001565
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001566 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001567 case DP_TRAIN_VOLTAGE_SWING_400:
1568 default:
1569 signal_levels |= DP_VOLTAGE_0_4;
1570 break;
1571 case DP_TRAIN_VOLTAGE_SWING_600:
1572 signal_levels |= DP_VOLTAGE_0_6;
1573 break;
1574 case DP_TRAIN_VOLTAGE_SWING_800:
1575 signal_levels |= DP_VOLTAGE_0_8;
1576 break;
1577 case DP_TRAIN_VOLTAGE_SWING_1200:
1578 signal_levels |= DP_VOLTAGE_1_2;
1579 break;
1580 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001581 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001582 case DP_TRAIN_PRE_EMPHASIS_0:
1583 default:
1584 signal_levels |= DP_PRE_EMPHASIS_0;
1585 break;
1586 case DP_TRAIN_PRE_EMPHASIS_3_5:
1587 signal_levels |= DP_PRE_EMPHASIS_3_5;
1588 break;
1589 case DP_TRAIN_PRE_EMPHASIS_6:
1590 signal_levels |= DP_PRE_EMPHASIS_6;
1591 break;
1592 case DP_TRAIN_PRE_EMPHASIS_9_5:
1593 signal_levels |= DP_PRE_EMPHASIS_9_5;
1594 break;
1595 }
1596 return signal_levels;
1597}
1598
Zhenyu Wange3421a12010-04-08 09:43:27 +08001599/* Gen6's DP voltage swing and pre-emphasis control */
1600static uint32_t
1601intel_gen6_edp_signal_levels(uint8_t train_set)
1602{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001603 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
1604 DP_TRAIN_PRE_EMPHASIS_MASK);
1605 switch (signal_levels) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08001606 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001607 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
1608 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
1609 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
1610 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001611 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001612 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
1613 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001614 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001615 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
1616 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001617 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001618 case DP_TRAIN_VOLTAGE_SWING_1200 | DP_TRAIN_PRE_EMPHASIS_0:
1619 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001620 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001621 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
1622 "0x%x\n", signal_levels);
1623 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001624 }
1625}
1626
Keith Packard1a2eb462011-11-16 16:26:07 -08001627/* Gen7's DP voltage swing and pre-emphasis control */
1628static uint32_t
1629intel_gen7_edp_signal_levels(uint8_t train_set)
1630{
1631 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
1632 DP_TRAIN_PRE_EMPHASIS_MASK);
1633 switch (signal_levels) {
1634 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
1635 return EDP_LINK_TRAIN_400MV_0DB_IVB;
1636 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
1637 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
1638 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
1639 return EDP_LINK_TRAIN_400MV_6DB_IVB;
1640
1641 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
1642 return EDP_LINK_TRAIN_600MV_0DB_IVB;
1643 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
1644 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
1645
1646 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
1647 return EDP_LINK_TRAIN_800MV_0DB_IVB;
1648 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
1649 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
1650
1651 default:
1652 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
1653 "0x%x\n", signal_levels);
1654 return EDP_LINK_TRAIN_500MV_0DB_IVB;
1655 }
1656}
1657
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001658/* Gen7.5's (HSW) DP voltage swing and pre-emphasis control */
1659static uint32_t
Paulo Zanonif0a34242012-12-06 16:51:50 -02001660intel_hsw_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001661{
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001662 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
1663 DP_TRAIN_PRE_EMPHASIS_MASK);
1664 switch (signal_levels) {
1665 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
1666 return DDI_BUF_EMP_400MV_0DB_HSW;
1667 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
1668 return DDI_BUF_EMP_400MV_3_5DB_HSW;
1669 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
1670 return DDI_BUF_EMP_400MV_6DB_HSW;
1671 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_9_5:
1672 return DDI_BUF_EMP_400MV_9_5DB_HSW;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001673
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001674 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
1675 return DDI_BUF_EMP_600MV_0DB_HSW;
1676 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
1677 return DDI_BUF_EMP_600MV_3_5DB_HSW;
1678 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
1679 return DDI_BUF_EMP_600MV_6DB_HSW;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001680
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001681 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
1682 return DDI_BUF_EMP_800MV_0DB_HSW;
1683 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
1684 return DDI_BUF_EMP_800MV_3_5DB_HSW;
1685 default:
1686 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
1687 "0x%x\n", signal_levels);
1688 return DDI_BUF_EMP_400MV_0DB_HSW;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001689 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001690}
1691
Paulo Zanonif0a34242012-12-06 16:51:50 -02001692/* Properly updates "DP" with the correct signal levels. */
1693static void
1694intel_dp_set_signal_levels(struct intel_dp *intel_dp, uint32_t *DP)
1695{
1696 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1697 struct drm_device *dev = intel_dig_port->base.base.dev;
1698 uint32_t signal_levels, mask;
1699 uint8_t train_set = intel_dp->train_set[0];
1700
Paulo Zanoni22b8bf12013-02-18 19:00:23 -03001701 if (HAS_DDI(dev)) {
Paulo Zanonif0a34242012-12-06 16:51:50 -02001702 signal_levels = intel_hsw_signal_levels(train_set);
1703 mask = DDI_BUF_EMP_MASK;
1704 } else if (IS_GEN7(dev) && is_cpu_edp(intel_dp) && !IS_VALLEYVIEW(dev)) {
1705 signal_levels = intel_gen7_edp_signal_levels(train_set);
1706 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
1707 } else if (IS_GEN6(dev) && is_cpu_edp(intel_dp)) {
1708 signal_levels = intel_gen6_edp_signal_levels(train_set);
1709 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
1710 } else {
1711 signal_levels = intel_gen4_signal_levels(train_set);
1712 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
1713 }
1714
1715 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
1716
1717 *DP = (*DP & ~mask) | signal_levels;
1718}
1719
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001720static bool
Chris Wilsonea5b2132010-08-04 13:50:23 +01001721intel_dp_set_link_train(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001722 uint32_t dp_reg_value,
Chris Wilson58e10eb2010-10-03 10:56:11 +01001723 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001724{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001725 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1726 struct drm_device *dev = intel_dig_port->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001727 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001728 enum port port = intel_dig_port->port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001729 int ret;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001730 uint32_t temp;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001731
Paulo Zanoni22b8bf12013-02-18 19:00:23 -03001732 if (HAS_DDI(dev)) {
Paulo Zanoni174edf12012-10-26 19:05:50 -02001733 temp = I915_READ(DP_TP_CTL(port));
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001734
1735 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
1736 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
1737 else
1738 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
1739
1740 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
1741 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
1742 case DP_TRAINING_PATTERN_DISABLE:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001743
Paulo Zanoni10aa17c2013-01-29 16:35:18 -02001744 if (port != PORT_A) {
1745 temp |= DP_TP_CTL_LINK_TRAIN_IDLE;
1746 I915_WRITE(DP_TP_CTL(port), temp);
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001747
Paulo Zanoni10aa17c2013-01-29 16:35:18 -02001748 if (wait_for((I915_READ(DP_TP_STATUS(port)) &
1749 DP_TP_STATUS_IDLE_DONE), 1))
1750 DRM_ERROR("Timed out waiting for DP idle patterns\n");
1751
1752 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
1753 }
1754
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001755 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
1756
1757 break;
1758 case DP_TRAINING_PATTERN_1:
1759 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
1760 break;
1761 case DP_TRAINING_PATTERN_2:
1762 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
1763 break;
1764 case DP_TRAINING_PATTERN_3:
1765 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
1766 break;
1767 }
Paulo Zanoni174edf12012-10-26 19:05:50 -02001768 I915_WRITE(DP_TP_CTL(port), temp);
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001769
1770 } else if (HAS_PCH_CPT(dev) &&
1771 (IS_GEN7(dev) || !is_cpu_edp(intel_dp))) {
Paulo Zanoni47ea7542012-07-17 16:55:16 -03001772 dp_reg_value &= ~DP_LINK_TRAIN_MASK_CPT;
1773
1774 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
1775 case DP_TRAINING_PATTERN_DISABLE:
1776 dp_reg_value |= DP_LINK_TRAIN_OFF_CPT;
1777 break;
1778 case DP_TRAINING_PATTERN_1:
1779 dp_reg_value |= DP_LINK_TRAIN_PAT_1_CPT;
1780 break;
1781 case DP_TRAINING_PATTERN_2:
1782 dp_reg_value |= DP_LINK_TRAIN_PAT_2_CPT;
1783 break;
1784 case DP_TRAINING_PATTERN_3:
1785 DRM_ERROR("DP training pattern 3 not supported\n");
1786 dp_reg_value |= DP_LINK_TRAIN_PAT_2_CPT;
1787 break;
1788 }
1789
1790 } else {
1791 dp_reg_value &= ~DP_LINK_TRAIN_MASK;
1792
1793 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
1794 case DP_TRAINING_PATTERN_DISABLE:
1795 dp_reg_value |= DP_LINK_TRAIN_OFF;
1796 break;
1797 case DP_TRAINING_PATTERN_1:
1798 dp_reg_value |= DP_LINK_TRAIN_PAT_1;
1799 break;
1800 case DP_TRAINING_PATTERN_2:
1801 dp_reg_value |= DP_LINK_TRAIN_PAT_2;
1802 break;
1803 case DP_TRAINING_PATTERN_3:
1804 DRM_ERROR("DP training pattern 3 not supported\n");
1805 dp_reg_value |= DP_LINK_TRAIN_PAT_2;
1806 break;
1807 }
1808 }
1809
Chris Wilsonea5b2132010-08-04 13:50:23 +01001810 I915_WRITE(intel_dp->output_reg, dp_reg_value);
1811 POSTING_READ(intel_dp->output_reg);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001812
Chris Wilsonea5b2132010-08-04 13:50:23 +01001813 intel_dp_aux_native_write_1(intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001814 DP_TRAINING_PATTERN_SET,
1815 dp_train_pat);
1816
Paulo Zanoni47ea7542012-07-17 16:55:16 -03001817 if ((dp_train_pat & DP_TRAINING_PATTERN_MASK) !=
1818 DP_TRAINING_PATTERN_DISABLE) {
1819 ret = intel_dp_aux_native_write(intel_dp,
1820 DP_TRAINING_LANE0_SET,
1821 intel_dp->train_set,
1822 intel_dp->lane_count);
1823 if (ret != intel_dp->lane_count)
1824 return false;
1825 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001826
1827 return true;
1828}
1829
Jesse Barnes33a34e42010-09-08 12:42:02 -07001830/* Enable corresponding port and start training pattern 1 */
Paulo Zanonic19b0662012-10-15 15:51:41 -03001831void
Jesse Barnes33a34e42010-09-08 12:42:02 -07001832intel_dp_start_link_train(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001833{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001834 struct drm_encoder *encoder = &dp_to_dig_port(intel_dp)->base.base;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001835 struct drm_device *dev = encoder->dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001836 int i;
1837 uint8_t voltage;
1838 bool clock_recovery = false;
Keith Packardcdb0e952011-11-01 20:00:06 -07001839 int voltage_tries, loop_tries;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001840 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001841
Paulo Zanoniaffa9352012-11-23 15:30:39 -02001842 if (HAS_DDI(dev))
Paulo Zanonic19b0662012-10-15 15:51:41 -03001843 intel_ddi_prepare_link_retrain(encoder);
1844
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001845 /* Write the link configuration data */
1846 intel_dp_aux_native_write(intel_dp, DP_LINK_BW_SET,
1847 intel_dp->link_configuration,
1848 DP_LINK_CONFIGURATION_SIZE);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001849
1850 DP |= DP_PORT_EN;
Keith Packard1a2eb462011-11-16 16:26:07 -08001851
Jesse Barnes33a34e42010-09-08 12:42:02 -07001852 memset(intel_dp->train_set, 0, 4);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001853 voltage = 0xff;
Keith Packardcdb0e952011-11-01 20:00:06 -07001854 voltage_tries = 0;
1855 loop_tries = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001856 clock_recovery = false;
1857 for (;;) {
Jesse Barnes33a34e42010-09-08 12:42:02 -07001858 /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */
Keith Packard93f62da2011-11-01 19:45:03 -07001859 uint8_t link_status[DP_LINK_STATUS_SIZE];
Keith Packard417e8222011-11-01 19:54:11 -07001860
Paulo Zanonif0a34242012-12-06 16:51:50 -02001861 intel_dp_set_signal_levels(intel_dp, &DP);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001862
Daniel Vettera7c96552012-10-18 10:15:30 +02001863 /* Set training pattern 1 */
Paulo Zanoni47ea7542012-07-17 16:55:16 -03001864 if (!intel_dp_set_link_train(intel_dp, DP,
Adam Jackson81055852011-07-21 17:48:37 -04001865 DP_TRAINING_PATTERN_1 |
1866 DP_LINK_SCRAMBLING_DISABLE))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001867 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001868
Daniel Vettera7c96552012-10-18 10:15:30 +02001869 drm_dp_link_train_clock_recovery_delay(intel_dp->dpcd);
Keith Packard93f62da2011-11-01 19:45:03 -07001870 if (!intel_dp_get_link_status(intel_dp, link_status)) {
1871 DRM_ERROR("failed to get link status\n");
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001872 break;
Keith Packard93f62da2011-11-01 19:45:03 -07001873 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001874
Daniel Vetter01916272012-10-18 10:15:25 +02001875 if (drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
Keith Packard93f62da2011-11-01 19:45:03 -07001876 DRM_DEBUG_KMS("clock recovery OK\n");
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001877 clock_recovery = true;
1878 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001879 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001880
1881 /* Check to see if we've tried the max voltage */
1882 for (i = 0; i < intel_dp->lane_count; i++)
1883 if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
1884 break;
Paulo Zanoni0d710682012-06-29 16:03:34 -03001885 if (i == intel_dp->lane_count && voltage_tries == 5) {
Daniel Vetterb06fbda2012-10-16 09:50:25 +02001886 ++loop_tries;
1887 if (loop_tries == 5) {
Keith Packardcdb0e952011-11-01 20:00:06 -07001888 DRM_DEBUG_KMS("too many full retries, give up\n");
1889 break;
1890 }
1891 memset(intel_dp->train_set, 0, 4);
1892 voltage_tries = 0;
1893 continue;
1894 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001895
1896 /* Check to see if we've tried the same voltage 5 times */
Daniel Vetterb06fbda2012-10-16 09:50:25 +02001897 if ((intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) == voltage) {
Chris Wilson24773672012-09-26 16:48:30 +01001898 ++voltage_tries;
Daniel Vetterb06fbda2012-10-16 09:50:25 +02001899 if (voltage_tries == 5) {
1900 DRM_DEBUG_KMS("too many voltage retries, give up\n");
1901 break;
1902 }
1903 } else
1904 voltage_tries = 0;
1905 voltage = intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001906
1907 /* Compute new intel_dp->train_set as requested by target */
Keith Packard93f62da2011-11-01 19:45:03 -07001908 intel_get_adjust_train(intel_dp, link_status);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001909 }
1910
Jesse Barnes33a34e42010-09-08 12:42:02 -07001911 intel_dp->DP = DP;
1912}
1913
Paulo Zanonic19b0662012-10-15 15:51:41 -03001914void
Jesse Barnes33a34e42010-09-08 12:42:02 -07001915intel_dp_complete_link_train(struct intel_dp *intel_dp)
1916{
Jesse Barnes33a34e42010-09-08 12:42:02 -07001917 bool channel_eq = false;
Jesse Barnes37f80972011-01-05 14:45:24 -08001918 int tries, cr_tries;
Jesse Barnes33a34e42010-09-08 12:42:02 -07001919 uint32_t DP = intel_dp->DP;
1920
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001921 /* channel equalization */
1922 tries = 0;
Jesse Barnes37f80972011-01-05 14:45:24 -08001923 cr_tries = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001924 channel_eq = false;
1925 for (;;) {
Keith Packard93f62da2011-11-01 19:45:03 -07001926 uint8_t link_status[DP_LINK_STATUS_SIZE];
Zhenyu Wange3421a12010-04-08 09:43:27 +08001927
Jesse Barnes37f80972011-01-05 14:45:24 -08001928 if (cr_tries > 5) {
1929 DRM_ERROR("failed to train DP, aborting\n");
1930 intel_dp_link_down(intel_dp);
1931 break;
1932 }
1933
Paulo Zanonif0a34242012-12-06 16:51:50 -02001934 intel_dp_set_signal_levels(intel_dp, &DP);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001935
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001936 /* channel eq pattern */
Paulo Zanoni47ea7542012-07-17 16:55:16 -03001937 if (!intel_dp_set_link_train(intel_dp, DP,
Adam Jackson81055852011-07-21 17:48:37 -04001938 DP_TRAINING_PATTERN_2 |
1939 DP_LINK_SCRAMBLING_DISABLE))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001940 break;
1941
Daniel Vettera7c96552012-10-18 10:15:30 +02001942 drm_dp_link_train_channel_eq_delay(intel_dp->dpcd);
Keith Packard93f62da2011-11-01 19:45:03 -07001943 if (!intel_dp_get_link_status(intel_dp, link_status))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001944 break;
Jesse Barnes869184a2010-10-07 16:01:22 -07001945
Jesse Barnes37f80972011-01-05 14:45:24 -08001946 /* Make sure clock is still ok */
Daniel Vetter01916272012-10-18 10:15:25 +02001947 if (!drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
Jesse Barnes37f80972011-01-05 14:45:24 -08001948 intel_dp_start_link_train(intel_dp);
1949 cr_tries++;
1950 continue;
1951 }
1952
Daniel Vetter1ffdff12012-10-18 10:15:24 +02001953 if (drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001954 channel_eq = true;
1955 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001956 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001957
Jesse Barnes37f80972011-01-05 14:45:24 -08001958 /* Try 5 times, then try clock recovery if that fails */
1959 if (tries > 5) {
1960 intel_dp_link_down(intel_dp);
1961 intel_dp_start_link_train(intel_dp);
1962 tries = 0;
1963 cr_tries++;
1964 continue;
1965 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001966
1967 /* Compute new intel_dp->train_set as requested by target */
Keith Packard93f62da2011-11-01 19:45:03 -07001968 intel_get_adjust_train(intel_dp, link_status);
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001969 ++tries;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001970 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001971
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001972 if (channel_eq)
1973 DRM_DEBUG_KMS("Channel EQ done. DP Training successfull\n");
1974
Paulo Zanoni47ea7542012-07-17 16:55:16 -03001975 intel_dp_set_link_train(intel_dp, DP, DP_TRAINING_PATTERN_DISABLE);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001976}
1977
1978static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01001979intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001980{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001981 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1982 struct drm_device *dev = intel_dig_port->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001983 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterab527ef2012-11-29 15:59:33 +01001984 struct intel_crtc *intel_crtc =
1985 to_intel_crtc(intel_dig_port->base.base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01001986 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001987
Paulo Zanonic19b0662012-10-15 15:51:41 -03001988 /*
1989 * DDI code has a strict mode set sequence and we should try to respect
1990 * it, otherwise we might hang the machine in many different ways. So we
1991 * really should be disabling the port only on a complete crtc_disable
1992 * sequence. This function is just called under two conditions on DDI
1993 * code:
1994 * - Link train failed while doing crtc_enable, and on this case we
1995 * really should respect the mode set sequence and wait for a
1996 * crtc_disable.
1997 * - Someone turned the monitor off and intel_dp_check_link_status
1998 * called us. We don't need to disable the whole port on this case, so
1999 * when someone turns the monitor on again,
2000 * intel_ddi_prepare_link_retrain will take care of redoing the link
2001 * train.
2002 */
Paulo Zanoniaffa9352012-11-23 15:30:39 -02002003 if (HAS_DDI(dev))
Paulo Zanonic19b0662012-10-15 15:51:41 -03002004 return;
2005
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002006 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00002007 return;
2008
Zhao Yakui28c97732009-10-09 11:39:41 +08002009 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002010
Keith Packard1a2eb462011-11-16 16:26:07 -08002011 if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || !is_cpu_edp(intel_dp))) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08002012 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Chris Wilsonea5b2132010-08-04 13:50:23 +01002013 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT);
Zhenyu Wange3421a12010-04-08 09:43:27 +08002014 } else {
2015 DP &= ~DP_LINK_TRAIN_MASK;
Chris Wilsonea5b2132010-08-04 13:50:23 +01002016 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE);
Zhenyu Wange3421a12010-04-08 09:43:27 +08002017 }
Chris Wilsonfe255d02010-09-11 21:37:48 +01002018 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002019
Daniel Vetterab527ef2012-11-29 15:59:33 +01002020 /* We don't really know why we're doing this */
2021 intel_wait_for_vblank(dev, intel_crtc->pipe);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002022
Daniel Vetter493a7082012-05-30 12:31:56 +02002023 if (HAS_PCH_IBX(dev) &&
Chris Wilson1b39d6f2010-12-06 11:20:45 +00002024 I915_READ(intel_dp->output_reg) & DP_PIPEB_SELECT) {
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002025 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
Chris Wilson31acbcc2011-04-17 06:38:35 +01002026
Eric Anholt5bddd172010-11-18 09:32:59 +08002027 /* Hardware workaround: leaving our transcoder select
2028 * set to transcoder B while it's off will prevent the
2029 * corresponding HDMI output on transcoder A.
2030 *
2031 * Combine this with another hardware workaround:
2032 * transcoder select bit can only be cleared while the
2033 * port is enabled.
2034 */
2035 DP &= ~DP_PIPEB_SELECT;
2036 I915_WRITE(intel_dp->output_reg, DP);
2037
2038 /* Changes to enable or select take place the vblank
2039 * after being written.
2040 */
Daniel Vetterff50afe2012-11-29 15:59:34 +01002041 if (WARN_ON(crtc == NULL)) {
2042 /* We should never try to disable a port without a crtc
2043 * attached. For paranoia keep the code around for a
2044 * bit. */
Chris Wilson31acbcc2011-04-17 06:38:35 +01002045 POSTING_READ(intel_dp->output_reg);
2046 msleep(50);
2047 } else
Daniel Vetterab527ef2012-11-29 15:59:33 +01002048 intel_wait_for_vblank(dev, intel_crtc->pipe);
Eric Anholt5bddd172010-11-18 09:32:59 +08002049 }
2050
Wu Fengguang832afda2011-12-09 20:42:21 +08002051 DP &= ~DP_AUDIO_OUTPUT_ENABLE;
Chris Wilsonea5b2132010-08-04 13:50:23 +01002052 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
2053 POSTING_READ(intel_dp->output_reg);
Keith Packardf01eca22011-09-28 16:48:10 -07002054 msleep(intel_dp->panel_power_down_delay);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002055}
2056
Keith Packard26d61aa2011-07-25 20:01:09 -07002057static bool
2058intel_dp_get_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07002059{
Damien Lespiau577c7a52012-12-13 16:09:02 +00002060 char dpcd_hex_dump[sizeof(intel_dp->dpcd) * 3];
2061
Keith Packard92fd8fd2011-07-25 19:50:10 -07002062 if (intel_dp_aux_native_read_retry(intel_dp, 0x000, intel_dp->dpcd,
Adam Jacksonedb39242012-09-18 10:58:49 -04002063 sizeof(intel_dp->dpcd)) == 0)
2064 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07002065
Damien Lespiau577c7a52012-12-13 16:09:02 +00002066 hex_dump_to_buffer(intel_dp->dpcd, sizeof(intel_dp->dpcd),
2067 32, 1, dpcd_hex_dump, sizeof(dpcd_hex_dump), false);
2068 DRM_DEBUG_KMS("DPCD: %s\n", dpcd_hex_dump);
2069
Adam Jacksonedb39242012-09-18 10:58:49 -04002070 if (intel_dp->dpcd[DP_DPCD_REV] == 0)
2071 return false; /* DPCD not present */
2072
2073 if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
2074 DP_DWN_STRM_PORT_PRESENT))
2075 return true; /* native DP sink */
2076
2077 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
2078 return true; /* no per-port downstream info */
2079
2080 if (intel_dp_aux_native_read_retry(intel_dp, DP_DOWNSTREAM_PORT_0,
2081 intel_dp->downstream_ports,
2082 DP_MAX_DOWNSTREAM_PORTS) == 0)
2083 return false; /* downstream port status fetch failed */
2084
2085 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07002086}
2087
Adam Jackson0d198322012-05-14 16:05:47 -04002088static void
2089intel_dp_probe_oui(struct intel_dp *intel_dp)
2090{
2091 u8 buf[3];
2092
2093 if (!(intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] & DP_OUI_SUPPORT))
2094 return;
2095
Daniel Vetter351cfc32012-06-12 13:20:47 +02002096 ironlake_edp_panel_vdd_on(intel_dp);
2097
Adam Jackson0d198322012-05-14 16:05:47 -04002098 if (intel_dp_aux_native_read_retry(intel_dp, DP_SINK_OUI, buf, 3))
2099 DRM_DEBUG_KMS("Sink OUI: %02hx%02hx%02hx\n",
2100 buf[0], buf[1], buf[2]);
2101
2102 if (intel_dp_aux_native_read_retry(intel_dp, DP_BRANCH_OUI, buf, 3))
2103 DRM_DEBUG_KMS("Branch OUI: %02hx%02hx%02hx\n",
2104 buf[0], buf[1], buf[2]);
Daniel Vetter351cfc32012-06-12 13:20:47 +02002105
2106 ironlake_edp_panel_vdd_off(intel_dp, false);
Adam Jackson0d198322012-05-14 16:05:47 -04002107}
2108
Jesse Barnesa60f0e32011-10-20 15:09:17 -07002109static bool
2110intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
2111{
2112 int ret;
2113
2114 ret = intel_dp_aux_native_read_retry(intel_dp,
2115 DP_DEVICE_SERVICE_IRQ_VECTOR,
2116 sink_irq_vector, 1);
2117 if (!ret)
2118 return false;
2119
2120 return true;
2121}
2122
2123static void
2124intel_dp_handle_test_request(struct intel_dp *intel_dp)
2125{
2126 /* NAK by default */
Daniel Vetter9324cf72012-10-20 21:13:05 +02002127 intel_dp_aux_native_write_1(intel_dp, DP_TEST_RESPONSE, DP_TEST_NAK);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07002128}
2129
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002130/*
2131 * According to DP spec
2132 * 5.1.2:
2133 * 1. Read DPCD
2134 * 2. Configure link according to Receiver Capabilities
2135 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
2136 * 4. Check link status on receipt of hot-plug interrupt
2137 */
2138
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002139void
Chris Wilsonea5b2132010-08-04 13:50:23 +01002140intel_dp_check_link_status(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002141{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002142 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07002143 u8 sink_irq_vector;
Keith Packard93f62da2011-11-01 19:45:03 -07002144 u8 link_status[DP_LINK_STATUS_SIZE];
Jesse Barnesa60f0e32011-10-20 15:09:17 -07002145
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002146 if (!intel_encoder->connectors_active)
Keith Packardd2b996a2011-07-25 22:37:51 -07002147 return;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07002148
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002149 if (WARN_ON(!intel_encoder->base.crtc))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002150 return;
2151
Keith Packard92fd8fd2011-07-25 19:50:10 -07002152 /* Try to read receiver status if the link appears to be up */
Keith Packard93f62da2011-11-01 19:45:03 -07002153 if (!intel_dp_get_link_status(intel_dp, link_status)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01002154 intel_dp_link_down(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002155 return;
2156 }
2157
Keith Packard92fd8fd2011-07-25 19:50:10 -07002158 /* Now read the DPCD to see if it's actually running */
Keith Packard26d61aa2011-07-25 20:01:09 -07002159 if (!intel_dp_get_dpcd(intel_dp)) {
Jesse Barnes59cd09e2011-07-07 11:10:59 -07002160 intel_dp_link_down(intel_dp);
2161 return;
2162 }
2163
Jesse Barnesa60f0e32011-10-20 15:09:17 -07002164 /* Try to read the source of the interrupt */
2165 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
2166 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector)) {
2167 /* Clear interrupt source */
2168 intel_dp_aux_native_write_1(intel_dp,
2169 DP_DEVICE_SERVICE_IRQ_VECTOR,
2170 sink_irq_vector);
2171
2172 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
2173 intel_dp_handle_test_request(intel_dp);
2174 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
2175 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
2176 }
2177
Daniel Vetter1ffdff12012-10-18 10:15:24 +02002178 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Keith Packard92fd8fd2011-07-25 19:50:10 -07002179 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002180 drm_get_encoder_name(&intel_encoder->base));
Jesse Barnes33a34e42010-09-08 12:42:02 -07002181 intel_dp_start_link_train(intel_dp);
2182 intel_dp_complete_link_train(intel_dp);
2183 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002184}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002185
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04002186/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002187static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07002188intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04002189{
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04002190 uint8_t *dpcd = intel_dp->dpcd;
2191 bool hpd;
2192 uint8_t type;
2193
2194 if (!intel_dp_get_dpcd(intel_dp))
2195 return connector_status_disconnected;
2196
2197 /* if there's no downstream port, we're done */
2198 if (!(dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT))
Keith Packard26d61aa2011-07-25 20:01:09 -07002199 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04002200
2201 /* If we're HPD-aware, SINK_COUNT changes dynamically */
2202 hpd = !!(intel_dp->downstream_ports[0] & DP_DS_PORT_HPD);
2203 if (hpd) {
Adam Jackson23235172012-09-20 16:42:45 -04002204 uint8_t reg;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04002205 if (!intel_dp_aux_native_read_retry(intel_dp, DP_SINK_COUNT,
Adam Jackson23235172012-09-20 16:42:45 -04002206 &reg, 1))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04002207 return connector_status_unknown;
Adam Jackson23235172012-09-20 16:42:45 -04002208 return DP_GET_SINK_COUNT(reg) ? connector_status_connected
2209 : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04002210 }
2211
2212 /* If no HPD, poke DDC gently */
2213 if (drm_probe_ddc(&intel_dp->adapter))
2214 return connector_status_connected;
2215
2216 /* Well we tried, say unknown for unreliable port types */
2217 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
2218 if (type == DP_DS_PORT_TYPE_VGA || type == DP_DS_PORT_TYPE_NON_EDID)
2219 return connector_status_unknown;
2220
2221 /* Anything else is out of spec, warn and ignore */
2222 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07002223 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04002224}
2225
2226static enum drm_connector_status
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002227ironlake_dp_detect(struct intel_dp *intel_dp)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002228{
Paulo Zanoni30add222012-10-26 19:05:45 -02002229 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Damien Lespiau1b469632012-12-13 16:09:01 +00002230 struct drm_i915_private *dev_priv = dev->dev_private;
2231 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002232 enum drm_connector_status status;
2233
Chris Wilsonfe16d942011-02-12 10:29:38 +00002234 /* Can't disconnect eDP, but you can close the lid... */
2235 if (is_edp(intel_dp)) {
Paulo Zanoni30add222012-10-26 19:05:45 -02002236 status = intel_panel_detect(dev);
Chris Wilsonfe16d942011-02-12 10:29:38 +00002237 if (status == connector_status_unknown)
2238 status = connector_status_connected;
2239 return status;
2240 }
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002241
Damien Lespiau1b469632012-12-13 16:09:01 +00002242 if (!ibx_digital_port_connected(dev_priv, intel_dig_port))
2243 return connector_status_disconnected;
2244
Keith Packard26d61aa2011-07-25 20:01:09 -07002245 return intel_dp_detect_dpcd(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002246}
2247
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002248static enum drm_connector_status
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002249g4x_dp_detect(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002250{
Paulo Zanoni30add222012-10-26 19:05:45 -02002251 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002252 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä34f2be42013-01-24 15:29:27 +02002253 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilson10f76a32012-05-11 18:01:32 +01002254 uint32_t bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002255
Jesse Barnes35aad752013-03-01 13:14:31 -08002256 /* Can't disconnect eDP, but you can close the lid... */
2257 if (is_edp(intel_dp)) {
2258 enum drm_connector_status status;
2259
2260 status = intel_panel_detect(dev);
2261 if (status == connector_status_unknown)
2262 status = connector_status_connected;
2263 return status;
2264 }
2265
Ville Syrjälä34f2be42013-01-24 15:29:27 +02002266 switch (intel_dig_port->port) {
2267 case PORT_B:
Daniel Vetter26739f12013-02-07 12:42:32 +01002268 bit = PORTB_HOTPLUG_LIVE_STATUS;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002269 break;
Ville Syrjälä34f2be42013-01-24 15:29:27 +02002270 case PORT_C:
Daniel Vetter26739f12013-02-07 12:42:32 +01002271 bit = PORTC_HOTPLUG_LIVE_STATUS;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002272 break;
Ville Syrjälä34f2be42013-01-24 15:29:27 +02002273 case PORT_D:
Daniel Vetter26739f12013-02-07 12:42:32 +01002274 bit = PORTD_HOTPLUG_LIVE_STATUS;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002275 break;
2276 default:
2277 return connector_status_unknown;
2278 }
2279
Chris Wilson10f76a32012-05-11 18:01:32 +01002280 if ((I915_READ(PORT_HOTPLUG_STAT) & bit) == 0)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002281 return connector_status_disconnected;
2282
Keith Packard26d61aa2011-07-25 20:01:09 -07002283 return intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002284}
2285
Keith Packard8c241fe2011-09-28 16:38:44 -07002286static struct edid *
2287intel_dp_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
2288{
Jani Nikula9cd300e2012-10-19 14:51:52 +03002289 struct intel_connector *intel_connector = to_intel_connector(connector);
Keith Packard8c241fe2011-09-28 16:38:44 -07002290
Jani Nikula9cd300e2012-10-19 14:51:52 +03002291 /* use cached edid if we have one */
2292 if (intel_connector->edid) {
2293 struct edid *edid;
2294 int size;
2295
2296 /* invalid edid */
2297 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04002298 return NULL;
2299
Jani Nikula9cd300e2012-10-19 14:51:52 +03002300 size = (intel_connector->edid->extensions + 1) * EDID_LENGTH;
Jesse Barnesd6f24d02012-06-14 15:28:33 -04002301 edid = kmalloc(size, GFP_KERNEL);
2302 if (!edid)
2303 return NULL;
2304
Jani Nikula9cd300e2012-10-19 14:51:52 +03002305 memcpy(edid, intel_connector->edid, size);
Jesse Barnesd6f24d02012-06-14 15:28:33 -04002306 return edid;
2307 }
2308
Jani Nikula9cd300e2012-10-19 14:51:52 +03002309 return drm_get_edid(connector, adapter);
Keith Packard8c241fe2011-09-28 16:38:44 -07002310}
2311
2312static int
2313intel_dp_get_edid_modes(struct drm_connector *connector, struct i2c_adapter *adapter)
2314{
Jani Nikula9cd300e2012-10-19 14:51:52 +03002315 struct intel_connector *intel_connector = to_intel_connector(connector);
Keith Packard8c241fe2011-09-28 16:38:44 -07002316
Jani Nikula9cd300e2012-10-19 14:51:52 +03002317 /* use cached edid if we have one */
2318 if (intel_connector->edid) {
2319 /* invalid edid */
2320 if (IS_ERR(intel_connector->edid))
2321 return 0;
2322
2323 return intel_connector_update_modes(connector,
2324 intel_connector->edid);
Jesse Barnesd6f24d02012-06-14 15:28:33 -04002325 }
2326
Jani Nikula9cd300e2012-10-19 14:51:52 +03002327 return intel_ddc_get_modes(connector, adapter);
Keith Packard8c241fe2011-09-28 16:38:44 -07002328}
2329
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002330static enum drm_connector_status
2331intel_dp_detect(struct drm_connector *connector, bool force)
2332{
2333 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02002334 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2335 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02002336 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002337 enum drm_connector_status status;
2338 struct edid *edid = NULL;
2339
2340 intel_dp->has_audio = false;
2341
2342 if (HAS_PCH_SPLIT(dev))
2343 status = ironlake_dp_detect(intel_dp);
2344 else
2345 status = g4x_dp_detect(intel_dp);
Adam Jackson1b9be9d2011-07-12 17:38:01 -04002346
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002347 if (status != connector_status_connected)
2348 return status;
2349
Adam Jackson0d198322012-05-14 16:05:47 -04002350 intel_dp_probe_oui(intel_dp);
2351
Daniel Vetterc3e5f672012-02-23 17:14:47 +01002352 if (intel_dp->force_audio != HDMI_AUDIO_AUTO) {
2353 intel_dp->has_audio = (intel_dp->force_audio == HDMI_AUDIO_ON);
Chris Wilsonf6849602010-09-19 09:29:33 +01002354 } else {
Keith Packard8c241fe2011-09-28 16:38:44 -07002355 edid = intel_dp_get_edid(connector, &intel_dp->adapter);
Chris Wilsonf6849602010-09-19 09:29:33 +01002356 if (edid) {
2357 intel_dp->has_audio = drm_detect_monitor_audio(edid);
Chris Wilsonf6849602010-09-19 09:29:33 +01002358 kfree(edid);
2359 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002360 }
2361
Paulo Zanonid63885d2012-10-26 19:05:49 -02002362 if (intel_encoder->type != INTEL_OUTPUT_EDP)
2363 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002364 return connector_status_connected;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002365}
2366
2367static int intel_dp_get_modes(struct drm_connector *connector)
2368{
Chris Wilsondf0e9242010-09-09 16:20:55 +01002369 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +03002370 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonifa90ece2012-10-26 19:05:44 -02002371 struct drm_device *dev = connector->dev;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002372 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002373
2374 /* We should parse the EDID data and find out if it has an audio sink
2375 */
2376
Keith Packard8c241fe2011-09-28 16:38:44 -07002377 ret = intel_dp_get_edid_modes(connector, &intel_dp->adapter);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002378 if (ret)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002379 return ret;
2380
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002381 /* if eDP has no EDID, fall back to fixed mode */
Jani Nikuladd06f902012-10-19 14:51:50 +03002382 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002383 struct drm_display_mode *mode;
Jani Nikuladd06f902012-10-19 14:51:50 +03002384 mode = drm_mode_duplicate(dev,
2385 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002386 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002387 drm_mode_probed_add(connector, mode);
2388 return 1;
2389 }
2390 }
2391 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002392}
2393
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002394static bool
2395intel_dp_detect_audio(struct drm_connector *connector)
2396{
2397 struct intel_dp *intel_dp = intel_attached_dp(connector);
2398 struct edid *edid;
2399 bool has_audio = false;
2400
Keith Packard8c241fe2011-09-28 16:38:44 -07002401 edid = intel_dp_get_edid(connector, &intel_dp->adapter);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002402 if (edid) {
2403 has_audio = drm_detect_monitor_audio(edid);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002404 kfree(edid);
2405 }
2406
2407 return has_audio;
2408}
2409
Chris Wilsonf6849602010-09-19 09:29:33 +01002410static int
2411intel_dp_set_property(struct drm_connector *connector,
2412 struct drm_property *property,
2413 uint64_t val)
2414{
Chris Wilsone953fd72011-02-21 22:23:52 +00002415 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Yuly Novikov53b41832012-10-26 12:04:00 +03002416 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002417 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
2418 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01002419 int ret;
2420
Rob Clark662595d2012-10-11 20:36:04 -05002421 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01002422 if (ret)
2423 return ret;
2424
Chris Wilson3f43c482011-05-12 22:17:24 +01002425 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002426 int i = val;
2427 bool has_audio;
2428
2429 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01002430 return 0;
2431
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002432 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01002433
Daniel Vetterc3e5f672012-02-23 17:14:47 +01002434 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002435 has_audio = intel_dp_detect_audio(connector);
2436 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01002437 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002438
2439 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01002440 return 0;
2441
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002442 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01002443 goto done;
2444 }
2445
Chris Wilsone953fd72011-02-21 22:23:52 +00002446 if (property == dev_priv->broadcast_rgb_property) {
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02002447 switch (val) {
2448 case INTEL_BROADCAST_RGB_AUTO:
2449 intel_dp->color_range_auto = true;
2450 break;
2451 case INTEL_BROADCAST_RGB_FULL:
2452 intel_dp->color_range_auto = false;
2453 intel_dp->color_range = 0;
2454 break;
2455 case INTEL_BROADCAST_RGB_LIMITED:
2456 intel_dp->color_range_auto = false;
2457 intel_dp->color_range = DP_COLOR_RANGE_16_235;
2458 break;
2459 default:
2460 return -EINVAL;
2461 }
Chris Wilsone953fd72011-02-21 22:23:52 +00002462 goto done;
2463 }
2464
Yuly Novikov53b41832012-10-26 12:04:00 +03002465 if (is_edp(intel_dp) &&
2466 property == connector->dev->mode_config.scaling_mode_property) {
2467 if (val == DRM_MODE_SCALE_NONE) {
2468 DRM_DEBUG_KMS("no scaling not supported\n");
2469 return -EINVAL;
2470 }
2471
2472 if (intel_connector->panel.fitting_mode == val) {
2473 /* the eDP scaling property is not changed */
2474 return 0;
2475 }
2476 intel_connector->panel.fitting_mode = val;
2477
2478 goto done;
2479 }
2480
Chris Wilsonf6849602010-09-19 09:29:33 +01002481 return -EINVAL;
2482
2483done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00002484 if (intel_encoder->base.crtc)
2485 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01002486
2487 return 0;
2488}
2489
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002490static void
Akshay Joshi0206e352011-08-16 15:34:10 -04002491intel_dp_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002492{
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02002493 struct drm_device *dev = connector->dev;
Jani Nikulabe3cd5e2012-10-12 10:33:05 +03002494 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikula1d508702012-10-19 14:51:49 +03002495 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02002496
Jani Nikula9cd300e2012-10-19 14:51:52 +03002497 if (!IS_ERR_OR_NULL(intel_connector->edid))
2498 kfree(intel_connector->edid);
2499
Jani Nikula1d508702012-10-19 14:51:49 +03002500 if (is_edp(intel_dp)) {
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02002501 intel_panel_destroy_backlight(dev);
Jani Nikula1d508702012-10-19 14:51:49 +03002502 intel_panel_fini(&intel_connector->panel);
2503 }
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02002504
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002505 drm_sysfs_connector_remove(connector);
2506 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08002507 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002508}
2509
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002510void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02002511{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002512 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
2513 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02002514
2515 i2c_del_adapter(&intel_dp->adapter);
2516 drm_encoder_cleanup(encoder);
Keith Packardbd943152011-09-18 23:09:52 -07002517 if (is_edp(intel_dp)) {
2518 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
2519 ironlake_panel_vdd_off_sync(intel_dp);
2520 }
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002521 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02002522}
2523
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002524static const struct drm_encoder_helper_funcs intel_dp_helper_funcs = {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002525 .mode_set = intel_dp_mode_set,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002526};
2527
2528static const struct drm_connector_funcs intel_dp_connector_funcs = {
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002529 .dpms = intel_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002530 .detect = intel_dp_detect,
2531 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01002532 .set_property = intel_dp_set_property,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002533 .destroy = intel_dp_destroy,
2534};
2535
2536static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
2537 .get_modes = intel_dp_get_modes,
2538 .mode_valid = intel_dp_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +01002539 .best_encoder = intel_best_encoder,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002540};
2541
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002542static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Daniel Vetter24d05922010-08-20 18:08:28 +02002543 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002544};
2545
Chris Wilson995b6762010-08-20 13:23:26 +01002546static void
Eric Anholt21d40d32010-03-25 11:11:14 -07002547intel_dp_hot_plug(struct intel_encoder *intel_encoder)
Keith Packardc8110e52009-05-06 11:51:10 -07002548{
Paulo Zanonifa90ece2012-10-26 19:05:44 -02002549 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Keith Packardc8110e52009-05-06 11:51:10 -07002550
Jesse Barnes885a5012011-07-07 11:11:01 -07002551 intel_dp_check_link_status(intel_dp);
Keith Packardc8110e52009-05-06 11:51:10 -07002552}
2553
Zhenyu Wange3421a12010-04-08 09:43:27 +08002554/* Return which DP Port should be selected for Transcoder DP control */
2555int
Akshay Joshi0206e352011-08-16 15:34:10 -04002556intel_trans_dp_port_sel(struct drm_crtc *crtc)
Zhenyu Wange3421a12010-04-08 09:43:27 +08002557{
2558 struct drm_device *dev = crtc->dev;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02002559 struct intel_encoder *intel_encoder;
2560 struct intel_dp *intel_dp;
Zhenyu Wange3421a12010-04-08 09:43:27 +08002561
Paulo Zanonifa90ece2012-10-26 19:05:44 -02002562 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
2563 intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002564
Paulo Zanonifa90ece2012-10-26 19:05:44 -02002565 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
2566 intel_encoder->type == INTEL_OUTPUT_EDP)
Chris Wilsonea5b2132010-08-04 13:50:23 +01002567 return intel_dp->output_reg;
Zhenyu Wange3421a12010-04-08 09:43:27 +08002568 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002569
Zhenyu Wange3421a12010-04-08 09:43:27 +08002570 return -1;
2571}
2572
Zhao Yakui36e83a12010-06-12 14:32:21 +08002573/* check the VBT to see whether the eDP is on DP-D port */
Adam Jacksoncb0953d2010-07-16 14:46:29 -04002574bool intel_dpd_is_edp(struct drm_device *dev)
Zhao Yakui36e83a12010-06-12 14:32:21 +08002575{
2576 struct drm_i915_private *dev_priv = dev->dev_private;
2577 struct child_device_config *p_child;
2578 int i;
2579
2580 if (!dev_priv->child_dev_num)
2581 return false;
2582
2583 for (i = 0; i < dev_priv->child_dev_num; i++) {
2584 p_child = dev_priv->child_dev + i;
2585
2586 if (p_child->dvo_port == PORT_IDPD &&
2587 p_child->device_type == DEVICE_TYPE_eDP)
2588 return true;
2589 }
2590 return false;
2591}
2592
Chris Wilsonf6849602010-09-19 09:29:33 +01002593static void
2594intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
2595{
Yuly Novikov53b41832012-10-26 12:04:00 +03002596 struct intel_connector *intel_connector = to_intel_connector(connector);
2597
Chris Wilson3f43c482011-05-12 22:17:24 +01002598 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00002599 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02002600 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03002601
2602 if (is_edp(intel_dp)) {
2603 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05002604 drm_object_attach_property(
2605 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03002606 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03002607 DRM_MODE_SCALE_ASPECT);
2608 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03002609 }
Chris Wilsonf6849602010-09-19 09:29:33 +01002610}
2611
Daniel Vetter67a54562012-10-20 20:57:45 +02002612static void
2613intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Jani Nikulaf30d26e2013-01-16 10:53:40 +02002614 struct intel_dp *intel_dp,
2615 struct edp_power_seq *out)
Daniel Vetter67a54562012-10-20 20:57:45 +02002616{
2617 struct drm_i915_private *dev_priv = dev->dev_private;
2618 struct edp_power_seq cur, vbt, spec, final;
2619 u32 pp_on, pp_off, pp_div, pp;
2620
2621 /* Workaround: Need to write PP_CONTROL with the unlock key as
2622 * the very first thing. */
2623 pp = ironlake_get_pp_control(dev_priv);
2624 I915_WRITE(PCH_PP_CONTROL, pp);
2625
2626 pp_on = I915_READ(PCH_PP_ON_DELAYS);
2627 pp_off = I915_READ(PCH_PP_OFF_DELAYS);
2628 pp_div = I915_READ(PCH_PP_DIVISOR);
2629
2630 /* Pull timing values out of registers */
2631 cur.t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
2632 PANEL_POWER_UP_DELAY_SHIFT;
2633
2634 cur.t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
2635 PANEL_LIGHT_ON_DELAY_SHIFT;
2636
2637 cur.t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
2638 PANEL_LIGHT_OFF_DELAY_SHIFT;
2639
2640 cur.t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
2641 PANEL_POWER_DOWN_DELAY_SHIFT;
2642
2643 cur.t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
2644 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
2645
2646 DRM_DEBUG_KMS("cur t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
2647 cur.t1_t3, cur.t8, cur.t9, cur.t10, cur.t11_t12);
2648
2649 vbt = dev_priv->edp.pps;
2650
2651 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
2652 * our hw here, which are all in 100usec. */
2653 spec.t1_t3 = 210 * 10;
2654 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
2655 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
2656 spec.t10 = 500 * 10;
2657 /* This one is special and actually in units of 100ms, but zero
2658 * based in the hw (so we need to add 100 ms). But the sw vbt
2659 * table multiplies it with 1000 to make it in units of 100usec,
2660 * too. */
2661 spec.t11_t12 = (510 + 100) * 10;
2662
2663 DRM_DEBUG_KMS("vbt t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
2664 vbt.t1_t3, vbt.t8, vbt.t9, vbt.t10, vbt.t11_t12);
2665
2666 /* Use the max of the register settings and vbt. If both are
2667 * unset, fall back to the spec limits. */
2668#define assign_final(field) final.field = (max(cur.field, vbt.field) == 0 ? \
2669 spec.field : \
2670 max(cur.field, vbt.field))
2671 assign_final(t1_t3);
2672 assign_final(t8);
2673 assign_final(t9);
2674 assign_final(t10);
2675 assign_final(t11_t12);
2676#undef assign_final
2677
2678#define get_delay(field) (DIV_ROUND_UP(final.field, 10))
2679 intel_dp->panel_power_up_delay = get_delay(t1_t3);
2680 intel_dp->backlight_on_delay = get_delay(t8);
2681 intel_dp->backlight_off_delay = get_delay(t9);
2682 intel_dp->panel_power_down_delay = get_delay(t10);
2683 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
2684#undef get_delay
2685
Jani Nikulaf30d26e2013-01-16 10:53:40 +02002686 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
2687 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
2688 intel_dp->panel_power_cycle_delay);
2689
2690 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
2691 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
2692
2693 if (out)
2694 *out = final;
2695}
2696
2697static void
2698intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
2699 struct intel_dp *intel_dp,
2700 struct edp_power_seq *seq)
2701{
2702 struct drm_i915_private *dev_priv = dev->dev_private;
2703 u32 pp_on, pp_off, pp_div;
2704
Daniel Vetter67a54562012-10-20 20:57:45 +02002705 /* And finally store the new values in the power sequencer. */
Jani Nikulaf30d26e2013-01-16 10:53:40 +02002706 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
2707 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
2708 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
2709 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02002710 /* Compute the divisor for the pp clock, simply match the Bspec
2711 * formula. */
2712 pp_div = ((100 * intel_pch_rawclk(dev))/2 - 1)
2713 << PP_REFERENCE_DIVIDER_SHIFT;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02002714 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
Daniel Vetter67a54562012-10-20 20:57:45 +02002715 << PANEL_POWER_CYCLE_DELAY_SHIFT);
2716
2717 /* Haswell doesn't have any port selection bits for the panel
2718 * power sequencer any more. */
2719 if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) {
2720 if (is_cpu_edp(intel_dp))
2721 pp_on |= PANEL_POWER_PORT_DP_A;
2722 else
2723 pp_on |= PANEL_POWER_PORT_DP_D;
2724 }
2725
2726 I915_WRITE(PCH_PP_ON_DELAYS, pp_on);
2727 I915_WRITE(PCH_PP_OFF_DELAYS, pp_off);
2728 I915_WRITE(PCH_PP_DIVISOR, pp_div);
2729
Daniel Vetter67a54562012-10-20 20:57:45 +02002730 DRM_DEBUG_KMS("panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n",
2731 I915_READ(PCH_PP_ON_DELAYS),
2732 I915_READ(PCH_PP_OFF_DELAYS),
2733 I915_READ(PCH_PP_DIVISOR));
Keith Packardc8110e52009-05-06 11:51:10 -07002734}
2735
2736void
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02002737intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
2738 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002739{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02002740 struct drm_connector *connector = &intel_connector->base;
2741 struct intel_dp *intel_dp = &intel_dig_port->dp;
2742 struct intel_encoder *intel_encoder = &intel_dig_port->base;
2743 struct drm_device *dev = intel_encoder->base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002744 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002745 struct drm_display_mode *fixed_mode = NULL;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02002746 struct edp_power_seq power_seq = { 0 };
Paulo Zanoni174edf12012-10-26 19:05:50 -02002747 enum port port = intel_dig_port->port;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002748 const char *name = NULL;
Adam Jacksonb3295302010-07-16 14:46:28 -04002749 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002750
Daniel Vetter07679352012-09-06 22:15:42 +02002751 /* Preserve the current hw state. */
2752 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03002753 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00002754
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02002755 if (HAS_PCH_SPLIT(dev) && port == PORT_D)
Adam Jacksonb3295302010-07-16 14:46:28 -04002756 if (intel_dpd_is_edp(dev))
Chris Wilsonea5b2132010-08-04 13:50:23 +01002757 intel_dp->is_pch_edp = true;
Adam Jacksonb3295302010-07-16 14:46:28 -04002758
Gajanan Bhat19c03922012-09-27 19:13:07 +05302759 /*
2760 * FIXME : We need to initialize built-in panels before external panels.
2761 * For X0, DP_C is fixed as eDP. Revisit this as part of VLV eDP cleanup
2762 */
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02002763 if (IS_VALLEYVIEW(dev) && port == PORT_C) {
Gajanan Bhat19c03922012-09-27 19:13:07 +05302764 type = DRM_MODE_CONNECTOR_eDP;
2765 intel_encoder->type = INTEL_OUTPUT_EDP;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02002766 } else if (port == PORT_A || is_pch_edp(intel_dp)) {
Adam Jacksonb3295302010-07-16 14:46:28 -04002767 type = DRM_MODE_CONNECTOR_eDP;
2768 intel_encoder->type = INTEL_OUTPUT_EDP;
2769 } else {
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002770 /* The intel_encoder->type value may be INTEL_OUTPUT_UNKNOWN for
2771 * DDI or INTEL_OUTPUT_DISPLAYPORT for the older gens, so don't
2772 * rewrite it.
2773 */
Adam Jacksonb3295302010-07-16 14:46:28 -04002774 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04002775 }
2776
Adam Jacksonb3295302010-07-16 14:46:28 -04002777 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002778 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
2779
Dave Airlieeb1f8e42010-05-07 06:42:51 +00002780 connector->polled = DRM_CONNECTOR_POLL_HPD;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02002781 connector->interlace_allowed = true;
2782 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08002783
Daniel Vetter66a92782012-07-12 20:08:18 +02002784 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
2785 ironlake_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08002786
Chris Wilsondf0e9242010-09-09 16:20:55 +01002787 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002788 drm_sysfs_connector_add(connector);
2789
Paulo Zanoniaffa9352012-11-23 15:30:39 -02002790 if (HAS_DDI(dev))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02002791 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
2792 else
2793 intel_connector->get_hw_state = intel_connector_get_hw_state;
2794
Paulo Zanoni9ed35ab2013-02-18 19:00:25 -03002795 intel_dp->aux_ch_ctl_reg = intel_dp->output_reg + 0x10;
2796 if (HAS_DDI(dev)) {
2797 switch (intel_dig_port->port) {
2798 case PORT_A:
2799 intel_dp->aux_ch_ctl_reg = DPA_AUX_CH_CTL;
2800 break;
2801 case PORT_B:
2802 intel_dp->aux_ch_ctl_reg = PCH_DPB_AUX_CH_CTL;
2803 break;
2804 case PORT_C:
2805 intel_dp->aux_ch_ctl_reg = PCH_DPC_AUX_CH_CTL;
2806 break;
2807 case PORT_D:
2808 intel_dp->aux_ch_ctl_reg = PCH_DPD_AUX_CH_CTL;
2809 break;
2810 default:
2811 BUG();
2812 }
2813 }
Daniel Vettere8cb4552012-07-01 13:05:48 +02002814
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002815 /* Set up the DDC bus. */
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03002816 switch (port) {
2817 case PORT_A:
Egbert Eich1d843f92013-02-25 12:06:49 -05002818 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03002819 name = "DPDDC-A";
2820 break;
2821 case PORT_B:
Egbert Eich1d843f92013-02-25 12:06:49 -05002822 intel_encoder->hpd_pin = HPD_PORT_B;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03002823 name = "DPDDC-B";
2824 break;
2825 case PORT_C:
Egbert Eich1d843f92013-02-25 12:06:49 -05002826 intel_encoder->hpd_pin = HPD_PORT_C;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03002827 name = "DPDDC-C";
2828 break;
2829 case PORT_D:
Egbert Eich1d843f92013-02-25 12:06:49 -05002830 intel_encoder->hpd_pin = HPD_PORT_D;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03002831 name = "DPDDC-D";
2832 break;
2833 default:
Damien Lespiauad1c0b12013-03-07 15:30:28 +00002834 BUG();
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002835 }
2836
Daniel Vetter67a54562012-10-20 20:57:45 +02002837 if (is_edp(intel_dp))
Jani Nikulaf30d26e2013-01-16 10:53:40 +02002838 intel_dp_init_panel_power_sequencer(dev, intel_dp, &power_seq);
Dave Airliec1f05262012-08-30 11:06:18 +10002839
2840 intel_dp_i2c_init(intel_dp, intel_connector, name);
2841
Daniel Vetter67a54562012-10-20 20:57:45 +02002842 /* Cache DPCD and EDID for edp. */
Dave Airliec1f05262012-08-30 11:06:18 +10002843 if (is_edp(intel_dp)) {
2844 bool ret;
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002845 struct drm_display_mode *scan;
Dave Airliec1f05262012-08-30 11:06:18 +10002846 struct edid *edid;
Jesse Barnes5d613502011-01-24 17:10:54 -08002847
2848 ironlake_edp_panel_vdd_on(intel_dp);
Keith Packard59f3e272011-07-25 20:01:56 -07002849 ret = intel_dp_get_dpcd(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002850 ironlake_edp_panel_vdd_off(intel_dp, false);
Keith Packard99ea7122011-11-01 19:57:50 -07002851
Keith Packard59f3e272011-07-25 20:01:56 -07002852 if (ret) {
Jesse Barnes7183dc22011-07-07 11:10:58 -07002853 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
2854 dev_priv->no_aux_handshake =
2855 intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
Jesse Barnes89667382010-10-07 16:01:21 -07002856 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
2857 } else {
Chris Wilson3d3dc142011-02-12 10:33:12 +00002858 /* if this fails, presume the device is a ghost */
Takashi Iwai48898b02011-03-18 09:06:49 +00002859 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Paulo Zanonifa90ece2012-10-26 19:05:44 -02002860 intel_dp_encoder_destroy(&intel_encoder->base);
2861 intel_dp_destroy(connector);
Chris Wilson3d3dc142011-02-12 10:33:12 +00002862 return;
Jesse Barnes89667382010-10-07 16:01:21 -07002863 }
Jesse Barnes89667382010-10-07 16:01:21 -07002864
Jani Nikulaf30d26e2013-01-16 10:53:40 +02002865 /* We now know it's not a ghost, init power sequence regs. */
2866 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp,
2867 &power_seq);
2868
Jesse Barnesd6f24d02012-06-14 15:28:33 -04002869 ironlake_edp_panel_vdd_on(intel_dp);
2870 edid = drm_get_edid(connector, &intel_dp->adapter);
2871 if (edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03002872 if (drm_add_edid_modes(connector, edid)) {
2873 drm_mode_connector_update_edid_property(connector, edid);
2874 drm_edid_to_eld(connector, edid);
2875 } else {
2876 kfree(edid);
2877 edid = ERR_PTR(-EINVAL);
2878 }
2879 } else {
2880 edid = ERR_PTR(-ENOENT);
Jesse Barnesd6f24d02012-06-14 15:28:33 -04002881 }
Jani Nikula9cd300e2012-10-19 14:51:52 +03002882 intel_connector->edid = edid;
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002883
2884 /* prefer fixed mode from EDID if available */
2885 list_for_each_entry(scan, &connector->probed_modes, head) {
2886 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
2887 fixed_mode = drm_mode_duplicate(dev, scan);
2888 break;
2889 }
2890 }
2891
2892 /* fallback to VBT if available for eDP */
2893 if (!fixed_mode && dev_priv->lfp_lvds_vbt_mode) {
2894 fixed_mode = drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);
2895 if (fixed_mode)
2896 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
2897 }
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002898
Jesse Barnesd6f24d02012-06-14 15:28:33 -04002899 ironlake_edp_panel_vdd_off(intel_dp, false);
2900 }
Keith Packard552fb0b2011-09-28 16:31:53 -07002901
Jesse Barnes4d926462010-10-07 16:01:07 -07002902 if (is_edp(intel_dp)) {
Jani Nikuladd06f902012-10-19 14:51:50 +03002903 intel_panel_init(&intel_connector->panel, fixed_mode);
Jani Nikula0657b6b2012-10-19 14:51:46 +03002904 intel_panel_setup_backlight(connector);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002905 }
2906
Chris Wilsonf6849602010-09-19 09:29:33 +01002907 intel_dp_add_properties(intel_dp, connector);
2908
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002909 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
2910 * 0xd. Failure to do so will result in spurious interrupts being
2911 * generated on the port when a cable is not attached.
2912 */
2913 if (IS_G4X(dev) && !IS_GM45(dev)) {
2914 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
2915 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
2916 }
2917}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02002918
2919void
2920intel_dp_init(struct drm_device *dev, int output_reg, enum port port)
2921{
2922 struct intel_digital_port *intel_dig_port;
2923 struct intel_encoder *intel_encoder;
2924 struct drm_encoder *encoder;
2925 struct intel_connector *intel_connector;
2926
2927 intel_dig_port = kzalloc(sizeof(struct intel_digital_port), GFP_KERNEL);
2928 if (!intel_dig_port)
2929 return;
2930
2931 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
2932 if (!intel_connector) {
2933 kfree(intel_dig_port);
2934 return;
2935 }
2936
2937 intel_encoder = &intel_dig_port->base;
2938 encoder = &intel_encoder->base;
2939
2940 drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
2941 DRM_MODE_ENCODER_TMDS);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002942 drm_encoder_helper_add(&intel_encoder->base, &intel_dp_helper_funcs);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02002943
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002944 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002945 intel_encoder->enable = intel_enable_dp;
2946 intel_encoder->pre_enable = intel_pre_enable_dp;
2947 intel_encoder->disable = intel_disable_dp;
2948 intel_encoder->post_disable = intel_post_disable_dp;
2949 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02002950
Paulo Zanoni174edf12012-10-26 19:05:50 -02002951 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02002952 intel_dig_port->dp.output_reg = output_reg;
2953
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002954 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02002955 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
2956 intel_encoder->cloneable = false;
2957 intel_encoder->hot_plug = intel_dp_hot_plug;
2958
2959 intel_dp_init_connector(intel_dig_port, intel_connector);
2960}