blob: 623b50c46bbcf7f46c7ae340e9dd1705de436f8b [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
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080041struct dp_link_dpll {
42 int link_bw;
43 struct dpll dpll;
44};
45
46static const struct dp_link_dpll gen4_dpll[] = {
47 { DP_LINK_BW_1_62,
48 { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
49 { DP_LINK_BW_2_7,
50 { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
51};
52
53static const struct dp_link_dpll pch_dpll[] = {
54 { DP_LINK_BW_1_62,
55 { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
56 { DP_LINK_BW_2_7,
57 { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
58};
59
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080060static const struct dp_link_dpll vlv_dpll[] = {
61 { DP_LINK_BW_1_62,
Chon Ming Lee58f6e632013-09-25 15:47:51 +080062 { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } },
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080063 { DP_LINK_BW_2_7,
64 { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } }
65};
66
Jesse Barnescfcb0fc2010-10-07 16:01:06 -070067/**
68 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
69 * @intel_dp: DP struct
70 *
71 * If a CPU or PCH DP output is attached to an eDP panel, this function
72 * will return true, and false otherwise.
73 */
74static bool is_edp(struct intel_dp *intel_dp)
75{
Paulo Zanonida63a9f2012-10-26 19:05:46 -020076 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
77
78 return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -070079}
80
Imre Deak68b4d822013-05-08 13:14:06 +030081static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp)
Jesse Barnescfcb0fc2010-10-07 16:01:06 -070082{
Imre Deak68b4d822013-05-08 13:14:06 +030083 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
84
85 return intel_dig_port->base.base.dev;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -070086}
87
Chris Wilsondf0e9242010-09-09 16:20:55 +010088static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
89{
Paulo Zanonifa90ece2012-10-26 19:05:44 -020090 return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
Chris Wilsondf0e9242010-09-09 16:20:55 +010091}
92
Chris Wilsonea5b2132010-08-04 13:50:23 +010093static void intel_dp_link_down(struct intel_dp *intel_dp);
Jani Nikulaadddaaf2014-03-14 16:51:13 +020094static bool _edp_panel_vdd_on(struct intel_dp *intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +010095static void edp_panel_vdd_on(struct intel_dp *intel_dp);
96static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
Keith Packarda4fc5ed2009-04-07 16:16:42 -070097
98static int
Chris Wilsonea5b2132010-08-04 13:50:23 +010099intel_dp_max_link_bw(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700100{
Jesse Barnes7183dc22011-07-07 11:10:58 -0700101 int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
Todd Previte06ea66b2014-01-20 10:19:39 -0700102 struct drm_device *dev = intel_dp->attached_connector->base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700103
104 switch (max_link_bw) {
105 case DP_LINK_BW_1_62:
106 case DP_LINK_BW_2_7:
107 break;
Imre Deakd4eead52013-07-09 17:05:26 +0300108 case DP_LINK_BW_5_4: /* 1.2 capable displays may advertise higher bw */
Todd Previte06ea66b2014-01-20 10:19:39 -0700109 if ((IS_HASWELL(dev) || INTEL_INFO(dev)->gen >= 8) &&
110 intel_dp->dpcd[DP_DPCD_REV] >= 0x12)
111 max_link_bw = DP_LINK_BW_5_4;
112 else
113 max_link_bw = DP_LINK_BW_2_7;
Imre Deakd4eead52013-07-09 17:05:26 +0300114 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700115 default:
Imre Deakd4eead52013-07-09 17:05:26 +0300116 WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
117 max_link_bw);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700118 max_link_bw = DP_LINK_BW_1_62;
119 break;
120 }
121 return max_link_bw;
122}
123
Adam Jacksoncd9dde42011-10-14 12:43:49 -0400124/*
125 * The units on the numbers in the next two are... bizarre. Examples will
126 * make it clearer; this one parallels an example in the eDP spec.
127 *
128 * intel_dp_max_data_rate for one lane of 2.7GHz evaluates as:
129 *
130 * 270000 * 1 * 8 / 10 == 216000
131 *
132 * The actual data capacity of that configuration is 2.16Gbit/s, so the
133 * units are decakilobits. ->clock in a drm_display_mode is in kilohertz -
134 * or equivalently, kilopixels per second - so for 1680x1050R it'd be
135 * 119000. At 18bpp that's 2142000 kilobits per second.
136 *
137 * Thus the strange-looking division by 10 in intel_dp_link_required, to
138 * get the result in decakilobits instead of kilobits.
139 */
140
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700141static int
Keith Packardc8982612012-01-25 08:16:25 -0800142intel_dp_link_required(int pixel_clock, int bpp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700143{
Adam Jacksoncd9dde42011-10-14 12:43:49 -0400144 return (pixel_clock * bpp + 9) / 10;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700145}
146
147static int
Dave Airliefe27d532010-06-30 11:46:17 +1000148intel_dp_max_data_rate(int max_link_clock, int max_lanes)
149{
150 return (max_link_clock * max_lanes * 8) / 10;
151}
152
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000153static enum drm_mode_status
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700154intel_dp_mode_valid(struct drm_connector *connector,
155 struct drm_display_mode *mode)
156{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100157 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300158 struct intel_connector *intel_connector = to_intel_connector(connector);
159 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Daniel Vetter36008362013-03-27 00:44:59 +0100160 int target_clock = mode->clock;
161 int max_rate, mode_rate, max_lanes, max_link_clock;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700162
Jani Nikuladd06f902012-10-19 14:51:50 +0300163 if (is_edp(intel_dp) && fixed_mode) {
164 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100165 return MODE_PANEL;
166
Jani Nikuladd06f902012-10-19 14:51:50 +0300167 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100168 return MODE_PANEL;
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200169
170 target_clock = fixed_mode->clock;
Zhao Yakui7de56f42010-07-19 09:43:14 +0100171 }
172
Daniel Vetter36008362013-03-27 00:44:59 +0100173 max_link_clock = drm_dp_bw_code_to_link_rate(intel_dp_max_link_bw(intel_dp));
174 max_lanes = drm_dp_max_lane_count(intel_dp->dpcd);
175
176 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
177 mode_rate = intel_dp_link_required(target_clock, 18);
178
179 if (mode_rate > max_rate)
Daniel Vetterc4867932012-04-10 10:42:36 +0200180 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700181
182 if (mode->clock < 10000)
183 return MODE_CLOCK_LOW;
184
Daniel Vetter0af78a22012-05-23 11:30:55 +0200185 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
186 return MODE_H_ILLEGAL;
187
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700188 return MODE_OK;
189}
190
191static uint32_t
192pack_aux(uint8_t *src, int src_bytes)
193{
194 int i;
195 uint32_t v = 0;
196
197 if (src_bytes > 4)
198 src_bytes = 4;
199 for (i = 0; i < src_bytes; i++)
200 v |= ((uint32_t) src[i]) << ((3-i) * 8);
201 return v;
202}
203
204static void
205unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
206{
207 int i;
208 if (dst_bytes > 4)
209 dst_bytes = 4;
210 for (i = 0; i < dst_bytes; i++)
211 dst[i] = src >> ((3-i) * 8);
212}
213
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700214/* hrawclock is 1/4 the FSB frequency */
215static int
216intel_hrawclk(struct drm_device *dev)
217{
218 struct drm_i915_private *dev_priv = dev->dev_private;
219 uint32_t clkcfg;
220
Vijay Purushothaman9473c8f2012-09-27 19:13:01 +0530221 /* There is no CLKCFG reg in Valleyview. VLV hrawclk is 200 MHz */
222 if (IS_VALLEYVIEW(dev))
223 return 200;
224
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700225 clkcfg = I915_READ(CLKCFG);
226 switch (clkcfg & CLKCFG_FSB_MASK) {
227 case CLKCFG_FSB_400:
228 return 100;
229 case CLKCFG_FSB_533:
230 return 133;
231 case CLKCFG_FSB_667:
232 return 166;
233 case CLKCFG_FSB_800:
234 return 200;
235 case CLKCFG_FSB_1067:
236 return 266;
237 case CLKCFG_FSB_1333:
238 return 333;
239 /* these two are just a guess; one of them might be right */
240 case CLKCFG_FSB_1600:
241 case CLKCFG_FSB_1600_ALT:
242 return 400;
243 default:
244 return 133;
245 }
246}
247
Jani Nikulabf13e812013-09-06 07:40:05 +0300248static void
249intel_dp_init_panel_power_sequencer(struct drm_device *dev,
250 struct intel_dp *intel_dp,
251 struct edp_power_seq *out);
252static void
253intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
254 struct intel_dp *intel_dp,
255 struct edp_power_seq *out);
256
257static enum pipe
258vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
259{
260 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
261 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
262 struct drm_device *dev = intel_dig_port->base.base.dev;
263 struct drm_i915_private *dev_priv = dev->dev_private;
264 enum port port = intel_dig_port->port;
265 enum pipe pipe;
266
267 /* modeset should have pipe */
268 if (crtc)
269 return to_intel_crtc(crtc)->pipe;
270
271 /* init time, try to find a pipe with this port selected */
272 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
273 u32 port_sel = I915_READ(VLV_PIPE_PP_ON_DELAYS(pipe)) &
274 PANEL_PORT_SELECT_MASK;
275 if (port_sel == PANEL_PORT_SELECT_DPB_VLV && port == PORT_B)
276 return pipe;
277 if (port_sel == PANEL_PORT_SELECT_DPC_VLV && port == PORT_C)
278 return pipe;
279 }
280
281 /* shrug */
282 return PIPE_A;
283}
284
285static u32 _pp_ctrl_reg(struct intel_dp *intel_dp)
286{
287 struct drm_device *dev = intel_dp_to_dev(intel_dp);
288
289 if (HAS_PCH_SPLIT(dev))
290 return PCH_PP_CONTROL;
291 else
292 return VLV_PIPE_PP_CONTROL(vlv_power_sequencer_pipe(intel_dp));
293}
294
295static u32 _pp_stat_reg(struct intel_dp *intel_dp)
296{
297 struct drm_device *dev = intel_dp_to_dev(intel_dp);
298
299 if (HAS_PCH_SPLIT(dev))
300 return PCH_PP_STATUS;
301 else
302 return VLV_PIPE_PP_STATUS(vlv_power_sequencer_pipe(intel_dp));
303}
304
Daniel Vetter4be73782014-01-17 14:39:48 +0100305static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700306{
Paulo Zanoni30add222012-10-26 19:05:45 -0200307 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packardebf33b12011-09-29 15:53:27 -0700308 struct drm_i915_private *dev_priv = dev->dev_private;
309
Jani Nikulabf13e812013-09-06 07:40:05 +0300310 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700311}
312
Daniel Vetter4be73782014-01-17 14:39:48 +0100313static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700314{
Paulo Zanoni30add222012-10-26 19:05:45 -0200315 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packardebf33b12011-09-29 15:53:27 -0700316 struct drm_i915_private *dev_priv = dev->dev_private;
317
Jani Nikulabf13e812013-09-06 07:40:05 +0300318 return (I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700319}
320
Keith Packard9b984da2011-09-19 13:54:47 -0700321static void
322intel_dp_check_edp(struct intel_dp *intel_dp)
323{
Paulo Zanoni30add222012-10-26 19:05:45 -0200324 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packard9b984da2011-09-19 13:54:47 -0700325 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packardebf33b12011-09-29 15:53:27 -0700326
Keith Packard9b984da2011-09-19 13:54:47 -0700327 if (!is_edp(intel_dp))
328 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700329
Daniel Vetter4be73782014-01-17 14:39:48 +0100330 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700331 WARN(1, "eDP powered off while attempting aux channel communication.\n");
332 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300333 I915_READ(_pp_stat_reg(intel_dp)),
334 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700335 }
336}
337
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100338static uint32_t
339intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
340{
341 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
342 struct drm_device *dev = intel_dig_port->base.base.dev;
343 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni9ed35ab2013-02-18 19:00:25 -0300344 uint32_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100345 uint32_t status;
346 bool done;
347
Daniel Vetteref04f002012-12-01 21:03:59 +0100348#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100349 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300350 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300351 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100352 else
353 done = wait_for_atomic(C, 10) == 0;
354 if (!done)
355 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
356 has_aux_irq);
357#undef C
358
359 return status;
360}
361
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000362static uint32_t i9xx_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
363{
364 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
365 struct drm_device *dev = intel_dig_port->base.base.dev;
366
367 /*
368 * The clock divider is based off the hrawclk, and would like to run at
369 * 2MHz. So, take the hrawclk value and divide by 2 and use that
370 */
371 return index ? 0 : intel_hrawclk(dev) / 2;
372}
373
374static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
375{
376 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
377 struct drm_device *dev = intel_dig_port->base.base.dev;
378
379 if (index)
380 return 0;
381
382 if (intel_dig_port->port == PORT_A) {
383 if (IS_GEN6(dev) || IS_GEN7(dev))
384 return 200; /* SNB & IVB eDP input clock at 400Mhz */
385 else
386 return 225; /* eDP input clock at 450Mhz */
387 } else {
388 return DIV_ROUND_UP(intel_pch_rawclk(dev), 2);
389 }
390}
391
392static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300393{
394 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
395 struct drm_device *dev = intel_dig_port->base.base.dev;
396 struct drm_i915_private *dev_priv = dev->dev_private;
397
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000398 if (intel_dig_port->port == PORT_A) {
Chris Wilsonbc866252013-07-21 16:00:03 +0100399 if (index)
400 return 0;
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000401 return DIV_ROUND_CLOSEST(intel_ddi_get_cdclk_freq(dev_priv), 2000);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300402 } else if (dev_priv->pch_id == INTEL_PCH_LPT_DEVICE_ID_TYPE) {
403 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100404 switch (index) {
405 case 0: return 63;
406 case 1: return 72;
407 default: return 0;
408 }
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000409 } else {
Chris Wilsonbc866252013-07-21 16:00:03 +0100410 return index ? 0 : DIV_ROUND_UP(intel_pch_rawclk(dev), 2);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300411 }
412}
413
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000414static uint32_t vlv_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
415{
416 return index ? 0 : 100;
417}
418
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000419static uint32_t i9xx_get_aux_send_ctl(struct intel_dp *intel_dp,
420 bool has_aux_irq,
421 int send_bytes,
422 uint32_t aux_clock_divider)
423{
424 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
425 struct drm_device *dev = intel_dig_port->base.base.dev;
426 uint32_t precharge, timeout;
427
428 if (IS_GEN6(dev))
429 precharge = 3;
430 else
431 precharge = 5;
432
433 if (IS_BROADWELL(dev) && intel_dp->aux_ch_ctl_reg == DPA_AUX_CH_CTL)
434 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
435 else
436 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
437
438 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +0000439 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000440 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000441 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000442 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +0000443 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000444 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
445 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000446 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000447}
448
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700449static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100450intel_dp_aux_ch(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700451 uint8_t *send, int send_bytes,
452 uint8_t *recv, int recv_size)
453{
Paulo Zanoni174edf12012-10-26 19:05:50 -0200454 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
455 struct drm_device *dev = intel_dig_port->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700456 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni9ed35ab2013-02-18 19:00:25 -0300457 uint32_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700458 uint32_t ch_data = ch_ctl + 4;
Chris Wilsonbc866252013-07-21 16:00:03 +0100459 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100460 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700461 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000462 int try, clock = 0;
Daniel Vetter4e6b7882014-02-07 16:33:20 +0100463 bool has_aux_irq = HAS_AUX_IRQ(dev);
Jani Nikula884f19e2014-03-14 16:51:14 +0200464 bool vdd;
465
466 vdd = _edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100467
468 /* dp aux is extremely sensitive to irq latency, hence request the
469 * lowest possible wakeup latency and so prevent the cpu from going into
470 * deep sleep states.
471 */
472 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700473
Keith Packard9b984da2011-09-19 13:54:47 -0700474 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +0800475
Paulo Zanonic67a4702013-08-19 13:18:09 -0300476 intel_aux_display_runtime_get(dev_priv);
477
Jesse Barnes11bee432011-08-01 15:02:20 -0700478 /* Try to wait for any previous AUX channel activity */
479 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +0100480 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -0700481 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
482 break;
483 msleep(1);
484 }
485
486 if (try == 3) {
487 WARN(1, "dp_aux_ch not started status 0x%08x\n",
488 I915_READ(ch_ctl));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100489 ret = -EBUSY;
490 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100491 }
492
Paulo Zanoni46a5ae92013-09-17 11:14:10 -0300493 /* Only 5 data registers! */
494 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
495 ret = -E2BIG;
496 goto out;
497 }
498
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000499 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +0000500 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
501 has_aux_irq,
502 send_bytes,
503 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000504
Chris Wilsonbc866252013-07-21 16:00:03 +0100505 /* Must try at least 3 times according to DP spec */
506 for (try = 0; try < 5; try++) {
507 /* Load the send data into the aux channel data registers */
508 for (i = 0; i < send_bytes; i += 4)
509 I915_WRITE(ch_data + i,
510 pack_aux(send + i, send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -0400511
Chris Wilsonbc866252013-07-21 16:00:03 +0100512 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000513 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100514
Chris Wilsonbc866252013-07-21 16:00:03 +0100515 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -0400516
Chris Wilsonbc866252013-07-21 16:00:03 +0100517 /* Clear done status and any errors */
518 I915_WRITE(ch_ctl,
519 status |
520 DP_AUX_CH_CTL_DONE |
521 DP_AUX_CH_CTL_TIME_OUT_ERROR |
522 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -0400523
Chris Wilsonbc866252013-07-21 16:00:03 +0100524 if (status & (DP_AUX_CH_CTL_TIME_OUT_ERROR |
525 DP_AUX_CH_CTL_RECEIVE_ERROR))
526 continue;
527 if (status & DP_AUX_CH_CTL_DONE)
528 break;
529 }
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100530 if (status & DP_AUX_CH_CTL_DONE)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700531 break;
532 }
533
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700534 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700535 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100536 ret = -EBUSY;
537 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700538 }
539
540 /* Check for timeout or receive error.
541 * Timeouts occur when the sink is not connected
542 */
Keith Packarda5b3da52009-06-11 22:30:32 -0700543 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700544 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100545 ret = -EIO;
546 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -0700547 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700548
549 /* Timeouts occur when the device isn't connected, so they're
550 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -0700551 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Zhao Yakui28c97732009-10-09 11:39:41 +0800552 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100553 ret = -ETIMEDOUT;
554 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700555 }
556
557 /* Unload any bytes sent back from the other side */
558 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
559 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700560 if (recv_bytes > recv_size)
561 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -0400562
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100563 for (i = 0; i < recv_bytes; i += 4)
564 unpack_aux(I915_READ(ch_data + i),
565 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700566
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100567 ret = recv_bytes;
568out:
569 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
Paulo Zanonic67a4702013-08-19 13:18:09 -0300570 intel_aux_display_runtime_put(dev_priv);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100571
Jani Nikula884f19e2014-03-14 16:51:14 +0200572 if (vdd)
573 edp_panel_vdd_off(intel_dp, false);
574
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100575 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700576}
577
Jani Nikula9d1a1032014-03-14 16:51:15 +0200578#define HEADER_SIZE 4
579static ssize_t
580intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700581{
Jani Nikula9d1a1032014-03-14 16:51:15 +0200582 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
583 uint8_t txbuf[20], rxbuf[20];
584 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700585 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700586
Jani Nikula9d1a1032014-03-14 16:51:15 +0200587 txbuf[0] = msg->request << 4;
588 txbuf[1] = msg->address >> 8;
589 txbuf[2] = msg->address & 0xff;
590 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -0300591
Jani Nikula9d1a1032014-03-14 16:51:15 +0200592 switch (msg->request & ~DP_AUX_I2C_MOT) {
593 case DP_AUX_NATIVE_WRITE:
594 case DP_AUX_I2C_WRITE:
595 txsize = HEADER_SIZE + msg->size;
596 rxsize = 1;
Jani Nikulaf51a44b2014-02-11 11:52:05 +0200597
Jani Nikula9d1a1032014-03-14 16:51:15 +0200598 if (WARN_ON(txsize > 20))
599 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700600
Jani Nikula9d1a1032014-03-14 16:51:15 +0200601 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700602
Jani Nikula9d1a1032014-03-14 16:51:15 +0200603 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
604 if (ret > 0) {
605 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700606
Jani Nikula9d1a1032014-03-14 16:51:15 +0200607 /* Return payload size. */
608 ret = msg->size;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700609 }
Jani Nikula9d1a1032014-03-14 16:51:15 +0200610 break;
611
612 case DP_AUX_NATIVE_READ:
613 case DP_AUX_I2C_READ:
614 txsize = HEADER_SIZE;
615 rxsize = msg->size + 1;
616
617 if (WARN_ON(rxsize > 20))
618 return -E2BIG;
619
620 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
621 if (ret > 0) {
622 msg->reply = rxbuf[0] >> 4;
623 /*
624 * Assume happy day, and copy the data. The caller is
625 * expected to check msg->reply before touching it.
626 *
627 * Return payload size.
628 */
629 ret--;
630 memcpy(msg->buffer, rxbuf + 1, ret);
631 }
632 break;
633
634 default:
635 ret = -EINVAL;
636 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700637 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +0200638
Jani Nikula9d1a1032014-03-14 16:51:15 +0200639 return ret;
640}
641
642static void
643intel_dp_aux_init(struct intel_dp *intel_dp, struct intel_connector *connector)
644{
645 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jani Nikula33ad6622014-03-14 16:51:16 +0200646 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
647 enum port port = intel_dig_port->port;
648
649 switch (port) {
650 case PORT_A:
651 intel_dp->aux_ch_ctl_reg = DPA_AUX_CH_CTL;
652 break;
653 case PORT_B:
654 intel_dp->aux_ch_ctl_reg = PCH_DPB_AUX_CH_CTL;
655 break;
656 case PORT_C:
657 intel_dp->aux_ch_ctl_reg = PCH_DPC_AUX_CH_CTL;
658 break;
659 case PORT_D:
660 intel_dp->aux_ch_ctl_reg = PCH_DPD_AUX_CH_CTL;
661 break;
662 default:
663 BUG();
664 }
665
666 if (!HAS_DDI(dev))
667 intel_dp->aux_ch_ctl_reg = intel_dp->output_reg + 0x10;
Jani Nikula9d1a1032014-03-14 16:51:15 +0200668
669 intel_dp->aux.dev = dev->dev;
670 intel_dp->aux.transfer = intel_dp_aux_transfer;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700671}
672
673static int
Dave Airlieab2c0672009-12-04 10:55:24 +1000674intel_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode,
675 uint8_t write_byte, uint8_t *read_byte)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700676{
Dave Airlieab2c0672009-12-04 10:55:24 +1000677 struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100678 struct intel_dp *intel_dp = container_of(adapter,
679 struct intel_dp,
680 adapter);
Dave Airlieab2c0672009-12-04 10:55:24 +1000681 uint16_t address = algo_data->address;
682 uint8_t msg[5];
683 uint8_t reply[2];
David Flynn8316f332010-12-08 16:10:21 +0000684 unsigned retry;
Dave Airlieab2c0672009-12-04 10:55:24 +1000685 int msg_bytes;
686 int reply_bytes;
687 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700688
Dave Airlieab2c0672009-12-04 10:55:24 +1000689 /* Set up the command byte */
690 if (mode & MODE_I2C_READ)
Thierry Reding6b27f7f2013-12-16 17:01:29 +0100691 msg[0] = DP_AUX_I2C_READ << 4;
Dave Airlieab2c0672009-12-04 10:55:24 +1000692 else
Thierry Reding6b27f7f2013-12-16 17:01:29 +0100693 msg[0] = DP_AUX_I2C_WRITE << 4;
Dave Airlieab2c0672009-12-04 10:55:24 +1000694
695 if (!(mode & MODE_I2C_STOP))
Thierry Reding6b27f7f2013-12-16 17:01:29 +0100696 msg[0] |= DP_AUX_I2C_MOT << 4;
Dave Airlieab2c0672009-12-04 10:55:24 +1000697
698 msg[1] = address >> 8;
699 msg[2] = address;
700
701 switch (mode) {
702 case MODE_I2C_WRITE:
703 msg[3] = 0;
704 msg[4] = write_byte;
705 msg_bytes = 5;
706 reply_bytes = 1;
707 break;
708 case MODE_I2C_READ:
709 msg[3] = 0;
710 msg_bytes = 4;
711 reply_bytes = 2;
712 break;
713 default:
714 msg_bytes = 3;
715 reply_bytes = 1;
716 break;
717 }
718
Jani Nikula58c67ce2013-09-20 16:42:14 +0300719 /*
720 * DP1.2 sections 2.7.7.1.5.6.1 and 2.7.7.1.6.6.1: A DP Source device is
721 * required to retry at least seven times upon receiving AUX_DEFER
722 * before giving up the AUX transaction.
723 */
724 for (retry = 0; retry < 7; retry++) {
David Flynn8316f332010-12-08 16:10:21 +0000725 ret = intel_dp_aux_ch(intel_dp,
726 msg, msg_bytes,
727 reply, reply_bytes);
Dave Airlieab2c0672009-12-04 10:55:24 +1000728 if (ret < 0) {
Dave Airlie3ff99162009-12-08 14:03:47 +1000729 DRM_DEBUG_KMS("aux_ch failed %d\n", ret);
Paulo Zanoni8a5e6aeb2013-10-30 19:50:26 -0200730 goto out;
Dave Airlieab2c0672009-12-04 10:55:24 +1000731 }
David Flynn8316f332010-12-08 16:10:21 +0000732
Thierry Reding6b27f7f2013-12-16 17:01:29 +0100733 switch ((reply[0] >> 4) & DP_AUX_NATIVE_REPLY_MASK) {
734 case DP_AUX_NATIVE_REPLY_ACK:
David Flynn8316f332010-12-08 16:10:21 +0000735 /* I2C-over-AUX Reply field is only valid
736 * when paired with AUX ACK.
737 */
738 break;
Thierry Reding6b27f7f2013-12-16 17:01:29 +0100739 case DP_AUX_NATIVE_REPLY_NACK:
David Flynn8316f332010-12-08 16:10:21 +0000740 DRM_DEBUG_KMS("aux_ch native nack\n");
Paulo Zanoni8a5e6aeb2013-10-30 19:50:26 -0200741 ret = -EREMOTEIO;
742 goto out;
Thierry Reding6b27f7f2013-12-16 17:01:29 +0100743 case DP_AUX_NATIVE_REPLY_DEFER:
Jani Nikula8d16f252013-09-20 16:42:15 +0300744 /*
745 * For now, just give more slack to branch devices. We
746 * could check the DPCD for I2C bit rate capabilities,
747 * and if available, adjust the interval. We could also
748 * be more careful with DP-to-Legacy adapters where a
749 * long legacy cable may force very low I2C bit rates.
750 */
751 if (intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
752 DP_DWN_STRM_PORT_PRESENT)
753 usleep_range(500, 600);
754 else
755 usleep_range(300, 400);
David Flynn8316f332010-12-08 16:10:21 +0000756 continue;
757 default:
758 DRM_ERROR("aux_ch invalid native reply 0x%02x\n",
759 reply[0]);
Paulo Zanoni8a5e6aeb2013-10-30 19:50:26 -0200760 ret = -EREMOTEIO;
761 goto out;
David Flynn8316f332010-12-08 16:10:21 +0000762 }
763
Thierry Reding6b27f7f2013-12-16 17:01:29 +0100764 switch ((reply[0] >> 4) & DP_AUX_I2C_REPLY_MASK) {
765 case DP_AUX_I2C_REPLY_ACK:
Dave Airlieab2c0672009-12-04 10:55:24 +1000766 if (mode == MODE_I2C_READ) {
767 *read_byte = reply[1];
768 }
Paulo Zanoni8a5e6aeb2013-10-30 19:50:26 -0200769 ret = reply_bytes - 1;
770 goto out;
Thierry Reding6b27f7f2013-12-16 17:01:29 +0100771 case DP_AUX_I2C_REPLY_NACK:
David Flynn8316f332010-12-08 16:10:21 +0000772 DRM_DEBUG_KMS("aux_i2c nack\n");
Paulo Zanoni8a5e6aeb2013-10-30 19:50:26 -0200773 ret = -EREMOTEIO;
774 goto out;
Thierry Reding6b27f7f2013-12-16 17:01:29 +0100775 case DP_AUX_I2C_REPLY_DEFER:
David Flynn8316f332010-12-08 16:10:21 +0000776 DRM_DEBUG_KMS("aux_i2c defer\n");
Dave Airlieab2c0672009-12-04 10:55:24 +1000777 udelay(100);
778 break;
779 default:
David Flynn8316f332010-12-08 16:10:21 +0000780 DRM_ERROR("aux_i2c invalid reply 0x%02x\n", reply[0]);
Paulo Zanoni8a5e6aeb2013-10-30 19:50:26 -0200781 ret = -EREMOTEIO;
782 goto out;
Dave Airlieab2c0672009-12-04 10:55:24 +1000783 }
784 }
David Flynn8316f332010-12-08 16:10:21 +0000785
786 DRM_ERROR("too many retries, giving up\n");
Paulo Zanoni8a5e6aeb2013-10-30 19:50:26 -0200787 ret = -EREMOTEIO;
788
789out:
Paulo Zanoni8a5e6aeb2013-10-30 19:50:26 -0200790 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700791}
792
Imre Deak80f65de2014-02-11 17:12:49 +0200793static void
794intel_dp_connector_unregister(struct intel_connector *intel_connector)
795{
796 struct intel_dp *intel_dp = intel_attached_dp(&intel_connector->base);
797
798 sysfs_remove_link(&intel_connector->base.kdev->kobj,
799 intel_dp->adapter.dev.kobj.name);
800 intel_connector_unregister(intel_connector);
801}
802
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700803static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100804intel_dp_i2c_init(struct intel_dp *intel_dp,
Zhenyu Wang55f78c42010-03-29 16:13:57 +0800805 struct intel_connector *intel_connector, const char *name)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700806{
Keith Packard0b5c5412011-09-28 16:41:05 -0700807 int ret;
808
Zhenyu Wangd54e9d22009-10-19 15:43:51 +0800809 DRM_DEBUG_KMS("i2c_init %s\n", name);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100810 intel_dp->algo.running = false;
811 intel_dp->algo.address = 0;
812 intel_dp->algo.aux_ch = intel_dp_i2c_aux_ch;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700813
Akshay Joshi0206e352011-08-16 15:34:10 -0400814 memset(&intel_dp->adapter, '\0', sizeof(intel_dp->adapter));
Chris Wilsonea5b2132010-08-04 13:50:23 +0100815 intel_dp->adapter.owner = THIS_MODULE;
816 intel_dp->adapter.class = I2C_CLASS_DDC;
Akshay Joshi0206e352011-08-16 15:34:10 -0400817 strncpy(intel_dp->adapter.name, name, sizeof(intel_dp->adapter.name) - 1);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100818 intel_dp->adapter.name[sizeof(intel_dp->adapter.name) - 1] = '\0';
819 intel_dp->adapter.algo_data = &intel_dp->algo;
Imre Deak80f65de2014-02-11 17:12:49 +0200820 intel_dp->adapter.dev.parent = intel_connector->base.dev->dev;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100821
Keith Packard0b5c5412011-09-28 16:41:05 -0700822 ret = i2c_dp_aux_add_bus(&intel_dp->adapter);
Imre Deak80f65de2014-02-11 17:12:49 +0200823 if (ret < 0)
824 return ret;
825
826 ret = sysfs_create_link(&intel_connector->base.kdev->kobj,
827 &intel_dp->adapter.dev.kobj,
828 intel_dp->adapter.dev.kobj.name);
829
830 if (ret < 0)
831 i2c_del_adapter(&intel_dp->adapter);
832
Keith Packard0b5c5412011-09-28 16:41:05 -0700833 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700834}
835
Daniel Vetterc6bb3532013-04-19 11:14:33 +0200836static void
837intel_dp_set_clock(struct intel_encoder *encoder,
838 struct intel_crtc_config *pipe_config, int link_bw)
839{
840 struct drm_device *dev = encoder->base.dev;
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +0800841 const struct dp_link_dpll *divisor = NULL;
842 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +0200843
844 if (IS_G4X(dev)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +0800845 divisor = gen4_dpll;
846 count = ARRAY_SIZE(gen4_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +0200847 } else if (IS_HASWELL(dev)) {
848 /* Haswell has special-purpose DP DDI clocks. */
849 } else if (HAS_PCH_SPLIT(dev)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +0800850 divisor = pch_dpll;
851 count = ARRAY_SIZE(pch_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +0200852 } else if (IS_VALLEYVIEW(dev)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +0800853 divisor = vlv_dpll;
854 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +0200855 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +0800856
857 if (divisor && count) {
858 for (i = 0; i < count; i++) {
859 if (link_bw == divisor[i].link_bw) {
860 pipe_config->dpll = divisor[i].dpll;
861 pipe_config->clock_set = true;
862 break;
863 }
864 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +0200865 }
866}
867
Paulo Zanoni00c09d72012-10-26 19:05:52 -0200868bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100869intel_dp_compute_config(struct intel_encoder *encoder,
870 struct intel_crtc_config *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700871{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100872 struct drm_device *dev = encoder->base.dev;
Daniel Vetter36008362013-03-27 00:44:59 +0100873 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100874 struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100875 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +0300876 enum port port = dp_to_dig_port(intel_dp)->port;
Jesse Barnes2dd24552013-04-25 12:55:01 -0700877 struct intel_crtc *intel_crtc = encoder->new_crtc;
Jani Nikuladd06f902012-10-19 14:51:50 +0300878 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700879 int lane_count, clock;
Daniel Vetter397fe152012-10-22 22:56:43 +0200880 int max_lane_count = drm_dp_max_lane_count(intel_dp->dpcd);
Todd Previte06ea66b2014-01-20 10:19:39 -0700881 /* Conveniently, the link BW constants become indices with a shift...*/
882 int max_clock = intel_dp_max_link_bw(intel_dp) >> 3;
Daniel Vetter083f9562012-04-20 20:23:49 +0200883 int bpp, mode_rate;
Todd Previte06ea66b2014-01-20 10:19:39 -0700884 static int bws[] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7, DP_LINK_BW_5_4 };
Daniel Vetterff9a6752013-06-01 17:16:21 +0200885 int link_avail, link_clock;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700886
Imre Deakbc7d38a2013-05-16 14:40:36 +0300887 if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100888 pipe_config->has_pch_encoder = true;
889
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200890 pipe_config->has_dp_encoder = true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700891
Jani Nikuladd06f902012-10-19 14:51:50 +0300892 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
893 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
894 adjusted_mode);
Jesse Barnes2dd24552013-04-25 12:55:01 -0700895 if (!HAS_PCH_SPLIT(dev))
896 intel_gmch_panel_fitting(intel_crtc, pipe_config,
897 intel_connector->panel.fitting_mode);
898 else
Jesse Barnesb074cec2013-04-25 12:55:02 -0700899 intel_pch_panel_fitting(intel_crtc, pipe_config,
900 intel_connector->panel.fitting_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +0100901 }
902
Daniel Vettercb1793c2012-06-04 18:39:21 +0200903 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +0200904 return false;
905
Daniel Vetter083f9562012-04-20 20:23:49 +0200906 DRM_DEBUG_KMS("DP link computation with max lane count %i "
907 "max bw %02x pixel clock %iKHz\n",
Damien Lespiau241bfc32013-09-25 16:45:37 +0100908 max_lane_count, bws[max_clock],
909 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +0200910
Daniel Vetter36008362013-03-27 00:44:59 +0100911 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
912 * bpc in between. */
Daniel Vetter3e7ca982013-06-01 19:45:56 +0200913 bpp = pipe_config->pipe_bpp;
Jani Nikula6da7f102013-10-16 17:06:17 +0300914 if (is_edp(intel_dp) && dev_priv->vbt.edp_bpp &&
915 dev_priv->vbt.edp_bpp < bpp) {
Imre Deak79842112013-07-18 17:44:13 +0300916 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
917 dev_priv->vbt.edp_bpp);
Jani Nikula6da7f102013-10-16 17:06:17 +0300918 bpp = dev_priv->vbt.edp_bpp;
Imre Deak79842112013-07-18 17:44:13 +0300919 }
Daniel Vetter657445f2013-05-04 10:09:18 +0200920
Daniel Vetter36008362013-03-27 00:44:59 +0100921 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +0100922 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
923 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +0200924
Daniel Vetter38aecea2014-03-03 11:18:10 +0100925 for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) {
926 for (clock = 0; clock <= max_clock; clock++) {
Daniel Vetter36008362013-03-27 00:44:59 +0100927 link_clock = drm_dp_bw_code_to_link_rate(bws[clock]);
928 link_avail = intel_dp_max_data_rate(link_clock,
929 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200930
Daniel Vetter36008362013-03-27 00:44:59 +0100931 if (mode_rate <= link_avail) {
932 goto found;
933 }
934 }
935 }
936 }
937
938 return false;
939
940found:
Ville Syrjälä55bc60d2013-01-17 16:31:29 +0200941 if (intel_dp->color_range_auto) {
942 /*
943 * See:
944 * CEA-861-E - 5.1 Default Encoding Parameters
945 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
946 */
Thierry Reding18316c82012-12-20 15:41:44 +0100947 if (bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1)
Ville Syrjälä55bc60d2013-01-17 16:31:29 +0200948 intel_dp->color_range = DP_COLOR_RANGE_16_235;
949 else
950 intel_dp->color_range = 0;
951 }
952
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200953 if (intel_dp->color_range)
Daniel Vetter50f3b012013-03-27 00:44:56 +0100954 pipe_config->limited_color_range = true;
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200955
Daniel Vetter36008362013-03-27 00:44:59 +0100956 intel_dp->link_bw = bws[clock];
957 intel_dp->lane_count = lane_count;
Daniel Vetter657445f2013-05-04 10:09:18 +0200958 pipe_config->pipe_bpp = bpp;
Daniel Vetterff9a6752013-06-01 17:16:21 +0200959 pipe_config->port_clock = drm_dp_bw_code_to_link_rate(intel_dp->link_bw);
Daniel Vetterc4867932012-04-10 10:42:36 +0200960
Daniel Vetter36008362013-03-27 00:44:59 +0100961 DRM_DEBUG_KMS("DP link bw %02x lane count %d clock %d bpp %d\n",
962 intel_dp->link_bw, intel_dp->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +0200963 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +0100964 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
965 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700966
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200967 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +0100968 adjusted_mode->crtc_clock,
969 pipe_config->port_clock,
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200970 &pipe_config->dp_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700971
Daniel Vetterc6bb3532013-04-19 11:14:33 +0200972 intel_dp_set_clock(encoder, pipe_config, intel_dp->link_bw);
973
Daniel Vetter36008362013-03-27 00:44:59 +0100974 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700975}
976
Daniel Vetter7c62a162013-06-01 17:16:20 +0200977static void ironlake_set_pll_cpu_edp(struct intel_dp *intel_dp)
Daniel Vetterea9b6002012-11-29 15:59:31 +0100978{
Daniel Vetter7c62a162013-06-01 17:16:20 +0200979 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
980 struct intel_crtc *crtc = to_intel_crtc(dig_port->base.base.crtc);
981 struct drm_device *dev = crtc->base.dev;
Daniel Vetterea9b6002012-11-29 15:59:31 +0100982 struct drm_i915_private *dev_priv = dev->dev_private;
983 u32 dpa_ctl;
984
Daniel Vetterff9a6752013-06-01 17:16:21 +0200985 DRM_DEBUG_KMS("eDP PLL enable for clock %d\n", crtc->config.port_clock);
Daniel Vetterea9b6002012-11-29 15:59:31 +0100986 dpa_ctl = I915_READ(DP_A);
987 dpa_ctl &= ~DP_PLL_FREQ_MASK;
988
Daniel Vetterff9a6752013-06-01 17:16:21 +0200989 if (crtc->config.port_clock == 162000) {
Daniel Vetter1ce17032012-11-29 15:59:32 +0100990 /* For a long time we've carried around a ILK-DevA w/a for the
991 * 160MHz clock. If we're really unlucky, it's still required.
992 */
993 DRM_DEBUG_KMS("160MHz cpu eDP clock, might need ilk devA w/a\n");
Daniel Vetterea9b6002012-11-29 15:59:31 +0100994 dpa_ctl |= DP_PLL_FREQ_160MHZ;
Daniel Vetter7c62a162013-06-01 17:16:20 +0200995 intel_dp->DP |= DP_PLL_FREQ_160MHZ;
Daniel Vetterea9b6002012-11-29 15:59:31 +0100996 } else {
997 dpa_ctl |= DP_PLL_FREQ_270MHZ;
Daniel Vetter7c62a162013-06-01 17:16:20 +0200998 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
Daniel Vetterea9b6002012-11-29 15:59:31 +0100999 }
Daniel Vetter1ce17032012-11-29 15:59:32 +01001000
Daniel Vetterea9b6002012-11-29 15:59:31 +01001001 I915_WRITE(DP_A, dpa_ctl);
1002
1003 POSTING_READ(DP_A);
1004 udelay(500);
1005}
1006
Daniel Vetterb934223d2013-07-21 21:37:05 +02001007static void intel_dp_mode_set(struct intel_encoder *encoder)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001008{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001009 struct drm_device *dev = encoder->base.dev;
Keith Packard417e8222011-11-01 19:54:11 -07001010 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001011 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001012 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001013 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
1014 struct drm_display_mode *adjusted_mode = &crtc->config.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001015
Keith Packard417e8222011-11-01 19:54:11 -07001016 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001017 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001018 *
1019 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001020 * SNB CPU
1021 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001022 * CPT PCH
1023 *
1024 * IBX PCH and CPU are the same for almost everything,
1025 * except that the CPU DP PLL is configured in this
1026 * register
1027 *
1028 * CPT PCH is quite different, having many bits moved
1029 * to the TRANS_DP_CTL register instead. That
1030 * configuration happens (oddly) in ironlake_pch_enable
1031 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001032
Keith Packard417e8222011-11-01 19:54:11 -07001033 /* Preserve the BIOS-computed detected bit. This is
1034 * supposed to be read-only.
1035 */
1036 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001037
Keith Packard417e8222011-11-01 19:54:11 -07001038 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001039 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Daniel Vetter17aa6be2013-04-30 14:01:40 +02001040 intel_dp->DP |= DP_PORT_WIDTH(intel_dp->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001041
Wu Fengguange0dac652011-09-05 14:25:34 +08001042 if (intel_dp->has_audio) {
1043 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Daniel Vetter7c62a162013-06-01 17:16:20 +02001044 pipe_name(crtc->pipe));
Chris Wilsonea5b2132010-08-04 13:50:23 +01001045 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001046 intel_write_eld(&encoder->base, adjusted_mode);
Wu Fengguange0dac652011-09-05 14:25:34 +08001047 }
Paulo Zanoni247d89f2012-10-15 15:51:33 -03001048
Keith Packard417e8222011-11-01 19:54:11 -07001049 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001050
Imre Deakbc7d38a2013-05-16 14:40:36 +03001051 if (port == PORT_A && IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001052 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1053 intel_dp->DP |= DP_SYNC_HS_HIGH;
1054 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1055 intel_dp->DP |= DP_SYNC_VS_HIGH;
1056 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1057
Jani Nikula6aba5b62013-10-04 15:08:10 +03001058 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001059 intel_dp->DP |= DP_ENHANCED_FRAMING;
1060
Daniel Vetter7c62a162013-06-01 17:16:20 +02001061 intel_dp->DP |= crtc->pipe << 29;
Imre Deakbc7d38a2013-05-16 14:40:36 +03001062 } else if (!HAS_PCH_CPT(dev) || port == PORT_A) {
Jesse Barnesb2634012013-03-28 09:55:40 -07001063 if (!HAS_PCH_SPLIT(dev) && !IS_VALLEYVIEW(dev))
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001064 intel_dp->DP |= intel_dp->color_range;
Keith Packard417e8222011-11-01 19:54:11 -07001065
1066 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1067 intel_dp->DP |= DP_SYNC_HS_HIGH;
1068 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1069 intel_dp->DP |= DP_SYNC_VS_HIGH;
1070 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1071
Jani Nikula6aba5b62013-10-04 15:08:10 +03001072 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001073 intel_dp->DP |= DP_ENHANCED_FRAMING;
1074
Daniel Vetter7c62a162013-06-01 17:16:20 +02001075 if (crtc->pipe == 1)
Keith Packard417e8222011-11-01 19:54:11 -07001076 intel_dp->DP |= DP_PIPEB_SELECT;
Keith Packard417e8222011-11-01 19:54:11 -07001077 } else {
1078 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001079 }
Daniel Vetterea9b6002012-11-29 15:59:31 +01001080
Imre Deakbc7d38a2013-05-16 14:40:36 +03001081 if (port == PORT_A && !IS_VALLEYVIEW(dev))
Daniel Vetter7c62a162013-06-01 17:16:20 +02001082 ironlake_set_pll_cpu_edp(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001083}
1084
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001085#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1086#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001087
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001088#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1089#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001090
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001091#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1092#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001093
Daniel Vetter4be73782014-01-17 14:39:48 +01001094static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001095 u32 mask,
1096 u32 value)
1097{
Paulo Zanoni30add222012-10-26 19:05:45 -02001098 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001099 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes453c5422013-03-28 09:55:41 -07001100 u32 pp_stat_reg, pp_ctrl_reg;
1101
Jani Nikulabf13e812013-09-06 07:40:05 +03001102 pp_stat_reg = _pp_stat_reg(intel_dp);
1103 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001104
1105 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001106 mask, value,
1107 I915_READ(pp_stat_reg),
1108 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001109
Jesse Barnes453c5422013-03-28 09:55:41 -07001110 if (_wait_for((I915_READ(pp_stat_reg) & mask) == value, 5000, 10)) {
Keith Packard99ea7122011-11-01 19:57:50 -07001111 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001112 I915_READ(pp_stat_reg),
1113 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001114 }
Chris Wilson54c136d2013-12-02 09:57:16 +00001115
1116 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001117}
1118
Daniel Vetter4be73782014-01-17 14:39:48 +01001119static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001120{
1121 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001122 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001123}
1124
Daniel Vetter4be73782014-01-17 14:39:48 +01001125static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001126{
Keith Packardbd943152011-09-18 23:09:52 -07001127 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001128 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001129}
Keith Packardbd943152011-09-18 23:09:52 -07001130
Daniel Vetter4be73782014-01-17 14:39:48 +01001131static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001132{
1133 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001134
1135 /* When we disable the VDD override bit last we have to do the manual
1136 * wait. */
1137 wait_remaining_ms_from_jiffies(intel_dp->last_power_cycle,
1138 intel_dp->panel_power_cycle_delay);
1139
Daniel Vetter4be73782014-01-17 14:39:48 +01001140 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001141}
Keith Packardbd943152011-09-18 23:09:52 -07001142
Daniel Vetter4be73782014-01-17 14:39:48 +01001143static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001144{
1145 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1146 intel_dp->backlight_on_delay);
1147}
1148
Daniel Vetter4be73782014-01-17 14:39:48 +01001149static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001150{
1151 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
1152 intel_dp->backlight_off_delay);
1153}
Keith Packard99ea7122011-11-01 19:57:50 -07001154
Keith Packard832dd3c2011-11-01 19:34:06 -07001155/* Read the current pp_control value, unlocking the register if it
1156 * is locked
1157 */
1158
Jesse Barnes453c5422013-03-28 09:55:41 -07001159static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07001160{
Jesse Barnes453c5422013-03-28 09:55:41 -07001161 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1162 struct drm_i915_private *dev_priv = dev->dev_private;
1163 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07001164
Jani Nikulabf13e812013-09-06 07:40:05 +03001165 control = I915_READ(_pp_ctrl_reg(intel_dp));
Keith Packard832dd3c2011-11-01 19:34:06 -07001166 control &= ~PANEL_UNLOCK_MASK;
1167 control |= PANEL_UNLOCK_REGS;
1168 return control;
Keith Packardbd943152011-09-18 23:09:52 -07001169}
1170
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001171static bool _edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001172{
Paulo Zanoni30add222012-10-26 19:05:45 -02001173 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001174 struct drm_i915_private *dev_priv = dev->dev_private;
1175 u32 pp;
Jesse Barnes453c5422013-03-28 09:55:41 -07001176 u32 pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001177 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08001178
Keith Packard97af61f572011-09-28 16:23:51 -07001179 if (!is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001180 return false;
Keith Packardbd943152011-09-18 23:09:52 -07001181
1182 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07001183
Daniel Vetter4be73782014-01-17 14:39:48 +01001184 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001185 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02001186
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02001187 intel_runtime_pm_get(dev_priv);
1188
Paulo Zanonib0665d52013-10-30 19:50:27 -02001189 DRM_DEBUG_KMS("Turning eDP VDD on\n");
Keith Packardbd943152011-09-18 23:09:52 -07001190
Daniel Vetter4be73782014-01-17 14:39:48 +01001191 if (!edp_have_panel_power(intel_dp))
1192 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001193
Jesse Barnes453c5422013-03-28 09:55:41 -07001194 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001195 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07001196
Jani Nikulabf13e812013-09-06 07:40:05 +03001197 pp_stat_reg = _pp_stat_reg(intel_dp);
1198 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001199
1200 I915_WRITE(pp_ctrl_reg, pp);
1201 POSTING_READ(pp_ctrl_reg);
1202 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1203 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07001204 /*
1205 * If the panel wasn't on, delay before accessing aux channel
1206 */
Daniel Vetter4be73782014-01-17 14:39:48 +01001207 if (!edp_have_panel_power(intel_dp)) {
Keith Packardbd943152011-09-18 23:09:52 -07001208 DRM_DEBUG_KMS("eDP was not running\n");
Keith Packardf01eca22011-09-28 16:48:10 -07001209 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07001210 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001211
1212 return need_to_disable;
1213}
1214
1215static void edp_panel_vdd_on(struct intel_dp *intel_dp)
1216{
1217 if (is_edp(intel_dp)) {
1218 bool vdd = _edp_panel_vdd_on(intel_dp);
1219
1220 WARN(!vdd, "eDP VDD already requested on\n");
1221 }
Jesse Barnes5d613502011-01-24 17:10:54 -08001222}
1223
Daniel Vetter4be73782014-01-17 14:39:48 +01001224static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001225{
Paulo Zanoni30add222012-10-26 19:05:45 -02001226 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001227 struct drm_i915_private *dev_priv = dev->dev_private;
1228 u32 pp;
Jesse Barnes453c5422013-03-28 09:55:41 -07001229 u32 pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08001230
Daniel Vettera0e99e62012-12-02 01:05:46 +01001231 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
1232
Daniel Vetter4be73782014-01-17 14:39:48 +01001233 if (!intel_dp->want_panel_vdd && edp_have_panel_vdd(intel_dp)) {
Paulo Zanonib0665d52013-10-30 19:50:27 -02001234 DRM_DEBUG_KMS("Turning eDP VDD off\n");
1235
Jesse Barnes453c5422013-03-28 09:55:41 -07001236 pp = ironlake_get_pp_control(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07001237 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07001238
Paulo Zanoni9f08ef52013-10-31 12:44:21 -02001239 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
1240 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001241
1242 I915_WRITE(pp_ctrl_reg, pp);
1243 POSTING_READ(pp_ctrl_reg);
Jesse Barnes5d613502011-01-24 17:10:54 -08001244
Keith Packardbd943152011-09-18 23:09:52 -07001245 /* Make sure sequencer is idle before allowing subsequent activity */
Jesse Barnes453c5422013-03-28 09:55:41 -07001246 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1247 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanoni90791a52013-12-06 17:32:42 -02001248
1249 if ((pp & POWER_TARGET_ON) == 0)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001250 intel_dp->last_power_cycle = jiffies;
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02001251
1252 intel_runtime_pm_put(dev_priv);
Keith Packardbd943152011-09-18 23:09:52 -07001253 }
1254}
1255
Daniel Vetter4be73782014-01-17 14:39:48 +01001256static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07001257{
1258 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
1259 struct intel_dp, panel_vdd_work);
Paulo Zanoni30add222012-10-26 19:05:45 -02001260 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07001261
Keith Packard627f7672011-10-31 11:30:10 -07001262 mutex_lock(&dev->mode_config.mutex);
Daniel Vetter4be73782014-01-17 14:39:48 +01001263 edp_panel_vdd_off_sync(intel_dp);
Keith Packard627f7672011-10-31 11:30:10 -07001264 mutex_unlock(&dev->mode_config.mutex);
Keith Packardbd943152011-09-18 23:09:52 -07001265}
1266
Daniel Vetter4be73782014-01-17 14:39:48 +01001267static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07001268{
Keith Packard97af61f572011-09-28 16:23:51 -07001269 if (!is_edp(intel_dp))
1270 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08001271
Keith Packardbd943152011-09-18 23:09:52 -07001272 WARN(!intel_dp->want_panel_vdd, "eDP VDD not forced on");
Keith Packardf2e8b182011-11-01 20:01:35 -07001273
Keith Packardbd943152011-09-18 23:09:52 -07001274 intel_dp->want_panel_vdd = false;
1275
1276 if (sync) {
Daniel Vetter4be73782014-01-17 14:39:48 +01001277 edp_panel_vdd_off_sync(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07001278 } else {
1279 /*
1280 * Queue the timer to fire a long
1281 * time from now (relative to the power down delay)
1282 * to keep the panel power up across a sequence of operations
1283 */
1284 schedule_delayed_work(&intel_dp->panel_vdd_work,
1285 msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5));
1286 }
Jesse Barnes5d613502011-01-24 17:10:54 -08001287}
1288
Daniel Vetter4be73782014-01-17 14:39:48 +01001289void intel_edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07001290{
Paulo Zanoni30add222012-10-26 19:05:45 -02001291 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07001292 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packard99ea7122011-11-01 19:57:50 -07001293 u32 pp;
Jesse Barnes453c5422013-03-28 09:55:41 -07001294 u32 pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07001295
Keith Packard97af61f572011-09-28 16:23:51 -07001296 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07001297 return;
Keith Packard99ea7122011-11-01 19:57:50 -07001298
1299 DRM_DEBUG_KMS("Turn eDP power on\n");
1300
Daniel Vetter4be73782014-01-17 14:39:48 +01001301 if (edp_have_panel_power(intel_dp)) {
Keith Packard99ea7122011-11-01 19:57:50 -07001302 DRM_DEBUG_KMS("eDP power already on\n");
Keith Packard7d639f32011-09-29 16:05:34 -07001303 return;
Keith Packard99ea7122011-11-01 19:57:50 -07001304 }
Jesse Barnes9934c132010-07-22 13:18:19 -07001305
Daniel Vetter4be73782014-01-17 14:39:48 +01001306 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001307
Jani Nikulabf13e812013-09-06 07:40:05 +03001308 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001309 pp = ironlake_get_pp_control(intel_dp);
Keith Packard05ce1a42011-09-29 16:33:01 -07001310 if (IS_GEN5(dev)) {
1311 /* ILK workaround: disable reset around power sequence */
1312 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03001313 I915_WRITE(pp_ctrl_reg, pp);
1314 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07001315 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001316
Keith Packard1c0ae802011-09-19 13:59:29 -07001317 pp |= POWER_TARGET_ON;
Keith Packard99ea7122011-11-01 19:57:50 -07001318 if (!IS_GEN5(dev))
1319 pp |= PANEL_POWER_RESET;
1320
Jesse Barnes453c5422013-03-28 09:55:41 -07001321 I915_WRITE(pp_ctrl_reg, pp);
1322 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07001323
Daniel Vetter4be73782014-01-17 14:39:48 +01001324 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001325 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07001326
Keith Packard05ce1a42011-09-29 16:33:01 -07001327 if (IS_GEN5(dev)) {
1328 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03001329 I915_WRITE(pp_ctrl_reg, pp);
1330 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07001331 }
Jesse Barnes9934c132010-07-22 13:18:19 -07001332}
1333
Daniel Vetter4be73782014-01-17 14:39:48 +01001334void intel_edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07001335{
Paulo Zanoni30add222012-10-26 19:05:45 -02001336 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07001337 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packard99ea7122011-11-01 19:57:50 -07001338 u32 pp;
Jesse Barnes453c5422013-03-28 09:55:41 -07001339 u32 pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07001340
Keith Packard97af61f572011-09-28 16:23:51 -07001341 if (!is_edp(intel_dp))
1342 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001343
Keith Packard99ea7122011-11-01 19:57:50 -07001344 DRM_DEBUG_KMS("Turn eDP power off\n");
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001345
Daniel Vetter4be73782014-01-17 14:39:48 +01001346 edp_wait_backlight_off(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001347
Jesse Barnes453c5422013-03-28 09:55:41 -07001348 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02001349 /* We need to switch off panel power _and_ force vdd, for otherwise some
1350 * panels get very unhappy and cease to work. */
Patrik Jakobssonb3064152014-03-04 00:42:44 +01001351 pp &= ~(POWER_TARGET_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
1352 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07001353
Jani Nikulabf13e812013-09-06 07:40:05 +03001354 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001355
1356 I915_WRITE(pp_ctrl_reg, pp);
1357 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07001358
Paulo Zanonidce56b32013-12-19 14:29:40 -02001359 intel_dp->last_power_cycle = jiffies;
Daniel Vetter4be73782014-01-17 14:39:48 +01001360 wait_panel_off(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07001361}
1362
Daniel Vetter4be73782014-01-17 14:39:48 +01001363void intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001364{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001365 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1366 struct drm_device *dev = intel_dig_port->base.base.dev;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001367 struct drm_i915_private *dev_priv = dev->dev_private;
1368 u32 pp;
Jesse Barnes453c5422013-03-28 09:55:41 -07001369 u32 pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001370
Keith Packardf01eca22011-09-28 16:48:10 -07001371 if (!is_edp(intel_dp))
1372 return;
1373
Zhao Yakui28c97732009-10-09 11:39:41 +08001374 DRM_DEBUG_KMS("\n");
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001375 /*
1376 * If we enable the backlight right away following a panel power
1377 * on, we may see slight flicker as the panel syncs with the eDP
1378 * link. So delay a bit to make sure the image is solid before
1379 * allowing it to appear.
1380 */
Daniel Vetter4be73782014-01-17 14:39:48 +01001381 wait_backlight_on(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001382 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001383 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07001384
Jani Nikulabf13e812013-09-06 07:40:05 +03001385 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001386
1387 I915_WRITE(pp_ctrl_reg, pp);
1388 POSTING_READ(pp_ctrl_reg);
Daniel Vetter035aa3d2012-10-20 20:57:42 +02001389
Jesse Barnes752aa882013-10-31 18:55:49 +02001390 intel_panel_enable_backlight(intel_dp->attached_connector);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001391}
1392
Daniel Vetter4be73782014-01-17 14:39:48 +01001393void intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001394{
Paulo Zanoni30add222012-10-26 19:05:45 -02001395 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001396 struct drm_i915_private *dev_priv = dev->dev_private;
1397 u32 pp;
Jesse Barnes453c5422013-03-28 09:55:41 -07001398 u32 pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001399
Keith Packardf01eca22011-09-28 16:48:10 -07001400 if (!is_edp(intel_dp))
1401 return;
1402
Jesse Barnes752aa882013-10-31 18:55:49 +02001403 intel_panel_disable_backlight(intel_dp->attached_connector);
Daniel Vetter035aa3d2012-10-20 20:57:42 +02001404
Zhao Yakui28c97732009-10-09 11:39:41 +08001405 DRM_DEBUG_KMS("\n");
Jesse Barnes453c5422013-03-28 09:55:41 -07001406 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001407 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07001408
Jani Nikulabf13e812013-09-06 07:40:05 +03001409 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001410
1411 I915_WRITE(pp_ctrl_reg, pp);
1412 POSTING_READ(pp_ctrl_reg);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001413 intel_dp->last_backlight_off = jiffies;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001414}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001415
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001416static void ironlake_edp_pll_on(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07001417{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001418 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1419 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
1420 struct drm_device *dev = crtc->dev;
Jesse Barnesd240f202010-08-13 15:43:26 -07001421 struct drm_i915_private *dev_priv = dev->dev_private;
1422 u32 dpa_ctl;
1423
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001424 assert_pipe_disabled(dev_priv,
1425 to_intel_crtc(crtc)->pipe);
1426
Jesse Barnesd240f202010-08-13 15:43:26 -07001427 DRM_DEBUG_KMS("\n");
1428 dpa_ctl = I915_READ(DP_A);
Daniel Vetter07679352012-09-06 22:15:42 +02001429 WARN(dpa_ctl & DP_PLL_ENABLE, "dp pll on, should be off\n");
1430 WARN(dpa_ctl & DP_PORT_EN, "dp port still on, should be off\n");
1431
1432 /* We don't adjust intel_dp->DP while tearing down the link, to
1433 * facilitate link retraining (e.g. after hotplug). Hence clear all
1434 * enable bits here to ensure that we don't enable too much. */
1435 intel_dp->DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
1436 intel_dp->DP |= DP_PLL_ENABLE;
1437 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07001438 POSTING_READ(DP_A);
1439 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07001440}
1441
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001442static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07001443{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001444 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1445 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
1446 struct drm_device *dev = crtc->dev;
Jesse Barnesd240f202010-08-13 15:43:26 -07001447 struct drm_i915_private *dev_priv = dev->dev_private;
1448 u32 dpa_ctl;
1449
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001450 assert_pipe_disabled(dev_priv,
1451 to_intel_crtc(crtc)->pipe);
1452
Jesse Barnesd240f202010-08-13 15:43:26 -07001453 dpa_ctl = I915_READ(DP_A);
Daniel Vetter07679352012-09-06 22:15:42 +02001454 WARN((dpa_ctl & DP_PLL_ENABLE) == 0,
1455 "dp pll off, should be on\n");
1456 WARN(dpa_ctl & DP_PORT_EN, "dp port still on, should be off\n");
1457
1458 /* We can't rely on the value tracked for the DP register in
1459 * intel_dp->DP because link_down must not change that (otherwise link
1460 * re-training will fail. */
Jesse Barnes298b0b32010-10-07 16:01:24 -07001461 dpa_ctl &= ~DP_PLL_ENABLE;
Jesse Barnesd240f202010-08-13 15:43:26 -07001462 I915_WRITE(DP_A, dpa_ctl);
Chris Wilson1af5fa12010-09-08 21:07:28 +01001463 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07001464 udelay(200);
1465}
1466
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001467/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03001468void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001469{
1470 int ret, i;
1471
1472 /* Should have a valid DPCD by this point */
1473 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
1474 return;
1475
1476 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02001477 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
1478 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001479 if (ret != 1)
1480 DRM_DEBUG_DRIVER("failed to write sink power state\n");
1481 } else {
1482 /*
1483 * When turning on, we need to retry for 1ms to give the sink
1484 * time to wake up.
1485 */
1486 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02001487 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
1488 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001489 if (ret == 1)
1490 break;
1491 msleep(1);
1492 }
1493 }
1494}
1495
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001496static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
1497 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07001498{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001499 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001500 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001501 struct drm_device *dev = encoder->base.dev;
1502 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deak6d129be2014-03-05 16:20:54 +02001503 enum intel_display_power_domain power_domain;
1504 u32 tmp;
1505
1506 power_domain = intel_display_port_power_domain(encoder);
1507 if (!intel_display_power_enabled(dev_priv, power_domain))
1508 return false;
1509
1510 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07001511
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001512 if (!(tmp & DP_PORT_EN))
1513 return false;
1514
Imre Deakbc7d38a2013-05-16 14:40:36 +03001515 if (port == PORT_A && IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001516 *pipe = PORT_TO_PIPE_CPT(tmp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001517 } else if (!HAS_PCH_CPT(dev) || port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001518 *pipe = PORT_TO_PIPE(tmp);
1519 } else {
1520 u32 trans_sel;
1521 u32 trans_dp;
1522 int i;
1523
1524 switch (intel_dp->output_reg) {
1525 case PCH_DP_B:
1526 trans_sel = TRANS_DP_PORT_SEL_B;
1527 break;
1528 case PCH_DP_C:
1529 trans_sel = TRANS_DP_PORT_SEL_C;
1530 break;
1531 case PCH_DP_D:
1532 trans_sel = TRANS_DP_PORT_SEL_D;
1533 break;
1534 default:
1535 return true;
1536 }
1537
1538 for_each_pipe(i) {
1539 trans_dp = I915_READ(TRANS_DP_CTL(i));
1540 if ((trans_dp & TRANS_DP_PORT_SEL_MASK) == trans_sel) {
1541 *pipe = i;
1542 return true;
1543 }
1544 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001545
Daniel Vetter4a0833e2012-10-26 10:58:11 +02001546 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
1547 intel_dp->output_reg);
1548 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001549
1550 return true;
1551}
1552
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001553static void intel_dp_get_config(struct intel_encoder *encoder,
1554 struct intel_crtc_config *pipe_config)
1555{
1556 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001557 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08001558 struct drm_device *dev = encoder->base.dev;
1559 struct drm_i915_private *dev_priv = dev->dev_private;
1560 enum port port = dp_to_dig_port(intel_dp)->port;
1561 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjälä18442d02013-09-13 16:00:08 +03001562 int dotclock;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001563
Xiong Zhang63000ef2013-06-28 12:59:06 +08001564 if ((port == PORT_A) || !HAS_PCH_CPT(dev)) {
1565 tmp = I915_READ(intel_dp->output_reg);
1566 if (tmp & DP_SYNC_HS_HIGH)
1567 flags |= DRM_MODE_FLAG_PHSYNC;
1568 else
1569 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001570
Xiong Zhang63000ef2013-06-28 12:59:06 +08001571 if (tmp & DP_SYNC_VS_HIGH)
1572 flags |= DRM_MODE_FLAG_PVSYNC;
1573 else
1574 flags |= DRM_MODE_FLAG_NVSYNC;
1575 } else {
1576 tmp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1577 if (tmp & TRANS_DP_HSYNC_ACTIVE_HIGH)
1578 flags |= DRM_MODE_FLAG_PHSYNC;
1579 else
1580 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001581
Xiong Zhang63000ef2013-06-28 12:59:06 +08001582 if (tmp & TRANS_DP_VSYNC_ACTIVE_HIGH)
1583 flags |= DRM_MODE_FLAG_PVSYNC;
1584 else
1585 flags |= DRM_MODE_FLAG_NVSYNC;
1586 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001587
1588 pipe_config->adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03001589
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03001590 pipe_config->has_dp_encoder = true;
1591
1592 intel_dp_get_m_n(crtc, pipe_config);
1593
Ville Syrjälä18442d02013-09-13 16:00:08 +03001594 if (port == PORT_A) {
Jesse Barnesf1f644d2013-06-27 00:39:25 +03001595 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_160MHZ)
1596 pipe_config->port_clock = 162000;
1597 else
1598 pipe_config->port_clock = 270000;
1599 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03001600
1601 dotclock = intel_dotclock_calculate(pipe_config->port_clock,
1602 &pipe_config->dp_m_n);
1603
1604 if (HAS_PCH_SPLIT(dev_priv->dev) && port != PORT_A)
1605 ironlake_check_encoder_dotclock(pipe_config, dotclock);
1606
Damien Lespiau241bfc32013-09-25 16:45:37 +01001607 pipe_config->adjusted_mode.crtc_clock = dotclock;
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01001608
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03001609 if (is_edp(intel_dp) && dev_priv->vbt.edp_bpp &&
1610 pipe_config->pipe_bpp > dev_priv->vbt.edp_bpp) {
1611 /*
1612 * This is a big fat ugly hack.
1613 *
1614 * Some machines in UEFI boot mode provide us a VBT that has 18
1615 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
1616 * unknown we fail to light up. Yet the same BIOS boots up with
1617 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
1618 * max, not what it tells us to use.
1619 *
1620 * Note: This will still be broken if the eDP panel is not lit
1621 * up by the BIOS, and thus we can't get the mode at module
1622 * load.
1623 */
1624 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
1625 pipe_config->pipe_bpp, dev_priv->vbt.edp_bpp);
1626 dev_priv->vbt.edp_bpp = pipe_config->pipe_bpp;
1627 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001628}
1629
Rodrigo Vivia031d702013-10-03 16:15:06 -03001630static bool is_edp_psr(struct drm_device *dev)
Shobhit Kumar2293bb52013-07-11 18:44:56 -03001631{
Rodrigo Vivia031d702013-10-03 16:15:06 -03001632 struct drm_i915_private *dev_priv = dev->dev_private;
1633
1634 return dev_priv->psr.sink_support;
Shobhit Kumar2293bb52013-07-11 18:44:56 -03001635}
1636
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001637static bool intel_edp_is_psr_enabled(struct drm_device *dev)
1638{
1639 struct drm_i915_private *dev_priv = dev->dev_private;
1640
Ben Widawsky18b59922013-09-20 09:35:30 -07001641 if (!HAS_PSR(dev))
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001642 return false;
1643
Ben Widawsky18b59922013-09-20 09:35:30 -07001644 return I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001645}
1646
1647static void intel_edp_psr_write_vsc(struct intel_dp *intel_dp,
1648 struct edp_vsc_psr *vsc_psr)
1649{
1650 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1651 struct drm_device *dev = dig_port->base.base.dev;
1652 struct drm_i915_private *dev_priv = dev->dev_private;
1653 struct intel_crtc *crtc = to_intel_crtc(dig_port->base.base.crtc);
1654 u32 ctl_reg = HSW_TVIDEO_DIP_CTL(crtc->config.cpu_transcoder);
1655 u32 data_reg = HSW_TVIDEO_DIP_VSC_DATA(crtc->config.cpu_transcoder);
1656 uint32_t *data = (uint32_t *) vsc_psr;
1657 unsigned int i;
1658
1659 /* As per BSPec (Pipe Video Data Island Packet), we need to disable
1660 the video DIP being updated before program video DIP data buffer
1661 registers for DIP being updated. */
1662 I915_WRITE(ctl_reg, 0);
1663 POSTING_READ(ctl_reg);
1664
1665 for (i = 0; i < VIDEO_DIP_VSC_DATA_SIZE; i += 4) {
1666 if (i < sizeof(struct edp_vsc_psr))
1667 I915_WRITE(data_reg + i, *data++);
1668 else
1669 I915_WRITE(data_reg + i, 0);
1670 }
1671
1672 I915_WRITE(ctl_reg, VIDEO_DIP_ENABLE_VSC_HSW);
1673 POSTING_READ(ctl_reg);
1674}
1675
1676static void intel_edp_psr_setup(struct intel_dp *intel_dp)
1677{
1678 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1679 struct drm_i915_private *dev_priv = dev->dev_private;
1680 struct edp_vsc_psr psr_vsc;
1681
1682 if (intel_dp->psr_setup_done)
1683 return;
1684
1685 /* Prepare VSC packet as per EDP 1.3 spec, Table 3.10 */
1686 memset(&psr_vsc, 0, sizeof(psr_vsc));
1687 psr_vsc.sdp_header.HB0 = 0;
1688 psr_vsc.sdp_header.HB1 = 0x7;
1689 psr_vsc.sdp_header.HB2 = 0x2;
1690 psr_vsc.sdp_header.HB3 = 0x8;
1691 intel_edp_psr_write_vsc(intel_dp, &psr_vsc);
1692
1693 /* Avoid continuous PSR exit by masking memup and hpd */
Ben Widawsky18b59922013-09-20 09:35:30 -07001694 I915_WRITE(EDP_PSR_DEBUG_CTL(dev), EDP_PSR_DEBUG_MASK_MEMUP |
Rodrigo Vivi0cc4b692013-10-03 13:31:26 -03001695 EDP_PSR_DEBUG_MASK_HPD | EDP_PSR_DEBUG_MASK_LPSP);
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001696
1697 intel_dp->psr_setup_done = true;
1698}
1699
1700static void intel_edp_psr_enable_sink(struct intel_dp *intel_dp)
1701{
1702 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1703 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00001704 uint32_t aux_clock_divider;
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001705 int precharge = 0x3;
1706 int msg_size = 5; /* Header(4) + Message(1) */
1707
Damien Lespiauec5b01d2014-01-21 13:35:39 +00001708 aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, 0);
1709
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001710 /* Enable PSR in sink */
1711 if (intel_dp->psr_dpcd[1] & DP_PSR_NO_TRAIN_ON_EXIT)
Jani Nikula9d1a1032014-03-14 16:51:15 +02001712 drm_dp_dpcd_writeb(&intel_dp->aux, DP_PSR_EN_CFG,
1713 DP_PSR_ENABLE & ~DP_PSR_MAIN_LINK_ACTIVE);
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001714 else
Jani Nikula9d1a1032014-03-14 16:51:15 +02001715 drm_dp_dpcd_writeb(&intel_dp->aux, DP_PSR_EN_CFG,
1716 DP_PSR_ENABLE | DP_PSR_MAIN_LINK_ACTIVE);
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001717
1718 /* Setup AUX registers */
Ben Widawsky18b59922013-09-20 09:35:30 -07001719 I915_WRITE(EDP_PSR_AUX_DATA1(dev), EDP_PSR_DPCD_COMMAND);
1720 I915_WRITE(EDP_PSR_AUX_DATA2(dev), EDP_PSR_DPCD_NORMAL_OPERATION);
1721 I915_WRITE(EDP_PSR_AUX_CTL(dev),
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001722 DP_AUX_CH_CTL_TIME_OUT_400us |
1723 (msg_size << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
1724 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
1725 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT));
1726}
1727
1728static void intel_edp_psr_enable_source(struct intel_dp *intel_dp)
1729{
1730 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1731 struct drm_i915_private *dev_priv = dev->dev_private;
1732 uint32_t max_sleep_time = 0x1f;
1733 uint32_t idle_frames = 1;
1734 uint32_t val = 0x0;
Ben Widawskyed8546a2013-11-04 22:45:05 -08001735 const uint32_t link_entry_time = EDP_PSR_MIN_LINK_ENTRY_TIME_8_LINES;
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001736
1737 if (intel_dp->psr_dpcd[1] & DP_PSR_NO_TRAIN_ON_EXIT) {
1738 val |= EDP_PSR_LINK_STANDBY;
1739 val |= EDP_PSR_TP2_TP3_TIME_0us;
1740 val |= EDP_PSR_TP1_TIME_0us;
1741 val |= EDP_PSR_SKIP_AUX_EXIT;
1742 } else
1743 val |= EDP_PSR_LINK_DISABLE;
1744
Ben Widawsky18b59922013-09-20 09:35:30 -07001745 I915_WRITE(EDP_PSR_CTL(dev), val |
Ben Widawskyed8546a2013-11-04 22:45:05 -08001746 IS_BROADWELL(dev) ? 0 : link_entry_time |
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001747 max_sleep_time << EDP_PSR_MAX_SLEEP_TIME_SHIFT |
1748 idle_frames << EDP_PSR_IDLE_FRAME_SHIFT |
1749 EDP_PSR_ENABLE);
1750}
1751
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001752static bool intel_edp_psr_match_conditions(struct intel_dp *intel_dp)
1753{
1754 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1755 struct drm_device *dev = dig_port->base.base.dev;
1756 struct drm_i915_private *dev_priv = dev->dev_private;
1757 struct drm_crtc *crtc = dig_port->base.base.crtc;
1758 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1759 struct drm_i915_gem_object *obj = to_intel_framebuffer(crtc->fb)->obj;
1760 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
1761
Rodrigo Vivia031d702013-10-03 16:15:06 -03001762 dev_priv->psr.source_ok = false;
1763
Ben Widawsky18b59922013-09-20 09:35:30 -07001764 if (!HAS_PSR(dev)) {
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001765 DRM_DEBUG_KMS("PSR not supported on this platform\n");
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001766 return false;
1767 }
1768
1769 if ((intel_encoder->type != INTEL_OUTPUT_EDP) ||
1770 (dig_port->port != PORT_A)) {
1771 DRM_DEBUG_KMS("HSW ties PSR to DDI A (eDP)\n");
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001772 return false;
1773 }
1774
Jani Nikulad330a952014-01-21 11:24:25 +02001775 if (!i915.enable_psr) {
Rodrigo Vivi105b7c12013-07-11 18:45:02 -03001776 DRM_DEBUG_KMS("PSR disable by flag\n");
Rodrigo Vivi105b7c12013-07-11 18:45:02 -03001777 return false;
1778 }
1779
Chris Wilsoncd234b02013-08-02 20:39:49 +01001780 crtc = dig_port->base.base.crtc;
1781 if (crtc == NULL) {
1782 DRM_DEBUG_KMS("crtc not active for PSR\n");
Chris Wilsoncd234b02013-08-02 20:39:49 +01001783 return false;
1784 }
1785
1786 intel_crtc = to_intel_crtc(crtc);
Ville Syrjälä20ddf662013-09-04 18:25:25 +03001787 if (!intel_crtc_active(crtc)) {
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001788 DRM_DEBUG_KMS("crtc not active for PSR\n");
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001789 return false;
1790 }
1791
Chris Wilsoncd234b02013-08-02 20:39:49 +01001792 obj = to_intel_framebuffer(crtc->fb)->obj;
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001793 if (obj->tiling_mode != I915_TILING_X ||
1794 obj->fence_reg == I915_FENCE_REG_NONE) {
1795 DRM_DEBUG_KMS("PSR condition failed: fb not tiled or fenced\n");
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001796 return false;
1797 }
1798
1799 if (I915_READ(SPRCTL(intel_crtc->pipe)) & SPRITE_ENABLE) {
1800 DRM_DEBUG_KMS("PSR condition failed: Sprite is Enabled\n");
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001801 return false;
1802 }
1803
1804 if (I915_READ(HSW_STEREO_3D_CTL(intel_crtc->config.cpu_transcoder)) &
1805 S3D_ENABLE) {
1806 DRM_DEBUG_KMS("PSR condition failed: Stereo 3D is Enabled\n");
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001807 return false;
1808 }
1809
Ville Syrjäläca73b4f2013-09-04 18:25:24 +03001810 if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001811 DRM_DEBUG_KMS("PSR condition failed: Interlaced is Enabled\n");
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001812 return false;
1813 }
1814
Rodrigo Vivia031d702013-10-03 16:15:06 -03001815 dev_priv->psr.source_ok = true;
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001816 return true;
1817}
1818
Rodrigo Vivi3d739d92013-07-11 18:45:01 -03001819static void intel_edp_psr_do_enable(struct intel_dp *intel_dp)
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001820{
1821 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1822
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001823 if (!intel_edp_psr_match_conditions(intel_dp) ||
1824 intel_edp_is_psr_enabled(dev))
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001825 return;
1826
1827 /* Setup PSR once */
1828 intel_edp_psr_setup(intel_dp);
1829
1830 /* Enable PSR on the panel */
1831 intel_edp_psr_enable_sink(intel_dp);
1832
1833 /* Enable PSR on the host */
1834 intel_edp_psr_enable_source(intel_dp);
1835}
1836
Rodrigo Vivi3d739d92013-07-11 18:45:01 -03001837void intel_edp_psr_enable(struct intel_dp *intel_dp)
1838{
1839 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1840
1841 if (intel_edp_psr_match_conditions(intel_dp) &&
1842 !intel_edp_is_psr_enabled(dev))
1843 intel_edp_psr_do_enable(intel_dp);
1844}
1845
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001846void intel_edp_psr_disable(struct intel_dp *intel_dp)
1847{
1848 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1849 struct drm_i915_private *dev_priv = dev->dev_private;
1850
1851 if (!intel_edp_is_psr_enabled(dev))
1852 return;
1853
Ben Widawsky18b59922013-09-20 09:35:30 -07001854 I915_WRITE(EDP_PSR_CTL(dev),
1855 I915_READ(EDP_PSR_CTL(dev)) & ~EDP_PSR_ENABLE);
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001856
1857 /* Wait till PSR is idle */
Ben Widawsky18b59922013-09-20 09:35:30 -07001858 if (_wait_for((I915_READ(EDP_PSR_STATUS_CTL(dev)) &
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001859 EDP_PSR_STATUS_STATE_MASK) == 0, 2000, 10))
1860 DRM_ERROR("Timed out waiting for PSR Idle State\n");
1861}
1862
Rodrigo Vivi3d739d92013-07-11 18:45:01 -03001863void intel_edp_psr_update(struct drm_device *dev)
1864{
1865 struct intel_encoder *encoder;
1866 struct intel_dp *intel_dp = NULL;
1867
1868 list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head)
1869 if (encoder->type == INTEL_OUTPUT_EDP) {
1870 intel_dp = enc_to_intel_dp(&encoder->base);
1871
Rodrigo Vivia031d702013-10-03 16:15:06 -03001872 if (!is_edp_psr(dev))
Rodrigo Vivi3d739d92013-07-11 18:45:01 -03001873 return;
1874
1875 if (!intel_edp_psr_match_conditions(intel_dp))
1876 intel_edp_psr_disable(intel_dp);
1877 else
1878 if (!intel_edp_is_psr_enabled(dev))
1879 intel_edp_psr_do_enable(intel_dp);
1880 }
1881}
1882
Daniel Vettere8cb4552012-07-01 13:05:48 +02001883static void intel_disable_dp(struct intel_encoder *encoder)
Jesse Barnesd240f202010-08-13 15:43:26 -07001884{
Daniel Vettere8cb4552012-07-01 13:05:48 +02001885 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03001886 enum port port = dp_to_dig_port(intel_dp)->port;
1887 struct drm_device *dev = encoder->base.dev;
Daniel Vetter6cb49832012-05-20 17:14:50 +02001888
1889 /* Make sure the panel is off before trying to change the mode. But also
1890 * ensure that we have vdd while we switch off the panel. */
Patrik Jakobssonb3064152014-03-04 00:42:44 +01001891 edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01001892 intel_edp_backlight_off(intel_dp);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02001893 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01001894 intel_edp_panel_off(intel_dp);
Patrik Jakobssonb3064152014-03-04 00:42:44 +01001895 edp_panel_vdd_off(intel_dp, true);
Daniel Vetter37398502012-09-06 22:15:44 +02001896
1897 /* cpu edp my only be disable _after_ the cpu pipe/plane is disabled. */
Imre Deak982a3862013-05-23 19:39:40 +03001898 if (!(port == PORT_A || IS_VALLEYVIEW(dev)))
Daniel Vetter37398502012-09-06 22:15:44 +02001899 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07001900}
1901
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001902static void intel_post_disable_dp(struct intel_encoder *encoder)
Jesse Barnesd240f202010-08-13 15:43:26 -07001903{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001904 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03001905 enum port port = dp_to_dig_port(intel_dp)->port;
Jesse Barnesb2634012013-03-28 09:55:40 -07001906 struct drm_device *dev = encoder->base.dev;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001907
Imre Deak982a3862013-05-23 19:39:40 +03001908 if (port == PORT_A || IS_VALLEYVIEW(dev)) {
Daniel Vetter37398502012-09-06 22:15:44 +02001909 intel_dp_link_down(intel_dp);
Jesse Barnesb2634012013-03-28 09:55:40 -07001910 if (!IS_VALLEYVIEW(dev))
1911 ironlake_edp_pll_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02001912 }
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001913}
1914
Daniel Vettere8cb4552012-07-01 13:05:48 +02001915static void intel_enable_dp(struct intel_encoder *encoder)
Jesse Barnesd240f202010-08-13 15:43:26 -07001916{
Daniel Vettere8cb4552012-07-01 13:05:48 +02001917 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1918 struct drm_device *dev = encoder->base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001919 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001920 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001921
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02001922 if (WARN_ON(dp_reg & DP_PORT_EN))
1923 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001924
Daniel Vetter4be73782014-01-17 14:39:48 +01001925 edp_panel_vdd_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001926 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1927 intel_dp_start_link_train(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01001928 intel_edp_panel_on(intel_dp);
1929 edp_panel_vdd_off(intel_dp, true);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001930 intel_dp_complete_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03001931 intel_dp_stop_link_train(intel_dp);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03001932}
Jesse Barnes89b667f2013-04-18 14:51:36 -07001933
Jani Nikulaecff4f32013-09-06 07:38:29 +03001934static void g4x_enable_dp(struct intel_encoder *encoder)
1935{
Jani Nikula828f5c62013-09-05 16:44:45 +03001936 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1937
Jani Nikulaecff4f32013-09-06 07:38:29 +03001938 intel_enable_dp(encoder);
Daniel Vetter4be73782014-01-17 14:39:48 +01001939 intel_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001940}
Jesse Barnes89b667f2013-04-18 14:51:36 -07001941
Jani Nikulaab1f90f2013-07-30 12:20:30 +03001942static void vlv_enable_dp(struct intel_encoder *encoder)
1943{
Jani Nikula828f5c62013-09-05 16:44:45 +03001944 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1945
Daniel Vetter4be73782014-01-17 14:39:48 +01001946 intel_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001947}
1948
Jani Nikulaecff4f32013-09-06 07:38:29 +03001949static void g4x_pre_enable_dp(struct intel_encoder *encoder)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001950{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001951 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001952 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03001953
1954 if (dport->port == PORT_A)
1955 ironlake_edp_pll_on(intel_dp);
1956}
1957
1958static void vlv_pre_enable_dp(struct intel_encoder *encoder)
1959{
1960 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1961 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
Jesse Barnesb2634012013-03-28 09:55:40 -07001962 struct drm_device *dev = encoder->base.dev;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001963 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03001964 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001965 enum dpio_channel port = vlv_dport_to_channel(dport);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03001966 int pipe = intel_crtc->pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +03001967 struct edp_power_seq power_seq;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03001968 u32 val;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001969
Jani Nikulaab1f90f2013-07-30 12:20:30 +03001970 mutex_lock(&dev_priv->dpio_lock);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001971
Chon Ming Leeab3c7592013-11-07 10:43:30 +08001972 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(port));
Jani Nikulaab1f90f2013-07-30 12:20:30 +03001973 val = 0;
1974 if (pipe)
1975 val |= (1<<21);
1976 else
1977 val &= ~(1<<21);
1978 val |= 0x001000c4;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08001979 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW8(port), val);
1980 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW14(port), 0x00760018);
1981 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW23(port), 0x00400888);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001982
Jani Nikulaab1f90f2013-07-30 12:20:30 +03001983 mutex_unlock(&dev_priv->dpio_lock);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001984
Imre Deak2cac6132014-01-30 16:50:42 +02001985 if (is_edp(intel_dp)) {
1986 /* init power sequencer on this pipe and port */
1987 intel_dp_init_panel_power_sequencer(dev, intel_dp, &power_seq);
1988 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp,
1989 &power_seq);
1990 }
Jani Nikulabf13e812013-09-06 07:40:05 +03001991
Jani Nikulaab1f90f2013-07-30 12:20:30 +03001992 intel_enable_dp(encoder);
1993
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001994 vlv_wait_port_ready(dev_priv, dport);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001995}
1996
Jani Nikulaecff4f32013-09-06 07:38:29 +03001997static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder)
Jesse Barnes89b667f2013-04-18 14:51:36 -07001998{
1999 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
2000 struct drm_device *dev = encoder->base.dev;
2001 struct drm_i915_private *dev_priv = dev->dev_private;
Chon Ming Lee5e69f972013-09-05 20:41:49 +08002002 struct intel_crtc *intel_crtc =
2003 to_intel_crtc(encoder->base.crtc);
Chon Ming Leee4607fc2013-11-06 14:36:35 +08002004 enum dpio_channel port = vlv_dport_to_channel(dport);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08002005 int pipe = intel_crtc->pipe;
Jesse Barnes89b667f2013-04-18 14:51:36 -07002006
Jesse Barnes89b667f2013-04-18 14:51:36 -07002007 /* Program Tx lane resets to default */
Chris Wilson0980a602013-07-26 19:57:35 +01002008 mutex_lock(&dev_priv->dpio_lock);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08002009 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07002010 DPIO_PCS_TX_LANE2_RESET |
2011 DPIO_PCS_TX_LANE1_RESET);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08002012 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07002013 DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
2014 DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
2015 (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
2016 DPIO_PCS_CLK_SOFT_RESET);
2017
2018 /* Fix up inter-pair skew failure */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08002019 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW12(port), 0x00750f00);
2020 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW11(port), 0x00001500);
2021 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW14(port), 0x40400000);
Chris Wilson0980a602013-07-26 19:57:35 +01002022 mutex_unlock(&dev_priv->dpio_lock);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002023}
2024
2025/*
Jesse Barnesdf0c2372011-07-07 11:11:02 -07002026 * Native read with retry for link status and receiver capability reads for
2027 * cases where the sink may still be asleep.
Jani Nikula9d1a1032014-03-14 16:51:15 +02002028 *
2029 * Sinks are *supposed* to come up within 1ms from an off state, but we're also
2030 * supposed to retry 3 times per the spec.
Jesse Barnesdf0c2372011-07-07 11:11:02 -07002031 */
Jani Nikula9d1a1032014-03-14 16:51:15 +02002032static ssize_t
2033intel_dp_dpcd_read_wake(struct drm_dp_aux *aux, unsigned int offset,
2034 void *buffer, size_t size)
Jesse Barnesdf0c2372011-07-07 11:11:02 -07002035{
Jani Nikula9d1a1032014-03-14 16:51:15 +02002036 ssize_t ret;
2037 int i;
Jesse Barnesdf0c2372011-07-07 11:11:02 -07002038
Jesse Barnesdf0c2372011-07-07 11:11:02 -07002039 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002040 ret = drm_dp_dpcd_read(aux, offset, buffer, size);
2041 if (ret == size)
2042 return ret;
Jesse Barnesdf0c2372011-07-07 11:11:02 -07002043 msleep(1);
2044 }
2045
Jani Nikula9d1a1032014-03-14 16:51:15 +02002046 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002047}
2048
2049/*
2050 * Fetch AUX CH registers 0x202 - 0x207 which contain
2051 * link status information
2052 */
2053static bool
Keith Packard93f62da2011-11-01 19:45:03 -07002054intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002055{
Jani Nikula9d1a1032014-03-14 16:51:15 +02002056 return intel_dp_dpcd_read_wake(&intel_dp->aux,
2057 DP_LANE0_1_STATUS,
2058 link_status,
2059 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002060}
2061
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002062/*
2063 * These are source-specific values; current Intel hardware supports
2064 * a maximum voltage of 800mV and a maximum pre-emphasis of 6dB
2065 */
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002066
2067static uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08002068intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002069{
Paulo Zanoni30add222012-10-26 19:05:45 -02002070 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002071 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08002072
Paulo Zanoni8f93f4f2013-11-02 21:07:43 -07002073 if (IS_VALLEYVIEW(dev) || IS_BROADWELL(dev))
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002074 return DP_TRAIN_VOLTAGE_SWING_1200;
Imre Deakbc7d38a2013-05-16 14:40:36 +03002075 else if (IS_GEN7(dev) && port == PORT_A)
Keith Packard1a2eb462011-11-16 16:26:07 -08002076 return DP_TRAIN_VOLTAGE_SWING_800;
Imre Deakbc7d38a2013-05-16 14:40:36 +03002077 else if (HAS_PCH_CPT(dev) && port != PORT_A)
Keith Packard1a2eb462011-11-16 16:26:07 -08002078 return DP_TRAIN_VOLTAGE_SWING_1200;
2079 else
2080 return DP_TRAIN_VOLTAGE_SWING_800;
2081}
2082
2083static uint8_t
2084intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
2085{
Paulo Zanoni30add222012-10-26 19:05:45 -02002086 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002087 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08002088
Paulo Zanoni8f93f4f2013-11-02 21:07:43 -07002089 if (IS_BROADWELL(dev)) {
2090 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
2091 case DP_TRAIN_VOLTAGE_SWING_400:
2092 case DP_TRAIN_VOLTAGE_SWING_600:
2093 return DP_TRAIN_PRE_EMPHASIS_6;
2094 case DP_TRAIN_VOLTAGE_SWING_800:
2095 return DP_TRAIN_PRE_EMPHASIS_3_5;
2096 case DP_TRAIN_VOLTAGE_SWING_1200:
2097 default:
2098 return DP_TRAIN_PRE_EMPHASIS_0;
2099 }
2100 } else if (IS_HASWELL(dev)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002101 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
2102 case DP_TRAIN_VOLTAGE_SWING_400:
2103 return DP_TRAIN_PRE_EMPHASIS_9_5;
2104 case DP_TRAIN_VOLTAGE_SWING_600:
2105 return DP_TRAIN_PRE_EMPHASIS_6;
2106 case DP_TRAIN_VOLTAGE_SWING_800:
2107 return DP_TRAIN_PRE_EMPHASIS_3_5;
2108 case DP_TRAIN_VOLTAGE_SWING_1200:
2109 default:
2110 return DP_TRAIN_PRE_EMPHASIS_0;
2111 }
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002112 } else if (IS_VALLEYVIEW(dev)) {
2113 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
2114 case DP_TRAIN_VOLTAGE_SWING_400:
2115 return DP_TRAIN_PRE_EMPHASIS_9_5;
2116 case DP_TRAIN_VOLTAGE_SWING_600:
2117 return DP_TRAIN_PRE_EMPHASIS_6;
2118 case DP_TRAIN_VOLTAGE_SWING_800:
2119 return DP_TRAIN_PRE_EMPHASIS_3_5;
2120 case DP_TRAIN_VOLTAGE_SWING_1200:
2121 default:
2122 return DP_TRAIN_PRE_EMPHASIS_0;
2123 }
Imre Deakbc7d38a2013-05-16 14:40:36 +03002124 } else if (IS_GEN7(dev) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08002125 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
2126 case DP_TRAIN_VOLTAGE_SWING_400:
2127 return DP_TRAIN_PRE_EMPHASIS_6;
2128 case DP_TRAIN_VOLTAGE_SWING_600:
2129 case DP_TRAIN_VOLTAGE_SWING_800:
2130 return DP_TRAIN_PRE_EMPHASIS_3_5;
2131 default:
2132 return DP_TRAIN_PRE_EMPHASIS_0;
2133 }
2134 } else {
2135 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
2136 case DP_TRAIN_VOLTAGE_SWING_400:
2137 return DP_TRAIN_PRE_EMPHASIS_6;
2138 case DP_TRAIN_VOLTAGE_SWING_600:
2139 return DP_TRAIN_PRE_EMPHASIS_6;
2140 case DP_TRAIN_VOLTAGE_SWING_800:
2141 return DP_TRAIN_PRE_EMPHASIS_3_5;
2142 case DP_TRAIN_VOLTAGE_SWING_1200:
2143 default:
2144 return DP_TRAIN_PRE_EMPHASIS_0;
2145 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002146 }
2147}
2148
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002149static uint32_t intel_vlv_signal_levels(struct intel_dp *intel_dp)
2150{
2151 struct drm_device *dev = intel_dp_to_dev(intel_dp);
2152 struct drm_i915_private *dev_priv = dev->dev_private;
2153 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08002154 struct intel_crtc *intel_crtc =
2155 to_intel_crtc(dport->base.base.crtc);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002156 unsigned long demph_reg_value, preemph_reg_value,
2157 uniqtranscale_reg_value;
2158 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4607fc2013-11-06 14:36:35 +08002159 enum dpio_channel port = vlv_dport_to_channel(dport);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08002160 int pipe = intel_crtc->pipe;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002161
2162 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
2163 case DP_TRAIN_PRE_EMPHASIS_0:
2164 preemph_reg_value = 0x0004000;
2165 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
2166 case DP_TRAIN_VOLTAGE_SWING_400:
2167 demph_reg_value = 0x2B405555;
2168 uniqtranscale_reg_value = 0x552AB83A;
2169 break;
2170 case DP_TRAIN_VOLTAGE_SWING_600:
2171 demph_reg_value = 0x2B404040;
2172 uniqtranscale_reg_value = 0x5548B83A;
2173 break;
2174 case DP_TRAIN_VOLTAGE_SWING_800:
2175 demph_reg_value = 0x2B245555;
2176 uniqtranscale_reg_value = 0x5560B83A;
2177 break;
2178 case DP_TRAIN_VOLTAGE_SWING_1200:
2179 demph_reg_value = 0x2B405555;
2180 uniqtranscale_reg_value = 0x5598DA3A;
2181 break;
2182 default:
2183 return 0;
2184 }
2185 break;
2186 case DP_TRAIN_PRE_EMPHASIS_3_5:
2187 preemph_reg_value = 0x0002000;
2188 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
2189 case DP_TRAIN_VOLTAGE_SWING_400:
2190 demph_reg_value = 0x2B404040;
2191 uniqtranscale_reg_value = 0x5552B83A;
2192 break;
2193 case DP_TRAIN_VOLTAGE_SWING_600:
2194 demph_reg_value = 0x2B404848;
2195 uniqtranscale_reg_value = 0x5580B83A;
2196 break;
2197 case DP_TRAIN_VOLTAGE_SWING_800:
2198 demph_reg_value = 0x2B404040;
2199 uniqtranscale_reg_value = 0x55ADDA3A;
2200 break;
2201 default:
2202 return 0;
2203 }
2204 break;
2205 case DP_TRAIN_PRE_EMPHASIS_6:
2206 preemph_reg_value = 0x0000000;
2207 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
2208 case DP_TRAIN_VOLTAGE_SWING_400:
2209 demph_reg_value = 0x2B305555;
2210 uniqtranscale_reg_value = 0x5570B83A;
2211 break;
2212 case DP_TRAIN_VOLTAGE_SWING_600:
2213 demph_reg_value = 0x2B2B4040;
2214 uniqtranscale_reg_value = 0x55ADDA3A;
2215 break;
2216 default:
2217 return 0;
2218 }
2219 break;
2220 case DP_TRAIN_PRE_EMPHASIS_9_5:
2221 preemph_reg_value = 0x0006000;
2222 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
2223 case DP_TRAIN_VOLTAGE_SWING_400:
2224 demph_reg_value = 0x1B405555;
2225 uniqtranscale_reg_value = 0x55ADDA3A;
2226 break;
2227 default:
2228 return 0;
2229 }
2230 break;
2231 default:
2232 return 0;
2233 }
2234
Chris Wilson0980a602013-07-26 19:57:35 +01002235 mutex_lock(&dev_priv->dpio_lock);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08002236 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0x00000000);
2237 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW4(port), demph_reg_value);
2238 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW2(port),
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002239 uniqtranscale_reg_value);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08002240 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW3(port), 0x0C782040);
2241 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW11(port), 0x00030000);
2242 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW9(port), preemph_reg_value);
2243 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0x80000000);
Chris Wilson0980a602013-07-26 19:57:35 +01002244 mutex_unlock(&dev_priv->dpio_lock);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002245
2246 return 0;
2247}
2248
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002249static void
Jani Nikula0301b3a2013-10-15 09:36:08 +03002250intel_get_adjust_train(struct intel_dp *intel_dp,
2251 const uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002252{
2253 uint8_t v = 0;
2254 uint8_t p = 0;
2255 int lane;
Keith Packard1a2eb462011-11-16 16:26:07 -08002256 uint8_t voltage_max;
2257 uint8_t preemph_max;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002258
Jesse Barnes33a34e42010-09-08 12:42:02 -07002259 for (lane = 0; lane < intel_dp->lane_count; lane++) {
Daniel Vetter0f037bd2012-10-18 10:15:27 +02002260 uint8_t this_v = drm_dp_get_adjust_request_voltage(link_status, lane);
2261 uint8_t this_p = drm_dp_get_adjust_request_pre_emphasis(link_status, lane);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002262
2263 if (this_v > v)
2264 v = this_v;
2265 if (this_p > p)
2266 p = this_p;
2267 }
2268
Keith Packard1a2eb462011-11-16 16:26:07 -08002269 voltage_max = intel_dp_voltage_max(intel_dp);
Keith Packard417e8222011-11-01 19:54:11 -07002270 if (v >= voltage_max)
2271 v = voltage_max | DP_TRAIN_MAX_SWING_REACHED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002272
Keith Packard1a2eb462011-11-16 16:26:07 -08002273 preemph_max = intel_dp_pre_emphasis_max(intel_dp, v);
2274 if (p >= preemph_max)
2275 p = preemph_max | DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002276
2277 for (lane = 0; lane < 4; lane++)
Jesse Barnes33a34e42010-09-08 12:42:02 -07002278 intel_dp->train_set[lane] = v | p;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002279}
2280
2281static uint32_t
Paulo Zanonif0a34242012-12-06 16:51:50 -02002282intel_gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002283{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002284 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002285
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002286 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002287 case DP_TRAIN_VOLTAGE_SWING_400:
2288 default:
2289 signal_levels |= DP_VOLTAGE_0_4;
2290 break;
2291 case DP_TRAIN_VOLTAGE_SWING_600:
2292 signal_levels |= DP_VOLTAGE_0_6;
2293 break;
2294 case DP_TRAIN_VOLTAGE_SWING_800:
2295 signal_levels |= DP_VOLTAGE_0_8;
2296 break;
2297 case DP_TRAIN_VOLTAGE_SWING_1200:
2298 signal_levels |= DP_VOLTAGE_1_2;
2299 break;
2300 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002301 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002302 case DP_TRAIN_PRE_EMPHASIS_0:
2303 default:
2304 signal_levels |= DP_PRE_EMPHASIS_0;
2305 break;
2306 case DP_TRAIN_PRE_EMPHASIS_3_5:
2307 signal_levels |= DP_PRE_EMPHASIS_3_5;
2308 break;
2309 case DP_TRAIN_PRE_EMPHASIS_6:
2310 signal_levels |= DP_PRE_EMPHASIS_6;
2311 break;
2312 case DP_TRAIN_PRE_EMPHASIS_9_5:
2313 signal_levels |= DP_PRE_EMPHASIS_9_5;
2314 break;
2315 }
2316 return signal_levels;
2317}
2318
Zhenyu Wange3421a12010-04-08 09:43:27 +08002319/* Gen6's DP voltage swing and pre-emphasis control */
2320static uint32_t
2321intel_gen6_edp_signal_levels(uint8_t train_set)
2322{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08002323 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
2324 DP_TRAIN_PRE_EMPHASIS_MASK);
2325 switch (signal_levels) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08002326 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08002327 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
2328 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
2329 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
2330 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08002331 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08002332 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
2333 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08002334 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08002335 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
2336 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08002337 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08002338 case DP_TRAIN_VOLTAGE_SWING_1200 | DP_TRAIN_PRE_EMPHASIS_0:
2339 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08002340 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08002341 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
2342 "0x%x\n", signal_levels);
2343 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08002344 }
2345}
2346
Keith Packard1a2eb462011-11-16 16:26:07 -08002347/* Gen7's DP voltage swing and pre-emphasis control */
2348static uint32_t
2349intel_gen7_edp_signal_levels(uint8_t train_set)
2350{
2351 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
2352 DP_TRAIN_PRE_EMPHASIS_MASK);
2353 switch (signal_levels) {
2354 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
2355 return EDP_LINK_TRAIN_400MV_0DB_IVB;
2356 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
2357 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
2358 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
2359 return EDP_LINK_TRAIN_400MV_6DB_IVB;
2360
2361 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
2362 return EDP_LINK_TRAIN_600MV_0DB_IVB;
2363 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
2364 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
2365
2366 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
2367 return EDP_LINK_TRAIN_800MV_0DB_IVB;
2368 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
2369 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
2370
2371 default:
2372 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
2373 "0x%x\n", signal_levels);
2374 return EDP_LINK_TRAIN_500MV_0DB_IVB;
2375 }
2376}
2377
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002378/* Gen7.5's (HSW) DP voltage swing and pre-emphasis control */
2379static uint32_t
Paulo Zanonif0a34242012-12-06 16:51:50 -02002380intel_hsw_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002381{
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002382 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
2383 DP_TRAIN_PRE_EMPHASIS_MASK);
2384 switch (signal_levels) {
2385 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
2386 return DDI_BUF_EMP_400MV_0DB_HSW;
2387 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
2388 return DDI_BUF_EMP_400MV_3_5DB_HSW;
2389 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
2390 return DDI_BUF_EMP_400MV_6DB_HSW;
2391 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_9_5:
2392 return DDI_BUF_EMP_400MV_9_5DB_HSW;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002393
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002394 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
2395 return DDI_BUF_EMP_600MV_0DB_HSW;
2396 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
2397 return DDI_BUF_EMP_600MV_3_5DB_HSW;
2398 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
2399 return DDI_BUF_EMP_600MV_6DB_HSW;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002400
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002401 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
2402 return DDI_BUF_EMP_800MV_0DB_HSW;
2403 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
2404 return DDI_BUF_EMP_800MV_3_5DB_HSW;
2405 default:
2406 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
2407 "0x%x\n", signal_levels);
2408 return DDI_BUF_EMP_400MV_0DB_HSW;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002409 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002410}
2411
Paulo Zanoni8f93f4f2013-11-02 21:07:43 -07002412static uint32_t
2413intel_bdw_signal_levels(uint8_t train_set)
2414{
2415 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
2416 DP_TRAIN_PRE_EMPHASIS_MASK);
2417 switch (signal_levels) {
2418 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
2419 return DDI_BUF_EMP_400MV_0DB_BDW; /* Sel0 */
2420 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
2421 return DDI_BUF_EMP_400MV_3_5DB_BDW; /* Sel1 */
2422 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
2423 return DDI_BUF_EMP_400MV_6DB_BDW; /* Sel2 */
2424
2425 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
2426 return DDI_BUF_EMP_600MV_0DB_BDW; /* Sel3 */
2427 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
2428 return DDI_BUF_EMP_600MV_3_5DB_BDW; /* Sel4 */
2429 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
2430 return DDI_BUF_EMP_600MV_6DB_BDW; /* Sel5 */
2431
2432 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
2433 return DDI_BUF_EMP_800MV_0DB_BDW; /* Sel6 */
2434 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
2435 return DDI_BUF_EMP_800MV_3_5DB_BDW; /* Sel7 */
2436
2437 case DP_TRAIN_VOLTAGE_SWING_1200 | DP_TRAIN_PRE_EMPHASIS_0:
2438 return DDI_BUF_EMP_1200MV_0DB_BDW; /* Sel8 */
2439
2440 default:
2441 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
2442 "0x%x\n", signal_levels);
2443 return DDI_BUF_EMP_400MV_0DB_BDW; /* Sel0 */
2444 }
2445}
2446
Paulo Zanonif0a34242012-12-06 16:51:50 -02002447/* Properly updates "DP" with the correct signal levels. */
2448static void
2449intel_dp_set_signal_levels(struct intel_dp *intel_dp, uint32_t *DP)
2450{
2451 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002452 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02002453 struct drm_device *dev = intel_dig_port->base.base.dev;
2454 uint32_t signal_levels, mask;
2455 uint8_t train_set = intel_dp->train_set[0];
2456
Paulo Zanoni8f93f4f2013-11-02 21:07:43 -07002457 if (IS_BROADWELL(dev)) {
2458 signal_levels = intel_bdw_signal_levels(train_set);
2459 mask = DDI_BUF_EMP_MASK;
2460 } else if (IS_HASWELL(dev)) {
Paulo Zanonif0a34242012-12-06 16:51:50 -02002461 signal_levels = intel_hsw_signal_levels(train_set);
2462 mask = DDI_BUF_EMP_MASK;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002463 } else if (IS_VALLEYVIEW(dev)) {
2464 signal_levels = intel_vlv_signal_levels(intel_dp);
2465 mask = 0;
Imre Deakbc7d38a2013-05-16 14:40:36 +03002466 } else if (IS_GEN7(dev) && port == PORT_A) {
Paulo Zanonif0a34242012-12-06 16:51:50 -02002467 signal_levels = intel_gen7_edp_signal_levels(train_set);
2468 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Imre Deakbc7d38a2013-05-16 14:40:36 +03002469 } else if (IS_GEN6(dev) && port == PORT_A) {
Paulo Zanonif0a34242012-12-06 16:51:50 -02002470 signal_levels = intel_gen6_edp_signal_levels(train_set);
2471 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
2472 } else {
2473 signal_levels = intel_gen4_signal_levels(train_set);
2474 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
2475 }
2476
2477 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
2478
2479 *DP = (*DP & ~mask) | signal_levels;
2480}
2481
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002482static bool
Chris Wilsonea5b2132010-08-04 13:50:23 +01002483intel_dp_set_link_train(struct intel_dp *intel_dp,
Jani Nikula70aff662013-09-27 15:10:44 +03002484 uint32_t *DP,
Chris Wilson58e10eb2010-10-03 10:56:11 +01002485 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002486{
Paulo Zanoni174edf12012-10-26 19:05:50 -02002487 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2488 struct drm_device *dev = intel_dig_port->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002489 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -02002490 enum port port = intel_dig_port->port;
Jani Nikula2cdfe6c2013-10-04 15:08:48 +03002491 uint8_t buf[sizeof(intel_dp->train_set) + 1];
2492 int ret, len;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002493
Paulo Zanoni22b8bf12013-02-18 19:00:23 -03002494 if (HAS_DDI(dev)) {
Imre Deak3ab9c632013-05-03 12:57:41 +03002495 uint32_t temp = I915_READ(DP_TP_CTL(port));
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002496
2497 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2498 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2499 else
2500 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2501
2502 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2503 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2504 case DP_TRAINING_PATTERN_DISABLE:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002505 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2506
2507 break;
2508 case DP_TRAINING_PATTERN_1:
2509 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2510 break;
2511 case DP_TRAINING_PATTERN_2:
2512 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2513 break;
2514 case DP_TRAINING_PATTERN_3:
2515 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2516 break;
2517 }
Paulo Zanoni174edf12012-10-26 19:05:50 -02002518 I915_WRITE(DP_TP_CTL(port), temp);
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002519
Imre Deakbc7d38a2013-05-16 14:40:36 +03002520 } else if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || port != PORT_A)) {
Jani Nikula70aff662013-09-27 15:10:44 +03002521 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002522
2523 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2524 case DP_TRAINING_PATTERN_DISABLE:
Jani Nikula70aff662013-09-27 15:10:44 +03002525 *DP |= DP_LINK_TRAIN_OFF_CPT;
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002526 break;
2527 case DP_TRAINING_PATTERN_1:
Jani Nikula70aff662013-09-27 15:10:44 +03002528 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002529 break;
2530 case DP_TRAINING_PATTERN_2:
Jani Nikula70aff662013-09-27 15:10:44 +03002531 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002532 break;
2533 case DP_TRAINING_PATTERN_3:
2534 DRM_ERROR("DP training pattern 3 not supported\n");
Jani Nikula70aff662013-09-27 15:10:44 +03002535 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002536 break;
2537 }
2538
2539 } else {
Jani Nikula70aff662013-09-27 15:10:44 +03002540 *DP &= ~DP_LINK_TRAIN_MASK;
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002541
2542 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2543 case DP_TRAINING_PATTERN_DISABLE:
Jani Nikula70aff662013-09-27 15:10:44 +03002544 *DP |= DP_LINK_TRAIN_OFF;
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002545 break;
2546 case DP_TRAINING_PATTERN_1:
Jani Nikula70aff662013-09-27 15:10:44 +03002547 *DP |= DP_LINK_TRAIN_PAT_1;
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002548 break;
2549 case DP_TRAINING_PATTERN_2:
Jani Nikula70aff662013-09-27 15:10:44 +03002550 *DP |= DP_LINK_TRAIN_PAT_2;
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002551 break;
2552 case DP_TRAINING_PATTERN_3:
2553 DRM_ERROR("DP training pattern 3 not supported\n");
Jani Nikula70aff662013-09-27 15:10:44 +03002554 *DP |= DP_LINK_TRAIN_PAT_2;
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002555 break;
2556 }
2557 }
2558
Jani Nikula70aff662013-09-27 15:10:44 +03002559 I915_WRITE(intel_dp->output_reg, *DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002560 POSTING_READ(intel_dp->output_reg);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002561
Jani Nikula2cdfe6c2013-10-04 15:08:48 +03002562 buf[0] = dp_train_pat;
2563 if ((dp_train_pat & DP_TRAINING_PATTERN_MASK) ==
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002564 DP_TRAINING_PATTERN_DISABLE) {
Jani Nikula2cdfe6c2013-10-04 15:08:48 +03002565 /* don't write DP_TRAINING_LANEx_SET on disable */
2566 len = 1;
2567 } else {
2568 /* DP_TRAINING_LANEx_SET follow DP_TRAINING_PATTERN_SET */
2569 memcpy(buf + 1, intel_dp->train_set, intel_dp->lane_count);
2570 len = intel_dp->lane_count + 1;
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002571 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002572
Jani Nikula9d1a1032014-03-14 16:51:15 +02002573 ret = drm_dp_dpcd_write(&intel_dp->aux, DP_TRAINING_PATTERN_SET,
2574 buf, len);
Jani Nikula2cdfe6c2013-10-04 15:08:48 +03002575
2576 return ret == len;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002577}
2578
Jani Nikula70aff662013-09-27 15:10:44 +03002579static bool
2580intel_dp_reset_link_train(struct intel_dp *intel_dp, uint32_t *DP,
2581 uint8_t dp_train_pat)
2582{
Jani Nikula953d22e2013-10-04 15:08:47 +03002583 memset(intel_dp->train_set, 0, sizeof(intel_dp->train_set));
Jani Nikula70aff662013-09-27 15:10:44 +03002584 intel_dp_set_signal_levels(intel_dp, DP);
2585 return intel_dp_set_link_train(intel_dp, DP, dp_train_pat);
2586}
2587
2588static bool
2589intel_dp_update_link_train(struct intel_dp *intel_dp, uint32_t *DP,
Jani Nikula0301b3a2013-10-15 09:36:08 +03002590 const uint8_t link_status[DP_LINK_STATUS_SIZE])
Jani Nikula70aff662013-09-27 15:10:44 +03002591{
2592 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2593 struct drm_device *dev = intel_dig_port->base.base.dev;
2594 struct drm_i915_private *dev_priv = dev->dev_private;
2595 int ret;
2596
2597 intel_get_adjust_train(intel_dp, link_status);
2598 intel_dp_set_signal_levels(intel_dp, DP);
2599
2600 I915_WRITE(intel_dp->output_reg, *DP);
2601 POSTING_READ(intel_dp->output_reg);
2602
Jani Nikula9d1a1032014-03-14 16:51:15 +02002603 ret = drm_dp_dpcd_write(&intel_dp->aux, DP_TRAINING_LANE0_SET,
2604 intel_dp->train_set, intel_dp->lane_count);
Jani Nikula70aff662013-09-27 15:10:44 +03002605
2606 return ret == intel_dp->lane_count;
2607}
2608
Imre Deak3ab9c632013-05-03 12:57:41 +03002609static void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
2610{
2611 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2612 struct drm_device *dev = intel_dig_port->base.base.dev;
2613 struct drm_i915_private *dev_priv = dev->dev_private;
2614 enum port port = intel_dig_port->port;
2615 uint32_t val;
2616
2617 if (!HAS_DDI(dev))
2618 return;
2619
2620 val = I915_READ(DP_TP_CTL(port));
2621 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2622 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
2623 I915_WRITE(DP_TP_CTL(port), val);
2624
2625 /*
2626 * On PORT_A we can have only eDP in SST mode. There the only reason
2627 * we need to set idle transmission mode is to work around a HW issue
2628 * where we enable the pipe while not in idle link-training mode.
2629 * In this case there is requirement to wait for a minimum number of
2630 * idle patterns to be sent.
2631 */
2632 if (port == PORT_A)
2633 return;
2634
2635 if (wait_for((I915_READ(DP_TP_STATUS(port)) & DP_TP_STATUS_IDLE_DONE),
2636 1))
2637 DRM_ERROR("Timed out waiting for DP idle patterns\n");
2638}
2639
Jesse Barnes33a34e42010-09-08 12:42:02 -07002640/* Enable corresponding port and start training pattern 1 */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002641void
Jesse Barnes33a34e42010-09-08 12:42:02 -07002642intel_dp_start_link_train(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002643{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002644 struct drm_encoder *encoder = &dp_to_dig_port(intel_dp)->base.base;
Paulo Zanonic19b0662012-10-15 15:51:41 -03002645 struct drm_device *dev = encoder->dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002646 int i;
2647 uint8_t voltage;
Keith Packardcdb0e952011-11-01 20:00:06 -07002648 int voltage_tries, loop_tries;
Chris Wilsonea5b2132010-08-04 13:50:23 +01002649 uint32_t DP = intel_dp->DP;
Jani Nikula6aba5b62013-10-04 15:08:10 +03002650 uint8_t link_config[2];
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002651
Paulo Zanoniaffa9352012-11-23 15:30:39 -02002652 if (HAS_DDI(dev))
Paulo Zanonic19b0662012-10-15 15:51:41 -03002653 intel_ddi_prepare_link_retrain(encoder);
2654
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002655 /* Write the link configuration data */
Jani Nikula6aba5b62013-10-04 15:08:10 +03002656 link_config[0] = intel_dp->link_bw;
2657 link_config[1] = intel_dp->lane_count;
2658 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
2659 link_config[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
Jani Nikula9d1a1032014-03-14 16:51:15 +02002660 drm_dp_dpcd_write(&intel_dp->aux, DP_LINK_BW_SET, link_config, 2);
Jani Nikula6aba5b62013-10-04 15:08:10 +03002661
2662 link_config[0] = 0;
2663 link_config[1] = DP_SET_ANSI_8B10B;
Jani Nikula9d1a1032014-03-14 16:51:15 +02002664 drm_dp_dpcd_write(&intel_dp->aux, DP_DOWNSPREAD_CTRL, link_config, 2);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002665
2666 DP |= DP_PORT_EN;
Keith Packard1a2eb462011-11-16 16:26:07 -08002667
Jani Nikula70aff662013-09-27 15:10:44 +03002668 /* clock recovery */
2669 if (!intel_dp_reset_link_train(intel_dp, &DP,
2670 DP_TRAINING_PATTERN_1 |
2671 DP_LINK_SCRAMBLING_DISABLE)) {
2672 DRM_ERROR("failed to enable link training\n");
2673 return;
2674 }
2675
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002676 voltage = 0xff;
Keith Packardcdb0e952011-11-01 20:00:06 -07002677 voltage_tries = 0;
2678 loop_tries = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002679 for (;;) {
Jani Nikula70aff662013-09-27 15:10:44 +03002680 uint8_t link_status[DP_LINK_STATUS_SIZE];
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002681
Daniel Vettera7c96552012-10-18 10:15:30 +02002682 drm_dp_link_train_clock_recovery_delay(intel_dp->dpcd);
Keith Packard93f62da2011-11-01 19:45:03 -07002683 if (!intel_dp_get_link_status(intel_dp, link_status)) {
2684 DRM_ERROR("failed to get link status\n");
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002685 break;
Keith Packard93f62da2011-11-01 19:45:03 -07002686 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002687
Daniel Vetter01916272012-10-18 10:15:25 +02002688 if (drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
Keith Packard93f62da2011-11-01 19:45:03 -07002689 DRM_DEBUG_KMS("clock recovery OK\n");
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002690 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002691 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002692
2693 /* Check to see if we've tried the max voltage */
2694 for (i = 0; i < intel_dp->lane_count; i++)
2695 if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
2696 break;
Takashi Iwai3b4f8192013-03-11 18:40:16 +01002697 if (i == intel_dp->lane_count) {
Daniel Vetterb06fbda2012-10-16 09:50:25 +02002698 ++loop_tries;
2699 if (loop_tries == 5) {
Jani Nikula3def84b2013-10-05 16:13:56 +03002700 DRM_ERROR("too many full retries, give up\n");
Keith Packardcdb0e952011-11-01 20:00:06 -07002701 break;
2702 }
Jani Nikula70aff662013-09-27 15:10:44 +03002703 intel_dp_reset_link_train(intel_dp, &DP,
2704 DP_TRAINING_PATTERN_1 |
2705 DP_LINK_SCRAMBLING_DISABLE);
Keith Packardcdb0e952011-11-01 20:00:06 -07002706 voltage_tries = 0;
2707 continue;
2708 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002709
2710 /* Check to see if we've tried the same voltage 5 times */
Daniel Vetterb06fbda2012-10-16 09:50:25 +02002711 if ((intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) == voltage) {
Chris Wilson24773672012-09-26 16:48:30 +01002712 ++voltage_tries;
Daniel Vetterb06fbda2012-10-16 09:50:25 +02002713 if (voltage_tries == 5) {
Jani Nikula3def84b2013-10-05 16:13:56 +03002714 DRM_ERROR("too many voltage retries, give up\n");
Daniel Vetterb06fbda2012-10-16 09:50:25 +02002715 break;
2716 }
2717 } else
2718 voltage_tries = 0;
2719 voltage = intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002720
Jani Nikula70aff662013-09-27 15:10:44 +03002721 /* Update training set as requested by target */
2722 if (!intel_dp_update_link_train(intel_dp, &DP, link_status)) {
2723 DRM_ERROR("failed to update link training\n");
2724 break;
2725 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002726 }
2727
Jesse Barnes33a34e42010-09-08 12:42:02 -07002728 intel_dp->DP = DP;
2729}
2730
Paulo Zanonic19b0662012-10-15 15:51:41 -03002731void
Jesse Barnes33a34e42010-09-08 12:42:02 -07002732intel_dp_complete_link_train(struct intel_dp *intel_dp)
2733{
Jesse Barnes33a34e42010-09-08 12:42:02 -07002734 bool channel_eq = false;
Jesse Barnes37f80972011-01-05 14:45:24 -08002735 int tries, cr_tries;
Jesse Barnes33a34e42010-09-08 12:42:02 -07002736 uint32_t DP = intel_dp->DP;
Todd Previte06ea66b2014-01-20 10:19:39 -07002737 uint32_t training_pattern = DP_TRAINING_PATTERN_2;
2738
2739 /* Training Pattern 3 for HBR2 ot 1.2 devices that support it*/
2740 if (intel_dp->link_bw == DP_LINK_BW_5_4 || intel_dp->use_tps3)
2741 training_pattern = DP_TRAINING_PATTERN_3;
Jesse Barnes33a34e42010-09-08 12:42:02 -07002742
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002743 /* channel equalization */
Jani Nikula70aff662013-09-27 15:10:44 +03002744 if (!intel_dp_set_link_train(intel_dp, &DP,
Todd Previte06ea66b2014-01-20 10:19:39 -07002745 training_pattern |
Jani Nikula70aff662013-09-27 15:10:44 +03002746 DP_LINK_SCRAMBLING_DISABLE)) {
2747 DRM_ERROR("failed to start channel equalization\n");
2748 return;
2749 }
2750
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002751 tries = 0;
Jesse Barnes37f80972011-01-05 14:45:24 -08002752 cr_tries = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002753 channel_eq = false;
2754 for (;;) {
Jani Nikula70aff662013-09-27 15:10:44 +03002755 uint8_t link_status[DP_LINK_STATUS_SIZE];
Zhenyu Wange3421a12010-04-08 09:43:27 +08002756
Jesse Barnes37f80972011-01-05 14:45:24 -08002757 if (cr_tries > 5) {
2758 DRM_ERROR("failed to train DP, aborting\n");
Jesse Barnes37f80972011-01-05 14:45:24 -08002759 break;
2760 }
2761
Daniel Vettera7c96552012-10-18 10:15:30 +02002762 drm_dp_link_train_channel_eq_delay(intel_dp->dpcd);
Jani Nikula70aff662013-09-27 15:10:44 +03002763 if (!intel_dp_get_link_status(intel_dp, link_status)) {
2764 DRM_ERROR("failed to get link status\n");
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002765 break;
Jani Nikula70aff662013-09-27 15:10:44 +03002766 }
Jesse Barnes869184a2010-10-07 16:01:22 -07002767
Jesse Barnes37f80972011-01-05 14:45:24 -08002768 /* Make sure clock is still ok */
Daniel Vetter01916272012-10-18 10:15:25 +02002769 if (!drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
Jesse Barnes37f80972011-01-05 14:45:24 -08002770 intel_dp_start_link_train(intel_dp);
Jani Nikula70aff662013-09-27 15:10:44 +03002771 intel_dp_set_link_train(intel_dp, &DP,
Todd Previte06ea66b2014-01-20 10:19:39 -07002772 training_pattern |
Jani Nikula70aff662013-09-27 15:10:44 +03002773 DP_LINK_SCRAMBLING_DISABLE);
Jesse Barnes37f80972011-01-05 14:45:24 -08002774 cr_tries++;
2775 continue;
2776 }
2777
Daniel Vetter1ffdff12012-10-18 10:15:24 +02002778 if (drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002779 channel_eq = true;
2780 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002781 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002782
Jesse Barnes37f80972011-01-05 14:45:24 -08002783 /* Try 5 times, then try clock recovery if that fails */
2784 if (tries > 5) {
2785 intel_dp_link_down(intel_dp);
2786 intel_dp_start_link_train(intel_dp);
Jani Nikula70aff662013-09-27 15:10:44 +03002787 intel_dp_set_link_train(intel_dp, &DP,
Todd Previte06ea66b2014-01-20 10:19:39 -07002788 training_pattern |
Jani Nikula70aff662013-09-27 15:10:44 +03002789 DP_LINK_SCRAMBLING_DISABLE);
Jesse Barnes37f80972011-01-05 14:45:24 -08002790 tries = 0;
2791 cr_tries++;
2792 continue;
2793 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002794
Jani Nikula70aff662013-09-27 15:10:44 +03002795 /* Update training set as requested by target */
2796 if (!intel_dp_update_link_train(intel_dp, &DP, link_status)) {
2797 DRM_ERROR("failed to update link training\n");
2798 break;
2799 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002800 ++tries;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002801 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002802
Imre Deak3ab9c632013-05-03 12:57:41 +03002803 intel_dp_set_idle_link_train(intel_dp);
2804
2805 intel_dp->DP = DP;
2806
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002807 if (channel_eq)
Masanari Iida07f42252013-03-20 11:00:34 +09002808 DRM_DEBUG_KMS("Channel EQ done. DP Training successful\n");
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002809
Imre Deak3ab9c632013-05-03 12:57:41 +03002810}
2811
2812void intel_dp_stop_link_train(struct intel_dp *intel_dp)
2813{
Jani Nikula70aff662013-09-27 15:10:44 +03002814 intel_dp_set_link_train(intel_dp, &intel_dp->DP,
Imre Deak3ab9c632013-05-03 12:57:41 +03002815 DP_TRAINING_PATTERN_DISABLE);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002816}
2817
2818static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01002819intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002820{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002821 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002822 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002823 struct drm_device *dev = intel_dig_port->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002824 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterab527ef2012-11-29 15:59:33 +01002825 struct intel_crtc *intel_crtc =
2826 to_intel_crtc(intel_dig_port->base.base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002827 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002828
Paulo Zanonic19b0662012-10-15 15:51:41 -03002829 /*
2830 * DDI code has a strict mode set sequence and we should try to respect
2831 * it, otherwise we might hang the machine in many different ways. So we
2832 * really should be disabling the port only on a complete crtc_disable
2833 * sequence. This function is just called under two conditions on DDI
2834 * code:
2835 * - Link train failed while doing crtc_enable, and on this case we
2836 * really should respect the mode set sequence and wait for a
2837 * crtc_disable.
2838 * - Someone turned the monitor off and intel_dp_check_link_status
2839 * called us. We don't need to disable the whole port on this case, so
2840 * when someone turns the monitor on again,
2841 * intel_ddi_prepare_link_retrain will take care of redoing the link
2842 * train.
2843 */
Paulo Zanoniaffa9352012-11-23 15:30:39 -02002844 if (HAS_DDI(dev))
Paulo Zanonic19b0662012-10-15 15:51:41 -03002845 return;
2846
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002847 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00002848 return;
2849
Zhao Yakui28c97732009-10-09 11:39:41 +08002850 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002851
Imre Deakbc7d38a2013-05-16 14:40:36 +03002852 if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08002853 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Chris Wilsonea5b2132010-08-04 13:50:23 +01002854 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT);
Zhenyu Wange3421a12010-04-08 09:43:27 +08002855 } else {
2856 DP &= ~DP_LINK_TRAIN_MASK;
Chris Wilsonea5b2132010-08-04 13:50:23 +01002857 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE);
Zhenyu Wange3421a12010-04-08 09:43:27 +08002858 }
Chris Wilsonfe255d02010-09-11 21:37:48 +01002859 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002860
Daniel Vetterab527ef2012-11-29 15:59:33 +01002861 /* We don't really know why we're doing this */
2862 intel_wait_for_vblank(dev, intel_crtc->pipe);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002863
Daniel Vetter493a7082012-05-30 12:31:56 +02002864 if (HAS_PCH_IBX(dev) &&
Chris Wilson1b39d6f2010-12-06 11:20:45 +00002865 I915_READ(intel_dp->output_reg) & DP_PIPEB_SELECT) {
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002866 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
Chris Wilson31acbcc2011-04-17 06:38:35 +01002867
Eric Anholt5bddd172010-11-18 09:32:59 +08002868 /* Hardware workaround: leaving our transcoder select
2869 * set to transcoder B while it's off will prevent the
2870 * corresponding HDMI output on transcoder A.
2871 *
2872 * Combine this with another hardware workaround:
2873 * transcoder select bit can only be cleared while the
2874 * port is enabled.
2875 */
2876 DP &= ~DP_PIPEB_SELECT;
2877 I915_WRITE(intel_dp->output_reg, DP);
2878
2879 /* Changes to enable or select take place the vblank
2880 * after being written.
2881 */
Daniel Vetterff50afe2012-11-29 15:59:34 +01002882 if (WARN_ON(crtc == NULL)) {
2883 /* We should never try to disable a port without a crtc
2884 * attached. For paranoia keep the code around for a
2885 * bit. */
Chris Wilson31acbcc2011-04-17 06:38:35 +01002886 POSTING_READ(intel_dp->output_reg);
2887 msleep(50);
2888 } else
Daniel Vetterab527ef2012-11-29 15:59:33 +01002889 intel_wait_for_vblank(dev, intel_crtc->pipe);
Eric Anholt5bddd172010-11-18 09:32:59 +08002890 }
2891
Wu Fengguang832afda2011-12-09 20:42:21 +08002892 DP &= ~DP_AUDIO_OUTPUT_ENABLE;
Chris Wilsonea5b2132010-08-04 13:50:23 +01002893 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
2894 POSTING_READ(intel_dp->output_reg);
Keith Packardf01eca22011-09-28 16:48:10 -07002895 msleep(intel_dp->panel_power_down_delay);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002896}
2897
Keith Packard26d61aa2011-07-25 20:01:09 -07002898static bool
2899intel_dp_get_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07002900{
Rodrigo Vivia031d702013-10-03 16:15:06 -03002901 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2902 struct drm_device *dev = dig_port->base.base.dev;
2903 struct drm_i915_private *dev_priv = dev->dev_private;
2904
Damien Lespiau577c7a52012-12-13 16:09:02 +00002905 char dpcd_hex_dump[sizeof(intel_dp->dpcd) * 3];
2906
Jani Nikula9d1a1032014-03-14 16:51:15 +02002907 if (intel_dp_dpcd_read_wake(&intel_dp->aux, 0x000, intel_dp->dpcd,
2908 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04002909 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07002910
Damien Lespiau577c7a52012-12-13 16:09:02 +00002911 hex_dump_to_buffer(intel_dp->dpcd, sizeof(intel_dp->dpcd),
2912 32, 1, dpcd_hex_dump, sizeof(dpcd_hex_dump), false);
2913 DRM_DEBUG_KMS("DPCD: %s\n", dpcd_hex_dump);
2914
Adam Jacksonedb39242012-09-18 10:58:49 -04002915 if (intel_dp->dpcd[DP_DPCD_REV] == 0)
2916 return false; /* DPCD not present */
2917
Shobhit Kumar2293bb52013-07-11 18:44:56 -03002918 /* Check if the panel supports PSR */
2919 memset(intel_dp->psr_dpcd, 0, sizeof(intel_dp->psr_dpcd));
Jani Nikula50003932013-09-20 16:42:17 +03002920 if (is_edp(intel_dp)) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002921 intel_dp_dpcd_read_wake(&intel_dp->aux, DP_PSR_SUPPORT,
2922 intel_dp->psr_dpcd,
2923 sizeof(intel_dp->psr_dpcd));
Rodrigo Vivia031d702013-10-03 16:15:06 -03002924 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
2925 dev_priv->psr.sink_support = true;
Jani Nikula50003932013-09-20 16:42:17 +03002926 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
Rodrigo Vivia031d702013-10-03 16:15:06 -03002927 }
Jani Nikula50003932013-09-20 16:42:17 +03002928 }
2929
Todd Previte06ea66b2014-01-20 10:19:39 -07002930 /* Training Pattern 3 support */
2931 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x12 &&
2932 intel_dp->dpcd[DP_MAX_LANE_COUNT] & DP_TPS3_SUPPORTED) {
2933 intel_dp->use_tps3 = true;
2934 DRM_DEBUG_KMS("Displayport TPS3 supported");
2935 } else
2936 intel_dp->use_tps3 = false;
2937
Adam Jacksonedb39242012-09-18 10:58:49 -04002938 if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
2939 DP_DWN_STRM_PORT_PRESENT))
2940 return true; /* native DP sink */
2941
2942 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
2943 return true; /* no per-port downstream info */
2944
Jani Nikula9d1a1032014-03-14 16:51:15 +02002945 if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
2946 intel_dp->downstream_ports,
2947 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04002948 return false; /* downstream port status fetch failed */
2949
2950 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07002951}
2952
Adam Jackson0d198322012-05-14 16:05:47 -04002953static void
2954intel_dp_probe_oui(struct intel_dp *intel_dp)
2955{
2956 u8 buf[3];
2957
2958 if (!(intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] & DP_OUI_SUPPORT))
2959 return;
2960
Daniel Vetter4be73782014-01-17 14:39:48 +01002961 edp_panel_vdd_on(intel_dp);
Daniel Vetter351cfc32012-06-12 13:20:47 +02002962
Jani Nikula9d1a1032014-03-14 16:51:15 +02002963 if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_SINK_OUI, buf, 3) == 3)
Adam Jackson0d198322012-05-14 16:05:47 -04002964 DRM_DEBUG_KMS("Sink OUI: %02hx%02hx%02hx\n",
2965 buf[0], buf[1], buf[2]);
2966
Jani Nikula9d1a1032014-03-14 16:51:15 +02002967 if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_BRANCH_OUI, buf, 3) == 3)
Adam Jackson0d198322012-05-14 16:05:47 -04002968 DRM_DEBUG_KMS("Branch OUI: %02hx%02hx%02hx\n",
2969 buf[0], buf[1], buf[2]);
Daniel Vetter351cfc32012-06-12 13:20:47 +02002970
Daniel Vetter4be73782014-01-17 14:39:48 +01002971 edp_panel_vdd_off(intel_dp, false);
Adam Jackson0d198322012-05-14 16:05:47 -04002972}
2973
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002974int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
2975{
2976 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2977 struct drm_device *dev = intel_dig_port->base.base.dev;
2978 struct intel_crtc *intel_crtc =
2979 to_intel_crtc(intel_dig_port->base.base.crtc);
2980 u8 buf[1];
2981
Jani Nikula9d1a1032014-03-14 16:51:15 +02002982 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, buf) < 0)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002983 return -EAGAIN;
2984
2985 if (!(buf[0] & DP_TEST_CRC_SUPPORTED))
2986 return -ENOTTY;
2987
Jani Nikula9d1a1032014-03-14 16:51:15 +02002988 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
2989 DP_TEST_SINK_START) < 0)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002990 return -EAGAIN;
2991
2992 /* Wait 2 vblanks to be sure we will have the correct CRC value */
2993 intel_wait_for_vblank(dev, intel_crtc->pipe);
2994 intel_wait_for_vblank(dev, intel_crtc->pipe);
2995
Jani Nikula9d1a1032014-03-14 16:51:15 +02002996 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002997 return -EAGAIN;
2998
Jani Nikula9d1a1032014-03-14 16:51:15 +02002999 drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK, 0);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003000 return 0;
3001}
3002
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003003static bool
3004intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3005{
Jani Nikula9d1a1032014-03-14 16:51:15 +02003006 return intel_dp_dpcd_read_wake(&intel_dp->aux,
3007 DP_DEVICE_SERVICE_IRQ_VECTOR,
3008 sink_irq_vector, 1) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003009}
3010
3011static void
3012intel_dp_handle_test_request(struct intel_dp *intel_dp)
3013{
3014 /* NAK by default */
Jani Nikula9d1a1032014-03-14 16:51:15 +02003015 drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, DP_TEST_NAK);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003016}
3017
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003018/*
3019 * According to DP spec
3020 * 5.1.2:
3021 * 1. Read DPCD
3022 * 2. Configure link according to Receiver Capabilities
3023 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
3024 * 4. Check link status on receipt of hot-plug interrupt
3025 */
3026
Paulo Zanoni00c09d72012-10-26 19:05:52 -02003027void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003028intel_dp_check_link_status(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003029{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003030 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003031 u8 sink_irq_vector;
Keith Packard93f62da2011-11-01 19:45:03 -07003032 u8 link_status[DP_LINK_STATUS_SIZE];
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003033
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003034 if (!intel_encoder->connectors_active)
Keith Packardd2b996a2011-07-25 22:37:51 -07003035 return;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07003036
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003037 if (WARN_ON(!intel_encoder->base.crtc))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003038 return;
3039
Keith Packard92fd8fd2011-07-25 19:50:10 -07003040 /* Try to read receiver status if the link appears to be up */
Keith Packard93f62da2011-11-01 19:45:03 -07003041 if (!intel_dp_get_link_status(intel_dp, link_status)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003042 return;
3043 }
3044
Keith Packard92fd8fd2011-07-25 19:50:10 -07003045 /* Now read the DPCD to see if it's actually running */
Keith Packard26d61aa2011-07-25 20:01:09 -07003046 if (!intel_dp_get_dpcd(intel_dp)) {
Jesse Barnes59cd09e2011-07-07 11:10:59 -07003047 return;
3048 }
3049
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003050 /* Try to read the source of the interrupt */
3051 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
3052 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector)) {
3053 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02003054 drm_dp_dpcd_writeb(&intel_dp->aux,
3055 DP_DEVICE_SERVICE_IRQ_VECTOR,
3056 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003057
3058 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
3059 intel_dp_handle_test_request(intel_dp);
3060 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
3061 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
3062 }
3063
Daniel Vetter1ffdff12012-10-18 10:15:24 +02003064 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Keith Packard92fd8fd2011-07-25 19:50:10 -07003065 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003066 drm_get_encoder_name(&intel_encoder->base));
Jesse Barnes33a34e42010-09-08 12:42:02 -07003067 intel_dp_start_link_train(intel_dp);
3068 intel_dp_complete_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03003069 intel_dp_stop_link_train(intel_dp);
Jesse Barnes33a34e42010-09-08 12:42:02 -07003070 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003071}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003072
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04003073/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003074static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07003075intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04003076{
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04003077 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04003078 uint8_t type;
3079
3080 if (!intel_dp_get_dpcd(intel_dp))
3081 return connector_status_disconnected;
3082
3083 /* if there's no downstream port, we're done */
3084 if (!(dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT))
Keith Packard26d61aa2011-07-25 20:01:09 -07003085 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04003086
3087 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03003088 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
3089 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Adam Jackson23235172012-09-20 16:42:45 -04003090 uint8_t reg;
Jani Nikula9d1a1032014-03-14 16:51:15 +02003091
3092 if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_SINK_COUNT,
3093 &reg, 1) < 0)
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04003094 return connector_status_unknown;
Jani Nikula9d1a1032014-03-14 16:51:15 +02003095
Adam Jackson23235172012-09-20 16:42:45 -04003096 return DP_GET_SINK_COUNT(reg) ? connector_status_connected
3097 : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04003098 }
3099
3100 /* If no HPD, poke DDC gently */
3101 if (drm_probe_ddc(&intel_dp->adapter))
3102 return connector_status_connected;
3103
3104 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03003105 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
3106 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
3107 if (type == DP_DS_PORT_TYPE_VGA ||
3108 type == DP_DS_PORT_TYPE_NON_EDID)
3109 return connector_status_unknown;
3110 } else {
3111 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
3112 DP_DWN_STRM_PORT_TYPE_MASK;
3113 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
3114 type == DP_DWN_STRM_PORT_TYPE_OTHER)
3115 return connector_status_unknown;
3116 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04003117
3118 /* Anything else is out of spec, warn and ignore */
3119 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07003120 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04003121}
3122
3123static enum drm_connector_status
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08003124ironlake_dp_detect(struct intel_dp *intel_dp)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003125{
Paulo Zanoni30add222012-10-26 19:05:45 -02003126 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Damien Lespiau1b469632012-12-13 16:09:01 +00003127 struct drm_i915_private *dev_priv = dev->dev_private;
3128 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003129 enum drm_connector_status status;
3130
Chris Wilsonfe16d942011-02-12 10:29:38 +00003131 /* Can't disconnect eDP, but you can close the lid... */
3132 if (is_edp(intel_dp)) {
Paulo Zanoni30add222012-10-26 19:05:45 -02003133 status = intel_panel_detect(dev);
Chris Wilsonfe16d942011-02-12 10:29:38 +00003134 if (status == connector_status_unknown)
3135 status = connector_status_connected;
3136 return status;
3137 }
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07003138
Damien Lespiau1b469632012-12-13 16:09:01 +00003139 if (!ibx_digital_port_connected(dev_priv, intel_dig_port))
3140 return connector_status_disconnected;
3141
Keith Packard26d61aa2011-07-25 20:01:09 -07003142 return intel_dp_detect_dpcd(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003143}
3144
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003145static enum drm_connector_status
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08003146g4x_dp_detect(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003147{
Paulo Zanoni30add222012-10-26 19:05:45 -02003148 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003149 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä34f2be42013-01-24 15:29:27 +02003150 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilson10f76a32012-05-11 18:01:32 +01003151 uint32_t bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003152
Jesse Barnes35aad752013-03-01 13:14:31 -08003153 /* Can't disconnect eDP, but you can close the lid... */
3154 if (is_edp(intel_dp)) {
3155 enum drm_connector_status status;
3156
3157 status = intel_panel_detect(dev);
3158 if (status == connector_status_unknown)
3159 status = connector_status_connected;
3160 return status;
3161 }
3162
Todd Previte232a6ee2014-01-23 00:13:41 -07003163 if (IS_VALLEYVIEW(dev)) {
3164 switch (intel_dig_port->port) {
3165 case PORT_B:
3166 bit = PORTB_HOTPLUG_LIVE_STATUS_VLV;
3167 break;
3168 case PORT_C:
3169 bit = PORTC_HOTPLUG_LIVE_STATUS_VLV;
3170 break;
3171 case PORT_D:
3172 bit = PORTD_HOTPLUG_LIVE_STATUS_VLV;
3173 break;
3174 default:
3175 return connector_status_unknown;
3176 }
3177 } else {
3178 switch (intel_dig_port->port) {
3179 case PORT_B:
3180 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
3181 break;
3182 case PORT_C:
3183 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
3184 break;
3185 case PORT_D:
3186 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
3187 break;
3188 default:
3189 return connector_status_unknown;
3190 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003191 }
3192
Chris Wilson10f76a32012-05-11 18:01:32 +01003193 if ((I915_READ(PORT_HOTPLUG_STAT) & bit) == 0)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003194 return connector_status_disconnected;
3195
Keith Packard26d61aa2011-07-25 20:01:09 -07003196 return intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08003197}
3198
Keith Packard8c241fe2011-09-28 16:38:44 -07003199static struct edid *
3200intel_dp_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
3201{
Jani Nikula9cd300e2012-10-19 14:51:52 +03003202 struct intel_connector *intel_connector = to_intel_connector(connector);
Keith Packard8c241fe2011-09-28 16:38:44 -07003203
Jani Nikula9cd300e2012-10-19 14:51:52 +03003204 /* use cached edid if we have one */
3205 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03003206 /* invalid edid */
3207 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04003208 return NULL;
3209
Jani Nikula55e9ede2013-10-01 10:38:54 +03003210 return drm_edid_duplicate(intel_connector->edid);
Jesse Barnesd6f24d02012-06-14 15:28:33 -04003211 }
3212
Jani Nikula9cd300e2012-10-19 14:51:52 +03003213 return drm_get_edid(connector, adapter);
Keith Packard8c241fe2011-09-28 16:38:44 -07003214}
3215
3216static int
3217intel_dp_get_edid_modes(struct drm_connector *connector, struct i2c_adapter *adapter)
3218{
Jani Nikula9cd300e2012-10-19 14:51:52 +03003219 struct intel_connector *intel_connector = to_intel_connector(connector);
Keith Packard8c241fe2011-09-28 16:38:44 -07003220
Jani Nikula9cd300e2012-10-19 14:51:52 +03003221 /* use cached edid if we have one */
3222 if (intel_connector->edid) {
3223 /* invalid edid */
3224 if (IS_ERR(intel_connector->edid))
3225 return 0;
3226
3227 return intel_connector_update_modes(connector,
3228 intel_connector->edid);
Jesse Barnesd6f24d02012-06-14 15:28:33 -04003229 }
3230
Jani Nikula9cd300e2012-10-19 14:51:52 +03003231 return intel_ddc_get_modes(connector, adapter);
Keith Packard8c241fe2011-09-28 16:38:44 -07003232}
3233
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08003234static enum drm_connector_status
3235intel_dp_detect(struct drm_connector *connector, bool force)
3236{
3237 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02003238 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3239 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02003240 struct drm_device *dev = connector->dev;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02003241 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08003242 enum drm_connector_status status;
Imre Deak671dedd2014-03-05 16:20:53 +02003243 enum intel_display_power_domain power_domain;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08003244 struct edid *edid = NULL;
3245
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02003246 intel_runtime_pm_get(dev_priv);
3247
Imre Deak671dedd2014-03-05 16:20:53 +02003248 power_domain = intel_display_port_power_domain(intel_encoder);
3249 intel_display_power_get(dev_priv, power_domain);
3250
Chris Wilson164c8592013-07-20 20:27:08 +01003251 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
3252 connector->base.id, drm_get_connector_name(connector));
3253
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08003254 intel_dp->has_audio = false;
3255
3256 if (HAS_PCH_SPLIT(dev))
3257 status = ironlake_dp_detect(intel_dp);
3258 else
3259 status = g4x_dp_detect(intel_dp);
Adam Jackson1b9be9d2011-07-12 17:38:01 -04003260
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08003261 if (status != connector_status_connected)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02003262 goto out;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08003263
Adam Jackson0d198322012-05-14 16:05:47 -04003264 intel_dp_probe_oui(intel_dp);
3265
Daniel Vetterc3e5f672012-02-23 17:14:47 +01003266 if (intel_dp->force_audio != HDMI_AUDIO_AUTO) {
3267 intel_dp->has_audio = (intel_dp->force_audio == HDMI_AUDIO_ON);
Chris Wilsonf6849602010-09-19 09:29:33 +01003268 } else {
Keith Packard8c241fe2011-09-28 16:38:44 -07003269 edid = intel_dp_get_edid(connector, &intel_dp->adapter);
Chris Wilsonf6849602010-09-19 09:29:33 +01003270 if (edid) {
3271 intel_dp->has_audio = drm_detect_monitor_audio(edid);
Chris Wilsonf6849602010-09-19 09:29:33 +01003272 kfree(edid);
3273 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08003274 }
3275
Paulo Zanonid63885d2012-10-26 19:05:49 -02003276 if (intel_encoder->type != INTEL_OUTPUT_EDP)
3277 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02003278 status = connector_status_connected;
3279
3280out:
Imre Deak671dedd2014-03-05 16:20:53 +02003281 intel_display_power_put(dev_priv, power_domain);
3282
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02003283 intel_runtime_pm_put(dev_priv);
Imre Deak671dedd2014-03-05 16:20:53 +02003284
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02003285 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003286}
3287
3288static int intel_dp_get_modes(struct drm_connector *connector)
3289{
Chris Wilsondf0e9242010-09-09 16:20:55 +01003290 struct intel_dp *intel_dp = intel_attached_dp(connector);
Imre Deak671dedd2014-03-05 16:20:53 +02003291 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3292 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Jani Nikuladd06f902012-10-19 14:51:50 +03003293 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonifa90ece2012-10-26 19:05:44 -02003294 struct drm_device *dev = connector->dev;
Imre Deak671dedd2014-03-05 16:20:53 +02003295 struct drm_i915_private *dev_priv = dev->dev_private;
3296 enum intel_display_power_domain power_domain;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003297 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003298
3299 /* We should parse the EDID data and find out if it has an audio sink
3300 */
3301
Imre Deak671dedd2014-03-05 16:20:53 +02003302 power_domain = intel_display_port_power_domain(intel_encoder);
3303 intel_display_power_get(dev_priv, power_domain);
3304
Keith Packard8c241fe2011-09-28 16:38:44 -07003305 ret = intel_dp_get_edid_modes(connector, &intel_dp->adapter);
Imre Deak671dedd2014-03-05 16:20:53 +02003306 intel_display_power_put(dev_priv, power_domain);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03003307 if (ret)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003308 return ret;
3309
Jani Nikulaf8779fd2012-10-19 14:51:48 +03003310 /* if eDP has no EDID, fall back to fixed mode */
Jani Nikuladd06f902012-10-19 14:51:50 +03003311 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03003312 struct drm_display_mode *mode;
Jani Nikuladd06f902012-10-19 14:51:50 +03003313 mode = drm_mode_duplicate(dev,
3314 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03003315 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003316 drm_mode_probed_add(connector, mode);
3317 return 1;
3318 }
3319 }
3320 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003321}
3322
Chris Wilson1aad7ac2011-02-09 18:46:58 +00003323static bool
3324intel_dp_detect_audio(struct drm_connector *connector)
3325{
3326 struct intel_dp *intel_dp = intel_attached_dp(connector);
Imre Deak671dedd2014-03-05 16:20:53 +02003327 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3328 struct intel_encoder *intel_encoder = &intel_dig_port->base;
3329 struct drm_device *dev = connector->dev;
3330 struct drm_i915_private *dev_priv = dev->dev_private;
3331 enum intel_display_power_domain power_domain;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00003332 struct edid *edid;
3333 bool has_audio = false;
3334
Imre Deak671dedd2014-03-05 16:20:53 +02003335 power_domain = intel_display_port_power_domain(intel_encoder);
3336 intel_display_power_get(dev_priv, power_domain);
3337
Keith Packard8c241fe2011-09-28 16:38:44 -07003338 edid = intel_dp_get_edid(connector, &intel_dp->adapter);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00003339 if (edid) {
3340 has_audio = drm_detect_monitor_audio(edid);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00003341 kfree(edid);
3342 }
3343
Imre Deak671dedd2014-03-05 16:20:53 +02003344 intel_display_power_put(dev_priv, power_domain);
3345
Chris Wilson1aad7ac2011-02-09 18:46:58 +00003346 return has_audio;
3347}
3348
Chris Wilsonf6849602010-09-19 09:29:33 +01003349static int
3350intel_dp_set_property(struct drm_connector *connector,
3351 struct drm_property *property,
3352 uint64_t val)
3353{
Chris Wilsone953fd72011-02-21 22:23:52 +00003354 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Yuly Novikov53b41832012-10-26 12:04:00 +03003355 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003356 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
3357 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01003358 int ret;
3359
Rob Clark662595d2012-10-11 20:36:04 -05003360 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01003361 if (ret)
3362 return ret;
3363
Chris Wilson3f43c482011-05-12 22:17:24 +01003364 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00003365 int i = val;
3366 bool has_audio;
3367
3368 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01003369 return 0;
3370
Chris Wilson1aad7ac2011-02-09 18:46:58 +00003371 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01003372
Daniel Vetterc3e5f672012-02-23 17:14:47 +01003373 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00003374 has_audio = intel_dp_detect_audio(connector);
3375 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01003376 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00003377
3378 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01003379 return 0;
3380
Chris Wilson1aad7ac2011-02-09 18:46:58 +00003381 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01003382 goto done;
3383 }
3384
Chris Wilsone953fd72011-02-21 22:23:52 +00003385 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02003386 bool old_auto = intel_dp->color_range_auto;
3387 uint32_t old_range = intel_dp->color_range;
3388
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02003389 switch (val) {
3390 case INTEL_BROADCAST_RGB_AUTO:
3391 intel_dp->color_range_auto = true;
3392 break;
3393 case INTEL_BROADCAST_RGB_FULL:
3394 intel_dp->color_range_auto = false;
3395 intel_dp->color_range = 0;
3396 break;
3397 case INTEL_BROADCAST_RGB_LIMITED:
3398 intel_dp->color_range_auto = false;
3399 intel_dp->color_range = DP_COLOR_RANGE_16_235;
3400 break;
3401 default:
3402 return -EINVAL;
3403 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02003404
3405 if (old_auto == intel_dp->color_range_auto &&
3406 old_range == intel_dp->color_range)
3407 return 0;
3408
Chris Wilsone953fd72011-02-21 22:23:52 +00003409 goto done;
3410 }
3411
Yuly Novikov53b41832012-10-26 12:04:00 +03003412 if (is_edp(intel_dp) &&
3413 property == connector->dev->mode_config.scaling_mode_property) {
3414 if (val == DRM_MODE_SCALE_NONE) {
3415 DRM_DEBUG_KMS("no scaling not supported\n");
3416 return -EINVAL;
3417 }
3418
3419 if (intel_connector->panel.fitting_mode == val) {
3420 /* the eDP scaling property is not changed */
3421 return 0;
3422 }
3423 intel_connector->panel.fitting_mode = val;
3424
3425 goto done;
3426 }
3427
Chris Wilsonf6849602010-09-19 09:29:33 +01003428 return -EINVAL;
3429
3430done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00003431 if (intel_encoder->base.crtc)
3432 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01003433
3434 return 0;
3435}
3436
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003437static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03003438intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003439{
Jani Nikula1d508702012-10-19 14:51:49 +03003440 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02003441
Jani Nikula9cd300e2012-10-19 14:51:52 +03003442 if (!IS_ERR_OR_NULL(intel_connector->edid))
3443 kfree(intel_connector->edid);
3444
Paulo Zanoniacd8db102013-06-12 17:27:23 -03003445 /* Can't call is_edp() since the encoder may have been destroyed
3446 * already. */
3447 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03003448 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02003449
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003450 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08003451 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003452}
3453
Paulo Zanoni00c09d72012-10-26 19:05:52 -02003454void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02003455{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003456 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
3457 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetterbd173812013-03-25 11:24:10 +01003458 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Daniel Vetter24d05922010-08-20 18:08:28 +02003459
3460 i2c_del_adapter(&intel_dp->adapter);
3461 drm_encoder_cleanup(encoder);
Keith Packardbd943152011-09-18 23:09:52 -07003462 if (is_edp(intel_dp)) {
3463 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Daniel Vetterbd173812013-03-25 11:24:10 +01003464 mutex_lock(&dev->mode_config.mutex);
Daniel Vetter4be73782014-01-17 14:39:48 +01003465 edp_panel_vdd_off_sync(intel_dp);
Daniel Vetterbd173812013-03-25 11:24:10 +01003466 mutex_unlock(&dev->mode_config.mutex);
Keith Packardbd943152011-09-18 23:09:52 -07003467 }
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003468 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02003469}
3470
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003471static const struct drm_connector_funcs intel_dp_connector_funcs = {
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02003472 .dpms = intel_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003473 .detect = intel_dp_detect,
3474 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01003475 .set_property = intel_dp_set_property,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03003476 .destroy = intel_dp_connector_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003477};
3478
3479static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
3480 .get_modes = intel_dp_get_modes,
3481 .mode_valid = intel_dp_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +01003482 .best_encoder = intel_best_encoder,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003483};
3484
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003485static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Daniel Vetter24d05922010-08-20 18:08:28 +02003486 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003487};
3488
Chris Wilson995b67622010-08-20 13:23:26 +01003489static void
Eric Anholt21d40d32010-03-25 11:11:14 -07003490intel_dp_hot_plug(struct intel_encoder *intel_encoder)
Keith Packardc8110e52009-05-06 11:51:10 -07003491{
Paulo Zanonifa90ece2012-10-26 19:05:44 -02003492 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Keith Packardc8110e52009-05-06 11:51:10 -07003493
Jesse Barnes885a5012011-07-07 11:11:01 -07003494 intel_dp_check_link_status(intel_dp);
Keith Packardc8110e52009-05-06 11:51:10 -07003495}
3496
Zhenyu Wange3421a12010-04-08 09:43:27 +08003497/* Return which DP Port should be selected for Transcoder DP control */
3498int
Akshay Joshi0206e352011-08-16 15:34:10 -04003499intel_trans_dp_port_sel(struct drm_crtc *crtc)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003500{
3501 struct drm_device *dev = crtc->dev;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02003502 struct intel_encoder *intel_encoder;
3503 struct intel_dp *intel_dp;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003504
Paulo Zanonifa90ece2012-10-26 19:05:44 -02003505 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
3506 intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003507
Paulo Zanonifa90ece2012-10-26 19:05:44 -02003508 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
3509 intel_encoder->type == INTEL_OUTPUT_EDP)
Chris Wilsonea5b2132010-08-04 13:50:23 +01003510 return intel_dp->output_reg;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003511 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01003512
Zhenyu Wange3421a12010-04-08 09:43:27 +08003513 return -1;
3514}
3515
Zhao Yakui36e83a12010-06-12 14:32:21 +08003516/* check the VBT to see whether the eDP is on DP-D port */
Ville Syrjälä5d8a7752013-11-01 18:22:39 +02003517bool intel_dp_is_edp(struct drm_device *dev, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08003518{
3519 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni768f69c2013-09-11 18:02:47 -03003520 union child_device_config *p_child;
Zhao Yakui36e83a12010-06-12 14:32:21 +08003521 int i;
Ville Syrjälä5d8a7752013-11-01 18:22:39 +02003522 static const short port_mapping[] = {
3523 [PORT_B] = PORT_IDPB,
3524 [PORT_C] = PORT_IDPC,
3525 [PORT_D] = PORT_IDPD,
3526 };
Zhao Yakui36e83a12010-06-12 14:32:21 +08003527
Ville Syrjälä3b32a352013-11-01 18:22:41 +02003528 if (port == PORT_A)
3529 return true;
3530
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03003531 if (!dev_priv->vbt.child_dev_num)
Zhao Yakui36e83a12010-06-12 14:32:21 +08003532 return false;
3533
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03003534 for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
3535 p_child = dev_priv->vbt.child_dev + i;
Zhao Yakui36e83a12010-06-12 14:32:21 +08003536
Ville Syrjälä5d8a7752013-11-01 18:22:39 +02003537 if (p_child->common.dvo_port == port_mapping[port] &&
Ville Syrjäläf02586d2013-11-01 20:32:08 +02003538 (p_child->common.device_type & DEVICE_TYPE_eDP_BITS) ==
3539 (DEVICE_TYPE_eDP & DEVICE_TYPE_eDP_BITS))
Zhao Yakui36e83a12010-06-12 14:32:21 +08003540 return true;
3541 }
3542 return false;
3543}
3544
Chris Wilsonf6849602010-09-19 09:29:33 +01003545static void
3546intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
3547{
Yuly Novikov53b41832012-10-26 12:04:00 +03003548 struct intel_connector *intel_connector = to_intel_connector(connector);
3549
Chris Wilson3f43c482011-05-12 22:17:24 +01003550 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00003551 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02003552 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03003553
3554 if (is_edp(intel_dp)) {
3555 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05003556 drm_object_attach_property(
3557 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03003558 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03003559 DRM_MODE_SCALE_ASPECT);
3560 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03003561 }
Chris Wilsonf6849602010-09-19 09:29:33 +01003562}
3563
Imre Deakdada1a92014-01-29 13:25:41 +02003564static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
3565{
3566 intel_dp->last_power_cycle = jiffies;
3567 intel_dp->last_power_on = jiffies;
3568 intel_dp->last_backlight_off = jiffies;
3569}
3570
Daniel Vetter67a54562012-10-20 20:57:45 +02003571static void
3572intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Jani Nikulaf30d26e2013-01-16 10:53:40 +02003573 struct intel_dp *intel_dp,
3574 struct edp_power_seq *out)
Daniel Vetter67a54562012-10-20 20:57:45 +02003575{
3576 struct drm_i915_private *dev_priv = dev->dev_private;
3577 struct edp_power_seq cur, vbt, spec, final;
3578 u32 pp_on, pp_off, pp_div, pp;
Jani Nikulabf13e812013-09-06 07:40:05 +03003579 int pp_ctrl_reg, pp_on_reg, pp_off_reg, pp_div_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07003580
3581 if (HAS_PCH_SPLIT(dev)) {
Jani Nikulabf13e812013-09-06 07:40:05 +03003582 pp_ctrl_reg = PCH_PP_CONTROL;
Jesse Barnes453c5422013-03-28 09:55:41 -07003583 pp_on_reg = PCH_PP_ON_DELAYS;
3584 pp_off_reg = PCH_PP_OFF_DELAYS;
3585 pp_div_reg = PCH_PP_DIVISOR;
3586 } else {
Jani Nikulabf13e812013-09-06 07:40:05 +03003587 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
3588
3589 pp_ctrl_reg = VLV_PIPE_PP_CONTROL(pipe);
3590 pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe);
3591 pp_off_reg = VLV_PIPE_PP_OFF_DELAYS(pipe);
3592 pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe);
Jesse Barnes453c5422013-03-28 09:55:41 -07003593 }
Daniel Vetter67a54562012-10-20 20:57:45 +02003594
3595 /* Workaround: Need to write PP_CONTROL with the unlock key as
3596 * the very first thing. */
Jesse Barnes453c5422013-03-28 09:55:41 -07003597 pp = ironlake_get_pp_control(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +03003598 I915_WRITE(pp_ctrl_reg, pp);
Daniel Vetter67a54562012-10-20 20:57:45 +02003599
Jesse Barnes453c5422013-03-28 09:55:41 -07003600 pp_on = I915_READ(pp_on_reg);
3601 pp_off = I915_READ(pp_off_reg);
3602 pp_div = I915_READ(pp_div_reg);
Daniel Vetter67a54562012-10-20 20:57:45 +02003603
3604 /* Pull timing values out of registers */
3605 cur.t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
3606 PANEL_POWER_UP_DELAY_SHIFT;
3607
3608 cur.t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
3609 PANEL_LIGHT_ON_DELAY_SHIFT;
3610
3611 cur.t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
3612 PANEL_LIGHT_OFF_DELAY_SHIFT;
3613
3614 cur.t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
3615 PANEL_POWER_DOWN_DELAY_SHIFT;
3616
3617 cur.t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
3618 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
3619
3620 DRM_DEBUG_KMS("cur t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
3621 cur.t1_t3, cur.t8, cur.t9, cur.t10, cur.t11_t12);
3622
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03003623 vbt = dev_priv->vbt.edp_pps;
Daniel Vetter67a54562012-10-20 20:57:45 +02003624
3625 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
3626 * our hw here, which are all in 100usec. */
3627 spec.t1_t3 = 210 * 10;
3628 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
3629 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
3630 spec.t10 = 500 * 10;
3631 /* This one is special and actually in units of 100ms, but zero
3632 * based in the hw (so we need to add 100 ms). But the sw vbt
3633 * table multiplies it with 1000 to make it in units of 100usec,
3634 * too. */
3635 spec.t11_t12 = (510 + 100) * 10;
3636
3637 DRM_DEBUG_KMS("vbt t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
3638 vbt.t1_t3, vbt.t8, vbt.t9, vbt.t10, vbt.t11_t12);
3639
3640 /* Use the max of the register settings and vbt. If both are
3641 * unset, fall back to the spec limits. */
3642#define assign_final(field) final.field = (max(cur.field, vbt.field) == 0 ? \
3643 spec.field : \
3644 max(cur.field, vbt.field))
3645 assign_final(t1_t3);
3646 assign_final(t8);
3647 assign_final(t9);
3648 assign_final(t10);
3649 assign_final(t11_t12);
3650#undef assign_final
3651
3652#define get_delay(field) (DIV_ROUND_UP(final.field, 10))
3653 intel_dp->panel_power_up_delay = get_delay(t1_t3);
3654 intel_dp->backlight_on_delay = get_delay(t8);
3655 intel_dp->backlight_off_delay = get_delay(t9);
3656 intel_dp->panel_power_down_delay = get_delay(t10);
3657 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
3658#undef get_delay
3659
Jani Nikulaf30d26e2013-01-16 10:53:40 +02003660 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
3661 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
3662 intel_dp->panel_power_cycle_delay);
3663
3664 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
3665 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
3666
3667 if (out)
3668 *out = final;
3669}
3670
3671static void
3672intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
3673 struct intel_dp *intel_dp,
3674 struct edp_power_seq *seq)
3675{
3676 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes453c5422013-03-28 09:55:41 -07003677 u32 pp_on, pp_off, pp_div, port_sel = 0;
3678 int div = HAS_PCH_SPLIT(dev) ? intel_pch_rawclk(dev) : intel_hrawclk(dev);
3679 int pp_on_reg, pp_off_reg, pp_div_reg;
3680
3681 if (HAS_PCH_SPLIT(dev)) {
3682 pp_on_reg = PCH_PP_ON_DELAYS;
3683 pp_off_reg = PCH_PP_OFF_DELAYS;
3684 pp_div_reg = PCH_PP_DIVISOR;
3685 } else {
Jani Nikulabf13e812013-09-06 07:40:05 +03003686 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
3687
3688 pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe);
3689 pp_off_reg = VLV_PIPE_PP_OFF_DELAYS(pipe);
3690 pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe);
Jesse Barnes453c5422013-03-28 09:55:41 -07003691 }
3692
Paulo Zanonib2f19d12013-12-19 14:29:44 -02003693 /*
3694 * And finally store the new values in the power sequencer. The
3695 * backlight delays are set to 1 because we do manual waits on them. For
3696 * T8, even BSpec recommends doing it. For T9, if we don't do this,
3697 * we'll end up waiting for the backlight off delay twice: once when we
3698 * do the manual sleep, and once when we disable the panel and wait for
3699 * the PP_STATUS bit to become zero.
3700 */
Jani Nikulaf30d26e2013-01-16 10:53:40 +02003701 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Paulo Zanonib2f19d12013-12-19 14:29:44 -02003702 (1 << PANEL_LIGHT_ON_DELAY_SHIFT);
3703 pp_off = (1 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02003704 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02003705 /* Compute the divisor for the pp clock, simply match the Bspec
3706 * formula. */
Jesse Barnes453c5422013-03-28 09:55:41 -07003707 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02003708 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
Daniel Vetter67a54562012-10-20 20:57:45 +02003709 << PANEL_POWER_CYCLE_DELAY_SHIFT);
3710
3711 /* Haswell doesn't have any port selection bits for the panel
3712 * power sequencer any more. */
Imre Deakbc7d38a2013-05-16 14:40:36 +03003713 if (IS_VALLEYVIEW(dev)) {
Jani Nikulabf13e812013-09-06 07:40:05 +03003714 if (dp_to_dig_port(intel_dp)->port == PORT_B)
3715 port_sel = PANEL_PORT_SELECT_DPB_VLV;
3716 else
3717 port_sel = PANEL_PORT_SELECT_DPC_VLV;
Imre Deakbc7d38a2013-05-16 14:40:36 +03003718 } else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) {
3719 if (dp_to_dig_port(intel_dp)->port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03003720 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02003721 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03003722 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02003723 }
3724
Jesse Barnes453c5422013-03-28 09:55:41 -07003725 pp_on |= port_sel;
3726
3727 I915_WRITE(pp_on_reg, pp_on);
3728 I915_WRITE(pp_off_reg, pp_off);
3729 I915_WRITE(pp_div_reg, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02003730
Daniel Vetter67a54562012-10-20 20:57:45 +02003731 DRM_DEBUG_KMS("panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07003732 I915_READ(pp_on_reg),
3733 I915_READ(pp_off_reg),
3734 I915_READ(pp_div_reg));
Keith Packardc8110e52009-05-06 11:51:10 -07003735}
3736
Paulo Zanonied92f0b2013-06-12 17:27:24 -03003737static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Paulo Zanoni0095e6d2013-12-19 14:29:39 -02003738 struct intel_connector *intel_connector,
3739 struct edp_power_seq *power_seq)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03003740{
3741 struct drm_connector *connector = &intel_connector->base;
3742 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3743 struct drm_device *dev = intel_dig_port->base.base.dev;
3744 struct drm_i915_private *dev_priv = dev->dev_private;
3745 struct drm_display_mode *fixed_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03003746 bool has_dpcd;
3747 struct drm_display_mode *scan;
3748 struct edid *edid;
3749
3750 if (!is_edp(intel_dp))
3751 return true;
3752
Paulo Zanonied92f0b2013-06-12 17:27:24 -03003753 /* Cache DPCD and EDID for edp. */
Daniel Vetter4be73782014-01-17 14:39:48 +01003754 edp_panel_vdd_on(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03003755 has_dpcd = intel_dp_get_dpcd(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01003756 edp_panel_vdd_off(intel_dp, false);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03003757
3758 if (has_dpcd) {
3759 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3760 dev_priv->no_aux_handshake =
3761 intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3762 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3763 } else {
3764 /* if this fails, presume the device is a ghost */
3765 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Paulo Zanonied92f0b2013-06-12 17:27:24 -03003766 return false;
3767 }
3768
3769 /* We now know it's not a ghost, init power sequence regs. */
Paulo Zanoni0095e6d2013-12-19 14:29:39 -02003770 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, power_seq);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03003771
Paulo Zanonied92f0b2013-06-12 17:27:24 -03003772 edid = drm_get_edid(connector, &intel_dp->adapter);
3773 if (edid) {
3774 if (drm_add_edid_modes(connector, edid)) {
3775 drm_mode_connector_update_edid_property(connector,
3776 edid);
3777 drm_edid_to_eld(connector, edid);
3778 } else {
3779 kfree(edid);
3780 edid = ERR_PTR(-EINVAL);
3781 }
3782 } else {
3783 edid = ERR_PTR(-ENOENT);
3784 }
3785 intel_connector->edid = edid;
3786
3787 /* prefer fixed mode from EDID if available */
3788 list_for_each_entry(scan, &connector->probed_modes, head) {
3789 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
3790 fixed_mode = drm_mode_duplicate(dev, scan);
3791 break;
3792 }
3793 }
3794
3795 /* fallback to VBT if available for eDP */
3796 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
3797 fixed_mode = drm_mode_duplicate(dev,
3798 dev_priv->vbt.lfp_lvds_vbt_mode);
3799 if (fixed_mode)
3800 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
3801 }
3802
Vandana Kannan4b6ed682014-02-11 14:26:36 +05303803 intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03003804 intel_panel_setup_backlight(connector);
3805
3806 return true;
3807}
3808
Paulo Zanoni16c25532013-06-12 17:27:25 -03003809bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003810intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
3811 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003812{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003813 struct drm_connector *connector = &intel_connector->base;
3814 struct intel_dp *intel_dp = &intel_dig_port->dp;
3815 struct intel_encoder *intel_encoder = &intel_dig_port->base;
3816 struct drm_device *dev = intel_encoder->base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003817 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -02003818 enum port port = intel_dig_port->port;
Paulo Zanoni0095e6d2013-12-19 14:29:39 -02003819 struct edp_power_seq power_seq = { 0 };
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003820 const char *name = NULL;
Paulo Zanonib2a14752013-06-12 17:27:28 -03003821 int type, error;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003822
Damien Lespiauec5b01d2014-01-21 13:35:39 +00003823 /* intel_dp vfuncs */
3824 if (IS_VALLEYVIEW(dev))
3825 intel_dp->get_aux_clock_divider = vlv_get_aux_clock_divider;
3826 else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
3827 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
3828 else if (HAS_PCH_SPLIT(dev))
3829 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
3830 else
3831 intel_dp->get_aux_clock_divider = i9xx_get_aux_clock_divider;
3832
Damien Lespiau153b1102014-01-21 13:37:15 +00003833 intel_dp->get_aux_send_ctl = i9xx_get_aux_send_ctl;
3834
Daniel Vetter07679352012-09-06 22:15:42 +02003835 /* Preserve the current hw state. */
3836 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03003837 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00003838
Ville Syrjälä3b32a352013-11-01 18:22:41 +02003839 if (intel_dp_is_edp(dev, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05303840 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02003841 else
3842 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04003843
Imre Deakf7d24902013-05-08 13:14:05 +03003844 /*
3845 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
3846 * for DP the encoder type can be set by the caller to
3847 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
3848 */
3849 if (type == DRM_MODE_CONNECTOR_eDP)
3850 intel_encoder->type = INTEL_OUTPUT_EDP;
3851
Imre Deake7281ea2013-05-08 13:14:08 +03003852 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
3853 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
3854 port_name(port));
3855
Adam Jacksonb3295302010-07-16 14:46:28 -04003856 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003857 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
3858
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003859 connector->interlace_allowed = true;
3860 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08003861
Daniel Vetter66a92782012-07-12 20:08:18 +02003862 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01003863 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08003864
Chris Wilsondf0e9242010-09-09 16:20:55 +01003865 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003866 drm_sysfs_connector_add(connector);
3867
Paulo Zanoniaffa9352012-11-23 15:30:39 -02003868 if (HAS_DDI(dev))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02003869 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
3870 else
3871 intel_connector->get_hw_state = intel_connector_get_hw_state;
Imre Deak80f65de2014-02-11 17:12:49 +02003872 intel_connector->unregister = intel_dp_connector_unregister;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02003873
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003874 /* Set up the DDC bus. */
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03003875 switch (port) {
3876 case PORT_A:
Egbert Eich1d843f92013-02-25 12:06:49 -05003877 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03003878 name = "DPDDC-A";
3879 break;
3880 case PORT_B:
Egbert Eich1d843f92013-02-25 12:06:49 -05003881 intel_encoder->hpd_pin = HPD_PORT_B;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03003882 name = "DPDDC-B";
3883 break;
3884 case PORT_C:
Egbert Eich1d843f92013-02-25 12:06:49 -05003885 intel_encoder->hpd_pin = HPD_PORT_C;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03003886 name = "DPDDC-C";
3887 break;
3888 case PORT_D:
Egbert Eich1d843f92013-02-25 12:06:49 -05003889 intel_encoder->hpd_pin = HPD_PORT_D;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03003890 name = "DPDDC-D";
3891 break;
3892 default:
Damien Lespiauad1c0b12013-03-07 15:30:28 +00003893 BUG();
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003894 }
3895
Imre Deakdada1a92014-01-29 13:25:41 +02003896 if (is_edp(intel_dp)) {
3897 intel_dp_init_panel_power_timestamps(intel_dp);
Paulo Zanoni0095e6d2013-12-19 14:29:39 -02003898 intel_dp_init_panel_power_sequencer(dev, intel_dp, &power_seq);
Imre Deakdada1a92014-01-29 13:25:41 +02003899 }
Paulo Zanoni0095e6d2013-12-19 14:29:39 -02003900
Jani Nikula9d1a1032014-03-14 16:51:15 +02003901 intel_dp_aux_init(intel_dp, intel_connector);
3902
Paulo Zanonib2a14752013-06-12 17:27:28 -03003903 error = intel_dp_i2c_init(intel_dp, intel_connector, name);
3904 WARN(error, "intel_dp_i2c_init failed with error %d for port %c\n",
3905 error, port_name(port));
Dave Airliec1f05262012-08-30 11:06:18 +10003906
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03003907 intel_dp->psr_setup_done = false;
3908
Paulo Zanoni0095e6d2013-12-19 14:29:39 -02003909 if (!intel_edp_init_connector(intel_dp, intel_connector, &power_seq)) {
Paulo Zanoni15b1d172013-06-12 17:27:27 -03003910 i2c_del_adapter(&intel_dp->adapter);
3911 if (is_edp(intel_dp)) {
3912 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
3913 mutex_lock(&dev->mode_config.mutex);
Daniel Vetter4be73782014-01-17 14:39:48 +01003914 edp_panel_vdd_off_sync(intel_dp);
Paulo Zanoni15b1d172013-06-12 17:27:27 -03003915 mutex_unlock(&dev->mode_config.mutex);
3916 }
Paulo Zanonib2f246a2013-06-12 17:27:26 -03003917 drm_sysfs_connector_remove(connector);
3918 drm_connector_cleanup(connector);
Paulo Zanoni16c25532013-06-12 17:27:25 -03003919 return false;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03003920 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003921
Chris Wilsonf6849602010-09-19 09:29:33 +01003922 intel_dp_add_properties(intel_dp, connector);
3923
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003924 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
3925 * 0xd. Failure to do so will result in spurious interrupts being
3926 * generated on the port when a cable is not attached.
3927 */
3928 if (IS_G4X(dev) && !IS_GM45(dev)) {
3929 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
3930 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
3931 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03003932
3933 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003934}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003935
3936void
3937intel_dp_init(struct drm_device *dev, int output_reg, enum port port)
3938{
3939 struct intel_digital_port *intel_dig_port;
3940 struct intel_encoder *intel_encoder;
3941 struct drm_encoder *encoder;
3942 struct intel_connector *intel_connector;
3943
Daniel Vetterb14c5672013-09-19 12:18:32 +02003944 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003945 if (!intel_dig_port)
3946 return;
3947
Daniel Vetterb14c5672013-09-19 12:18:32 +02003948 intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003949 if (!intel_connector) {
3950 kfree(intel_dig_port);
3951 return;
3952 }
3953
3954 intel_encoder = &intel_dig_port->base;
3955 encoder = &intel_encoder->base;
3956
3957 drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
3958 DRM_MODE_ENCODER_TMDS);
3959
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01003960 intel_encoder->compute_config = intel_dp_compute_config;
Daniel Vetterb934223d2013-07-21 21:37:05 +02003961 intel_encoder->mode_set = intel_dp_mode_set;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02003962 intel_encoder->disable = intel_disable_dp;
3963 intel_encoder->post_disable = intel_post_disable_dp;
3964 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07003965 intel_encoder->get_config = intel_dp_get_config;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03003966 if (IS_VALLEYVIEW(dev)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03003967 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03003968 intel_encoder->pre_enable = vlv_pre_enable_dp;
3969 intel_encoder->enable = vlv_enable_dp;
3970 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03003971 intel_encoder->pre_enable = g4x_pre_enable_dp;
3972 intel_encoder->enable = g4x_enable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03003973 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003974
Paulo Zanoni174edf12012-10-26 19:05:50 -02003975 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003976 intel_dig_port->dp.output_reg = output_reg;
3977
Paulo Zanoni00c09d72012-10-26 19:05:52 -02003978 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003979 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
3980 intel_encoder->cloneable = false;
3981 intel_encoder->hot_plug = intel_dp_hot_plug;
3982
Paulo Zanoni15b1d172013-06-12 17:27:27 -03003983 if (!intel_dp_init_connector(intel_dig_port, intel_connector)) {
3984 drm_encoder_cleanup(encoder);
3985 kfree(intel_dig_port);
Paulo Zanonib2f246a2013-06-12 17:27:26 -03003986 kfree(intel_connector);
Paulo Zanoni15b1d172013-06-12 17:27:27 -03003987 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003988}