blob: eb783925b28cd06db7d199f7e23fbd7aebf8e3d3 [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)) {
Jesse Barnesb2634012013-03-28 09:55:40 -0700939 if (!HAS_PCH_SPLIT(dev) && !IS_VALLEYVIEW(dev))
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200940 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
Jesse Barnesb2634012013-03-28 09:55:40 -0700954 if (is_cpu_edp(intel_dp) && !IS_VALLEYVIEW(dev)) {
Keith Packard417e8222011-11-01 19:54:11 -0700955 /* 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);
Jesse Barnesb2634012013-03-28 09:55:40 -07001386 struct drm_device *dev = encoder->base.dev;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001387
Daniel Vetter37398502012-09-06 22:15:44 +02001388 if (is_cpu_edp(intel_dp)) {
1389 intel_dp_link_down(intel_dp);
Jesse Barnesb2634012013-03-28 09:55:40 -07001390 if (!IS_VALLEYVIEW(dev))
1391 ironlake_edp_pll_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02001392 }
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001393}
1394
Daniel Vettere8cb4552012-07-01 13:05:48 +02001395static void intel_enable_dp(struct intel_encoder *encoder)
Jesse Barnesd240f202010-08-13 15:43:26 -07001396{
Daniel Vettere8cb4552012-07-01 13:05:48 +02001397 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1398 struct drm_device *dev = encoder->base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001399 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001400 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001401
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02001402 if (WARN_ON(dp_reg & DP_PORT_EN))
1403 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001404
1405 ironlake_edp_panel_vdd_on(intel_dp);
1406 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1407 intel_dp_start_link_train(intel_dp);
1408 ironlake_edp_panel_on(intel_dp);
1409 ironlake_edp_panel_vdd_off(intel_dp, true);
1410 intel_dp_complete_link_train(intel_dp);
1411 ironlake_edp_backlight_on(intel_dp);
1412}
1413
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001414static void intel_pre_enable_dp(struct intel_encoder *encoder)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001415{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001416 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnesb2634012013-03-28 09:55:40 -07001417 struct drm_device *dev = encoder->base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001418
Jesse Barnesb2634012013-03-28 09:55:40 -07001419 if (is_cpu_edp(intel_dp) && !IS_VALLEYVIEW(dev))
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001420 ironlake_edp_pll_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001421}
1422
1423/*
Jesse Barnesdf0c2372011-07-07 11:11:02 -07001424 * Native read with retry for link status and receiver capability reads for
1425 * cases where the sink may still be asleep.
1426 */
1427static bool
1428intel_dp_aux_native_read_retry(struct intel_dp *intel_dp, uint16_t address,
1429 uint8_t *recv, int recv_bytes)
1430{
1431 int ret, i;
1432
1433 /*
1434 * Sinks are *supposed* to come up within 1ms from an off state,
1435 * but we're also supposed to retry 3 times per the spec.
1436 */
1437 for (i = 0; i < 3; i++) {
1438 ret = intel_dp_aux_native_read(intel_dp, address, recv,
1439 recv_bytes);
1440 if (ret == recv_bytes)
1441 return true;
1442 msleep(1);
1443 }
1444
1445 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001446}
1447
1448/*
1449 * Fetch AUX CH registers 0x202 - 0x207 which contain
1450 * link status information
1451 */
1452static bool
Keith Packard93f62da2011-11-01 19:45:03 -07001453intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001454{
Jesse Barnesdf0c2372011-07-07 11:11:02 -07001455 return intel_dp_aux_native_read_retry(intel_dp,
1456 DP_LANE0_1_STATUS,
Keith Packard93f62da2011-11-01 19:45:03 -07001457 link_status,
Jesse Barnesdf0c2372011-07-07 11:11:02 -07001458 DP_LINK_STATUS_SIZE);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001459}
1460
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001461#if 0
1462static char *voltage_names[] = {
1463 "0.4V", "0.6V", "0.8V", "1.2V"
1464};
1465static char *pre_emph_names[] = {
1466 "0dB", "3.5dB", "6dB", "9.5dB"
1467};
1468static char *link_train_names[] = {
1469 "pattern 1", "pattern 2", "idle", "off"
1470};
1471#endif
1472
1473/*
1474 * These are source-specific values; current Intel hardware supports
1475 * a maximum voltage of 800mV and a maximum pre-emphasis of 6dB
1476 */
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001477
1478static uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08001479intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001480{
Paulo Zanoni30add222012-10-26 19:05:45 -02001481 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packard1a2eb462011-11-16 16:26:07 -08001482
1483 if (IS_GEN7(dev) && is_cpu_edp(intel_dp))
1484 return DP_TRAIN_VOLTAGE_SWING_800;
1485 else if (HAS_PCH_CPT(dev) && !is_cpu_edp(intel_dp))
1486 return DP_TRAIN_VOLTAGE_SWING_1200;
1487 else
1488 return DP_TRAIN_VOLTAGE_SWING_800;
1489}
1490
1491static uint8_t
1492intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
1493{
Paulo Zanoni30add222012-10-26 19:05:45 -02001494 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packard1a2eb462011-11-16 16:26:07 -08001495
Paulo Zanoni22b8bf12013-02-18 19:00:23 -03001496 if (HAS_DDI(dev)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001497 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
1498 case DP_TRAIN_VOLTAGE_SWING_400:
1499 return DP_TRAIN_PRE_EMPHASIS_9_5;
1500 case DP_TRAIN_VOLTAGE_SWING_600:
1501 return DP_TRAIN_PRE_EMPHASIS_6;
1502 case DP_TRAIN_VOLTAGE_SWING_800:
1503 return DP_TRAIN_PRE_EMPHASIS_3_5;
1504 case DP_TRAIN_VOLTAGE_SWING_1200:
1505 default:
1506 return DP_TRAIN_PRE_EMPHASIS_0;
1507 }
1508 } else if (IS_GEN7(dev) && is_cpu_edp(intel_dp) && !IS_VALLEYVIEW(dev)) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001509 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
1510 case DP_TRAIN_VOLTAGE_SWING_400:
1511 return DP_TRAIN_PRE_EMPHASIS_6;
1512 case DP_TRAIN_VOLTAGE_SWING_600:
1513 case DP_TRAIN_VOLTAGE_SWING_800:
1514 return DP_TRAIN_PRE_EMPHASIS_3_5;
1515 default:
1516 return DP_TRAIN_PRE_EMPHASIS_0;
1517 }
1518 } else {
1519 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
1520 case DP_TRAIN_VOLTAGE_SWING_400:
1521 return DP_TRAIN_PRE_EMPHASIS_6;
1522 case DP_TRAIN_VOLTAGE_SWING_600:
1523 return DP_TRAIN_PRE_EMPHASIS_6;
1524 case DP_TRAIN_VOLTAGE_SWING_800:
1525 return DP_TRAIN_PRE_EMPHASIS_3_5;
1526 case DP_TRAIN_VOLTAGE_SWING_1200:
1527 default:
1528 return DP_TRAIN_PRE_EMPHASIS_0;
1529 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001530 }
1531}
1532
1533static void
Keith Packard93f62da2011-11-01 19:45:03 -07001534intel_get_adjust_train(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001535{
1536 uint8_t v = 0;
1537 uint8_t p = 0;
1538 int lane;
Keith Packard1a2eb462011-11-16 16:26:07 -08001539 uint8_t voltage_max;
1540 uint8_t preemph_max;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001541
Jesse Barnes33a34e42010-09-08 12:42:02 -07001542 for (lane = 0; lane < intel_dp->lane_count; lane++) {
Daniel Vetter0f037bd2012-10-18 10:15:27 +02001543 uint8_t this_v = drm_dp_get_adjust_request_voltage(link_status, lane);
1544 uint8_t this_p = drm_dp_get_adjust_request_pre_emphasis(link_status, lane);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001545
1546 if (this_v > v)
1547 v = this_v;
1548 if (this_p > p)
1549 p = this_p;
1550 }
1551
Keith Packard1a2eb462011-11-16 16:26:07 -08001552 voltage_max = intel_dp_voltage_max(intel_dp);
Keith Packard417e8222011-11-01 19:54:11 -07001553 if (v >= voltage_max)
1554 v = voltage_max | DP_TRAIN_MAX_SWING_REACHED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001555
Keith Packard1a2eb462011-11-16 16:26:07 -08001556 preemph_max = intel_dp_pre_emphasis_max(intel_dp, v);
1557 if (p >= preemph_max)
1558 p = preemph_max | DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001559
1560 for (lane = 0; lane < 4; lane++)
Jesse Barnes33a34e42010-09-08 12:42:02 -07001561 intel_dp->train_set[lane] = v | p;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001562}
1563
1564static uint32_t
Paulo Zanonif0a34242012-12-06 16:51:50 -02001565intel_gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001566{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001567 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001568
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001569 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001570 case DP_TRAIN_VOLTAGE_SWING_400:
1571 default:
1572 signal_levels |= DP_VOLTAGE_0_4;
1573 break;
1574 case DP_TRAIN_VOLTAGE_SWING_600:
1575 signal_levels |= DP_VOLTAGE_0_6;
1576 break;
1577 case DP_TRAIN_VOLTAGE_SWING_800:
1578 signal_levels |= DP_VOLTAGE_0_8;
1579 break;
1580 case DP_TRAIN_VOLTAGE_SWING_1200:
1581 signal_levels |= DP_VOLTAGE_1_2;
1582 break;
1583 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001584 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001585 case DP_TRAIN_PRE_EMPHASIS_0:
1586 default:
1587 signal_levels |= DP_PRE_EMPHASIS_0;
1588 break;
1589 case DP_TRAIN_PRE_EMPHASIS_3_5:
1590 signal_levels |= DP_PRE_EMPHASIS_3_5;
1591 break;
1592 case DP_TRAIN_PRE_EMPHASIS_6:
1593 signal_levels |= DP_PRE_EMPHASIS_6;
1594 break;
1595 case DP_TRAIN_PRE_EMPHASIS_9_5:
1596 signal_levels |= DP_PRE_EMPHASIS_9_5;
1597 break;
1598 }
1599 return signal_levels;
1600}
1601
Zhenyu Wange3421a12010-04-08 09:43:27 +08001602/* Gen6's DP voltage swing and pre-emphasis control */
1603static uint32_t
1604intel_gen6_edp_signal_levels(uint8_t train_set)
1605{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001606 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
1607 DP_TRAIN_PRE_EMPHASIS_MASK);
1608 switch (signal_levels) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08001609 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001610 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
1611 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
1612 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
1613 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001614 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001615 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
1616 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001617 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001618 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
1619 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001620 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001621 case DP_TRAIN_VOLTAGE_SWING_1200 | DP_TRAIN_PRE_EMPHASIS_0:
1622 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001623 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08001624 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
1625 "0x%x\n", signal_levels);
1626 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08001627 }
1628}
1629
Keith Packard1a2eb462011-11-16 16:26:07 -08001630/* Gen7's DP voltage swing and pre-emphasis control */
1631static uint32_t
1632intel_gen7_edp_signal_levels(uint8_t train_set)
1633{
1634 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
1635 DP_TRAIN_PRE_EMPHASIS_MASK);
1636 switch (signal_levels) {
1637 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
1638 return EDP_LINK_TRAIN_400MV_0DB_IVB;
1639 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
1640 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
1641 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
1642 return EDP_LINK_TRAIN_400MV_6DB_IVB;
1643
1644 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
1645 return EDP_LINK_TRAIN_600MV_0DB_IVB;
1646 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
1647 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
1648
1649 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
1650 return EDP_LINK_TRAIN_800MV_0DB_IVB;
1651 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
1652 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
1653
1654 default:
1655 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
1656 "0x%x\n", signal_levels);
1657 return EDP_LINK_TRAIN_500MV_0DB_IVB;
1658 }
1659}
1660
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001661/* Gen7.5's (HSW) DP voltage swing and pre-emphasis control */
1662static uint32_t
Paulo Zanonif0a34242012-12-06 16:51:50 -02001663intel_hsw_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001664{
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001665 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
1666 DP_TRAIN_PRE_EMPHASIS_MASK);
1667 switch (signal_levels) {
1668 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
1669 return DDI_BUF_EMP_400MV_0DB_HSW;
1670 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
1671 return DDI_BUF_EMP_400MV_3_5DB_HSW;
1672 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
1673 return DDI_BUF_EMP_400MV_6DB_HSW;
1674 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_9_5:
1675 return DDI_BUF_EMP_400MV_9_5DB_HSW;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001676
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001677 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
1678 return DDI_BUF_EMP_600MV_0DB_HSW;
1679 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
1680 return DDI_BUF_EMP_600MV_3_5DB_HSW;
1681 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
1682 return DDI_BUF_EMP_600MV_6DB_HSW;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001683
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001684 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
1685 return DDI_BUF_EMP_800MV_0DB_HSW;
1686 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
1687 return DDI_BUF_EMP_800MV_3_5DB_HSW;
1688 default:
1689 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
1690 "0x%x\n", signal_levels);
1691 return DDI_BUF_EMP_400MV_0DB_HSW;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001692 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001693}
1694
Paulo Zanonif0a34242012-12-06 16:51:50 -02001695/* Properly updates "DP" with the correct signal levels. */
1696static void
1697intel_dp_set_signal_levels(struct intel_dp *intel_dp, uint32_t *DP)
1698{
1699 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1700 struct drm_device *dev = intel_dig_port->base.base.dev;
1701 uint32_t signal_levels, mask;
1702 uint8_t train_set = intel_dp->train_set[0];
1703
Paulo Zanoni22b8bf12013-02-18 19:00:23 -03001704 if (HAS_DDI(dev)) {
Paulo Zanonif0a34242012-12-06 16:51:50 -02001705 signal_levels = intel_hsw_signal_levels(train_set);
1706 mask = DDI_BUF_EMP_MASK;
1707 } else if (IS_GEN7(dev) && is_cpu_edp(intel_dp) && !IS_VALLEYVIEW(dev)) {
1708 signal_levels = intel_gen7_edp_signal_levels(train_set);
1709 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
1710 } else if (IS_GEN6(dev) && is_cpu_edp(intel_dp)) {
1711 signal_levels = intel_gen6_edp_signal_levels(train_set);
1712 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
1713 } else {
1714 signal_levels = intel_gen4_signal_levels(train_set);
1715 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
1716 }
1717
1718 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
1719
1720 *DP = (*DP & ~mask) | signal_levels;
1721}
1722
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001723static bool
Chris Wilsonea5b2132010-08-04 13:50:23 +01001724intel_dp_set_link_train(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001725 uint32_t dp_reg_value,
Chris Wilson58e10eb2010-10-03 10:56:11 +01001726 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001727{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001728 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1729 struct drm_device *dev = intel_dig_port->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001730 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001731 enum port port = intel_dig_port->port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001732 int ret;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001733 uint32_t temp;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001734
Paulo Zanoni22b8bf12013-02-18 19:00:23 -03001735 if (HAS_DDI(dev)) {
Paulo Zanoni174edf12012-10-26 19:05:50 -02001736 temp = I915_READ(DP_TP_CTL(port));
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001737
1738 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
1739 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
1740 else
1741 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
1742
1743 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
1744 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
1745 case DP_TRAINING_PATTERN_DISABLE:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001746
Paulo Zanoni10aa17c2013-01-29 16:35:18 -02001747 if (port != PORT_A) {
1748 temp |= DP_TP_CTL_LINK_TRAIN_IDLE;
1749 I915_WRITE(DP_TP_CTL(port), temp);
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001750
Paulo Zanoni10aa17c2013-01-29 16:35:18 -02001751 if (wait_for((I915_READ(DP_TP_STATUS(port)) &
1752 DP_TP_STATUS_IDLE_DONE), 1))
1753 DRM_ERROR("Timed out waiting for DP idle patterns\n");
1754
1755 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
1756 }
1757
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001758 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
1759
1760 break;
1761 case DP_TRAINING_PATTERN_1:
1762 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
1763 break;
1764 case DP_TRAINING_PATTERN_2:
1765 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
1766 break;
1767 case DP_TRAINING_PATTERN_3:
1768 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
1769 break;
1770 }
Paulo Zanoni174edf12012-10-26 19:05:50 -02001771 I915_WRITE(DP_TP_CTL(port), temp);
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001772
1773 } else if (HAS_PCH_CPT(dev) &&
1774 (IS_GEN7(dev) || !is_cpu_edp(intel_dp))) {
Paulo Zanoni47ea7542012-07-17 16:55:16 -03001775 dp_reg_value &= ~DP_LINK_TRAIN_MASK_CPT;
1776
1777 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
1778 case DP_TRAINING_PATTERN_DISABLE:
1779 dp_reg_value |= DP_LINK_TRAIN_OFF_CPT;
1780 break;
1781 case DP_TRAINING_PATTERN_1:
1782 dp_reg_value |= DP_LINK_TRAIN_PAT_1_CPT;
1783 break;
1784 case DP_TRAINING_PATTERN_2:
1785 dp_reg_value |= DP_LINK_TRAIN_PAT_2_CPT;
1786 break;
1787 case DP_TRAINING_PATTERN_3:
1788 DRM_ERROR("DP training pattern 3 not supported\n");
1789 dp_reg_value |= DP_LINK_TRAIN_PAT_2_CPT;
1790 break;
1791 }
1792
1793 } else {
1794 dp_reg_value &= ~DP_LINK_TRAIN_MASK;
1795
1796 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
1797 case DP_TRAINING_PATTERN_DISABLE:
1798 dp_reg_value |= DP_LINK_TRAIN_OFF;
1799 break;
1800 case DP_TRAINING_PATTERN_1:
1801 dp_reg_value |= DP_LINK_TRAIN_PAT_1;
1802 break;
1803 case DP_TRAINING_PATTERN_2:
1804 dp_reg_value |= DP_LINK_TRAIN_PAT_2;
1805 break;
1806 case DP_TRAINING_PATTERN_3:
1807 DRM_ERROR("DP training pattern 3 not supported\n");
1808 dp_reg_value |= DP_LINK_TRAIN_PAT_2;
1809 break;
1810 }
1811 }
1812
Chris Wilsonea5b2132010-08-04 13:50:23 +01001813 I915_WRITE(intel_dp->output_reg, dp_reg_value);
1814 POSTING_READ(intel_dp->output_reg);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001815
Chris Wilsonea5b2132010-08-04 13:50:23 +01001816 intel_dp_aux_native_write_1(intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001817 DP_TRAINING_PATTERN_SET,
1818 dp_train_pat);
1819
Paulo Zanoni47ea7542012-07-17 16:55:16 -03001820 if ((dp_train_pat & DP_TRAINING_PATTERN_MASK) !=
1821 DP_TRAINING_PATTERN_DISABLE) {
1822 ret = intel_dp_aux_native_write(intel_dp,
1823 DP_TRAINING_LANE0_SET,
1824 intel_dp->train_set,
1825 intel_dp->lane_count);
1826 if (ret != intel_dp->lane_count)
1827 return false;
1828 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001829
1830 return true;
1831}
1832
Jesse Barnes33a34e42010-09-08 12:42:02 -07001833/* Enable corresponding port and start training pattern 1 */
Paulo Zanonic19b0662012-10-15 15:51:41 -03001834void
Jesse Barnes33a34e42010-09-08 12:42:02 -07001835intel_dp_start_link_train(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001836{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001837 struct drm_encoder *encoder = &dp_to_dig_port(intel_dp)->base.base;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001838 struct drm_device *dev = encoder->dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001839 int i;
1840 uint8_t voltage;
1841 bool clock_recovery = false;
Keith Packardcdb0e952011-11-01 20:00:06 -07001842 int voltage_tries, loop_tries;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001843 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001844
Paulo Zanoniaffa9352012-11-23 15:30:39 -02001845 if (HAS_DDI(dev))
Paulo Zanonic19b0662012-10-15 15:51:41 -03001846 intel_ddi_prepare_link_retrain(encoder);
1847
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001848 /* Write the link configuration data */
1849 intel_dp_aux_native_write(intel_dp, DP_LINK_BW_SET,
1850 intel_dp->link_configuration,
1851 DP_LINK_CONFIGURATION_SIZE);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001852
1853 DP |= DP_PORT_EN;
Keith Packard1a2eb462011-11-16 16:26:07 -08001854
Jesse Barnes33a34e42010-09-08 12:42:02 -07001855 memset(intel_dp->train_set, 0, 4);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001856 voltage = 0xff;
Keith Packardcdb0e952011-11-01 20:00:06 -07001857 voltage_tries = 0;
1858 loop_tries = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001859 clock_recovery = false;
1860 for (;;) {
Jesse Barnes33a34e42010-09-08 12:42:02 -07001861 /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */
Keith Packard93f62da2011-11-01 19:45:03 -07001862 uint8_t link_status[DP_LINK_STATUS_SIZE];
Keith Packard417e8222011-11-01 19:54:11 -07001863
Paulo Zanonif0a34242012-12-06 16:51:50 -02001864 intel_dp_set_signal_levels(intel_dp, &DP);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001865
Daniel Vettera7c96552012-10-18 10:15:30 +02001866 /* Set training pattern 1 */
Paulo Zanoni47ea7542012-07-17 16:55:16 -03001867 if (!intel_dp_set_link_train(intel_dp, DP,
Adam Jackson81055852011-07-21 17:48:37 -04001868 DP_TRAINING_PATTERN_1 |
1869 DP_LINK_SCRAMBLING_DISABLE))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001870 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001871
Daniel Vettera7c96552012-10-18 10:15:30 +02001872 drm_dp_link_train_clock_recovery_delay(intel_dp->dpcd);
Keith Packard93f62da2011-11-01 19:45:03 -07001873 if (!intel_dp_get_link_status(intel_dp, link_status)) {
1874 DRM_ERROR("failed to get link status\n");
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001875 break;
Keith Packard93f62da2011-11-01 19:45:03 -07001876 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001877
Daniel Vetter01916272012-10-18 10:15:25 +02001878 if (drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
Keith Packard93f62da2011-11-01 19:45:03 -07001879 DRM_DEBUG_KMS("clock recovery OK\n");
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001880 clock_recovery = true;
1881 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001882 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001883
1884 /* Check to see if we've tried the max voltage */
1885 for (i = 0; i < intel_dp->lane_count; i++)
1886 if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
1887 break;
Paulo Zanoni0d710682012-06-29 16:03:34 -03001888 if (i == intel_dp->lane_count && voltage_tries == 5) {
Daniel Vetterb06fbda2012-10-16 09:50:25 +02001889 ++loop_tries;
1890 if (loop_tries == 5) {
Keith Packardcdb0e952011-11-01 20:00:06 -07001891 DRM_DEBUG_KMS("too many full retries, give up\n");
1892 break;
1893 }
1894 memset(intel_dp->train_set, 0, 4);
1895 voltage_tries = 0;
1896 continue;
1897 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001898
1899 /* Check to see if we've tried the same voltage 5 times */
Daniel Vetterb06fbda2012-10-16 09:50:25 +02001900 if ((intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) == voltage) {
Chris Wilson24773672012-09-26 16:48:30 +01001901 ++voltage_tries;
Daniel Vetterb06fbda2012-10-16 09:50:25 +02001902 if (voltage_tries == 5) {
1903 DRM_DEBUG_KMS("too many voltage retries, give up\n");
1904 break;
1905 }
1906 } else
1907 voltage_tries = 0;
1908 voltage = intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001909
1910 /* Compute new intel_dp->train_set as requested by target */
Keith Packard93f62da2011-11-01 19:45:03 -07001911 intel_get_adjust_train(intel_dp, link_status);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001912 }
1913
Jesse Barnes33a34e42010-09-08 12:42:02 -07001914 intel_dp->DP = DP;
1915}
1916
Paulo Zanonic19b0662012-10-15 15:51:41 -03001917void
Jesse Barnes33a34e42010-09-08 12:42:02 -07001918intel_dp_complete_link_train(struct intel_dp *intel_dp)
1919{
Jesse Barnes33a34e42010-09-08 12:42:02 -07001920 bool channel_eq = false;
Jesse Barnes37f80972011-01-05 14:45:24 -08001921 int tries, cr_tries;
Jesse Barnes33a34e42010-09-08 12:42:02 -07001922 uint32_t DP = intel_dp->DP;
1923
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001924 /* channel equalization */
1925 tries = 0;
Jesse Barnes37f80972011-01-05 14:45:24 -08001926 cr_tries = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001927 channel_eq = false;
1928 for (;;) {
Keith Packard93f62da2011-11-01 19:45:03 -07001929 uint8_t link_status[DP_LINK_STATUS_SIZE];
Zhenyu Wange3421a12010-04-08 09:43:27 +08001930
Jesse Barnes37f80972011-01-05 14:45:24 -08001931 if (cr_tries > 5) {
1932 DRM_ERROR("failed to train DP, aborting\n");
1933 intel_dp_link_down(intel_dp);
1934 break;
1935 }
1936
Paulo Zanonif0a34242012-12-06 16:51:50 -02001937 intel_dp_set_signal_levels(intel_dp, &DP);
Zhenyu Wange3421a12010-04-08 09:43:27 +08001938
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001939 /* channel eq pattern */
Paulo Zanoni47ea7542012-07-17 16:55:16 -03001940 if (!intel_dp_set_link_train(intel_dp, DP,
Adam Jackson81055852011-07-21 17:48:37 -04001941 DP_TRAINING_PATTERN_2 |
1942 DP_LINK_SCRAMBLING_DISABLE))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001943 break;
1944
Daniel Vettera7c96552012-10-18 10:15:30 +02001945 drm_dp_link_train_channel_eq_delay(intel_dp->dpcd);
Keith Packard93f62da2011-11-01 19:45:03 -07001946 if (!intel_dp_get_link_status(intel_dp, link_status))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001947 break;
Jesse Barnes869184a2010-10-07 16:01:22 -07001948
Jesse Barnes37f80972011-01-05 14:45:24 -08001949 /* Make sure clock is still ok */
Daniel Vetter01916272012-10-18 10:15:25 +02001950 if (!drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
Jesse Barnes37f80972011-01-05 14:45:24 -08001951 intel_dp_start_link_train(intel_dp);
1952 cr_tries++;
1953 continue;
1954 }
1955
Daniel Vetter1ffdff12012-10-18 10:15:24 +02001956 if (drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001957 channel_eq = true;
1958 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001959 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001960
Jesse Barnes37f80972011-01-05 14:45:24 -08001961 /* Try 5 times, then try clock recovery if that fails */
1962 if (tries > 5) {
1963 intel_dp_link_down(intel_dp);
1964 intel_dp_start_link_train(intel_dp);
1965 tries = 0;
1966 cr_tries++;
1967 continue;
1968 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001969
1970 /* Compute new intel_dp->train_set as requested by target */
Keith Packard93f62da2011-11-01 19:45:03 -07001971 intel_get_adjust_train(intel_dp, link_status);
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001972 ++tries;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001973 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00001974
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001975 if (channel_eq)
1976 DRM_DEBUG_KMS("Channel EQ done. DP Training successfull\n");
1977
Paulo Zanoni47ea7542012-07-17 16:55:16 -03001978 intel_dp_set_link_train(intel_dp, DP, DP_TRAINING_PATTERN_DISABLE);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001979}
1980
1981static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01001982intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001983{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001984 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1985 struct drm_device *dev = intel_dig_port->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001986 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterab527ef2012-11-29 15:59:33 +01001987 struct intel_crtc *intel_crtc =
1988 to_intel_crtc(intel_dig_port->base.base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01001989 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001990
Paulo Zanonic19b0662012-10-15 15:51:41 -03001991 /*
1992 * DDI code has a strict mode set sequence and we should try to respect
1993 * it, otherwise we might hang the machine in many different ways. So we
1994 * really should be disabling the port only on a complete crtc_disable
1995 * sequence. This function is just called under two conditions on DDI
1996 * code:
1997 * - Link train failed while doing crtc_enable, and on this case we
1998 * really should respect the mode set sequence and wait for a
1999 * crtc_disable.
2000 * - Someone turned the monitor off and intel_dp_check_link_status
2001 * called us. We don't need to disable the whole port on this case, so
2002 * when someone turns the monitor on again,
2003 * intel_ddi_prepare_link_retrain will take care of redoing the link
2004 * train.
2005 */
Paulo Zanoniaffa9352012-11-23 15:30:39 -02002006 if (HAS_DDI(dev))
Paulo Zanonic19b0662012-10-15 15:51:41 -03002007 return;
2008
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002009 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00002010 return;
2011
Zhao Yakui28c97732009-10-09 11:39:41 +08002012 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002013
Keith Packard1a2eb462011-11-16 16:26:07 -08002014 if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || !is_cpu_edp(intel_dp))) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08002015 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Chris Wilsonea5b2132010-08-04 13:50:23 +01002016 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT);
Zhenyu Wange3421a12010-04-08 09:43:27 +08002017 } else {
2018 DP &= ~DP_LINK_TRAIN_MASK;
Chris Wilsonea5b2132010-08-04 13:50:23 +01002019 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE);
Zhenyu Wange3421a12010-04-08 09:43:27 +08002020 }
Chris Wilsonfe255d02010-09-11 21:37:48 +01002021 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002022
Daniel Vetterab527ef2012-11-29 15:59:33 +01002023 /* We don't really know why we're doing this */
2024 intel_wait_for_vblank(dev, intel_crtc->pipe);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002025
Daniel Vetter493a7082012-05-30 12:31:56 +02002026 if (HAS_PCH_IBX(dev) &&
Chris Wilson1b39d6f2010-12-06 11:20:45 +00002027 I915_READ(intel_dp->output_reg) & DP_PIPEB_SELECT) {
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002028 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
Chris Wilson31acbcc2011-04-17 06:38:35 +01002029
Eric Anholt5bddd172010-11-18 09:32:59 +08002030 /* Hardware workaround: leaving our transcoder select
2031 * set to transcoder B while it's off will prevent the
2032 * corresponding HDMI output on transcoder A.
2033 *
2034 * Combine this with another hardware workaround:
2035 * transcoder select bit can only be cleared while the
2036 * port is enabled.
2037 */
2038 DP &= ~DP_PIPEB_SELECT;
2039 I915_WRITE(intel_dp->output_reg, DP);
2040
2041 /* Changes to enable or select take place the vblank
2042 * after being written.
2043 */
Daniel Vetterff50afe2012-11-29 15:59:34 +01002044 if (WARN_ON(crtc == NULL)) {
2045 /* We should never try to disable a port without a crtc
2046 * attached. For paranoia keep the code around for a
2047 * bit. */
Chris Wilson31acbcc2011-04-17 06:38:35 +01002048 POSTING_READ(intel_dp->output_reg);
2049 msleep(50);
2050 } else
Daniel Vetterab527ef2012-11-29 15:59:33 +01002051 intel_wait_for_vblank(dev, intel_crtc->pipe);
Eric Anholt5bddd172010-11-18 09:32:59 +08002052 }
2053
Wu Fengguang832afda2011-12-09 20:42:21 +08002054 DP &= ~DP_AUDIO_OUTPUT_ENABLE;
Chris Wilsonea5b2132010-08-04 13:50:23 +01002055 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
2056 POSTING_READ(intel_dp->output_reg);
Keith Packardf01eca22011-09-28 16:48:10 -07002057 msleep(intel_dp->panel_power_down_delay);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002058}
2059
Keith Packard26d61aa2011-07-25 20:01:09 -07002060static bool
2061intel_dp_get_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07002062{
Damien Lespiau577c7a52012-12-13 16:09:02 +00002063 char dpcd_hex_dump[sizeof(intel_dp->dpcd) * 3];
2064
Keith Packard92fd8fd2011-07-25 19:50:10 -07002065 if (intel_dp_aux_native_read_retry(intel_dp, 0x000, intel_dp->dpcd,
Adam Jacksonedb39242012-09-18 10:58:49 -04002066 sizeof(intel_dp->dpcd)) == 0)
2067 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07002068
Damien Lespiau577c7a52012-12-13 16:09:02 +00002069 hex_dump_to_buffer(intel_dp->dpcd, sizeof(intel_dp->dpcd),
2070 32, 1, dpcd_hex_dump, sizeof(dpcd_hex_dump), false);
2071 DRM_DEBUG_KMS("DPCD: %s\n", dpcd_hex_dump);
2072
Adam Jacksonedb39242012-09-18 10:58:49 -04002073 if (intel_dp->dpcd[DP_DPCD_REV] == 0)
2074 return false; /* DPCD not present */
2075
2076 if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
2077 DP_DWN_STRM_PORT_PRESENT))
2078 return true; /* native DP sink */
2079
2080 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
2081 return true; /* no per-port downstream info */
2082
2083 if (intel_dp_aux_native_read_retry(intel_dp, DP_DOWNSTREAM_PORT_0,
2084 intel_dp->downstream_ports,
2085 DP_MAX_DOWNSTREAM_PORTS) == 0)
2086 return false; /* downstream port status fetch failed */
2087
2088 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07002089}
2090
Adam Jackson0d198322012-05-14 16:05:47 -04002091static void
2092intel_dp_probe_oui(struct intel_dp *intel_dp)
2093{
2094 u8 buf[3];
2095
2096 if (!(intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] & DP_OUI_SUPPORT))
2097 return;
2098
Daniel Vetter351cfc32012-06-12 13:20:47 +02002099 ironlake_edp_panel_vdd_on(intel_dp);
2100
Adam Jackson0d198322012-05-14 16:05:47 -04002101 if (intel_dp_aux_native_read_retry(intel_dp, DP_SINK_OUI, buf, 3))
2102 DRM_DEBUG_KMS("Sink OUI: %02hx%02hx%02hx\n",
2103 buf[0], buf[1], buf[2]);
2104
2105 if (intel_dp_aux_native_read_retry(intel_dp, DP_BRANCH_OUI, buf, 3))
2106 DRM_DEBUG_KMS("Branch OUI: %02hx%02hx%02hx\n",
2107 buf[0], buf[1], buf[2]);
Daniel Vetter351cfc32012-06-12 13:20:47 +02002108
2109 ironlake_edp_panel_vdd_off(intel_dp, false);
Adam Jackson0d198322012-05-14 16:05:47 -04002110}
2111
Jesse Barnesa60f0e32011-10-20 15:09:17 -07002112static bool
2113intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
2114{
2115 int ret;
2116
2117 ret = intel_dp_aux_native_read_retry(intel_dp,
2118 DP_DEVICE_SERVICE_IRQ_VECTOR,
2119 sink_irq_vector, 1);
2120 if (!ret)
2121 return false;
2122
2123 return true;
2124}
2125
2126static void
2127intel_dp_handle_test_request(struct intel_dp *intel_dp)
2128{
2129 /* NAK by default */
Daniel Vetter9324cf72012-10-20 21:13:05 +02002130 intel_dp_aux_native_write_1(intel_dp, DP_TEST_RESPONSE, DP_TEST_NAK);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07002131}
2132
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002133/*
2134 * According to DP spec
2135 * 5.1.2:
2136 * 1. Read DPCD
2137 * 2. Configure link according to Receiver Capabilities
2138 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
2139 * 4. Check link status on receipt of hot-plug interrupt
2140 */
2141
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002142void
Chris Wilsonea5b2132010-08-04 13:50:23 +01002143intel_dp_check_link_status(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002144{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002145 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07002146 u8 sink_irq_vector;
Keith Packard93f62da2011-11-01 19:45:03 -07002147 u8 link_status[DP_LINK_STATUS_SIZE];
Jesse Barnesa60f0e32011-10-20 15:09:17 -07002148
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002149 if (!intel_encoder->connectors_active)
Keith Packardd2b996a2011-07-25 22:37:51 -07002150 return;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07002151
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002152 if (WARN_ON(!intel_encoder->base.crtc))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002153 return;
2154
Keith Packard92fd8fd2011-07-25 19:50:10 -07002155 /* Try to read receiver status if the link appears to be up */
Keith Packard93f62da2011-11-01 19:45:03 -07002156 if (!intel_dp_get_link_status(intel_dp, link_status)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01002157 intel_dp_link_down(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002158 return;
2159 }
2160
Keith Packard92fd8fd2011-07-25 19:50:10 -07002161 /* Now read the DPCD to see if it's actually running */
Keith Packard26d61aa2011-07-25 20:01:09 -07002162 if (!intel_dp_get_dpcd(intel_dp)) {
Jesse Barnes59cd09e2011-07-07 11:10:59 -07002163 intel_dp_link_down(intel_dp);
2164 return;
2165 }
2166
Jesse Barnesa60f0e32011-10-20 15:09:17 -07002167 /* Try to read the source of the interrupt */
2168 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
2169 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector)) {
2170 /* Clear interrupt source */
2171 intel_dp_aux_native_write_1(intel_dp,
2172 DP_DEVICE_SERVICE_IRQ_VECTOR,
2173 sink_irq_vector);
2174
2175 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
2176 intel_dp_handle_test_request(intel_dp);
2177 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
2178 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
2179 }
2180
Daniel Vetter1ffdff12012-10-18 10:15:24 +02002181 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Keith Packard92fd8fd2011-07-25 19:50:10 -07002182 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002183 drm_get_encoder_name(&intel_encoder->base));
Jesse Barnes33a34e42010-09-08 12:42:02 -07002184 intel_dp_start_link_train(intel_dp);
2185 intel_dp_complete_link_train(intel_dp);
2186 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002187}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002188
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04002189/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002190static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07002191intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04002192{
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04002193 uint8_t *dpcd = intel_dp->dpcd;
2194 bool hpd;
2195 uint8_t type;
2196
2197 if (!intel_dp_get_dpcd(intel_dp))
2198 return connector_status_disconnected;
2199
2200 /* if there's no downstream port, we're done */
2201 if (!(dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT))
Keith Packard26d61aa2011-07-25 20:01:09 -07002202 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04002203
2204 /* If we're HPD-aware, SINK_COUNT changes dynamically */
2205 hpd = !!(intel_dp->downstream_ports[0] & DP_DS_PORT_HPD);
2206 if (hpd) {
Adam Jackson23235172012-09-20 16:42:45 -04002207 uint8_t reg;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04002208 if (!intel_dp_aux_native_read_retry(intel_dp, DP_SINK_COUNT,
Adam Jackson23235172012-09-20 16:42:45 -04002209 &reg, 1))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04002210 return connector_status_unknown;
Adam Jackson23235172012-09-20 16:42:45 -04002211 return DP_GET_SINK_COUNT(reg) ? connector_status_connected
2212 : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04002213 }
2214
2215 /* If no HPD, poke DDC gently */
2216 if (drm_probe_ddc(&intel_dp->adapter))
2217 return connector_status_connected;
2218
2219 /* Well we tried, say unknown for unreliable port types */
2220 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
2221 if (type == DP_DS_PORT_TYPE_VGA || type == DP_DS_PORT_TYPE_NON_EDID)
2222 return connector_status_unknown;
2223
2224 /* Anything else is out of spec, warn and ignore */
2225 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07002226 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04002227}
2228
2229static enum drm_connector_status
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002230ironlake_dp_detect(struct intel_dp *intel_dp)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002231{
Paulo Zanoni30add222012-10-26 19:05:45 -02002232 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Damien Lespiau1b469632012-12-13 16:09:01 +00002233 struct drm_i915_private *dev_priv = dev->dev_private;
2234 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002235 enum drm_connector_status status;
2236
Chris Wilsonfe16d942011-02-12 10:29:38 +00002237 /* Can't disconnect eDP, but you can close the lid... */
2238 if (is_edp(intel_dp)) {
Paulo Zanoni30add222012-10-26 19:05:45 -02002239 status = intel_panel_detect(dev);
Chris Wilsonfe16d942011-02-12 10:29:38 +00002240 if (status == connector_status_unknown)
2241 status = connector_status_connected;
2242 return status;
2243 }
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002244
Damien Lespiau1b469632012-12-13 16:09:01 +00002245 if (!ibx_digital_port_connected(dev_priv, intel_dig_port))
2246 return connector_status_disconnected;
2247
Keith Packard26d61aa2011-07-25 20:01:09 -07002248 return intel_dp_detect_dpcd(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002249}
2250
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002251static enum drm_connector_status
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002252g4x_dp_detect(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002253{
Paulo Zanoni30add222012-10-26 19:05:45 -02002254 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002255 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä34f2be42013-01-24 15:29:27 +02002256 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilson10f76a32012-05-11 18:01:32 +01002257 uint32_t bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002258
Jesse Barnes35aad752013-03-01 13:14:31 -08002259 /* Can't disconnect eDP, but you can close the lid... */
2260 if (is_edp(intel_dp)) {
2261 enum drm_connector_status status;
2262
2263 status = intel_panel_detect(dev);
2264 if (status == connector_status_unknown)
2265 status = connector_status_connected;
2266 return status;
2267 }
2268
Ville Syrjälä34f2be42013-01-24 15:29:27 +02002269 switch (intel_dig_port->port) {
2270 case PORT_B:
Daniel Vetter26739f12013-02-07 12:42:32 +01002271 bit = PORTB_HOTPLUG_LIVE_STATUS;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002272 break;
Ville Syrjälä34f2be42013-01-24 15:29:27 +02002273 case PORT_C:
Daniel Vetter26739f12013-02-07 12:42:32 +01002274 bit = PORTC_HOTPLUG_LIVE_STATUS;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002275 break;
Ville Syrjälä34f2be42013-01-24 15:29:27 +02002276 case PORT_D:
Daniel Vetter26739f12013-02-07 12:42:32 +01002277 bit = PORTD_HOTPLUG_LIVE_STATUS;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002278 break;
2279 default:
2280 return connector_status_unknown;
2281 }
2282
Chris Wilson10f76a32012-05-11 18:01:32 +01002283 if ((I915_READ(PORT_HOTPLUG_STAT) & bit) == 0)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002284 return connector_status_disconnected;
2285
Keith Packard26d61aa2011-07-25 20:01:09 -07002286 return intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002287}
2288
Keith Packard8c241fe2011-09-28 16:38:44 -07002289static struct edid *
2290intel_dp_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
2291{
Jani Nikula9cd300e2012-10-19 14:51:52 +03002292 struct intel_connector *intel_connector = to_intel_connector(connector);
Keith Packard8c241fe2011-09-28 16:38:44 -07002293
Jani Nikula9cd300e2012-10-19 14:51:52 +03002294 /* use cached edid if we have one */
2295 if (intel_connector->edid) {
2296 struct edid *edid;
2297 int size;
2298
2299 /* invalid edid */
2300 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04002301 return NULL;
2302
Jani Nikula9cd300e2012-10-19 14:51:52 +03002303 size = (intel_connector->edid->extensions + 1) * EDID_LENGTH;
Jesse Barnesd6f24d02012-06-14 15:28:33 -04002304 edid = kmalloc(size, GFP_KERNEL);
2305 if (!edid)
2306 return NULL;
2307
Jani Nikula9cd300e2012-10-19 14:51:52 +03002308 memcpy(edid, intel_connector->edid, size);
Jesse Barnesd6f24d02012-06-14 15:28:33 -04002309 return edid;
2310 }
2311
Jani Nikula9cd300e2012-10-19 14:51:52 +03002312 return drm_get_edid(connector, adapter);
Keith Packard8c241fe2011-09-28 16:38:44 -07002313}
2314
2315static int
2316intel_dp_get_edid_modes(struct drm_connector *connector, struct i2c_adapter *adapter)
2317{
Jani Nikula9cd300e2012-10-19 14:51:52 +03002318 struct intel_connector *intel_connector = to_intel_connector(connector);
Keith Packard8c241fe2011-09-28 16:38:44 -07002319
Jani Nikula9cd300e2012-10-19 14:51:52 +03002320 /* use cached edid if we have one */
2321 if (intel_connector->edid) {
2322 /* invalid edid */
2323 if (IS_ERR(intel_connector->edid))
2324 return 0;
2325
2326 return intel_connector_update_modes(connector,
2327 intel_connector->edid);
Jesse Barnesd6f24d02012-06-14 15:28:33 -04002328 }
2329
Jani Nikula9cd300e2012-10-19 14:51:52 +03002330 return intel_ddc_get_modes(connector, adapter);
Keith Packard8c241fe2011-09-28 16:38:44 -07002331}
2332
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002333static enum drm_connector_status
2334intel_dp_detect(struct drm_connector *connector, bool force)
2335{
2336 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02002337 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2338 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02002339 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002340 enum drm_connector_status status;
2341 struct edid *edid = NULL;
2342
2343 intel_dp->has_audio = false;
2344
2345 if (HAS_PCH_SPLIT(dev))
2346 status = ironlake_dp_detect(intel_dp);
2347 else
2348 status = g4x_dp_detect(intel_dp);
Adam Jackson1b9be9d2011-07-12 17:38:01 -04002349
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002350 if (status != connector_status_connected)
2351 return status;
2352
Adam Jackson0d198322012-05-14 16:05:47 -04002353 intel_dp_probe_oui(intel_dp);
2354
Daniel Vetterc3e5f672012-02-23 17:14:47 +01002355 if (intel_dp->force_audio != HDMI_AUDIO_AUTO) {
2356 intel_dp->has_audio = (intel_dp->force_audio == HDMI_AUDIO_ON);
Chris Wilsonf6849602010-09-19 09:29:33 +01002357 } else {
Keith Packard8c241fe2011-09-28 16:38:44 -07002358 edid = intel_dp_get_edid(connector, &intel_dp->adapter);
Chris Wilsonf6849602010-09-19 09:29:33 +01002359 if (edid) {
2360 intel_dp->has_audio = drm_detect_monitor_audio(edid);
Chris Wilsonf6849602010-09-19 09:29:33 +01002361 kfree(edid);
2362 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002363 }
2364
Paulo Zanonid63885d2012-10-26 19:05:49 -02002365 if (intel_encoder->type != INTEL_OUTPUT_EDP)
2366 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002367 return connector_status_connected;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002368}
2369
2370static int intel_dp_get_modes(struct drm_connector *connector)
2371{
Chris Wilsondf0e9242010-09-09 16:20:55 +01002372 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +03002373 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonifa90ece2012-10-26 19:05:44 -02002374 struct drm_device *dev = connector->dev;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002375 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002376
2377 /* We should parse the EDID data and find out if it has an audio sink
2378 */
2379
Keith Packard8c241fe2011-09-28 16:38:44 -07002380 ret = intel_dp_get_edid_modes(connector, &intel_dp->adapter);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002381 if (ret)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002382 return ret;
2383
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002384 /* if eDP has no EDID, fall back to fixed mode */
Jani Nikuladd06f902012-10-19 14:51:50 +03002385 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002386 struct drm_display_mode *mode;
Jani Nikuladd06f902012-10-19 14:51:50 +03002387 mode = drm_mode_duplicate(dev,
2388 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002389 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002390 drm_mode_probed_add(connector, mode);
2391 return 1;
2392 }
2393 }
2394 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002395}
2396
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002397static bool
2398intel_dp_detect_audio(struct drm_connector *connector)
2399{
2400 struct intel_dp *intel_dp = intel_attached_dp(connector);
2401 struct edid *edid;
2402 bool has_audio = false;
2403
Keith Packard8c241fe2011-09-28 16:38:44 -07002404 edid = intel_dp_get_edid(connector, &intel_dp->adapter);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002405 if (edid) {
2406 has_audio = drm_detect_monitor_audio(edid);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002407 kfree(edid);
2408 }
2409
2410 return has_audio;
2411}
2412
Chris Wilsonf6849602010-09-19 09:29:33 +01002413static int
2414intel_dp_set_property(struct drm_connector *connector,
2415 struct drm_property *property,
2416 uint64_t val)
2417{
Chris Wilsone953fd72011-02-21 22:23:52 +00002418 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Yuly Novikov53b41832012-10-26 12:04:00 +03002419 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002420 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
2421 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01002422 int ret;
2423
Rob Clark662595d2012-10-11 20:36:04 -05002424 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01002425 if (ret)
2426 return ret;
2427
Chris Wilson3f43c482011-05-12 22:17:24 +01002428 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002429 int i = val;
2430 bool has_audio;
2431
2432 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01002433 return 0;
2434
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002435 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01002436
Daniel Vetterc3e5f672012-02-23 17:14:47 +01002437 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002438 has_audio = intel_dp_detect_audio(connector);
2439 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01002440 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002441
2442 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01002443 return 0;
2444
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002445 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01002446 goto done;
2447 }
2448
Chris Wilsone953fd72011-02-21 22:23:52 +00002449 if (property == dev_priv->broadcast_rgb_property) {
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02002450 switch (val) {
2451 case INTEL_BROADCAST_RGB_AUTO:
2452 intel_dp->color_range_auto = true;
2453 break;
2454 case INTEL_BROADCAST_RGB_FULL:
2455 intel_dp->color_range_auto = false;
2456 intel_dp->color_range = 0;
2457 break;
2458 case INTEL_BROADCAST_RGB_LIMITED:
2459 intel_dp->color_range_auto = false;
2460 intel_dp->color_range = DP_COLOR_RANGE_16_235;
2461 break;
2462 default:
2463 return -EINVAL;
2464 }
Chris Wilsone953fd72011-02-21 22:23:52 +00002465 goto done;
2466 }
2467
Yuly Novikov53b41832012-10-26 12:04:00 +03002468 if (is_edp(intel_dp) &&
2469 property == connector->dev->mode_config.scaling_mode_property) {
2470 if (val == DRM_MODE_SCALE_NONE) {
2471 DRM_DEBUG_KMS("no scaling not supported\n");
2472 return -EINVAL;
2473 }
2474
2475 if (intel_connector->panel.fitting_mode == val) {
2476 /* the eDP scaling property is not changed */
2477 return 0;
2478 }
2479 intel_connector->panel.fitting_mode = val;
2480
2481 goto done;
2482 }
2483
Chris Wilsonf6849602010-09-19 09:29:33 +01002484 return -EINVAL;
2485
2486done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00002487 if (intel_encoder->base.crtc)
2488 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01002489
2490 return 0;
2491}
2492
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002493static void
Akshay Joshi0206e352011-08-16 15:34:10 -04002494intel_dp_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002495{
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02002496 struct drm_device *dev = connector->dev;
Jani Nikulabe3cd5e2012-10-12 10:33:05 +03002497 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikula1d508702012-10-19 14:51:49 +03002498 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02002499
Jani Nikula9cd300e2012-10-19 14:51:52 +03002500 if (!IS_ERR_OR_NULL(intel_connector->edid))
2501 kfree(intel_connector->edid);
2502
Jani Nikula1d508702012-10-19 14:51:49 +03002503 if (is_edp(intel_dp)) {
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02002504 intel_panel_destroy_backlight(dev);
Jani Nikula1d508702012-10-19 14:51:49 +03002505 intel_panel_fini(&intel_connector->panel);
2506 }
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02002507
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002508 drm_sysfs_connector_remove(connector);
2509 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08002510 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002511}
2512
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002513void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02002514{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002515 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
2516 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02002517
2518 i2c_del_adapter(&intel_dp->adapter);
2519 drm_encoder_cleanup(encoder);
Keith Packardbd943152011-09-18 23:09:52 -07002520 if (is_edp(intel_dp)) {
2521 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
2522 ironlake_panel_vdd_off_sync(intel_dp);
2523 }
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002524 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02002525}
2526
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002527static const struct drm_encoder_helper_funcs intel_dp_helper_funcs = {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002528 .mode_set = intel_dp_mode_set,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002529};
2530
2531static const struct drm_connector_funcs intel_dp_connector_funcs = {
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002532 .dpms = intel_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002533 .detect = intel_dp_detect,
2534 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01002535 .set_property = intel_dp_set_property,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002536 .destroy = intel_dp_destroy,
2537};
2538
2539static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
2540 .get_modes = intel_dp_get_modes,
2541 .mode_valid = intel_dp_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +01002542 .best_encoder = intel_best_encoder,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002543};
2544
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002545static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Daniel Vetter24d05922010-08-20 18:08:28 +02002546 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002547};
2548
Chris Wilson995b6762010-08-20 13:23:26 +01002549static void
Eric Anholt21d40d32010-03-25 11:11:14 -07002550intel_dp_hot_plug(struct intel_encoder *intel_encoder)
Keith Packardc8110e52009-05-06 11:51:10 -07002551{
Paulo Zanonifa90ece2012-10-26 19:05:44 -02002552 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Keith Packardc8110e52009-05-06 11:51:10 -07002553
Jesse Barnes885a5012011-07-07 11:11:01 -07002554 intel_dp_check_link_status(intel_dp);
Keith Packardc8110e52009-05-06 11:51:10 -07002555}
2556
Zhenyu Wange3421a12010-04-08 09:43:27 +08002557/* Return which DP Port should be selected for Transcoder DP control */
2558int
Akshay Joshi0206e352011-08-16 15:34:10 -04002559intel_trans_dp_port_sel(struct drm_crtc *crtc)
Zhenyu Wange3421a12010-04-08 09:43:27 +08002560{
2561 struct drm_device *dev = crtc->dev;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02002562 struct intel_encoder *intel_encoder;
2563 struct intel_dp *intel_dp;
Zhenyu Wange3421a12010-04-08 09:43:27 +08002564
Paulo Zanonifa90ece2012-10-26 19:05:44 -02002565 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
2566 intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002567
Paulo Zanonifa90ece2012-10-26 19:05:44 -02002568 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
2569 intel_encoder->type == INTEL_OUTPUT_EDP)
Chris Wilsonea5b2132010-08-04 13:50:23 +01002570 return intel_dp->output_reg;
Zhenyu Wange3421a12010-04-08 09:43:27 +08002571 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01002572
Zhenyu Wange3421a12010-04-08 09:43:27 +08002573 return -1;
2574}
2575
Zhao Yakui36e83a12010-06-12 14:32:21 +08002576/* check the VBT to see whether the eDP is on DP-D port */
Adam Jacksoncb0953d2010-07-16 14:46:29 -04002577bool intel_dpd_is_edp(struct drm_device *dev)
Zhao Yakui36e83a12010-06-12 14:32:21 +08002578{
2579 struct drm_i915_private *dev_priv = dev->dev_private;
2580 struct child_device_config *p_child;
2581 int i;
2582
2583 if (!dev_priv->child_dev_num)
2584 return false;
2585
2586 for (i = 0; i < dev_priv->child_dev_num; i++) {
2587 p_child = dev_priv->child_dev + i;
2588
2589 if (p_child->dvo_port == PORT_IDPD &&
2590 p_child->device_type == DEVICE_TYPE_eDP)
2591 return true;
2592 }
2593 return false;
2594}
2595
Chris Wilsonf6849602010-09-19 09:29:33 +01002596static void
2597intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
2598{
Yuly Novikov53b41832012-10-26 12:04:00 +03002599 struct intel_connector *intel_connector = to_intel_connector(connector);
2600
Chris Wilson3f43c482011-05-12 22:17:24 +01002601 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00002602 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02002603 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03002604
2605 if (is_edp(intel_dp)) {
2606 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05002607 drm_object_attach_property(
2608 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03002609 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03002610 DRM_MODE_SCALE_ASPECT);
2611 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03002612 }
Chris Wilsonf6849602010-09-19 09:29:33 +01002613}
2614
Daniel Vetter67a54562012-10-20 20:57:45 +02002615static void
2616intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Jani Nikulaf30d26e2013-01-16 10:53:40 +02002617 struct intel_dp *intel_dp,
2618 struct edp_power_seq *out)
Daniel Vetter67a54562012-10-20 20:57:45 +02002619{
2620 struct drm_i915_private *dev_priv = dev->dev_private;
2621 struct edp_power_seq cur, vbt, spec, final;
2622 u32 pp_on, pp_off, pp_div, pp;
2623
2624 /* Workaround: Need to write PP_CONTROL with the unlock key as
2625 * the very first thing. */
2626 pp = ironlake_get_pp_control(dev_priv);
2627 I915_WRITE(PCH_PP_CONTROL, pp);
2628
2629 pp_on = I915_READ(PCH_PP_ON_DELAYS);
2630 pp_off = I915_READ(PCH_PP_OFF_DELAYS);
2631 pp_div = I915_READ(PCH_PP_DIVISOR);
2632
2633 /* Pull timing values out of registers */
2634 cur.t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
2635 PANEL_POWER_UP_DELAY_SHIFT;
2636
2637 cur.t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
2638 PANEL_LIGHT_ON_DELAY_SHIFT;
2639
2640 cur.t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
2641 PANEL_LIGHT_OFF_DELAY_SHIFT;
2642
2643 cur.t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
2644 PANEL_POWER_DOWN_DELAY_SHIFT;
2645
2646 cur.t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
2647 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
2648
2649 DRM_DEBUG_KMS("cur t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
2650 cur.t1_t3, cur.t8, cur.t9, cur.t10, cur.t11_t12);
2651
2652 vbt = dev_priv->edp.pps;
2653
2654 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
2655 * our hw here, which are all in 100usec. */
2656 spec.t1_t3 = 210 * 10;
2657 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
2658 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
2659 spec.t10 = 500 * 10;
2660 /* This one is special and actually in units of 100ms, but zero
2661 * based in the hw (so we need to add 100 ms). But the sw vbt
2662 * table multiplies it with 1000 to make it in units of 100usec,
2663 * too. */
2664 spec.t11_t12 = (510 + 100) * 10;
2665
2666 DRM_DEBUG_KMS("vbt t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
2667 vbt.t1_t3, vbt.t8, vbt.t9, vbt.t10, vbt.t11_t12);
2668
2669 /* Use the max of the register settings and vbt. If both are
2670 * unset, fall back to the spec limits. */
2671#define assign_final(field) final.field = (max(cur.field, vbt.field) == 0 ? \
2672 spec.field : \
2673 max(cur.field, vbt.field))
2674 assign_final(t1_t3);
2675 assign_final(t8);
2676 assign_final(t9);
2677 assign_final(t10);
2678 assign_final(t11_t12);
2679#undef assign_final
2680
2681#define get_delay(field) (DIV_ROUND_UP(final.field, 10))
2682 intel_dp->panel_power_up_delay = get_delay(t1_t3);
2683 intel_dp->backlight_on_delay = get_delay(t8);
2684 intel_dp->backlight_off_delay = get_delay(t9);
2685 intel_dp->panel_power_down_delay = get_delay(t10);
2686 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
2687#undef get_delay
2688
Jani Nikulaf30d26e2013-01-16 10:53:40 +02002689 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
2690 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
2691 intel_dp->panel_power_cycle_delay);
2692
2693 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
2694 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
2695
2696 if (out)
2697 *out = final;
2698}
2699
2700static void
2701intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
2702 struct intel_dp *intel_dp,
2703 struct edp_power_seq *seq)
2704{
2705 struct drm_i915_private *dev_priv = dev->dev_private;
2706 u32 pp_on, pp_off, pp_div;
2707
Daniel Vetter67a54562012-10-20 20:57:45 +02002708 /* And finally store the new values in the power sequencer. */
Jani Nikulaf30d26e2013-01-16 10:53:40 +02002709 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
2710 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
2711 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
2712 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02002713 /* Compute the divisor for the pp clock, simply match the Bspec
2714 * formula. */
2715 pp_div = ((100 * intel_pch_rawclk(dev))/2 - 1)
2716 << PP_REFERENCE_DIVIDER_SHIFT;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02002717 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
Daniel Vetter67a54562012-10-20 20:57:45 +02002718 << PANEL_POWER_CYCLE_DELAY_SHIFT);
2719
2720 /* Haswell doesn't have any port selection bits for the panel
2721 * power sequencer any more. */
2722 if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) {
2723 if (is_cpu_edp(intel_dp))
2724 pp_on |= PANEL_POWER_PORT_DP_A;
2725 else
2726 pp_on |= PANEL_POWER_PORT_DP_D;
2727 }
2728
2729 I915_WRITE(PCH_PP_ON_DELAYS, pp_on);
2730 I915_WRITE(PCH_PP_OFF_DELAYS, pp_off);
2731 I915_WRITE(PCH_PP_DIVISOR, pp_div);
2732
Daniel Vetter67a54562012-10-20 20:57:45 +02002733 DRM_DEBUG_KMS("panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n",
2734 I915_READ(PCH_PP_ON_DELAYS),
2735 I915_READ(PCH_PP_OFF_DELAYS),
2736 I915_READ(PCH_PP_DIVISOR));
Keith Packardc8110e52009-05-06 11:51:10 -07002737}
2738
2739void
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02002740intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
2741 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002742{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02002743 struct drm_connector *connector = &intel_connector->base;
2744 struct intel_dp *intel_dp = &intel_dig_port->dp;
2745 struct intel_encoder *intel_encoder = &intel_dig_port->base;
2746 struct drm_device *dev = intel_encoder->base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002747 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002748 struct drm_display_mode *fixed_mode = NULL;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02002749 struct edp_power_seq power_seq = { 0 };
Paulo Zanoni174edf12012-10-26 19:05:50 -02002750 enum port port = intel_dig_port->port;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002751 const char *name = NULL;
Adam Jacksonb3295302010-07-16 14:46:28 -04002752 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002753
Daniel Vetter07679352012-09-06 22:15:42 +02002754 /* Preserve the current hw state. */
2755 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03002756 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00002757
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02002758 if (HAS_PCH_SPLIT(dev) && port == PORT_D)
Adam Jacksonb3295302010-07-16 14:46:28 -04002759 if (intel_dpd_is_edp(dev))
Chris Wilsonea5b2132010-08-04 13:50:23 +01002760 intel_dp->is_pch_edp = true;
Adam Jacksonb3295302010-07-16 14:46:28 -04002761
Gajanan Bhat19c03922012-09-27 19:13:07 +05302762 /*
2763 * FIXME : We need to initialize built-in panels before external panels.
2764 * For X0, DP_C is fixed as eDP. Revisit this as part of VLV eDP cleanup
2765 */
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02002766 if (IS_VALLEYVIEW(dev) && port == PORT_C) {
Gajanan Bhat19c03922012-09-27 19:13:07 +05302767 type = DRM_MODE_CONNECTOR_eDP;
2768 intel_encoder->type = INTEL_OUTPUT_EDP;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02002769 } else if (port == PORT_A || is_pch_edp(intel_dp)) {
Adam Jacksonb3295302010-07-16 14:46:28 -04002770 type = DRM_MODE_CONNECTOR_eDP;
2771 intel_encoder->type = INTEL_OUTPUT_EDP;
2772 } else {
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002773 /* The intel_encoder->type value may be INTEL_OUTPUT_UNKNOWN for
2774 * DDI or INTEL_OUTPUT_DISPLAYPORT for the older gens, so don't
2775 * rewrite it.
2776 */
Adam Jacksonb3295302010-07-16 14:46:28 -04002777 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04002778 }
2779
Adam Jacksonb3295302010-07-16 14:46:28 -04002780 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002781 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
2782
Dave Airlieeb1f8e42010-05-07 06:42:51 +00002783 connector->polled = DRM_CONNECTOR_POLL_HPD;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02002784 connector->interlace_allowed = true;
2785 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08002786
Daniel Vetter66a92782012-07-12 20:08:18 +02002787 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
2788 ironlake_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08002789
Chris Wilsondf0e9242010-09-09 16:20:55 +01002790 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002791 drm_sysfs_connector_add(connector);
2792
Paulo Zanoniaffa9352012-11-23 15:30:39 -02002793 if (HAS_DDI(dev))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02002794 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
2795 else
2796 intel_connector->get_hw_state = intel_connector_get_hw_state;
2797
Paulo Zanoni9ed35ab2013-02-18 19:00:25 -03002798 intel_dp->aux_ch_ctl_reg = intel_dp->output_reg + 0x10;
2799 if (HAS_DDI(dev)) {
2800 switch (intel_dig_port->port) {
2801 case PORT_A:
2802 intel_dp->aux_ch_ctl_reg = DPA_AUX_CH_CTL;
2803 break;
2804 case PORT_B:
2805 intel_dp->aux_ch_ctl_reg = PCH_DPB_AUX_CH_CTL;
2806 break;
2807 case PORT_C:
2808 intel_dp->aux_ch_ctl_reg = PCH_DPC_AUX_CH_CTL;
2809 break;
2810 case PORT_D:
2811 intel_dp->aux_ch_ctl_reg = PCH_DPD_AUX_CH_CTL;
2812 break;
2813 default:
2814 BUG();
2815 }
2816 }
Daniel Vettere8cb4552012-07-01 13:05:48 +02002817
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002818 /* Set up the DDC bus. */
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03002819 switch (port) {
2820 case PORT_A:
Egbert Eich1d843f92013-02-25 12:06:49 -05002821 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03002822 name = "DPDDC-A";
2823 break;
2824 case PORT_B:
Egbert Eich1d843f92013-02-25 12:06:49 -05002825 intel_encoder->hpd_pin = HPD_PORT_B;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03002826 name = "DPDDC-B";
2827 break;
2828 case PORT_C:
Egbert Eich1d843f92013-02-25 12:06:49 -05002829 intel_encoder->hpd_pin = HPD_PORT_C;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03002830 name = "DPDDC-C";
2831 break;
2832 case PORT_D:
Egbert Eich1d843f92013-02-25 12:06:49 -05002833 intel_encoder->hpd_pin = HPD_PORT_D;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03002834 name = "DPDDC-D";
2835 break;
2836 default:
Damien Lespiauad1c0b12013-03-07 15:30:28 +00002837 BUG();
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002838 }
2839
Daniel Vetter67a54562012-10-20 20:57:45 +02002840 if (is_edp(intel_dp))
Jani Nikulaf30d26e2013-01-16 10:53:40 +02002841 intel_dp_init_panel_power_sequencer(dev, intel_dp, &power_seq);
Dave Airliec1f05262012-08-30 11:06:18 +10002842
2843 intel_dp_i2c_init(intel_dp, intel_connector, name);
2844
Daniel Vetter67a54562012-10-20 20:57:45 +02002845 /* Cache DPCD and EDID for edp. */
Dave Airliec1f05262012-08-30 11:06:18 +10002846 if (is_edp(intel_dp)) {
2847 bool ret;
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002848 struct drm_display_mode *scan;
Dave Airliec1f05262012-08-30 11:06:18 +10002849 struct edid *edid;
Jesse Barnes5d613502011-01-24 17:10:54 -08002850
2851 ironlake_edp_panel_vdd_on(intel_dp);
Keith Packard59f3e272011-07-25 20:01:56 -07002852 ret = intel_dp_get_dpcd(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002853 ironlake_edp_panel_vdd_off(intel_dp, false);
Keith Packard99ea7122011-11-01 19:57:50 -07002854
Keith Packard59f3e272011-07-25 20:01:56 -07002855 if (ret) {
Jesse Barnes7183dc22011-07-07 11:10:58 -07002856 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
2857 dev_priv->no_aux_handshake =
2858 intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
Jesse Barnes89667382010-10-07 16:01:21 -07002859 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
2860 } else {
Chris Wilson3d3dc142011-02-12 10:33:12 +00002861 /* if this fails, presume the device is a ghost */
Takashi Iwai48898b02011-03-18 09:06:49 +00002862 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Paulo Zanonifa90ece2012-10-26 19:05:44 -02002863 intel_dp_encoder_destroy(&intel_encoder->base);
2864 intel_dp_destroy(connector);
Chris Wilson3d3dc142011-02-12 10:33:12 +00002865 return;
Jesse Barnes89667382010-10-07 16:01:21 -07002866 }
Jesse Barnes89667382010-10-07 16:01:21 -07002867
Jani Nikulaf30d26e2013-01-16 10:53:40 +02002868 /* We now know it's not a ghost, init power sequence regs. */
2869 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp,
2870 &power_seq);
2871
Jesse Barnesd6f24d02012-06-14 15:28:33 -04002872 ironlake_edp_panel_vdd_on(intel_dp);
2873 edid = drm_get_edid(connector, &intel_dp->adapter);
2874 if (edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03002875 if (drm_add_edid_modes(connector, edid)) {
2876 drm_mode_connector_update_edid_property(connector, edid);
2877 drm_edid_to_eld(connector, edid);
2878 } else {
2879 kfree(edid);
2880 edid = ERR_PTR(-EINVAL);
2881 }
2882 } else {
2883 edid = ERR_PTR(-ENOENT);
Jesse Barnesd6f24d02012-06-14 15:28:33 -04002884 }
Jani Nikula9cd300e2012-10-19 14:51:52 +03002885 intel_connector->edid = edid;
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002886
2887 /* prefer fixed mode from EDID if available */
2888 list_for_each_entry(scan, &connector->probed_modes, head) {
2889 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
2890 fixed_mode = drm_mode_duplicate(dev, scan);
2891 break;
2892 }
2893 }
2894
2895 /* fallback to VBT if available for eDP */
2896 if (!fixed_mode && dev_priv->lfp_lvds_vbt_mode) {
2897 fixed_mode = drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);
2898 if (fixed_mode)
2899 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
2900 }
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002901
Jesse Barnesd6f24d02012-06-14 15:28:33 -04002902 ironlake_edp_panel_vdd_off(intel_dp, false);
2903 }
Keith Packard552fb0b2011-09-28 16:31:53 -07002904
Jesse Barnes4d926462010-10-07 16:01:07 -07002905 if (is_edp(intel_dp)) {
Jani Nikuladd06f902012-10-19 14:51:50 +03002906 intel_panel_init(&intel_connector->panel, fixed_mode);
Jani Nikula0657b6b2012-10-19 14:51:46 +03002907 intel_panel_setup_backlight(connector);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002908 }
2909
Chris Wilsonf6849602010-09-19 09:29:33 +01002910 intel_dp_add_properties(intel_dp, connector);
2911
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002912 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
2913 * 0xd. Failure to do so will result in spurious interrupts being
2914 * generated on the port when a cable is not attached.
2915 */
2916 if (IS_G4X(dev) && !IS_GM45(dev)) {
2917 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
2918 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
2919 }
2920}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02002921
2922void
2923intel_dp_init(struct drm_device *dev, int output_reg, enum port port)
2924{
2925 struct intel_digital_port *intel_dig_port;
2926 struct intel_encoder *intel_encoder;
2927 struct drm_encoder *encoder;
2928 struct intel_connector *intel_connector;
2929
2930 intel_dig_port = kzalloc(sizeof(struct intel_digital_port), GFP_KERNEL);
2931 if (!intel_dig_port)
2932 return;
2933
2934 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
2935 if (!intel_connector) {
2936 kfree(intel_dig_port);
2937 return;
2938 }
2939
2940 intel_encoder = &intel_dig_port->base;
2941 encoder = &intel_encoder->base;
2942
2943 drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
2944 DRM_MODE_ENCODER_TMDS);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002945 drm_encoder_helper_add(&intel_encoder->base, &intel_dp_helper_funcs);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02002946
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002947 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002948 intel_encoder->enable = intel_enable_dp;
2949 intel_encoder->pre_enable = intel_pre_enable_dp;
2950 intel_encoder->disable = intel_disable_dp;
2951 intel_encoder->post_disable = intel_post_disable_dp;
2952 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02002953
Paulo Zanoni174edf12012-10-26 19:05:50 -02002954 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02002955 intel_dig_port->dp.output_reg = output_reg;
2956
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002957 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02002958 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
2959 intel_encoder->cloneable = false;
2960 intel_encoder->hot_plug = intel_dp_hot_plug;
2961
2962 intel_dp_init_connector(intel_dig_port, intel_connector);
2963}