blob: c192dbb8a36c8030916801901df5d05188b85308 [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,
62 { .p1 = 3, .p2 = 2, .n = 5, .m1 = 5, .m2 = 3 } },
63 { 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
Keith Packardebf33b12011-09-29 15:53:27 -0700240static bool ironlake_edp_have_panel_power(struct intel_dp *intel_dp)
241{
Paulo Zanoni30add222012-10-26 19:05:45 -0200242 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packardebf33b12011-09-29 15:53:27 -0700243 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes453c5422013-03-28 09:55:41 -0700244 u32 pp_stat_reg;
Keith Packardebf33b12011-09-29 15:53:27 -0700245
Jesse Barnes453c5422013-03-28 09:55:41 -0700246 pp_stat_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_STATUS : PCH_PP_STATUS;
247 return (I915_READ(pp_stat_reg) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700248}
249
250static bool ironlake_edp_have_panel_vdd(struct intel_dp *intel_dp)
251{
Paulo Zanoni30add222012-10-26 19:05:45 -0200252 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packardebf33b12011-09-29 15:53:27 -0700253 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes453c5422013-03-28 09:55:41 -0700254 u32 pp_ctrl_reg;
Keith Packardebf33b12011-09-29 15:53:27 -0700255
Jesse Barnes453c5422013-03-28 09:55:41 -0700256 pp_ctrl_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_CONTROL : PCH_PP_CONTROL;
257 return (I915_READ(pp_ctrl_reg) & EDP_FORCE_VDD) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700258}
259
Keith Packard9b984da2011-09-19 13:54:47 -0700260static void
261intel_dp_check_edp(struct intel_dp *intel_dp)
262{
Paulo Zanoni30add222012-10-26 19:05:45 -0200263 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packard9b984da2011-09-19 13:54:47 -0700264 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes453c5422013-03-28 09:55:41 -0700265 u32 pp_stat_reg, pp_ctrl_reg;
Keith Packardebf33b12011-09-29 15:53:27 -0700266
Keith Packard9b984da2011-09-19 13:54:47 -0700267 if (!is_edp(intel_dp))
268 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700269
270 pp_stat_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_STATUS : PCH_PP_STATUS;
271 pp_ctrl_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_CONTROL : PCH_PP_CONTROL;
272
Keith Packardebf33b12011-09-29 15:53:27 -0700273 if (!ironlake_edp_have_panel_power(intel_dp) && !ironlake_edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700274 WARN(1, "eDP powered off while attempting aux channel communication.\n");
275 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -0700276 I915_READ(pp_stat_reg),
277 I915_READ(pp_ctrl_reg));
Keith Packard9b984da2011-09-19 13:54:47 -0700278 }
279}
280
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100281static uint32_t
282intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
283{
284 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
285 struct drm_device *dev = intel_dig_port->base.base.dev;
286 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni9ed35ab2013-02-18 19:00:25 -0300287 uint32_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100288 uint32_t status;
289 bool done;
290
Daniel Vetteref04f002012-12-01 21:03:59 +0100291#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100292 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300293 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300294 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100295 else
296 done = wait_for_atomic(C, 10) == 0;
297 if (!done)
298 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
299 has_aux_irq);
300#undef C
301
302 return status;
303}
304
Chris Wilsonbc866252013-07-21 16:00:03 +0100305static uint32_t get_aux_clock_divider(struct intel_dp *intel_dp,
306 int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300307{
308 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
309 struct drm_device *dev = intel_dig_port->base.base.dev;
310 struct drm_i915_private *dev_priv = dev->dev_private;
311
312 /* The clock divider is based off the hrawclk,
313 * and would like to run at 2MHz. So, take the
314 * hrawclk value and divide by 2 and use that
315 *
316 * Note that PCH attached eDP panels should use a 125MHz input
317 * clock divider.
318 */
319 if (IS_VALLEYVIEW(dev)) {
Chris Wilsonbc866252013-07-21 16:00:03 +0100320 return index ? 0 : 100;
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300321 } else if (intel_dig_port->port == PORT_A) {
Chris Wilsonbc866252013-07-21 16:00:03 +0100322 if (index)
323 return 0;
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300324 if (HAS_DDI(dev))
Chris Wilsonbc866252013-07-21 16:00:03 +0100325 return DIV_ROUND_CLOSEST(intel_ddi_get_cdclk_freq(dev_priv), 2000);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300326 else if (IS_GEN6(dev) || IS_GEN7(dev))
327 return 200; /* SNB & IVB eDP input clock at 400Mhz */
328 else
329 return 225; /* eDP input clock at 450Mhz */
330 } else if (dev_priv->pch_id == INTEL_PCH_LPT_DEVICE_ID_TYPE) {
331 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100332 switch (index) {
333 case 0: return 63;
334 case 1: return 72;
335 default: return 0;
336 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300337 } else if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonbc866252013-07-21 16:00:03 +0100338 return index ? 0 : DIV_ROUND_UP(intel_pch_rawclk(dev), 2);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300339 } else {
Chris Wilsonbc866252013-07-21 16:00:03 +0100340 return index ? 0 :intel_hrawclk(dev) / 2;
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300341 }
342}
343
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700344static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100345intel_dp_aux_ch(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700346 uint8_t *send, int send_bytes,
347 uint8_t *recv, int recv_size)
348{
Paulo Zanoni174edf12012-10-26 19:05:50 -0200349 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
350 struct drm_device *dev = intel_dig_port->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700351 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni9ed35ab2013-02-18 19:00:25 -0300352 uint32_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700353 uint32_t ch_data = ch_ctl + 4;
Chris Wilsonbc866252013-07-21 16:00:03 +0100354 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100355 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700356 uint32_t status;
Chris Wilsonbc866252013-07-21 16:00:03 +0100357 int try, precharge, clock = 0;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100358 bool has_aux_irq = INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev);
359
360 /* dp aux is extremely sensitive to irq latency, hence request the
361 * lowest possible wakeup latency and so prevent the cpu from going into
362 * deep sleep states.
363 */
364 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700365
Keith Packard9b984da2011-09-19 13:54:47 -0700366 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +0800367
Daniel Vetter6b4e0a92012-06-14 22:15:00 +0200368 if (IS_GEN6(dev))
369 precharge = 3;
370 else
371 precharge = 5;
372
Paulo Zanonic67a4702013-08-19 13:18:09 -0300373 intel_aux_display_runtime_get(dev_priv);
374
Jesse Barnes11bee432011-08-01 15:02:20 -0700375 /* Try to wait for any previous AUX channel activity */
376 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +0100377 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -0700378 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
379 break;
380 msleep(1);
381 }
382
383 if (try == 3) {
384 WARN(1, "dp_aux_ch not started status 0x%08x\n",
385 I915_READ(ch_ctl));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100386 ret = -EBUSY;
387 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100388 }
389
Chris Wilsonbc866252013-07-21 16:00:03 +0100390 while ((aux_clock_divider = get_aux_clock_divider(intel_dp, clock++))) {
391 /* Must try at least 3 times according to DP spec */
392 for (try = 0; try < 5; try++) {
393 /* Load the send data into the aux channel data registers */
394 for (i = 0; i < send_bytes; i += 4)
395 I915_WRITE(ch_data + i,
396 pack_aux(send + i, send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -0400397
Chris Wilsonbc866252013-07-21 16:00:03 +0100398 /* Send the command and wait for it to complete */
399 I915_WRITE(ch_ctl,
400 DP_AUX_CH_CTL_SEND_BUSY |
401 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
402 DP_AUX_CH_CTL_TIME_OUT_400us |
403 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
404 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
405 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT) |
406 DP_AUX_CH_CTL_DONE |
407 DP_AUX_CH_CTL_TIME_OUT_ERROR |
408 DP_AUX_CH_CTL_RECEIVE_ERROR);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100409
Chris Wilsonbc866252013-07-21 16:00:03 +0100410 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -0400411
Chris Wilsonbc866252013-07-21 16:00:03 +0100412 /* Clear done status and any errors */
413 I915_WRITE(ch_ctl,
414 status |
415 DP_AUX_CH_CTL_DONE |
416 DP_AUX_CH_CTL_TIME_OUT_ERROR |
417 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -0400418
Chris Wilsonbc866252013-07-21 16:00:03 +0100419 if (status & (DP_AUX_CH_CTL_TIME_OUT_ERROR |
420 DP_AUX_CH_CTL_RECEIVE_ERROR))
421 continue;
422 if (status & DP_AUX_CH_CTL_DONE)
423 break;
424 }
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100425 if (status & DP_AUX_CH_CTL_DONE)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700426 break;
427 }
428
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700429 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700430 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100431 ret = -EBUSY;
432 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700433 }
434
435 /* Check for timeout or receive error.
436 * Timeouts occur when the sink is not connected
437 */
Keith Packarda5b3da52009-06-11 22:30:32 -0700438 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700439 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100440 ret = -EIO;
441 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -0700442 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700443
444 /* Timeouts occur when the device isn't connected, so they're
445 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -0700446 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Zhao Yakui28c97732009-10-09 11:39:41 +0800447 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100448 ret = -ETIMEDOUT;
449 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700450 }
451
452 /* Unload any bytes sent back from the other side */
453 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
454 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700455 if (recv_bytes > recv_size)
456 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -0400457
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100458 for (i = 0; i < recv_bytes; i += 4)
459 unpack_aux(I915_READ(ch_data + i),
460 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700461
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100462 ret = recv_bytes;
463out:
464 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
Paulo Zanonic67a4702013-08-19 13:18:09 -0300465 intel_aux_display_runtime_put(dev_priv);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100466
467 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700468}
469
470/* Write data to the aux channel in native mode */
471static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100472intel_dp_aux_native_write(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700473 uint16_t address, uint8_t *send, int send_bytes)
474{
475 int ret;
476 uint8_t msg[20];
477 int msg_bytes;
478 uint8_t ack;
479
Keith Packard9b984da2011-09-19 13:54:47 -0700480 intel_dp_check_edp(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700481 if (send_bytes > 16)
482 return -1;
483 msg[0] = AUX_NATIVE_WRITE << 4;
484 msg[1] = address >> 8;
Zhenyu Wangeebc8632009-07-24 01:00:30 +0800485 msg[2] = address & 0xff;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700486 msg[3] = send_bytes - 1;
487 memcpy(&msg[4], send, send_bytes);
488 msg_bytes = send_bytes + 4;
489 for (;;) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100490 ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes, &ack, 1);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700491 if (ret < 0)
492 return ret;
493 if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK)
494 break;
495 else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
496 udelay(100);
497 else
Keith Packarda5b3da52009-06-11 22:30:32 -0700498 return -EIO;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700499 }
500 return send_bytes;
501}
502
503/* Write a single byte to the aux channel in native mode */
504static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100505intel_dp_aux_native_write_1(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700506 uint16_t address, uint8_t byte)
507{
Chris Wilsonea5b2132010-08-04 13:50:23 +0100508 return intel_dp_aux_native_write(intel_dp, address, &byte, 1);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700509}
510
511/* read bytes from a native aux channel */
512static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100513intel_dp_aux_native_read(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700514 uint16_t address, uint8_t *recv, int recv_bytes)
515{
516 uint8_t msg[4];
517 int msg_bytes;
518 uint8_t reply[20];
519 int reply_bytes;
520 uint8_t ack;
521 int ret;
522
Keith Packard9b984da2011-09-19 13:54:47 -0700523 intel_dp_check_edp(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700524 msg[0] = AUX_NATIVE_READ << 4;
525 msg[1] = address >> 8;
526 msg[2] = address & 0xff;
527 msg[3] = recv_bytes - 1;
528
529 msg_bytes = 4;
530 reply_bytes = recv_bytes + 1;
531
532 for (;;) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100533 ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700534 reply, reply_bytes);
Keith Packarda5b3da52009-06-11 22:30:32 -0700535 if (ret == 0)
536 return -EPROTO;
537 if (ret < 0)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700538 return ret;
539 ack = reply[0];
540 if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK) {
541 memcpy(recv, reply + 1, ret - 1);
542 return ret - 1;
543 }
544 else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
545 udelay(100);
546 else
Keith Packarda5b3da52009-06-11 22:30:32 -0700547 return -EIO;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700548 }
549}
550
551static int
Dave Airlieab2c0672009-12-04 10:55:24 +1000552intel_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode,
553 uint8_t write_byte, uint8_t *read_byte)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700554{
Dave Airlieab2c0672009-12-04 10:55:24 +1000555 struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100556 struct intel_dp *intel_dp = container_of(adapter,
557 struct intel_dp,
558 adapter);
Dave Airlieab2c0672009-12-04 10:55:24 +1000559 uint16_t address = algo_data->address;
560 uint8_t msg[5];
561 uint8_t reply[2];
David Flynn8316f332010-12-08 16:10:21 +0000562 unsigned retry;
Dave Airlieab2c0672009-12-04 10:55:24 +1000563 int msg_bytes;
564 int reply_bytes;
565 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700566
Keith Packard9b984da2011-09-19 13:54:47 -0700567 intel_dp_check_edp(intel_dp);
Dave Airlieab2c0672009-12-04 10:55:24 +1000568 /* Set up the command byte */
569 if (mode & MODE_I2C_READ)
570 msg[0] = AUX_I2C_READ << 4;
571 else
572 msg[0] = AUX_I2C_WRITE << 4;
573
574 if (!(mode & MODE_I2C_STOP))
575 msg[0] |= AUX_I2C_MOT << 4;
576
577 msg[1] = address >> 8;
578 msg[2] = address;
579
580 switch (mode) {
581 case MODE_I2C_WRITE:
582 msg[3] = 0;
583 msg[4] = write_byte;
584 msg_bytes = 5;
585 reply_bytes = 1;
586 break;
587 case MODE_I2C_READ:
588 msg[3] = 0;
589 msg_bytes = 4;
590 reply_bytes = 2;
591 break;
592 default:
593 msg_bytes = 3;
594 reply_bytes = 1;
595 break;
596 }
597
David Flynn8316f332010-12-08 16:10:21 +0000598 for (retry = 0; retry < 5; retry++) {
599 ret = intel_dp_aux_ch(intel_dp,
600 msg, msg_bytes,
601 reply, reply_bytes);
Dave Airlieab2c0672009-12-04 10:55:24 +1000602 if (ret < 0) {
Dave Airlie3ff99162009-12-08 14:03:47 +1000603 DRM_DEBUG_KMS("aux_ch failed %d\n", ret);
Dave Airlieab2c0672009-12-04 10:55:24 +1000604 return ret;
605 }
David Flynn8316f332010-12-08 16:10:21 +0000606
607 switch (reply[0] & AUX_NATIVE_REPLY_MASK) {
608 case AUX_NATIVE_REPLY_ACK:
609 /* I2C-over-AUX Reply field is only valid
610 * when paired with AUX ACK.
611 */
612 break;
613 case AUX_NATIVE_REPLY_NACK:
614 DRM_DEBUG_KMS("aux_ch native nack\n");
615 return -EREMOTEIO;
616 case AUX_NATIVE_REPLY_DEFER:
617 udelay(100);
618 continue;
619 default:
620 DRM_ERROR("aux_ch invalid native reply 0x%02x\n",
621 reply[0]);
622 return -EREMOTEIO;
623 }
624
Dave Airlieab2c0672009-12-04 10:55:24 +1000625 switch (reply[0] & AUX_I2C_REPLY_MASK) {
626 case AUX_I2C_REPLY_ACK:
627 if (mode == MODE_I2C_READ) {
628 *read_byte = reply[1];
629 }
630 return reply_bytes - 1;
631 case AUX_I2C_REPLY_NACK:
David Flynn8316f332010-12-08 16:10:21 +0000632 DRM_DEBUG_KMS("aux_i2c nack\n");
Dave Airlieab2c0672009-12-04 10:55:24 +1000633 return -EREMOTEIO;
634 case AUX_I2C_REPLY_DEFER:
David Flynn8316f332010-12-08 16:10:21 +0000635 DRM_DEBUG_KMS("aux_i2c defer\n");
Dave Airlieab2c0672009-12-04 10:55:24 +1000636 udelay(100);
637 break;
638 default:
David Flynn8316f332010-12-08 16:10:21 +0000639 DRM_ERROR("aux_i2c invalid reply 0x%02x\n", reply[0]);
Dave Airlieab2c0672009-12-04 10:55:24 +1000640 return -EREMOTEIO;
641 }
642 }
David Flynn8316f332010-12-08 16:10:21 +0000643
644 DRM_ERROR("too many retries, giving up\n");
645 return -EREMOTEIO;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700646}
647
648static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100649intel_dp_i2c_init(struct intel_dp *intel_dp,
Zhenyu Wang55f78c42010-03-29 16:13:57 +0800650 struct intel_connector *intel_connector, const char *name)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700651{
Keith Packard0b5c5412011-09-28 16:41:05 -0700652 int ret;
653
Zhenyu Wangd54e9d22009-10-19 15:43:51 +0800654 DRM_DEBUG_KMS("i2c_init %s\n", name);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100655 intel_dp->algo.running = false;
656 intel_dp->algo.address = 0;
657 intel_dp->algo.aux_ch = intel_dp_i2c_aux_ch;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700658
Akshay Joshi0206e352011-08-16 15:34:10 -0400659 memset(&intel_dp->adapter, '\0', sizeof(intel_dp->adapter));
Chris Wilsonea5b2132010-08-04 13:50:23 +0100660 intel_dp->adapter.owner = THIS_MODULE;
661 intel_dp->adapter.class = I2C_CLASS_DDC;
Akshay Joshi0206e352011-08-16 15:34:10 -0400662 strncpy(intel_dp->adapter.name, name, sizeof(intel_dp->adapter.name) - 1);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100663 intel_dp->adapter.name[sizeof(intel_dp->adapter.name) - 1] = '\0';
664 intel_dp->adapter.algo_data = &intel_dp->algo;
665 intel_dp->adapter.dev.parent = &intel_connector->base.kdev;
666
Keith Packard0b5c5412011-09-28 16:41:05 -0700667 ironlake_edp_panel_vdd_on(intel_dp);
668 ret = i2c_dp_aux_add_bus(&intel_dp->adapter);
Keith Packardbd943152011-09-18 23:09:52 -0700669 ironlake_edp_panel_vdd_off(intel_dp, false);
Keith Packard0b5c5412011-09-28 16:41:05 -0700670 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700671}
672
Daniel Vetterc6bb3532013-04-19 11:14:33 +0200673static void
674intel_dp_set_clock(struct intel_encoder *encoder,
675 struct intel_crtc_config *pipe_config, int link_bw)
676{
677 struct drm_device *dev = encoder->base.dev;
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +0800678 const struct dp_link_dpll *divisor = NULL;
679 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +0200680
681 if (IS_G4X(dev)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +0800682 divisor = gen4_dpll;
683 count = ARRAY_SIZE(gen4_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +0200684 } else if (IS_HASWELL(dev)) {
685 /* Haswell has special-purpose DP DDI clocks. */
686 } else if (HAS_PCH_SPLIT(dev)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +0800687 divisor = pch_dpll;
688 count = ARRAY_SIZE(pch_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +0200689 } else if (IS_VALLEYVIEW(dev)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +0800690 divisor = vlv_dpll;
691 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +0200692 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +0800693
694 if (divisor && count) {
695 for (i = 0; i < count; i++) {
696 if (link_bw == divisor[i].link_bw) {
697 pipe_config->dpll = divisor[i].dpll;
698 pipe_config->clock_set = true;
699 break;
700 }
701 }
702 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +0200703}
704
Paulo Zanoni00c09d72012-10-26 19:05:52 -0200705bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100706intel_dp_compute_config(struct intel_encoder *encoder,
707 struct intel_crtc_config *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700708{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100709 struct drm_device *dev = encoder->base.dev;
Daniel Vetter36008362013-03-27 00:44:59 +0100710 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100711 struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100712 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +0300713 enum port port = dp_to_dig_port(intel_dp)->port;
Jesse Barnes2dd24552013-04-25 12:55:01 -0700714 struct intel_crtc *intel_crtc = encoder->new_crtc;
Jani Nikuladd06f902012-10-19 14:51:50 +0300715 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700716 int lane_count, clock;
Daniel Vetter397fe152012-10-22 22:56:43 +0200717 int max_lane_count = drm_dp_max_lane_count(intel_dp->dpcd);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100718 int max_clock = intel_dp_max_link_bw(intel_dp) == DP_LINK_BW_2_7 ? 1 : 0;
Daniel Vetter083f9562012-04-20 20:23:49 +0200719 int bpp, mode_rate;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700720 static int bws[2] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7 };
Daniel Vetterff9a6752013-06-01 17:16:21 +0200721 int link_avail, link_clock;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700722
Imre Deakbc7d38a2013-05-16 14:40:36 +0300723 if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100724 pipe_config->has_pch_encoder = true;
725
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200726 pipe_config->has_dp_encoder = true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700727
Jani Nikuladd06f902012-10-19 14:51:50 +0300728 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
729 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
730 adjusted_mode);
Jesse Barnes2dd24552013-04-25 12:55:01 -0700731 if (!HAS_PCH_SPLIT(dev))
732 intel_gmch_panel_fitting(intel_crtc, pipe_config,
733 intel_connector->panel.fitting_mode);
734 else
Jesse Barnesb074cec2013-04-25 12:55:02 -0700735 intel_pch_panel_fitting(intel_crtc, pipe_config,
736 intel_connector->panel.fitting_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +0100737 }
738
Daniel Vettercb1793c2012-06-04 18:39:21 +0200739 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +0200740 return false;
741
Daniel Vetter083f9562012-04-20 20:23:49 +0200742 DRM_DEBUG_KMS("DP link computation with max lane count %i "
743 "max bw %02x pixel clock %iKHz\n",
Daniel Vetter71244652012-06-04 18:39:20 +0200744 max_lane_count, bws[max_clock], adjusted_mode->clock);
Daniel Vetter083f9562012-04-20 20:23:49 +0200745
Daniel Vetter36008362013-03-27 00:44:59 +0100746 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
747 * bpc in between. */
Daniel Vetter3e7ca982013-06-01 19:45:56 +0200748 bpp = pipe_config->pipe_bpp;
Imre Deak79842112013-07-18 17:44:13 +0300749 if (is_edp(intel_dp) && dev_priv->vbt.edp_bpp) {
750 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
751 dev_priv->vbt.edp_bpp);
Daniel Vettere1b73cb2013-05-21 09:52:16 +0200752 bpp = min_t(int, bpp, dev_priv->vbt.edp_bpp);
Imre Deak79842112013-07-18 17:44:13 +0300753 }
Daniel Vetter657445f2013-05-04 10:09:18 +0200754
Daniel Vetter36008362013-03-27 00:44:59 +0100755 for (; bpp >= 6*3; bpp -= 2*3) {
Daniel Vetterff9a6752013-06-01 17:16:21 +0200756 mode_rate = intel_dp_link_required(adjusted_mode->clock, bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +0200757
Daniel Vetter36008362013-03-27 00:44:59 +0100758 for (clock = 0; clock <= max_clock; clock++) {
759 for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) {
760 link_clock = drm_dp_bw_code_to_link_rate(bws[clock]);
761 link_avail = intel_dp_max_data_rate(link_clock,
762 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200763
Daniel Vetter36008362013-03-27 00:44:59 +0100764 if (mode_rate <= link_avail) {
765 goto found;
766 }
767 }
768 }
769 }
770
771 return false;
772
773found:
Ville Syrjälä55bc60d2013-01-17 16:31:29 +0200774 if (intel_dp->color_range_auto) {
775 /*
776 * See:
777 * CEA-861-E - 5.1 Default Encoding Parameters
778 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
779 */
Thierry Reding18316c82012-12-20 15:41:44 +0100780 if (bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1)
Ville Syrjälä55bc60d2013-01-17 16:31:29 +0200781 intel_dp->color_range = DP_COLOR_RANGE_16_235;
782 else
783 intel_dp->color_range = 0;
784 }
785
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200786 if (intel_dp->color_range)
Daniel Vetter50f3b012013-03-27 00:44:56 +0100787 pipe_config->limited_color_range = true;
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200788
Daniel Vetter36008362013-03-27 00:44:59 +0100789 intel_dp->link_bw = bws[clock];
790 intel_dp->lane_count = lane_count;
Daniel Vetter657445f2013-05-04 10:09:18 +0200791 pipe_config->pipe_bpp = bpp;
Daniel Vetterff9a6752013-06-01 17:16:21 +0200792 pipe_config->port_clock = drm_dp_bw_code_to_link_rate(intel_dp->link_bw);
Daniel Vetterc4867932012-04-10 10:42:36 +0200793
Daniel Vetter36008362013-03-27 00:44:59 +0100794 DRM_DEBUG_KMS("DP link bw %02x lane count %d clock %d bpp %d\n",
795 intel_dp->link_bw, intel_dp->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +0200796 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +0100797 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
798 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700799
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200800 intel_link_compute_m_n(bpp, lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +0200801 adjusted_mode->clock, pipe_config->port_clock,
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200802 &pipe_config->dp_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700803
Daniel Vetterc6bb3532013-04-19 11:14:33 +0200804 intel_dp_set_clock(encoder, pipe_config, intel_dp->link_bw);
805
Daniel Vetter36008362013-03-27 00:44:59 +0100806 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700807}
808
Paulo Zanoni247d89f2012-10-15 15:51:33 -0300809void intel_dp_init_link_config(struct intel_dp *intel_dp)
810{
811 memset(intel_dp->link_configuration, 0, DP_LINK_CONFIGURATION_SIZE);
812 intel_dp->link_configuration[0] = intel_dp->link_bw;
813 intel_dp->link_configuration[1] = intel_dp->lane_count;
814 intel_dp->link_configuration[8] = DP_SET_ANSI_8B10B;
815 /*
816 * Check for DPCD version > 1.1 and enhanced framing support
817 */
818 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
819 (intel_dp->dpcd[DP_MAX_LANE_COUNT] & DP_ENHANCED_FRAME_CAP)) {
820 intel_dp->link_configuration[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
821 }
822}
823
Daniel Vetter7c62a162013-06-01 17:16:20 +0200824static void ironlake_set_pll_cpu_edp(struct intel_dp *intel_dp)
Daniel Vetterea9b6002012-11-29 15:59:31 +0100825{
Daniel Vetter7c62a162013-06-01 17:16:20 +0200826 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
827 struct intel_crtc *crtc = to_intel_crtc(dig_port->base.base.crtc);
828 struct drm_device *dev = crtc->base.dev;
Daniel Vetterea9b6002012-11-29 15:59:31 +0100829 struct drm_i915_private *dev_priv = dev->dev_private;
830 u32 dpa_ctl;
831
Daniel Vetterff9a6752013-06-01 17:16:21 +0200832 DRM_DEBUG_KMS("eDP PLL enable for clock %d\n", crtc->config.port_clock);
Daniel Vetterea9b6002012-11-29 15:59:31 +0100833 dpa_ctl = I915_READ(DP_A);
834 dpa_ctl &= ~DP_PLL_FREQ_MASK;
835
Daniel Vetterff9a6752013-06-01 17:16:21 +0200836 if (crtc->config.port_clock == 162000) {
Daniel Vetter1ce17032012-11-29 15:59:32 +0100837 /* For a long time we've carried around a ILK-DevA w/a for the
838 * 160MHz clock. If we're really unlucky, it's still required.
839 */
840 DRM_DEBUG_KMS("160MHz cpu eDP clock, might need ilk devA w/a\n");
Daniel Vetterea9b6002012-11-29 15:59:31 +0100841 dpa_ctl |= DP_PLL_FREQ_160MHZ;
Daniel Vetter7c62a162013-06-01 17:16:20 +0200842 intel_dp->DP |= DP_PLL_FREQ_160MHZ;
Daniel Vetterea9b6002012-11-29 15:59:31 +0100843 } else {
844 dpa_ctl |= DP_PLL_FREQ_270MHZ;
Daniel Vetter7c62a162013-06-01 17:16:20 +0200845 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
Daniel Vetterea9b6002012-11-29 15:59:31 +0100846 }
Daniel Vetter1ce17032012-11-29 15:59:32 +0100847
Daniel Vetterea9b6002012-11-29 15:59:31 +0100848 I915_WRITE(DP_A, dpa_ctl);
849
850 POSTING_READ(DP_A);
851 udelay(500);
852}
853
Daniel Vetterb934223d2013-07-21 21:37:05 +0200854static void intel_dp_mode_set(struct intel_encoder *encoder)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700855{
Daniel Vetterb934223d2013-07-21 21:37:05 +0200856 struct drm_device *dev = encoder->base.dev;
Keith Packard417e8222011-11-01 19:54:11 -0700857 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb934223d2013-07-21 21:37:05 +0200858 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +0300859 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +0200860 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
861 struct drm_display_mode *adjusted_mode = &crtc->config.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700862
Keith Packard417e8222011-11-01 19:54:11 -0700863 /*
Keith Packard1a2eb462011-11-16 16:26:07 -0800864 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -0700865 *
866 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -0800867 * SNB CPU
868 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -0700869 * CPT PCH
870 *
871 * IBX PCH and CPU are the same for almost everything,
872 * except that the CPU DP PLL is configured in this
873 * register
874 *
875 * CPT PCH is quite different, having many bits moved
876 * to the TRANS_DP_CTL register instead. That
877 * configuration happens (oddly) in ironlake_pch_enable
878 */
Adam Jackson9c9e7922010-04-05 17:57:59 -0400879
Keith Packard417e8222011-11-01 19:54:11 -0700880 /* Preserve the BIOS-computed detected bit. This is
881 * supposed to be read-only.
882 */
883 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700884
Keith Packard417e8222011-11-01 19:54:11 -0700885 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -0700886 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Daniel Vetter17aa6be2013-04-30 14:01:40 +0200887 intel_dp->DP |= DP_PORT_WIDTH(intel_dp->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700888
Wu Fengguange0dac652011-09-05 14:25:34 +0800889 if (intel_dp->has_audio) {
890 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Daniel Vetter7c62a162013-06-01 17:16:20 +0200891 pipe_name(crtc->pipe));
Chris Wilsonea5b2132010-08-04 13:50:23 +0100892 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Daniel Vetterb934223d2013-07-21 21:37:05 +0200893 intel_write_eld(&encoder->base, adjusted_mode);
Wu Fengguange0dac652011-09-05 14:25:34 +0800894 }
Paulo Zanoni247d89f2012-10-15 15:51:33 -0300895
896 intel_dp_init_link_config(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700897
Keith Packard417e8222011-11-01 19:54:11 -0700898 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800899
Imre Deakbc7d38a2013-05-16 14:40:36 +0300900 if (port == PORT_A && IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) {
Keith Packard1a2eb462011-11-16 16:26:07 -0800901 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
902 intel_dp->DP |= DP_SYNC_HS_HIGH;
903 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
904 intel_dp->DP |= DP_SYNC_VS_HIGH;
905 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
906
907 if (intel_dp->link_configuration[1] & DP_LANE_COUNT_ENHANCED_FRAME_EN)
908 intel_dp->DP |= DP_ENHANCED_FRAMING;
909
Daniel Vetter7c62a162013-06-01 17:16:20 +0200910 intel_dp->DP |= crtc->pipe << 29;
Imre Deakbc7d38a2013-05-16 14:40:36 +0300911 } else if (!HAS_PCH_CPT(dev) || port == PORT_A) {
Jesse Barnesb2634012013-03-28 09:55:40 -0700912 if (!HAS_PCH_SPLIT(dev) && !IS_VALLEYVIEW(dev))
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200913 intel_dp->DP |= intel_dp->color_range;
Keith Packard417e8222011-11-01 19:54:11 -0700914
915 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
916 intel_dp->DP |= DP_SYNC_HS_HIGH;
917 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
918 intel_dp->DP |= DP_SYNC_VS_HIGH;
919 intel_dp->DP |= DP_LINK_TRAIN_OFF;
920
921 if (intel_dp->link_configuration[1] & DP_LANE_COUNT_ENHANCED_FRAME_EN)
922 intel_dp->DP |= DP_ENHANCED_FRAMING;
923
Daniel Vetter7c62a162013-06-01 17:16:20 +0200924 if (crtc->pipe == 1)
Keith Packard417e8222011-11-01 19:54:11 -0700925 intel_dp->DP |= DP_PIPEB_SELECT;
Keith Packard417e8222011-11-01 19:54:11 -0700926 } else {
927 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800928 }
Daniel Vetterea9b6002012-11-29 15:59:31 +0100929
Imre Deakbc7d38a2013-05-16 14:40:36 +0300930 if (port == PORT_A && !IS_VALLEYVIEW(dev))
Daniel Vetter7c62a162013-06-01 17:16:20 +0200931 ironlake_set_pll_cpu_edp(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700932}
933
Keith Packard99ea7122011-11-01 19:57:50 -0700934#define IDLE_ON_MASK (PP_ON | 0 | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
935#define IDLE_ON_VALUE (PP_ON | 0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
936
937#define IDLE_OFF_MASK (PP_ON | 0 | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
938#define IDLE_OFF_VALUE (0 | 0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
939
940#define IDLE_CYCLE_MASK (PP_ON | 0 | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
941#define IDLE_CYCLE_VALUE (0 | 0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
942
943static void ironlake_wait_panel_status(struct intel_dp *intel_dp,
944 u32 mask,
945 u32 value)
946{
Paulo Zanoni30add222012-10-26 19:05:45 -0200947 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -0700948 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes453c5422013-03-28 09:55:41 -0700949 u32 pp_stat_reg, pp_ctrl_reg;
950
951 pp_stat_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_STATUS : PCH_PP_STATUS;
952 pp_ctrl_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_CONTROL : PCH_PP_CONTROL;
Keith Packard99ea7122011-11-01 19:57:50 -0700953
954 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -0700955 mask, value,
956 I915_READ(pp_stat_reg),
957 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -0700958
Jesse Barnes453c5422013-03-28 09:55:41 -0700959 if (_wait_for((I915_READ(pp_stat_reg) & mask) == value, 5000, 10)) {
Keith Packard99ea7122011-11-01 19:57:50 -0700960 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -0700961 I915_READ(pp_stat_reg),
962 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -0700963 }
964}
965
966static void ironlake_wait_panel_on(struct intel_dp *intel_dp)
967{
968 DRM_DEBUG_KMS("Wait for panel power on\n");
969 ironlake_wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
970}
971
Keith Packardbd943152011-09-18 23:09:52 -0700972static void ironlake_wait_panel_off(struct intel_dp *intel_dp)
973{
Keith Packardbd943152011-09-18 23:09:52 -0700974 DRM_DEBUG_KMS("Wait for panel power off time\n");
Keith Packard99ea7122011-11-01 19:57:50 -0700975 ironlake_wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -0700976}
Keith Packardbd943152011-09-18 23:09:52 -0700977
Keith Packard99ea7122011-11-01 19:57:50 -0700978static void ironlake_wait_panel_power_cycle(struct intel_dp *intel_dp)
979{
980 DRM_DEBUG_KMS("Wait for panel power cycle\n");
981 ironlake_wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
982}
Keith Packardbd943152011-09-18 23:09:52 -0700983
Keith Packard99ea7122011-11-01 19:57:50 -0700984
Keith Packard832dd3c2011-11-01 19:34:06 -0700985/* Read the current pp_control value, unlocking the register if it
986 * is locked
987 */
988
Jesse Barnes453c5422013-03-28 09:55:41 -0700989static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -0700990{
Jesse Barnes453c5422013-03-28 09:55:41 -0700991 struct drm_device *dev = intel_dp_to_dev(intel_dp);
992 struct drm_i915_private *dev_priv = dev->dev_private;
993 u32 control;
994 u32 pp_ctrl_reg;
995
996 pp_ctrl_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_CONTROL : PCH_PP_CONTROL;
997 control = I915_READ(pp_ctrl_reg);
Keith Packard832dd3c2011-11-01 19:34:06 -0700998
999 control &= ~PANEL_UNLOCK_MASK;
1000 control |= PANEL_UNLOCK_REGS;
1001 return control;
Keith Packardbd943152011-09-18 23:09:52 -07001002}
1003
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001004void ironlake_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001005{
Paulo Zanoni30add222012-10-26 19:05:45 -02001006 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001007 struct drm_i915_private *dev_priv = dev->dev_private;
1008 u32 pp;
Jesse Barnes453c5422013-03-28 09:55:41 -07001009 u32 pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08001010
Keith Packard97af61f572011-09-28 16:23:51 -07001011 if (!is_edp(intel_dp))
1012 return;
Keith Packardf01eca22011-09-28 16:48:10 -07001013 DRM_DEBUG_KMS("Turn eDP VDD on\n");
Jesse Barnes5d613502011-01-24 17:10:54 -08001014
Keith Packardbd943152011-09-18 23:09:52 -07001015 WARN(intel_dp->want_panel_vdd,
1016 "eDP VDD already requested on\n");
1017
1018 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07001019
Keith Packardbd943152011-09-18 23:09:52 -07001020 if (ironlake_edp_have_panel_vdd(intel_dp)) {
1021 DRM_DEBUG_KMS("eDP VDD already on\n");
1022 return;
1023 }
1024
Keith Packard99ea7122011-11-01 19:57:50 -07001025 if (!ironlake_edp_have_panel_power(intel_dp))
1026 ironlake_wait_panel_power_cycle(intel_dp);
1027
Jesse Barnes453c5422013-03-28 09:55:41 -07001028 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001029 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07001030
Jesse Barnes453c5422013-03-28 09:55:41 -07001031 pp_stat_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_STATUS : PCH_PP_STATUS;
1032 pp_ctrl_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_CONTROL : PCH_PP_CONTROL;
1033
1034 I915_WRITE(pp_ctrl_reg, pp);
1035 POSTING_READ(pp_ctrl_reg);
1036 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1037 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07001038 /*
1039 * If the panel wasn't on, delay before accessing aux channel
1040 */
1041 if (!ironlake_edp_have_panel_power(intel_dp)) {
Keith Packardbd943152011-09-18 23:09:52 -07001042 DRM_DEBUG_KMS("eDP was not running\n");
Keith Packardf01eca22011-09-28 16:48:10 -07001043 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07001044 }
Jesse Barnes5d613502011-01-24 17:10:54 -08001045}
1046
Keith Packardbd943152011-09-18 23:09:52 -07001047static void ironlake_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001048{
Paulo Zanoni30add222012-10-26 19:05:45 -02001049 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001050 struct drm_i915_private *dev_priv = dev->dev_private;
1051 u32 pp;
Jesse Barnes453c5422013-03-28 09:55:41 -07001052 u32 pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08001053
Daniel Vettera0e99e62012-12-02 01:05:46 +01001054 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
1055
Keith Packardbd943152011-09-18 23:09:52 -07001056 if (!intel_dp->want_panel_vdd && ironlake_edp_have_panel_vdd(intel_dp)) {
Jesse Barnes453c5422013-03-28 09:55:41 -07001057 pp = ironlake_get_pp_control(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07001058 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07001059
1060 pp_stat_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_STATUS : PCH_PP_STATUS;
1061 pp_ctrl_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_CONTROL : PCH_PP_CONTROL;
1062
1063 I915_WRITE(pp_ctrl_reg, pp);
1064 POSTING_READ(pp_ctrl_reg);
Jesse Barnes5d613502011-01-24 17:10:54 -08001065
Keith Packardbd943152011-09-18 23:09:52 -07001066 /* Make sure sequencer is idle before allowing subsequent activity */
Jesse Barnes453c5422013-03-28 09:55:41 -07001067 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1068 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001069 msleep(intel_dp->panel_power_down_delay);
Keith Packardbd943152011-09-18 23:09:52 -07001070 }
1071}
1072
1073static void ironlake_panel_vdd_work(struct work_struct *__work)
1074{
1075 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
1076 struct intel_dp, panel_vdd_work);
Paulo Zanoni30add222012-10-26 19:05:45 -02001077 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07001078
Keith Packard627f7672011-10-31 11:30:10 -07001079 mutex_lock(&dev->mode_config.mutex);
Keith Packardbd943152011-09-18 23:09:52 -07001080 ironlake_panel_vdd_off_sync(intel_dp);
Keith Packard627f7672011-10-31 11:30:10 -07001081 mutex_unlock(&dev->mode_config.mutex);
Keith Packardbd943152011-09-18 23:09:52 -07001082}
1083
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001084void ironlake_edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07001085{
Keith Packard97af61f572011-09-28 16:23:51 -07001086 if (!is_edp(intel_dp))
1087 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08001088
Keith Packardbd943152011-09-18 23:09:52 -07001089 DRM_DEBUG_KMS("Turn eDP VDD off %d\n", intel_dp->want_panel_vdd);
1090 WARN(!intel_dp->want_panel_vdd, "eDP VDD not forced on");
Keith Packardf2e8b182011-11-01 20:01:35 -07001091
Keith Packardbd943152011-09-18 23:09:52 -07001092 intel_dp->want_panel_vdd = false;
1093
1094 if (sync) {
1095 ironlake_panel_vdd_off_sync(intel_dp);
1096 } else {
1097 /*
1098 * Queue the timer to fire a long
1099 * time from now (relative to the power down delay)
1100 * to keep the panel power up across a sequence of operations
1101 */
1102 schedule_delayed_work(&intel_dp->panel_vdd_work,
1103 msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5));
1104 }
Jesse Barnes5d613502011-01-24 17:10:54 -08001105}
1106
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001107void ironlake_edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07001108{
Paulo Zanoni30add222012-10-26 19:05:45 -02001109 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07001110 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packard99ea7122011-11-01 19:57:50 -07001111 u32 pp;
Jesse Barnes453c5422013-03-28 09:55:41 -07001112 u32 pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07001113
Keith Packard97af61f572011-09-28 16:23:51 -07001114 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07001115 return;
Keith Packard99ea7122011-11-01 19:57:50 -07001116
1117 DRM_DEBUG_KMS("Turn eDP power on\n");
1118
1119 if (ironlake_edp_have_panel_power(intel_dp)) {
1120 DRM_DEBUG_KMS("eDP power already on\n");
Keith Packard7d639f32011-09-29 16:05:34 -07001121 return;
Keith Packard99ea7122011-11-01 19:57:50 -07001122 }
Jesse Barnes9934c132010-07-22 13:18:19 -07001123
Keith Packard99ea7122011-11-01 19:57:50 -07001124 ironlake_wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001125
Jesse Barnes453c5422013-03-28 09:55:41 -07001126 pp = ironlake_get_pp_control(intel_dp);
Keith Packard05ce1a42011-09-29 16:33:01 -07001127 if (IS_GEN5(dev)) {
1128 /* ILK workaround: disable reset around power sequence */
1129 pp &= ~PANEL_POWER_RESET;
1130 I915_WRITE(PCH_PP_CONTROL, pp);
1131 POSTING_READ(PCH_PP_CONTROL);
1132 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001133
Keith Packard1c0ae802011-09-19 13:59:29 -07001134 pp |= POWER_TARGET_ON;
Keith Packard99ea7122011-11-01 19:57:50 -07001135 if (!IS_GEN5(dev))
1136 pp |= PANEL_POWER_RESET;
1137
Jesse Barnes453c5422013-03-28 09:55:41 -07001138 pp_ctrl_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_CONTROL : PCH_PP_CONTROL;
1139
1140 I915_WRITE(pp_ctrl_reg, pp);
1141 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07001142
Keith Packard99ea7122011-11-01 19:57:50 -07001143 ironlake_wait_panel_on(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07001144
Keith Packard05ce1a42011-09-29 16:33:01 -07001145 if (IS_GEN5(dev)) {
1146 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
1147 I915_WRITE(PCH_PP_CONTROL, pp);
1148 POSTING_READ(PCH_PP_CONTROL);
1149 }
Jesse Barnes9934c132010-07-22 13:18:19 -07001150}
1151
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001152void ironlake_edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07001153{
Paulo Zanoni30add222012-10-26 19:05:45 -02001154 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07001155 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packard99ea7122011-11-01 19:57:50 -07001156 u32 pp;
Jesse Barnes453c5422013-03-28 09:55:41 -07001157 u32 pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07001158
Keith Packard97af61f572011-09-28 16:23:51 -07001159 if (!is_edp(intel_dp))
1160 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001161
Keith Packard99ea7122011-11-01 19:57:50 -07001162 DRM_DEBUG_KMS("Turn eDP power off\n");
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07001163
Daniel Vetter6cb49832012-05-20 17:14:50 +02001164 WARN(!intel_dp->want_panel_vdd, "Need VDD to turn off panel\n");
Jesse Barnes9934c132010-07-22 13:18:19 -07001165
Jesse Barnes453c5422013-03-28 09:55:41 -07001166 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02001167 /* We need to switch off panel power _and_ force vdd, for otherwise some
1168 * panels get very unhappy and cease to work. */
1169 pp &= ~(POWER_TARGET_ON | EDP_FORCE_VDD | PANEL_POWER_RESET | EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07001170
1171 pp_ctrl_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_CONTROL : PCH_PP_CONTROL;
1172
1173 I915_WRITE(pp_ctrl_reg, pp);
1174 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07001175
Daniel Vetter35a38552012-08-12 22:17:14 +02001176 intel_dp->want_panel_vdd = false;
1177
Keith Packard99ea7122011-11-01 19:57:50 -07001178 ironlake_wait_panel_off(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07001179}
1180
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001181void ironlake_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001182{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001183 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1184 struct drm_device *dev = intel_dig_port->base.base.dev;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001185 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001186 int pipe = to_intel_crtc(intel_dig_port->base.base.crtc)->pipe;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001187 u32 pp;
Jesse Barnes453c5422013-03-28 09:55:41 -07001188 u32 pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001189
Keith Packardf01eca22011-09-28 16:48:10 -07001190 if (!is_edp(intel_dp))
1191 return;
1192
Zhao Yakui28c97732009-10-09 11:39:41 +08001193 DRM_DEBUG_KMS("\n");
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07001194 /*
1195 * If we enable the backlight right away following a panel power
1196 * on, we may see slight flicker as the panel syncs with the eDP
1197 * link. So delay a bit to make sure the image is solid before
1198 * allowing it to appear.
1199 */
Keith Packardf01eca22011-09-28 16:48:10 -07001200 msleep(intel_dp->backlight_on_delay);
Jesse Barnes453c5422013-03-28 09:55:41 -07001201 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001202 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07001203
1204 pp_ctrl_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_CONTROL : PCH_PP_CONTROL;
1205
1206 I915_WRITE(pp_ctrl_reg, pp);
1207 POSTING_READ(pp_ctrl_reg);
Daniel Vetter035aa3d2012-10-20 20:57:42 +02001208
1209 intel_panel_enable_backlight(dev, pipe);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001210}
1211
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001212void ironlake_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001213{
Paulo Zanoni30add222012-10-26 19:05:45 -02001214 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001215 struct drm_i915_private *dev_priv = dev->dev_private;
1216 u32 pp;
Jesse Barnes453c5422013-03-28 09:55:41 -07001217 u32 pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001218
Keith Packardf01eca22011-09-28 16:48:10 -07001219 if (!is_edp(intel_dp))
1220 return;
1221
Daniel Vetter035aa3d2012-10-20 20:57:42 +02001222 intel_panel_disable_backlight(dev);
1223
Zhao Yakui28c97732009-10-09 11:39:41 +08001224 DRM_DEBUG_KMS("\n");
Jesse Barnes453c5422013-03-28 09:55:41 -07001225 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001226 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07001227
1228 pp_ctrl_reg = IS_VALLEYVIEW(dev) ? PIPEA_PP_CONTROL : PCH_PP_CONTROL;
1229
1230 I915_WRITE(pp_ctrl_reg, pp);
1231 POSTING_READ(pp_ctrl_reg);
Keith Packardf01eca22011-09-28 16:48:10 -07001232 msleep(intel_dp->backlight_off_delay);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001233}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001234
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001235static void ironlake_edp_pll_on(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07001236{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001237 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1238 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
1239 struct drm_device *dev = crtc->dev;
Jesse Barnesd240f202010-08-13 15:43:26 -07001240 struct drm_i915_private *dev_priv = dev->dev_private;
1241 u32 dpa_ctl;
1242
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001243 assert_pipe_disabled(dev_priv,
1244 to_intel_crtc(crtc)->pipe);
1245
Jesse Barnesd240f202010-08-13 15:43:26 -07001246 DRM_DEBUG_KMS("\n");
1247 dpa_ctl = I915_READ(DP_A);
Daniel Vetter07679352012-09-06 22:15:42 +02001248 WARN(dpa_ctl & DP_PLL_ENABLE, "dp pll on, should be off\n");
1249 WARN(dpa_ctl & DP_PORT_EN, "dp port still on, should be off\n");
1250
1251 /* We don't adjust intel_dp->DP while tearing down the link, to
1252 * facilitate link retraining (e.g. after hotplug). Hence clear all
1253 * enable bits here to ensure that we don't enable too much. */
1254 intel_dp->DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
1255 intel_dp->DP |= DP_PLL_ENABLE;
1256 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07001257 POSTING_READ(DP_A);
1258 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07001259}
1260
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001261static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07001262{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001263 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1264 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
1265 struct drm_device *dev = crtc->dev;
Jesse Barnesd240f202010-08-13 15:43:26 -07001266 struct drm_i915_private *dev_priv = dev->dev_private;
1267 u32 dpa_ctl;
1268
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001269 assert_pipe_disabled(dev_priv,
1270 to_intel_crtc(crtc)->pipe);
1271
Jesse Barnesd240f202010-08-13 15:43:26 -07001272 dpa_ctl = I915_READ(DP_A);
Daniel Vetter07679352012-09-06 22:15:42 +02001273 WARN((dpa_ctl & DP_PLL_ENABLE) == 0,
1274 "dp pll off, should be on\n");
1275 WARN(dpa_ctl & DP_PORT_EN, "dp port still on, should be off\n");
1276
1277 /* We can't rely on the value tracked for the DP register in
1278 * intel_dp->DP because link_down must not change that (otherwise link
1279 * re-training will fail. */
Jesse Barnes298b0b32010-10-07 16:01:24 -07001280 dpa_ctl &= ~DP_PLL_ENABLE;
Jesse Barnesd240f202010-08-13 15:43:26 -07001281 I915_WRITE(DP_A, dpa_ctl);
Chris Wilson1af5fa12010-09-08 21:07:28 +01001282 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07001283 udelay(200);
1284}
1285
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001286/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03001287void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001288{
1289 int ret, i;
1290
1291 /* Should have a valid DPCD by this point */
1292 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
1293 return;
1294
1295 if (mode != DRM_MODE_DPMS_ON) {
1296 ret = intel_dp_aux_native_write_1(intel_dp, DP_SET_POWER,
1297 DP_SET_POWER_D3);
1298 if (ret != 1)
1299 DRM_DEBUG_DRIVER("failed to write sink power state\n");
1300 } else {
1301 /*
1302 * When turning on, we need to retry for 1ms to give the sink
1303 * time to wake up.
1304 */
1305 for (i = 0; i < 3; i++) {
1306 ret = intel_dp_aux_native_write_1(intel_dp,
1307 DP_SET_POWER,
1308 DP_SET_POWER_D0);
1309 if (ret == 1)
1310 break;
1311 msleep(1);
1312 }
1313 }
1314}
1315
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001316static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
1317 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07001318{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001319 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001320 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001321 struct drm_device *dev = encoder->base.dev;
1322 struct drm_i915_private *dev_priv = dev->dev_private;
1323 u32 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07001324
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001325 if (!(tmp & DP_PORT_EN))
1326 return false;
1327
Imre Deakbc7d38a2013-05-16 14:40:36 +03001328 if (port == PORT_A && IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001329 *pipe = PORT_TO_PIPE_CPT(tmp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001330 } else if (!HAS_PCH_CPT(dev) || port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001331 *pipe = PORT_TO_PIPE(tmp);
1332 } else {
1333 u32 trans_sel;
1334 u32 trans_dp;
1335 int i;
1336
1337 switch (intel_dp->output_reg) {
1338 case PCH_DP_B:
1339 trans_sel = TRANS_DP_PORT_SEL_B;
1340 break;
1341 case PCH_DP_C:
1342 trans_sel = TRANS_DP_PORT_SEL_C;
1343 break;
1344 case PCH_DP_D:
1345 trans_sel = TRANS_DP_PORT_SEL_D;
1346 break;
1347 default:
1348 return true;
1349 }
1350
1351 for_each_pipe(i) {
1352 trans_dp = I915_READ(TRANS_DP_CTL(i));
1353 if ((trans_dp & TRANS_DP_PORT_SEL_MASK) == trans_sel) {
1354 *pipe = i;
1355 return true;
1356 }
1357 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001358
Daniel Vetter4a0833e2012-10-26 10:58:11 +02001359 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
1360 intel_dp->output_reg);
1361 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02001362
1363 return true;
1364}
1365
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001366static void intel_dp_get_config(struct intel_encoder *encoder,
1367 struct intel_crtc_config *pipe_config)
1368{
1369 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001370 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08001371 struct drm_device *dev = encoder->base.dev;
1372 struct drm_i915_private *dev_priv = dev->dev_private;
1373 enum port port = dp_to_dig_port(intel_dp)->port;
1374 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001375
Xiong Zhang63000ef2013-06-28 12:59:06 +08001376 if ((port == PORT_A) || !HAS_PCH_CPT(dev)) {
1377 tmp = I915_READ(intel_dp->output_reg);
1378 if (tmp & DP_SYNC_HS_HIGH)
1379 flags |= DRM_MODE_FLAG_PHSYNC;
1380 else
1381 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001382
Xiong Zhang63000ef2013-06-28 12:59:06 +08001383 if (tmp & DP_SYNC_VS_HIGH)
1384 flags |= DRM_MODE_FLAG_PVSYNC;
1385 else
1386 flags |= DRM_MODE_FLAG_NVSYNC;
1387 } else {
1388 tmp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1389 if (tmp & TRANS_DP_HSYNC_ACTIVE_HIGH)
1390 flags |= DRM_MODE_FLAG_PHSYNC;
1391 else
1392 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001393
Xiong Zhang63000ef2013-06-28 12:59:06 +08001394 if (tmp & TRANS_DP_VSYNC_ACTIVE_HIGH)
1395 flags |= DRM_MODE_FLAG_PVSYNC;
1396 else
1397 flags |= DRM_MODE_FLAG_NVSYNC;
1398 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001399
1400 pipe_config->adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03001401
1402 if (dp_to_dig_port(intel_dp)->port == PORT_A) {
1403 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_160MHZ)
1404 pipe_config->port_clock = 162000;
1405 else
1406 pipe_config->port_clock = 270000;
1407 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001408}
1409
Shobhit Kumar2293bb52013-07-11 18:44:56 -03001410static bool is_edp_psr(struct intel_dp *intel_dp)
1411{
1412 return is_edp(intel_dp) &&
1413 intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED;
1414}
1415
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001416static bool intel_edp_is_psr_enabled(struct drm_device *dev)
1417{
1418 struct drm_i915_private *dev_priv = dev->dev_private;
1419
1420 if (!IS_HASWELL(dev))
1421 return false;
1422
1423 return I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
1424}
1425
1426static void intel_edp_psr_write_vsc(struct intel_dp *intel_dp,
1427 struct edp_vsc_psr *vsc_psr)
1428{
1429 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1430 struct drm_device *dev = dig_port->base.base.dev;
1431 struct drm_i915_private *dev_priv = dev->dev_private;
1432 struct intel_crtc *crtc = to_intel_crtc(dig_port->base.base.crtc);
1433 u32 ctl_reg = HSW_TVIDEO_DIP_CTL(crtc->config.cpu_transcoder);
1434 u32 data_reg = HSW_TVIDEO_DIP_VSC_DATA(crtc->config.cpu_transcoder);
1435 uint32_t *data = (uint32_t *) vsc_psr;
1436 unsigned int i;
1437
1438 /* As per BSPec (Pipe Video Data Island Packet), we need to disable
1439 the video DIP being updated before program video DIP data buffer
1440 registers for DIP being updated. */
1441 I915_WRITE(ctl_reg, 0);
1442 POSTING_READ(ctl_reg);
1443
1444 for (i = 0; i < VIDEO_DIP_VSC_DATA_SIZE; i += 4) {
1445 if (i < sizeof(struct edp_vsc_psr))
1446 I915_WRITE(data_reg + i, *data++);
1447 else
1448 I915_WRITE(data_reg + i, 0);
1449 }
1450
1451 I915_WRITE(ctl_reg, VIDEO_DIP_ENABLE_VSC_HSW);
1452 POSTING_READ(ctl_reg);
1453}
1454
1455static void intel_edp_psr_setup(struct intel_dp *intel_dp)
1456{
1457 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1458 struct drm_i915_private *dev_priv = dev->dev_private;
1459 struct edp_vsc_psr psr_vsc;
1460
1461 if (intel_dp->psr_setup_done)
1462 return;
1463
1464 /* Prepare VSC packet as per EDP 1.3 spec, Table 3.10 */
1465 memset(&psr_vsc, 0, sizeof(psr_vsc));
1466 psr_vsc.sdp_header.HB0 = 0;
1467 psr_vsc.sdp_header.HB1 = 0x7;
1468 psr_vsc.sdp_header.HB2 = 0x2;
1469 psr_vsc.sdp_header.HB3 = 0x8;
1470 intel_edp_psr_write_vsc(intel_dp, &psr_vsc);
1471
1472 /* Avoid continuous PSR exit by masking memup and hpd */
1473 I915_WRITE(EDP_PSR_DEBUG_CTL, EDP_PSR_DEBUG_MASK_MEMUP |
1474 EDP_PSR_DEBUG_MASK_HPD);
1475
1476 intel_dp->psr_setup_done = true;
1477}
1478
1479static void intel_edp_psr_enable_sink(struct intel_dp *intel_dp)
1480{
1481 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1482 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonbc866252013-07-21 16:00:03 +01001483 uint32_t aux_clock_divider = get_aux_clock_divider(intel_dp, 0);
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001484 int precharge = 0x3;
1485 int msg_size = 5; /* Header(4) + Message(1) */
1486
1487 /* Enable PSR in sink */
1488 if (intel_dp->psr_dpcd[1] & DP_PSR_NO_TRAIN_ON_EXIT)
1489 intel_dp_aux_native_write_1(intel_dp, DP_PSR_EN_CFG,
1490 DP_PSR_ENABLE &
1491 ~DP_PSR_MAIN_LINK_ACTIVE);
1492 else
1493 intel_dp_aux_native_write_1(intel_dp, DP_PSR_EN_CFG,
1494 DP_PSR_ENABLE |
1495 DP_PSR_MAIN_LINK_ACTIVE);
1496
1497 /* Setup AUX registers */
1498 I915_WRITE(EDP_PSR_AUX_DATA1, EDP_PSR_DPCD_COMMAND);
1499 I915_WRITE(EDP_PSR_AUX_DATA2, EDP_PSR_DPCD_NORMAL_OPERATION);
1500 I915_WRITE(EDP_PSR_AUX_CTL,
1501 DP_AUX_CH_CTL_TIME_OUT_400us |
1502 (msg_size << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
1503 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
1504 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT));
1505}
1506
1507static void intel_edp_psr_enable_source(struct intel_dp *intel_dp)
1508{
1509 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1510 struct drm_i915_private *dev_priv = dev->dev_private;
1511 uint32_t max_sleep_time = 0x1f;
1512 uint32_t idle_frames = 1;
1513 uint32_t val = 0x0;
1514
1515 if (intel_dp->psr_dpcd[1] & DP_PSR_NO_TRAIN_ON_EXIT) {
1516 val |= EDP_PSR_LINK_STANDBY;
1517 val |= EDP_PSR_TP2_TP3_TIME_0us;
1518 val |= EDP_PSR_TP1_TIME_0us;
1519 val |= EDP_PSR_SKIP_AUX_EXIT;
1520 } else
1521 val |= EDP_PSR_LINK_DISABLE;
1522
1523 I915_WRITE(EDP_PSR_CTL, val |
1524 EDP_PSR_MIN_LINK_ENTRY_TIME_8_LINES |
1525 max_sleep_time << EDP_PSR_MAX_SLEEP_TIME_SHIFT |
1526 idle_frames << EDP_PSR_IDLE_FRAME_SHIFT |
1527 EDP_PSR_ENABLE);
1528}
1529
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001530static bool intel_edp_psr_match_conditions(struct intel_dp *intel_dp)
1531{
1532 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1533 struct drm_device *dev = dig_port->base.base.dev;
1534 struct drm_i915_private *dev_priv = dev->dev_private;
1535 struct drm_crtc *crtc = dig_port->base.base.crtc;
1536 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1537 struct drm_i915_gem_object *obj = to_intel_framebuffer(crtc->fb)->obj;
1538 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
1539
1540 if (!IS_HASWELL(dev)) {
1541 DRM_DEBUG_KMS("PSR not supported on this platform\n");
1542 dev_priv->no_psr_reason = PSR_NO_SOURCE;
1543 return false;
1544 }
1545
1546 if ((intel_encoder->type != INTEL_OUTPUT_EDP) ||
1547 (dig_port->port != PORT_A)) {
1548 DRM_DEBUG_KMS("HSW ties PSR to DDI A (eDP)\n");
1549 dev_priv->no_psr_reason = PSR_HSW_NOT_DDIA;
1550 return false;
1551 }
1552
1553 if (!is_edp_psr(intel_dp)) {
1554 DRM_DEBUG_KMS("PSR not supported by this panel\n");
1555 dev_priv->no_psr_reason = PSR_NO_SINK;
1556 return false;
1557 }
1558
Rodrigo Vivi105b7c12013-07-11 18:45:02 -03001559 if (!i915_enable_psr) {
1560 DRM_DEBUG_KMS("PSR disable by flag\n");
1561 dev_priv->no_psr_reason = PSR_MODULE_PARAM;
1562 return false;
1563 }
1564
Chris Wilsoncd234b02013-08-02 20:39:49 +01001565 crtc = dig_port->base.base.crtc;
1566 if (crtc == NULL) {
1567 DRM_DEBUG_KMS("crtc not active for PSR\n");
1568 dev_priv->no_psr_reason = PSR_CRTC_NOT_ACTIVE;
1569 return false;
1570 }
1571
1572 intel_crtc = to_intel_crtc(crtc);
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001573 if (!intel_crtc->active || !crtc->fb || !crtc->mode.clock) {
1574 DRM_DEBUG_KMS("crtc not active for PSR\n");
1575 dev_priv->no_psr_reason = PSR_CRTC_NOT_ACTIVE;
1576 return false;
1577 }
1578
Chris Wilsoncd234b02013-08-02 20:39:49 +01001579 obj = to_intel_framebuffer(crtc->fb)->obj;
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001580 if (obj->tiling_mode != I915_TILING_X ||
1581 obj->fence_reg == I915_FENCE_REG_NONE) {
1582 DRM_DEBUG_KMS("PSR condition failed: fb not tiled or fenced\n");
1583 dev_priv->no_psr_reason = PSR_NOT_TILED;
1584 return false;
1585 }
1586
1587 if (I915_READ(SPRCTL(intel_crtc->pipe)) & SPRITE_ENABLE) {
1588 DRM_DEBUG_KMS("PSR condition failed: Sprite is Enabled\n");
1589 dev_priv->no_psr_reason = PSR_SPRITE_ENABLED;
1590 return false;
1591 }
1592
1593 if (I915_READ(HSW_STEREO_3D_CTL(intel_crtc->config.cpu_transcoder)) &
1594 S3D_ENABLE) {
1595 DRM_DEBUG_KMS("PSR condition failed: Stereo 3D is Enabled\n");
1596 dev_priv->no_psr_reason = PSR_S3D_ENABLED;
1597 return false;
1598 }
1599
1600 if (crtc->mode.flags & DRM_MODE_FLAG_INTERLACE) {
1601 DRM_DEBUG_KMS("PSR condition failed: Interlaced is Enabled\n");
1602 dev_priv->no_psr_reason = PSR_INTERLACED_ENABLED;
1603 return false;
1604 }
1605
1606 return true;
1607}
1608
Rodrigo Vivi3d739d92013-07-11 18:45:01 -03001609static void intel_edp_psr_do_enable(struct intel_dp *intel_dp)
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001610{
1611 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1612
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001613 if (!intel_edp_psr_match_conditions(intel_dp) ||
1614 intel_edp_is_psr_enabled(dev))
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001615 return;
1616
1617 /* Setup PSR once */
1618 intel_edp_psr_setup(intel_dp);
1619
1620 /* Enable PSR on the panel */
1621 intel_edp_psr_enable_sink(intel_dp);
1622
1623 /* Enable PSR on the host */
1624 intel_edp_psr_enable_source(intel_dp);
1625}
1626
Rodrigo Vivi3d739d92013-07-11 18:45:01 -03001627void intel_edp_psr_enable(struct intel_dp *intel_dp)
1628{
1629 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1630
1631 if (intel_edp_psr_match_conditions(intel_dp) &&
1632 !intel_edp_is_psr_enabled(dev))
1633 intel_edp_psr_do_enable(intel_dp);
1634}
1635
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03001636void intel_edp_psr_disable(struct intel_dp *intel_dp)
1637{
1638 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1639 struct drm_i915_private *dev_priv = dev->dev_private;
1640
1641 if (!intel_edp_is_psr_enabled(dev))
1642 return;
1643
1644 I915_WRITE(EDP_PSR_CTL, I915_READ(EDP_PSR_CTL) & ~EDP_PSR_ENABLE);
1645
1646 /* Wait till PSR is idle */
1647 if (_wait_for((I915_READ(EDP_PSR_STATUS_CTL) &
1648 EDP_PSR_STATUS_STATE_MASK) == 0, 2000, 10))
1649 DRM_ERROR("Timed out waiting for PSR Idle State\n");
1650}
1651
Rodrigo Vivi3d739d92013-07-11 18:45:01 -03001652void intel_edp_psr_update(struct drm_device *dev)
1653{
1654 struct intel_encoder *encoder;
1655 struct intel_dp *intel_dp = NULL;
1656
1657 list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head)
1658 if (encoder->type == INTEL_OUTPUT_EDP) {
1659 intel_dp = enc_to_intel_dp(&encoder->base);
1660
1661 if (!is_edp_psr(intel_dp))
1662 return;
1663
1664 if (!intel_edp_psr_match_conditions(intel_dp))
1665 intel_edp_psr_disable(intel_dp);
1666 else
1667 if (!intel_edp_is_psr_enabled(dev))
1668 intel_edp_psr_do_enable(intel_dp);
1669 }
1670}
1671
Daniel Vettere8cb4552012-07-01 13:05:48 +02001672static void intel_disable_dp(struct intel_encoder *encoder)
Jesse Barnesd240f202010-08-13 15:43:26 -07001673{
Daniel Vettere8cb4552012-07-01 13:05:48 +02001674 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03001675 enum port port = dp_to_dig_port(intel_dp)->port;
1676 struct drm_device *dev = encoder->base.dev;
Daniel Vetter6cb49832012-05-20 17:14:50 +02001677
1678 /* Make sure the panel is off before trying to change the mode. But also
1679 * ensure that we have vdd while we switch off the panel. */
1680 ironlake_edp_panel_vdd_on(intel_dp);
Keith Packard21264c62011-11-01 20:25:21 -07001681 ironlake_edp_backlight_off(intel_dp);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07001682 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
Daniel Vetter35a38552012-08-12 22:17:14 +02001683 ironlake_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02001684
1685 /* cpu edp my only be disable _after_ the cpu pipe/plane is disabled. */
Imre Deak982a3862013-05-23 19:39:40 +03001686 if (!(port == PORT_A || IS_VALLEYVIEW(dev)))
Daniel Vetter37398502012-09-06 22:15:44 +02001687 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07001688}
1689
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001690static void intel_post_disable_dp(struct intel_encoder *encoder)
Jesse Barnesd240f202010-08-13 15:43:26 -07001691{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001692 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03001693 enum port port = dp_to_dig_port(intel_dp)->port;
Jesse Barnesb2634012013-03-28 09:55:40 -07001694 struct drm_device *dev = encoder->base.dev;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001695
Imre Deak982a3862013-05-23 19:39:40 +03001696 if (port == PORT_A || IS_VALLEYVIEW(dev)) {
Daniel Vetter37398502012-09-06 22:15:44 +02001697 intel_dp_link_down(intel_dp);
Jesse Barnesb2634012013-03-28 09:55:40 -07001698 if (!IS_VALLEYVIEW(dev))
1699 ironlake_edp_pll_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02001700 }
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001701}
1702
Daniel Vettere8cb4552012-07-01 13:05:48 +02001703static void intel_enable_dp(struct intel_encoder *encoder)
Jesse Barnesd240f202010-08-13 15:43:26 -07001704{
Daniel Vettere8cb4552012-07-01 13:05:48 +02001705 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1706 struct drm_device *dev = encoder->base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001707 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +01001708 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001709
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02001710 if (WARN_ON(dp_reg & DP_PORT_EN))
1711 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001712
1713 ironlake_edp_panel_vdd_on(intel_dp);
1714 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1715 intel_dp_start_link_train(intel_dp);
1716 ironlake_edp_panel_on(intel_dp);
1717 ironlake_edp_panel_vdd_off(intel_dp, true);
1718 intel_dp_complete_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03001719 intel_dp_stop_link_train(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001720 ironlake_edp_backlight_on(intel_dp);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03001721}
Jesse Barnes89b667f2013-04-18 14:51:36 -07001722
Jani Nikulaab1f90f2013-07-30 12:20:30 +03001723static void vlv_enable_dp(struct intel_encoder *encoder)
1724{
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001725}
1726
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001727static void intel_pre_enable_dp(struct intel_encoder *encoder)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001728{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02001729 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001730 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03001731
1732 if (dport->port == PORT_A)
1733 ironlake_edp_pll_on(intel_dp);
1734}
1735
1736static void vlv_pre_enable_dp(struct intel_encoder *encoder)
1737{
1738 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1739 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
Jesse Barnesb2634012013-03-28 09:55:40 -07001740 struct drm_device *dev = encoder->base.dev;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001741 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03001742 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
1743 int port = vlv_dport_to_channel(dport);
1744 int pipe = intel_crtc->pipe;
1745 u32 val;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001746
Jani Nikulaab1f90f2013-07-30 12:20:30 +03001747 mutex_lock(&dev_priv->dpio_lock);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001748
Jani Nikulaab1f90f2013-07-30 12:20:30 +03001749 val = vlv_dpio_read(dev_priv, DPIO_DATA_LANE_A(port));
1750 val = 0;
1751 if (pipe)
1752 val |= (1<<21);
1753 else
1754 val &= ~(1<<21);
1755 val |= 0x001000c4;
1756 vlv_dpio_write(dev_priv, DPIO_DATA_CHANNEL(port), val);
1757 vlv_dpio_write(dev_priv, DPIO_PCS_CLOCKBUF0(port), 0x00760018);
1758 vlv_dpio_write(dev_priv, DPIO_PCS_CLOCKBUF8(port), 0x00400888);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001759
Jani Nikulaab1f90f2013-07-30 12:20:30 +03001760 mutex_unlock(&dev_priv->dpio_lock);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001761
Jani Nikulaab1f90f2013-07-30 12:20:30 +03001762 intel_enable_dp(encoder);
1763
1764 vlv_wait_port_ready(dev_priv, port);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001765}
1766
1767static void intel_dp_pre_pll_enable(struct intel_encoder *encoder)
1768{
1769 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1770 struct drm_device *dev = encoder->base.dev;
1771 struct drm_i915_private *dev_priv = dev->dev_private;
1772 int port = vlv_dport_to_channel(dport);
1773
1774 if (!IS_VALLEYVIEW(dev))
1775 return;
1776
Jesse Barnes89b667f2013-04-18 14:51:36 -07001777 /* Program Tx lane resets to default */
Chris Wilson0980a602013-07-26 19:57:35 +01001778 mutex_lock(&dev_priv->dpio_lock);
Jani Nikulaae992582013-05-22 15:36:19 +03001779 vlv_dpio_write(dev_priv, DPIO_PCS_TX(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001780 DPIO_PCS_TX_LANE2_RESET |
1781 DPIO_PCS_TX_LANE1_RESET);
Jani Nikulaae992582013-05-22 15:36:19 +03001782 vlv_dpio_write(dev_priv, DPIO_PCS_CLK(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001783 DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
1784 DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
1785 (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
1786 DPIO_PCS_CLK_SOFT_RESET);
1787
1788 /* Fix up inter-pair skew failure */
Jani Nikulaae992582013-05-22 15:36:19 +03001789 vlv_dpio_write(dev_priv, DPIO_PCS_STAGGER1(port), 0x00750f00);
1790 vlv_dpio_write(dev_priv, DPIO_TX_CTL(port), 0x00001500);
1791 vlv_dpio_write(dev_priv, DPIO_TX_LANE(port), 0x40400000);
Chris Wilson0980a602013-07-26 19:57:35 +01001792 mutex_unlock(&dev_priv->dpio_lock);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001793}
1794
1795/*
Jesse Barnesdf0c2372011-07-07 11:11:02 -07001796 * Native read with retry for link status and receiver capability reads for
1797 * cases where the sink may still be asleep.
1798 */
1799static bool
1800intel_dp_aux_native_read_retry(struct intel_dp *intel_dp, uint16_t address,
1801 uint8_t *recv, int recv_bytes)
1802{
1803 int ret, i;
1804
1805 /*
1806 * Sinks are *supposed* to come up within 1ms from an off state,
1807 * but we're also supposed to retry 3 times per the spec.
1808 */
1809 for (i = 0; i < 3; i++) {
1810 ret = intel_dp_aux_native_read(intel_dp, address, recv,
1811 recv_bytes);
1812 if (ret == recv_bytes)
1813 return true;
1814 msleep(1);
1815 }
1816
1817 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001818}
1819
1820/*
1821 * Fetch AUX CH registers 0x202 - 0x207 which contain
1822 * link status information
1823 */
1824static bool
Keith Packard93f62da2011-11-01 19:45:03 -07001825intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001826{
Jesse Barnesdf0c2372011-07-07 11:11:02 -07001827 return intel_dp_aux_native_read_retry(intel_dp,
1828 DP_LANE0_1_STATUS,
Keith Packard93f62da2011-11-01 19:45:03 -07001829 link_status,
Jesse Barnesdf0c2372011-07-07 11:11:02 -07001830 DP_LINK_STATUS_SIZE);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001831}
1832
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001833#if 0
1834static char *voltage_names[] = {
1835 "0.4V", "0.6V", "0.8V", "1.2V"
1836};
1837static char *pre_emph_names[] = {
1838 "0dB", "3.5dB", "6dB", "9.5dB"
1839};
1840static char *link_train_names[] = {
1841 "pattern 1", "pattern 2", "idle", "off"
1842};
1843#endif
1844
1845/*
1846 * These are source-specific values; current Intel hardware supports
1847 * a maximum voltage of 800mV and a maximum pre-emphasis of 6dB
1848 */
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001849
1850static uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08001851intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001852{
Paulo Zanoni30add222012-10-26 19:05:45 -02001853 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001854 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08001855
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07001856 if (IS_VALLEYVIEW(dev))
1857 return DP_TRAIN_VOLTAGE_SWING_1200;
Imre Deakbc7d38a2013-05-16 14:40:36 +03001858 else if (IS_GEN7(dev) && port == PORT_A)
Keith Packard1a2eb462011-11-16 16:26:07 -08001859 return DP_TRAIN_VOLTAGE_SWING_800;
Imre Deakbc7d38a2013-05-16 14:40:36 +03001860 else if (HAS_PCH_CPT(dev) && port != PORT_A)
Keith Packard1a2eb462011-11-16 16:26:07 -08001861 return DP_TRAIN_VOLTAGE_SWING_1200;
1862 else
1863 return DP_TRAIN_VOLTAGE_SWING_800;
1864}
1865
1866static uint8_t
1867intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
1868{
Paulo Zanoni30add222012-10-26 19:05:45 -02001869 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001870 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08001871
Paulo Zanoni22b8bf12013-02-18 19:00:23 -03001872 if (HAS_DDI(dev)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03001873 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
1874 case DP_TRAIN_VOLTAGE_SWING_400:
1875 return DP_TRAIN_PRE_EMPHASIS_9_5;
1876 case DP_TRAIN_VOLTAGE_SWING_600:
1877 return DP_TRAIN_PRE_EMPHASIS_6;
1878 case DP_TRAIN_VOLTAGE_SWING_800:
1879 return DP_TRAIN_PRE_EMPHASIS_3_5;
1880 case DP_TRAIN_VOLTAGE_SWING_1200:
1881 default:
1882 return DP_TRAIN_PRE_EMPHASIS_0;
1883 }
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07001884 } else if (IS_VALLEYVIEW(dev)) {
1885 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
1886 case DP_TRAIN_VOLTAGE_SWING_400:
1887 return DP_TRAIN_PRE_EMPHASIS_9_5;
1888 case DP_TRAIN_VOLTAGE_SWING_600:
1889 return DP_TRAIN_PRE_EMPHASIS_6;
1890 case DP_TRAIN_VOLTAGE_SWING_800:
1891 return DP_TRAIN_PRE_EMPHASIS_3_5;
1892 case DP_TRAIN_VOLTAGE_SWING_1200:
1893 default:
1894 return DP_TRAIN_PRE_EMPHASIS_0;
1895 }
Imre Deakbc7d38a2013-05-16 14:40:36 +03001896 } else if (IS_GEN7(dev) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001897 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
1898 case DP_TRAIN_VOLTAGE_SWING_400:
1899 return DP_TRAIN_PRE_EMPHASIS_6;
1900 case DP_TRAIN_VOLTAGE_SWING_600:
1901 case DP_TRAIN_VOLTAGE_SWING_800:
1902 return DP_TRAIN_PRE_EMPHASIS_3_5;
1903 default:
1904 return DP_TRAIN_PRE_EMPHASIS_0;
1905 }
1906 } else {
1907 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
1908 case DP_TRAIN_VOLTAGE_SWING_400:
1909 return DP_TRAIN_PRE_EMPHASIS_6;
1910 case DP_TRAIN_VOLTAGE_SWING_600:
1911 return DP_TRAIN_PRE_EMPHASIS_6;
1912 case DP_TRAIN_VOLTAGE_SWING_800:
1913 return DP_TRAIN_PRE_EMPHASIS_3_5;
1914 case DP_TRAIN_VOLTAGE_SWING_1200:
1915 default:
1916 return DP_TRAIN_PRE_EMPHASIS_0;
1917 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001918 }
1919}
1920
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07001921static uint32_t intel_vlv_signal_levels(struct intel_dp *intel_dp)
1922{
1923 struct drm_device *dev = intel_dp_to_dev(intel_dp);
1924 struct drm_i915_private *dev_priv = dev->dev_private;
1925 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
1926 unsigned long demph_reg_value, preemph_reg_value,
1927 uniqtranscale_reg_value;
1928 uint8_t train_set = intel_dp->train_set[0];
Jesse Barnescece5d52013-04-19 08:46:35 -07001929 int port = vlv_dport_to_channel(dport);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07001930
1931 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
1932 case DP_TRAIN_PRE_EMPHASIS_0:
1933 preemph_reg_value = 0x0004000;
1934 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
1935 case DP_TRAIN_VOLTAGE_SWING_400:
1936 demph_reg_value = 0x2B405555;
1937 uniqtranscale_reg_value = 0x552AB83A;
1938 break;
1939 case DP_TRAIN_VOLTAGE_SWING_600:
1940 demph_reg_value = 0x2B404040;
1941 uniqtranscale_reg_value = 0x5548B83A;
1942 break;
1943 case DP_TRAIN_VOLTAGE_SWING_800:
1944 demph_reg_value = 0x2B245555;
1945 uniqtranscale_reg_value = 0x5560B83A;
1946 break;
1947 case DP_TRAIN_VOLTAGE_SWING_1200:
1948 demph_reg_value = 0x2B405555;
1949 uniqtranscale_reg_value = 0x5598DA3A;
1950 break;
1951 default:
1952 return 0;
1953 }
1954 break;
1955 case DP_TRAIN_PRE_EMPHASIS_3_5:
1956 preemph_reg_value = 0x0002000;
1957 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
1958 case DP_TRAIN_VOLTAGE_SWING_400:
1959 demph_reg_value = 0x2B404040;
1960 uniqtranscale_reg_value = 0x5552B83A;
1961 break;
1962 case DP_TRAIN_VOLTAGE_SWING_600:
1963 demph_reg_value = 0x2B404848;
1964 uniqtranscale_reg_value = 0x5580B83A;
1965 break;
1966 case DP_TRAIN_VOLTAGE_SWING_800:
1967 demph_reg_value = 0x2B404040;
1968 uniqtranscale_reg_value = 0x55ADDA3A;
1969 break;
1970 default:
1971 return 0;
1972 }
1973 break;
1974 case DP_TRAIN_PRE_EMPHASIS_6:
1975 preemph_reg_value = 0x0000000;
1976 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
1977 case DP_TRAIN_VOLTAGE_SWING_400:
1978 demph_reg_value = 0x2B305555;
1979 uniqtranscale_reg_value = 0x5570B83A;
1980 break;
1981 case DP_TRAIN_VOLTAGE_SWING_600:
1982 demph_reg_value = 0x2B2B4040;
1983 uniqtranscale_reg_value = 0x55ADDA3A;
1984 break;
1985 default:
1986 return 0;
1987 }
1988 break;
1989 case DP_TRAIN_PRE_EMPHASIS_9_5:
1990 preemph_reg_value = 0x0006000;
1991 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
1992 case DP_TRAIN_VOLTAGE_SWING_400:
1993 demph_reg_value = 0x1B405555;
1994 uniqtranscale_reg_value = 0x55ADDA3A;
1995 break;
1996 default:
1997 return 0;
1998 }
1999 break;
2000 default:
2001 return 0;
2002 }
2003
Chris Wilson0980a602013-07-26 19:57:35 +01002004 mutex_lock(&dev_priv->dpio_lock);
Jani Nikulaae992582013-05-22 15:36:19 +03002005 vlv_dpio_write(dev_priv, DPIO_TX_OCALINIT(port), 0x00000000);
2006 vlv_dpio_write(dev_priv, DPIO_TX_SWING_CTL4(port), demph_reg_value);
2007 vlv_dpio_write(dev_priv, DPIO_TX_SWING_CTL2(port),
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002008 uniqtranscale_reg_value);
Jani Nikulaae992582013-05-22 15:36:19 +03002009 vlv_dpio_write(dev_priv, DPIO_TX_SWING_CTL3(port), 0x0C782040);
2010 vlv_dpio_write(dev_priv, DPIO_PCS_STAGGER0(port), 0x00030000);
2011 vlv_dpio_write(dev_priv, DPIO_PCS_CTL_OVER1(port), preemph_reg_value);
2012 vlv_dpio_write(dev_priv, DPIO_TX_OCALINIT(port), 0x80000000);
Chris Wilson0980a602013-07-26 19:57:35 +01002013 mutex_unlock(&dev_priv->dpio_lock);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002014
2015 return 0;
2016}
2017
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002018static void
Keith Packard93f62da2011-11-01 19:45:03 -07002019intel_get_adjust_train(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002020{
2021 uint8_t v = 0;
2022 uint8_t p = 0;
2023 int lane;
Keith Packard1a2eb462011-11-16 16:26:07 -08002024 uint8_t voltage_max;
2025 uint8_t preemph_max;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002026
Jesse Barnes33a34e42010-09-08 12:42:02 -07002027 for (lane = 0; lane < intel_dp->lane_count; lane++) {
Daniel Vetter0f037bd2012-10-18 10:15:27 +02002028 uint8_t this_v = drm_dp_get_adjust_request_voltage(link_status, lane);
2029 uint8_t this_p = drm_dp_get_adjust_request_pre_emphasis(link_status, lane);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002030
2031 if (this_v > v)
2032 v = this_v;
2033 if (this_p > p)
2034 p = this_p;
2035 }
2036
Keith Packard1a2eb462011-11-16 16:26:07 -08002037 voltage_max = intel_dp_voltage_max(intel_dp);
Keith Packard417e8222011-11-01 19:54:11 -07002038 if (v >= voltage_max)
2039 v = voltage_max | DP_TRAIN_MAX_SWING_REACHED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002040
Keith Packard1a2eb462011-11-16 16:26:07 -08002041 preemph_max = intel_dp_pre_emphasis_max(intel_dp, v);
2042 if (p >= preemph_max)
2043 p = preemph_max | DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002044
2045 for (lane = 0; lane < 4; lane++)
Jesse Barnes33a34e42010-09-08 12:42:02 -07002046 intel_dp->train_set[lane] = v | p;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002047}
2048
2049static uint32_t
Paulo Zanonif0a34242012-12-06 16:51:50 -02002050intel_gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002051{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002052 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002053
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002054 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002055 case DP_TRAIN_VOLTAGE_SWING_400:
2056 default:
2057 signal_levels |= DP_VOLTAGE_0_4;
2058 break;
2059 case DP_TRAIN_VOLTAGE_SWING_600:
2060 signal_levels |= DP_VOLTAGE_0_6;
2061 break;
2062 case DP_TRAIN_VOLTAGE_SWING_800:
2063 signal_levels |= DP_VOLTAGE_0_8;
2064 break;
2065 case DP_TRAIN_VOLTAGE_SWING_1200:
2066 signal_levels |= DP_VOLTAGE_1_2;
2067 break;
2068 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002069 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002070 case DP_TRAIN_PRE_EMPHASIS_0:
2071 default:
2072 signal_levels |= DP_PRE_EMPHASIS_0;
2073 break;
2074 case DP_TRAIN_PRE_EMPHASIS_3_5:
2075 signal_levels |= DP_PRE_EMPHASIS_3_5;
2076 break;
2077 case DP_TRAIN_PRE_EMPHASIS_6:
2078 signal_levels |= DP_PRE_EMPHASIS_6;
2079 break;
2080 case DP_TRAIN_PRE_EMPHASIS_9_5:
2081 signal_levels |= DP_PRE_EMPHASIS_9_5;
2082 break;
2083 }
2084 return signal_levels;
2085}
2086
Zhenyu Wange3421a12010-04-08 09:43:27 +08002087/* Gen6's DP voltage swing and pre-emphasis control */
2088static uint32_t
2089intel_gen6_edp_signal_levels(uint8_t train_set)
2090{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08002091 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
2092 DP_TRAIN_PRE_EMPHASIS_MASK);
2093 switch (signal_levels) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08002094 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08002095 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
2096 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
2097 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
2098 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08002099 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08002100 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
2101 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08002102 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08002103 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
2104 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08002105 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08002106 case DP_TRAIN_VOLTAGE_SWING_1200 | DP_TRAIN_PRE_EMPHASIS_0:
2107 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08002108 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08002109 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
2110 "0x%x\n", signal_levels);
2111 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08002112 }
2113}
2114
Keith Packard1a2eb462011-11-16 16:26:07 -08002115/* Gen7's DP voltage swing and pre-emphasis control */
2116static uint32_t
2117intel_gen7_edp_signal_levels(uint8_t train_set)
2118{
2119 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
2120 DP_TRAIN_PRE_EMPHASIS_MASK);
2121 switch (signal_levels) {
2122 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
2123 return EDP_LINK_TRAIN_400MV_0DB_IVB;
2124 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
2125 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
2126 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
2127 return EDP_LINK_TRAIN_400MV_6DB_IVB;
2128
2129 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
2130 return EDP_LINK_TRAIN_600MV_0DB_IVB;
2131 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
2132 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
2133
2134 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
2135 return EDP_LINK_TRAIN_800MV_0DB_IVB;
2136 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
2137 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
2138
2139 default:
2140 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
2141 "0x%x\n", signal_levels);
2142 return EDP_LINK_TRAIN_500MV_0DB_IVB;
2143 }
2144}
2145
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002146/* Gen7.5's (HSW) DP voltage swing and pre-emphasis control */
2147static uint32_t
Paulo Zanonif0a34242012-12-06 16:51:50 -02002148intel_hsw_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002149{
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002150 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
2151 DP_TRAIN_PRE_EMPHASIS_MASK);
2152 switch (signal_levels) {
2153 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
2154 return DDI_BUF_EMP_400MV_0DB_HSW;
2155 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
2156 return DDI_BUF_EMP_400MV_3_5DB_HSW;
2157 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
2158 return DDI_BUF_EMP_400MV_6DB_HSW;
2159 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_9_5:
2160 return DDI_BUF_EMP_400MV_9_5DB_HSW;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002161
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002162 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
2163 return DDI_BUF_EMP_600MV_0DB_HSW;
2164 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
2165 return DDI_BUF_EMP_600MV_3_5DB_HSW;
2166 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
2167 return DDI_BUF_EMP_600MV_6DB_HSW;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002168
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002169 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
2170 return DDI_BUF_EMP_800MV_0DB_HSW;
2171 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
2172 return DDI_BUF_EMP_800MV_3_5DB_HSW;
2173 default:
2174 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
2175 "0x%x\n", signal_levels);
2176 return DDI_BUF_EMP_400MV_0DB_HSW;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002177 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002178}
2179
Paulo Zanonif0a34242012-12-06 16:51:50 -02002180/* Properly updates "DP" with the correct signal levels. */
2181static void
2182intel_dp_set_signal_levels(struct intel_dp *intel_dp, uint32_t *DP)
2183{
2184 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002185 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02002186 struct drm_device *dev = intel_dig_port->base.base.dev;
2187 uint32_t signal_levels, mask;
2188 uint8_t train_set = intel_dp->train_set[0];
2189
Paulo Zanoni22b8bf12013-02-18 19:00:23 -03002190 if (HAS_DDI(dev)) {
Paulo Zanonif0a34242012-12-06 16:51:50 -02002191 signal_levels = intel_hsw_signal_levels(train_set);
2192 mask = DDI_BUF_EMP_MASK;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07002193 } else if (IS_VALLEYVIEW(dev)) {
2194 signal_levels = intel_vlv_signal_levels(intel_dp);
2195 mask = 0;
Imre Deakbc7d38a2013-05-16 14:40:36 +03002196 } else if (IS_GEN7(dev) && port == PORT_A) {
Paulo Zanonif0a34242012-12-06 16:51:50 -02002197 signal_levels = intel_gen7_edp_signal_levels(train_set);
2198 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Imre Deakbc7d38a2013-05-16 14:40:36 +03002199 } else if (IS_GEN6(dev) && port == PORT_A) {
Paulo Zanonif0a34242012-12-06 16:51:50 -02002200 signal_levels = intel_gen6_edp_signal_levels(train_set);
2201 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
2202 } else {
2203 signal_levels = intel_gen4_signal_levels(train_set);
2204 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
2205 }
2206
2207 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
2208
2209 *DP = (*DP & ~mask) | signal_levels;
2210}
2211
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002212static bool
Chris Wilsonea5b2132010-08-04 13:50:23 +01002213intel_dp_set_link_train(struct intel_dp *intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002214 uint32_t dp_reg_value,
Chris Wilson58e10eb2010-10-03 10:56:11 +01002215 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002216{
Paulo Zanoni174edf12012-10-26 19:05:50 -02002217 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2218 struct drm_device *dev = intel_dig_port->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002219 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -02002220 enum port port = intel_dig_port->port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002221 int ret;
2222
Paulo Zanoni22b8bf12013-02-18 19:00:23 -03002223 if (HAS_DDI(dev)) {
Imre Deak3ab9c632013-05-03 12:57:41 +03002224 uint32_t temp = I915_READ(DP_TP_CTL(port));
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002225
2226 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2227 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2228 else
2229 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2230
2231 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2232 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2233 case DP_TRAINING_PATTERN_DISABLE:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002234 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2235
2236 break;
2237 case DP_TRAINING_PATTERN_1:
2238 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2239 break;
2240 case DP_TRAINING_PATTERN_2:
2241 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2242 break;
2243 case DP_TRAINING_PATTERN_3:
2244 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2245 break;
2246 }
Paulo Zanoni174edf12012-10-26 19:05:50 -02002247 I915_WRITE(DP_TP_CTL(port), temp);
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002248
Imre Deakbc7d38a2013-05-16 14:40:36 +03002249 } else if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || port != PORT_A)) {
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002250 dp_reg_value &= ~DP_LINK_TRAIN_MASK_CPT;
2251
2252 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2253 case DP_TRAINING_PATTERN_DISABLE:
2254 dp_reg_value |= DP_LINK_TRAIN_OFF_CPT;
2255 break;
2256 case DP_TRAINING_PATTERN_1:
2257 dp_reg_value |= DP_LINK_TRAIN_PAT_1_CPT;
2258 break;
2259 case DP_TRAINING_PATTERN_2:
2260 dp_reg_value |= DP_LINK_TRAIN_PAT_2_CPT;
2261 break;
2262 case DP_TRAINING_PATTERN_3:
2263 DRM_ERROR("DP training pattern 3 not supported\n");
2264 dp_reg_value |= DP_LINK_TRAIN_PAT_2_CPT;
2265 break;
2266 }
2267
2268 } else {
2269 dp_reg_value &= ~DP_LINK_TRAIN_MASK;
2270
2271 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2272 case DP_TRAINING_PATTERN_DISABLE:
2273 dp_reg_value |= DP_LINK_TRAIN_OFF;
2274 break;
2275 case DP_TRAINING_PATTERN_1:
2276 dp_reg_value |= DP_LINK_TRAIN_PAT_1;
2277 break;
2278 case DP_TRAINING_PATTERN_2:
2279 dp_reg_value |= DP_LINK_TRAIN_PAT_2;
2280 break;
2281 case DP_TRAINING_PATTERN_3:
2282 DRM_ERROR("DP training pattern 3 not supported\n");
2283 dp_reg_value |= DP_LINK_TRAIN_PAT_2;
2284 break;
2285 }
2286 }
2287
Chris Wilsonea5b2132010-08-04 13:50:23 +01002288 I915_WRITE(intel_dp->output_reg, dp_reg_value);
2289 POSTING_READ(intel_dp->output_reg);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002290
Chris Wilsonea5b2132010-08-04 13:50:23 +01002291 intel_dp_aux_native_write_1(intel_dp,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002292 DP_TRAINING_PATTERN_SET,
2293 dp_train_pat);
2294
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002295 if ((dp_train_pat & DP_TRAINING_PATTERN_MASK) !=
2296 DP_TRAINING_PATTERN_DISABLE) {
2297 ret = intel_dp_aux_native_write(intel_dp,
2298 DP_TRAINING_LANE0_SET,
2299 intel_dp->train_set,
2300 intel_dp->lane_count);
2301 if (ret != intel_dp->lane_count)
2302 return false;
2303 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002304
2305 return true;
2306}
2307
Imre Deak3ab9c632013-05-03 12:57:41 +03002308static void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
2309{
2310 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2311 struct drm_device *dev = intel_dig_port->base.base.dev;
2312 struct drm_i915_private *dev_priv = dev->dev_private;
2313 enum port port = intel_dig_port->port;
2314 uint32_t val;
2315
2316 if (!HAS_DDI(dev))
2317 return;
2318
2319 val = I915_READ(DP_TP_CTL(port));
2320 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2321 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
2322 I915_WRITE(DP_TP_CTL(port), val);
2323
2324 /*
2325 * On PORT_A we can have only eDP in SST mode. There the only reason
2326 * we need to set idle transmission mode is to work around a HW issue
2327 * where we enable the pipe while not in idle link-training mode.
2328 * In this case there is requirement to wait for a minimum number of
2329 * idle patterns to be sent.
2330 */
2331 if (port == PORT_A)
2332 return;
2333
2334 if (wait_for((I915_READ(DP_TP_STATUS(port)) & DP_TP_STATUS_IDLE_DONE),
2335 1))
2336 DRM_ERROR("Timed out waiting for DP idle patterns\n");
2337}
2338
Jesse Barnes33a34e42010-09-08 12:42:02 -07002339/* Enable corresponding port and start training pattern 1 */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002340void
Jesse Barnes33a34e42010-09-08 12:42:02 -07002341intel_dp_start_link_train(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002342{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002343 struct drm_encoder *encoder = &dp_to_dig_port(intel_dp)->base.base;
Paulo Zanonic19b0662012-10-15 15:51:41 -03002344 struct drm_device *dev = encoder->dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002345 int i;
2346 uint8_t voltage;
Keith Packardcdb0e952011-11-01 20:00:06 -07002347 int voltage_tries, loop_tries;
Chris Wilsonea5b2132010-08-04 13:50:23 +01002348 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002349
Paulo Zanoniaffa9352012-11-23 15:30:39 -02002350 if (HAS_DDI(dev))
Paulo Zanonic19b0662012-10-15 15:51:41 -03002351 intel_ddi_prepare_link_retrain(encoder);
2352
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002353 /* Write the link configuration data */
2354 intel_dp_aux_native_write(intel_dp, DP_LINK_BW_SET,
2355 intel_dp->link_configuration,
2356 DP_LINK_CONFIGURATION_SIZE);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002357
2358 DP |= DP_PORT_EN;
Keith Packard1a2eb462011-11-16 16:26:07 -08002359
Jesse Barnes33a34e42010-09-08 12:42:02 -07002360 memset(intel_dp->train_set, 0, 4);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002361 voltage = 0xff;
Keith Packardcdb0e952011-11-01 20:00:06 -07002362 voltage_tries = 0;
2363 loop_tries = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002364 for (;;) {
Jesse Barnes33a34e42010-09-08 12:42:02 -07002365 /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */
Keith Packard93f62da2011-11-01 19:45:03 -07002366 uint8_t link_status[DP_LINK_STATUS_SIZE];
Keith Packard417e8222011-11-01 19:54:11 -07002367
Paulo Zanonif0a34242012-12-06 16:51:50 -02002368 intel_dp_set_signal_levels(intel_dp, &DP);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002369
Daniel Vettera7c96552012-10-18 10:15:30 +02002370 /* Set training pattern 1 */
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002371 if (!intel_dp_set_link_train(intel_dp, DP,
Adam Jackson81055852011-07-21 17:48:37 -04002372 DP_TRAINING_PATTERN_1 |
2373 DP_LINK_SCRAMBLING_DISABLE))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002374 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002375
Daniel Vettera7c96552012-10-18 10:15:30 +02002376 drm_dp_link_train_clock_recovery_delay(intel_dp->dpcd);
Keith Packard93f62da2011-11-01 19:45:03 -07002377 if (!intel_dp_get_link_status(intel_dp, link_status)) {
2378 DRM_ERROR("failed to get link status\n");
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002379 break;
Keith Packard93f62da2011-11-01 19:45:03 -07002380 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002381
Daniel Vetter01916272012-10-18 10:15:25 +02002382 if (drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
Keith Packard93f62da2011-11-01 19:45:03 -07002383 DRM_DEBUG_KMS("clock recovery OK\n");
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002384 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002385 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002386
2387 /* Check to see if we've tried the max voltage */
2388 for (i = 0; i < intel_dp->lane_count; i++)
2389 if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
2390 break;
Takashi Iwai3b4f8192013-03-11 18:40:16 +01002391 if (i == intel_dp->lane_count) {
Daniel Vetterb06fbda2012-10-16 09:50:25 +02002392 ++loop_tries;
2393 if (loop_tries == 5) {
Keith Packardcdb0e952011-11-01 20:00:06 -07002394 DRM_DEBUG_KMS("too many full retries, give up\n");
2395 break;
2396 }
2397 memset(intel_dp->train_set, 0, 4);
2398 voltage_tries = 0;
2399 continue;
2400 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002401
2402 /* Check to see if we've tried the same voltage 5 times */
Daniel Vetterb06fbda2012-10-16 09:50:25 +02002403 if ((intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) == voltage) {
Chris Wilson24773672012-09-26 16:48:30 +01002404 ++voltage_tries;
Daniel Vetterb06fbda2012-10-16 09:50:25 +02002405 if (voltage_tries == 5) {
2406 DRM_DEBUG_KMS("too many voltage retries, give up\n");
2407 break;
2408 }
2409 } else
2410 voltage_tries = 0;
2411 voltage = intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002412
2413 /* Compute new intel_dp->train_set as requested by target */
Keith Packard93f62da2011-11-01 19:45:03 -07002414 intel_get_adjust_train(intel_dp, link_status);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002415 }
2416
Jesse Barnes33a34e42010-09-08 12:42:02 -07002417 intel_dp->DP = DP;
2418}
2419
Paulo Zanonic19b0662012-10-15 15:51:41 -03002420void
Jesse Barnes33a34e42010-09-08 12:42:02 -07002421intel_dp_complete_link_train(struct intel_dp *intel_dp)
2422{
Jesse Barnes33a34e42010-09-08 12:42:02 -07002423 bool channel_eq = false;
Jesse Barnes37f80972011-01-05 14:45:24 -08002424 int tries, cr_tries;
Jesse Barnes33a34e42010-09-08 12:42:02 -07002425 uint32_t DP = intel_dp->DP;
2426
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002427 /* channel equalization */
2428 tries = 0;
Jesse Barnes37f80972011-01-05 14:45:24 -08002429 cr_tries = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002430 channel_eq = false;
2431 for (;;) {
Keith Packard93f62da2011-11-01 19:45:03 -07002432 uint8_t link_status[DP_LINK_STATUS_SIZE];
Zhenyu Wange3421a12010-04-08 09:43:27 +08002433
Jesse Barnes37f80972011-01-05 14:45:24 -08002434 if (cr_tries > 5) {
2435 DRM_ERROR("failed to train DP, aborting\n");
2436 intel_dp_link_down(intel_dp);
2437 break;
2438 }
2439
Paulo Zanonif0a34242012-12-06 16:51:50 -02002440 intel_dp_set_signal_levels(intel_dp, &DP);
Zhenyu Wange3421a12010-04-08 09:43:27 +08002441
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002442 /* channel eq pattern */
Paulo Zanoni47ea7542012-07-17 16:55:16 -03002443 if (!intel_dp_set_link_train(intel_dp, DP,
Adam Jackson81055852011-07-21 17:48:37 -04002444 DP_TRAINING_PATTERN_2 |
2445 DP_LINK_SCRAMBLING_DISABLE))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002446 break;
2447
Daniel Vettera7c96552012-10-18 10:15:30 +02002448 drm_dp_link_train_channel_eq_delay(intel_dp->dpcd);
Keith Packard93f62da2011-11-01 19:45:03 -07002449 if (!intel_dp_get_link_status(intel_dp, link_status))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002450 break;
Jesse Barnes869184a2010-10-07 16:01:22 -07002451
Jesse Barnes37f80972011-01-05 14:45:24 -08002452 /* Make sure clock is still ok */
Daniel Vetter01916272012-10-18 10:15:25 +02002453 if (!drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
Jesse Barnes37f80972011-01-05 14:45:24 -08002454 intel_dp_start_link_train(intel_dp);
2455 cr_tries++;
2456 continue;
2457 }
2458
Daniel Vetter1ffdff12012-10-18 10:15:24 +02002459 if (drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002460 channel_eq = true;
2461 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002462 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002463
Jesse Barnes37f80972011-01-05 14:45:24 -08002464 /* Try 5 times, then try clock recovery if that fails */
2465 if (tries > 5) {
2466 intel_dp_link_down(intel_dp);
2467 intel_dp_start_link_train(intel_dp);
2468 tries = 0;
2469 cr_tries++;
2470 continue;
2471 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002472
2473 /* Compute new intel_dp->train_set as requested by target */
Keith Packard93f62da2011-11-01 19:45:03 -07002474 intel_get_adjust_train(intel_dp, link_status);
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002475 ++tries;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002476 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00002477
Imre Deak3ab9c632013-05-03 12:57:41 +03002478 intel_dp_set_idle_link_train(intel_dp);
2479
2480 intel_dp->DP = DP;
2481
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002482 if (channel_eq)
Masanari Iida07f42252013-03-20 11:00:34 +09002483 DRM_DEBUG_KMS("Channel EQ done. DP Training successful\n");
Paulo Zanonid6c0d722012-10-15 15:51:34 -03002484
Imre Deak3ab9c632013-05-03 12:57:41 +03002485}
2486
2487void intel_dp_stop_link_train(struct intel_dp *intel_dp)
2488{
2489 intel_dp_set_link_train(intel_dp, intel_dp->DP,
2490 DP_TRAINING_PATTERN_DISABLE);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002491}
2492
2493static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01002494intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002495{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002496 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002497 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002498 struct drm_device *dev = intel_dig_port->base.base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002499 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterab527ef2012-11-29 15:59:33 +01002500 struct intel_crtc *intel_crtc =
2501 to_intel_crtc(intel_dig_port->base.base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002502 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002503
Paulo Zanonic19b0662012-10-15 15:51:41 -03002504 /*
2505 * DDI code has a strict mode set sequence and we should try to respect
2506 * it, otherwise we might hang the machine in many different ways. So we
2507 * really should be disabling the port only on a complete crtc_disable
2508 * sequence. This function is just called under two conditions on DDI
2509 * code:
2510 * - Link train failed while doing crtc_enable, and on this case we
2511 * really should respect the mode set sequence and wait for a
2512 * crtc_disable.
2513 * - Someone turned the monitor off and intel_dp_check_link_status
2514 * called us. We don't need to disable the whole port on this case, so
2515 * when someone turns the monitor on again,
2516 * intel_ddi_prepare_link_retrain will take care of redoing the link
2517 * train.
2518 */
Paulo Zanoniaffa9352012-11-23 15:30:39 -02002519 if (HAS_DDI(dev))
Paulo Zanonic19b0662012-10-15 15:51:41 -03002520 return;
2521
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002522 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00002523 return;
2524
Zhao Yakui28c97732009-10-09 11:39:41 +08002525 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002526
Imre Deakbc7d38a2013-05-16 14:40:36 +03002527 if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08002528 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Chris Wilsonea5b2132010-08-04 13:50:23 +01002529 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT);
Zhenyu Wange3421a12010-04-08 09:43:27 +08002530 } else {
2531 DP &= ~DP_LINK_TRAIN_MASK;
Chris Wilsonea5b2132010-08-04 13:50:23 +01002532 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE);
Zhenyu Wange3421a12010-04-08 09:43:27 +08002533 }
Chris Wilsonfe255d02010-09-11 21:37:48 +01002534 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002535
Daniel Vetterab527ef2012-11-29 15:59:33 +01002536 /* We don't really know why we're doing this */
2537 intel_wait_for_vblank(dev, intel_crtc->pipe);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002538
Daniel Vetter493a7082012-05-30 12:31:56 +02002539 if (HAS_PCH_IBX(dev) &&
Chris Wilson1b39d6f2010-12-06 11:20:45 +00002540 I915_READ(intel_dp->output_reg) & DP_PIPEB_SELECT) {
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002541 struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
Chris Wilson31acbcc2011-04-17 06:38:35 +01002542
Eric Anholt5bddd172010-11-18 09:32:59 +08002543 /* Hardware workaround: leaving our transcoder select
2544 * set to transcoder B while it's off will prevent the
2545 * corresponding HDMI output on transcoder A.
2546 *
2547 * Combine this with another hardware workaround:
2548 * transcoder select bit can only be cleared while the
2549 * port is enabled.
2550 */
2551 DP &= ~DP_PIPEB_SELECT;
2552 I915_WRITE(intel_dp->output_reg, DP);
2553
2554 /* Changes to enable or select take place the vblank
2555 * after being written.
2556 */
Daniel Vetterff50afe2012-11-29 15:59:34 +01002557 if (WARN_ON(crtc == NULL)) {
2558 /* We should never try to disable a port without a crtc
2559 * attached. For paranoia keep the code around for a
2560 * bit. */
Chris Wilson31acbcc2011-04-17 06:38:35 +01002561 POSTING_READ(intel_dp->output_reg);
2562 msleep(50);
2563 } else
Daniel Vetterab527ef2012-11-29 15:59:33 +01002564 intel_wait_for_vblank(dev, intel_crtc->pipe);
Eric Anholt5bddd172010-11-18 09:32:59 +08002565 }
2566
Wu Fengguang832afda2011-12-09 20:42:21 +08002567 DP &= ~DP_AUDIO_OUTPUT_ENABLE;
Chris Wilsonea5b2132010-08-04 13:50:23 +01002568 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
2569 POSTING_READ(intel_dp->output_reg);
Keith Packardf01eca22011-09-28 16:48:10 -07002570 msleep(intel_dp->panel_power_down_delay);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002571}
2572
Keith Packard26d61aa2011-07-25 20:01:09 -07002573static bool
2574intel_dp_get_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07002575{
Damien Lespiau577c7a52012-12-13 16:09:02 +00002576 char dpcd_hex_dump[sizeof(intel_dp->dpcd) * 3];
2577
Keith Packard92fd8fd2011-07-25 19:50:10 -07002578 if (intel_dp_aux_native_read_retry(intel_dp, 0x000, intel_dp->dpcd,
Adam Jacksonedb39242012-09-18 10:58:49 -04002579 sizeof(intel_dp->dpcd)) == 0)
2580 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07002581
Damien Lespiau577c7a52012-12-13 16:09:02 +00002582 hex_dump_to_buffer(intel_dp->dpcd, sizeof(intel_dp->dpcd),
2583 32, 1, dpcd_hex_dump, sizeof(dpcd_hex_dump), false);
2584 DRM_DEBUG_KMS("DPCD: %s\n", dpcd_hex_dump);
2585
Adam Jacksonedb39242012-09-18 10:58:49 -04002586 if (intel_dp->dpcd[DP_DPCD_REV] == 0)
2587 return false; /* DPCD not present */
2588
Shobhit Kumar2293bb52013-07-11 18:44:56 -03002589 /* Check if the panel supports PSR */
2590 memset(intel_dp->psr_dpcd, 0, sizeof(intel_dp->psr_dpcd));
2591 intel_dp_aux_native_read_retry(intel_dp, DP_PSR_SUPPORT,
2592 intel_dp->psr_dpcd,
2593 sizeof(intel_dp->psr_dpcd));
2594 if (is_edp_psr(intel_dp))
2595 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
Adam Jacksonedb39242012-09-18 10:58:49 -04002596 if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
2597 DP_DWN_STRM_PORT_PRESENT))
2598 return true; /* native DP sink */
2599
2600 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
2601 return true; /* no per-port downstream info */
2602
2603 if (intel_dp_aux_native_read_retry(intel_dp, DP_DOWNSTREAM_PORT_0,
2604 intel_dp->downstream_ports,
2605 DP_MAX_DOWNSTREAM_PORTS) == 0)
2606 return false; /* downstream port status fetch failed */
2607
2608 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07002609}
2610
Adam Jackson0d198322012-05-14 16:05:47 -04002611static void
2612intel_dp_probe_oui(struct intel_dp *intel_dp)
2613{
2614 u8 buf[3];
2615
2616 if (!(intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] & DP_OUI_SUPPORT))
2617 return;
2618
Daniel Vetter351cfc32012-06-12 13:20:47 +02002619 ironlake_edp_panel_vdd_on(intel_dp);
2620
Adam Jackson0d198322012-05-14 16:05:47 -04002621 if (intel_dp_aux_native_read_retry(intel_dp, DP_SINK_OUI, buf, 3))
2622 DRM_DEBUG_KMS("Sink OUI: %02hx%02hx%02hx\n",
2623 buf[0], buf[1], buf[2]);
2624
2625 if (intel_dp_aux_native_read_retry(intel_dp, DP_BRANCH_OUI, buf, 3))
2626 DRM_DEBUG_KMS("Branch OUI: %02hx%02hx%02hx\n",
2627 buf[0], buf[1], buf[2]);
Daniel Vetter351cfc32012-06-12 13:20:47 +02002628
2629 ironlake_edp_panel_vdd_off(intel_dp, false);
Adam Jackson0d198322012-05-14 16:05:47 -04002630}
2631
Jesse Barnesa60f0e32011-10-20 15:09:17 -07002632static bool
2633intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
2634{
2635 int ret;
2636
2637 ret = intel_dp_aux_native_read_retry(intel_dp,
2638 DP_DEVICE_SERVICE_IRQ_VECTOR,
2639 sink_irq_vector, 1);
2640 if (!ret)
2641 return false;
2642
2643 return true;
2644}
2645
2646static void
2647intel_dp_handle_test_request(struct intel_dp *intel_dp)
2648{
2649 /* NAK by default */
Daniel Vetter9324cf72012-10-20 21:13:05 +02002650 intel_dp_aux_native_write_1(intel_dp, DP_TEST_RESPONSE, DP_TEST_NAK);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07002651}
2652
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002653/*
2654 * According to DP spec
2655 * 5.1.2:
2656 * 1. Read DPCD
2657 * 2. Configure link according to Receiver Capabilities
2658 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
2659 * 4. Check link status on receipt of hot-plug interrupt
2660 */
2661
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002662void
Chris Wilsonea5b2132010-08-04 13:50:23 +01002663intel_dp_check_link_status(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002664{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002665 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07002666 u8 sink_irq_vector;
Keith Packard93f62da2011-11-01 19:45:03 -07002667 u8 link_status[DP_LINK_STATUS_SIZE];
Jesse Barnesa60f0e32011-10-20 15:09:17 -07002668
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002669 if (!intel_encoder->connectors_active)
Keith Packardd2b996a2011-07-25 22:37:51 -07002670 return;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07002671
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002672 if (WARN_ON(!intel_encoder->base.crtc))
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002673 return;
2674
Keith Packard92fd8fd2011-07-25 19:50:10 -07002675 /* Try to read receiver status if the link appears to be up */
Keith Packard93f62da2011-11-01 19:45:03 -07002676 if (!intel_dp_get_link_status(intel_dp, link_status)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +01002677 intel_dp_link_down(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002678 return;
2679 }
2680
Keith Packard92fd8fd2011-07-25 19:50:10 -07002681 /* Now read the DPCD to see if it's actually running */
Keith Packard26d61aa2011-07-25 20:01:09 -07002682 if (!intel_dp_get_dpcd(intel_dp)) {
Jesse Barnes59cd09e2011-07-07 11:10:59 -07002683 intel_dp_link_down(intel_dp);
2684 return;
2685 }
2686
Jesse Barnesa60f0e32011-10-20 15:09:17 -07002687 /* Try to read the source of the interrupt */
2688 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
2689 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector)) {
2690 /* Clear interrupt source */
2691 intel_dp_aux_native_write_1(intel_dp,
2692 DP_DEVICE_SERVICE_IRQ_VECTOR,
2693 sink_irq_vector);
2694
2695 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
2696 intel_dp_handle_test_request(intel_dp);
2697 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
2698 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
2699 }
2700
Daniel Vetter1ffdff12012-10-18 10:15:24 +02002701 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Keith Packard92fd8fd2011-07-25 19:50:10 -07002702 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002703 drm_get_encoder_name(&intel_encoder->base));
Jesse Barnes33a34e42010-09-08 12:42:02 -07002704 intel_dp_start_link_train(intel_dp);
2705 intel_dp_complete_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002706 intel_dp_stop_link_train(intel_dp);
Jesse Barnes33a34e42010-09-08 12:42:02 -07002707 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002708}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002709
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04002710/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002711static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07002712intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04002713{
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04002714 uint8_t *dpcd = intel_dp->dpcd;
2715 bool hpd;
2716 uint8_t type;
2717
2718 if (!intel_dp_get_dpcd(intel_dp))
2719 return connector_status_disconnected;
2720
2721 /* if there's no downstream port, we're done */
2722 if (!(dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT))
Keith Packard26d61aa2011-07-25 20:01:09 -07002723 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04002724
2725 /* If we're HPD-aware, SINK_COUNT changes dynamically */
2726 hpd = !!(intel_dp->downstream_ports[0] & DP_DS_PORT_HPD);
2727 if (hpd) {
Adam Jackson23235172012-09-20 16:42:45 -04002728 uint8_t reg;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04002729 if (!intel_dp_aux_native_read_retry(intel_dp, DP_SINK_COUNT,
Adam Jackson23235172012-09-20 16:42:45 -04002730 &reg, 1))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04002731 return connector_status_unknown;
Adam Jackson23235172012-09-20 16:42:45 -04002732 return DP_GET_SINK_COUNT(reg) ? connector_status_connected
2733 : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04002734 }
2735
2736 /* If no HPD, poke DDC gently */
2737 if (drm_probe_ddc(&intel_dp->adapter))
2738 return connector_status_connected;
2739
2740 /* Well we tried, say unknown for unreliable port types */
2741 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
2742 if (type == DP_DS_PORT_TYPE_VGA || type == DP_DS_PORT_TYPE_NON_EDID)
2743 return connector_status_unknown;
2744
2745 /* Anything else is out of spec, warn and ignore */
2746 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07002747 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04002748}
2749
2750static enum drm_connector_status
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002751ironlake_dp_detect(struct intel_dp *intel_dp)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002752{
Paulo Zanoni30add222012-10-26 19:05:45 -02002753 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Damien Lespiau1b469632012-12-13 16:09:01 +00002754 struct drm_i915_private *dev_priv = dev->dev_private;
2755 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002756 enum drm_connector_status status;
2757
Chris Wilsonfe16d942011-02-12 10:29:38 +00002758 /* Can't disconnect eDP, but you can close the lid... */
2759 if (is_edp(intel_dp)) {
Paulo Zanoni30add222012-10-26 19:05:45 -02002760 status = intel_panel_detect(dev);
Chris Wilsonfe16d942011-02-12 10:29:38 +00002761 if (status == connector_status_unknown)
2762 status = connector_status_connected;
2763 return status;
2764 }
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002765
Damien Lespiau1b469632012-12-13 16:09:01 +00002766 if (!ibx_digital_port_connected(dev_priv, intel_dig_port))
2767 return connector_status_disconnected;
2768
Keith Packard26d61aa2011-07-25 20:01:09 -07002769 return intel_dp_detect_dpcd(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002770}
2771
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002772static enum drm_connector_status
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002773g4x_dp_detect(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002774{
Paulo Zanoni30add222012-10-26 19:05:45 -02002775 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002776 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä34f2be42013-01-24 15:29:27 +02002777 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilson10f76a32012-05-11 18:01:32 +01002778 uint32_t bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08002779
Jesse Barnes35aad752013-03-01 13:14:31 -08002780 /* Can't disconnect eDP, but you can close the lid... */
2781 if (is_edp(intel_dp)) {
2782 enum drm_connector_status status;
2783
2784 status = intel_panel_detect(dev);
2785 if (status == connector_status_unknown)
2786 status = connector_status_connected;
2787 return status;
2788 }
2789
Ville Syrjälä34f2be42013-01-24 15:29:27 +02002790 switch (intel_dig_port->port) {
2791 case PORT_B:
Daniel Vetter26739f12013-02-07 12:42:32 +01002792 bit = PORTB_HOTPLUG_LIVE_STATUS;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002793 break;
Ville Syrjälä34f2be42013-01-24 15:29:27 +02002794 case PORT_C:
Daniel Vetter26739f12013-02-07 12:42:32 +01002795 bit = PORTC_HOTPLUG_LIVE_STATUS;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002796 break;
Ville Syrjälä34f2be42013-01-24 15:29:27 +02002797 case PORT_D:
Daniel Vetter26739f12013-02-07 12:42:32 +01002798 bit = PORTD_HOTPLUG_LIVE_STATUS;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002799 break;
2800 default:
2801 return connector_status_unknown;
2802 }
2803
Chris Wilson10f76a32012-05-11 18:01:32 +01002804 if ((I915_READ(PORT_HOTPLUG_STAT) & bit) == 0)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002805 return connector_status_disconnected;
2806
Keith Packard26d61aa2011-07-25 20:01:09 -07002807 return intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002808}
2809
Keith Packard8c241fe2011-09-28 16:38:44 -07002810static struct edid *
2811intel_dp_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
2812{
Jani Nikula9cd300e2012-10-19 14:51:52 +03002813 struct intel_connector *intel_connector = to_intel_connector(connector);
Keith Packard8c241fe2011-09-28 16:38:44 -07002814
Jani Nikula9cd300e2012-10-19 14:51:52 +03002815 /* use cached edid if we have one */
2816 if (intel_connector->edid) {
2817 struct edid *edid;
2818 int size;
2819
2820 /* invalid edid */
2821 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04002822 return NULL;
2823
Jani Nikula9cd300e2012-10-19 14:51:52 +03002824 size = (intel_connector->edid->extensions + 1) * EDID_LENGTH;
Thomas Meyeredbe1582013-05-22 23:07:09 +02002825 edid = kmemdup(intel_connector->edid, size, GFP_KERNEL);
Jesse Barnesd6f24d02012-06-14 15:28:33 -04002826 if (!edid)
2827 return NULL;
2828
Jesse Barnesd6f24d02012-06-14 15:28:33 -04002829 return edid;
2830 }
2831
Jani Nikula9cd300e2012-10-19 14:51:52 +03002832 return drm_get_edid(connector, adapter);
Keith Packard8c241fe2011-09-28 16:38:44 -07002833}
2834
2835static int
2836intel_dp_get_edid_modes(struct drm_connector *connector, struct i2c_adapter *adapter)
2837{
Jani Nikula9cd300e2012-10-19 14:51:52 +03002838 struct intel_connector *intel_connector = to_intel_connector(connector);
Keith Packard8c241fe2011-09-28 16:38:44 -07002839
Jani Nikula9cd300e2012-10-19 14:51:52 +03002840 /* use cached edid if we have one */
2841 if (intel_connector->edid) {
2842 /* invalid edid */
2843 if (IS_ERR(intel_connector->edid))
2844 return 0;
2845
2846 return intel_connector_update_modes(connector,
2847 intel_connector->edid);
Jesse Barnesd6f24d02012-06-14 15:28:33 -04002848 }
2849
Jani Nikula9cd300e2012-10-19 14:51:52 +03002850 return intel_ddc_get_modes(connector, adapter);
Keith Packard8c241fe2011-09-28 16:38:44 -07002851}
2852
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002853static enum drm_connector_status
2854intel_dp_detect(struct drm_connector *connector, bool force)
2855{
2856 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02002857 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2858 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02002859 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002860 enum drm_connector_status status;
2861 struct edid *edid = NULL;
2862
Chris Wilson164c8592013-07-20 20:27:08 +01002863 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2864 connector->base.id, drm_get_connector_name(connector));
2865
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002866 intel_dp->has_audio = false;
2867
2868 if (HAS_PCH_SPLIT(dev))
2869 status = ironlake_dp_detect(intel_dp);
2870 else
2871 status = g4x_dp_detect(intel_dp);
Adam Jackson1b9be9d2011-07-12 17:38:01 -04002872
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002873 if (status != connector_status_connected)
2874 return status;
2875
Adam Jackson0d198322012-05-14 16:05:47 -04002876 intel_dp_probe_oui(intel_dp);
2877
Daniel Vetterc3e5f672012-02-23 17:14:47 +01002878 if (intel_dp->force_audio != HDMI_AUDIO_AUTO) {
2879 intel_dp->has_audio = (intel_dp->force_audio == HDMI_AUDIO_ON);
Chris Wilsonf6849602010-09-19 09:29:33 +01002880 } else {
Keith Packard8c241fe2011-09-28 16:38:44 -07002881 edid = intel_dp_get_edid(connector, &intel_dp->adapter);
Chris Wilsonf6849602010-09-19 09:29:33 +01002882 if (edid) {
2883 intel_dp->has_audio = drm_detect_monitor_audio(edid);
Chris Wilsonf6849602010-09-19 09:29:33 +01002884 kfree(edid);
2885 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002886 }
2887
Paulo Zanonid63885d2012-10-26 19:05:49 -02002888 if (intel_encoder->type != INTEL_OUTPUT_EDP)
2889 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08002890 return connector_status_connected;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002891}
2892
2893static int intel_dp_get_modes(struct drm_connector *connector)
2894{
Chris Wilsondf0e9242010-09-09 16:20:55 +01002895 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +03002896 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonifa90ece2012-10-26 19:05:44 -02002897 struct drm_device *dev = connector->dev;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002898 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002899
2900 /* We should parse the EDID data and find out if it has an audio sink
2901 */
2902
Keith Packard8c241fe2011-09-28 16:38:44 -07002903 ret = intel_dp_get_edid_modes(connector, &intel_dp->adapter);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002904 if (ret)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002905 return ret;
2906
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002907 /* if eDP has no EDID, fall back to fixed mode */
Jani Nikuladd06f902012-10-19 14:51:50 +03002908 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002909 struct drm_display_mode *mode;
Jani Nikuladd06f902012-10-19 14:51:50 +03002910 mode = drm_mode_duplicate(dev,
2911 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03002912 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002913 drm_mode_probed_add(connector, mode);
2914 return 1;
2915 }
2916 }
2917 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002918}
2919
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002920static bool
2921intel_dp_detect_audio(struct drm_connector *connector)
2922{
2923 struct intel_dp *intel_dp = intel_attached_dp(connector);
2924 struct edid *edid;
2925 bool has_audio = false;
2926
Keith Packard8c241fe2011-09-28 16:38:44 -07002927 edid = intel_dp_get_edid(connector, &intel_dp->adapter);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002928 if (edid) {
2929 has_audio = drm_detect_monitor_audio(edid);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002930 kfree(edid);
2931 }
2932
2933 return has_audio;
2934}
2935
Chris Wilsonf6849602010-09-19 09:29:33 +01002936static int
2937intel_dp_set_property(struct drm_connector *connector,
2938 struct drm_property *property,
2939 uint64_t val)
2940{
Chris Wilsone953fd72011-02-21 22:23:52 +00002941 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Yuly Novikov53b41832012-10-26 12:04:00 +03002942 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002943 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
2944 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01002945 int ret;
2946
Rob Clark662595d2012-10-11 20:36:04 -05002947 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01002948 if (ret)
2949 return ret;
2950
Chris Wilson3f43c482011-05-12 22:17:24 +01002951 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002952 int i = val;
2953 bool has_audio;
2954
2955 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01002956 return 0;
2957
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002958 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01002959
Daniel Vetterc3e5f672012-02-23 17:14:47 +01002960 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002961 has_audio = intel_dp_detect_audio(connector);
2962 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01002963 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002964
2965 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01002966 return 0;
2967
Chris Wilson1aad7ac2011-02-09 18:46:58 +00002968 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01002969 goto done;
2970 }
2971
Chris Wilsone953fd72011-02-21 22:23:52 +00002972 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02002973 bool old_auto = intel_dp->color_range_auto;
2974 uint32_t old_range = intel_dp->color_range;
2975
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02002976 switch (val) {
2977 case INTEL_BROADCAST_RGB_AUTO:
2978 intel_dp->color_range_auto = true;
2979 break;
2980 case INTEL_BROADCAST_RGB_FULL:
2981 intel_dp->color_range_auto = false;
2982 intel_dp->color_range = 0;
2983 break;
2984 case INTEL_BROADCAST_RGB_LIMITED:
2985 intel_dp->color_range_auto = false;
2986 intel_dp->color_range = DP_COLOR_RANGE_16_235;
2987 break;
2988 default:
2989 return -EINVAL;
2990 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02002991
2992 if (old_auto == intel_dp->color_range_auto &&
2993 old_range == intel_dp->color_range)
2994 return 0;
2995
Chris Wilsone953fd72011-02-21 22:23:52 +00002996 goto done;
2997 }
2998
Yuly Novikov53b41832012-10-26 12:04:00 +03002999 if (is_edp(intel_dp) &&
3000 property == connector->dev->mode_config.scaling_mode_property) {
3001 if (val == DRM_MODE_SCALE_NONE) {
3002 DRM_DEBUG_KMS("no scaling not supported\n");
3003 return -EINVAL;
3004 }
3005
3006 if (intel_connector->panel.fitting_mode == val) {
3007 /* the eDP scaling property is not changed */
3008 return 0;
3009 }
3010 intel_connector->panel.fitting_mode = val;
3011
3012 goto done;
3013 }
3014
Chris Wilsonf6849602010-09-19 09:29:33 +01003015 return -EINVAL;
3016
3017done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00003018 if (intel_encoder->base.crtc)
3019 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01003020
3021 return 0;
3022}
3023
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003024static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03003025intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003026{
Jani Nikula1d508702012-10-19 14:51:49 +03003027 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02003028
Jani Nikula9cd300e2012-10-19 14:51:52 +03003029 if (!IS_ERR_OR_NULL(intel_connector->edid))
3030 kfree(intel_connector->edid);
3031
Paulo Zanoniacd8db102013-06-12 17:27:23 -03003032 /* Can't call is_edp() since the encoder may have been destroyed
3033 * already. */
3034 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03003035 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02003036
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003037 drm_sysfs_connector_remove(connector);
3038 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08003039 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003040}
3041
Paulo Zanoni00c09d72012-10-26 19:05:52 -02003042void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02003043{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003044 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
3045 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetterbd173812013-03-25 11:24:10 +01003046 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Daniel Vetter24d05922010-08-20 18:08:28 +02003047
3048 i2c_del_adapter(&intel_dp->adapter);
3049 drm_encoder_cleanup(encoder);
Keith Packardbd943152011-09-18 23:09:52 -07003050 if (is_edp(intel_dp)) {
3051 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Daniel Vetterbd173812013-03-25 11:24:10 +01003052 mutex_lock(&dev->mode_config.mutex);
Keith Packardbd943152011-09-18 23:09:52 -07003053 ironlake_panel_vdd_off_sync(intel_dp);
Daniel Vetterbd173812013-03-25 11:24:10 +01003054 mutex_unlock(&dev->mode_config.mutex);
Keith Packardbd943152011-09-18 23:09:52 -07003055 }
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003056 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02003057}
3058
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003059static const struct drm_connector_funcs intel_dp_connector_funcs = {
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02003060 .dpms = intel_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003061 .detect = intel_dp_detect,
3062 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01003063 .set_property = intel_dp_set_property,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03003064 .destroy = intel_dp_connector_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003065};
3066
3067static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
3068 .get_modes = intel_dp_get_modes,
3069 .mode_valid = intel_dp_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +01003070 .best_encoder = intel_best_encoder,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003071};
3072
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003073static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Daniel Vetter24d05922010-08-20 18:08:28 +02003074 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003075};
3076
Chris Wilson995b6762010-08-20 13:23:26 +01003077static void
Eric Anholt21d40d32010-03-25 11:11:14 -07003078intel_dp_hot_plug(struct intel_encoder *intel_encoder)
Keith Packardc8110e52009-05-06 11:51:10 -07003079{
Paulo Zanonifa90ece2012-10-26 19:05:44 -02003080 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Keith Packardc8110e52009-05-06 11:51:10 -07003081
Jesse Barnes885a5012011-07-07 11:11:01 -07003082 intel_dp_check_link_status(intel_dp);
Keith Packardc8110e52009-05-06 11:51:10 -07003083}
3084
Zhenyu Wange3421a12010-04-08 09:43:27 +08003085/* Return which DP Port should be selected for Transcoder DP control */
3086int
Akshay Joshi0206e352011-08-16 15:34:10 -04003087intel_trans_dp_port_sel(struct drm_crtc *crtc)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003088{
3089 struct drm_device *dev = crtc->dev;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02003090 struct intel_encoder *intel_encoder;
3091 struct intel_dp *intel_dp;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003092
Paulo Zanonifa90ece2012-10-26 19:05:44 -02003093 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
3094 intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003095
Paulo Zanonifa90ece2012-10-26 19:05:44 -02003096 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
3097 intel_encoder->type == INTEL_OUTPUT_EDP)
Chris Wilsonea5b2132010-08-04 13:50:23 +01003098 return intel_dp->output_reg;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003099 }
Chris Wilsonea5b2132010-08-04 13:50:23 +01003100
Zhenyu Wange3421a12010-04-08 09:43:27 +08003101 return -1;
3102}
3103
Zhao Yakui36e83a12010-06-12 14:32:21 +08003104/* check the VBT to see whether the eDP is on DP-D port */
Adam Jacksoncb0953d2010-07-16 14:46:29 -04003105bool intel_dpd_is_edp(struct drm_device *dev)
Zhao Yakui36e83a12010-06-12 14:32:21 +08003106{
3107 struct drm_i915_private *dev_priv = dev->dev_private;
3108 struct child_device_config *p_child;
3109 int i;
3110
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03003111 if (!dev_priv->vbt.child_dev_num)
Zhao Yakui36e83a12010-06-12 14:32:21 +08003112 return false;
3113
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03003114 for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
3115 p_child = dev_priv->vbt.child_dev + i;
Zhao Yakui36e83a12010-06-12 14:32:21 +08003116
3117 if (p_child->dvo_port == PORT_IDPD &&
3118 p_child->device_type == DEVICE_TYPE_eDP)
3119 return true;
3120 }
3121 return false;
3122}
3123
Chris Wilsonf6849602010-09-19 09:29:33 +01003124static void
3125intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
3126{
Yuly Novikov53b41832012-10-26 12:04:00 +03003127 struct intel_connector *intel_connector = to_intel_connector(connector);
3128
Chris Wilson3f43c482011-05-12 22:17:24 +01003129 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00003130 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02003131 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03003132
3133 if (is_edp(intel_dp)) {
3134 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05003135 drm_object_attach_property(
3136 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03003137 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03003138 DRM_MODE_SCALE_ASPECT);
3139 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03003140 }
Chris Wilsonf6849602010-09-19 09:29:33 +01003141}
3142
Daniel Vetter67a54562012-10-20 20:57:45 +02003143static void
3144intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Jani Nikulaf30d26e2013-01-16 10:53:40 +02003145 struct intel_dp *intel_dp,
3146 struct edp_power_seq *out)
Daniel Vetter67a54562012-10-20 20:57:45 +02003147{
3148 struct drm_i915_private *dev_priv = dev->dev_private;
3149 struct edp_power_seq cur, vbt, spec, final;
3150 u32 pp_on, pp_off, pp_div, pp;
Jesse Barnes453c5422013-03-28 09:55:41 -07003151 int pp_control_reg, pp_on_reg, pp_off_reg, pp_div_reg;
3152
3153 if (HAS_PCH_SPLIT(dev)) {
3154 pp_control_reg = PCH_PP_CONTROL;
3155 pp_on_reg = PCH_PP_ON_DELAYS;
3156 pp_off_reg = PCH_PP_OFF_DELAYS;
3157 pp_div_reg = PCH_PP_DIVISOR;
3158 } else {
3159 pp_control_reg = PIPEA_PP_CONTROL;
3160 pp_on_reg = PIPEA_PP_ON_DELAYS;
3161 pp_off_reg = PIPEA_PP_OFF_DELAYS;
3162 pp_div_reg = PIPEA_PP_DIVISOR;
3163 }
Daniel Vetter67a54562012-10-20 20:57:45 +02003164
3165 /* Workaround: Need to write PP_CONTROL with the unlock key as
3166 * the very first thing. */
Jesse Barnes453c5422013-03-28 09:55:41 -07003167 pp = ironlake_get_pp_control(intel_dp);
3168 I915_WRITE(pp_control_reg, pp);
Daniel Vetter67a54562012-10-20 20:57:45 +02003169
Jesse Barnes453c5422013-03-28 09:55:41 -07003170 pp_on = I915_READ(pp_on_reg);
3171 pp_off = I915_READ(pp_off_reg);
3172 pp_div = I915_READ(pp_div_reg);
Daniel Vetter67a54562012-10-20 20:57:45 +02003173
3174 /* Pull timing values out of registers */
3175 cur.t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
3176 PANEL_POWER_UP_DELAY_SHIFT;
3177
3178 cur.t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
3179 PANEL_LIGHT_ON_DELAY_SHIFT;
3180
3181 cur.t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
3182 PANEL_LIGHT_OFF_DELAY_SHIFT;
3183
3184 cur.t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
3185 PANEL_POWER_DOWN_DELAY_SHIFT;
3186
3187 cur.t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
3188 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
3189
3190 DRM_DEBUG_KMS("cur t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
3191 cur.t1_t3, cur.t8, cur.t9, cur.t10, cur.t11_t12);
3192
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03003193 vbt = dev_priv->vbt.edp_pps;
Daniel Vetter67a54562012-10-20 20:57:45 +02003194
3195 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
3196 * our hw here, which are all in 100usec. */
3197 spec.t1_t3 = 210 * 10;
3198 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
3199 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
3200 spec.t10 = 500 * 10;
3201 /* This one is special and actually in units of 100ms, but zero
3202 * based in the hw (so we need to add 100 ms). But the sw vbt
3203 * table multiplies it with 1000 to make it in units of 100usec,
3204 * too. */
3205 spec.t11_t12 = (510 + 100) * 10;
3206
3207 DRM_DEBUG_KMS("vbt t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
3208 vbt.t1_t3, vbt.t8, vbt.t9, vbt.t10, vbt.t11_t12);
3209
3210 /* Use the max of the register settings and vbt. If both are
3211 * unset, fall back to the spec limits. */
3212#define assign_final(field) final.field = (max(cur.field, vbt.field) == 0 ? \
3213 spec.field : \
3214 max(cur.field, vbt.field))
3215 assign_final(t1_t3);
3216 assign_final(t8);
3217 assign_final(t9);
3218 assign_final(t10);
3219 assign_final(t11_t12);
3220#undef assign_final
3221
3222#define get_delay(field) (DIV_ROUND_UP(final.field, 10))
3223 intel_dp->panel_power_up_delay = get_delay(t1_t3);
3224 intel_dp->backlight_on_delay = get_delay(t8);
3225 intel_dp->backlight_off_delay = get_delay(t9);
3226 intel_dp->panel_power_down_delay = get_delay(t10);
3227 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
3228#undef get_delay
3229
Jani Nikulaf30d26e2013-01-16 10:53:40 +02003230 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
3231 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
3232 intel_dp->panel_power_cycle_delay);
3233
3234 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
3235 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
3236
3237 if (out)
3238 *out = final;
3239}
3240
3241static void
3242intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
3243 struct intel_dp *intel_dp,
3244 struct edp_power_seq *seq)
3245{
3246 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes453c5422013-03-28 09:55:41 -07003247 u32 pp_on, pp_off, pp_div, port_sel = 0;
3248 int div = HAS_PCH_SPLIT(dev) ? intel_pch_rawclk(dev) : intel_hrawclk(dev);
3249 int pp_on_reg, pp_off_reg, pp_div_reg;
3250
3251 if (HAS_PCH_SPLIT(dev)) {
3252 pp_on_reg = PCH_PP_ON_DELAYS;
3253 pp_off_reg = PCH_PP_OFF_DELAYS;
3254 pp_div_reg = PCH_PP_DIVISOR;
3255 } else {
3256 pp_on_reg = PIPEA_PP_ON_DELAYS;
3257 pp_off_reg = PIPEA_PP_OFF_DELAYS;
3258 pp_div_reg = PIPEA_PP_DIVISOR;
3259 }
3260
Daniel Vetter67a54562012-10-20 20:57:45 +02003261 /* And finally store the new values in the power sequencer. */
Jani Nikulaf30d26e2013-01-16 10:53:40 +02003262 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
3263 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
3264 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
3265 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02003266 /* Compute the divisor for the pp clock, simply match the Bspec
3267 * formula. */
Jesse Barnes453c5422013-03-28 09:55:41 -07003268 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02003269 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
Daniel Vetter67a54562012-10-20 20:57:45 +02003270 << PANEL_POWER_CYCLE_DELAY_SHIFT);
3271
3272 /* Haswell doesn't have any port selection bits for the panel
3273 * power sequencer any more. */
Imre Deakbc7d38a2013-05-16 14:40:36 +03003274 if (IS_VALLEYVIEW(dev)) {
3275 port_sel = I915_READ(pp_on_reg) & 0xc0000000;
3276 } else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) {
3277 if (dp_to_dig_port(intel_dp)->port == PORT_A)
Jesse Barnes453c5422013-03-28 09:55:41 -07003278 port_sel = PANEL_POWER_PORT_DP_A;
Daniel Vetter67a54562012-10-20 20:57:45 +02003279 else
Jesse Barnes453c5422013-03-28 09:55:41 -07003280 port_sel = PANEL_POWER_PORT_DP_D;
Daniel Vetter67a54562012-10-20 20:57:45 +02003281 }
3282
Jesse Barnes453c5422013-03-28 09:55:41 -07003283 pp_on |= port_sel;
3284
3285 I915_WRITE(pp_on_reg, pp_on);
3286 I915_WRITE(pp_off_reg, pp_off);
3287 I915_WRITE(pp_div_reg, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02003288
Daniel Vetter67a54562012-10-20 20:57:45 +02003289 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 -07003290 I915_READ(pp_on_reg),
3291 I915_READ(pp_off_reg),
3292 I915_READ(pp_div_reg));
Keith Packardc8110e52009-05-06 11:51:10 -07003293}
3294
Paulo Zanonied92f0b2013-06-12 17:27:24 -03003295static bool intel_edp_init_connector(struct intel_dp *intel_dp,
3296 struct intel_connector *intel_connector)
3297{
3298 struct drm_connector *connector = &intel_connector->base;
3299 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3300 struct drm_device *dev = intel_dig_port->base.base.dev;
3301 struct drm_i915_private *dev_priv = dev->dev_private;
3302 struct drm_display_mode *fixed_mode = NULL;
3303 struct edp_power_seq power_seq = { 0 };
3304 bool has_dpcd;
3305 struct drm_display_mode *scan;
3306 struct edid *edid;
3307
3308 if (!is_edp(intel_dp))
3309 return true;
3310
3311 intel_dp_init_panel_power_sequencer(dev, intel_dp, &power_seq);
3312
3313 /* Cache DPCD and EDID for edp. */
3314 ironlake_edp_panel_vdd_on(intel_dp);
3315 has_dpcd = intel_dp_get_dpcd(intel_dp);
3316 ironlake_edp_panel_vdd_off(intel_dp, false);
3317
3318 if (has_dpcd) {
3319 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3320 dev_priv->no_aux_handshake =
3321 intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3322 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3323 } else {
3324 /* if this fails, presume the device is a ghost */
3325 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Paulo Zanonied92f0b2013-06-12 17:27:24 -03003326 return false;
3327 }
3328
3329 /* We now know it's not a ghost, init power sequence regs. */
3330 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp,
3331 &power_seq);
3332
3333 ironlake_edp_panel_vdd_on(intel_dp);
3334 edid = drm_get_edid(connector, &intel_dp->adapter);
3335 if (edid) {
3336 if (drm_add_edid_modes(connector, edid)) {
3337 drm_mode_connector_update_edid_property(connector,
3338 edid);
3339 drm_edid_to_eld(connector, edid);
3340 } else {
3341 kfree(edid);
3342 edid = ERR_PTR(-EINVAL);
3343 }
3344 } else {
3345 edid = ERR_PTR(-ENOENT);
3346 }
3347 intel_connector->edid = edid;
3348
3349 /* prefer fixed mode from EDID if available */
3350 list_for_each_entry(scan, &connector->probed_modes, head) {
3351 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
3352 fixed_mode = drm_mode_duplicate(dev, scan);
3353 break;
3354 }
3355 }
3356
3357 /* fallback to VBT if available for eDP */
3358 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
3359 fixed_mode = drm_mode_duplicate(dev,
3360 dev_priv->vbt.lfp_lvds_vbt_mode);
3361 if (fixed_mode)
3362 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
3363 }
3364
3365 ironlake_edp_panel_vdd_off(intel_dp, false);
3366
3367 intel_panel_init(&intel_connector->panel, fixed_mode);
3368 intel_panel_setup_backlight(connector);
3369
3370 return true;
3371}
3372
Paulo Zanoni16c25532013-06-12 17:27:25 -03003373bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003374intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
3375 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003376{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003377 struct drm_connector *connector = &intel_connector->base;
3378 struct intel_dp *intel_dp = &intel_dig_port->dp;
3379 struct intel_encoder *intel_encoder = &intel_dig_port->base;
3380 struct drm_device *dev = intel_encoder->base.dev;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003381 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -02003382 enum port port = intel_dig_port->port;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003383 const char *name = NULL;
Paulo Zanonib2a14752013-06-12 17:27:28 -03003384 int type, error;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003385
Daniel Vetter07679352012-09-06 22:15:42 +02003386 /* Preserve the current hw state. */
3387 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03003388 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00003389
Imre Deakf7d24902013-05-08 13:14:05 +03003390 type = DRM_MODE_CONNECTOR_DisplayPort;
Gajanan Bhat19c03922012-09-27 19:13:07 +05303391 /*
3392 * FIXME : We need to initialize built-in panels before external panels.
3393 * For X0, DP_C is fixed as eDP. Revisit this as part of VLV eDP cleanup
3394 */
Imre Deakf7d24902013-05-08 13:14:05 +03003395 switch (port) {
3396 case PORT_A:
Gajanan Bhat19c03922012-09-27 19:13:07 +05303397 type = DRM_MODE_CONNECTOR_eDP;
Imre Deakf7d24902013-05-08 13:14:05 +03003398 break;
3399 case PORT_C:
3400 if (IS_VALLEYVIEW(dev))
3401 type = DRM_MODE_CONNECTOR_eDP;
3402 break;
3403 case PORT_D:
3404 if (HAS_PCH_SPLIT(dev) && intel_dpd_is_edp(dev))
3405 type = DRM_MODE_CONNECTOR_eDP;
3406 break;
3407 default: /* silence GCC warning */
3408 break;
Adam Jacksonb3295302010-07-16 14:46:28 -04003409 }
3410
Imre Deakf7d24902013-05-08 13:14:05 +03003411 /*
3412 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
3413 * for DP the encoder type can be set by the caller to
3414 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
3415 */
3416 if (type == DRM_MODE_CONNECTOR_eDP)
3417 intel_encoder->type = INTEL_OUTPUT_EDP;
3418
Imre Deake7281ea2013-05-08 13:14:08 +03003419 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
3420 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
3421 port_name(port));
3422
Adam Jacksonb3295302010-07-16 14:46:28 -04003423 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003424 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
3425
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003426 connector->interlace_allowed = true;
3427 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08003428
Daniel Vetter66a92782012-07-12 20:08:18 +02003429 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
3430 ironlake_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08003431
Chris Wilsondf0e9242010-09-09 16:20:55 +01003432 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003433 drm_sysfs_connector_add(connector);
3434
Paulo Zanoniaffa9352012-11-23 15:30:39 -02003435 if (HAS_DDI(dev))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02003436 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
3437 else
3438 intel_connector->get_hw_state = intel_connector_get_hw_state;
3439
Paulo Zanoni9ed35ab2013-02-18 19:00:25 -03003440 intel_dp->aux_ch_ctl_reg = intel_dp->output_reg + 0x10;
3441 if (HAS_DDI(dev)) {
3442 switch (intel_dig_port->port) {
3443 case PORT_A:
3444 intel_dp->aux_ch_ctl_reg = DPA_AUX_CH_CTL;
3445 break;
3446 case PORT_B:
3447 intel_dp->aux_ch_ctl_reg = PCH_DPB_AUX_CH_CTL;
3448 break;
3449 case PORT_C:
3450 intel_dp->aux_ch_ctl_reg = PCH_DPC_AUX_CH_CTL;
3451 break;
3452 case PORT_D:
3453 intel_dp->aux_ch_ctl_reg = PCH_DPD_AUX_CH_CTL;
3454 break;
3455 default:
3456 BUG();
3457 }
3458 }
Daniel Vettere8cb4552012-07-01 13:05:48 +02003459
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003460 /* Set up the DDC bus. */
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03003461 switch (port) {
3462 case PORT_A:
Egbert Eich1d843f92013-02-25 12:06:49 -05003463 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03003464 name = "DPDDC-A";
3465 break;
3466 case PORT_B:
Egbert Eich1d843f92013-02-25 12:06:49 -05003467 intel_encoder->hpd_pin = HPD_PORT_B;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03003468 name = "DPDDC-B";
3469 break;
3470 case PORT_C:
Egbert Eich1d843f92013-02-25 12:06:49 -05003471 intel_encoder->hpd_pin = HPD_PORT_C;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03003472 name = "DPDDC-C";
3473 break;
3474 case PORT_D:
Egbert Eich1d843f92013-02-25 12:06:49 -05003475 intel_encoder->hpd_pin = HPD_PORT_D;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03003476 name = "DPDDC-D";
3477 break;
3478 default:
Damien Lespiauad1c0b12013-03-07 15:30:28 +00003479 BUG();
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003480 }
3481
Paulo Zanonib2a14752013-06-12 17:27:28 -03003482 error = intel_dp_i2c_init(intel_dp, intel_connector, name);
3483 WARN(error, "intel_dp_i2c_init failed with error %d for port %c\n",
3484 error, port_name(port));
Dave Airliec1f05262012-08-30 11:06:18 +10003485
Rodrigo Vivi2b28bb12013-07-11 18:44:58 -03003486 intel_dp->psr_setup_done = false;
3487
Paulo Zanonib2f246a2013-06-12 17:27:26 -03003488 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Paulo Zanoni15b1d172013-06-12 17:27:27 -03003489 i2c_del_adapter(&intel_dp->adapter);
3490 if (is_edp(intel_dp)) {
3491 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
3492 mutex_lock(&dev->mode_config.mutex);
3493 ironlake_panel_vdd_off_sync(intel_dp);
3494 mutex_unlock(&dev->mode_config.mutex);
3495 }
Paulo Zanonib2f246a2013-06-12 17:27:26 -03003496 drm_sysfs_connector_remove(connector);
3497 drm_connector_cleanup(connector);
Paulo Zanoni16c25532013-06-12 17:27:25 -03003498 return false;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03003499 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003500
Chris Wilsonf6849602010-09-19 09:29:33 +01003501 intel_dp_add_properties(intel_dp, connector);
3502
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003503 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
3504 * 0xd. Failure to do so will result in spurious interrupts being
3505 * generated on the port when a cable is not attached.
3506 */
3507 if (IS_G4X(dev) && !IS_GM45(dev)) {
3508 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
3509 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
3510 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03003511
3512 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003513}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003514
3515void
3516intel_dp_init(struct drm_device *dev, int output_reg, enum port port)
3517{
3518 struct intel_digital_port *intel_dig_port;
3519 struct intel_encoder *intel_encoder;
3520 struct drm_encoder *encoder;
3521 struct intel_connector *intel_connector;
3522
3523 intel_dig_port = kzalloc(sizeof(struct intel_digital_port), GFP_KERNEL);
3524 if (!intel_dig_port)
3525 return;
3526
3527 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
3528 if (!intel_connector) {
3529 kfree(intel_dig_port);
3530 return;
3531 }
3532
3533 intel_encoder = &intel_dig_port->base;
3534 encoder = &intel_encoder->base;
3535
3536 drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
3537 DRM_MODE_ENCODER_TMDS);
3538
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01003539 intel_encoder->compute_config = intel_dp_compute_config;
Daniel Vetterb934223d2013-07-21 21:37:05 +02003540 intel_encoder->mode_set = intel_dp_mode_set;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02003541 intel_encoder->disable = intel_disable_dp;
3542 intel_encoder->post_disable = intel_post_disable_dp;
3543 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07003544 intel_encoder->get_config = intel_dp_get_config;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03003545 if (IS_VALLEYVIEW(dev)) {
Jesse Barnes89b667f2013-04-18 14:51:36 -07003546 intel_encoder->pre_pll_enable = intel_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03003547 intel_encoder->pre_enable = vlv_pre_enable_dp;
3548 intel_encoder->enable = vlv_enable_dp;
3549 } else {
3550 intel_encoder->pre_enable = intel_pre_enable_dp;
3551 intel_encoder->enable = intel_enable_dp;
3552 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003553
Paulo Zanoni174edf12012-10-26 19:05:50 -02003554 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003555 intel_dig_port->dp.output_reg = output_reg;
3556
Paulo Zanoni00c09d72012-10-26 19:05:52 -02003557 intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003558 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
3559 intel_encoder->cloneable = false;
3560 intel_encoder->hot_plug = intel_dp_hot_plug;
3561
Paulo Zanoni15b1d172013-06-12 17:27:27 -03003562 if (!intel_dp_init_connector(intel_dig_port, intel_connector)) {
3563 drm_encoder_cleanup(encoder);
3564 kfree(intel_dig_port);
Paulo Zanonib2f246a2013-06-12 17:27:26 -03003565 kfree(intel_connector);
Paulo Zanoni15b1d172013-06-12 17:27:27 -03003566 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02003567}