blob: 3fec49b91d25eccb93e5d37711a4c2ba13f62011 [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);
Keith Packarda4fc5ed2009-04-07 16:16:42 -070094
95static int
Chris Wilsonea5b2132010-08-04 13:50:23 +010096intel_dp_max_link_bw(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -070097{
Jesse Barnes7183dc22011-07-07 11:10:58 -070098 int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
Keith Packarda4fc5ed2009-04-07 16:16:42 -070099
100 switch (max_link_bw) {
101 case DP_LINK_BW_1_62:
102 case DP_LINK_BW_2_7:
103 break;
Imre Deakd4eead52013-07-09 17:05:26 +0300104 case DP_LINK_BW_5_4: /* 1.2 capable displays may advertise higher bw */
105 max_link_bw = DP_LINK_BW_2_7;
106 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700107 default:
Imre Deakd4eead52013-07-09 17:05:26 +0300108 WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
109 max_link_bw);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700110 max_link_bw = DP_LINK_BW_1_62;
111 break;
112 }
113 return max_link_bw;
114}
115
Adam Jacksoncd9dde42011-10-14 12:43:49 -0400116/*
117 * The units on the numbers in the next two are... bizarre. Examples will
118 * make it clearer; this one parallels an example in the eDP spec.
119 *
120 * intel_dp_max_data_rate for one lane of 2.7GHz evaluates as:
121 *
122 * 270000 * 1 * 8 / 10 == 216000
123 *
124 * The actual data capacity of that configuration is 2.16Gbit/s, so the
125 * units are decakilobits. ->clock in a drm_display_mode is in kilohertz -
126 * or equivalently, kilopixels per second - so for 1680x1050R it'd be
127 * 119000. At 18bpp that's 2142000 kilobits per second.
128 *
129 * Thus the strange-looking division by 10 in intel_dp_link_required, to
130 * get the result in decakilobits instead of kilobits.
131 */
132
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700133static int
Keith Packardc8982612012-01-25 08:16:25 -0800134intel_dp_link_required(int pixel_clock, int bpp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700135{
Adam Jacksoncd9dde42011-10-14 12:43:49 -0400136 return (pixel_clock * bpp + 9) / 10;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700137}
138
139static int
Dave Airliefe27d532010-06-30 11:46:17 +1000140intel_dp_max_data_rate(int max_link_clock, int max_lanes)
141{
142 return (max_link_clock * max_lanes * 8) / 10;
143}
144
145static int
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700146intel_dp_mode_valid(struct drm_connector *connector,
147 struct drm_display_mode *mode)
148{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100149 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300150 struct intel_connector *intel_connector = to_intel_connector(connector);
151 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Daniel Vetter36008362013-03-27 00:44:59 +0100152 int target_clock = mode->clock;
153 int max_rate, mode_rate, max_lanes, max_link_clock;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700154
Jani Nikuladd06f902012-10-19 14:51:50 +0300155 if (is_edp(intel_dp) && fixed_mode) {
156 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100157 return MODE_PANEL;
158
Jani Nikuladd06f902012-10-19 14:51:50 +0300159 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100160 return MODE_PANEL;
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200161
162 target_clock = fixed_mode->clock;
Zhao Yakui7de56f42010-07-19 09:43:14 +0100163 }
164
Daniel Vetter36008362013-03-27 00:44:59 +0100165 max_link_clock = drm_dp_bw_code_to_link_rate(intel_dp_max_link_bw(intel_dp));
166 max_lanes = drm_dp_max_lane_count(intel_dp->dpcd);
167
168 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
169 mode_rate = intel_dp_link_required(target_clock, 18);
170
171 if (mode_rate > max_rate)
Daniel Vetterc4867932012-04-10 10:42:36 +0200172 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700173
174 if (mode->clock < 10000)
175 return MODE_CLOCK_LOW;
176
Daniel Vetter0af78a22012-05-23 11:30:55 +0200177 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
178 return MODE_H_ILLEGAL;
179
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700180 return MODE_OK;
181}
182
183static uint32_t
184pack_aux(uint8_t *src, int src_bytes)
185{
186 int i;
187 uint32_t v = 0;
188
189 if (src_bytes > 4)
190 src_bytes = 4;
191 for (i = 0; i < src_bytes; i++)
192 v |= ((uint32_t) src[i]) << ((3-i) * 8);
193 return v;
194}
195
196static void
197unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
198{
199 int i;
200 if (dst_bytes > 4)
201 dst_bytes = 4;
202 for (i = 0; i < dst_bytes; i++)
203 dst[i] = src >> ((3-i) * 8);
204}
205
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700206/* hrawclock is 1/4 the FSB frequency */
207static int
208intel_hrawclk(struct drm_device *dev)
209{
210 struct drm_i915_private *dev_priv = dev->dev_private;
211 uint32_t clkcfg;
212
Vijay Purushothaman9473c8f2012-09-27 19:13:01 +0530213 /* There is no CLKCFG reg in Valleyview. VLV hrawclk is 200 MHz */
214 if (IS_VALLEYVIEW(dev))
215 return 200;
216
Keith Packardfb0f8fb2009-06-11 22:31:31 -0700217 clkcfg = I915_READ(CLKCFG);
218 switch (clkcfg & CLKCFG_FSB_MASK) {
219 case CLKCFG_FSB_400:
220 return 100;
221 case CLKCFG_FSB_533:
222 return 133;
223 case CLKCFG_FSB_667:
224 return 166;
225 case CLKCFG_FSB_800:
226 return 200;
227 case CLKCFG_FSB_1067:
228 return 266;
229 case CLKCFG_FSB_1333:
230 return 333;
231 /* these two are just a guess; one of them might be right */
232 case CLKCFG_FSB_1600:
233 case CLKCFG_FSB_1600_ALT:
234 return 400;
235 default:
236 return 133;
237 }
238}
239
Jani Nikulabf13e812013-09-06 07:40:05 +0300240static void
241intel_dp_init_panel_power_sequencer(struct drm_device *dev,
242 struct intel_dp *intel_dp,
243 struct edp_power_seq *out);
244static void
245intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
246 struct intel_dp *intel_dp,
247 struct edp_power_seq *out);
248
249static enum pipe
250vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
251{
252 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
253 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
254 struct drm_device *dev = intel_dig_port->base.base.dev;
255 struct drm_i915_private *dev_priv = dev->dev_private;
256 enum port port = intel_dig_port->port;
257 enum pipe pipe;
258
259 /* modeset should have pipe */
260 if (crtc)
261 return to_intel_crtc(crtc)->pipe;
262
263 /* init time, try to find a pipe with this port selected */
264 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
265 u32 port_sel = I915_READ(VLV_PIPE_PP_ON_DELAYS(pipe)) &
266 PANEL_PORT_SELECT_MASK;
267 if (port_sel == PANEL_PORT_SELECT_DPB_VLV && port == PORT_B)
268 return pipe;
269 if (port_sel == PANEL_PORT_SELECT_DPC_VLV && port == PORT_C)
270 return pipe;
271 }
272
273 /* shrug */
274 return PIPE_A;
275}
276
277static u32 _pp_ctrl_reg(struct intel_dp *intel_dp)
278{
279 struct drm_device *dev = intel_dp_to_dev(intel_dp);
280
281 if (HAS_PCH_SPLIT(dev))
282 return PCH_PP_CONTROL;
283 else
284 return VLV_PIPE_PP_CONTROL(vlv_power_sequencer_pipe(intel_dp));
285}
286
287static u32 _pp_stat_reg(struct intel_dp *intel_dp)
288{
289 struct drm_device *dev = intel_dp_to_dev(intel_dp);
290
291 if (HAS_PCH_SPLIT(dev))
292 return PCH_PP_STATUS;
293 else
294 return VLV_PIPE_PP_STATUS(vlv_power_sequencer_pipe(intel_dp));
295}
296
Keith Packardebf33b12011-09-29 15:53:27 -0700297static bool ironlake_edp_have_panel_power(struct intel_dp *intel_dp)
298{
Paulo Zanoni30add222012-10-26 19:05:45 -0200299 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packardebf33b12011-09-29 15:53:27 -0700300 struct drm_i915_private *dev_priv = dev->dev_private;
301
Jani Nikulabf13e812013-09-06 07:40:05 +0300302 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700303}
304
305static bool ironlake_edp_have_panel_vdd(struct intel_dp *intel_dp)
306{
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_ctrl_reg(intel_dp)) & EDP_FORCE_VDD) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700311}
312
Keith Packard9b984da2011-09-19 13:54:47 -0700313static void
314intel_dp_check_edp(struct intel_dp *intel_dp)
315{
Paulo Zanoni30add222012-10-26 19:05:45 -0200316 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packard9b984da2011-09-19 13:54:47 -0700317 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packardebf33b12011-09-29 15:53:27 -0700318
Keith Packard9b984da2011-09-19 13:54:47 -0700319 if (!is_edp(intel_dp))
320 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700321
Keith Packardebf33b12011-09-29 15:53:27 -0700322 if (!ironlake_edp_have_panel_power(intel_dp) && !ironlake_edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700323 WARN(1, "eDP powered off while attempting aux channel communication.\n");
324 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300325 I915_READ(_pp_stat_reg(intel_dp)),
326 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700327 }
328}
329
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100330static uint32_t
331intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
332{
333 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
334 struct drm_device *dev = intel_dig_port->base.base.dev;
335 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni9ed35ab2013-02-18 19:00:25 -0300336 uint32_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100337 uint32_t status;
338 bool done;
339
Daniel Vetteref04f002012-12-01 21:03:59 +0100340#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100341 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300342 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300343 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100344 else
345 done = wait_for_atomic(C, 10) == 0;
346 if (!done)
347 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
348 has_aux_irq);
349#undef C
350
351 return status;
352}
353
Chris Wilsonbc866252013-07-21 16:00:03 +0100354static uint32_t get_aux_clock_divider(struct intel_dp *intel_dp,
355 int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300356{
357 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
358 struct drm_device *dev = intel_dig_port->base.base.dev;
359 struct drm_i915_private *dev_priv = dev->dev_private;
360
361 /* The clock divider is based off the hrawclk,
362 * and would like to run at 2MHz. So, take the
363 * hrawclk value and divide by 2 and use that
364 *
365 * Note that PCH attached eDP panels should use a 125MHz input
366 * clock divider.
367 */
368 if (IS_VALLEYVIEW(dev)) {
Chris Wilsonbc866252013-07-21 16:00:03 +0100369 return index ? 0 : 100;
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300370 } else if (intel_dig_port->port == PORT_A) {
Chris Wilsonbc866252013-07-21 16:00:03 +0100371 if (index)
372 return 0;
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300373 if (HAS_DDI(dev))
Chris Wilsonbc866252013-07-21 16:00:03 +0100374 return DIV_ROUND_CLOSEST(intel_ddi_get_cdclk_freq(dev_priv), 2000);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300375 else if (IS_GEN6(dev) || IS_GEN7(dev))
376 return 200; /* SNB & IVB eDP input clock at 400Mhz */
377 else
378 return 225; /* eDP input clock at 450Mhz */
379 } else if (dev_priv->pch_id == INTEL_PCH_LPT_DEVICE_ID_TYPE) {
380 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100381 switch (index) {
382 case 0: return 63;
383 case 1: return 72;
384 default: return 0;
385 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300386 } else if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonbc866252013-07-21 16:00:03 +0100387 return index ? 0 : DIV_ROUND_UP(intel_pch_rawclk(dev), 2);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300388 } else {
Chris Wilsonbc866252013-07-21 16:00:03 +0100389 return index ? 0 :intel_hrawclk(dev) / 2;
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300390 }
391}
392
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700393static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100394intel_dp_aux_ch(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700395 uint8_t *send, int send_bytes,
396 uint8_t *recv, int recv_size)
397{
Paulo Zanoni174edf12012-10-26 19:05:50 -0200398 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
399 struct drm_device *dev = intel_dig_port->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700400 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni9ed35ab2013-02-18 19:00:25 -0300401 uint32_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700402 uint32_t ch_data = ch_ctl + 4;
Chris Wilsonbc866252013-07-21 16:00:03 +0100403 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100404 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700405 uint32_t status;
Chris Wilsonbc866252013-07-21 16:00:03 +0100406 int try, precharge, clock = 0;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100407 bool has_aux_irq = INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev);
Ben Widawskya81a5072013-11-04 23:11:32 -0800408 uint32_t timeout;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100409
410 /* dp aux is extremely sensitive to irq latency, hence request the
411 * lowest possible wakeup latency and so prevent the cpu from going into
412 * deep sleep states.
413 */
414 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700415
Keith Packard9b984da2011-09-19 13:54:47 -0700416 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +0800417
Daniel Vetter6b4e0a92012-06-14 22:15:00 +0200418 if (IS_GEN6(dev))
419 precharge = 3;
420 else
421 precharge = 5;
422
Ben Widawskya81a5072013-11-04 23:11:32 -0800423 if (IS_BROADWELL(dev) && ch_ctl == DPA_AUX_CH_CTL)
424 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
425 else
426 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
427
Paulo Zanonic67a4702013-08-19 13:18:09 -0300428 intel_aux_display_runtime_get(dev_priv);
429
Jesse Barnes11bee432011-08-01 15:02:20 -0700430 /* Try to wait for any previous AUX channel activity */
431 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +0100432 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -0700433 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
434 break;
435 msleep(1);
436 }
437
438 if (try == 3) {
439 WARN(1, "dp_aux_ch not started status 0x%08x\n",
440 I915_READ(ch_ctl));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100441 ret = -EBUSY;
442 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100443 }
444
Paulo Zanoni46a5ae92013-09-17 11:14:10 -0300445 /* Only 5 data registers! */
446 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
447 ret = -E2BIG;
448 goto out;
449 }
450
Chris Wilsonbc866252013-07-21 16:00:03 +0100451 while ((aux_clock_divider = get_aux_clock_divider(intel_dp, clock++))) {
452 /* Must try at least 3 times according to DP spec */
453 for (try = 0; try < 5; try++) {
454 /* Load the send data into the aux channel data registers */
455 for (i = 0; i < send_bytes; i += 4)
456 I915_WRITE(ch_data + i,
457 pack_aux(send + i, send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -0400458
Chris Wilsonbc866252013-07-21 16:00:03 +0100459 /* Send the command and wait for it to complete */
460 I915_WRITE(ch_ctl,
461 DP_AUX_CH_CTL_SEND_BUSY |
462 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Ben Widawskya81a5072013-11-04 23:11:32 -0800463 timeout |
Chris Wilsonbc866252013-07-21 16:00:03 +0100464 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
465 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
466 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT) |
467 DP_AUX_CH_CTL_DONE |
468 DP_AUX_CH_CTL_TIME_OUT_ERROR |
469 DP_AUX_CH_CTL_RECEIVE_ERROR);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100470
Chris Wilsonbc866252013-07-21 16:00:03 +0100471 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -0400472
Chris Wilsonbc866252013-07-21 16:00:03 +0100473 /* Clear done status and any errors */
474 I915_WRITE(ch_ctl,
475 status |
476 DP_AUX_CH_CTL_DONE |
477 DP_AUX_CH_CTL_TIME_OUT_ERROR |
478 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -0400479
Chris Wilsonbc866252013-07-21 16:00:03 +0100480 if (status & (DP_AUX_CH_CTL_TIME_OUT_ERROR |
481 DP_AUX_CH_CTL_RECEIVE_ERROR))
482 continue;
483 if (status & DP_AUX_CH_CTL_DONE)
484 break;
485 }
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100486 if (status & DP_AUX_CH_CTL_DONE)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700487 break;
488 }
489
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700490 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700491 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100492 ret = -EBUSY;
493 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700494 }
495
496 /* Check for timeout or receive error.
497 * Timeouts occur when the sink is not connected
498 */
Keith Packarda5b3da52009-06-11 22:30:32 -0700499 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700500 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100501 ret = -EIO;
502 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -0700503 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700504
505 /* Timeouts occur when the device isn't connected, so they're
506 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -0700507 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Zhao Yakui28c97732009-10-09 11:39:41 +0800508 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100509 ret = -ETIMEDOUT;
510 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700511 }
512
513 /* Unload any bytes sent back from the other side */
514 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
515 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700516 if (recv_bytes > recv_size)
517 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -0400518
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100519 for (i = 0; i < recv_bytes; i += 4)
520 unpack_aux(I915_READ(ch_data + i),
521 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700522
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100523 ret = recv_bytes;
524out:
525 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
Paulo Zanonic67a4702013-08-19 13:18:09 -0300526 intel_aux_display_runtime_put(dev_priv);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100527
528 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700529}
530
531/* Write data to the aux channel in native mode */
532static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100533intel_dp_aux_native_write(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700534 uint16_t address, uint8_t *send, int send_bytes)
535{
536 int ret;
537 uint8_t msg[20];
538 int msg_bytes;
539 uint8_t ack;
540
Paulo Zanoni46a5ae92013-09-17 11:14:10 -0300541 if (WARN_ON(send_bytes > 16))
542 return -E2BIG;
543
Keith Packard9b984da2011-09-19 13:54:47 -0700544 intel_dp_check_edp(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700545 msg[0] = AUX_NATIVE_WRITE << 4;
546 msg[1] = address >> 8;
Zhenyu Wangeebc8632009-07-24 01:00:30 +0800547 msg[2] = address & 0xff;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700548 msg[3] = send_bytes - 1;
549 memcpy(&msg[4], send, send_bytes);
550 msg_bytes = send_bytes + 4;
551 for (;;) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100552 ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes, &ack, 1);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700553 if (ret < 0)
554 return ret;
555 if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK)
556 break;
557 else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
558 udelay(100);
559 else
Keith Packarda5b3da52009-06-11 22:30:32 -0700560 return -EIO;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700561 }
562 return send_bytes;
563}
564
565/* Write a single byte to the aux channel in native mode */
566static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100567intel_dp_aux_native_write_1(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700568 uint16_t address, uint8_t byte)
569{
Chris Wilsonea5b2132010-08-04 13:50:23 +0100570 return intel_dp_aux_native_write(intel_dp, address, &byte, 1);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700571}
572
573/* read bytes from a native aux channel */
574static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100575intel_dp_aux_native_read(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700576 uint16_t address, uint8_t *recv, int recv_bytes)
577{
578 uint8_t msg[4];
579 int msg_bytes;
580 uint8_t reply[20];
581 int reply_bytes;
582 uint8_t ack;
583 int ret;
584
Paulo Zanoni46a5ae92013-09-17 11:14:10 -0300585 if (WARN_ON(recv_bytes > 19))
586 return -E2BIG;
587
Keith Packard9b984da2011-09-19 13:54:47 -0700588 intel_dp_check_edp(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700589 msg[0] = AUX_NATIVE_READ << 4;
590 msg[1] = address >> 8;
591 msg[2] = address & 0xff;
592 msg[3] = recv_bytes - 1;
593
594 msg_bytes = 4;
595 reply_bytes = recv_bytes + 1;
596
597 for (;;) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100598 ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700599 reply, reply_bytes);
Keith Packarda5b3da52009-06-11 22:30:32 -0700600 if (ret == 0)
601 return -EPROTO;
602 if (ret < 0)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700603 return ret;
604 ack = reply[0];
605 if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK) {
606 memcpy(recv, reply + 1, ret - 1);
607 return ret - 1;
608 }
609 else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
610 udelay(100);
611 else
Keith Packarda5b3da52009-06-11 22:30:32 -0700612 return -EIO;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700613 }
614}
615
616static int
Dave Airlieab2c0672009-12-04 10:55:24 +1000617intel_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode,
618 uint8_t write_byte, uint8_t *read_byte)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700619{
Dave Airlieab2c0672009-12-04 10:55:24 +1000620 struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100621 struct intel_dp *intel_dp = container_of(adapter,
622 struct intel_dp,
623 adapter);
Dave Airlieab2c0672009-12-04 10:55:24 +1000624 uint16_t address = algo_data->address;
625 uint8_t msg[5];
626 uint8_t reply[2];
David Flynn8316f332010-12-08 16:10:21 +0000627 unsigned retry;
Dave Airlieab2c0672009-12-04 10:55:24 +1000628 int msg_bytes;
629 int reply_bytes;
630 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700631
Paulo Zanoni8a5e6aeb2013-10-30 19:50:26 -0200632 ironlake_edp_panel_vdd_on(intel_dp);
Keith Packard9b984da2011-09-19 13:54:47 -0700633 intel_dp_check_edp(intel_dp);
Dave Airlieab2c0672009-12-04 10:55:24 +1000634 /* Set up the command byte */
635 if (mode & MODE_I2C_READ)
636 msg[0] = AUX_I2C_READ << 4;
637 else
638 msg[0] = AUX_I2C_WRITE << 4;
639
640 if (!(mode & MODE_I2C_STOP))
641 msg[0] |= AUX_I2C_MOT << 4;
642
643 msg[1] = address >> 8;
644 msg[2] = address;
645
646 switch (mode) {
647 case MODE_I2C_WRITE:
648 msg[3] = 0;
649 msg[4] = write_byte;
650 msg_bytes = 5;
651 reply_bytes = 1;
652 break;
653 case MODE_I2C_READ:
654 msg[3] = 0;
655 msg_bytes = 4;
656 reply_bytes = 2;
657 break;
658 default:
659 msg_bytes = 3;
660 reply_bytes = 1;
661 break;
662 }
663
Jani Nikula58c67ce2013-09-20 16:42:14 +0300664 /*
665 * DP1.2 sections 2.7.7.1.5.6.1 and 2.7.7.1.6.6.1: A DP Source device is
666 * required to retry at least seven times upon receiving AUX_DEFER
667 * before giving up the AUX transaction.
668 */
669 for (retry = 0; retry < 7; retry++) {
David Flynn8316f332010-12-08 16:10:21 +0000670 ret = intel_dp_aux_ch(intel_dp,
671 msg, msg_bytes,
672 reply, reply_bytes);
Dave Airlieab2c0672009-12-04 10:55:24 +1000673 if (ret < 0) {
Dave Airlie3ff99162009-12-08 14:03:47 +1000674 DRM_DEBUG_KMS("aux_ch failed %d\n", ret);
Paulo Zanoni8a5e6aeb2013-10-30 19:50:26 -0200675 goto out;
Dave Airlieab2c0672009-12-04 10:55:24 +1000676 }
David Flynn8316f332010-12-08 16:10:21 +0000677
678 switch (reply[0] & AUX_NATIVE_REPLY_MASK) {
679 case AUX_NATIVE_REPLY_ACK:
680 /* I2C-over-AUX Reply field is only valid
681 * when paired with AUX ACK.
682 */
683 break;
684 case AUX_NATIVE_REPLY_NACK:
685 DRM_DEBUG_KMS("aux_ch native nack\n");
Paulo Zanoni8a5e6aeb2013-10-30 19:50:26 -0200686 ret = -EREMOTEIO;
687 goto out;
David Flynn8316f332010-12-08 16:10:21 +0000688 case AUX_NATIVE_REPLY_DEFER:
Jani Nikula8d16f252013-09-20 16:42:15 +0300689 /*
690 * For now, just give more slack to branch devices. We
691 * could check the DPCD for I2C bit rate capabilities,
692 * and if available, adjust the interval. We could also
693 * be more careful with DP-to-Legacy adapters where a
694 * long legacy cable may force very low I2C bit rates.
695 */
696 if (intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
697 DP_DWN_STRM_PORT_PRESENT)
698 usleep_range(500, 600);
699 else
700 usleep_range(300, 400);
David Flynn8316f332010-12-08 16:10:21 +0000701 continue;
702 default:
703 DRM_ERROR("aux_ch invalid native reply 0x%02x\n",
704 reply[0]);
Paulo Zanoni8a5e6aeb2013-10-30 19:50:26 -0200705 ret = -EREMOTEIO;
706 goto out;
David Flynn8316f332010-12-08 16:10:21 +0000707 }
708
Dave Airlieab2c0672009-12-04 10:55:24 +1000709 switch (reply[0] & AUX_I2C_REPLY_MASK) {
710 case AUX_I2C_REPLY_ACK:
711 if (mode == MODE_I2C_READ) {
712 *read_byte = reply[1];
713 }
Paulo Zanoni8a5e6aeb2013-10-30 19:50:26 -0200714 ret = reply_bytes - 1;
715 goto out;
Dave Airlieab2c0672009-12-04 10:55:24 +1000716 case AUX_I2C_REPLY_NACK:
David Flynn8316f332010-12-08 16:10:21 +0000717 DRM_DEBUG_KMS("aux_i2c nack\n");
Paulo Zanoni8a5e6aeb2013-10-30 19:50:26 -0200718 ret = -EREMOTEIO;
719 goto out;
Dave Airlieab2c0672009-12-04 10:55:24 +1000720 case AUX_I2C_REPLY_DEFER:
David Flynn8316f332010-12-08 16:10:21 +0000721 DRM_DEBUG_KMS("aux_i2c defer\n");
Dave Airlieab2c0672009-12-04 10:55:24 +1000722 udelay(100);
723 break;
724 default:
David Flynn8316f332010-12-08 16:10:21 +0000725 DRM_ERROR("aux_i2c invalid reply 0x%02x\n", reply[0]);
Paulo Zanoni8a5e6aeb2013-10-30 19:50:26 -0200726 ret = -EREMOTEIO;
727 goto out;
Dave Airlieab2c0672009-12-04 10:55:24 +1000728 }
729 }
David Flynn8316f332010-12-08 16:10:21 +0000730
731 DRM_ERROR("too many retries, giving up\n");
Paulo Zanoni8a5e6aeb2013-10-30 19:50:26 -0200732 ret = -EREMOTEIO;
733
734out:
735 ironlake_edp_panel_vdd_off(intel_dp, false);
736 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700737}
738
739static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100740intel_dp_i2c_init(struct intel_dp *intel_dp,
Zhenyu Wang55f78c42010-03-29 16:13:57 +0800741 struct intel_connector *intel_connector, const char *name)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700742{
Keith Packard0b5c5412011-09-28 16:41:05 -0700743 int ret;
744
Zhenyu Wangd54e9d22009-10-19 15:43:51 +0800745 DRM_DEBUG_KMS("i2c_init %s\n", name);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100746 intel_dp->algo.running = false;
747 intel_dp->algo.address = 0;
748 intel_dp->algo.aux_ch = intel_dp_i2c_aux_ch;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700749
Akshay Joshi0206e352011-08-16 15:34:10 -0400750 memset(&intel_dp->adapter, '\0', sizeof(intel_dp->adapter));
Chris Wilsonea5b2132010-08-04 13:50:23 +0100751 intel_dp->adapter.owner = THIS_MODULE;
752 intel_dp->adapter.class = I2C_CLASS_DDC;
Akshay Joshi0206e352011-08-16 15:34:10 -0400753 strncpy(intel_dp->adapter.name, name, sizeof(intel_dp->adapter.name) - 1);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100754 intel_dp->adapter.name[sizeof(intel_dp->adapter.name) - 1] = '\0';
755 intel_dp->adapter.algo_data = &intel_dp->algo;
756 intel_dp->adapter.dev.parent = &intel_connector->base.kdev;
757
Keith Packard0b5c5412011-09-28 16:41:05 -0700758 ret = i2c_dp_aux_add_bus(&intel_dp->adapter);
Keith Packard0b5c5412011-09-28 16:41:05 -0700759 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700760}
761
Daniel Vetterc6bb3532013-04-19 11:14:33 +0200762static void
763intel_dp_set_clock(struct intel_encoder *encoder,
764 struct intel_crtc_config *pipe_config, int link_bw)
765{
766 struct drm_device *dev = encoder->base.dev;
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +0800767 const struct dp_link_dpll *divisor = NULL;
768 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +0200769
770 if (IS_G4X(dev)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +0800771 divisor = gen4_dpll;
772 count = ARRAY_SIZE(gen4_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +0200773 } else if (IS_HASWELL(dev)) {
774 /* Haswell has special-purpose DP DDI clocks. */
775 } else if (HAS_PCH_SPLIT(dev)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +0800776 divisor = pch_dpll;
777 count = ARRAY_SIZE(pch_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +0200778 } else if (IS_VALLEYVIEW(dev)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +0800779 divisor = vlv_dpll;
780 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +0200781 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +0800782
783 if (divisor && count) {
784 for (i = 0; i < count; i++) {
785 if (link_bw == divisor[i].link_bw) {
786 pipe_config->dpll = divisor[i].dpll;
787 pipe_config->clock_set = true;
788 break;
789 }
790 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +0200791 }
792}
793
Paulo Zanoni00c09d72012-10-26 19:05:52 -0200794bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100795intel_dp_compute_config(struct intel_encoder *encoder,
796 struct intel_crtc_config *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700797{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100798 struct drm_device *dev = encoder->base.dev;
Daniel Vetter36008362013-03-27 00:44:59 +0100799 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100800 struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100801 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +0300802 enum port port = dp_to_dig_port(intel_dp)->port;
Jesse Barnes2dd24552013-04-25 12:55:01 -0700803 struct intel_crtc *intel_crtc = encoder->new_crtc;
Jani Nikuladd06f902012-10-19 14:51:50 +0300804 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700805 int lane_count, clock;
Daniel Vetter397fe152012-10-22 22:56:43 +0200806 int max_lane_count = drm_dp_max_lane_count(intel_dp->dpcd);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100807 int max_clock = intel_dp_max_link_bw(intel_dp) == DP_LINK_BW_2_7 ? 1 : 0;
Daniel Vetter083f9562012-04-20 20:23:49 +0200808 int bpp, mode_rate;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700809 static int bws[2] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7 };
Daniel Vetterff9a6752013-06-01 17:16:21 +0200810 int link_avail, link_clock;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700811
Imre Deakbc7d38a2013-05-16 14:40:36 +0300812 if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100813 pipe_config->has_pch_encoder = true;
814
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200815 pipe_config->has_dp_encoder = true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700816
Jani Nikuladd06f902012-10-19 14:51:50 +0300817 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
818 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
819 adjusted_mode);
Jesse Barnes2dd24552013-04-25 12:55:01 -0700820 if (!HAS_PCH_SPLIT(dev))
821 intel_gmch_panel_fitting(intel_crtc, pipe_config,
822 intel_connector->panel.fitting_mode);
823 else
Jesse Barnesb074cec2013-04-25 12:55:02 -0700824 intel_pch_panel_fitting(intel_crtc, pipe_config,
825 intel_connector->panel.fitting_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +0100826 }
827
Daniel Vettercb1793c2012-06-04 18:39:21 +0200828 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +0200829 return false;
830
Daniel Vetter083f9562012-04-20 20:23:49 +0200831 DRM_DEBUG_KMS("DP link computation with max lane count %i "
832 "max bw %02x pixel clock %iKHz\n",
Damien Lespiau241bfc32013-09-25 16:45:37 +0100833 max_lane_count, bws[max_clock],
834 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +0200835
Daniel Vetter36008362013-03-27 00:44:59 +0100836 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
837 * bpc in between. */
Daniel Vetter3e7ca982013-06-01 19:45:56 +0200838 bpp = pipe_config->pipe_bpp;
Jani Nikula6da7f102013-10-16 17:06:17 +0300839 if (is_edp(intel_dp) && dev_priv->vbt.edp_bpp &&
840 dev_priv->vbt.edp_bpp < bpp) {
Imre Deak79842112013-07-18 17:44:13 +0300841 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
842 dev_priv->vbt.edp_bpp);
Jani Nikula6da7f102013-10-16 17:06:17 +0300843 bpp = dev_priv->vbt.edp_bpp;
Imre Deak79842112013-07-18 17:44:13 +0300844 }
Daniel Vetter657445f2013-05-04 10:09:18 +0200845
Daniel Vetter36008362013-03-27 00:44:59 +0100846 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +0100847 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
848 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +0200849
Daniel Vetter36008362013-03-27 00:44:59 +0100850 for (clock = 0; clock <= max_clock; clock++) {
851 for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) {
852 link_clock = drm_dp_bw_code_to_link_rate(bws[clock]);
853 link_avail = intel_dp_max_data_rate(link_clock,
854 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200855
Daniel Vetter36008362013-03-27 00:44:59 +0100856 if (mode_rate <= link_avail) {
857 goto found;
858 }
859 }
860 }
861 }
862
863 return false;
864
865found:
Ville Syrjälä55bc60d2013-01-17 16:31:29 +0200866 if (intel_dp->color_range_auto) {
867 /*
868 * See:
869 * CEA-861-E - 5.1 Default Encoding Parameters
870 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
871 */
Thierry Reding18316c82012-12-20 15:41:44 +0100872 if (bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1)
Ville Syrjälä55bc60d2013-01-17 16:31:29 +0200873 intel_dp->color_range = DP_COLOR_RANGE_16_235;
874 else
875 intel_dp->color_range = 0;
876 }
877
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200878 if (intel_dp->color_range)
Daniel Vetter50f3b012013-03-27 00:44:56 +0100879 pipe_config->limited_color_range = true;
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200880
Daniel Vetter36008362013-03-27 00:44:59 +0100881 intel_dp->link_bw = bws[clock];
882 intel_dp->lane_count = lane_count;
Daniel Vetter657445f2013-05-04 10:09:18 +0200883 pipe_config->pipe_bpp = bpp;
Daniel Vetterff9a6752013-06-01 17:16:21 +0200884 pipe_config->port_clock = drm_dp_bw_code_to_link_rate(intel_dp->link_bw);
Daniel Vetterc4867932012-04-10 10:42:36 +0200885
Daniel Vetter36008362013-03-27 00:44:59 +0100886 DRM_DEBUG_KMS("DP link bw %02x lane count %d clock %d bpp %d\n",
887 intel_dp->link_bw, intel_dp->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +0200888 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +0100889 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
890 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700891
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200892 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +0100893 adjusted_mode->crtc_clock,
894 pipe_config->port_clock,
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200895 &pipe_config->dp_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700896
Daniel Vetterc6bb3532013-04-19 11:14:33 +0200897 intel_dp_set_clock(encoder, pipe_config, intel_dp->link_bw);
898
Daniel Vetter36008362013-03-27 00:44:59 +0100899 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700900}
901
Daniel Vetter7c62a162013-06-01 17:16:20 +0200902static void ironlake_set_pll_cpu_edp(struct intel_dp *intel_dp)
Daniel Vetterea9b6002012-11-29 15:59:31 +0100903{
Daniel Vetter7c62a162013-06-01 17:16:20 +0200904 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
905 struct intel_crtc *crtc = to_intel_crtc(dig_port->base.base.crtc);
906 struct drm_device *dev = crtc->base.dev;
Daniel Vetterea9b6002012-11-29 15:59:31 +0100907 struct drm_i915_private *dev_priv = dev->dev_private;
908 u32 dpa_ctl;
909
Daniel Vetterff9a6752013-06-01 17:16:21 +0200910 DRM_DEBUG_KMS("eDP PLL enable for clock %d\n", crtc->config.port_clock);
Daniel Vetterea9b6002012-11-29 15:59:31 +0100911 dpa_ctl = I915_READ(DP_A);
912 dpa_ctl &= ~DP_PLL_FREQ_MASK;
913
Daniel Vetterff9a6752013-06-01 17:16:21 +0200914 if (crtc->config.port_clock == 162000) {
Daniel Vetter1ce17032012-11-29 15:59:32 +0100915 /* For a long time we've carried around a ILK-DevA w/a for the
916 * 160MHz clock. If we're really unlucky, it's still required.
917 */
918 DRM_DEBUG_KMS("160MHz cpu eDP clock, might need ilk devA w/a\n");
Daniel Vetterea9b6002012-11-29 15:59:31 +0100919 dpa_ctl |= DP_PLL_FREQ_160MHZ;
Daniel Vetter7c62a162013-06-01 17:16:20 +0200920 intel_dp->DP |= DP_PLL_FREQ_160MHZ;
Daniel Vetterea9b6002012-11-29 15:59:31 +0100921 } else {
922 dpa_ctl |= DP_PLL_FREQ_270MHZ;
Daniel Vetter7c62a162013-06-01 17:16:20 +0200923 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
Daniel Vetterea9b6002012-11-29 15:59:31 +0100924 }
Daniel Vetter1ce17032012-11-29 15:59:32 +0100925
Daniel Vetterea9b6002012-11-29 15:59:31 +0100926 I915_WRITE(DP_A, dpa_ctl);
927
928 POSTING_READ(DP_A);
929 udelay(500);
930}
931
Daniel Vetterb934223d2013-07-21 21:37:05 +0200932static void intel_dp_mode_set(struct intel_encoder *encoder)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700933{
Daniel Vetterb934223d2013-07-21 21:37:05 +0200934 struct drm_device *dev = encoder->base.dev;
Keith Packard417e8222011-11-01 19:54:11 -0700935 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb934223d2013-07-21 21:37:05 +0200936 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +0300937 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +0200938 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
939 struct drm_display_mode *adjusted_mode = &crtc->config.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700940
Keith Packard417e8222011-11-01 19:54:11 -0700941 /*
Keith Packard1a2eb462011-11-16 16:26:07 -0800942 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -0700943 *
944 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -0800945 * SNB CPU
946 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -0700947 * CPT PCH
948 *
949 * IBX PCH and CPU are the same for almost everything,
950 * except that the CPU DP PLL is configured in this
951 * register
952 *
953 * CPT PCH is quite different, having many bits moved
954 * to the TRANS_DP_CTL register instead. That
955 * configuration happens (oddly) in ironlake_pch_enable
956 */
Adam Jackson9c9e7922010-04-05 17:57:59 -0400957
Keith Packard417e8222011-11-01 19:54:11 -0700958 /* Preserve the BIOS-computed detected bit. This is
959 * supposed to be read-only.
960 */
961 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700962
Keith Packard417e8222011-11-01 19:54:11 -0700963 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -0700964 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Daniel Vetter17aa6be2013-04-30 14:01:40 +0200965 intel_dp->DP |= DP_PORT_WIDTH(intel_dp->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700966
Wu Fengguange0dac652011-09-05 14:25:34 +0800967 if (intel_dp->has_audio) {
968 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Daniel Vetter7c62a162013-06-01 17:16:20 +0200969 pipe_name(crtc->pipe));
Chris Wilsonea5b2132010-08-04 13:50:23 +0100970 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Daniel Vetterb934223d2013-07-21 21:37:05 +0200971 intel_write_eld(&encoder->base, adjusted_mode);
Wu Fengguange0dac652011-09-05 14:25:34 +0800972 }
Paulo Zanoni247d89f2012-10-15 15:51:33 -0300973
Keith Packard417e8222011-11-01 19:54:11 -0700974 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800975
Imre Deakbc7d38a2013-05-16 14:40:36 +0300976 if (port == PORT_A && IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) {
Keith Packard1a2eb462011-11-16 16:26:07 -0800977 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
978 intel_dp->DP |= DP_SYNC_HS_HIGH;
979 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
980 intel_dp->DP |= DP_SYNC_VS_HIGH;
981 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
982
Jani Nikula6aba5b62013-10-04 15:08:10 +0300983 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -0800984 intel_dp->DP |= DP_ENHANCED_FRAMING;
985
Daniel Vetter7c62a162013-06-01 17:16:20 +0200986 intel_dp->DP |= crtc->pipe << 29;
Imre Deakbc7d38a2013-05-16 14:40:36 +0300987 } else if (!HAS_PCH_CPT(dev) || port == PORT_A) {
Jesse Barnesb2634012013-03-28 09:55:40 -0700988 if (!HAS_PCH_SPLIT(dev) && !IS_VALLEYVIEW(dev))
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200989 intel_dp->DP |= intel_dp->color_range;
Keith Packard417e8222011-11-01 19:54:11 -0700990
991 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
992 intel_dp->DP |= DP_SYNC_HS_HIGH;
993 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
994 intel_dp->DP |= DP_SYNC_VS_HIGH;
995 intel_dp->DP |= DP_LINK_TRAIN_OFF;
996
Jani Nikula6aba5b62013-10-04 15:08:10 +0300997 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -0700998 intel_dp->DP |= DP_ENHANCED_FRAMING;
999
Daniel Vetter7c62a162013-06-01 17:16:20 +02001000 if (crtc->pipe == 1)
Keith Packard417e8222011-11-01 19:54:11 -07001001 intel_dp->DP |= DP_PIPEB_SELECT;
Keith Packard417e8222011-11-01 19:54:11 -07001002 } else {
1003 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001004 }
Daniel Vetterea9b6002012-11-29 15:59:31 +01001005
Imre Deakbc7d38a2013-05-16 14:40:36 +03001006 if (port == PORT_A && !IS_VALLEYVIEW(dev))
Daniel Vetter7c62a162013-06-01 17:16:20 +02001007 ironlake_set_pll_cpu_edp(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001008}
1009
Keith Packard99ea7122011-11-01 19:57:50 -07001010#define IDLE_ON_MASK (PP_ON | 0 | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1011#define IDLE_ON_VALUE (PP_ON | 0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
1012
1013#define IDLE_OFF_MASK (PP_ON | 0 | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1014#define IDLE_OFF_VALUE (0 | 0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
1015
1016#define IDLE_CYCLE_MASK (PP_ON | 0 | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1017#define IDLE_CYCLE_VALUE (0 | 0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
1018
1019static void ironlake_wait_panel_status(struct intel_dp *intel_dp,
1020 u32 mask,
1021 u32 value)
1022{
Paulo Zanoni30add222012-10-26 19:05:45 -02001023 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001024 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes453c5422013-03-28 09:55:41 -07001025 u32 pp_stat_reg, pp_ctrl_reg;
1026
Jani Nikulabf13e812013-09-06 07:40:05 +03001027 pp_stat_reg = _pp_stat_reg(intel_dp);
1028 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001029
1030 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001031 mask, value,
1032 I915_READ(pp_stat_reg),
1033 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001034
Jesse Barnes453c5422013-03-28 09:55:41 -07001035 if (_wait_for((I915_READ(pp_stat_reg) & mask) == value, 5000, 10)) {
Keith Packard99ea7122011-11-01 19:57:50 -07001036 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001037 I915_READ(pp_stat_reg),
1038 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001039 }
1040}
1041
1042static void ironlake_wait_panel_on(struct intel_dp *intel_dp)
1043{
1044 DRM_DEBUG_KMS("Wait for panel power on\n");
1045 ironlake_wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
1046}
1047
Keith Packardbd943152011-09-18 23:09:52 -07001048static void ironlake_wait_panel_off(struct intel_dp *intel_dp)
1049{
Keith Packardbd943152011-09-18 23:09:52 -07001050 DRM_DEBUG_KMS("Wait for panel power off time\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001051 ironlake_wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001052}
Keith Packardbd943152011-09-18 23:09:52 -07001053
Keith Packard99ea7122011-11-01 19:57:50 -07001054static void ironlake_wait_panel_power_cycle(struct intel_dp *intel_dp)
1055{
1056 DRM_DEBUG_KMS("Wait for panel power cycle\n");
1057 ironlake_wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
1058}
Keith Packardbd943152011-09-18 23:09:52 -07001059
Keith Packard99ea7122011-11-01 19:57:50 -07001060
Keith Packard832dd3c2011-11-01 19:34:06 -07001061/* Read the current pp_control value, unlocking the register if it
1062 * is locked
1063 */
1064
Jesse Barnes453c5422013-03-28 09:55:41 -07001065static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07001066{
Jesse Barnes453c5422013-03-28 09:55:41 -07001067 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1068 struct drm_i915_private *dev_priv = dev->dev_private;
1069 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07001070
Jani Nikulabf13e812013-09-06 07:40:05 +03001071 control = I915_READ(_pp_ctrl_reg(intel_dp));
Keith Packard832dd3c2011-11-01 19:34:06 -07001072 control &= ~PANEL_UNLOCK_MASK;
1073 control |= PANEL_UNLOCK_REGS;
1074 return control;
Keith Packardbd943152011-09-18 23:09:52 -07001075}
1076
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001077void ironlake_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001078{
Paulo Zanoni30add222012-10-26 19:05:45 -02001079 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001080 struct drm_i915_private *dev_priv = dev->dev_private;
1081 u32 pp;
Jesse Barnes453c5422013-03-28 09:55:41 -07001082 u32 pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08001083
Keith Packard97af61f572011-09-28 16:23:51 -07001084 if (!is_edp(intel_dp))
1085 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08001086
Keith Packardbd943152011-09-18 23:09:52 -07001087 WARN(intel_dp->want_panel_vdd,
1088 "eDP VDD already requested on\n");
1089
1090 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07001091
Paulo Zanonib0665d52013-10-30 19:50:27 -02001092 if (ironlake_edp_have_panel_vdd(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07001093 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02001094
1095 DRM_DEBUG_KMS("Turning eDP VDD on\n");
Keith Packardbd943152011-09-18 23:09:52 -07001096
Keith Packard99ea7122011-11-01 19:57:50 -07001097 if (!ironlake_edp_have_panel_power(intel_dp))
1098 ironlake_wait_panel_power_cycle(intel_dp);
1099
Jesse Barnes453c5422013-03-28 09:55:41 -07001100 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001101 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07001102
Jani Nikulabf13e812013-09-06 07:40:05 +03001103 pp_stat_reg = _pp_stat_reg(intel_dp);
1104 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001105
1106 I915_WRITE(pp_ctrl_reg, pp);
1107 POSTING_READ(pp_ctrl_reg);
1108 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1109 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07001110 /*
1111 * If the panel wasn't on, delay before accessing aux channel
1112 */
1113 if (!ironlake_edp_have_panel_power(intel_dp)) {
Keith Packardbd943152011-09-18 23:09:52 -07001114 DRM_DEBUG_KMS("eDP was not running\n");
Keith Packardf01eca22011-09-28 16:48:10 -07001115 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07001116 }
Jesse Barnes5d613502011-01-24 17:10:54 -08001117}
1118
Keith Packardbd943152011-09-18 23:09:52 -07001119static void ironlake_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001120{
Paulo Zanoni30add222012-10-26 19:05:45 -02001121 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001122 struct drm_i915_private *dev_priv = dev->dev_private;
1123 u32 pp;
Jesse Barnes453c5422013-03-28 09:55:41 -07001124 u32 pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08001125
Daniel Vettera0e99e62012-12-02 01:05:46 +01001126 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
1127
Keith Packardbd943152011-09-18 23:09:52 -07001128 if (!intel_dp->want_panel_vdd && ironlake_edp_have_panel_vdd(intel_dp)) {
Paulo Zanonib0665d52013-10-30 19:50:27 -02001129 DRM_DEBUG_KMS("Turning eDP VDD off\n");
1130
Jesse Barnes453c5422013-03-28 09:55:41 -07001131 pp = ironlake_get_pp_control(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07001132 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07001133
Paulo Zanoni9f08ef52013-10-31 12:44:21 -02001134 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
1135 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001136
1137 I915_WRITE(pp_ctrl_reg, pp);
1138 POSTING_READ(pp_ctrl_reg);
Jesse Barnes5d613502011-01-24 17:10:54 -08001139
Keith Packardbd943152011-09-18 23:09:52 -07001140 /* Make sure sequencer is idle before allowing subsequent activity */
Jesse Barnes453c5422013-03-28 09:55:41 -07001141 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1142 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001143 msleep(intel_dp->panel_power_down_delay);
Keith Packardbd943152011-09-18 23:09:52 -07001144 }
1145}
1146
1147static void ironlake_panel_vdd_work(struct work_struct *__work)
1148{
1149 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
1150 struct intel_dp, panel_vdd_work);
Paulo Zanoni30add222012-10-26 19:05:45 -02001151 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07001152
Keith Packard627f7672011-10-31 11:30:10 -07001153 mutex_lock(&dev->mode_config.mutex);
Keith Packardbd943152011-09-18 23:09:52 -07001154 ironlake_panel_vdd_off_sync(intel_dp);
Keith Packard627f7672011-10-31 11:30:10 -07001155 mutex_unlock(&dev->mode_config.mutex);
Keith Packardbd943152011-09-18 23:09:52 -07001156}
1157
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001158void ironlake_edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07001159{
Keith Packard97af61f572011-09-28 16:23:51 -07001160 if (!is_edp(intel_dp))
1161 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08001162
Keith Packardbd943152011-09-18 23:09:52 -07001163 WARN(!intel_dp->want_panel_vdd, "eDP VDD not forced on");
Keith Packardf2e8b182011-11-01 20:01:35 -07001164
Keith Packardbd943152011-09-18 23:09:52 -07001165 intel_dp->want_panel_vdd = false;
1166
1167 if (sync) {
1168 ironlake_panel_vdd_off_sync(intel_dp);
1169 } else {
1170 /*
1171 * Queue the timer to fire a long
1172 * time from now (relative to the power down delay)
1173 * to keep the panel power up across a sequence of operations
1174 */
1175 schedule_delayed_work(&intel_dp->panel_vdd_work,
1176 msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5));
1177 }
Jesse Barnes5d613502011-01-24 17:10:54 -08001178}
1179
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001180void ironlake_edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07001181{
Paulo Zanoni30add222012-10-26 19:05:45 -02001182 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07001183 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packard99ea7122011-11-01 19:57:50 -07001184 u32 pp;
Jesse Barnes453c5422013-03-28 09:55:41 -07001185 u32 pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07001186
Keith Packard97af61f572011-09-28 16:23:51 -07001187 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07001188 return;
Keith Packard99ea7122011-11-01 19:57:50 -07001189
1190 DRM_DEBUG_KMS("Turn eDP power on\n");
1191
1192 if (ironlake_edp_have_panel_power(intel_dp)) {
1193 DRM_DEBUG_KMS("eDP power already on\n");
Keith Packard7d639f32011-09-29 16:05:34 -07001194 return;
Keith Packard99ea7122011-11-01 19:57:50 -07001195 }
Jesse Barnes9934c132010-07-22 13:18:19 -07001196
Keith Packard99ea7122011-11-01 19:57:50 -07001197 ironlake_wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001198
Jani Nikulabf13e812013-09-06 07:40:05 +03001199 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001200 pp = ironlake_get_pp_control(intel_dp);
Keith Packard05ce1a42011-09-29 16:33:01 -07001201 if (IS_GEN5(dev)) {
1202 /* ILK workaround: disable reset around power sequence */
1203 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03001204 I915_WRITE(pp_ctrl_reg, pp);
1205 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07001206 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001207
Keith Packard1c0ae802011-09-19 13:59:29 -07001208 pp |= POWER_TARGET_ON;
Keith Packard99ea7122011-11-01 19:57:50 -07001209 if (!IS_GEN5(dev))
1210 pp |= PANEL_POWER_RESET;
1211
Jesse Barnes453c5422013-03-28 09:55:41 -07001212 I915_WRITE(pp_ctrl_reg, pp);
1213 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07001214
Keith Packard99ea7122011-11-01 19:57:50 -07001215 ironlake_wait_panel_on(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07001216
Keith Packard05ce1a42011-09-29 16:33:01 -07001217 if (IS_GEN5(dev)) {
1218 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03001219 I915_WRITE(pp_ctrl_reg, pp);
1220 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07001221 }
Jesse Barnes9934c132010-07-22 13:18:19 -07001222}
1223
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001224void ironlake_edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07001225{
Paulo Zanoni30add222012-10-26 19:05:45 -02001226 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07001227 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packard99ea7122011-11-01 19:57:50 -07001228 u32 pp;
Jesse Barnes453c5422013-03-28 09:55:41 -07001229 u32 pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07001230
Keith Packard97af61f572011-09-28 16:23:51 -07001231 if (!is_edp(intel_dp))
1232 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001233
Keith Packard99ea7122011-11-01 19:57:50 -07001234 DRM_DEBUG_KMS("Turn eDP power off\n");
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001235
Daniel Vetter6cb49832012-05-20 17:14:50 +02001236 WARN(!intel_dp->want_panel_vdd, "Need VDD to turn off panel\n");
Jesse Barnes9934c132010-07-22 13:18:19 -07001237
Jesse Barnes453c5422013-03-28 09:55:41 -07001238 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02001239 /* We need to switch off panel power _and_ force vdd, for otherwise some
1240 * panels get very unhappy and cease to work. */
1241 pp &= ~(POWER_TARGET_ON | EDP_FORCE_VDD | PANEL_POWER_RESET | EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07001242
Jani Nikulabf13e812013-09-06 07:40:05 +03001243 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001244
1245 I915_WRITE(pp_ctrl_reg, pp);
1246 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07001247
Daniel Vetter35a38552012-08-12 22:17:14 +02001248 intel_dp->want_panel_vdd = false;
1249
Keith Packard99ea7122011-11-01 19:57:50 -07001250 ironlake_wait_panel_off(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07001251}
1252
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001253void ironlake_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001254{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001255 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1256 struct drm_device *dev = intel_dig_port->base.base.dev;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001257 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001258 int pipe = to_intel_crtc(intel_dig_port->base.base.crtc)->pipe;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001259 u32 pp;
Jesse Barnes453c5422013-03-28 09:55:41 -07001260 u32 pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001261
Keith Packardf01eca22011-09-28 16:48:10 -07001262 if (!is_edp(intel_dp))
1263 return;
1264
Zhao Yakui28c97732009-10-09 11:39:41 +08001265 DRM_DEBUG_KMS("\n");
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001266 /*
1267 * If we enable the backlight right away following a panel power
1268 * on, we may see slight flicker as the panel syncs with the eDP
1269 * link. So delay a bit to make sure the image is solid before
1270 * allowing it to appear.
1271 */
Keith Packardf01eca22011-09-28 16:48:10 -07001272 msleep(intel_dp->backlight_on_delay);
Jesse Barnes453c5422013-03-28 09:55:41 -07001273 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001274 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07001275
Jani Nikulabf13e812013-09-06 07:40:05 +03001276 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001277
1278 I915_WRITE(pp_ctrl_reg, pp);
1279 POSTING_READ(pp_ctrl_reg);
Daniel Vetter035aa3d2012-10-20 20:57:42 +02001280
1281 intel_panel_enable_backlight(dev, pipe);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001282}
1283
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001284void ironlake_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001285{
Paulo Zanoni30add222012-10-26 19:05:45 -02001286 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001287 struct drm_i915_private *dev_priv = dev->dev_private;
1288 u32 pp;
Jesse Barnes453c5422013-03-28 09:55:41 -07001289 u32 pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001290
Keith Packardf01eca22011-09-28 16:48:10 -07001291 if (!is_edp(intel_dp))
1292 return;
1293
Daniel Vetter035aa3d2012-10-20 20:57:42 +02001294 intel_panel_disable_backlight(dev);
1295
Zhao Yakui28c97732009-10-09 11:39:41 +08001296 DRM_DEBUG_KMS("\n");
Jesse Barnes453c5422013-03-28 09:55:41 -07001297 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001298 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07001299
Jani Nikulabf13e812013-09-06 07:40:05 +03001300 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001301
1302 I915_WRITE(pp_ctrl_reg, pp);
1303 POSTING_READ(pp_ctrl_reg);
Keith Packardf01eca22011-09-28 16:48:10 -07001304 msleep(intel_dp->backlight_off_delay);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001305}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001306
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001307static void ironlake_edp_pll_on(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07001308{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001309 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1310 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
1311 struct drm_device *dev = crtc->dev;
Jesse Barnesd240f202010-08-13 15:43:26 -07001312 struct drm_i915_private *dev_priv = dev->dev_private;
1313 u32 dpa_ctl;
1314
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001315 assert_pipe_disabled(dev_priv,
1316 to_intel_crtc(crtc)->pipe);
1317
Jesse Barnesd240f202010-08-13 15:43:26 -07001318 DRM_DEBUG_KMS("\n");
1319 dpa_ctl = I915_READ(DP_A);
Daniel Vetter07679352012-09-06 22:15:42 +02001320 WARN(dpa_ctl & DP_PLL_ENABLE, "dp pll on, should be off\n");
1321 WARN(dpa_ctl & DP_PORT_EN, "dp port still on, should be off\n");
1322
1323 /* We don't adjust intel_dp->DP while tearing down the link, to
1324 * facilitate link retraining (e.g. after hotplug). Hence clear all
1325 * enable bits here to ensure that we don't enable too much. */
1326 intel_dp->DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
1327 intel_dp->DP |= DP_PLL_ENABLE;
1328 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07001329 POSTING_READ(DP_A);
1330 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07001331}
1332
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001333static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07001334{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001335 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1336 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
1337 struct drm_device *dev = crtc->dev;
Jesse Barnesd240f202010-08-13 15:43:26 -07001338 struct drm_i915_private *dev_priv = dev->dev_private;
1339 u32 dpa_ctl;
1340
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001341 assert_pipe_disabled(dev_priv,
1342 to_intel_crtc(crtc)->pipe);
1343
Jesse Barnesd240f202010-08-13 15:43:26 -07001344 dpa_ctl = I915_READ(DP_A);
Daniel Vetter07679352012-09-06 22:15:42 +02001345 WARN((dpa_ctl & DP_PLL_ENABLE) == 0,
1346 "dp pll off, should be on\n");
1347 WARN(dpa_ctl & DP_PORT_EN, "dp port still on, should be off\n");
1348
1349 /* We can't rely on the value tracked for the DP register in
1350 * intel_dp->DP because link_down must not change that (otherwise link
1351 * re-training will fail. */
Jesse Barnes298b0b32010-10-07 16:01:24 -07001352 dpa_ctl &= ~DP_PLL_ENABLE;
Jesse Barnesd240f202010-08-13 15:43:26 -07001353 I915_WRITE(DP_A, dpa_ctl);
Chris Wilson1af5fa12010-09-08 21:07:28 +01001354 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07001355 udelay(200);
1356}
1357
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001358/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03001359void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001360{
1361 int ret, i;
1362
1363 /* Should have a valid DPCD by this point */
1364 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
1365 return;
1366
1367 if (mode != DRM_MODE_DPMS_ON) {
1368 ret = intel_dp_aux_native_write_1(intel_dp, DP_SET_POWER,
1369 DP_SET_POWER_D3);
1370 if (ret != 1)
1371 DRM_DEBUG_DRIVER("failed to write sink power state\n");
1372 } else {
1373 /*
1374 * When turning on, we need to retry for 1ms to give the sink
1375 * time to wake up.
1376 */
1377 for (i = 0; i < 3; i++) {
1378 ret = intel_dp_aux_native_write_1(intel_dp,
1379 DP_SET_POWER,
1380 DP_SET_POWER_D0);
1381 if (ret == 1)
1382 break;
1383 msleep(1);
1384 }
1385 }
1386}
1387
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001388static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
1389 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07001390{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001391 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001392 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001393 struct drm_device *dev = encoder->base.dev;
1394 struct drm_i915_private *dev_priv = dev->dev_private;
1395 u32 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07001396
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001397 if (!(tmp & DP_PORT_EN))
1398 return false;
1399
Imre Deakbc7d38a2013-05-16 14:40:36 +03001400 if (port == PORT_A && IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001401 *pipe = PORT_TO_PIPE_CPT(tmp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001402 } else if (!HAS_PCH_CPT(dev) || port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001403 *pipe = PORT_TO_PIPE(tmp);
1404 } else {
1405 u32 trans_sel;
1406 u32 trans_dp;
1407 int i;
1408
1409 switch (intel_dp->output_reg) {
1410 case PCH_DP_B:
1411 trans_sel = TRANS_DP_PORT_SEL_B;
1412 break;
1413 case PCH_DP_C:
1414 trans_sel = TRANS_DP_PORT_SEL_C;
1415 break;
1416 case PCH_DP_D:
1417 trans_sel = TRANS_DP_PORT_SEL_D;
1418 break;
1419 default:
1420 return true;
1421 }
1422
1423 for_each_pipe(i) {
1424 trans_dp = I915_READ(TRANS_DP_CTL(i));
1425 if ((trans_dp & TRANS_DP_PORT_SEL_MASK) == trans_sel) {
1426 *pipe = i;
1427 return true;
1428 }
1429 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001430
Daniel Vetter4a0833e2012-10-26 10:58:11 +02001431 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
1432 intel_dp->output_reg);
1433 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001434
1435 return true;
1436}
1437
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001438static void intel_dp_get_config(struct intel_encoder *encoder,
1439 struct intel_crtc_config *pipe_config)
1440{
1441 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001442 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08001443 struct drm_device *dev = encoder->base.dev;
1444 struct drm_i915_private *dev_priv = dev->dev_private;
1445 enum port port = dp_to_dig_port(intel_dp)->port;
1446 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjälä18442d02013-09-13 16:00:08 +03001447 int dotclock;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001448
Xiong Zhang63000ef2013-06-28 12:59:06 +08001449 if ((port == PORT_A) || !HAS_PCH_CPT(dev)) {
1450 tmp = I915_READ(intel_dp->output_reg);
1451 if (tmp & DP_SYNC_HS_HIGH)
1452 flags |= DRM_MODE_FLAG_PHSYNC;
1453 else
1454 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001455
Xiong Zhang63000ef2013-06-28 12:59:06 +08001456 if (tmp & DP_SYNC_VS_HIGH)
1457 flags |= DRM_MODE_FLAG_PVSYNC;
1458 else
1459 flags |= DRM_MODE_FLAG_NVSYNC;
1460 } else {
1461 tmp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1462 if (tmp & TRANS_DP_HSYNC_ACTIVE_HIGH)
1463 flags |= DRM_MODE_FLAG_PHSYNC;
1464 else
1465 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001466
Xiong Zhang63000ef2013-06-28 12:59:06 +08001467 if (tmp & TRANS_DP_VSYNC_ACTIVE_HIGH)
1468 flags |= DRM_MODE_FLAG_PVSYNC;
1469 else
1470 flags |= DRM_MODE_FLAG_NVSYNC;
1471 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001472
1473 pipe_config->adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03001474
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03001475 pipe_config->has_dp_encoder = true;
1476
1477 intel_dp_get_m_n(crtc, pipe_config);
1478
Ville Syrjälä18442d02013-09-13 16:00:08 +03001479 if (port == PORT_A) {
Jesse Barnesf1f644d2013-06-27 00:39:25 +03001480 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_160MHZ)
1481 pipe_config->port_clock = 162000;
1482 else
1483 pipe_config->port_clock = 270000;
1484 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03001485
1486 dotclock = intel_dotclock_calculate(pipe_config->port_clock,
1487 &pipe_config->dp_m_n);
1488
1489 if (HAS_PCH_SPLIT(dev_priv->dev) && port != PORT_A)
1490 ironlake_check_encoder_dotclock(pipe_config, dotclock);
1491
Damien Lespiau241bfc32013-09-25 16:45:37 +01001492 pipe_config->adjusted_mode.crtc_clock = dotclock;
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01001493
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03001494 if (is_edp(intel_dp) && dev_priv->vbt.edp_bpp &&
1495 pipe_config->pipe_bpp > dev_priv->vbt.edp_bpp) {
1496 /*
1497 * This is a big fat ugly hack.
1498 *
1499 * Some machines in UEFI boot mode provide us a VBT that has 18
1500 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
1501 * unknown we fail to light up. Yet the same BIOS boots up with
1502 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
1503 * max, not what it tells us to use.
1504 *
1505 * Note: This will still be broken if the eDP panel is not lit
1506 * up by the BIOS, and thus we can't get the mode at module
1507 * load.
1508 */
1509 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
1510 pipe_config->pipe_bpp, dev_priv->vbt.edp_bpp);
1511 dev_priv->vbt.edp_bpp = pipe_config->pipe_bpp;
1512 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001513}
1514
Rodrigo Vivia031d702013-10-03 16:15:06 -03001515static bool is_edp_psr(struct drm_device *dev)
Shobhit Kumar2293bb52013-07-11 18:44:56 -03001516{
Rodrigo Vivia031d702013-10-03 16:15:06 -03001517 struct drm_i915_private *dev_priv = dev->dev_private;
1518
1519 return dev_priv->psr.sink_support;
Shobhit Kumar2293bb52013-07-11 18:44:56 -03001520}
1521
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001522static bool intel_edp_is_psr_enabled(struct drm_device *dev)
1523{
1524 struct drm_i915_private *dev_priv = dev->dev_private;
1525
Ben Widawsky18b59922013-09-20 09:35:30 -07001526 if (!HAS_PSR(dev))
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001527 return false;
1528
Ben Widawsky18b59922013-09-20 09:35:30 -07001529 return I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001530}
1531
1532static void intel_edp_psr_write_vsc(struct intel_dp *intel_dp,
1533 struct edp_vsc_psr *vsc_psr)
1534{
1535 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1536 struct drm_device *dev = dig_port->base.base.dev;
1537 struct drm_i915_private *dev_priv = dev->dev_private;
1538 struct intel_crtc *crtc = to_intel_crtc(dig_port->base.base.crtc);
1539 u32 ctl_reg = HSW_TVIDEO_DIP_CTL(crtc->config.cpu_transcoder);
1540 u32 data_reg = HSW_TVIDEO_DIP_VSC_DATA(crtc->config.cpu_transcoder);
1541 uint32_t *data = (uint32_t *) vsc_psr;
1542 unsigned int i;
1543
1544 /* As per BSPec (Pipe Video Data Island Packet), we need to disable
1545 the video DIP being updated before program video DIP data buffer
1546 registers for DIP being updated. */
1547 I915_WRITE(ctl_reg, 0);
1548 POSTING_READ(ctl_reg);
1549
1550 for (i = 0; i < VIDEO_DIP_VSC_DATA_SIZE; i += 4) {
1551 if (i < sizeof(struct edp_vsc_psr))
1552 I915_WRITE(data_reg + i, *data++);
1553 else
1554 I915_WRITE(data_reg + i, 0);
1555 }
1556
1557 I915_WRITE(ctl_reg, VIDEO_DIP_ENABLE_VSC_HSW);
1558 POSTING_READ(ctl_reg);
1559}
1560
1561static void intel_edp_psr_setup(struct intel_dp *intel_dp)
1562{
1563 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1564 struct drm_i915_private *dev_priv = dev->dev_private;
1565 struct edp_vsc_psr psr_vsc;
1566
1567 if (intel_dp->psr_setup_done)
1568 return;
1569
1570 /* Prepare VSC packet as per EDP 1.3 spec, Table 3.10 */
1571 memset(&psr_vsc, 0, sizeof(psr_vsc));
1572 psr_vsc.sdp_header.HB0 = 0;
1573 psr_vsc.sdp_header.HB1 = 0x7;
1574 psr_vsc.sdp_header.HB2 = 0x2;
1575 psr_vsc.sdp_header.HB3 = 0x8;
1576 intel_edp_psr_write_vsc(intel_dp, &psr_vsc);
1577
1578 /* Avoid continuous PSR exit by masking memup and hpd */
Ben Widawsky18b59922013-09-20 09:35:30 -07001579 I915_WRITE(EDP_PSR_DEBUG_CTL(dev), EDP_PSR_DEBUG_MASK_MEMUP |
Rodrigo Vivi0cc4b692013-10-03 13:31:26 -03001580 EDP_PSR_DEBUG_MASK_HPD | EDP_PSR_DEBUG_MASK_LPSP);
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001581
1582 intel_dp->psr_setup_done = true;
1583}
1584
1585static void intel_edp_psr_enable_sink(struct intel_dp *intel_dp)
1586{
1587 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1588 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonbc866252013-07-21 16:00:03 +01001589 uint32_t aux_clock_divider = get_aux_clock_divider(intel_dp, 0);
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001590 int precharge = 0x3;
1591 int msg_size = 5; /* Header(4) + Message(1) */
1592
1593 /* Enable PSR in sink */
1594 if (intel_dp->psr_dpcd[1] & DP_PSR_NO_TRAIN_ON_EXIT)
1595 intel_dp_aux_native_write_1(intel_dp, DP_PSR_EN_CFG,
1596 DP_PSR_ENABLE &
1597 ~DP_PSR_MAIN_LINK_ACTIVE);
1598 else
1599 intel_dp_aux_native_write_1(intel_dp, DP_PSR_EN_CFG,
1600 DP_PSR_ENABLE |
1601 DP_PSR_MAIN_LINK_ACTIVE);
1602
1603 /* Setup AUX registers */
Ben Widawsky18b59922013-09-20 09:35:30 -07001604 I915_WRITE(EDP_PSR_AUX_DATA1(dev), EDP_PSR_DPCD_COMMAND);
1605 I915_WRITE(EDP_PSR_AUX_DATA2(dev), EDP_PSR_DPCD_NORMAL_OPERATION);
1606 I915_WRITE(EDP_PSR_AUX_CTL(dev),
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001607 DP_AUX_CH_CTL_TIME_OUT_400us |
1608 (msg_size << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
1609 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
1610 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT));
1611}
1612
1613static void intel_edp_psr_enable_source(struct intel_dp *intel_dp)
1614{
1615 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1616 struct drm_i915_private *dev_priv = dev->dev_private;
1617 uint32_t max_sleep_time = 0x1f;
1618 uint32_t idle_frames = 1;
1619 uint32_t val = 0x0;
Ben Widawskyed8546a2013-11-04 22:45:05 -08001620 const uint32_t link_entry_time = EDP_PSR_MIN_LINK_ENTRY_TIME_8_LINES;
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001621
1622 if (intel_dp->psr_dpcd[1] & DP_PSR_NO_TRAIN_ON_EXIT) {
1623 val |= EDP_PSR_LINK_STANDBY;
1624 val |= EDP_PSR_TP2_TP3_TIME_0us;
1625 val |= EDP_PSR_TP1_TIME_0us;
1626 val |= EDP_PSR_SKIP_AUX_EXIT;
1627 } else
1628 val |= EDP_PSR_LINK_DISABLE;
1629
Ben Widawsky18b59922013-09-20 09:35:30 -07001630 I915_WRITE(EDP_PSR_CTL(dev), val |
Ben Widawskyed8546a2013-11-04 22:45:05 -08001631 IS_BROADWELL(dev) ? 0 : link_entry_time |
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001632 max_sleep_time << EDP_PSR_MAX_SLEEP_TIME_SHIFT |
1633 idle_frames << EDP_PSR_IDLE_FRAME_SHIFT |
1634 EDP_PSR_ENABLE);
1635}
1636
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001637static bool intel_edp_psr_match_conditions(struct intel_dp *intel_dp)
1638{
1639 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1640 struct drm_device *dev = dig_port->base.base.dev;
1641 struct drm_i915_private *dev_priv = dev->dev_private;
1642 struct drm_crtc *crtc = dig_port->base.base.crtc;
1643 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1644 struct drm_i915_gem_object *obj = to_intel_framebuffer(crtc->fb)->obj;
1645 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
1646
Rodrigo Vivia031d702013-10-03 16:15:06 -03001647 dev_priv->psr.source_ok = false;
1648
Ben Widawsky18b59922013-09-20 09:35:30 -07001649 if (!HAS_PSR(dev)) {
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001650 DRM_DEBUG_KMS("PSR not supported on this platform\n");
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001651 return false;
1652 }
1653
1654 if ((intel_encoder->type != INTEL_OUTPUT_EDP) ||
1655 (dig_port->port != PORT_A)) {
1656 DRM_DEBUG_KMS("HSW ties PSR to DDI A (eDP)\n");
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001657 return false;
1658 }
1659
Rodrigo Vivi105b7c12013-07-11 18:45:02 -03001660 if (!i915_enable_psr) {
1661 DRM_DEBUG_KMS("PSR disable by flag\n");
Rodrigo Vivi105b7c12013-07-11 18:45:02 -03001662 return false;
1663 }
1664
Chris Wilsoncd234b02013-08-02 20:39:49 +01001665 crtc = dig_port->base.base.crtc;
1666 if (crtc == NULL) {
1667 DRM_DEBUG_KMS("crtc not active for PSR\n");
Chris Wilsoncd234b02013-08-02 20:39:49 +01001668 return false;
1669 }
1670
1671 intel_crtc = to_intel_crtc(crtc);
Ville Syrjälä20ddf662013-09-04 18:25:25 +03001672 if (!intel_crtc_active(crtc)) {
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001673 DRM_DEBUG_KMS("crtc not active for PSR\n");
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001674 return false;
1675 }
1676
Chris Wilsoncd234b02013-08-02 20:39:49 +01001677 obj = to_intel_framebuffer(crtc->fb)->obj;
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001678 if (obj->tiling_mode != I915_TILING_X ||
1679 obj->fence_reg == I915_FENCE_REG_NONE) {
1680 DRM_DEBUG_KMS("PSR condition failed: fb not tiled or fenced\n");
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001681 return false;
1682 }
1683
1684 if (I915_READ(SPRCTL(intel_crtc->pipe)) & SPRITE_ENABLE) {
1685 DRM_DEBUG_KMS("PSR condition failed: Sprite is Enabled\n");
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001686 return false;
1687 }
1688
1689 if (I915_READ(HSW_STEREO_3D_CTL(intel_crtc->config.cpu_transcoder)) &
1690 S3D_ENABLE) {
1691 DRM_DEBUG_KMS("PSR condition failed: Stereo 3D is Enabled\n");
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001692 return false;
1693 }
1694
Ville Syrjäläca73b4f2013-09-04 18:25:24 +03001695 if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001696 DRM_DEBUG_KMS("PSR condition failed: Interlaced is Enabled\n");
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001697 return false;
1698 }
1699
Rodrigo Vivia031d702013-10-03 16:15:06 -03001700 dev_priv->psr.source_ok = true;
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001701 return true;
1702}
1703
Rodrigo Vivi3d739d92013-07-11 18:45:01 -03001704static void intel_edp_psr_do_enable(struct intel_dp *intel_dp)
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001705{
1706 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1707
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001708 if (!intel_edp_psr_match_conditions(intel_dp) ||
1709 intel_edp_is_psr_enabled(dev))
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001710 return;
1711
1712 /* Setup PSR once */
1713 intel_edp_psr_setup(intel_dp);
1714
1715 /* Enable PSR on the panel */
1716 intel_edp_psr_enable_sink(intel_dp);
1717
1718 /* Enable PSR on the host */
1719 intel_edp_psr_enable_source(intel_dp);
1720}
1721
Rodrigo Vivi3d739d92013-07-11 18:45:01 -03001722void intel_edp_psr_enable(struct intel_dp *intel_dp)
1723{
1724 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1725
1726 if (intel_edp_psr_match_conditions(intel_dp) &&
1727 !intel_edp_is_psr_enabled(dev))
1728 intel_edp_psr_do_enable(intel_dp);
1729}
1730
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001731void intel_edp_psr_disable(struct intel_dp *intel_dp)
1732{
1733 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1734 struct drm_i915_private *dev_priv = dev->dev_private;
1735
1736 if (!intel_edp_is_psr_enabled(dev))
1737 return;
1738
Ben Widawsky18b59922013-09-20 09:35:30 -07001739 I915_WRITE(EDP_PSR_CTL(dev),
1740 I915_READ(EDP_PSR_CTL(dev)) & ~EDP_PSR_ENABLE);
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001741
1742 /* Wait till PSR is idle */
Ben Widawsky18b59922013-09-20 09:35:30 -07001743 if (_wait_for((I915_READ(EDP_PSR_STATUS_CTL(dev)) &
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001744 EDP_PSR_STATUS_STATE_MASK) == 0, 2000, 10))
1745 DRM_ERROR("Timed out waiting for PSR Idle State\n");
1746}
1747
Rodrigo Vivi3d739d92013-07-11 18:45:01 -03001748void intel_edp_psr_update(struct drm_device *dev)
1749{
1750 struct intel_encoder *encoder;
1751 struct intel_dp *intel_dp = NULL;
1752
1753 list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head)
1754 if (encoder->type == INTEL_OUTPUT_EDP) {
1755 intel_dp = enc_to_intel_dp(&encoder->base);
1756
Rodrigo Vivia031d702013-10-03 16:15:06 -03001757 if (!is_edp_psr(dev))
Rodrigo Vivi3d739d92013-07-11 18:45:01 -03001758 return;
1759
1760 if (!intel_edp_psr_match_conditions(intel_dp))
1761 intel_edp_psr_disable(intel_dp);
1762 else
1763 if (!intel_edp_is_psr_enabled(dev))
1764 intel_edp_psr_do_enable(intel_dp);
1765 }
1766}
1767
Daniel Vettere8cb4552012-07-01 13:05:48 +02001768static void intel_disable_dp(struct intel_encoder *encoder)
Jesse Barnesd240f202010-08-13 15:43:26 -07001769{
Daniel Vettere8cb4552012-07-01 13:05:48 +02001770 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03001771 enum port port = dp_to_dig_port(intel_dp)->port;
1772 struct drm_device *dev = encoder->base.dev;
Daniel Vetter6cb49832012-05-20 17:14:50 +02001773
1774 /* Make sure the panel is off before trying to change the mode. But also
1775 * ensure that we have vdd while we switch off the panel. */
1776 ironlake_edp_panel_vdd_on(intel_dp);
Keith Packard21264c62011-11-01 20:25:21 -07001777 ironlake_edp_backlight_off(intel_dp);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001778 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
Daniel Vetter35a38552012-08-12 22:17:14 +02001779 ironlake_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02001780
1781 /* cpu edp my only be disable _after_ the cpu pipe/plane is disabled. */
Imre Deak982a3862013-05-23 19:39:40 +03001782 if (!(port == PORT_A || IS_VALLEYVIEW(dev)))
Daniel Vetter37398502012-09-06 22:15:44 +02001783 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07001784}
1785
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001786static void intel_post_disable_dp(struct intel_encoder *encoder)
Jesse Barnesd240f202010-08-13 15:43:26 -07001787{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001788 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03001789 enum port port = dp_to_dig_port(intel_dp)->port;
Jesse Barnesb2634012013-03-28 09:55:40 -07001790 struct drm_device *dev = encoder->base.dev;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001791
Imre Deak982a3862013-05-23 19:39:40 +03001792 if (port == PORT_A || IS_VALLEYVIEW(dev)) {
Daniel Vetter37398502012-09-06 22:15:44 +02001793 intel_dp_link_down(intel_dp);
Jesse Barnesb2634012013-03-28 09:55:40 -07001794 if (!IS_VALLEYVIEW(dev))
1795 ironlake_edp_pll_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02001796 }
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001797}
1798
Daniel Vettere8cb4552012-07-01 13:05:48 +02001799static void intel_enable_dp(struct intel_encoder *encoder)
Jesse Barnesd240f202010-08-13 15:43:26 -07001800{
Daniel Vettere8cb4552012-07-01 13:05:48 +02001801 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1802 struct drm_device *dev = encoder->base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001803 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001804 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001805
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02001806 if (WARN_ON(dp_reg & DP_PORT_EN))
1807 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001808
1809 ironlake_edp_panel_vdd_on(intel_dp);
1810 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1811 intel_dp_start_link_train(intel_dp);
1812 ironlake_edp_panel_on(intel_dp);
1813 ironlake_edp_panel_vdd_off(intel_dp, true);
1814 intel_dp_complete_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03001815 intel_dp_stop_link_train(intel_dp);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03001816}
Jesse Barnes89b667f2013-04-18 14:51:36 -07001817
Jani Nikulaecff4f32013-09-06 07:38:29 +03001818static void g4x_enable_dp(struct intel_encoder *encoder)
1819{
Jani Nikula828f5c62013-09-05 16:44:45 +03001820 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1821
Jani Nikulaecff4f32013-09-06 07:38:29 +03001822 intel_enable_dp(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001823 ironlake_edp_backlight_on(intel_dp);
1824}
Jesse Barnes89b667f2013-04-18 14:51:36 -07001825
Jani Nikulaab1f90f2013-07-30 12:20:30 +03001826static void vlv_enable_dp(struct intel_encoder *encoder)
1827{
Jani Nikula828f5c62013-09-05 16:44:45 +03001828 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1829
1830 ironlake_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001831}
1832
Jani Nikulaecff4f32013-09-06 07:38:29 +03001833static void g4x_pre_enable_dp(struct intel_encoder *encoder)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001834{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001835 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001836 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03001837
1838 if (dport->port == PORT_A)
1839 ironlake_edp_pll_on(intel_dp);
1840}
1841
1842static void vlv_pre_enable_dp(struct intel_encoder *encoder)
1843{
1844 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1845 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
Jesse Barnesb2634012013-03-28 09:55:40 -07001846 struct drm_device *dev = encoder->base.dev;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001847 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03001848 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
1849 int port = vlv_dport_to_channel(dport);
1850 int pipe = intel_crtc->pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +03001851 struct edp_power_seq power_seq;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03001852 u32 val;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001853
Jani Nikulaab1f90f2013-07-30 12:20:30 +03001854 mutex_lock(&dev_priv->dpio_lock);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001855
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001856 val = vlv_dpio_read(dev_priv, pipe, DPIO_DATA_LANE_A(port));
Jani Nikulaab1f90f2013-07-30 12:20:30 +03001857 val = 0;
1858 if (pipe)
1859 val |= (1<<21);
1860 else
1861 val &= ~(1<<21);
1862 val |= 0x001000c4;
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001863 vlv_dpio_write(dev_priv, pipe, DPIO_DATA_CHANNEL(port), val);
1864 vlv_dpio_write(dev_priv, pipe, DPIO_PCS_CLOCKBUF0(port), 0x00760018);
1865 vlv_dpio_write(dev_priv, pipe, DPIO_PCS_CLOCKBUF8(port), 0x00400888);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001866
Jani Nikulaab1f90f2013-07-30 12:20:30 +03001867 mutex_unlock(&dev_priv->dpio_lock);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001868
Jani Nikulabf13e812013-09-06 07:40:05 +03001869 /* init power sequencer on this pipe and port */
1870 intel_dp_init_panel_power_sequencer(dev, intel_dp, &power_seq);
1871 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp,
1872 &power_seq);
1873
Jani Nikulaab1f90f2013-07-30 12:20:30 +03001874 intel_enable_dp(encoder);
1875
1876 vlv_wait_port_ready(dev_priv, port);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001877}
1878
Jani Nikulaecff4f32013-09-06 07:38:29 +03001879static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder)
Jesse Barnes89b667f2013-04-18 14:51:36 -07001880{
1881 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1882 struct drm_device *dev = encoder->base.dev;
1883 struct drm_i915_private *dev_priv = dev->dev_private;
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001884 struct intel_crtc *intel_crtc =
1885 to_intel_crtc(encoder->base.crtc);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001886 int port = vlv_dport_to_channel(dport);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001887 int pipe = intel_crtc->pipe;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001888
Jesse Barnes89b667f2013-04-18 14:51:36 -07001889 /* Program Tx lane resets to default */
Chris Wilson0980a602013-07-26 19:57:35 +01001890 mutex_lock(&dev_priv->dpio_lock);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001891 vlv_dpio_write(dev_priv, pipe, DPIO_PCS_TX(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001892 DPIO_PCS_TX_LANE2_RESET |
1893 DPIO_PCS_TX_LANE1_RESET);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001894 vlv_dpio_write(dev_priv, pipe, DPIO_PCS_CLK(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001895 DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
1896 DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
1897 (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
1898 DPIO_PCS_CLK_SOFT_RESET);
1899
1900 /* Fix up inter-pair skew failure */
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001901 vlv_dpio_write(dev_priv, pipe, DPIO_PCS_STAGGER1(port), 0x00750f00);
1902 vlv_dpio_write(dev_priv, pipe, DPIO_TX_CTL(port), 0x00001500);
1903 vlv_dpio_write(dev_priv, pipe, DPIO_TX_LANE(port), 0x40400000);
Chris Wilson0980a602013-07-26 19:57:35 +01001904 mutex_unlock(&dev_priv->dpio_lock);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001905}
1906
1907/*
Jesse Barnesdf0c2372011-07-07 11:11:02 -07001908 * Native read with retry for link status and receiver capability reads for
1909 * cases where the sink may still be asleep.
1910 */
1911static bool
1912intel_dp_aux_native_read_retry(struct intel_dp *intel_dp, uint16_t address,
1913 uint8_t *recv, int recv_bytes)
1914{
1915 int ret, i;
1916
1917 /*
1918 * Sinks are *supposed* to come up within 1ms from an off state,
1919 * but we're also supposed to retry 3 times per the spec.
1920 */
1921 for (i = 0; i < 3; i++) {
1922 ret = intel_dp_aux_native_read(intel_dp, address, recv,
1923 recv_bytes);
1924 if (ret == recv_bytes)
1925 return true;
1926 msleep(1);
1927 }
1928
1929 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001930}
1931
1932/*
1933 * Fetch AUX CH registers 0x202 - 0x207 which contain
1934 * link status information
1935 */
1936static bool
Keith Packard93f62da2011-11-01 19:45:03 -07001937intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001938{
Jesse Barnesdf0c2372011-07-07 11:11:02 -07001939 return intel_dp_aux_native_read_retry(intel_dp,
1940 DP_LANE0_1_STATUS,
Keith Packard93f62da2011-11-01 19:45:03 -07001941 link_status,
Jesse Barnesdf0c2372011-07-07 11:11:02 -07001942 DP_LINK_STATUS_SIZE);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001943}
1944
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001945#if 0
1946static char *voltage_names[] = {
1947 "0.4V", "0.6V", "0.8V", "1.2V"
1948};
1949static char *pre_emph_names[] = {
1950 "0dB", "3.5dB", "6dB", "9.5dB"
1951};
1952static char *link_train_names[] = {
1953 "pattern 1", "pattern 2", "idle", "off"
1954};
1955#endif
1956
1957/*
1958 * These are source-specific values; current Intel hardware supports
1959 * a maximum voltage of 800mV and a maximum pre-emphasis of 6dB
1960 */
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001961
1962static uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08001963intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001964{
Paulo Zanoni30add222012-10-26 19:05:45 -02001965 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001966 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08001967
Paulo Zanoni8f93f4f2013-11-02 21:07:43 -07001968 if (IS_VALLEYVIEW(dev) || IS_BROADWELL(dev))
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07001969 return DP_TRAIN_VOLTAGE_SWING_1200;
Imre Deakbc7d38a2013-05-16 14:40:36 +03001970 else if (IS_GEN7(dev) && port == PORT_A)
Keith Packard1a2eb462011-11-16 16:26:07 -08001971 return DP_TRAIN_VOLTAGE_SWING_800;
Imre Deakbc7d38a2013-05-16 14:40:36 +03001972 else if (HAS_PCH_CPT(dev) && port != PORT_A)
Keith Packard1a2eb462011-11-16 16:26:07 -08001973 return DP_TRAIN_VOLTAGE_SWING_1200;
1974 else
1975 return DP_TRAIN_VOLTAGE_SWING_800;
1976}
1977
1978static uint8_t
1979intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
1980{
Paulo Zanoni30add222012-10-26 19:05:45 -02001981 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001982 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08001983
Paulo Zanoni8f93f4f2013-11-02 21:07:43 -07001984 if (IS_BROADWELL(dev)) {
1985 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
1986 case DP_TRAIN_VOLTAGE_SWING_400:
1987 case DP_TRAIN_VOLTAGE_SWING_600:
1988 return DP_TRAIN_PRE_EMPHASIS_6;
1989 case DP_TRAIN_VOLTAGE_SWING_800:
1990 return DP_TRAIN_PRE_EMPHASIS_3_5;
1991 case DP_TRAIN_VOLTAGE_SWING_1200:
1992 default:
1993 return DP_TRAIN_PRE_EMPHASIS_0;
1994 }
1995 } else if (IS_HASWELL(dev)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001996 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
1997 case DP_TRAIN_VOLTAGE_SWING_400:
1998 return DP_TRAIN_PRE_EMPHASIS_9_5;
1999 case DP_TRAIN_VOLTAGE_SWING_600:
2000 return DP_TRAIN_PRE_EMPHASIS_6;
2001 case DP_TRAIN_VOLTAGE_SWING_800:
2002 return DP_TRAIN_PRE_EMPHASIS_3_5;
2003 case DP_TRAIN_VOLTAGE_SWING_1200:
2004 default:
2005 return DP_TRAIN_PRE_EMPHASIS_0;
2006 }
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002007 } else if (IS_VALLEYVIEW(dev)) {
2008 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
2009 case DP_TRAIN_VOLTAGE_SWING_400:
2010 return DP_TRAIN_PRE_EMPHASIS_9_5;
2011 case DP_TRAIN_VOLTAGE_SWING_600:
2012 return DP_TRAIN_PRE_EMPHASIS_6;
2013 case DP_TRAIN_VOLTAGE_SWING_800:
2014 return DP_TRAIN_PRE_EMPHASIS_3_5;
2015 case DP_TRAIN_VOLTAGE_SWING_1200:
2016 default:
2017 return DP_TRAIN_PRE_EMPHASIS_0;
2018 }
Imre Deakbc7d38a2013-05-16 14:40:36 +03002019 } else if (IS_GEN7(dev) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08002020 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
2021 case DP_TRAIN_VOLTAGE_SWING_400:
2022 return DP_TRAIN_PRE_EMPHASIS_6;
2023 case DP_TRAIN_VOLTAGE_SWING_600:
2024 case DP_TRAIN_VOLTAGE_SWING_800:
2025 return DP_TRAIN_PRE_EMPHASIS_3_5;
2026 default:
2027 return DP_TRAIN_PRE_EMPHASIS_0;
2028 }
2029 } else {
2030 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
2031 case DP_TRAIN_VOLTAGE_SWING_400:
2032 return DP_TRAIN_PRE_EMPHASIS_6;
2033 case DP_TRAIN_VOLTAGE_SWING_600:
2034 return DP_TRAIN_PRE_EMPHASIS_6;
2035 case DP_TRAIN_VOLTAGE_SWING_800:
2036 return DP_TRAIN_PRE_EMPHASIS_3_5;
2037 case DP_TRAIN_VOLTAGE_SWING_1200:
2038 default:
2039 return DP_TRAIN_PRE_EMPHASIS_0;
2040 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002041 }
2042}
2043
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002044static uint32_t intel_vlv_signal_levels(struct intel_dp *intel_dp)
2045{
2046 struct drm_device *dev = intel_dp_to_dev(intel_dp);
2047 struct drm_i915_private *dev_priv = dev->dev_private;
2048 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08002049 struct intel_crtc *intel_crtc =
2050 to_intel_crtc(dport->base.base.crtc);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002051 unsigned long demph_reg_value, preemph_reg_value,
2052 uniqtranscale_reg_value;
2053 uint8_t train_set = intel_dp->train_set[0];
Jesse Barnescece5d52013-04-19 08:46:35 -07002054 int port = vlv_dport_to_channel(dport);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08002055 int pipe = intel_crtc->pipe;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002056
2057 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
2058 case DP_TRAIN_PRE_EMPHASIS_0:
2059 preemph_reg_value = 0x0004000;
2060 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
2061 case DP_TRAIN_VOLTAGE_SWING_400:
2062 demph_reg_value = 0x2B405555;
2063 uniqtranscale_reg_value = 0x552AB83A;
2064 break;
2065 case DP_TRAIN_VOLTAGE_SWING_600:
2066 demph_reg_value = 0x2B404040;
2067 uniqtranscale_reg_value = 0x5548B83A;
2068 break;
2069 case DP_TRAIN_VOLTAGE_SWING_800:
2070 demph_reg_value = 0x2B245555;
2071 uniqtranscale_reg_value = 0x5560B83A;
2072 break;
2073 case DP_TRAIN_VOLTAGE_SWING_1200:
2074 demph_reg_value = 0x2B405555;
2075 uniqtranscale_reg_value = 0x5598DA3A;
2076 break;
2077 default:
2078 return 0;
2079 }
2080 break;
2081 case DP_TRAIN_PRE_EMPHASIS_3_5:
2082 preemph_reg_value = 0x0002000;
2083 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
2084 case DP_TRAIN_VOLTAGE_SWING_400:
2085 demph_reg_value = 0x2B404040;
2086 uniqtranscale_reg_value = 0x5552B83A;
2087 break;
2088 case DP_TRAIN_VOLTAGE_SWING_600:
2089 demph_reg_value = 0x2B404848;
2090 uniqtranscale_reg_value = 0x5580B83A;
2091 break;
2092 case DP_TRAIN_VOLTAGE_SWING_800:
2093 demph_reg_value = 0x2B404040;
2094 uniqtranscale_reg_value = 0x55ADDA3A;
2095 break;
2096 default:
2097 return 0;
2098 }
2099 break;
2100 case DP_TRAIN_PRE_EMPHASIS_6:
2101 preemph_reg_value = 0x0000000;
2102 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
2103 case DP_TRAIN_VOLTAGE_SWING_400:
2104 demph_reg_value = 0x2B305555;
2105 uniqtranscale_reg_value = 0x5570B83A;
2106 break;
2107 case DP_TRAIN_VOLTAGE_SWING_600:
2108 demph_reg_value = 0x2B2B4040;
2109 uniqtranscale_reg_value = 0x55ADDA3A;
2110 break;
2111 default:
2112 return 0;
2113 }
2114 break;
2115 case DP_TRAIN_PRE_EMPHASIS_9_5:
2116 preemph_reg_value = 0x0006000;
2117 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
2118 case DP_TRAIN_VOLTAGE_SWING_400:
2119 demph_reg_value = 0x1B405555;
2120 uniqtranscale_reg_value = 0x55ADDA3A;
2121 break;
2122 default:
2123 return 0;
2124 }
2125 break;
2126 default:
2127 return 0;
2128 }
2129
Chris Wilson0980a602013-07-26 19:57:35 +01002130 mutex_lock(&dev_priv->dpio_lock);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08002131 vlv_dpio_write(dev_priv, pipe, DPIO_TX_OCALINIT(port), 0x00000000);
2132 vlv_dpio_write(dev_priv, pipe, DPIO_TX_SWING_CTL4(port), demph_reg_value);
2133 vlv_dpio_write(dev_priv, pipe, DPIO_TX_SWING_CTL2(port),
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002134 uniqtranscale_reg_value);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08002135 vlv_dpio_write(dev_priv, pipe, DPIO_TX_SWING_CTL3(port), 0x0C782040);
2136 vlv_dpio_write(dev_priv, pipe, DPIO_PCS_STAGGER0(port), 0x00030000);
2137 vlv_dpio_write(dev_priv, pipe, DPIO_PCS_CTL_OVER1(port), preemph_reg_value);
2138 vlv_dpio_write(dev_priv, pipe, DPIO_TX_OCALINIT(port), 0x80000000);
Chris Wilson0980a602013-07-26 19:57:35 +01002139 mutex_unlock(&dev_priv->dpio_lock);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002140
2141 return 0;
2142}
2143
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002144static void
Jani Nikula0301b3a2013-10-15 09:36:08 +03002145intel_get_adjust_train(struct intel_dp *intel_dp,
2146 const uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002147{
2148 uint8_t v = 0;
2149 uint8_t p = 0;
2150 int lane;
Keith Packard1a2eb462011-11-16 16:26:07 -08002151 uint8_t voltage_max;
2152 uint8_t preemph_max;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002153
Jesse Barnes33a34e42010-09-08 12:42:02 -07002154 for (lane = 0; lane < intel_dp->lane_count; lane++) {
Daniel Vetter0f037bd2012-10-18 10:15:27 +02002155 uint8_t this_v = drm_dp_get_adjust_request_voltage(link_status, lane);
2156 uint8_t this_p = drm_dp_get_adjust_request_pre_emphasis(link_status, lane);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002157
2158 if (this_v > v)
2159 v = this_v;
2160 if (this_p > p)
2161 p = this_p;
2162 }
2163
Keith Packard1a2eb462011-11-16 16:26:07 -08002164 voltage_max = intel_dp_voltage_max(intel_dp);
Keith Packard417e8222011-11-01 19:54:11 -07002165 if (v >= voltage_max)
2166 v = voltage_max | DP_TRAIN_MAX_SWING_REACHED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002167
Keith Packard1a2eb462011-11-16 16:26:07 -08002168 preemph_max = intel_dp_pre_emphasis_max(intel_dp, v);
2169 if (p >= preemph_max)
2170 p = preemph_max | DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002171
2172 for (lane = 0; lane < 4; lane++)
Jesse Barnes33a34e42010-09-08 12:42:02 -07002173 intel_dp->train_set[lane] = v | p;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002174}
2175
2176static uint32_t
Paulo Zanonif0a34242012-12-06 16:51:50 -02002177intel_gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002178{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002179 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002180
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002181 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002182 case DP_TRAIN_VOLTAGE_SWING_400:
2183 default:
2184 signal_levels |= DP_VOLTAGE_0_4;
2185 break;
2186 case DP_TRAIN_VOLTAGE_SWING_600:
2187 signal_levels |= DP_VOLTAGE_0_6;
2188 break;
2189 case DP_TRAIN_VOLTAGE_SWING_800:
2190 signal_levels |= DP_VOLTAGE_0_8;
2191 break;
2192 case DP_TRAIN_VOLTAGE_SWING_1200:
2193 signal_levels |= DP_VOLTAGE_1_2;
2194 break;
2195 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002196 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002197 case DP_TRAIN_PRE_EMPHASIS_0:
2198 default:
2199 signal_levels |= DP_PRE_EMPHASIS_0;
2200 break;
2201 case DP_TRAIN_PRE_EMPHASIS_3_5:
2202 signal_levels |= DP_PRE_EMPHASIS_3_5;
2203 break;
2204 case DP_TRAIN_PRE_EMPHASIS_6:
2205 signal_levels |= DP_PRE_EMPHASIS_6;
2206 break;
2207 case DP_TRAIN_PRE_EMPHASIS_9_5:
2208 signal_levels |= DP_PRE_EMPHASIS_9_5;
2209 break;
2210 }
2211 return signal_levels;
2212}
2213
Zhenyu Wange3421a12010-04-08 09:43:27 +08002214/* Gen6's DP voltage swing and pre-emphasis control */
2215static uint32_t
2216intel_gen6_edp_signal_levels(uint8_t train_set)
2217{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08002218 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
2219 DP_TRAIN_PRE_EMPHASIS_MASK);
2220 switch (signal_levels) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08002221 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08002222 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
2223 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
2224 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
2225 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08002226 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08002227 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
2228 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08002229 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08002230 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
2231 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08002232 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08002233 case DP_TRAIN_VOLTAGE_SWING_1200 | DP_TRAIN_PRE_EMPHASIS_0:
2234 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08002235 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08002236 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
2237 "0x%x\n", signal_levels);
2238 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08002239 }
2240}
2241
Keith Packard1a2eb462011-11-16 16:26:07 -08002242/* Gen7's DP voltage swing and pre-emphasis control */
2243static uint32_t
2244intel_gen7_edp_signal_levels(uint8_t train_set)
2245{
2246 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
2247 DP_TRAIN_PRE_EMPHASIS_MASK);
2248 switch (signal_levels) {
2249 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
2250 return EDP_LINK_TRAIN_400MV_0DB_IVB;
2251 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
2252 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
2253 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
2254 return EDP_LINK_TRAIN_400MV_6DB_IVB;
2255
2256 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
2257 return EDP_LINK_TRAIN_600MV_0DB_IVB;
2258 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
2259 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
2260
2261 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
2262 return EDP_LINK_TRAIN_800MV_0DB_IVB;
2263 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
2264 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
2265
2266 default:
2267 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
2268 "0x%x\n", signal_levels);
2269 return EDP_LINK_TRAIN_500MV_0DB_IVB;
2270 }
2271}
2272
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002273/* Gen7.5's (HSW) DP voltage swing and pre-emphasis control */
2274static uint32_t
Paulo Zanonif0a34242012-12-06 16:51:50 -02002275intel_hsw_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002276{
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002277 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
2278 DP_TRAIN_PRE_EMPHASIS_MASK);
2279 switch (signal_levels) {
2280 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
2281 return DDI_BUF_EMP_400MV_0DB_HSW;
2282 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
2283 return DDI_BUF_EMP_400MV_3_5DB_HSW;
2284 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
2285 return DDI_BUF_EMP_400MV_6DB_HSW;
2286 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_9_5:
2287 return DDI_BUF_EMP_400MV_9_5DB_HSW;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002288
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002289 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
2290 return DDI_BUF_EMP_600MV_0DB_HSW;
2291 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
2292 return DDI_BUF_EMP_600MV_3_5DB_HSW;
2293 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
2294 return DDI_BUF_EMP_600MV_6DB_HSW;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002295
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002296 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
2297 return DDI_BUF_EMP_800MV_0DB_HSW;
2298 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
2299 return DDI_BUF_EMP_800MV_3_5DB_HSW;
2300 default:
2301 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
2302 "0x%x\n", signal_levels);
2303 return DDI_BUF_EMP_400MV_0DB_HSW;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002304 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002305}
2306
Paulo Zanoni8f93f4f2013-11-02 21:07:43 -07002307static uint32_t
2308intel_bdw_signal_levels(uint8_t train_set)
2309{
2310 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
2311 DP_TRAIN_PRE_EMPHASIS_MASK);
2312 switch (signal_levels) {
2313 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
2314 return DDI_BUF_EMP_400MV_0DB_BDW; /* Sel0 */
2315 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
2316 return DDI_BUF_EMP_400MV_3_5DB_BDW; /* Sel1 */
2317 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
2318 return DDI_BUF_EMP_400MV_6DB_BDW; /* Sel2 */
2319
2320 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
2321 return DDI_BUF_EMP_600MV_0DB_BDW; /* Sel3 */
2322 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
2323 return DDI_BUF_EMP_600MV_3_5DB_BDW; /* Sel4 */
2324 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
2325 return DDI_BUF_EMP_600MV_6DB_BDW; /* Sel5 */
2326
2327 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
2328 return DDI_BUF_EMP_800MV_0DB_BDW; /* Sel6 */
2329 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
2330 return DDI_BUF_EMP_800MV_3_5DB_BDW; /* Sel7 */
2331
2332 case DP_TRAIN_VOLTAGE_SWING_1200 | DP_TRAIN_PRE_EMPHASIS_0:
2333 return DDI_BUF_EMP_1200MV_0DB_BDW; /* Sel8 */
2334
2335 default:
2336 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
2337 "0x%x\n", signal_levels);
2338 return DDI_BUF_EMP_400MV_0DB_BDW; /* Sel0 */
2339 }
2340}
2341
Paulo Zanonif0a34242012-12-06 16:51:50 -02002342/* Properly updates "DP" with the correct signal levels. */
2343static void
2344intel_dp_set_signal_levels(struct intel_dp *intel_dp, uint32_t *DP)
2345{
2346 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002347 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02002348 struct drm_device *dev = intel_dig_port->base.base.dev;
2349 uint32_t signal_levels, mask;
2350 uint8_t train_set = intel_dp->train_set[0];
2351
Paulo Zanoni8f93f4f2013-11-02 21:07:43 -07002352 if (IS_BROADWELL(dev)) {
2353 signal_levels = intel_bdw_signal_levels(train_set);
2354 mask = DDI_BUF_EMP_MASK;
2355 } else if (IS_HASWELL(dev)) {
Paulo Zanonif0a34242012-12-06 16:51:50 -02002356 signal_levels = intel_hsw_signal_levels(train_set);
2357 mask = DDI_BUF_EMP_MASK;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002358 } else if (IS_VALLEYVIEW(dev)) {
2359 signal_levels = intel_vlv_signal_levels(intel_dp);
2360 mask = 0;
Imre Deakbc7d38a2013-05-16 14:40:36 +03002361 } else if (IS_GEN7(dev) && port == PORT_A) {
Paulo Zanonif0a34242012-12-06 16:51:50 -02002362 signal_levels = intel_gen7_edp_signal_levels(train_set);
2363 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Imre Deakbc7d38a2013-05-16 14:40:36 +03002364 } else if (IS_GEN6(dev) && port == PORT_A) {
Paulo Zanonif0a34242012-12-06 16:51:50 -02002365 signal_levels = intel_gen6_edp_signal_levels(train_set);
2366 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
2367 } else {
2368 signal_levels = intel_gen4_signal_levels(train_set);
2369 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
2370 }
2371
2372 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
2373
2374 *DP = (*DP & ~mask) | signal_levels;
2375}
2376
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002377static bool
Chris Wilsonea5b2132010-08-04 13:50:23 +01002378intel_dp_set_link_train(struct intel_dp *intel_dp,
Jani Nikula70aff662013-09-27 15:10:44 +03002379 uint32_t *DP,
Chris Wilson58e10eb2010-10-03 10:56:11 +01002380 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002381{
Paulo Zanoni174edf12012-10-26 19:05:50 -02002382 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2383 struct drm_device *dev = intel_dig_port->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002384 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -02002385 enum port port = intel_dig_port->port;
Jani Nikula2cdfe6c2013-10-04 15:08:48 +03002386 uint8_t buf[sizeof(intel_dp->train_set) + 1];
2387 int ret, len;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002388
Paulo Zanoni22b8bf12013-02-18 19:00:23 -03002389 if (HAS_DDI(dev)) {
Imre Deak3ab9c632013-05-03 12:57:41 +03002390 uint32_t temp = I915_READ(DP_TP_CTL(port));
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002391
2392 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2393 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2394 else
2395 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2396
2397 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2398 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2399 case DP_TRAINING_PATTERN_DISABLE:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002400 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2401
2402 break;
2403 case DP_TRAINING_PATTERN_1:
2404 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2405 break;
2406 case DP_TRAINING_PATTERN_2:
2407 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2408 break;
2409 case DP_TRAINING_PATTERN_3:
2410 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2411 break;
2412 }
Paulo Zanoni174edf12012-10-26 19:05:50 -02002413 I915_WRITE(DP_TP_CTL(port), temp);
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002414
Imre Deakbc7d38a2013-05-16 14:40:36 +03002415 } else if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || port != PORT_A)) {
Jani Nikula70aff662013-09-27 15:10:44 +03002416 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002417
2418 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2419 case DP_TRAINING_PATTERN_DISABLE:
Jani Nikula70aff662013-09-27 15:10:44 +03002420 *DP |= DP_LINK_TRAIN_OFF_CPT;
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002421 break;
2422 case DP_TRAINING_PATTERN_1:
Jani Nikula70aff662013-09-27 15:10:44 +03002423 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002424 break;
2425 case DP_TRAINING_PATTERN_2:
Jani Nikula70aff662013-09-27 15:10:44 +03002426 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002427 break;
2428 case DP_TRAINING_PATTERN_3:
2429 DRM_ERROR("DP training pattern 3 not supported\n");
Jani Nikula70aff662013-09-27 15:10:44 +03002430 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002431 break;
2432 }
2433
2434 } else {
Jani Nikula70aff662013-09-27 15:10:44 +03002435 *DP &= ~DP_LINK_TRAIN_MASK;
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002436
2437 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2438 case DP_TRAINING_PATTERN_DISABLE:
Jani Nikula70aff662013-09-27 15:10:44 +03002439 *DP |= DP_LINK_TRAIN_OFF;
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002440 break;
2441 case DP_TRAINING_PATTERN_1:
Jani Nikula70aff662013-09-27 15:10:44 +03002442 *DP |= DP_LINK_TRAIN_PAT_1;
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002443 break;
2444 case DP_TRAINING_PATTERN_2:
Jani Nikula70aff662013-09-27 15:10:44 +03002445 *DP |= DP_LINK_TRAIN_PAT_2;
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002446 break;
2447 case DP_TRAINING_PATTERN_3:
2448 DRM_ERROR("DP training pattern 3 not supported\n");
Jani Nikula70aff662013-09-27 15:10:44 +03002449 *DP |= DP_LINK_TRAIN_PAT_2;
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002450 break;
2451 }
2452 }
2453
Jani Nikula70aff662013-09-27 15:10:44 +03002454 I915_WRITE(intel_dp->output_reg, *DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002455 POSTING_READ(intel_dp->output_reg);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002456
Jani Nikula2cdfe6c2013-10-04 15:08:48 +03002457 buf[0] = dp_train_pat;
2458 if ((dp_train_pat & DP_TRAINING_PATTERN_MASK) ==
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002459 DP_TRAINING_PATTERN_DISABLE) {
Jani Nikula2cdfe6c2013-10-04 15:08:48 +03002460 /* don't write DP_TRAINING_LANEx_SET on disable */
2461 len = 1;
2462 } else {
2463 /* DP_TRAINING_LANEx_SET follow DP_TRAINING_PATTERN_SET */
2464 memcpy(buf + 1, intel_dp->train_set, intel_dp->lane_count);
2465 len = intel_dp->lane_count + 1;
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002466 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002467
Jani Nikula2cdfe6c2013-10-04 15:08:48 +03002468 ret = intel_dp_aux_native_write(intel_dp, DP_TRAINING_PATTERN_SET,
2469 buf, len);
2470
2471 return ret == len;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002472}
2473
Jani Nikula70aff662013-09-27 15:10:44 +03002474static bool
2475intel_dp_reset_link_train(struct intel_dp *intel_dp, uint32_t *DP,
2476 uint8_t dp_train_pat)
2477{
Jani Nikula953d22e2013-10-04 15:08:47 +03002478 memset(intel_dp->train_set, 0, sizeof(intel_dp->train_set));
Jani Nikula70aff662013-09-27 15:10:44 +03002479 intel_dp_set_signal_levels(intel_dp, DP);
2480 return intel_dp_set_link_train(intel_dp, DP, dp_train_pat);
2481}
2482
2483static bool
2484intel_dp_update_link_train(struct intel_dp *intel_dp, uint32_t *DP,
Jani Nikula0301b3a2013-10-15 09:36:08 +03002485 const uint8_t link_status[DP_LINK_STATUS_SIZE])
Jani Nikula70aff662013-09-27 15:10:44 +03002486{
2487 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2488 struct drm_device *dev = intel_dig_port->base.base.dev;
2489 struct drm_i915_private *dev_priv = dev->dev_private;
2490 int ret;
2491
2492 intel_get_adjust_train(intel_dp, link_status);
2493 intel_dp_set_signal_levels(intel_dp, DP);
2494
2495 I915_WRITE(intel_dp->output_reg, *DP);
2496 POSTING_READ(intel_dp->output_reg);
2497
2498 ret = intel_dp_aux_native_write(intel_dp, DP_TRAINING_LANE0_SET,
2499 intel_dp->train_set,
2500 intel_dp->lane_count);
2501
2502 return ret == intel_dp->lane_count;
2503}
2504
Imre Deak3ab9c632013-05-03 12:57:41 +03002505static void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
2506{
2507 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2508 struct drm_device *dev = intel_dig_port->base.base.dev;
2509 struct drm_i915_private *dev_priv = dev->dev_private;
2510 enum port port = intel_dig_port->port;
2511 uint32_t val;
2512
2513 if (!HAS_DDI(dev))
2514 return;
2515
2516 val = I915_READ(DP_TP_CTL(port));
2517 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2518 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
2519 I915_WRITE(DP_TP_CTL(port), val);
2520
2521 /*
2522 * On PORT_A we can have only eDP in SST mode. There the only reason
2523 * we need to set idle transmission mode is to work around a HW issue
2524 * where we enable the pipe while not in idle link-training mode.
2525 * In this case there is requirement to wait for a minimum number of
2526 * idle patterns to be sent.
2527 */
2528 if (port == PORT_A)
2529 return;
2530
2531 if (wait_for((I915_READ(DP_TP_STATUS(port)) & DP_TP_STATUS_IDLE_DONE),
2532 1))
2533 DRM_ERROR("Timed out waiting for DP idle patterns\n");
2534}
2535
Jesse Barnes33a34e42010-09-08 12:42:02 -07002536/* Enable corresponding port and start training pattern 1 */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002537void
Jesse Barnes33a34e42010-09-08 12:42:02 -07002538intel_dp_start_link_train(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002539{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002540 struct drm_encoder *encoder = &dp_to_dig_port(intel_dp)->base.base;
Paulo Zanonic19b0662012-10-15 15:51:41 -03002541 struct drm_device *dev = encoder->dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002542 int i;
2543 uint8_t voltage;
Keith Packardcdb0e952011-11-01 20:00:06 -07002544 int voltage_tries, loop_tries;
Chris Wilsonea5b2132010-08-04 13:50:23 +01002545 uint32_t DP = intel_dp->DP;
Jani Nikula6aba5b62013-10-04 15:08:10 +03002546 uint8_t link_config[2];
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002547
Paulo Zanoniaffa9352012-11-23 15:30:39 -02002548 if (HAS_DDI(dev))
Paulo Zanonic19b0662012-10-15 15:51:41 -03002549 intel_ddi_prepare_link_retrain(encoder);
2550
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002551 /* Write the link configuration data */
Jani Nikula6aba5b62013-10-04 15:08:10 +03002552 link_config[0] = intel_dp->link_bw;
2553 link_config[1] = intel_dp->lane_count;
2554 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
2555 link_config[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
2556 intel_dp_aux_native_write(intel_dp, DP_LINK_BW_SET, link_config, 2);
2557
2558 link_config[0] = 0;
2559 link_config[1] = DP_SET_ANSI_8B10B;
2560 intel_dp_aux_native_write(intel_dp, DP_DOWNSPREAD_CTRL, link_config, 2);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002561
2562 DP |= DP_PORT_EN;
Keith Packard1a2eb462011-11-16 16:26:07 -08002563
Jani Nikula70aff662013-09-27 15:10:44 +03002564 /* clock recovery */
2565 if (!intel_dp_reset_link_train(intel_dp, &DP,
2566 DP_TRAINING_PATTERN_1 |
2567 DP_LINK_SCRAMBLING_DISABLE)) {
2568 DRM_ERROR("failed to enable link training\n");
2569 return;
2570 }
2571
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002572 voltage = 0xff;
Keith Packardcdb0e952011-11-01 20:00:06 -07002573 voltage_tries = 0;
2574 loop_tries = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002575 for (;;) {
Jani Nikula70aff662013-09-27 15:10:44 +03002576 uint8_t link_status[DP_LINK_STATUS_SIZE];
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002577
Daniel Vettera7c96552012-10-18 10:15:30 +02002578 drm_dp_link_train_clock_recovery_delay(intel_dp->dpcd);
Keith Packard93f62da2011-11-01 19:45:03 -07002579 if (!intel_dp_get_link_status(intel_dp, link_status)) {
2580 DRM_ERROR("failed to get link status\n");
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002581 break;
Keith Packard93f62da2011-11-01 19:45:03 -07002582 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002583
Daniel Vetter01916272012-10-18 10:15:25 +02002584 if (drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
Keith Packard93f62da2011-11-01 19:45:03 -07002585 DRM_DEBUG_KMS("clock recovery OK\n");
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002586 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002587 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002588
2589 /* Check to see if we've tried the max voltage */
2590 for (i = 0; i < intel_dp->lane_count; i++)
2591 if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
2592 break;
Takashi Iwai3b4f8192013-03-11 18:40:16 +01002593 if (i == intel_dp->lane_count) {
Daniel Vetterb06fbda2012-10-16 09:50:25 +02002594 ++loop_tries;
2595 if (loop_tries == 5) {
Jani Nikula3def84b2013-10-05 16:13:56 +03002596 DRM_ERROR("too many full retries, give up\n");
Keith Packardcdb0e952011-11-01 20:00:06 -07002597 break;
2598 }
Jani Nikula70aff662013-09-27 15:10:44 +03002599 intel_dp_reset_link_train(intel_dp, &DP,
2600 DP_TRAINING_PATTERN_1 |
2601 DP_LINK_SCRAMBLING_DISABLE);
Keith Packardcdb0e952011-11-01 20:00:06 -07002602 voltage_tries = 0;
2603 continue;
2604 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002605
2606 /* Check to see if we've tried the same voltage 5 times */
Daniel Vetterb06fbda2012-10-16 09:50:25 +02002607 if ((intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) == voltage) {
Chris Wilson24773672012-09-26 16:48:30 +01002608 ++voltage_tries;
Daniel Vetterb06fbda2012-10-16 09:50:25 +02002609 if (voltage_tries == 5) {
Jani Nikula3def84b2013-10-05 16:13:56 +03002610 DRM_ERROR("too many voltage retries, give up\n");
Daniel Vetterb06fbda2012-10-16 09:50:25 +02002611 break;
2612 }
2613 } else
2614 voltage_tries = 0;
2615 voltage = intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002616
Jani Nikula70aff662013-09-27 15:10:44 +03002617 /* Update training set as requested by target */
2618 if (!intel_dp_update_link_train(intel_dp, &DP, link_status)) {
2619 DRM_ERROR("failed to update link training\n");
2620 break;
2621 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002622 }
2623
Jesse Barnes33a34e42010-09-08 12:42:02 -07002624 intel_dp->DP = DP;
2625}
2626
Paulo Zanonic19b0662012-10-15 15:51:41 -03002627void
Jesse Barnes33a34e42010-09-08 12:42:02 -07002628intel_dp_complete_link_train(struct intel_dp *intel_dp)
2629{
Jesse Barnes33a34e42010-09-08 12:42:02 -07002630 bool channel_eq = false;
Jesse Barnes37f80972011-01-05 14:45:24 -08002631 int tries, cr_tries;
Jesse Barnes33a34e42010-09-08 12:42:02 -07002632 uint32_t DP = intel_dp->DP;
2633
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002634 /* channel equalization */
Jani Nikula70aff662013-09-27 15:10:44 +03002635 if (!intel_dp_set_link_train(intel_dp, &DP,
2636 DP_TRAINING_PATTERN_2 |
2637 DP_LINK_SCRAMBLING_DISABLE)) {
2638 DRM_ERROR("failed to start channel equalization\n");
2639 return;
2640 }
2641
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002642 tries = 0;
Jesse Barnes37f80972011-01-05 14:45:24 -08002643 cr_tries = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002644 channel_eq = false;
2645 for (;;) {
Jani Nikula70aff662013-09-27 15:10:44 +03002646 uint8_t link_status[DP_LINK_STATUS_SIZE];
Zhenyu Wange3421a12010-04-08 09:43:27 +08002647
Jesse Barnes37f80972011-01-05 14:45:24 -08002648 if (cr_tries > 5) {
2649 DRM_ERROR("failed to train DP, aborting\n");
2650 intel_dp_link_down(intel_dp);
2651 break;
2652 }
2653
Daniel Vettera7c96552012-10-18 10:15:30 +02002654 drm_dp_link_train_channel_eq_delay(intel_dp->dpcd);
Jani Nikula70aff662013-09-27 15:10:44 +03002655 if (!intel_dp_get_link_status(intel_dp, link_status)) {
2656 DRM_ERROR("failed to get link status\n");
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002657 break;
Jani Nikula70aff662013-09-27 15:10:44 +03002658 }
Jesse Barnes869184a2010-10-07 16:01:22 -07002659
Jesse Barnes37f80972011-01-05 14:45:24 -08002660 /* Make sure clock is still ok */
Daniel Vetter01916272012-10-18 10:15:25 +02002661 if (!drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
Jesse Barnes37f80972011-01-05 14:45:24 -08002662 intel_dp_start_link_train(intel_dp);
Jani Nikula70aff662013-09-27 15:10:44 +03002663 intel_dp_set_link_train(intel_dp, &DP,
2664 DP_TRAINING_PATTERN_2 |
2665 DP_LINK_SCRAMBLING_DISABLE);
Jesse Barnes37f80972011-01-05 14:45:24 -08002666 cr_tries++;
2667 continue;
2668 }
2669
Daniel Vetter1ffdff12012-10-18 10:15:24 +02002670 if (drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002671 channel_eq = true;
2672 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002673 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002674
Jesse Barnes37f80972011-01-05 14:45:24 -08002675 /* Try 5 times, then try clock recovery if that fails */
2676 if (tries > 5) {
2677 intel_dp_link_down(intel_dp);
2678 intel_dp_start_link_train(intel_dp);
Jani Nikula70aff662013-09-27 15:10:44 +03002679 intel_dp_set_link_train(intel_dp, &DP,
2680 DP_TRAINING_PATTERN_2 |
2681 DP_LINK_SCRAMBLING_DISABLE);
Jesse Barnes37f80972011-01-05 14:45:24 -08002682 tries = 0;
2683 cr_tries++;
2684 continue;
2685 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002686
Jani Nikula70aff662013-09-27 15:10:44 +03002687 /* Update training set as requested by target */
2688 if (!intel_dp_update_link_train(intel_dp, &DP, link_status)) {
2689 DRM_ERROR("failed to update link training\n");
2690 break;
2691 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002692 ++tries;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002693 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002694
Imre Deak3ab9c632013-05-03 12:57:41 +03002695 intel_dp_set_idle_link_train(intel_dp);
2696
2697 intel_dp->DP = DP;
2698
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002699 if (channel_eq)
Masanari Iida07f42252013-03-20 11:00:34 +09002700 DRM_DEBUG_KMS("Channel EQ done. DP Training successful\n");
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002701
Imre Deak3ab9c632013-05-03 12:57:41 +03002702}
2703
2704void intel_dp_stop_link_train(struct intel_dp *intel_dp)
2705{
Jani Nikula70aff662013-09-27 15:10:44 +03002706 intel_dp_set_link_train(intel_dp, &intel_dp->DP,
Imre Deak3ab9c632013-05-03 12:57:41 +03002707 DP_TRAINING_PATTERN_DISABLE);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002708}
2709
2710static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01002711intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002712{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002713 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002714 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002715 struct drm_device *dev = intel_dig_port->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002716 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterab527ef2012-11-29 15:59:33 +01002717 struct intel_crtc *intel_crtc =
2718 to_intel_crtc(intel_dig_port->base.base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002719 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002720
Paulo Zanonic19b0662012-10-15 15:51:41 -03002721 /*
2722 * DDI code has a strict mode set sequence and we should try to respect
2723 * it, otherwise we might hang the machine in many different ways. So we
2724 * really should be disabling the port only on a complete crtc_disable
2725 * sequence. This function is just called under two conditions on DDI
2726 * code:
2727 * - Link train failed while doing crtc_enable, and on this case we
2728 * really should respect the mode set sequence and wait for a
2729 * crtc_disable.
2730 * - Someone turned the monitor off and intel_dp_check_link_status
2731 * called us. We don't need to disable the whole port on this case, so
2732 * when someone turns the monitor on again,
2733 * intel_ddi_prepare_link_retrain will take care of redoing the link
2734 * train.
2735 */
Paulo Zanoniaffa9352012-11-23 15:30:39 -02002736 if (HAS_DDI(dev))
Paulo Zanonic19b0662012-10-15 15:51:41 -03002737 return;
2738
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002739 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00002740 return;
2741
Zhao Yakui28c97732009-10-09 11:39:41 +08002742 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002743
Imre Deakbc7d38a2013-05-16 14:40:36 +03002744 if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08002745 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Chris Wilsonea5b2132010-08-04 13:50:23 +01002746 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT);
Zhenyu Wange3421a12010-04-08 09:43:27 +08002747 } else {
2748 DP &= ~DP_LINK_TRAIN_MASK;
Chris Wilsonea5b2132010-08-04 13:50:23 +01002749 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE);
Zhenyu Wange3421a12010-04-08 09:43:27 +08002750 }
Chris Wilsonfe255d02010-09-11 21:37:48 +01002751 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002752
Daniel Vetterab527ef2012-11-29 15:59:33 +01002753 /* We don't really know why we're doing this */
2754 intel_wait_for_vblank(dev, intel_crtc->pipe);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002755
Daniel Vetter493a7082012-05-30 12:31:56 +02002756 if (HAS_PCH_IBX(dev) &&
Chris Wilson1b39d6f2010-12-06 11:20:45 +00002757 I915_READ(intel_dp->output_reg) & DP_PIPEB_SELECT) {
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002758 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
Chris Wilson31acbcc2011-04-17 06:38:35 +01002759
Eric Anholt5bddd172010-11-18 09:32:59 +08002760 /* Hardware workaround: leaving our transcoder select
2761 * set to transcoder B while it's off will prevent the
2762 * corresponding HDMI output on transcoder A.
2763 *
2764 * Combine this with another hardware workaround:
2765 * transcoder select bit can only be cleared while the
2766 * port is enabled.
2767 */
2768 DP &= ~DP_PIPEB_SELECT;
2769 I915_WRITE(intel_dp->output_reg, DP);
2770
2771 /* Changes to enable or select take place the vblank
2772 * after being written.
2773 */
Daniel Vetterff50afe2012-11-29 15:59:34 +01002774 if (WARN_ON(crtc == NULL)) {
2775 /* We should never try to disable a port without a crtc
2776 * attached. For paranoia keep the code around for a
2777 * bit. */
Chris Wilson31acbcc2011-04-17 06:38:35 +01002778 POSTING_READ(intel_dp->output_reg);
2779 msleep(50);
2780 } else
Daniel Vetterab527ef2012-11-29 15:59:33 +01002781 intel_wait_for_vblank(dev, intel_crtc->pipe);
Eric Anholt5bddd172010-11-18 09:32:59 +08002782 }
2783
Wu Fengguang832afda2011-12-09 20:42:21 +08002784 DP &= ~DP_AUDIO_OUTPUT_ENABLE;
Chris Wilsonea5b2132010-08-04 13:50:23 +01002785 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
2786 POSTING_READ(intel_dp->output_reg);
Keith Packardf01eca22011-09-28 16:48:10 -07002787 msleep(intel_dp->panel_power_down_delay);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002788}
2789
Keith Packard26d61aa2011-07-25 20:01:09 -07002790static bool
2791intel_dp_get_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07002792{
Rodrigo Vivia031d702013-10-03 16:15:06 -03002793 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2794 struct drm_device *dev = dig_port->base.base.dev;
2795 struct drm_i915_private *dev_priv = dev->dev_private;
2796
Damien Lespiau577c7a52012-12-13 16:09:02 +00002797 char dpcd_hex_dump[sizeof(intel_dp->dpcd) * 3];
2798
Keith Packard92fd8fd2011-07-25 19:50:10 -07002799 if (intel_dp_aux_native_read_retry(intel_dp, 0x000, intel_dp->dpcd,
Adam Jacksonedb39242012-09-18 10:58:49 -04002800 sizeof(intel_dp->dpcd)) == 0)
2801 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07002802
Damien Lespiau577c7a52012-12-13 16:09:02 +00002803 hex_dump_to_buffer(intel_dp->dpcd, sizeof(intel_dp->dpcd),
2804 32, 1, dpcd_hex_dump, sizeof(dpcd_hex_dump), false);
2805 DRM_DEBUG_KMS("DPCD: %s\n", dpcd_hex_dump);
2806
Adam Jacksonedb39242012-09-18 10:58:49 -04002807 if (intel_dp->dpcd[DP_DPCD_REV] == 0)
2808 return false; /* DPCD not present */
2809
Shobhit Kumar2293bb52013-07-11 18:44:56 -03002810 /* Check if the panel supports PSR */
2811 memset(intel_dp->psr_dpcd, 0, sizeof(intel_dp->psr_dpcd));
Jani Nikula50003932013-09-20 16:42:17 +03002812 if (is_edp(intel_dp)) {
2813 intel_dp_aux_native_read_retry(intel_dp, DP_PSR_SUPPORT,
2814 intel_dp->psr_dpcd,
2815 sizeof(intel_dp->psr_dpcd));
Rodrigo Vivia031d702013-10-03 16:15:06 -03002816 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
2817 dev_priv->psr.sink_support = true;
Jani Nikula50003932013-09-20 16:42:17 +03002818 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
Rodrigo Vivia031d702013-10-03 16:15:06 -03002819 }
Jani Nikula50003932013-09-20 16:42:17 +03002820 }
2821
Adam Jacksonedb39242012-09-18 10:58:49 -04002822 if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
2823 DP_DWN_STRM_PORT_PRESENT))
2824 return true; /* native DP sink */
2825
2826 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
2827 return true; /* no per-port downstream info */
2828
2829 if (intel_dp_aux_native_read_retry(intel_dp, DP_DOWNSTREAM_PORT_0,
2830 intel_dp->downstream_ports,
2831 DP_MAX_DOWNSTREAM_PORTS) == 0)
2832 return false; /* downstream port status fetch failed */
2833
2834 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07002835}
2836
Adam Jackson0d198322012-05-14 16:05:47 -04002837static void
2838intel_dp_probe_oui(struct intel_dp *intel_dp)
2839{
2840 u8 buf[3];
2841
2842 if (!(intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] & DP_OUI_SUPPORT))
2843 return;
2844
Daniel Vetter351cfc32012-06-12 13:20:47 +02002845 ironlake_edp_panel_vdd_on(intel_dp);
2846
Adam Jackson0d198322012-05-14 16:05:47 -04002847 if (intel_dp_aux_native_read_retry(intel_dp, DP_SINK_OUI, buf, 3))
2848 DRM_DEBUG_KMS("Sink OUI: %02hx%02hx%02hx\n",
2849 buf[0], buf[1], buf[2]);
2850
2851 if (intel_dp_aux_native_read_retry(intel_dp, DP_BRANCH_OUI, buf, 3))
2852 DRM_DEBUG_KMS("Branch OUI: %02hx%02hx%02hx\n",
2853 buf[0], buf[1], buf[2]);
Daniel Vetter351cfc32012-06-12 13:20:47 +02002854
2855 ironlake_edp_panel_vdd_off(intel_dp, false);
Adam Jackson0d198322012-05-14 16:05:47 -04002856}
2857
Jesse Barnesa60f0e32011-10-20 15:09:17 -07002858static bool
2859intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
2860{
2861 int ret;
2862
2863 ret = intel_dp_aux_native_read_retry(intel_dp,
2864 DP_DEVICE_SERVICE_IRQ_VECTOR,
2865 sink_irq_vector, 1);
2866 if (!ret)
2867 return false;
2868
2869 return true;
2870}
2871
2872static void
2873intel_dp_handle_test_request(struct intel_dp *intel_dp)
2874{
2875 /* NAK by default */
Daniel Vetter9324cf72012-10-20 21:13:05 +02002876 intel_dp_aux_native_write_1(intel_dp, DP_TEST_RESPONSE, DP_TEST_NAK);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07002877}
2878
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002879/*
2880 * According to DP spec
2881 * 5.1.2:
2882 * 1. Read DPCD
2883 * 2. Configure link according to Receiver Capabilities
2884 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
2885 * 4. Check link status on receipt of hot-plug interrupt
2886 */
2887
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002888void
Chris Wilsonea5b2132010-08-04 13:50:23 +01002889intel_dp_check_link_status(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002890{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002891 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07002892 u8 sink_irq_vector;
Keith Packard93f62da2011-11-01 19:45:03 -07002893 u8 link_status[DP_LINK_STATUS_SIZE];
Jesse Barnesa60f0e32011-10-20 15:09:17 -07002894
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002895 if (!intel_encoder->connectors_active)
Keith Packardd2b996a2011-07-25 22:37:51 -07002896 return;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07002897
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002898 if (WARN_ON(!intel_encoder->base.crtc))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002899 return;
2900
Keith Packard92fd8fd2011-07-25 19:50:10 -07002901 /* Try to read receiver status if the link appears to be up */
Keith Packard93f62da2011-11-01 19:45:03 -07002902 if (!intel_dp_get_link_status(intel_dp, link_status)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01002903 intel_dp_link_down(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002904 return;
2905 }
2906
Keith Packard92fd8fd2011-07-25 19:50:10 -07002907 /* Now read the DPCD to see if it's actually running */
Keith Packard26d61aa2011-07-25 20:01:09 -07002908 if (!intel_dp_get_dpcd(intel_dp)) {
Jesse Barnes59cd09e2011-07-07 11:10:59 -07002909 intel_dp_link_down(intel_dp);
2910 return;
2911 }
2912
Jesse Barnesa60f0e32011-10-20 15:09:17 -07002913 /* Try to read the source of the interrupt */
2914 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
2915 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector)) {
2916 /* Clear interrupt source */
2917 intel_dp_aux_native_write_1(intel_dp,
2918 DP_DEVICE_SERVICE_IRQ_VECTOR,
2919 sink_irq_vector);
2920
2921 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
2922 intel_dp_handle_test_request(intel_dp);
2923 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
2924 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
2925 }
2926
Daniel Vetter1ffdff12012-10-18 10:15:24 +02002927 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Keith Packard92fd8fd2011-07-25 19:50:10 -07002928 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002929 drm_get_encoder_name(&intel_encoder->base));
Jesse Barnes33a34e42010-09-08 12:42:02 -07002930 intel_dp_start_link_train(intel_dp);
2931 intel_dp_complete_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002932 intel_dp_stop_link_train(intel_dp);
Jesse Barnes33a34e42010-09-08 12:42:02 -07002933 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002934}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002935
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04002936/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002937static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07002938intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04002939{
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04002940 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04002941 uint8_t type;
2942
2943 if (!intel_dp_get_dpcd(intel_dp))
2944 return connector_status_disconnected;
2945
2946 /* if there's no downstream port, we're done */
2947 if (!(dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT))
Keith Packard26d61aa2011-07-25 20:01:09 -07002948 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04002949
2950 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03002951 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
2952 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Adam Jackson23235172012-09-20 16:42:45 -04002953 uint8_t reg;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04002954 if (!intel_dp_aux_native_read_retry(intel_dp, DP_SINK_COUNT,
Adam Jackson23235172012-09-20 16:42:45 -04002955 &reg, 1))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04002956 return connector_status_unknown;
Adam Jackson23235172012-09-20 16:42:45 -04002957 return DP_GET_SINK_COUNT(reg) ? connector_status_connected
2958 : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04002959 }
2960
2961 /* If no HPD, poke DDC gently */
2962 if (drm_probe_ddc(&intel_dp->adapter))
2963 return connector_status_connected;
2964
2965 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03002966 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
2967 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
2968 if (type == DP_DS_PORT_TYPE_VGA ||
2969 type == DP_DS_PORT_TYPE_NON_EDID)
2970 return connector_status_unknown;
2971 } else {
2972 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
2973 DP_DWN_STRM_PORT_TYPE_MASK;
2974 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
2975 type == DP_DWN_STRM_PORT_TYPE_OTHER)
2976 return connector_status_unknown;
2977 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04002978
2979 /* Anything else is out of spec, warn and ignore */
2980 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07002981 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04002982}
2983
2984static enum drm_connector_status
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002985ironlake_dp_detect(struct intel_dp *intel_dp)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002986{
Paulo Zanoni30add222012-10-26 19:05:45 -02002987 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Damien Lespiau1b469632012-12-13 16:09:01 +00002988 struct drm_i915_private *dev_priv = dev->dev_private;
2989 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002990 enum drm_connector_status status;
2991
Chris Wilsonfe16d942011-02-12 10:29:38 +00002992 /* Can't disconnect eDP, but you can close the lid... */
2993 if (is_edp(intel_dp)) {
Paulo Zanoni30add222012-10-26 19:05:45 -02002994 status = intel_panel_detect(dev);
Chris Wilsonfe16d942011-02-12 10:29:38 +00002995 if (status == connector_status_unknown)
2996 status = connector_status_connected;
2997 return status;
2998 }
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002999
Damien Lespiau1b469632012-12-13 16:09:01 +00003000 if (!ibx_digital_port_connected(dev_priv, intel_dig_port))
3001 return connector_status_disconnected;
3002
Keith Packard26d61aa2011-07-25 20:01:09 -07003003 return intel_dp_detect_dpcd(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003004}
3005
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003006static enum drm_connector_status
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08003007g4x_dp_detect(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003008{
Paulo Zanoni30add222012-10-26 19:05:45 -02003009 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003010 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä34f2be42013-01-24 15:29:27 +02003011 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilson10f76a32012-05-11 18:01:32 +01003012 uint32_t bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003013
Jesse Barnes35aad752013-03-01 13:14:31 -08003014 /* Can't disconnect eDP, but you can close the lid... */
3015 if (is_edp(intel_dp)) {
3016 enum drm_connector_status status;
3017
3018 status = intel_panel_detect(dev);
3019 if (status == connector_status_unknown)
3020 status = connector_status_connected;
3021 return status;
3022 }
3023
Ville Syrjälä34f2be42013-01-24 15:29:27 +02003024 switch (intel_dig_port->port) {
3025 case PORT_B:
Daniel Vetter26739f12013-02-07 12:42:32 +01003026 bit = PORTB_HOTPLUG_LIVE_STATUS;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003027 break;
Ville Syrjälä34f2be42013-01-24 15:29:27 +02003028 case PORT_C:
Daniel Vetter26739f12013-02-07 12:42:32 +01003029 bit = PORTC_HOTPLUG_LIVE_STATUS;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003030 break;
Ville Syrjälä34f2be42013-01-24 15:29:27 +02003031 case PORT_D:
Daniel Vetter26739f12013-02-07 12:42:32 +01003032 bit = PORTD_HOTPLUG_LIVE_STATUS;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003033 break;
3034 default:
3035 return connector_status_unknown;
3036 }
3037
Chris Wilson10f76a32012-05-11 18:01:32 +01003038 if ((I915_READ(PORT_HOTPLUG_STAT) & bit) == 0)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003039 return connector_status_disconnected;
3040
Keith Packard26d61aa2011-07-25 20:01:09 -07003041 return intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08003042}
3043
Keith Packard8c241fe2011-09-28 16:38:44 -07003044static struct edid *
3045intel_dp_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
3046{
Jani Nikula9cd300e2012-10-19 14:51:52 +03003047 struct intel_connector *intel_connector = to_intel_connector(connector);
Keith Packard8c241fe2011-09-28 16:38:44 -07003048
Jani Nikula9cd300e2012-10-19 14:51:52 +03003049 /* use cached edid if we have one */
3050 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03003051 /* invalid edid */
3052 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04003053 return NULL;
3054
Jani Nikula55e9ede2013-10-01 10:38:54 +03003055 return drm_edid_duplicate(intel_connector->edid);
Jesse Barnesd6f24d02012-06-14 15:28:33 -04003056 }
3057
Jani Nikula9cd300e2012-10-19 14:51:52 +03003058 return drm_get_edid(connector, adapter);
Keith Packard8c241fe2011-09-28 16:38:44 -07003059}
3060
3061static int
3062intel_dp_get_edid_modes(struct drm_connector *connector, struct i2c_adapter *adapter)
3063{
Jani Nikula9cd300e2012-10-19 14:51:52 +03003064 struct intel_connector *intel_connector = to_intel_connector(connector);
Keith Packard8c241fe2011-09-28 16:38:44 -07003065
Jani Nikula9cd300e2012-10-19 14:51:52 +03003066 /* use cached edid if we have one */
3067 if (intel_connector->edid) {
3068 /* invalid edid */
3069 if (IS_ERR(intel_connector->edid))
3070 return 0;
3071
3072 return intel_connector_update_modes(connector,
3073 intel_connector->edid);
Jesse Barnesd6f24d02012-06-14 15:28:33 -04003074 }
3075
Jani Nikula9cd300e2012-10-19 14:51:52 +03003076 return intel_ddc_get_modes(connector, adapter);
Keith Packard8c241fe2011-09-28 16:38:44 -07003077}
3078
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08003079static enum drm_connector_status
3080intel_dp_detect(struct drm_connector *connector, bool force)
3081{
3082 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02003083 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3084 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02003085 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08003086 enum drm_connector_status status;
3087 struct edid *edid = NULL;
3088
Chris Wilson164c8592013-07-20 20:27:08 +01003089 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
3090 connector->base.id, drm_get_connector_name(connector));
3091
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08003092 intel_dp->has_audio = false;
3093
3094 if (HAS_PCH_SPLIT(dev))
3095 status = ironlake_dp_detect(intel_dp);
3096 else
3097 status = g4x_dp_detect(intel_dp);
Adam Jackson1b9be9d2011-07-12 17:38:01 -04003098
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08003099 if (status != connector_status_connected)
3100 return status;
3101
Adam Jackson0d198322012-05-14 16:05:47 -04003102 intel_dp_probe_oui(intel_dp);
3103
Daniel Vetterc3e5f672012-02-23 17:14:47 +01003104 if (intel_dp->force_audio != HDMI_AUDIO_AUTO) {
3105 intel_dp->has_audio = (intel_dp->force_audio == HDMI_AUDIO_ON);
Chris Wilsonf6849602010-09-19 09:29:33 +01003106 } else {
Keith Packard8c241fe2011-09-28 16:38:44 -07003107 edid = intel_dp_get_edid(connector, &intel_dp->adapter);
Chris Wilsonf6849602010-09-19 09:29:33 +01003108 if (edid) {
3109 intel_dp->has_audio = drm_detect_monitor_audio(edid);
Chris Wilsonf6849602010-09-19 09:29:33 +01003110 kfree(edid);
3111 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08003112 }
3113
Paulo Zanonid63885d2012-10-26 19:05:49 -02003114 if (intel_encoder->type != INTEL_OUTPUT_EDP)
3115 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08003116 return connector_status_connected;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003117}
3118
3119static int intel_dp_get_modes(struct drm_connector *connector)
3120{
Chris Wilsondf0e9242010-09-09 16:20:55 +01003121 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +03003122 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonifa90ece2012-10-26 19:05:44 -02003123 struct drm_device *dev = connector->dev;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003124 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003125
3126 /* We should parse the EDID data and find out if it has an audio sink
3127 */
3128
Keith Packard8c241fe2011-09-28 16:38:44 -07003129 ret = intel_dp_get_edid_modes(connector, &intel_dp->adapter);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03003130 if (ret)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003131 return ret;
3132
Jani Nikulaf8779fd2012-10-19 14:51:48 +03003133 /* if eDP has no EDID, fall back to fixed mode */
Jani Nikuladd06f902012-10-19 14:51:50 +03003134 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03003135 struct drm_display_mode *mode;
Jani Nikuladd06f902012-10-19 14:51:50 +03003136 mode = drm_mode_duplicate(dev,
3137 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03003138 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003139 drm_mode_probed_add(connector, mode);
3140 return 1;
3141 }
3142 }
3143 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003144}
3145
Chris Wilson1aad7ac2011-02-09 18:46:58 +00003146static bool
3147intel_dp_detect_audio(struct drm_connector *connector)
3148{
3149 struct intel_dp *intel_dp = intel_attached_dp(connector);
3150 struct edid *edid;
3151 bool has_audio = false;
3152
Keith Packard8c241fe2011-09-28 16:38:44 -07003153 edid = intel_dp_get_edid(connector, &intel_dp->adapter);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00003154 if (edid) {
3155 has_audio = drm_detect_monitor_audio(edid);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00003156 kfree(edid);
3157 }
3158
3159 return has_audio;
3160}
3161
Chris Wilsonf6849602010-09-19 09:29:33 +01003162static int
3163intel_dp_set_property(struct drm_connector *connector,
3164 struct drm_property *property,
3165 uint64_t val)
3166{
Chris Wilsone953fd72011-02-21 22:23:52 +00003167 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Yuly Novikov53b41832012-10-26 12:04:00 +03003168 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003169 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
3170 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01003171 int ret;
3172
Rob Clark662595d2012-10-11 20:36:04 -05003173 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01003174 if (ret)
3175 return ret;
3176
Chris Wilson3f43c482011-05-12 22:17:24 +01003177 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00003178 int i = val;
3179 bool has_audio;
3180
3181 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01003182 return 0;
3183
Chris Wilson1aad7ac2011-02-09 18:46:58 +00003184 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01003185
Daniel Vetterc3e5f672012-02-23 17:14:47 +01003186 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00003187 has_audio = intel_dp_detect_audio(connector);
3188 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01003189 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00003190
3191 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01003192 return 0;
3193
Chris Wilson1aad7ac2011-02-09 18:46:58 +00003194 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01003195 goto done;
3196 }
3197
Chris Wilsone953fd72011-02-21 22:23:52 +00003198 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02003199 bool old_auto = intel_dp->color_range_auto;
3200 uint32_t old_range = intel_dp->color_range;
3201
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02003202 switch (val) {
3203 case INTEL_BROADCAST_RGB_AUTO:
3204 intel_dp->color_range_auto = true;
3205 break;
3206 case INTEL_BROADCAST_RGB_FULL:
3207 intel_dp->color_range_auto = false;
3208 intel_dp->color_range = 0;
3209 break;
3210 case INTEL_BROADCAST_RGB_LIMITED:
3211 intel_dp->color_range_auto = false;
3212 intel_dp->color_range = DP_COLOR_RANGE_16_235;
3213 break;
3214 default:
3215 return -EINVAL;
3216 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02003217
3218 if (old_auto == intel_dp->color_range_auto &&
3219 old_range == intel_dp->color_range)
3220 return 0;
3221
Chris Wilsone953fd72011-02-21 22:23:52 +00003222 goto done;
3223 }
3224
Yuly Novikov53b41832012-10-26 12:04:00 +03003225 if (is_edp(intel_dp) &&
3226 property == connector->dev->mode_config.scaling_mode_property) {
3227 if (val == DRM_MODE_SCALE_NONE) {
3228 DRM_DEBUG_KMS("no scaling not supported\n");
3229 return -EINVAL;
3230 }
3231
3232 if (intel_connector->panel.fitting_mode == val) {
3233 /* the eDP scaling property is not changed */
3234 return 0;
3235 }
3236 intel_connector->panel.fitting_mode = val;
3237
3238 goto done;
3239 }
3240
Chris Wilsonf6849602010-09-19 09:29:33 +01003241 return -EINVAL;
3242
3243done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00003244 if (intel_encoder->base.crtc)
3245 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01003246
3247 return 0;
3248}
3249
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003250static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03003251intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003252{
Jani Nikula1d508702012-10-19 14:51:49 +03003253 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02003254
Jani Nikula9cd300e2012-10-19 14:51:52 +03003255 if (!IS_ERR_OR_NULL(intel_connector->edid))
3256 kfree(intel_connector->edid);
3257
Paulo Zanoniacd8db102013-06-12 17:27:23 -03003258 /* Can't call is_edp() since the encoder may have been destroyed
3259 * already. */
3260 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03003261 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02003262
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003263 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08003264 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003265}
3266
Paulo Zanoni00c09d72012-10-26 19:05:52 -02003267void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02003268{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003269 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
3270 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetterbd173812013-03-25 11:24:10 +01003271 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Daniel Vetter24d05922010-08-20 18:08:28 +02003272
3273 i2c_del_adapter(&intel_dp->adapter);
3274 drm_encoder_cleanup(encoder);
Keith Packardbd943152011-09-18 23:09:52 -07003275 if (is_edp(intel_dp)) {
3276 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Daniel Vetterbd173812013-03-25 11:24:10 +01003277 mutex_lock(&dev->mode_config.mutex);
Keith Packardbd943152011-09-18 23:09:52 -07003278 ironlake_panel_vdd_off_sync(intel_dp);
Daniel Vetterbd173812013-03-25 11:24:10 +01003279 mutex_unlock(&dev->mode_config.mutex);
Keith Packardbd943152011-09-18 23:09:52 -07003280 }
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003281 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02003282}
3283
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003284static const struct drm_connector_funcs intel_dp_connector_funcs = {
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02003285 .dpms = intel_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003286 .detect = intel_dp_detect,
3287 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01003288 .set_property = intel_dp_set_property,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03003289 .destroy = intel_dp_connector_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003290};
3291
3292static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
3293 .get_modes = intel_dp_get_modes,
3294 .mode_valid = intel_dp_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +01003295 .best_encoder = intel_best_encoder,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003296};
3297
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003298static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Daniel Vetter24d05922010-08-20 18:08:28 +02003299 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003300};
3301
Chris Wilson995b67622010-08-20 13:23:26 +01003302static void
Eric Anholt21d40d32010-03-25 11:11:14 -07003303intel_dp_hot_plug(struct intel_encoder *intel_encoder)
Keith Packardc8110e52009-05-06 11:51:10 -07003304{
Paulo Zanonifa90ece2012-10-26 19:05:44 -02003305 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Keith Packardc8110e52009-05-06 11:51:10 -07003306
Jesse Barnes885a5012011-07-07 11:11:01 -07003307 intel_dp_check_link_status(intel_dp);
Keith Packardc8110e52009-05-06 11:51:10 -07003308}
3309
Zhenyu Wange3421a12010-04-08 09:43:27 +08003310/* Return which DP Port should be selected for Transcoder DP control */
3311int
Akshay Joshi0206e352011-08-16 15:34:10 -04003312intel_trans_dp_port_sel(struct drm_crtc *crtc)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003313{
3314 struct drm_device *dev = crtc->dev;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02003315 struct intel_encoder *intel_encoder;
3316 struct intel_dp *intel_dp;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003317
Paulo Zanonifa90ece2012-10-26 19:05:44 -02003318 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
3319 intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003320
Paulo Zanonifa90ece2012-10-26 19:05:44 -02003321 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
3322 intel_encoder->type == INTEL_OUTPUT_EDP)
Chris Wilsonea5b2132010-08-04 13:50:23 +01003323 return intel_dp->output_reg;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003324 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01003325
Zhenyu Wange3421a12010-04-08 09:43:27 +08003326 return -1;
3327}
3328
Zhao Yakui36e83a12010-06-12 14:32:21 +08003329/* check the VBT to see whether the eDP is on DP-D port */
Adam Jacksoncb0953d2010-07-16 14:46:29 -04003330bool intel_dpd_is_edp(struct drm_device *dev)
Zhao Yakui36e83a12010-06-12 14:32:21 +08003331{
3332 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni768f69c2013-09-11 18:02:47 -03003333 union child_device_config *p_child;
Zhao Yakui36e83a12010-06-12 14:32:21 +08003334 int i;
3335
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03003336 if (!dev_priv->vbt.child_dev_num)
Zhao Yakui36e83a12010-06-12 14:32:21 +08003337 return false;
3338
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03003339 for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
3340 p_child = dev_priv->vbt.child_dev + i;
Zhao Yakui36e83a12010-06-12 14:32:21 +08003341
Paulo Zanoni768f69c2013-09-11 18:02:47 -03003342 if (p_child->common.dvo_port == PORT_IDPD &&
3343 p_child->common.device_type == DEVICE_TYPE_eDP)
Zhao Yakui36e83a12010-06-12 14:32:21 +08003344 return true;
3345 }
3346 return false;
3347}
3348
Chris Wilsonf6849602010-09-19 09:29:33 +01003349static void
3350intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
3351{
Yuly Novikov53b41832012-10-26 12:04:00 +03003352 struct intel_connector *intel_connector = to_intel_connector(connector);
3353
Chris Wilson3f43c482011-05-12 22:17:24 +01003354 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00003355 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02003356 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03003357
3358 if (is_edp(intel_dp)) {
3359 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05003360 drm_object_attach_property(
3361 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03003362 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03003363 DRM_MODE_SCALE_ASPECT);
3364 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03003365 }
Chris Wilsonf6849602010-09-19 09:29:33 +01003366}
3367
Daniel Vetter67a54562012-10-20 20:57:45 +02003368static void
3369intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Jani Nikulaf30d26e2013-01-16 10:53:40 +02003370 struct intel_dp *intel_dp,
3371 struct edp_power_seq *out)
Daniel Vetter67a54562012-10-20 20:57:45 +02003372{
3373 struct drm_i915_private *dev_priv = dev->dev_private;
3374 struct edp_power_seq cur, vbt, spec, final;
3375 u32 pp_on, pp_off, pp_div, pp;
Jani Nikulabf13e812013-09-06 07:40:05 +03003376 int pp_ctrl_reg, pp_on_reg, pp_off_reg, pp_div_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07003377
3378 if (HAS_PCH_SPLIT(dev)) {
Jani Nikulabf13e812013-09-06 07:40:05 +03003379 pp_ctrl_reg = PCH_PP_CONTROL;
Jesse Barnes453c5422013-03-28 09:55:41 -07003380 pp_on_reg = PCH_PP_ON_DELAYS;
3381 pp_off_reg = PCH_PP_OFF_DELAYS;
3382 pp_div_reg = PCH_PP_DIVISOR;
3383 } else {
Jani Nikulabf13e812013-09-06 07:40:05 +03003384 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
3385
3386 pp_ctrl_reg = VLV_PIPE_PP_CONTROL(pipe);
3387 pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe);
3388 pp_off_reg = VLV_PIPE_PP_OFF_DELAYS(pipe);
3389 pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe);
Jesse Barnes453c5422013-03-28 09:55:41 -07003390 }
Daniel Vetter67a54562012-10-20 20:57:45 +02003391
3392 /* Workaround: Need to write PP_CONTROL with the unlock key as
3393 * the very first thing. */
Jesse Barnes453c5422013-03-28 09:55:41 -07003394 pp = ironlake_get_pp_control(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +03003395 I915_WRITE(pp_ctrl_reg, pp);
Daniel Vetter67a54562012-10-20 20:57:45 +02003396
Jesse Barnes453c5422013-03-28 09:55:41 -07003397 pp_on = I915_READ(pp_on_reg);
3398 pp_off = I915_READ(pp_off_reg);
3399 pp_div = I915_READ(pp_div_reg);
Daniel Vetter67a54562012-10-20 20:57:45 +02003400
3401 /* Pull timing values out of registers */
3402 cur.t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
3403 PANEL_POWER_UP_DELAY_SHIFT;
3404
3405 cur.t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
3406 PANEL_LIGHT_ON_DELAY_SHIFT;
3407
3408 cur.t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
3409 PANEL_LIGHT_OFF_DELAY_SHIFT;
3410
3411 cur.t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
3412 PANEL_POWER_DOWN_DELAY_SHIFT;
3413
3414 cur.t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
3415 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
3416
3417 DRM_DEBUG_KMS("cur t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
3418 cur.t1_t3, cur.t8, cur.t9, cur.t10, cur.t11_t12);
3419
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03003420 vbt = dev_priv->vbt.edp_pps;
Daniel Vetter67a54562012-10-20 20:57:45 +02003421
3422 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
3423 * our hw here, which are all in 100usec. */
3424 spec.t1_t3 = 210 * 10;
3425 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
3426 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
3427 spec.t10 = 500 * 10;
3428 /* This one is special and actually in units of 100ms, but zero
3429 * based in the hw (so we need to add 100 ms). But the sw vbt
3430 * table multiplies it with 1000 to make it in units of 100usec,
3431 * too. */
3432 spec.t11_t12 = (510 + 100) * 10;
3433
3434 DRM_DEBUG_KMS("vbt t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
3435 vbt.t1_t3, vbt.t8, vbt.t9, vbt.t10, vbt.t11_t12);
3436
3437 /* Use the max of the register settings and vbt. If both are
3438 * unset, fall back to the spec limits. */
3439#define assign_final(field) final.field = (max(cur.field, vbt.field) == 0 ? \
3440 spec.field : \
3441 max(cur.field, vbt.field))
3442 assign_final(t1_t3);
3443 assign_final(t8);
3444 assign_final(t9);
3445 assign_final(t10);
3446 assign_final(t11_t12);
3447#undef assign_final
3448
3449#define get_delay(field) (DIV_ROUND_UP(final.field, 10))
3450 intel_dp->panel_power_up_delay = get_delay(t1_t3);
3451 intel_dp->backlight_on_delay = get_delay(t8);
3452 intel_dp->backlight_off_delay = get_delay(t9);
3453 intel_dp->panel_power_down_delay = get_delay(t10);
3454 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
3455#undef get_delay
3456
Jani Nikulaf30d26e2013-01-16 10:53:40 +02003457 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
3458 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
3459 intel_dp->panel_power_cycle_delay);
3460
3461 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
3462 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
3463
3464 if (out)
3465 *out = final;
3466}
3467
3468static void
3469intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
3470 struct intel_dp *intel_dp,
3471 struct edp_power_seq *seq)
3472{
3473 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes453c5422013-03-28 09:55:41 -07003474 u32 pp_on, pp_off, pp_div, port_sel = 0;
3475 int div = HAS_PCH_SPLIT(dev) ? intel_pch_rawclk(dev) : intel_hrawclk(dev);
3476 int pp_on_reg, pp_off_reg, pp_div_reg;
3477
3478 if (HAS_PCH_SPLIT(dev)) {
3479 pp_on_reg = PCH_PP_ON_DELAYS;
3480 pp_off_reg = PCH_PP_OFF_DELAYS;
3481 pp_div_reg = PCH_PP_DIVISOR;
3482 } else {
Jani Nikulabf13e812013-09-06 07:40:05 +03003483 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
3484
3485 pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe);
3486 pp_off_reg = VLV_PIPE_PP_OFF_DELAYS(pipe);
3487 pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe);
Jesse Barnes453c5422013-03-28 09:55:41 -07003488 }
3489
Daniel Vetter67a54562012-10-20 20:57:45 +02003490 /* And finally store the new values in the power sequencer. */
Jani Nikulaf30d26e2013-01-16 10:53:40 +02003491 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
3492 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
3493 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
3494 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02003495 /* Compute the divisor for the pp clock, simply match the Bspec
3496 * formula. */
Jesse Barnes453c5422013-03-28 09:55:41 -07003497 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02003498 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
Daniel Vetter67a54562012-10-20 20:57:45 +02003499 << PANEL_POWER_CYCLE_DELAY_SHIFT);
3500
3501 /* Haswell doesn't have any port selection bits for the panel
3502 * power sequencer any more. */
Imre Deakbc7d38a2013-05-16 14:40:36 +03003503 if (IS_VALLEYVIEW(dev)) {
Jani Nikulabf13e812013-09-06 07:40:05 +03003504 if (dp_to_dig_port(intel_dp)->port == PORT_B)
3505 port_sel = PANEL_PORT_SELECT_DPB_VLV;
3506 else
3507 port_sel = PANEL_PORT_SELECT_DPC_VLV;
Imre Deakbc7d38a2013-05-16 14:40:36 +03003508 } else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) {
3509 if (dp_to_dig_port(intel_dp)->port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03003510 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02003511 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03003512 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02003513 }
3514
Jesse Barnes453c5422013-03-28 09:55:41 -07003515 pp_on |= port_sel;
3516
3517 I915_WRITE(pp_on_reg, pp_on);
3518 I915_WRITE(pp_off_reg, pp_off);
3519 I915_WRITE(pp_div_reg, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02003520
Daniel Vetter67a54562012-10-20 20:57:45 +02003521 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 -07003522 I915_READ(pp_on_reg),
3523 I915_READ(pp_off_reg),
3524 I915_READ(pp_div_reg));
Keith Packardc8110e52009-05-06 11:51:10 -07003525}
3526
Paulo Zanonied92f0b2013-06-12 17:27:24 -03003527static bool intel_edp_init_connector(struct intel_dp *intel_dp,
3528 struct intel_connector *intel_connector)
3529{
3530 struct drm_connector *connector = &intel_connector->base;
3531 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3532 struct drm_device *dev = intel_dig_port->base.base.dev;
3533 struct drm_i915_private *dev_priv = dev->dev_private;
3534 struct drm_display_mode *fixed_mode = NULL;
3535 struct edp_power_seq power_seq = { 0 };
3536 bool has_dpcd;
3537 struct drm_display_mode *scan;
3538 struct edid *edid;
3539
3540 if (!is_edp(intel_dp))
3541 return true;
3542
3543 intel_dp_init_panel_power_sequencer(dev, intel_dp, &power_seq);
3544
3545 /* Cache DPCD and EDID for edp. */
3546 ironlake_edp_panel_vdd_on(intel_dp);
3547 has_dpcd = intel_dp_get_dpcd(intel_dp);
3548 ironlake_edp_panel_vdd_off(intel_dp, false);
3549
3550 if (has_dpcd) {
3551 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3552 dev_priv->no_aux_handshake =
3553 intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3554 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3555 } else {
3556 /* if this fails, presume the device is a ghost */
3557 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Paulo Zanonied92f0b2013-06-12 17:27:24 -03003558 return false;
3559 }
3560
3561 /* We now know it's not a ghost, init power sequence regs. */
3562 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp,
3563 &power_seq);
3564
Paulo Zanonied92f0b2013-06-12 17:27:24 -03003565 edid = drm_get_edid(connector, &intel_dp->adapter);
3566 if (edid) {
3567 if (drm_add_edid_modes(connector, edid)) {
3568 drm_mode_connector_update_edid_property(connector,
3569 edid);
3570 drm_edid_to_eld(connector, edid);
3571 } else {
3572 kfree(edid);
3573 edid = ERR_PTR(-EINVAL);
3574 }
3575 } else {
3576 edid = ERR_PTR(-ENOENT);
3577 }
3578 intel_connector->edid = edid;
3579
3580 /* prefer fixed mode from EDID if available */
3581 list_for_each_entry(scan, &connector->probed_modes, head) {
3582 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
3583 fixed_mode = drm_mode_duplicate(dev, scan);
3584 break;
3585 }
3586 }
3587
3588 /* fallback to VBT if available for eDP */
3589 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
3590 fixed_mode = drm_mode_duplicate(dev,
3591 dev_priv->vbt.lfp_lvds_vbt_mode);
3592 if (fixed_mode)
3593 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
3594 }
3595
Paulo Zanonied92f0b2013-06-12 17:27:24 -03003596 intel_panel_init(&intel_connector->panel, fixed_mode);
3597 intel_panel_setup_backlight(connector);
3598
3599 return true;
3600}
3601
Paulo Zanoni16c25532013-06-12 17:27:25 -03003602bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003603intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
3604 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003605{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003606 struct drm_connector *connector = &intel_connector->base;
3607 struct intel_dp *intel_dp = &intel_dig_port->dp;
3608 struct intel_encoder *intel_encoder = &intel_dig_port->base;
3609 struct drm_device *dev = intel_encoder->base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003610 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -02003611 enum port port = intel_dig_port->port;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003612 const char *name = NULL;
Paulo Zanonib2a14752013-06-12 17:27:28 -03003613 int type, error;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003614
Daniel Vetter07679352012-09-06 22:15:42 +02003615 /* Preserve the current hw state. */
3616 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03003617 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00003618
Imre Deakf7d24902013-05-08 13:14:05 +03003619 type = DRM_MODE_CONNECTOR_DisplayPort;
Gajanan Bhat19c03922012-09-27 19:13:07 +05303620 /*
3621 * FIXME : We need to initialize built-in panels before external panels.
3622 * For X0, DP_C is fixed as eDP. Revisit this as part of VLV eDP cleanup
3623 */
Imre Deakf7d24902013-05-08 13:14:05 +03003624 switch (port) {
3625 case PORT_A:
Gajanan Bhat19c03922012-09-27 19:13:07 +05303626 type = DRM_MODE_CONNECTOR_eDP;
Imre Deakf7d24902013-05-08 13:14:05 +03003627 break;
3628 case PORT_C:
3629 if (IS_VALLEYVIEW(dev))
3630 type = DRM_MODE_CONNECTOR_eDP;
3631 break;
3632 case PORT_D:
3633 if (HAS_PCH_SPLIT(dev) && intel_dpd_is_edp(dev))
3634 type = DRM_MODE_CONNECTOR_eDP;
3635 break;
3636 default: /* silence GCC warning */
3637 break;
Adam Jacksonb3295302010-07-16 14:46:28 -04003638 }
3639
Imre Deakf7d24902013-05-08 13:14:05 +03003640 /*
3641 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
3642 * for DP the encoder type can be set by the caller to
3643 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
3644 */
3645 if (type == DRM_MODE_CONNECTOR_eDP)
3646 intel_encoder->type = INTEL_OUTPUT_EDP;
3647
Imre Deake7281ea2013-05-08 13:14:08 +03003648 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
3649 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
3650 port_name(port));
3651
Adam Jacksonb3295302010-07-16 14:46:28 -04003652 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003653 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
3654
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003655 connector->interlace_allowed = true;
3656 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08003657
Daniel Vetter66a92782012-07-12 20:08:18 +02003658 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
3659 ironlake_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08003660
Chris Wilsondf0e9242010-09-09 16:20:55 +01003661 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003662 drm_sysfs_connector_add(connector);
3663
Paulo Zanoniaffa9352012-11-23 15:30:39 -02003664 if (HAS_DDI(dev))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02003665 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
3666 else
3667 intel_connector->get_hw_state = intel_connector_get_hw_state;
3668
Paulo Zanoni9ed35ab2013-02-18 19:00:25 -03003669 intel_dp->aux_ch_ctl_reg = intel_dp->output_reg + 0x10;
3670 if (HAS_DDI(dev)) {
3671 switch (intel_dig_port->port) {
3672 case PORT_A:
3673 intel_dp->aux_ch_ctl_reg = DPA_AUX_CH_CTL;
3674 break;
3675 case PORT_B:
3676 intel_dp->aux_ch_ctl_reg = PCH_DPB_AUX_CH_CTL;
3677 break;
3678 case PORT_C:
3679 intel_dp->aux_ch_ctl_reg = PCH_DPC_AUX_CH_CTL;
3680 break;
3681 case PORT_D:
3682 intel_dp->aux_ch_ctl_reg = PCH_DPD_AUX_CH_CTL;
3683 break;
3684 default:
3685 BUG();
3686 }
3687 }
Daniel Vettere8cb4552012-07-01 13:05:48 +02003688
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003689 /* Set up the DDC bus. */
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03003690 switch (port) {
3691 case PORT_A:
Egbert Eich1d843f92013-02-25 12:06:49 -05003692 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03003693 name = "DPDDC-A";
3694 break;
3695 case PORT_B:
Egbert Eich1d843f92013-02-25 12:06:49 -05003696 intel_encoder->hpd_pin = HPD_PORT_B;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03003697 name = "DPDDC-B";
3698 break;
3699 case PORT_C:
Egbert Eich1d843f92013-02-25 12:06:49 -05003700 intel_encoder->hpd_pin = HPD_PORT_C;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03003701 name = "DPDDC-C";
3702 break;
3703 case PORT_D:
Egbert Eich1d843f92013-02-25 12:06:49 -05003704 intel_encoder->hpd_pin = HPD_PORT_D;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03003705 name = "DPDDC-D";
3706 break;
3707 default:
Damien Lespiauad1c0b12013-03-07 15:30:28 +00003708 BUG();
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003709 }
3710
Paulo Zanonib2a14752013-06-12 17:27:28 -03003711 error = intel_dp_i2c_init(intel_dp, intel_connector, name);
3712 WARN(error, "intel_dp_i2c_init failed with error %d for port %c\n",
3713 error, port_name(port));
Dave Airliec1f05262012-08-30 11:06:18 +10003714
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03003715 intel_dp->psr_setup_done = false;
3716
Paulo Zanonib2f246a2013-06-12 17:27:26 -03003717 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Paulo Zanoni15b1d172013-06-12 17:27:27 -03003718 i2c_del_adapter(&intel_dp->adapter);
3719 if (is_edp(intel_dp)) {
3720 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
3721 mutex_lock(&dev->mode_config.mutex);
3722 ironlake_panel_vdd_off_sync(intel_dp);
3723 mutex_unlock(&dev->mode_config.mutex);
3724 }
Paulo Zanonib2f246a2013-06-12 17:27:26 -03003725 drm_sysfs_connector_remove(connector);
3726 drm_connector_cleanup(connector);
Paulo Zanoni16c25532013-06-12 17:27:25 -03003727 return false;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03003728 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003729
Chris Wilsonf6849602010-09-19 09:29:33 +01003730 intel_dp_add_properties(intel_dp, connector);
3731
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003732 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
3733 * 0xd. Failure to do so will result in spurious interrupts being
3734 * generated on the port when a cable is not attached.
3735 */
3736 if (IS_G4X(dev) && !IS_GM45(dev)) {
3737 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
3738 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
3739 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03003740
3741 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003742}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003743
3744void
3745intel_dp_init(struct drm_device *dev, int output_reg, enum port port)
3746{
3747 struct intel_digital_port *intel_dig_port;
3748 struct intel_encoder *intel_encoder;
3749 struct drm_encoder *encoder;
3750 struct intel_connector *intel_connector;
3751
Daniel Vetterb14c5672013-09-19 12:18:32 +02003752 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003753 if (!intel_dig_port)
3754 return;
3755
Daniel Vetterb14c5672013-09-19 12:18:32 +02003756 intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003757 if (!intel_connector) {
3758 kfree(intel_dig_port);
3759 return;
3760 }
3761
3762 intel_encoder = &intel_dig_port->base;
3763 encoder = &intel_encoder->base;
3764
3765 drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
3766 DRM_MODE_ENCODER_TMDS);
3767
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01003768 intel_encoder->compute_config = intel_dp_compute_config;
Daniel Vetterb934223d2013-07-21 21:37:05 +02003769 intel_encoder->mode_set = intel_dp_mode_set;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02003770 intel_encoder->disable = intel_disable_dp;
3771 intel_encoder->post_disable = intel_post_disable_dp;
3772 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07003773 intel_encoder->get_config = intel_dp_get_config;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03003774 if (IS_VALLEYVIEW(dev)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03003775 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03003776 intel_encoder->pre_enable = vlv_pre_enable_dp;
3777 intel_encoder->enable = vlv_enable_dp;
3778 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03003779 intel_encoder->pre_enable = g4x_pre_enable_dp;
3780 intel_encoder->enable = g4x_enable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03003781 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003782
Paulo Zanoni174edf12012-10-26 19:05:50 -02003783 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003784 intel_dig_port->dp.output_reg = output_reg;
3785
Paulo Zanoni00c09d72012-10-26 19:05:52 -02003786 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003787 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
3788 intel_encoder->cloneable = false;
3789 intel_encoder->hot_plug = intel_dp_hot_plug;
3790
Paulo Zanoni15b1d172013-06-12 17:27:27 -03003791 if (!intel_dp_init_connector(intel_dig_port, intel_connector)) {
3792 drm_encoder_cleanup(encoder);
3793 kfree(intel_dig_port);
Paulo Zanonib2f246a2013-06-12 17:27:26 -03003794 kfree(intel_connector);
Paulo Zanoni15b1d172013-06-12 17:27:27 -03003795 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003796}