blob: 5ba8366ff1e5bcb5c68754e23c013528dcf179cf [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>
Manasi Navare611032b2017-01-24 08:21:49 -080031#include <linux/types.h>
Clint Taylor01527b32014-07-07 13:01:46 -070032#include <linux/notifier.h>
33#include <linux/reboot.h>
Manasi Navare611032b2017-01-24 08:21:49 -080034#include <asm/byteorder.h>
David Howells760285e2012-10-02 18:01:07 +010035#include <drm/drmP.h>
Matt Roperc6f95f22015-01-22 16:50:32 -080036#include <drm/drm_atomic_helper.h>
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/drm_crtc.h>
38#include <drm/drm_crtc_helper.h>
39#include <drm/drm_edid.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070040#include "intel_drv.h"
David Howells760285e2012-10-02 18:01:07 +010041#include <drm/i915_drm.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070042#include "i915_drv.h"
Keith Packarda4fc5ed2009-04-07 16:16:42 -070043
Keith Packarda4fc5ed2009-04-07 16:16:42 -070044#define DP_LINK_CHECK_TIMEOUT (10 * 1000)
45
Todd Previte559be302015-05-04 07:48:20 -070046/* Compliance test status bits */
47#define INTEL_DP_RESOLUTION_SHIFT_MASK 0
48#define INTEL_DP_RESOLUTION_PREFERRED (1 << INTEL_DP_RESOLUTION_SHIFT_MASK)
49#define INTEL_DP_RESOLUTION_STANDARD (2 << INTEL_DP_RESOLUTION_SHIFT_MASK)
50#define INTEL_DP_RESOLUTION_FAILSAFE (3 << INTEL_DP_RESOLUTION_SHIFT_MASK)
51
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080052struct dp_link_dpll {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030053 int clock;
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080054 struct dpll dpll;
55};
56
57static const struct dp_link_dpll gen4_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030058 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080059 { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030060 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080061 { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
62};
63
64static const struct dp_link_dpll pch_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030065 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080066 { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030067 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080068 { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
69};
70
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080071static const struct dp_link_dpll vlv_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030072 { 162000,
Chon Ming Lee58f6e632013-09-25 15:47:51 +080073 { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030074 { 270000,
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080075 { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } }
76};
77
Chon Ming Leeef9348c2014-04-09 13:28:18 +030078/*
79 * CHV supports eDP 1.4 that have more link rates.
80 * Below only provides the fixed rate but exclude variable rate.
81 */
82static const struct dp_link_dpll chv_dpll[] = {
83 /*
84 * CHV requires to program fractional division for m2.
85 * m2 is stored in fixed point format using formula below
86 * (m2_int << 22) | m2_fraction
87 */
Ville Syrjälä840b32b2015-08-11 20:21:46 +030088 { 162000, /* m2_int = 32, m2_fraction = 1677722 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030089 { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030090 { 270000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030091 { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030092 { 540000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030093 { .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }
94};
Sonika Jindal637a9c62015-05-07 09:52:08 +053095
Sonika Jindal64987fc2015-05-26 17:50:13 +053096static const int bxt_rates[] = { 162000, 216000, 243000, 270000,
97 324000, 432000, 540000 };
Sonika Jindal637a9c62015-05-07 09:52:08 +053098static const int skl_rates[] = { 162000, 216000, 270000,
Ville Syrjäläf4896f12015-03-12 17:10:27 +020099 324000, 432000, 540000 };
Rodrigo Vivid907b662017-08-10 15:40:08 -0700100static const int cnl_rates[] = { 162000, 216000, 270000,
101 324000, 432000, 540000,
102 648000, 810000 };
Ville Syrjäläf4896f12015-03-12 17:10:27 +0200103static const int default_rates[] = { 162000, 270000, 540000 };
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300104
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700105/**
106 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
107 * @intel_dp: DP struct
108 *
109 * If a CPU or PCH DP output is attached to an eDP panel, this function
110 * will return true, and false otherwise.
111 */
112static bool is_edp(struct intel_dp *intel_dp)
113{
Paulo Zanonida63a9f2012-10-26 19:05:46 -0200114 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
115
116 return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700117}
118
Imre Deak68b4d822013-05-08 13:14:06 +0300119static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp)
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700120{
Imre Deak68b4d822013-05-08 13:14:06 +0300121 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
122
123 return intel_dig_port->base.base.dev;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700124}
125
Chris Wilsondf0e9242010-09-09 16:20:55 +0100126static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
127{
Paulo Zanonifa90ece2012-10-26 19:05:44 -0200128 return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
Chris Wilsondf0e9242010-09-09 16:20:55 +0100129}
130
Chris Wilsonea5b2132010-08-04 13:50:23 +0100131static void intel_dp_link_down(struct intel_dp *intel_dp);
Ville Syrjälä1e0560e2014-08-19 13:24:25 +0300132static bool edp_panel_vdd_on(struct intel_dp *intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +0100133static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
Ville Syrjälä093e3f12014-10-16 21:27:33 +0300134static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300135static void vlv_steal_power_sequencer(struct drm_device *dev,
136 enum pipe pipe);
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +0530137static void intel_dp_unset_edid(struct intel_dp *intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700138
Jani Nikula68f357c2017-03-28 17:59:05 +0300139static int intel_dp_num_rates(u8 link_bw_code)
140{
141 switch (link_bw_code) {
142 default:
143 WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
144 link_bw_code);
145 case DP_LINK_BW_1_62:
146 return 1;
147 case DP_LINK_BW_2_7:
148 return 2;
149 case DP_LINK_BW_5_4:
150 return 3;
151 }
152}
153
154/* update sink rates from dpcd */
155static void intel_dp_set_sink_rates(struct intel_dp *intel_dp)
156{
157 int i, num_rates;
158
159 num_rates = intel_dp_num_rates(intel_dp->dpcd[DP_MAX_LINK_RATE]);
160
161 for (i = 0; i < num_rates; i++)
162 intel_dp->sink_rates[i] = default_rates[i];
163
164 intel_dp->num_sink_rates = num_rates;
165}
166
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300167/* Theoretical max between source and sink */
168static int intel_dp_max_common_rate(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700169{
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300170 return intel_dp->common_rates[intel_dp->num_common_rates - 1];
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700171}
172
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300173/* Theoretical max between source and sink */
174static int intel_dp_max_common_lane_count(struct intel_dp *intel_dp)
Paulo Zanonieeb63242014-05-06 14:56:50 +0300175{
176 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300177 int source_max = intel_dig_port->max_lanes;
178 int sink_max = drm_dp_max_lane_count(intel_dp->dpcd);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300179
180 return min(source_max, sink_max);
181}
182
Jani Nikula3d65a732017-04-06 16:44:14 +0300183int intel_dp_max_lane_count(struct intel_dp *intel_dp)
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300184{
185 return intel_dp->max_link_lane_count;
186}
187
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800188int
Keith Packardc8982612012-01-25 08:16:25 -0800189intel_dp_link_required(int pixel_clock, int bpp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700190{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800191 /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
192 return DIV_ROUND_UP(pixel_clock * bpp, 8);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700193}
194
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800195int
Dave Airliefe27d532010-06-30 11:46:17 +1000196intel_dp_max_data_rate(int max_link_clock, int max_lanes)
197{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800198 /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
199 * link rate that is generally expressed in Gbps. Since, 8 bits of data
200 * is transmitted every LS_Clk per lane, there is no need to account for
201 * the channel encoding that is done in the PHY layer here.
202 */
203
204 return max_link_clock * max_lanes;
Dave Airliefe27d532010-06-30 11:46:17 +1000205}
206
Mika Kahola70ec0642016-09-09 14:10:55 +0300207static int
208intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp)
209{
210 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
211 struct intel_encoder *encoder = &intel_dig_port->base;
212 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
213 int max_dotclk = dev_priv->max_dotclk_freq;
214 int ds_max_dotclk;
215
216 int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
217
218 if (type != DP_DS_PORT_TYPE_VGA)
219 return max_dotclk;
220
221 ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd,
222 intel_dp->downstream_ports);
223
224 if (ds_max_dotclk != 0)
225 max_dotclk = min(max_dotclk, ds_max_dotclk);
226
227 return max_dotclk;
228}
229
Jani Nikula55cfc582017-03-28 17:59:04 +0300230static void
231intel_dp_set_source_rates(struct intel_dp *intel_dp)
Navare, Manasi D40dba342016-10-26 16:25:55 -0700232{
233 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
234 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivid907b662017-08-10 15:40:08 -0700235 enum port port = dig_port->port;
Jani Nikula55cfc582017-03-28 17:59:04 +0300236 const int *source_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700237 int size;
Rodrigo Vivid907b662017-08-10 15:40:08 -0700238 u32 voltage;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700239
Jani Nikula55cfc582017-03-28 17:59:04 +0300240 /* This should only be done once */
241 WARN_ON(intel_dp->source_rates || intel_dp->num_source_rates);
242
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200243 if (IS_GEN9_LP(dev_priv)) {
Jani Nikula55cfc582017-03-28 17:59:04 +0300244 source_rates = bxt_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700245 size = ARRAY_SIZE(bxt_rates);
Rodrigo Vivid907b662017-08-10 15:40:08 -0700246 } else if (IS_CANNONLAKE(dev_priv)) {
247 source_rates = cnl_rates;
248 size = ARRAY_SIZE(cnl_rates);
249 voltage = I915_READ(CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK;
250 if (port == PORT_A || port == PORT_D ||
251 voltage == VOLTAGE_INFO_0_85V)
252 size -= 2;
Rodrigo Vivib976dc52017-01-23 10:32:37 -0800253 } else if (IS_GEN9_BC(dev_priv)) {
Jani Nikula55cfc582017-03-28 17:59:04 +0300254 source_rates = skl_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700255 size = ARRAY_SIZE(skl_rates);
256 } else {
Jani Nikula55cfc582017-03-28 17:59:04 +0300257 source_rates = default_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700258 size = ARRAY_SIZE(default_rates);
259 }
260
261 /* This depends on the fact that 5.4 is last value in the array */
262 if (!intel_dp_source_supports_hbr2(intel_dp))
263 size--;
264
Jani Nikula55cfc582017-03-28 17:59:04 +0300265 intel_dp->source_rates = source_rates;
266 intel_dp->num_source_rates = size;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700267}
268
269static int intersect_rates(const int *source_rates, int source_len,
270 const int *sink_rates, int sink_len,
271 int *common_rates)
272{
273 int i = 0, j = 0, k = 0;
274
275 while (i < source_len && j < sink_len) {
276 if (source_rates[i] == sink_rates[j]) {
277 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
278 return k;
279 common_rates[k] = source_rates[i];
280 ++k;
281 ++i;
282 ++j;
283 } else if (source_rates[i] < sink_rates[j]) {
284 ++i;
285 } else {
286 ++j;
287 }
288 }
289 return k;
290}
291
Jani Nikula8001b752017-03-28 17:59:03 +0300292/* return index of rate in rates array, or -1 if not found */
293static int intel_dp_rate_index(const int *rates, int len, int rate)
294{
295 int i;
296
297 for (i = 0; i < len; i++)
298 if (rate == rates[i])
299 return i;
300
301 return -1;
302}
303
Jani Nikula975ee5fca2017-04-06 16:44:10 +0300304static void intel_dp_set_common_rates(struct intel_dp *intel_dp)
Navare, Manasi D40dba342016-10-26 16:25:55 -0700305{
Jani Nikula975ee5fca2017-04-06 16:44:10 +0300306 WARN_ON(!intel_dp->num_source_rates || !intel_dp->num_sink_rates);
Navare, Manasi D40dba342016-10-26 16:25:55 -0700307
Jani Nikula975ee5fca2017-04-06 16:44:10 +0300308 intel_dp->num_common_rates = intersect_rates(intel_dp->source_rates,
309 intel_dp->num_source_rates,
310 intel_dp->sink_rates,
311 intel_dp->num_sink_rates,
312 intel_dp->common_rates);
313
314 /* Paranoia, there should always be something in common. */
315 if (WARN_ON(intel_dp->num_common_rates == 0)) {
316 intel_dp->common_rates[0] = default_rates[0];
317 intel_dp->num_common_rates = 1;
318 }
319}
320
321/* get length of common rates potentially limited by max_rate */
322static int intel_dp_common_len_rate_limit(struct intel_dp *intel_dp,
323 int max_rate)
324{
325 const int *common_rates = intel_dp->common_rates;
326 int i, common_len = intel_dp->num_common_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700327
Jani Nikula68f357c2017-03-28 17:59:05 +0300328 /* Limit results by potentially reduced max rate */
329 for (i = 0; i < common_len; i++) {
330 if (common_rates[common_len - i - 1] <= max_rate)
331 return common_len - i;
332 }
333
334 return 0;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700335}
336
Manasi Navare14c562c2017-04-06 14:00:12 -0700337static bool intel_dp_link_params_valid(struct intel_dp *intel_dp)
338{
339 /*
340 * FIXME: we need to synchronize the current link parameters with
341 * hardware readout. Currently fast link training doesn't work on
342 * boot-up.
343 */
344 if (intel_dp->link_rate == 0 ||
345 intel_dp->link_rate > intel_dp->max_link_rate)
346 return false;
347
348 if (intel_dp->lane_count == 0 ||
349 intel_dp->lane_count > intel_dp_max_lane_count(intel_dp))
350 return false;
351
352 return true;
353}
354
Manasi Navarefdb14d32016-12-08 19:05:12 -0800355int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
356 int link_rate, uint8_t lane_count)
357{
Jani Nikulab1810a72017-04-06 16:44:11 +0300358 int index;
Manasi Navarefdb14d32016-12-08 19:05:12 -0800359
Jani Nikulab1810a72017-04-06 16:44:11 +0300360 index = intel_dp_rate_index(intel_dp->common_rates,
361 intel_dp->num_common_rates,
362 link_rate);
363 if (index > 0) {
Jani Nikulae6c0c642017-04-06 16:44:12 +0300364 intel_dp->max_link_rate = intel_dp->common_rates[index - 1];
365 intel_dp->max_link_lane_count = lane_count;
Manasi Navarefdb14d32016-12-08 19:05:12 -0800366 } else if (lane_count > 1) {
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300367 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
Jani Nikulae6c0c642017-04-06 16:44:12 +0300368 intel_dp->max_link_lane_count = lane_count >> 1;
Manasi Navarefdb14d32016-12-08 19:05:12 -0800369 } else {
370 DRM_ERROR("Link Training Unsuccessful\n");
371 return -1;
372 }
373
374 return 0;
375}
376
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000377static enum drm_mode_status
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700378intel_dp_mode_valid(struct drm_connector *connector,
379 struct drm_display_mode *mode)
380{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100381 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300382 struct intel_connector *intel_connector = to_intel_connector(connector);
383 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Daniel Vetter36008362013-03-27 00:44:59 +0100384 int target_clock = mode->clock;
385 int max_rate, mode_rate, max_lanes, max_link_clock;
Mika Kahola70ec0642016-09-09 14:10:55 +0300386 int max_dotclk;
387
388 max_dotclk = intel_dp_downstream_max_dotclock(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700389
Jani Nikuladd06f902012-10-19 14:51:50 +0300390 if (is_edp(intel_dp) && fixed_mode) {
391 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100392 return MODE_PANEL;
393
Jani Nikuladd06f902012-10-19 14:51:50 +0300394 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100395 return MODE_PANEL;
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200396
397 target_clock = fixed_mode->clock;
Zhao Yakui7de56f42010-07-19 09:43:14 +0100398 }
399
Ville Syrjälä50fec212015-03-12 17:10:34 +0200400 max_link_clock = intel_dp_max_link_rate(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300401 max_lanes = intel_dp_max_lane_count(intel_dp);
Daniel Vetter36008362013-03-27 00:44:59 +0100402
403 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
404 mode_rate = intel_dp_link_required(target_clock, 18);
405
Mika Kahola799487f2016-02-02 15:16:38 +0200406 if (mode_rate > max_rate || target_clock > max_dotclk)
Daniel Vetterc4867932012-04-10 10:42:36 +0200407 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700408
409 if (mode->clock < 10000)
410 return MODE_CLOCK_LOW;
411
Daniel Vetter0af78a22012-05-23 11:30:55 +0200412 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
413 return MODE_H_ILLEGAL;
414
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700415 return MODE_OK;
416}
417
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800418uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700419{
420 int i;
421 uint32_t v = 0;
422
423 if (src_bytes > 4)
424 src_bytes = 4;
425 for (i = 0; i < src_bytes; i++)
426 v |= ((uint32_t) src[i]) << ((3-i) * 8);
427 return v;
428}
429
Damien Lespiauc2af70e2015-02-10 19:32:23 +0000430static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700431{
432 int i;
433 if (dst_bytes > 4)
434 dst_bytes = 4;
435 for (i = 0; i < dst_bytes; i++)
436 dst[i] = src >> ((3-i) * 8);
437}
438
Jani Nikulabf13e812013-09-06 07:40:05 +0300439static void
440intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300441 struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300442static void
443intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200444 struct intel_dp *intel_dp,
445 bool force_disable_vdd);
Imre Deak335f7522016-08-10 14:07:32 +0300446static void
447intel_dp_pps_init(struct drm_device *dev, struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300448
Ville Syrjälä773538e82014-09-04 14:54:56 +0300449static void pps_lock(struct intel_dp *intel_dp)
450{
451 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
452 struct intel_encoder *encoder = &intel_dig_port->base;
453 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100454 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300455
456 /*
457 * See vlv_power_sequencer_reset() why we need
458 * a power domain reference here.
459 */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +0200460 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300461
462 mutex_lock(&dev_priv->pps_mutex);
463}
464
465static void pps_unlock(struct intel_dp *intel_dp)
466{
467 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
468 struct intel_encoder *encoder = &intel_dig_port->base;
469 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100470 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300471
472 mutex_unlock(&dev_priv->pps_mutex);
473
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +0200474 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300475}
476
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300477static void
478vlv_power_sequencer_kick(struct intel_dp *intel_dp)
479{
480 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200481 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300482 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300483 bool pll_enabled, release_cl_override = false;
484 enum dpio_phy phy = DPIO_PHY(pipe);
485 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300486 uint32_t DP;
487
488 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
489 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
490 pipe_name(pipe), port_name(intel_dig_port->port)))
491 return;
492
493 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
494 pipe_name(pipe), port_name(intel_dig_port->port));
495
496 /* Preserve the BIOS-computed detected bit. This is
497 * supposed to be read-only.
498 */
499 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
500 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
501 DP |= DP_PORT_WIDTH(1);
502 DP |= DP_LINK_TRAIN_PAT_1;
503
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100504 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300505 DP |= DP_PIPE_SELECT_CHV(pipe);
506 else if (pipe == PIPE_B)
507 DP |= DP_PIPEB_SELECT;
508
Ville Syrjäläd288f652014-10-28 13:20:22 +0200509 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
510
511 /*
512 * The DPLL for the pipe must be enabled for this to work.
513 * So enable temporarily it if it's not already enabled.
514 */
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300515 if (!pll_enabled) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100516 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300517 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
518
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200519 if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ?
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000520 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
521 DRM_ERROR("Failed to force on pll for pipe %c!\n",
522 pipe_name(pipe));
523 return;
524 }
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300525 }
Ville Syrjäläd288f652014-10-28 13:20:22 +0200526
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300527 /*
528 * Similar magic as in intel_dp_enable_port().
529 * We _must_ do this port enable + disable trick
530 * to make this power seqeuencer lock onto the port.
531 * Otherwise even VDD force bit won't work.
532 */
533 I915_WRITE(intel_dp->output_reg, DP);
534 POSTING_READ(intel_dp->output_reg);
535
536 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
537 POSTING_READ(intel_dp->output_reg);
538
539 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
540 POSTING_READ(intel_dp->output_reg);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200541
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300542 if (!pll_enabled) {
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200543 vlv_force_pll_off(dev_priv, pipe);
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300544
545 if (release_cl_override)
546 chv_phy_powergate_ch(dev_priv, phy, ch, false);
547 }
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300548}
549
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200550static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv)
551{
552 struct intel_encoder *encoder;
553 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
554
555 /*
556 * We don't have power sequencer currently.
557 * Pick one that's not used by other ports.
558 */
559 for_each_intel_encoder(&dev_priv->drm, encoder) {
560 struct intel_dp *intel_dp;
561
562 if (encoder->type != INTEL_OUTPUT_DP &&
563 encoder->type != INTEL_OUTPUT_EDP)
564 continue;
565
566 intel_dp = enc_to_intel_dp(&encoder->base);
567
568 if (encoder->type == INTEL_OUTPUT_EDP) {
569 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
570 intel_dp->active_pipe != intel_dp->pps_pipe);
571
572 if (intel_dp->pps_pipe != INVALID_PIPE)
573 pipes &= ~(1 << intel_dp->pps_pipe);
574 } else {
575 WARN_ON(intel_dp->pps_pipe != INVALID_PIPE);
576
577 if (intel_dp->active_pipe != INVALID_PIPE)
578 pipes &= ~(1 << intel_dp->active_pipe);
579 }
580 }
581
582 if (pipes == 0)
583 return INVALID_PIPE;
584
585 return ffs(pipes) - 1;
586}
587
Jani Nikulabf13e812013-09-06 07:40:05 +0300588static enum pipe
589vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
590{
591 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300592 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100593 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300594 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300595
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300596 lockdep_assert_held(&dev_priv->pps_mutex);
597
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300598 /* We should never land here with regular DP ports */
599 WARN_ON(!is_edp(intel_dp));
600
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200601 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
602 intel_dp->active_pipe != intel_dp->pps_pipe);
603
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300604 if (intel_dp->pps_pipe != INVALID_PIPE)
605 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300606
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200607 pipe = vlv_find_free_pps(dev_priv);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300608
609 /*
610 * Didn't find one. This should not happen since there
611 * are two power sequencers and up to two eDP ports.
612 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200613 if (WARN_ON(pipe == INVALID_PIPE))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300614 pipe = PIPE_A;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300615
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300616 vlv_steal_power_sequencer(dev, pipe);
617 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300618
619 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
620 pipe_name(intel_dp->pps_pipe),
621 port_name(intel_dig_port->port));
622
623 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300624 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200625 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300626
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300627 /*
628 * Even vdd force doesn't work until we've made
629 * the power sequencer lock in on the port.
630 */
631 vlv_power_sequencer_kick(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300632
633 return intel_dp->pps_pipe;
634}
635
Imre Deak78597992016-06-16 16:37:20 +0300636static int
637bxt_power_sequencer_idx(struct intel_dp *intel_dp)
638{
639 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
640 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100641 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak78597992016-06-16 16:37:20 +0300642
643 lockdep_assert_held(&dev_priv->pps_mutex);
644
645 /* We should never land here with regular DP ports */
646 WARN_ON(!is_edp(intel_dp));
647
648 /*
649 * TODO: BXT has 2 PPS instances. The correct port->PPS instance
650 * mapping needs to be retrieved from VBT, for now just hard-code to
651 * use instance #0 always.
652 */
653 if (!intel_dp->pps_reset)
654 return 0;
655
656 intel_dp->pps_reset = false;
657
658 /*
659 * Only the HW needs to be reprogrammed, the SW state is fixed and
660 * has been setup during connector init.
661 */
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200662 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak78597992016-06-16 16:37:20 +0300663
664 return 0;
665}
666
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300667typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
668 enum pipe pipe);
669
670static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
671 enum pipe pipe)
672{
Imre Deak44cb7342016-08-10 14:07:29 +0300673 return I915_READ(PP_STATUS(pipe)) & PP_ON;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300674}
675
676static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
677 enum pipe pipe)
678{
Imre Deak44cb7342016-08-10 14:07:29 +0300679 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300680}
681
682static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
683 enum pipe pipe)
684{
685 return true;
686}
687
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300688static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300689vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
690 enum port port,
691 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300692{
Jani Nikulabf13e812013-09-06 07:40:05 +0300693 enum pipe pipe;
694
Jani Nikulabf13e812013-09-06 07:40:05 +0300695 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
Imre Deak44cb7342016-08-10 14:07:29 +0300696 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
Jani Nikulabf13e812013-09-06 07:40:05 +0300697 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300698
699 if (port_sel != PANEL_PORT_SELECT_VLV(port))
700 continue;
701
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300702 if (!pipe_check(dev_priv, pipe))
703 continue;
704
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300705 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300706 }
707
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300708 return INVALID_PIPE;
709}
710
711static void
712vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
713{
714 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
715 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100716 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300717 enum port port = intel_dig_port->port;
718
719 lockdep_assert_held(&dev_priv->pps_mutex);
720
721 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300722 /* first pick one where the panel is on */
723 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
724 vlv_pipe_has_pp_on);
725 /* didn't find one? pick one where vdd is on */
726 if (intel_dp->pps_pipe == INVALID_PIPE)
727 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
728 vlv_pipe_has_vdd_on);
729 /* didn't find one? pick one with just the correct port */
730 if (intel_dp->pps_pipe == INVALID_PIPE)
731 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
732 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300733
734 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
735 if (intel_dp->pps_pipe == INVALID_PIPE) {
736 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
737 port_name(port));
738 return;
739 }
740
741 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
742 port_name(port), pipe_name(intel_dp->pps_pipe));
743
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300744 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200745 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Jani Nikulabf13e812013-09-06 07:40:05 +0300746}
747
Imre Deak78597992016-06-16 16:37:20 +0300748void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300749{
Chris Wilson91c8a322016-07-05 10:40:23 +0100750 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300751 struct intel_encoder *encoder;
752
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100753 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200754 !IS_GEN9_LP(dev_priv)))
Ville Syrjälä773538e82014-09-04 14:54:56 +0300755 return;
756
757 /*
758 * We can't grab pps_mutex here due to deadlock with power_domain
759 * mutex when power_domain functions are called while holding pps_mutex.
760 * That also means that in order to use pps_pipe the code needs to
761 * hold both a power domain reference and pps_mutex, and the power domain
762 * reference get/put must be done while _not_ holding pps_mutex.
763 * pps_{lock,unlock}() do these steps in the correct order, so one
764 * should use them always.
765 */
766
Jani Nikula19c80542015-12-16 12:48:16 +0200767 for_each_intel_encoder(dev, encoder) {
Ville Syrjälä773538e82014-09-04 14:54:56 +0300768 struct intel_dp *intel_dp;
769
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200770 if (encoder->type != INTEL_OUTPUT_DP &&
771 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300772 continue;
773
774 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200775
776 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
777
778 if (encoder->type != INTEL_OUTPUT_EDP)
779 continue;
780
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200781 if (IS_GEN9_LP(dev_priv))
Imre Deak78597992016-06-16 16:37:20 +0300782 intel_dp->pps_reset = true;
783 else
784 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300785 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300786}
787
Imre Deak8e8232d2016-06-16 16:37:21 +0300788struct pps_registers {
789 i915_reg_t pp_ctrl;
790 i915_reg_t pp_stat;
791 i915_reg_t pp_on;
792 i915_reg_t pp_off;
793 i915_reg_t pp_div;
794};
795
796static void intel_pps_get_registers(struct drm_i915_private *dev_priv,
797 struct intel_dp *intel_dp,
798 struct pps_registers *regs)
799{
Imre Deak44cb7342016-08-10 14:07:29 +0300800 int pps_idx = 0;
801
Imre Deak8e8232d2016-06-16 16:37:21 +0300802 memset(regs, 0, sizeof(*regs));
803
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200804 if (IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300805 pps_idx = bxt_power_sequencer_idx(intel_dp);
806 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
807 pps_idx = vlv_power_sequencer_pipe(intel_dp);
Imre Deak8e8232d2016-06-16 16:37:21 +0300808
Imre Deak44cb7342016-08-10 14:07:29 +0300809 regs->pp_ctrl = PP_CONTROL(pps_idx);
810 regs->pp_stat = PP_STATUS(pps_idx);
811 regs->pp_on = PP_ON_DELAYS(pps_idx);
812 regs->pp_off = PP_OFF_DELAYS(pps_idx);
Rodrigo Vivi938361e2017-06-02 13:06:44 -0700813 if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300814 regs->pp_div = PP_DIVISOR(pps_idx);
Imre Deak8e8232d2016-06-16 16:37:21 +0300815}
816
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200817static i915_reg_t
818_pp_ctrl_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300819{
Imre Deak8e8232d2016-06-16 16:37:21 +0300820 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300821
Imre Deak8e8232d2016-06-16 16:37:21 +0300822 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
823 &regs);
824
825 return regs.pp_ctrl;
Jani Nikulabf13e812013-09-06 07:40:05 +0300826}
827
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200828static i915_reg_t
829_pp_stat_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300830{
Imre Deak8e8232d2016-06-16 16:37:21 +0300831 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300832
Imre Deak8e8232d2016-06-16 16:37:21 +0300833 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
834 &regs);
835
836 return regs.pp_stat;
Jani Nikulabf13e812013-09-06 07:40:05 +0300837}
838
Clint Taylor01527b32014-07-07 13:01:46 -0700839/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
840 This function only applicable when panel PM state is not to be tracked */
841static int edp_notify_handler(struct notifier_block *this, unsigned long code,
842 void *unused)
843{
844 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
845 edp_notifier);
846 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100847 struct drm_i915_private *dev_priv = to_i915(dev);
Clint Taylor01527b32014-07-07 13:01:46 -0700848
849 if (!is_edp(intel_dp) || code != SYS_RESTART)
850 return 0;
851
Ville Syrjälä773538e82014-09-04 14:54:56 +0300852 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300853
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100854 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300855 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200856 i915_reg_t pp_ctrl_reg, pp_div_reg;
Ville Syrjälä649636e2015-09-22 19:50:01 +0300857 u32 pp_div;
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300858
Imre Deak44cb7342016-08-10 14:07:29 +0300859 pp_ctrl_reg = PP_CONTROL(pipe);
860 pp_div_reg = PP_DIVISOR(pipe);
Clint Taylor01527b32014-07-07 13:01:46 -0700861 pp_div = I915_READ(pp_div_reg);
862 pp_div &= PP_REFERENCE_DIVIDER_MASK;
863
864 /* 0x1F write to PP_DIV_REG sets max cycle delay */
865 I915_WRITE(pp_div_reg, pp_div | 0x1F);
866 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
867 msleep(intel_dp->panel_power_cycle_delay);
868 }
869
Ville Syrjälä773538e82014-09-04 14:54:56 +0300870 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300871
Clint Taylor01527b32014-07-07 13:01:46 -0700872 return 0;
873}
874
Daniel Vetter4be73782014-01-17 14:39:48 +0100875static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700876{
Paulo Zanoni30add222012-10-26 19:05:45 -0200877 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100878 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700879
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300880 lockdep_assert_held(&dev_priv->pps_mutex);
881
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100882 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300883 intel_dp->pps_pipe == INVALID_PIPE)
884 return false;
885
Jani Nikulabf13e812013-09-06 07:40:05 +0300886 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700887}
888
Daniel Vetter4be73782014-01-17 14:39:48 +0100889static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700890{
Paulo Zanoni30add222012-10-26 19:05:45 -0200891 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100892 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700893
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300894 lockdep_assert_held(&dev_priv->pps_mutex);
895
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100896 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300897 intel_dp->pps_pipe == INVALID_PIPE)
898 return false;
899
Ville Syrjälä773538e82014-09-04 14:54:56 +0300900 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700901}
902
Keith Packard9b984da2011-09-19 13:54:47 -0700903static void
904intel_dp_check_edp(struct intel_dp *intel_dp)
905{
Paulo Zanoni30add222012-10-26 19:05:45 -0200906 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100907 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700908
Keith Packard9b984da2011-09-19 13:54:47 -0700909 if (!is_edp(intel_dp))
910 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700911
Daniel Vetter4be73782014-01-17 14:39:48 +0100912 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700913 WARN(1, "eDP powered off while attempting aux channel communication.\n");
914 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300915 I915_READ(_pp_stat_reg(intel_dp)),
916 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700917 }
918}
919
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100920static uint32_t
921intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
922{
923 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
924 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100925 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200926 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100927 uint32_t status;
928 bool done;
929
Daniel Vetteref04f002012-12-01 21:03:59 +0100930#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100931 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300932 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300933 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100934 else
Imre Deak713a6b662016-06-28 13:37:33 +0300935 done = wait_for(C, 10) == 0;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100936 if (!done)
937 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
938 has_aux_irq);
939#undef C
940
941 return status;
942}
943
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200944static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000945{
946 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200947 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000948
Ville Syrjäläa457f542016-03-02 17:22:17 +0200949 if (index)
950 return 0;
951
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000952 /*
953 * The clock divider is based off the hrawclk, and would like to run at
Ville Syrjäläa457f542016-03-02 17:22:17 +0200954 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000955 */
Ville Syrjäläa457f542016-03-02 17:22:17 +0200956 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000957}
958
959static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
960{
961 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200962 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000963
964 if (index)
965 return 0;
966
Ville Syrjäläa457f542016-03-02 17:22:17 +0200967 /*
968 * The clock divider is based off the cdclk or PCH rawclk, and would
969 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
970 * divide by 2000 and use that
971 */
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200972 if (intel_dig_port->port == PORT_A)
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200973 return DIV_ROUND_CLOSEST(dev_priv->cdclk.hw.cdclk, 2000);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200974 else
975 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000976}
977
978static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300979{
980 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200981 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300982
Ville Syrjäläa457f542016-03-02 17:22:17 +0200983 if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300984 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100985 switch (index) {
986 case 0: return 63;
987 case 1: return 72;
988 default: return 0;
989 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300990 }
Ville Syrjäläa457f542016-03-02 17:22:17 +0200991
992 return ilk_get_aux_clock_divider(intel_dp, index);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300993}
994
Damien Lespiaub6b5e382014-01-20 16:00:59 +0000995static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
996{
997 /*
998 * SKL doesn't need us to program the AUX clock divider (Hardware will
999 * derive the clock from CDCLK automatically). We still implement the
1000 * get_aux_clock_divider vfunc to plug-in into the existing code.
1001 */
1002 return index ? 0 : 1;
1003}
1004
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02001005static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
1006 bool has_aux_irq,
1007 int send_bytes,
1008 uint32_t aux_clock_divider)
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001009{
1010 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin86527442016-10-13 11:03:00 +01001011 struct drm_i915_private *dev_priv =
1012 to_i915(intel_dig_port->base.base.dev);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001013 uint32_t precharge, timeout;
1014
Tvrtko Ursulin86527442016-10-13 11:03:00 +01001015 if (IS_GEN6(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001016 precharge = 3;
1017 else
1018 precharge = 5;
1019
Tvrtko Ursulin86527442016-10-13 11:03:00 +01001020 if (IS_BROADWELL(dev_priv) && intel_dig_port->port == PORT_A)
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001021 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
1022 else
1023 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
1024
1025 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +00001026 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001027 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +00001028 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001029 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +00001030 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001031 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
1032 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +00001033 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001034}
1035
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00001036static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
1037 bool has_aux_irq,
1038 int send_bytes,
1039 uint32_t unused)
1040{
1041 return DP_AUX_CH_CTL_SEND_BUSY |
1042 DP_AUX_CH_CTL_DONE |
1043 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
1044 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1045 DP_AUX_CH_CTL_TIME_OUT_1600us |
1046 DP_AUX_CH_CTL_RECEIVE_ERROR |
1047 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Daniel Vetterd4dcbdc2016-05-18 18:47:15 +02001048 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00001049 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
1050}
1051
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001052static int
Chris Wilsonea5b2132010-08-04 13:50:23 +01001053intel_dp_aux_ch(struct intel_dp *intel_dp,
Daniel Vetterbd9f74a2014-10-02 09:45:35 +02001054 const uint8_t *send, int send_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001055 uint8_t *recv, int recv_size)
1056{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001057 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001058 struct drm_i915_private *dev_priv =
1059 to_i915(intel_dig_port->base.base.dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001060 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Chris Wilsonbc866252013-07-21 16:00:03 +01001061 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001062 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001063 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001064 int try, clock = 0;
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001065 bool has_aux_irq = HAS_AUX_IRQ(dev_priv);
Jani Nikula884f19e2014-03-14 16:51:14 +02001066 bool vdd;
1067
Ville Syrjälä773538e82014-09-04 14:54:56 +03001068 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001069
Ville Syrjälä72c35002014-08-18 22:16:00 +03001070 /*
1071 * We will be called with VDD already enabled for dpcd/edid/oui reads.
1072 * In such cases we want to leave VDD enabled and it's up to upper layers
1073 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
1074 * ourselves.
1075 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001076 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001077
1078 /* dp aux is extremely sensitive to irq latency, hence request the
1079 * lowest possible wakeup latency and so prevent the cpu from going into
1080 * deep sleep states.
1081 */
1082 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001083
Keith Packard9b984da2011-09-19 13:54:47 -07001084 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001085
Jesse Barnes11bee432011-08-01 15:02:20 -07001086 /* Try to wait for any previous AUX channel activity */
1087 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +01001088 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -07001089 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
1090 break;
1091 msleep(1);
1092 }
1093
1094 if (try == 3) {
Mika Kuoppala02196c72015-08-06 16:48:58 +03001095 static u32 last_status = -1;
1096 const u32 status = I915_READ(ch_ctl);
1097
1098 if (status != last_status) {
1099 WARN(1, "dp_aux_ch not started status 0x%08x\n",
1100 status);
1101 last_status = status;
1102 }
1103
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001104 ret = -EBUSY;
1105 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001106 }
1107
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001108 /* Only 5 data registers! */
1109 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
1110 ret = -E2BIG;
1111 goto out;
1112 }
1113
Damien Lespiauec5b01d2014-01-21 13:35:39 +00001114 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +00001115 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
1116 has_aux_irq,
1117 send_bytes,
1118 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001119
Chris Wilsonbc866252013-07-21 16:00:03 +01001120 /* Must try at least 3 times according to DP spec */
1121 for (try = 0; try < 5; try++) {
1122 /* Load the send data into the aux channel data registers */
1123 for (i = 0; i < send_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001124 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001125 intel_dp_pack_aux(send + i,
1126 send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -04001127
Chris Wilsonbc866252013-07-21 16:00:03 +01001128 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001129 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001130
Chris Wilsonbc866252013-07-21 16:00:03 +01001131 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -04001132
Chris Wilsonbc866252013-07-21 16:00:03 +01001133 /* Clear done status and any errors */
1134 I915_WRITE(ch_ctl,
1135 status |
1136 DP_AUX_CH_CTL_DONE |
1137 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1138 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -04001139
Todd Previte74ebf292015-04-15 08:38:41 -07001140 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
Chris Wilsonbc866252013-07-21 16:00:03 +01001141 continue;
Todd Previte74ebf292015-04-15 08:38:41 -07001142
1143 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
1144 * 400us delay required for errors and timeouts
1145 * Timeout errors from the HW already meet this
1146 * requirement so skip to next iteration
1147 */
1148 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1149 usleep_range(400, 500);
1150 continue;
1151 }
Chris Wilsonbc866252013-07-21 16:00:03 +01001152 if (status & DP_AUX_CH_CTL_DONE)
Jim Bridee058c942015-05-27 10:21:48 -07001153 goto done;
Chris Wilsonbc866252013-07-21 16:00:03 +01001154 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001155 }
1156
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001157 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001158 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001159 ret = -EBUSY;
1160 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001161 }
1162
Jim Bridee058c942015-05-27 10:21:48 -07001163done:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001164 /* Check for timeout or receive error.
1165 * Timeouts occur when the sink is not connected
1166 */
Keith Packarda5b3da52009-06-11 22:30:32 -07001167 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001168 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001169 ret = -EIO;
1170 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -07001171 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001172
1173 /* Timeouts occur when the device isn't connected, so they're
1174 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -07001175 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Chris Wilsona5570fe2017-02-23 11:51:02 +00001176 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001177 ret = -ETIMEDOUT;
1178 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001179 }
1180
1181 /* Unload any bytes sent back from the other side */
1182 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
1183 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Rodrigo Vivi14e01882015-12-10 11:12:27 -08001184
1185 /*
1186 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1187 * We have no idea of what happened so we return -EBUSY so
1188 * drm layer takes care for the necessary retries.
1189 */
1190 if (recv_bytes == 0 || recv_bytes > 20) {
1191 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1192 recv_bytes);
1193 /*
1194 * FIXME: This patch was created on top of a series that
1195 * organize the retries at drm level. There EBUSY should
1196 * also take care for 1ms wait before retrying.
1197 * That aux retries re-org is still needed and after that is
1198 * merged we remove this sleep from here.
1199 */
1200 usleep_range(1000, 1500);
1201 ret = -EBUSY;
1202 goto out;
1203 }
1204
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001205 if (recv_bytes > recv_size)
1206 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -04001207
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001208 for (i = 0; i < recv_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001209 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001210 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001211
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001212 ret = recv_bytes;
1213out:
1214 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1215
Jani Nikula884f19e2014-03-14 16:51:14 +02001216 if (vdd)
1217 edp_panel_vdd_off(intel_dp, false);
1218
Ville Syrjälä773538e82014-09-04 14:54:56 +03001219 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001220
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001221 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001222}
1223
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001224#define BARE_ADDRESS_SIZE 3
1225#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +02001226static ssize_t
1227intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001228{
Jani Nikula9d1a1032014-03-14 16:51:15 +02001229 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1230 uint8_t txbuf[20], rxbuf[20];
1231 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001232 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001233
Ville Syrjäläd2d9cbb2015-03-19 11:44:06 +02001234 txbuf[0] = (msg->request << 4) |
1235 ((msg->address >> 16) & 0xf);
1236 txbuf[1] = (msg->address >> 8) & 0xff;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001237 txbuf[2] = msg->address & 0xff;
1238 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001239
Jani Nikula9d1a1032014-03-14 16:51:15 +02001240 switch (msg->request & ~DP_AUX_I2C_MOT) {
1241 case DP_AUX_NATIVE_WRITE:
1242 case DP_AUX_I2C_WRITE:
Ville Syrjäläc1e741222015-08-27 17:23:27 +03001243 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001244 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001245 rxsize = 2; /* 0 or 1 data bytes */
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001246
Jani Nikula9d1a1032014-03-14 16:51:15 +02001247 if (WARN_ON(txsize > 20))
1248 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001249
Ville Syrjälädd788092016-07-28 17:55:04 +03001250 WARN_ON(!msg->buffer != !msg->size);
1251
Imre Deakd81a67c2016-01-29 14:52:26 +02001252 if (msg->buffer)
1253 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001254
Jani Nikula9d1a1032014-03-14 16:51:15 +02001255 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1256 if (ret > 0) {
1257 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001258
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001259 if (ret > 1) {
1260 /* Number of bytes written in a short write. */
1261 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1262 } else {
1263 /* Return payload size. */
1264 ret = msg->size;
1265 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001266 }
Jani Nikula9d1a1032014-03-14 16:51:15 +02001267 break;
1268
1269 case DP_AUX_NATIVE_READ:
1270 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001271 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001272 rxsize = msg->size + 1;
1273
1274 if (WARN_ON(rxsize > 20))
1275 return -E2BIG;
1276
1277 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1278 if (ret > 0) {
1279 msg->reply = rxbuf[0] >> 4;
1280 /*
1281 * Assume happy day, and copy the data. The caller is
1282 * expected to check msg->reply before touching it.
1283 *
1284 * Return payload size.
1285 */
1286 ret--;
1287 memcpy(msg->buffer, rxbuf + 1, ret);
1288 }
1289 break;
1290
1291 default:
1292 ret = -EINVAL;
1293 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001294 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001295
Jani Nikula9d1a1032014-03-14 16:51:15 +02001296 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001297}
1298
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001299static enum port intel_aux_port(struct drm_i915_private *dev_priv,
1300 enum port port)
1301{
1302 const struct ddi_vbt_port_info *info =
1303 &dev_priv->vbt.ddi_port_info[port];
1304 enum port aux_port;
1305
1306 if (!info->alternate_aux_channel) {
1307 DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
1308 port_name(port), port_name(port));
1309 return port;
1310 }
1311
1312 switch (info->alternate_aux_channel) {
1313 case DP_AUX_A:
1314 aux_port = PORT_A;
1315 break;
1316 case DP_AUX_B:
1317 aux_port = PORT_B;
1318 break;
1319 case DP_AUX_C:
1320 aux_port = PORT_C;
1321 break;
1322 case DP_AUX_D:
1323 aux_port = PORT_D;
1324 break;
1325 default:
1326 MISSING_CASE(info->alternate_aux_channel);
1327 aux_port = PORT_A;
1328 break;
1329 }
1330
1331 DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
1332 port_name(aux_port), port_name(port));
1333
1334 return aux_port;
1335}
1336
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001337static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001338 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001339{
1340 switch (port) {
1341 case PORT_B:
1342 case PORT_C:
1343 case PORT_D:
1344 return DP_AUX_CH_CTL(port);
1345 default:
1346 MISSING_CASE(port);
1347 return DP_AUX_CH_CTL(PORT_B);
1348 }
1349}
1350
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001351static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001352 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001353{
1354 switch (port) {
1355 case PORT_B:
1356 case PORT_C:
1357 case PORT_D:
1358 return DP_AUX_CH_DATA(port, index);
1359 default:
1360 MISSING_CASE(port);
1361 return DP_AUX_CH_DATA(PORT_B, index);
1362 }
1363}
1364
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001365static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001366 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001367{
1368 switch (port) {
1369 case PORT_A:
1370 return DP_AUX_CH_CTL(port);
1371 case PORT_B:
1372 case PORT_C:
1373 case PORT_D:
1374 return PCH_DP_AUX_CH_CTL(port);
1375 default:
1376 MISSING_CASE(port);
1377 return DP_AUX_CH_CTL(PORT_A);
1378 }
1379}
1380
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001381static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001382 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001383{
1384 switch (port) {
1385 case PORT_A:
1386 return DP_AUX_CH_DATA(port, index);
1387 case PORT_B:
1388 case PORT_C:
1389 case PORT_D:
1390 return PCH_DP_AUX_CH_DATA(port, index);
1391 default:
1392 MISSING_CASE(port);
1393 return DP_AUX_CH_DATA(PORT_A, index);
1394 }
1395}
1396
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001397static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001398 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001399{
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001400 switch (port) {
1401 case PORT_A:
1402 case PORT_B:
1403 case PORT_C:
1404 case PORT_D:
1405 return DP_AUX_CH_CTL(port);
1406 default:
1407 MISSING_CASE(port);
1408 return DP_AUX_CH_CTL(PORT_A);
1409 }
1410}
1411
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001412static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001413 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001414{
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001415 switch (port) {
1416 case PORT_A:
1417 case PORT_B:
1418 case PORT_C:
1419 case PORT_D:
1420 return DP_AUX_CH_DATA(port, index);
1421 default:
1422 MISSING_CASE(port);
1423 return DP_AUX_CH_DATA(PORT_A, index);
1424 }
1425}
1426
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001427static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001428 enum port port)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001429{
1430 if (INTEL_INFO(dev_priv)->gen >= 9)
1431 return skl_aux_ctl_reg(dev_priv, port);
1432 else if (HAS_PCH_SPLIT(dev_priv))
1433 return ilk_aux_ctl_reg(dev_priv, port);
1434 else
1435 return g4x_aux_ctl_reg(dev_priv, port);
1436}
1437
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001438static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001439 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001440{
1441 if (INTEL_INFO(dev_priv)->gen >= 9)
1442 return skl_aux_data_reg(dev_priv, port, index);
1443 else if (HAS_PCH_SPLIT(dev_priv))
1444 return ilk_aux_data_reg(dev_priv, port, index);
1445 else
1446 return g4x_aux_data_reg(dev_priv, port, index);
1447}
1448
1449static void intel_aux_reg_init(struct intel_dp *intel_dp)
1450{
1451 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001452 enum port port = intel_aux_port(dev_priv,
1453 dp_to_dig_port(intel_dp)->port);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001454 int i;
1455
1456 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1457 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1458 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1459}
1460
Jani Nikula9d1a1032014-03-14 16:51:15 +02001461static void
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001462intel_dp_aux_fini(struct intel_dp *intel_dp)
1463{
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001464 kfree(intel_dp->aux.name);
1465}
1466
Chris Wilson7a418e32016-06-24 14:00:14 +01001467static void
Mika Kaholab6339582016-09-09 14:10:52 +03001468intel_dp_aux_init(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001469{
Jani Nikula33ad6622014-03-14 16:51:16 +02001470 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1471 enum port port = intel_dig_port->port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001472
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001473 intel_aux_reg_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01001474 drm_dp_aux_init(&intel_dp->aux);
David Flynn8316f332010-12-08 16:10:21 +00001475
Chris Wilson7a418e32016-06-24 14:00:14 +01001476 /* Failure to allocate our preferred name is not critical */
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001477 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
Jani Nikula9d1a1032014-03-14 16:51:15 +02001478 intel_dp->aux.transfer = intel_dp_aux_transfer;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001479}
1480
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001481bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301482{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001483 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Navare, Manasi D577c5432016-09-27 16:36:53 -07001484 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001485
Navare, Manasi D577c5432016-09-27 16:36:53 -07001486 if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
1487 IS_BROADWELL(dev_priv) || (INTEL_GEN(dev_priv) >= 9))
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301488 return true;
1489 else
1490 return false;
1491}
1492
Daniel Vetter0e503382014-07-04 11:26:04 -03001493static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001494intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001495 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001496{
1497 struct drm_device *dev = encoder->base.dev;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001498 struct drm_i915_private *dev_priv = to_i915(dev);
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001499 const struct dp_link_dpll *divisor = NULL;
1500 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001501
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001502 if (IS_G4X(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001503 divisor = gen4_dpll;
1504 count = ARRAY_SIZE(gen4_dpll);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001505 } else if (HAS_PCH_SPLIT(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001506 divisor = pch_dpll;
1507 count = ARRAY_SIZE(pch_dpll);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001508 } else if (IS_CHERRYVIEW(dev_priv)) {
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001509 divisor = chv_dpll;
1510 count = ARRAY_SIZE(chv_dpll);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001511 } else if (IS_VALLEYVIEW(dev_priv)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001512 divisor = vlv_dpll;
1513 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001514 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001515
1516 if (divisor && count) {
1517 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001518 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001519 pipe_config->dpll = divisor[i].dpll;
1520 pipe_config->clock_set = true;
1521 break;
1522 }
1523 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001524 }
1525}
1526
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001527static void snprintf_int_array(char *str, size_t len,
1528 const int *array, int nelem)
1529{
1530 int i;
1531
1532 str[0] = '\0';
1533
1534 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001535 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001536 if (r >= len)
1537 return;
1538 str += r;
1539 len -= r;
1540 }
1541}
1542
1543static void intel_dp_print_rates(struct intel_dp *intel_dp)
1544{
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001545 char str[128]; /* FIXME: too big for stack? */
1546
1547 if ((drm_debug & DRM_UT_KMS) == 0)
1548 return;
1549
Jani Nikula55cfc582017-03-28 17:59:04 +03001550 snprintf_int_array(str, sizeof(str),
1551 intel_dp->source_rates, intel_dp->num_source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001552 DRM_DEBUG_KMS("source rates: %s\n", str);
1553
Jani Nikula68f357c2017-03-28 17:59:05 +03001554 snprintf_int_array(str, sizeof(str),
1555 intel_dp->sink_rates, intel_dp->num_sink_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001556 DRM_DEBUG_KMS("sink rates: %s\n", str);
1557
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001558 snprintf_int_array(str, sizeof(str),
1559 intel_dp->common_rates, intel_dp->num_common_rates);
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001560 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001561}
1562
Ville Syrjälä50fec212015-03-12 17:10:34 +02001563int
1564intel_dp_max_link_rate(struct intel_dp *intel_dp)
1565{
Ville Syrjälä50fec212015-03-12 17:10:34 +02001566 int len;
1567
Jani Nikulae6c0c642017-04-06 16:44:12 +03001568 len = intel_dp_common_len_rate_limit(intel_dp, intel_dp->max_link_rate);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001569 if (WARN_ON(len <= 0))
1570 return 162000;
1571
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001572 return intel_dp->common_rates[len - 1];
Ville Syrjälä50fec212015-03-12 17:10:34 +02001573}
1574
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001575int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1576{
Jani Nikula8001b752017-03-28 17:59:03 +03001577 int i = intel_dp_rate_index(intel_dp->sink_rates,
1578 intel_dp->num_sink_rates, rate);
Jani Nikulab5c72b22017-03-28 17:59:02 +03001579
1580 if (WARN_ON(i < 0))
1581 i = 0;
1582
1583 return i;
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001584}
1585
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001586void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1587 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001588{
Jani Nikula68f357c2017-03-28 17:59:05 +03001589 /* eDP 1.4 rate select method. */
1590 if (intel_dp->use_rate_select) {
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001591 *link_bw = 0;
1592 *rate_select =
1593 intel_dp_rate_select(intel_dp, port_clock);
1594 } else {
1595 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1596 *rate_select = 0;
1597 }
1598}
1599
Jani Nikulaf580bea2016-09-15 16:28:52 +03001600static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1601 struct intel_crtc_state *pipe_config)
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001602{
1603 int bpp, bpc;
1604
1605 bpp = pipe_config->pipe_bpp;
1606 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1607
1608 if (bpc > 0)
1609 bpp = min(bpp, 3*bpc);
1610
Manasi Navare611032b2017-01-24 08:21:49 -08001611 /* For DP Compliance we override the computed bpp for the pipe */
1612 if (intel_dp->compliance.test_data.bpc != 0) {
1613 pipe_config->pipe_bpp = 3*intel_dp->compliance.test_data.bpc;
1614 pipe_config->dither_force_disable = pipe_config->pipe_bpp == 6*3;
1615 DRM_DEBUG_KMS("Setting pipe_bpp to %d\n",
1616 pipe_config->pipe_bpp);
1617 }
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001618 return bpp;
1619}
1620
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001621bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001622intel_dp_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001623 struct intel_crtc_state *pipe_config,
1624 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001625{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001626 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001627 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001628 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001629 enum port port = dp_to_dig_port(intel_dp)->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001630 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001631 struct intel_connector *intel_connector = intel_dp->attached_connector;
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001632 struct intel_digital_connector_state *intel_conn_state =
1633 to_intel_digital_connector_state(conn_state);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001634 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001635 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001636 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001637 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001638 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301639 int max_clock;
Daniel Vetter083f9562012-04-20 20:23:49 +02001640 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001641 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001642 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001643 uint8_t link_bw, rate_select;
Jani Nikulab31e85e2017-05-18 14:10:25 +03001644 bool reduce_m_n = drm_dp_has_quirk(&intel_dp->desc,
1645 DP_DPCD_QUIRK_LIMITED_M_N);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301646
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001647 common_len = intel_dp_common_len_rate_limit(intel_dp,
Jani Nikulae6c0c642017-04-06 16:44:12 +03001648 intel_dp->max_link_rate);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301649
1650 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001651 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301652
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001653 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001654
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001655 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001656 pipe_config->has_pch_encoder = true;
1657
Vandana Kannanf769cd22014-08-05 07:51:22 -07001658 pipe_config->has_drrs = false;
Maarten Lankhorste6b72c92017-05-01 15:38:00 +02001659 if (port == PORT_A)
1660 pipe_config->has_audio = false;
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001661 else if (intel_conn_state->force_audio == HDMI_AUDIO_AUTO)
Maarten Lankhorste6b72c92017-05-01 15:38:00 +02001662 pipe_config->has_audio = intel_dp->has_audio;
1663 else
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001664 pipe_config->has_audio = intel_conn_state->force_audio == HDMI_AUDIO_ON;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001665
Jani Nikuladd06f902012-10-19 14:51:50 +03001666 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1667 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
1668 adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001669
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001670 if (INTEL_GEN(dev_priv) >= 9) {
Chandra Kondurua1b22782015-04-07 15:28:45 -07001671 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001672 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001673 if (ret)
1674 return ret;
1675 }
1676
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001677 if (HAS_GMCH_DISPLAY(dev_priv))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001678 intel_gmch_panel_fitting(intel_crtc, pipe_config,
Maarten Lankhorsteead06d2017-05-01 15:37:55 +02001679 conn_state->scaling_mode);
Jesse Barnes2dd24552013-04-25 12:55:01 -07001680 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001681 intel_pch_panel_fitting(intel_crtc, pipe_config,
Maarten Lankhorsteead06d2017-05-01 15:37:55 +02001682 conn_state->scaling_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001683 }
1684
Daniel Vettercb1793c2012-06-04 18:39:21 +02001685 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001686 return false;
1687
Manasi Navareda15f7c2017-01-24 08:16:34 -08001688 /* Use values requested by Compliance Test Request */
1689 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
Jani Nikulaec990e22017-04-06 16:44:15 +03001690 int index;
1691
1692 index = intel_dp_rate_index(intel_dp->common_rates,
1693 intel_dp->num_common_rates,
1694 intel_dp->compliance.test_link_rate);
1695 if (index >= 0)
1696 min_clock = max_clock = index;
Manasi Navareda15f7c2017-01-24 08:16:34 -08001697 min_lane_count = max_lane_count = intel_dp->compliance.test_lane_count;
1698 }
Daniel Vetter083f9562012-04-20 20:23:49 +02001699 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301700 "max bw %d pixel clock %iKHz\n",
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001701 max_lane_count, intel_dp->common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001702 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001703
Daniel Vetter36008362013-03-27 00:44:59 +01001704 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1705 * bpc in between. */
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001706 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
Jani Nikula56071a22014-05-06 14:56:52 +03001707 if (is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301708
1709 /* Get bpp from vbt only for panels that dont have bpp in edid */
1710 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001711 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001712 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001713 dev_priv->vbt.edp.bpp);
1714 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001715 }
1716
Jani Nikula344c5bb2014-09-09 11:25:13 +03001717 /*
1718 * Use the maximum clock and number of lanes the eDP panel
1719 * advertizes being capable of. The panels are generally
1720 * designed to support only a single clock and lane
1721 * configuration, and typically these values correspond to the
1722 * native resolution of the panel.
1723 */
1724 min_lane_count = max_lane_count;
1725 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001726 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001727
Daniel Vetter36008362013-03-27 00:44:59 +01001728 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001729 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1730 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001731
Dave Airliec6930992014-07-14 11:04:39 +10001732 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301733 for (lane_count = min_lane_count;
1734 lane_count <= max_lane_count;
1735 lane_count <<= 1) {
1736
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001737 link_clock = intel_dp->common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001738 link_avail = intel_dp_max_data_rate(link_clock,
1739 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001740
Daniel Vetter36008362013-03-27 00:44:59 +01001741 if (mode_rate <= link_avail) {
1742 goto found;
1743 }
1744 }
1745 }
1746 }
1747
1748 return false;
1749
1750found:
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001751 if (intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_AUTO) {
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001752 /*
1753 * See:
1754 * CEA-861-E - 5.1 Default Encoding Parameters
1755 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1756 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001757 pipe_config->limited_color_range =
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02001758 bpp != 18 &&
1759 drm_default_rgb_quant_range(adjusted_mode) ==
1760 HDMI_QUANTIZATION_RANGE_LIMITED;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001761 } else {
1762 pipe_config->limited_color_range =
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001763 intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_LIMITED;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001764 }
1765
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001766 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301767
Daniel Vetter657445f2013-05-04 10:09:18 +02001768 pipe_config->pipe_bpp = bpp;
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001769 pipe_config->port_clock = intel_dp->common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001770
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001771 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1772 &link_bw, &rate_select);
1773
1774 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1775 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001776 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001777 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1778 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001779
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001780 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001781 adjusted_mode->crtc_clock,
1782 pipe_config->port_clock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03001783 &pipe_config->dp_m_n,
1784 reduce_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001785
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301786 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301787 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001788 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301789 intel_link_compute_m_n(bpp, lane_count,
1790 intel_connector->panel.downclock_mode->clock,
1791 pipe_config->port_clock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03001792 &pipe_config->dp_m2_n2,
1793 reduce_m_n);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301794 }
1795
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001796 /*
1797 * DPLL0 VCO may need to be adjusted to get the correct
1798 * clock for eDP. This will affect cdclk as well.
1799 */
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001800 if (is_edp(intel_dp) && IS_GEN9_BC(dev_priv)) {
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001801 int vco;
1802
1803 switch (pipe_config->port_clock / 2) {
1804 case 108000:
1805 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001806 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001807 break;
1808 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001809 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001810 break;
1811 }
1812
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +02001813 to_intel_atomic_state(pipe_config->base.state)->cdclk.logical.vco = vco;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001814 }
1815
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001816 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001817 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001818
Daniel Vetter36008362013-03-27 00:44:59 +01001819 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001820}
1821
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001822void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001823 int link_rate, uint8_t lane_count,
1824 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001825{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001826 intel_dp->link_rate = link_rate;
1827 intel_dp->lane_count = lane_count;
1828 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001829}
1830
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001831static void intel_dp_prepare(struct intel_encoder *encoder,
1832 struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001833{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001834 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001835 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001836 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001837 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001838 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001839 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001840
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001841 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1842 pipe_config->lane_count,
1843 intel_crtc_has_type(pipe_config,
1844 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001845
Keith Packard417e8222011-11-01 19:54:11 -07001846 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001847 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001848 *
1849 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001850 * SNB CPU
1851 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001852 * CPT PCH
1853 *
1854 * IBX PCH and CPU are the same for almost everything,
1855 * except that the CPU DP PLL is configured in this
1856 * register
1857 *
1858 * CPT PCH is quite different, having many bits moved
1859 * to the TRANS_DP_CTL register instead. That
1860 * configuration happens (oddly) in ironlake_pch_enable
1861 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001862
Keith Packard417e8222011-11-01 19:54:11 -07001863 /* Preserve the BIOS-computed detected bit. This is
1864 * supposed to be read-only.
1865 */
1866 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001867
Keith Packard417e8222011-11-01 19:54:11 -07001868 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001869 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001870 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001871
Keith Packard417e8222011-11-01 19:54:11 -07001872 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001873
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001874 if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001875 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1876 intel_dp->DP |= DP_SYNC_HS_HIGH;
1877 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1878 intel_dp->DP |= DP_SYNC_VS_HIGH;
1879 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1880
Jani Nikula6aba5b62013-10-04 15:08:10 +03001881 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001882 intel_dp->DP |= DP_ENHANCED_FRAMING;
1883
Daniel Vetter7c62a162013-06-01 17:16:20 +02001884 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001885 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001886 u32 trans_dp;
1887
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001888 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001889
1890 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1891 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1892 trans_dp |= TRANS_DP_ENH_FRAMING;
1893 else
1894 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1895 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001896 } else {
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02001897 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001898 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001899
1900 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1901 intel_dp->DP |= DP_SYNC_HS_HIGH;
1902 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1903 intel_dp->DP |= DP_SYNC_VS_HIGH;
1904 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1905
Jani Nikula6aba5b62013-10-04 15:08:10 +03001906 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001907 intel_dp->DP |= DP_ENHANCED_FRAMING;
1908
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001909 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001910 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001911 else if (crtc->pipe == PIPE_B)
1912 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001913 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001914}
1915
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001916#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1917#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001918
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001919#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1920#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001921
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001922#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1923#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001924
Imre Deakde9c1b62016-06-16 20:01:46 +03001925static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
1926 struct intel_dp *intel_dp);
1927
Daniel Vetter4be73782014-01-17 14:39:48 +01001928static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001929 u32 mask,
1930 u32 value)
1931{
Paulo Zanoni30add222012-10-26 19:05:45 -02001932 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001933 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001934 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001935
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001936 lockdep_assert_held(&dev_priv->pps_mutex);
1937
Imre Deakde9c1b62016-06-16 20:01:46 +03001938 intel_pps_verify_state(dev_priv, intel_dp);
1939
Jani Nikulabf13e812013-09-06 07:40:05 +03001940 pp_stat_reg = _pp_stat_reg(intel_dp);
1941 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001942
1943 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001944 mask, value,
1945 I915_READ(pp_stat_reg),
1946 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001947
Chris Wilson9036ff02016-06-30 15:33:09 +01001948 if (intel_wait_for_register(dev_priv,
1949 pp_stat_reg, mask, value,
1950 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001951 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001952 I915_READ(pp_stat_reg),
1953 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001954
1955 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001956}
1957
Daniel Vetter4be73782014-01-17 14:39:48 +01001958static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001959{
1960 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001961 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001962}
1963
Daniel Vetter4be73782014-01-17 14:39:48 +01001964static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001965{
Keith Packardbd943152011-09-18 23:09:52 -07001966 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001967 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001968}
Keith Packardbd943152011-09-18 23:09:52 -07001969
Daniel Vetter4be73782014-01-17 14:39:48 +01001970static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001971{
Abhay Kumard28d4732016-01-22 17:39:04 -08001972 ktime_t panel_power_on_time;
1973 s64 panel_power_off_duration;
1974
Keith Packard99ea7122011-11-01 19:57:50 -07001975 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001976
Abhay Kumard28d4732016-01-22 17:39:04 -08001977 /* take the difference of currrent time and panel power off time
1978 * and then make panel wait for t11_t12 if needed. */
1979 panel_power_on_time = ktime_get_boottime();
1980 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1981
Paulo Zanonidce56b32013-12-19 14:29:40 -02001982 /* When we disable the VDD override bit last we have to do the manual
1983 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08001984 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
1985 wait_remaining_ms_from_jiffies(jiffies,
1986 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001987
Daniel Vetter4be73782014-01-17 14:39:48 +01001988 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001989}
Keith Packardbd943152011-09-18 23:09:52 -07001990
Daniel Vetter4be73782014-01-17 14:39:48 +01001991static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001992{
1993 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1994 intel_dp->backlight_on_delay);
1995}
1996
Daniel Vetter4be73782014-01-17 14:39:48 +01001997static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001998{
1999 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
2000 intel_dp->backlight_off_delay);
2001}
Keith Packard99ea7122011-11-01 19:57:50 -07002002
Keith Packard832dd3c2011-11-01 19:34:06 -07002003/* Read the current pp_control value, unlocking the register if it
2004 * is locked
2005 */
2006
Jesse Barnes453c5422013-03-28 09:55:41 -07002007static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07002008{
Jesse Barnes453c5422013-03-28 09:55:41 -07002009 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002010 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07002011 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07002012
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002013 lockdep_assert_held(&dev_priv->pps_mutex);
2014
Jani Nikulabf13e812013-09-06 07:40:05 +03002015 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03002016 if (WARN_ON(!HAS_DDI(dev_priv) &&
2017 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05302018 control &= ~PANEL_UNLOCK_MASK;
2019 control |= PANEL_UNLOCK_REGS;
2020 }
Keith Packard832dd3c2011-11-01 19:34:06 -07002021 return control;
Keith Packardbd943152011-09-18 23:09:52 -07002022}
2023
Ville Syrjälä951468f2014-09-04 14:55:31 +03002024/*
2025 * Must be paired with edp_panel_vdd_off().
2026 * Must hold pps_mutex around the whole on/off sequence.
2027 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2028 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03002029static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002030{
Paulo Zanoni30add222012-10-26 19:05:45 -02002031 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002032 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002033 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes5d613502011-01-24 17:10:54 -08002034 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002035 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002036 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08002037
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002038 lockdep_assert_held(&dev_priv->pps_mutex);
2039
Keith Packard97af61f572011-09-28 16:23:51 -07002040 if (!is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002041 return false;
Keith Packardbd943152011-09-18 23:09:52 -07002042
Egbert Eich2c623c12014-11-25 12:54:57 +01002043 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002044 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07002045
Daniel Vetter4be73782014-01-17 14:39:48 +01002046 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002047 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002048
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002049 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002050
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002051 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
2052 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07002053
Daniel Vetter4be73782014-01-17 14:39:48 +01002054 if (!edp_have_panel_power(intel_dp))
2055 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07002056
Jesse Barnes453c5422013-03-28 09:55:41 -07002057 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002058 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07002059
Jani Nikulabf13e812013-09-06 07:40:05 +03002060 pp_stat_reg = _pp_stat_reg(intel_dp);
2061 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002062
2063 I915_WRITE(pp_ctrl_reg, pp);
2064 POSTING_READ(pp_ctrl_reg);
2065 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2066 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07002067 /*
2068 * If the panel wasn't on, delay before accessing aux channel
2069 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002070 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002071 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
2072 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07002073 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07002074 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002075
2076 return need_to_disable;
2077}
2078
Ville Syrjälä951468f2014-09-04 14:55:31 +03002079/*
2080 * Must be paired with intel_edp_panel_vdd_off() or
2081 * intel_edp_panel_off().
2082 * Nested calls to these functions are not allowed since
2083 * we drop the lock. Caller must use some higher level
2084 * locking to prevent nested calls from other threads.
2085 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01002086void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002087{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002088 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002089
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002090 if (!is_edp(intel_dp))
2091 return;
2092
Ville Syrjälä773538e82014-09-04 14:54:56 +03002093 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002094 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002095 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002096
Rob Clarke2c719b2014-12-15 13:56:32 -05002097 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002098 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08002099}
2100
Daniel Vetter4be73782014-01-17 14:39:48 +01002101static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002102{
Paulo Zanoni30add222012-10-26 19:05:45 -02002103 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002104 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002105 struct intel_digital_port *intel_dig_port =
2106 dp_to_dig_port(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002107 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002108 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002109
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002110 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002111
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002112 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002113
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002114 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002115 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002116
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002117 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2118 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002119
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002120 pp = ironlake_get_pp_control(intel_dp);
2121 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002122
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002123 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2124 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002125
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002126 I915_WRITE(pp_ctrl_reg, pp);
2127 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002128
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002129 /* Make sure sequencer is idle before allowing subsequent activity */
2130 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2131 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002132
Imre Deak5a162e22016-08-10 14:07:30 +03002133 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002134 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002135
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002136 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002137}
2138
Daniel Vetter4be73782014-01-17 14:39:48 +01002139static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002140{
2141 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2142 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002143
Ville Syrjälä773538e82014-09-04 14:54:56 +03002144 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002145 if (!intel_dp->want_panel_vdd)
2146 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002147 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002148}
2149
Imre Deakaba86892014-07-30 15:57:31 +03002150static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2151{
2152 unsigned long delay;
2153
2154 /*
2155 * Queue the timer to fire a long time from now (relative to the power
2156 * down delay) to keep the panel power up across a sequence of
2157 * operations.
2158 */
2159 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2160 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2161}
2162
Ville Syrjälä951468f2014-09-04 14:55:31 +03002163/*
2164 * Must be paired with edp_panel_vdd_on().
2165 * Must hold pps_mutex around the whole on/off sequence.
2166 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2167 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002168static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002169{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002170 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002171
2172 lockdep_assert_held(&dev_priv->pps_mutex);
2173
Keith Packard97af61f572011-09-28 16:23:51 -07002174 if (!is_edp(intel_dp))
2175 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002176
Rob Clarke2c719b2014-12-15 13:56:32 -05002177 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002178 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002179
Keith Packardbd943152011-09-18 23:09:52 -07002180 intel_dp->want_panel_vdd = false;
2181
Imre Deakaba86892014-07-30 15:57:31 +03002182 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002183 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002184 else
2185 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002186}
2187
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002188static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002189{
Paulo Zanoni30add222012-10-26 19:05:45 -02002190 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002191 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002192 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002193 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002194
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002195 lockdep_assert_held(&dev_priv->pps_mutex);
2196
Keith Packard97af61f572011-09-28 16:23:51 -07002197 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002198 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002199
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002200 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2201 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002202
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002203 if (WARN(edp_have_panel_power(intel_dp),
2204 "eDP port %c panel power already on\n",
2205 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002206 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002207
Daniel Vetter4be73782014-01-17 14:39:48 +01002208 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002209
Jani Nikulabf13e812013-09-06 07:40:05 +03002210 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002211 pp = ironlake_get_pp_control(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002212 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002213 /* ILK workaround: disable reset around power sequence */
2214 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002215 I915_WRITE(pp_ctrl_reg, pp);
2216 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002217 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002218
Imre Deak5a162e22016-08-10 14:07:30 +03002219 pp |= PANEL_POWER_ON;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002220 if (!IS_GEN5(dev_priv))
Keith Packard99ea7122011-11-01 19:57:50 -07002221 pp |= PANEL_POWER_RESET;
2222
Jesse Barnes453c5422013-03-28 09:55:41 -07002223 I915_WRITE(pp_ctrl_reg, pp);
2224 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002225
Daniel Vetter4be73782014-01-17 14:39:48 +01002226 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002227 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002228
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002229 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002230 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002231 I915_WRITE(pp_ctrl_reg, pp);
2232 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002233 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002234}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002235
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002236void intel_edp_panel_on(struct intel_dp *intel_dp)
2237{
2238 if (!is_edp(intel_dp))
2239 return;
2240
2241 pps_lock(intel_dp);
2242 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002243 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002244}
2245
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002246
2247static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002248{
Paulo Zanoni30add222012-10-26 19:05:45 -02002249 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002250 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002251 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002252 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002253
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002254 lockdep_assert_held(&dev_priv->pps_mutex);
2255
Keith Packard97af61f572011-09-28 16:23:51 -07002256 if (!is_edp(intel_dp))
2257 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002258
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002259 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2260 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002261
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002262 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2263 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002264
Jesse Barnes453c5422013-03-28 09:55:41 -07002265 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002266 /* We need to switch off panel power _and_ force vdd, for otherwise some
2267 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002268 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002269 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002270
Jani Nikulabf13e812013-09-06 07:40:05 +03002271 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002272
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002273 intel_dp->want_panel_vdd = false;
2274
Jesse Barnes453c5422013-03-28 09:55:41 -07002275 I915_WRITE(pp_ctrl_reg, pp);
2276 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002277
Abhay Kumard28d4732016-01-22 17:39:04 -08002278 intel_dp->panel_power_off_time = ktime_get_boottime();
Daniel Vetter4be73782014-01-17 14:39:48 +01002279 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002280
2281 /* We got a reference when we enabled the VDD. */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002282 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002283}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002284
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002285void intel_edp_panel_off(struct intel_dp *intel_dp)
2286{
2287 if (!is_edp(intel_dp))
2288 return;
2289
2290 pps_lock(intel_dp);
2291 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002292 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002293}
2294
Jani Nikula1250d102014-08-12 17:11:39 +03002295/* Enable backlight in the panel power control. */
2296static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002297{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002298 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2299 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002300 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002301 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002302 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002303
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002304 /*
2305 * If we enable the backlight right away following a panel power
2306 * on, we may see slight flicker as the panel syncs with the eDP
2307 * link. So delay a bit to make sure the image is solid before
2308 * allowing it to appear.
2309 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002310 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002311
Ville Syrjälä773538e82014-09-04 14:54:56 +03002312 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002313
Jesse Barnes453c5422013-03-28 09:55:41 -07002314 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002315 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002316
Jani Nikulabf13e812013-09-06 07:40:05 +03002317 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002318
2319 I915_WRITE(pp_ctrl_reg, pp);
2320 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002321
Ville Syrjälä773538e82014-09-04 14:54:56 +03002322 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002323}
2324
Jani Nikula1250d102014-08-12 17:11:39 +03002325/* Enable backlight PWM and backlight PP control. */
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002326void intel_edp_backlight_on(const struct intel_crtc_state *crtc_state,
2327 const struct drm_connector_state *conn_state)
Jani Nikula1250d102014-08-12 17:11:39 +03002328{
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002329 struct intel_dp *intel_dp = enc_to_intel_dp(conn_state->best_encoder);
2330
Jani Nikula1250d102014-08-12 17:11:39 +03002331 if (!is_edp(intel_dp))
2332 return;
2333
2334 DRM_DEBUG_KMS("\n");
2335
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002336 intel_panel_enable_backlight(crtc_state, conn_state);
Jani Nikula1250d102014-08-12 17:11:39 +03002337 _intel_edp_backlight_on(intel_dp);
2338}
2339
2340/* Disable backlight in the panel power control. */
2341static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002342{
Paulo Zanoni30add222012-10-26 19:05:45 -02002343 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002344 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002345 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002346 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002347
Keith Packardf01eca22011-09-28 16:48:10 -07002348 if (!is_edp(intel_dp))
2349 return;
2350
Ville Syrjälä773538e82014-09-04 14:54:56 +03002351 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002352
Jesse Barnes453c5422013-03-28 09:55:41 -07002353 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002354 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002355
Jani Nikulabf13e812013-09-06 07:40:05 +03002356 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002357
2358 I915_WRITE(pp_ctrl_reg, pp);
2359 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002360
Ville Syrjälä773538e82014-09-04 14:54:56 +03002361 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002362
Paulo Zanonidce56b32013-12-19 14:29:40 -02002363 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002364 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002365}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002366
Jani Nikula1250d102014-08-12 17:11:39 +03002367/* Disable backlight PP control and backlight PWM. */
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002368void intel_edp_backlight_off(const struct drm_connector_state *old_conn_state)
Jani Nikula1250d102014-08-12 17:11:39 +03002369{
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002370 struct intel_dp *intel_dp = enc_to_intel_dp(old_conn_state->best_encoder);
2371
Jani Nikula1250d102014-08-12 17:11:39 +03002372 if (!is_edp(intel_dp))
2373 return;
2374
2375 DRM_DEBUG_KMS("\n");
2376
2377 _intel_edp_backlight_off(intel_dp);
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002378 intel_panel_disable_backlight(old_conn_state);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002379}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002380
Jani Nikula73580fb72014-08-12 17:11:41 +03002381/*
2382 * Hook for controlling the panel power control backlight through the bl_power
2383 * sysfs attribute. Take care to handle multiple calls.
2384 */
2385static void intel_edp_backlight_power(struct intel_connector *connector,
2386 bool enable)
2387{
2388 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002389 bool is_enabled;
2390
Ville Syrjälä773538e82014-09-04 14:54:56 +03002391 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002392 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002393 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002394
2395 if (is_enabled == enable)
2396 return;
2397
Jani Nikula23ba9372014-08-27 14:08:43 +03002398 DRM_DEBUG_KMS("panel power control backlight %s\n",
2399 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002400
2401 if (enable)
2402 _intel_edp_backlight_on(intel_dp);
2403 else
2404 _intel_edp_backlight_off(intel_dp);
2405}
2406
Ville Syrjälä64e10772015-10-29 21:26:01 +02002407static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2408{
2409 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2410 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2411 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2412
2413 I915_STATE_WARN(cur_state != state,
2414 "DP port %c state assertion failure (expected %s, current %s)\n",
2415 port_name(dig_port->port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002416 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002417}
2418#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2419
2420static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2421{
2422 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2423
2424 I915_STATE_WARN(cur_state != state,
2425 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002426 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002427}
2428#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2429#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2430
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002431static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2432 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002433{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002434 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002435 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002436
Ville Syrjälä64e10772015-10-29 21:26:01 +02002437 assert_pipe_disabled(dev_priv, crtc->pipe);
2438 assert_dp_port_disabled(intel_dp);
2439 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002440
Ville Syrjäläabfce942015-10-29 21:26:03 +02002441 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002442 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002443
2444 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2445
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002446 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002447 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2448 else
2449 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2450
2451 I915_WRITE(DP_A, intel_dp->DP);
2452 POSTING_READ(DP_A);
2453 udelay(500);
2454
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002455 /*
2456 * [DevILK] Work around required when enabling DP PLL
2457 * while a pipe is enabled going to FDI:
2458 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2459 * 2. Program DP PLL enable
2460 */
2461 if (IS_GEN5(dev_priv))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02002462 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002463
Daniel Vetter07679352012-09-06 22:15:42 +02002464 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002465
Daniel Vetter07679352012-09-06 22:15:42 +02002466 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002467 POSTING_READ(DP_A);
2468 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002469}
2470
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002471static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002472{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002473 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002474 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2475 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002476
Ville Syrjälä64e10772015-10-29 21:26:01 +02002477 assert_pipe_disabled(dev_priv, crtc->pipe);
2478 assert_dp_port_disabled(intel_dp);
2479 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002480
Ville Syrjäläabfce942015-10-29 21:26:03 +02002481 DRM_DEBUG_KMS("disabling eDP PLL\n");
2482
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002483 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002484
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002485 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002486 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002487 udelay(200);
2488}
2489
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002490/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002491void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002492{
2493 int ret, i;
2494
2495 /* Should have a valid DPCD by this point */
2496 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2497 return;
2498
2499 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002500 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2501 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002502 } else {
Imre Deak357c0ae2016-11-21 21:15:06 +02002503 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
2504
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002505 /*
2506 * When turning on, we need to retry for 1ms to give the sink
2507 * time to wake up.
2508 */
2509 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002510 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2511 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002512 if (ret == 1)
2513 break;
2514 msleep(1);
2515 }
Imre Deak357c0ae2016-11-21 21:15:06 +02002516
2517 if (ret == 1 && lspcon->active)
2518 lspcon_wait_pcon_mode(lspcon);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002519 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002520
2521 if (ret != 1)
2522 DRM_DEBUG_KMS("failed to %s sink power state\n",
2523 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002524}
2525
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002526static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2527 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002528{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002529 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002530 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002531 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002532 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002533 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002534 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002535
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002536 if (!intel_display_power_get_if_enabled(dev_priv,
2537 encoder->power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002538 return false;
2539
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002540 ret = false;
2541
Imre Deak6d129be2014-03-05 16:20:54 +02002542 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002543
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002544 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002545 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002546
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002547 if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002548 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002549 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002550 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002551
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002552 for_each_pipe(dev_priv, p) {
2553 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2554 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2555 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002556 ret = true;
2557
2558 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002559 }
2560 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002561
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002562 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002563 i915_mmio_reg_offset(intel_dp->output_reg));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002564 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002565 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2566 } else {
2567 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002568 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002569
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002570 ret = true;
2571
2572out:
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002573 intel_display_power_put(dev_priv, encoder->power_domain);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002574
2575 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002576}
2577
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002578static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002579 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002580{
2581 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002582 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002583 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002584 struct drm_i915_private *dev_priv = to_i915(dev);
Xiong Zhang63000ef2013-06-28 12:59:06 +08002585 enum port port = dp_to_dig_port(intel_dp)->port;
2586 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002587
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002588 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002589
2590 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002591
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002592 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002593 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2594
2595 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002596 flags |= DRM_MODE_FLAG_PHSYNC;
2597 else
2598 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002599
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002600 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002601 flags |= DRM_MODE_FLAG_PVSYNC;
2602 else
2603 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002604 } else {
2605 if (tmp & DP_SYNC_HS_HIGH)
2606 flags |= DRM_MODE_FLAG_PHSYNC;
2607 else
2608 flags |= DRM_MODE_FLAG_NHSYNC;
2609
2610 if (tmp & DP_SYNC_VS_HIGH)
2611 flags |= DRM_MODE_FLAG_PVSYNC;
2612 else
2613 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002614 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002615
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002616 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002617
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02002618 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002619 pipe_config->limited_color_range = true;
2620
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002621 pipe_config->lane_count =
2622 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2623
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002624 intel_dp_get_m_n(crtc, pipe_config);
2625
Ville Syrjälä18442d02013-09-13 16:00:08 +03002626 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002627 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002628 pipe_config->port_clock = 162000;
2629 else
2630 pipe_config->port_clock = 270000;
2631 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002632
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002633 pipe_config->base.adjusted_mode.crtc_clock =
2634 intel_dotclock_calculate(pipe_config->port_clock,
2635 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002636
Jani Nikula6aa23e62016-03-24 17:50:20 +02002637 if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
2638 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002639 /*
2640 * This is a big fat ugly hack.
2641 *
2642 * Some machines in UEFI boot mode provide us a VBT that has 18
2643 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2644 * unknown we fail to light up. Yet the same BIOS boots up with
2645 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2646 * max, not what it tells us to use.
2647 *
2648 * Note: This will still be broken if the eDP panel is not lit
2649 * up by the BIOS, and thus we can't get the mode at module
2650 * load.
2651 */
2652 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002653 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2654 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002655 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002656}
2657
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002658static void intel_disable_dp(struct intel_encoder *encoder,
2659 struct intel_crtc_state *old_crtc_state,
2660 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002661{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002662 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002663 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002664
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002665 if (old_crtc_state->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002666 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002667
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002668 if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv))
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002669 intel_psr_disable(intel_dp);
2670
Daniel Vetter6cb49832012-05-20 17:14:50 +02002671 /* Make sure the panel is off before trying to change the mode. But also
2672 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002673 intel_edp_panel_vdd_on(intel_dp);
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002674 intel_edp_backlight_off(old_conn_state);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002675 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002676 intel_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02002677
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002678 /* disable the port before the pipe on g4x */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002679 if (INTEL_GEN(dev_priv) < 5)
Daniel Vetter37398502012-09-06 22:15:44 +02002680 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07002681}
2682
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002683static void ilk_post_disable_dp(struct intel_encoder *encoder,
2684 struct intel_crtc_state *old_crtc_state,
2685 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002686{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002687 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002688 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002689
Ville Syrjälä49277c32014-03-31 18:21:26 +03002690 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002691
2692 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002693 if (port == PORT_A)
2694 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002695}
2696
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002697static void vlv_post_disable_dp(struct intel_encoder *encoder,
2698 struct intel_crtc_state *old_crtc_state,
2699 struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002700{
2701 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2702
2703 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002704}
2705
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002706static void chv_post_disable_dp(struct intel_encoder *encoder,
2707 struct intel_crtc_state *old_crtc_state,
2708 struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002709{
2710 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002711 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002712 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002713
2714 intel_dp_link_down(intel_dp);
2715
Ville Syrjäläa5805162015-05-26 20:42:30 +03002716 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002717
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002718 /* Assert data lane reset */
2719 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002720
Ville Syrjäläa5805162015-05-26 20:42:30 +03002721 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002722}
2723
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002724static void
2725_intel_dp_set_link_train(struct intel_dp *intel_dp,
2726 uint32_t *DP,
2727 uint8_t dp_train_pat)
2728{
2729 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2730 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002731 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002732 enum port port = intel_dig_port->port;
2733
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002734 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2735 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2736 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2737
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002738 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002739 uint32_t temp = I915_READ(DP_TP_CTL(port));
2740
2741 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2742 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2743 else
2744 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2745
2746 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2747 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2748 case DP_TRAINING_PATTERN_DISABLE:
2749 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2750
2751 break;
2752 case DP_TRAINING_PATTERN_1:
2753 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2754 break;
2755 case DP_TRAINING_PATTERN_2:
2756 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2757 break;
2758 case DP_TRAINING_PATTERN_3:
2759 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2760 break;
2761 }
2762 I915_WRITE(DP_TP_CTL(port), temp);
2763
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002764 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002765 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002766 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2767
2768 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2769 case DP_TRAINING_PATTERN_DISABLE:
2770 *DP |= DP_LINK_TRAIN_OFF_CPT;
2771 break;
2772 case DP_TRAINING_PATTERN_1:
2773 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2774 break;
2775 case DP_TRAINING_PATTERN_2:
2776 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2777 break;
2778 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002779 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002780 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2781 break;
2782 }
2783
2784 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002785 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002786 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2787 else
2788 *DP &= ~DP_LINK_TRAIN_MASK;
2789
2790 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2791 case DP_TRAINING_PATTERN_DISABLE:
2792 *DP |= DP_LINK_TRAIN_OFF;
2793 break;
2794 case DP_TRAINING_PATTERN_1:
2795 *DP |= DP_LINK_TRAIN_PAT_1;
2796 break;
2797 case DP_TRAINING_PATTERN_2:
2798 *DP |= DP_LINK_TRAIN_PAT_2;
2799 break;
2800 case DP_TRAINING_PATTERN_3:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002801 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002802 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2803 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002804 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002805 *DP |= DP_LINK_TRAIN_PAT_2;
2806 }
2807 break;
2808 }
2809 }
2810}
2811
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002812static void intel_dp_enable_port(struct intel_dp *intel_dp,
2813 struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002814{
2815 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002816 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002817
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002818 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002819
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002820 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002821
2822 /*
2823 * Magic for VLV/CHV. We _must_ first set up the register
2824 * without actually enabling the port, and then do another
2825 * write to enable the port. Otherwise link training will
2826 * fail when the power sequencer is freshly used for this port.
2827 */
2828 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002829 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002830 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002831
2832 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2833 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002834}
2835
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002836static void intel_enable_dp(struct intel_encoder *encoder,
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002837 struct intel_crtc_state *pipe_config,
2838 struct drm_connector_state *conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002839{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002840 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2841 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002842 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulac1dec792014-10-27 16:26:56 +02002843 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002844 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002845 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002846
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002847 if (WARN_ON(dp_reg & DP_PORT_EN))
2848 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002849
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002850 pps_lock(intel_dp);
2851
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002852 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002853 vlv_init_panel_power_sequencer(intel_dp);
2854
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002855 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002856
2857 edp_panel_vdd_on(intel_dp);
2858 edp_panel_on(intel_dp);
2859 edp_panel_vdd_off(intel_dp, true);
2860
2861 pps_unlock(intel_dp);
2862
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002863 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002864 unsigned int lane_mask = 0x0;
2865
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002866 if (IS_CHERRYVIEW(dev_priv))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002867 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002868
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002869 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2870 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002871 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002872
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002873 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2874 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002875 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002876
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002877 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002878 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002879 pipe_name(pipe));
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002880 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Jani Nikulac1dec792014-10-27 16:26:56 +02002881 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002882}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002883
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002884static void g4x_enable_dp(struct intel_encoder *encoder,
2885 struct intel_crtc_state *pipe_config,
2886 struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03002887{
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002888 intel_enable_dp(encoder, pipe_config, conn_state);
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002889 intel_edp_backlight_on(pipe_config, conn_state);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002890}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002891
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002892static void vlv_enable_dp(struct intel_encoder *encoder,
2893 struct intel_crtc_state *pipe_config,
2894 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002895{
Jani Nikula828f5c62013-09-05 16:44:45 +03002896 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2897
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002898 intel_edp_backlight_on(pipe_config, conn_state);
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002899 intel_psr_enable(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002900}
2901
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002902static void g4x_pre_enable_dp(struct intel_encoder *encoder,
2903 struct intel_crtc_state *pipe_config,
2904 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002905{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002906 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002907 enum port port = dp_to_dig_port(intel_dp)->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002908
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002909 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002910
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002911 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002912 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002913 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002914}
2915
Ville Syrjälä83b84592014-10-16 21:29:51 +03002916static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2917{
2918 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002919 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002920 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03002921 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002922
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002923 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
2924
Ville Syrjäläd1586942017-02-08 19:52:54 +02002925 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2926 return;
2927
Ville Syrjälä83b84592014-10-16 21:29:51 +03002928 edp_panel_vdd_off_sync(intel_dp);
2929
2930 /*
2931 * VLV seems to get confused when multiple power seqeuencers
2932 * have the same port selected (even if only one has power/vdd
2933 * enabled). The failure manifests as vlv_wait_port_ready() failing
2934 * CHV on the other hand doesn't seem to mind having the same port
2935 * selected in multiple power seqeuencers, but let's clear the
2936 * port select always when logically disconnecting a power sequencer
2937 * from a port.
2938 */
2939 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2940 pipe_name(pipe), port_name(intel_dig_port->port));
2941 I915_WRITE(pp_on_reg, 0);
2942 POSTING_READ(pp_on_reg);
2943
2944 intel_dp->pps_pipe = INVALID_PIPE;
2945}
2946
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002947static void vlv_steal_power_sequencer(struct drm_device *dev,
2948 enum pipe pipe)
2949{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002950 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002951 struct intel_encoder *encoder;
2952
2953 lockdep_assert_held(&dev_priv->pps_mutex);
2954
Jani Nikula19c80542015-12-16 12:48:16 +02002955 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002956 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002957 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002958
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002959 if (encoder->type != INTEL_OUTPUT_DP &&
2960 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002961 continue;
2962
2963 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002964 port = dp_to_dig_port(intel_dp)->port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002965
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002966 WARN(intel_dp->active_pipe == pipe,
2967 "stealing pipe %c power sequencer from active (e)DP port %c\n",
2968 pipe_name(pipe), port_name(port));
2969
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002970 if (intel_dp->pps_pipe != pipe)
2971 continue;
2972
2973 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03002974 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002975
2976 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002977 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002978 }
2979}
2980
2981static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
2982{
2983 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2984 struct intel_encoder *encoder = &intel_dig_port->base;
2985 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002986 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002987 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002988
2989 lockdep_assert_held(&dev_priv->pps_mutex);
2990
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002991 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002992
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002993 if (intel_dp->pps_pipe != INVALID_PIPE &&
2994 intel_dp->pps_pipe != crtc->pipe) {
2995 /*
2996 * If another power sequencer was being used on this
2997 * port previously make sure to turn off vdd there while
2998 * we still have control of it.
2999 */
Ville Syrjälä83b84592014-10-16 21:29:51 +03003000 vlv_detach_power_sequencer(intel_dp);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003001 }
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003002
3003 /*
3004 * We may be stealing the power
3005 * sequencer from another port.
3006 */
3007 vlv_steal_power_sequencer(dev, crtc->pipe);
3008
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003009 intel_dp->active_pipe = crtc->pipe;
3010
3011 if (!is_edp(intel_dp))
3012 return;
3013
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003014 /* now it's all ours */
3015 intel_dp->pps_pipe = crtc->pipe;
3016
3017 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
3018 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
3019
3020 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03003021 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02003022 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003023}
3024
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003025static void vlv_pre_enable_dp(struct intel_encoder *encoder,
3026 struct intel_crtc_state *pipe_config,
3027 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03003028{
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03003029 vlv_phy_pre_encoder_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003030
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003031 intel_enable_dp(encoder, pipe_config, conn_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003032}
3033
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003034static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
3035 struct intel_crtc_state *pipe_config,
3036 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07003037{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003038 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02003039
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03003040 vlv_phy_pre_pll_enable(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003041}
3042
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003043static void chv_pre_enable_dp(struct intel_encoder *encoder,
3044 struct intel_crtc_state *pipe_config,
3045 struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003046{
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003047 chv_phy_pre_encoder_enable(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003048
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003049 intel_enable_dp(encoder, pipe_config, conn_state);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03003050
3051 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003052 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003053}
3054
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003055static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
3056 struct intel_crtc_state *pipe_config,
3057 struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03003058{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003059 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03003060
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03003061 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03003062}
3063
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003064static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
3065 struct intel_crtc_state *pipe_config,
3066 struct drm_connector_state *conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003067{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03003068 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003069}
3070
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003071/*
3072 * Fetch AUX CH registers 0x202 - 0x207 which contain
3073 * link status information
3074 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003075bool
Keith Packard93f62da2011-11-01 19:45:03 -07003076intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003077{
Lyude9f085eb2016-04-13 10:58:33 -04003078 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
3079 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003080}
3081
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303082static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp)
3083{
3084 uint8_t psr_caps = 0;
3085
Imre Deak9bacd4b2017-05-10 12:21:48 +03003086 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps) != 1)
3087 return false;
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303088 return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED;
3089}
3090
3091static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp)
3092{
3093 uint8_t dprx = 0;
3094
Imre Deak9bacd4b2017-05-10 12:21:48 +03003095 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_DPRX_FEATURE_ENUMERATION_LIST,
3096 &dprx) != 1)
3097 return false;
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303098 return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED;
3099}
3100
Chris Wilsona76f73d2017-01-14 10:51:13 +00003101static bool intel_dp_get_alpm_status(struct intel_dp *intel_dp)
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303102{
3103 uint8_t alpm_caps = 0;
3104
Imre Deak9bacd4b2017-05-10 12:21:48 +03003105 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_RECEIVER_ALPM_CAP,
3106 &alpm_caps) != 1)
3107 return false;
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303108 return alpm_caps & DP_ALPM_CAP;
3109}
3110
Paulo Zanoni11002442014-06-13 18:45:41 -03003111/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003112uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003113intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003114{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003115 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003116 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003117
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003118 if (IS_GEN9_LP(dev_priv))
Vandana Kannan93147262014-11-18 15:45:29 +05303119 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003120 else if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjäläffe51112017-02-23 19:49:01 +02003121 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3122 return intel_ddi_dp_voltage_max(encoder);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003123 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Sonika Jindalbd600182014-08-08 16:23:41 +05303124 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003125 else if (IS_GEN7(dev_priv) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303126 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003127 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303128 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08003129 else
Sonika Jindalbd600182014-08-08 16:23:41 +05303130 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08003131}
3132
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003133uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003134intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3135{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003136 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003137 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003138
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003139 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003140 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3141 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3142 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3143 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3144 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3145 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3146 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303147 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3148 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003149 default:
3150 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3151 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003152 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003153 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303154 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3155 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3156 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3157 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3158 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3159 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3160 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003161 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303162 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003163 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003164 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003165 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303166 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3167 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3168 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3169 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3170 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3171 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3172 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003173 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303174 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003175 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003176 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003177 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303178 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3179 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3180 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3181 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3182 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003183 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303184 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003185 }
3186 } else {
3187 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303188 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3189 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3190 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3191 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3192 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3193 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3194 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003195 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303196 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003197 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003198 }
3199}
3200
Daniel Vetter5829975c2015-04-16 11:36:52 +02003201static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003202{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003203 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003204 unsigned long demph_reg_value, preemph_reg_value,
3205 uniqtranscale_reg_value;
3206 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003207
3208 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303209 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003210 preemph_reg_value = 0x0004000;
3211 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303212 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003213 demph_reg_value = 0x2B405555;
3214 uniqtranscale_reg_value = 0x552AB83A;
3215 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303216 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003217 demph_reg_value = 0x2B404040;
3218 uniqtranscale_reg_value = 0x5548B83A;
3219 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303220 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003221 demph_reg_value = 0x2B245555;
3222 uniqtranscale_reg_value = 0x5560B83A;
3223 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303224 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003225 demph_reg_value = 0x2B405555;
3226 uniqtranscale_reg_value = 0x5598DA3A;
3227 break;
3228 default:
3229 return 0;
3230 }
3231 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303232 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003233 preemph_reg_value = 0x0002000;
3234 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303235 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003236 demph_reg_value = 0x2B404040;
3237 uniqtranscale_reg_value = 0x5552B83A;
3238 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303239 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003240 demph_reg_value = 0x2B404848;
3241 uniqtranscale_reg_value = 0x5580B83A;
3242 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303243 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003244 demph_reg_value = 0x2B404040;
3245 uniqtranscale_reg_value = 0x55ADDA3A;
3246 break;
3247 default:
3248 return 0;
3249 }
3250 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303251 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003252 preemph_reg_value = 0x0000000;
3253 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303254 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003255 demph_reg_value = 0x2B305555;
3256 uniqtranscale_reg_value = 0x5570B83A;
3257 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303258 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003259 demph_reg_value = 0x2B2B4040;
3260 uniqtranscale_reg_value = 0x55ADDA3A;
3261 break;
3262 default:
3263 return 0;
3264 }
3265 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303266 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003267 preemph_reg_value = 0x0006000;
3268 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303269 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003270 demph_reg_value = 0x1B405555;
3271 uniqtranscale_reg_value = 0x55ADDA3A;
3272 break;
3273 default:
3274 return 0;
3275 }
3276 break;
3277 default:
3278 return 0;
3279 }
3280
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003281 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3282 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003283
3284 return 0;
3285}
3286
Daniel Vetter5829975c2015-04-16 11:36:52 +02003287static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003288{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003289 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3290 u32 deemph_reg_value, margin_reg_value;
3291 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003292 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003293
3294 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303295 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003296 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303297 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003298 deemph_reg_value = 128;
3299 margin_reg_value = 52;
3300 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303301 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003302 deemph_reg_value = 128;
3303 margin_reg_value = 77;
3304 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303305 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003306 deemph_reg_value = 128;
3307 margin_reg_value = 102;
3308 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303309 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003310 deemph_reg_value = 128;
3311 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003312 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003313 break;
3314 default:
3315 return 0;
3316 }
3317 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303318 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003319 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303320 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003321 deemph_reg_value = 85;
3322 margin_reg_value = 78;
3323 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303324 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003325 deemph_reg_value = 85;
3326 margin_reg_value = 116;
3327 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303328 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003329 deemph_reg_value = 85;
3330 margin_reg_value = 154;
3331 break;
3332 default:
3333 return 0;
3334 }
3335 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303336 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003337 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303338 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003339 deemph_reg_value = 64;
3340 margin_reg_value = 104;
3341 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303342 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003343 deemph_reg_value = 64;
3344 margin_reg_value = 154;
3345 break;
3346 default:
3347 return 0;
3348 }
3349 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303350 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003351 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303352 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003353 deemph_reg_value = 43;
3354 margin_reg_value = 154;
3355 break;
3356 default:
3357 return 0;
3358 }
3359 break;
3360 default:
3361 return 0;
3362 }
3363
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003364 chv_set_phy_signal_level(encoder, deemph_reg_value,
3365 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003366
3367 return 0;
3368}
3369
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003370static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003371gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003372{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003373 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003374
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003375 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303376 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003377 default:
3378 signal_levels |= DP_VOLTAGE_0_4;
3379 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303380 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003381 signal_levels |= DP_VOLTAGE_0_6;
3382 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303383 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003384 signal_levels |= DP_VOLTAGE_0_8;
3385 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303386 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003387 signal_levels |= DP_VOLTAGE_1_2;
3388 break;
3389 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003390 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303391 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003392 default:
3393 signal_levels |= DP_PRE_EMPHASIS_0;
3394 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303395 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003396 signal_levels |= DP_PRE_EMPHASIS_3_5;
3397 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303398 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003399 signal_levels |= DP_PRE_EMPHASIS_6;
3400 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303401 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003402 signal_levels |= DP_PRE_EMPHASIS_9_5;
3403 break;
3404 }
3405 return signal_levels;
3406}
3407
Zhenyu Wange3421a12010-04-08 09:43:27 +08003408/* Gen6's DP voltage swing and pre-emphasis control */
3409static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003410gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003411{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003412 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3413 DP_TRAIN_PRE_EMPHASIS_MASK);
3414 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303415 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3416 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003417 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303418 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003419 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303420 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3421 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003422 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303423 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3424 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003425 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303426 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3427 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003428 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003429 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003430 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3431 "0x%x\n", signal_levels);
3432 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003433 }
3434}
3435
Keith Packard1a2eb462011-11-16 16:26:07 -08003436/* Gen7's DP voltage swing and pre-emphasis control */
3437static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003438gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003439{
3440 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3441 DP_TRAIN_PRE_EMPHASIS_MASK);
3442 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303443 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003444 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303445 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003446 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303447 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003448 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3449
Sonika Jindalbd600182014-08-08 16:23:41 +05303450 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003451 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303452 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003453 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3454
Sonika Jindalbd600182014-08-08 16:23:41 +05303455 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003456 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303457 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003458 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3459
3460 default:
3461 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3462 "0x%x\n", signal_levels);
3463 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3464 }
3465}
3466
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003467void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003468intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003469{
3470 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003471 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003472 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003473 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003474 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003475 uint8_t train_set = intel_dp->train_set[0];
3476
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003477 if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003478 signal_levels = ddi_signal_levels(intel_dp);
3479
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07003480 if (IS_GEN9_LP(dev_priv) || IS_CANNONLAKE(dev_priv))
David Weinehallf8896f52015-06-25 11:11:03 +03003481 signal_levels = 0;
3482 else
3483 mask = DDI_BUF_EMP_MASK;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003484 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003485 signal_levels = chv_signal_levels(intel_dp);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003486 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003487 signal_levels = vlv_signal_levels(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003488 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003489 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003490 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003491 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003492 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003493 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3494 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003495 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003496 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3497 }
3498
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303499 if (mask)
3500 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3501
3502 DRM_DEBUG_KMS("Using vswing level %d\n",
3503 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3504 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3505 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3506 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003507
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003508 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003509
3510 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3511 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003512}
3513
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003514void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003515intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3516 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003517{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003518 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003519 struct drm_i915_private *dev_priv =
3520 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003521
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003522 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003523
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003524 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003525 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003526}
3527
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003528void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003529{
3530 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3531 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003532 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak3ab9c632013-05-03 12:57:41 +03003533 enum port port = intel_dig_port->port;
3534 uint32_t val;
3535
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003536 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003537 return;
3538
3539 val = I915_READ(DP_TP_CTL(port));
3540 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3541 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3542 I915_WRITE(DP_TP_CTL(port), val);
3543
3544 /*
3545 * On PORT_A we can have only eDP in SST mode. There the only reason
3546 * we need to set idle transmission mode is to work around a HW issue
3547 * where we enable the pipe while not in idle link-training mode.
3548 * In this case there is requirement to wait for a minimum number of
3549 * idle patterns to be sent.
3550 */
3551 if (port == PORT_A)
3552 return;
3553
Chris Wilsona7670172016-06-30 15:33:10 +01003554 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3555 DP_TP_STATUS_IDLE_DONE,
3556 DP_TP_STATUS_IDLE_DONE,
3557 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003558 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3559}
3560
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003561static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003562intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003563{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003564 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003565 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003566 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003567 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003568 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003569 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003570
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003571 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003572 return;
3573
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003574 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003575 return;
3576
Zhao Yakui28c97732009-10-09 11:39:41 +08003577 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003578
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003579 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003580 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003581 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003582 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003583 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003584 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003585 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3586 else
3587 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003588 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003589 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003590 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003591 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003592
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003593 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3594 I915_WRITE(intel_dp->output_reg, DP);
3595 POSTING_READ(intel_dp->output_reg);
3596
3597 /*
3598 * HW workaround for IBX, we need to move the port
3599 * to transcoder A after disabling it to allow the
3600 * matching HDMI port to be enabled on transcoder A.
3601 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003602 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003603 /*
3604 * We get CPU/PCH FIFO underruns on the other pipe when
3605 * doing the workaround. Sweep them under the rug.
3606 */
3607 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3608 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3609
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003610 /* always enable with pattern 1 (as per spec) */
3611 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3612 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3613 I915_WRITE(intel_dp->output_reg, DP);
3614 POSTING_READ(intel_dp->output_reg);
3615
3616 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003617 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003618 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003619
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003620 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003621 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3622 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003623 }
3624
Keith Packardf01eca22011-09-28 16:48:10 -07003625 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003626
3627 intel_dp->DP = DP;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003628
3629 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3630 pps_lock(intel_dp);
3631 intel_dp->active_pipe = INVALID_PIPE;
3632 pps_unlock(intel_dp);
3633 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003634}
3635
Imre Deak24e807e2016-10-24 19:33:28 +03003636bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003637intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003638{
Lyude9f085eb2016-04-13 10:58:33 -04003639 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3640 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003641 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003642
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003643 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003644
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003645 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3646}
3647
3648static bool
3649intel_edp_init_dpcd(struct intel_dp *intel_dp)
3650{
3651 struct drm_i915_private *dev_priv =
3652 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3653
3654 /* this function is meant to be called only once */
3655 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3656
3657 if (!intel_dp_read_dpcd(intel_dp))
3658 return false;
3659
Jani Nikula84c36752017-05-18 14:10:23 +03003660 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
3661 drm_dp_is_branch(intel_dp->dpcd));
Imre Deak12a47a422016-10-24 19:33:29 +03003662
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003663 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3664 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3665 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3666
3667 /* Check if the panel supports PSR */
3668 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3669 intel_dp->psr_dpcd,
3670 sizeof(intel_dp->psr_dpcd));
3671 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3672 dev_priv->psr.sink_support = true;
3673 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3674 }
3675
3676 if (INTEL_GEN(dev_priv) >= 9 &&
3677 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3678 uint8_t frame_sync_cap;
3679
3680 dev_priv->psr.sink_support = true;
Imre Deak9bacd4b2017-05-10 12:21:48 +03003681 if (drm_dp_dpcd_readb(&intel_dp->aux,
3682 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3683 &frame_sync_cap) != 1)
3684 frame_sync_cap = 0;
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003685 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3686 /* PSR2 needs frame sync as well */
3687 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3688 DRM_DEBUG_KMS("PSR2 %s on sink",
3689 dev_priv->psr.psr2_support ? "supported" : "not supported");
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303690
3691 if (dev_priv->psr.psr2_support) {
3692 dev_priv->psr.y_cord_support =
3693 intel_dp_get_y_cord_status(intel_dp);
3694 dev_priv->psr.colorimetry_support =
3695 intel_dp_get_colorimetry_status(intel_dp);
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303696 dev_priv->psr.alpm =
3697 intel_dp_get_alpm_status(intel_dp);
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303698 }
3699
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003700 }
3701
3702 /* Read the eDP Display control capabilities registers */
3703 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
3704 drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003705 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3706 sizeof(intel_dp->edp_dpcd))
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003707 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3708 intel_dp->edp_dpcd);
3709
3710 /* Intermediate frequency support */
3711 if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */
3712 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3713 int i;
3714
3715 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3716 sink_rates, sizeof(sink_rates));
3717
3718 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3719 int val = le16_to_cpu(sink_rates[i]);
3720
3721 if (val == 0)
3722 break;
3723
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -08003724 /* Value read multiplied by 200kHz gives the per-lane
3725 * link rate in kHz. The source rates are, however,
3726 * stored in terms of LS_Clk kHz. The full conversion
3727 * back to symbols is
3728 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
3729 */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003730 intel_dp->sink_rates[i] = (val * 200) / 10;
3731 }
3732 intel_dp->num_sink_rates = i;
3733 }
3734
Jani Nikula68f357c2017-03-28 17:59:05 +03003735 if (intel_dp->num_sink_rates)
3736 intel_dp->use_rate_select = true;
3737 else
3738 intel_dp_set_sink_rates(intel_dp);
3739
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003740 intel_dp_set_common_rates(intel_dp);
3741
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003742 return true;
3743}
3744
3745
3746static bool
3747intel_dp_get_dpcd(struct intel_dp *intel_dp)
3748{
Jani Nikula27dbefb2017-04-06 16:44:17 +03003749 u8 sink_count;
3750
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003751 if (!intel_dp_read_dpcd(intel_dp))
3752 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003753
Jani Nikula68f357c2017-03-28 17:59:05 +03003754 /* Don't clobber cached eDP rates. */
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003755 if (!is_edp(intel_dp)) {
Jani Nikula68f357c2017-03-28 17:59:05 +03003756 intel_dp_set_sink_rates(intel_dp);
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003757 intel_dp_set_common_rates(intel_dp);
3758 }
Jani Nikula68f357c2017-03-28 17:59:05 +03003759
Jani Nikula27dbefb2017-04-06 16:44:17 +03003760 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_SINK_COUNT, &sink_count) <= 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303761 return false;
3762
3763 /*
3764 * Sink count can change between short pulse hpd hence
3765 * a member variable in intel_dp will track any changes
3766 * between short pulse interrupts.
3767 */
Jani Nikula27dbefb2017-04-06 16:44:17 +03003768 intel_dp->sink_count = DP_GET_SINK_COUNT(sink_count);
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303769
3770 /*
3771 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3772 * a dongle is present but no display. Unless we require to know
3773 * if a dongle is present or not, we don't need to update
3774 * downstream port information. So, an early return here saves
3775 * time from performing other operations which are not required.
3776 */
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05303777 if (!is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303778 return false;
3779
Imre Deakc726ad02016-10-24 19:33:24 +03003780 if (!drm_dp_is_branch(intel_dp->dpcd))
Adam Jacksonedb39242012-09-18 10:58:49 -04003781 return true; /* native DP sink */
3782
3783 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3784 return true; /* no per-port downstream info */
3785
Lyude9f085eb2016-04-13 10:58:33 -04003786 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3787 intel_dp->downstream_ports,
3788 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003789 return false; /* downstream port status fetch failed */
3790
3791 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003792}
3793
Dave Airlie0e32b392014-05-02 14:02:48 +10003794static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003795intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003796{
Jani Nikula010b9b32017-04-06 16:44:16 +03003797 u8 mstm_cap;
Dave Airlie0e32b392014-05-02 14:02:48 +10003798
Nathan Schulte7cc96132016-03-15 10:14:05 -05003799 if (!i915.enable_dp_mst)
3800 return false;
3801
Dave Airlie0e32b392014-05-02 14:02:48 +10003802 if (!intel_dp->can_mst)
3803 return false;
3804
3805 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3806 return false;
3807
Jani Nikula010b9b32017-04-06 16:44:16 +03003808 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_MSTM_CAP, &mstm_cap) != 1)
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003809 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003810
Jani Nikula010b9b32017-04-06 16:44:16 +03003811 return mstm_cap & DP_MST_CAP;
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003812}
3813
3814static void
3815intel_dp_configure_mst(struct intel_dp *intel_dp)
3816{
3817 if (!i915.enable_dp_mst)
3818 return;
3819
3820 if (!intel_dp->can_mst)
3821 return;
3822
3823 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3824
3825 if (intel_dp->is_mst)
3826 DRM_DEBUG_KMS("Sink is MST capable\n");
3827 else
3828 DRM_DEBUG_KMS("Sink is not MST capable\n");
3829
3830 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3831 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003832}
3833
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003834static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003835{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003836 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003837 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003838 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003839 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003840 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003841 int count = 0;
3842 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003843
3844 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003845 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003846 ret = -EIO;
3847 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003848 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003849
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003850 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003851 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003852 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003853 ret = -EIO;
3854 goto out;
3855 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003856
Rodrigo Vivic6297842015-11-05 10:50:20 -08003857 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003858 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivic6297842015-11-05 10:50:20 -08003859
3860 if (drm_dp_dpcd_readb(&intel_dp->aux,
3861 DP_TEST_SINK_MISC, &buf) < 0) {
3862 ret = -EIO;
3863 goto out;
3864 }
3865 count = buf & DP_TEST_COUNT_MASK;
3866 } while (--attempts && count);
3867
3868 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003869 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003870 ret = -ETIMEDOUT;
3871 }
3872
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003873 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003874 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003875 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003876}
3877
3878static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3879{
3880 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003881 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003882 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3883 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003884 int ret;
3885
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003886 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3887 return -EIO;
3888
3889 if (!(buf & DP_TEST_CRC_SUPPORTED))
3890 return -ENOTTY;
3891
3892 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3893 return -EIO;
3894
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003895 if (buf & DP_TEST_SINK_START) {
3896 ret = intel_dp_sink_crc_stop(intel_dp);
3897 if (ret)
3898 return ret;
3899 }
3900
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003901 hsw_disable_ips(intel_crtc);
3902
3903 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3904 buf | DP_TEST_SINK_START) < 0) {
3905 hsw_enable_ips(intel_crtc);
3906 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003907 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003908
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003909 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003910 return 0;
3911}
3912
3913int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3914{
3915 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003916 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003917 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3918 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003919 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003920 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003921
3922 ret = intel_dp_sink_crc_start(intel_dp);
3923 if (ret)
3924 return ret;
3925
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003926 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003927 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003928
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003929 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003930 DP_TEST_SINK_MISC, &buf) < 0) {
3931 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003932 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003933 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003934 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07003935
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003936 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003937
3938 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003939 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
3940 ret = -ETIMEDOUT;
3941 goto stop;
3942 }
3943
3944 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
3945 ret = -EIO;
3946 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003947 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003948
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003949stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003950 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003951 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003952}
3953
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003954static bool
3955intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3956{
Jani Nikula010b9b32017-04-06 16:44:16 +03003957 return drm_dp_dpcd_readb(&intel_dp->aux, DP_DEVICE_SERVICE_IRQ_VECTOR,
3958 sink_irq_vector) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003959}
3960
Dave Airlie0e32b392014-05-02 14:02:48 +10003961static bool
3962intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3963{
3964 int ret;
3965
Lyude9f085eb2016-04-13 10:58:33 -04003966 ret = drm_dp_dpcd_read(&intel_dp->aux,
Dave Airlie0e32b392014-05-02 14:02:48 +10003967 DP_SINK_COUNT_ESI,
3968 sink_irq_vector, 14);
3969 if (ret != 14)
3970 return false;
3971
3972 return true;
3973}
3974
Todd Previtec5d5ab72015-04-15 08:38:38 -07003975static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003976{
Manasi Navareda15f7c2017-01-24 08:16:34 -08003977 int status = 0;
3978 int min_lane_count = 1;
Manasi Navareda15f7c2017-01-24 08:16:34 -08003979 int link_rate_index, test_link_rate;
3980 uint8_t test_lane_count, test_link_bw;
3981 /* (DP CTS 1.2)
3982 * 4.3.1.11
3983 */
3984 /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */
3985 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT,
3986 &test_lane_count);
3987
3988 if (status <= 0) {
3989 DRM_DEBUG_KMS("Lane count read failed\n");
3990 return DP_TEST_NAK;
3991 }
3992 test_lane_count &= DP_MAX_LANE_COUNT_MASK;
3993 /* Validate the requested lane count */
3994 if (test_lane_count < min_lane_count ||
Jani Nikulae6c0c642017-04-06 16:44:12 +03003995 test_lane_count > intel_dp->max_link_lane_count)
Manasi Navareda15f7c2017-01-24 08:16:34 -08003996 return DP_TEST_NAK;
3997
3998 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE,
3999 &test_link_bw);
4000 if (status <= 0) {
4001 DRM_DEBUG_KMS("Link Rate read failed\n");
4002 return DP_TEST_NAK;
4003 }
4004 /* Validate the requested link rate */
4005 test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw);
Jani Nikulab1810a72017-04-06 16:44:11 +03004006 link_rate_index = intel_dp_rate_index(intel_dp->common_rates,
4007 intel_dp->num_common_rates,
4008 test_link_rate);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004009 if (link_rate_index < 0)
4010 return DP_TEST_NAK;
4011
4012 intel_dp->compliance.test_lane_count = test_lane_count;
4013 intel_dp->compliance.test_link_rate = test_link_rate;
4014
4015 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004016}
4017
4018static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
4019{
Manasi Navare611032b2017-01-24 08:21:49 -08004020 uint8_t test_pattern;
Jani Nikula010b9b32017-04-06 16:44:16 +03004021 uint8_t test_misc;
Manasi Navare611032b2017-01-24 08:21:49 -08004022 __be16 h_width, v_height;
4023 int status = 0;
4024
4025 /* Read the TEST_PATTERN (DP CTS 3.1.5) */
Jani Nikula010b9b32017-04-06 16:44:16 +03004026 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_PATTERN,
4027 &test_pattern);
Manasi Navare611032b2017-01-24 08:21:49 -08004028 if (status <= 0) {
4029 DRM_DEBUG_KMS("Test pattern read failed\n");
4030 return DP_TEST_NAK;
4031 }
4032 if (test_pattern != DP_COLOR_RAMP)
4033 return DP_TEST_NAK;
4034
4035 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI,
4036 &h_width, 2);
4037 if (status <= 0) {
4038 DRM_DEBUG_KMS("H Width read failed\n");
4039 return DP_TEST_NAK;
4040 }
4041
4042 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI,
4043 &v_height, 2);
4044 if (status <= 0) {
4045 DRM_DEBUG_KMS("V Height read failed\n");
4046 return DP_TEST_NAK;
4047 }
4048
Jani Nikula010b9b32017-04-06 16:44:16 +03004049 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_MISC0,
4050 &test_misc);
Manasi Navare611032b2017-01-24 08:21:49 -08004051 if (status <= 0) {
4052 DRM_DEBUG_KMS("TEST MISC read failed\n");
4053 return DP_TEST_NAK;
4054 }
4055 if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB)
4056 return DP_TEST_NAK;
4057 if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA)
4058 return DP_TEST_NAK;
4059 switch (test_misc & DP_TEST_BIT_DEPTH_MASK) {
4060 case DP_TEST_BIT_DEPTH_6:
4061 intel_dp->compliance.test_data.bpc = 6;
4062 break;
4063 case DP_TEST_BIT_DEPTH_8:
4064 intel_dp->compliance.test_data.bpc = 8;
4065 break;
4066 default:
4067 return DP_TEST_NAK;
4068 }
4069
4070 intel_dp->compliance.test_data.video_pattern = test_pattern;
4071 intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width);
4072 intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height);
4073 /* Set test active flag here so userspace doesn't interrupt things */
4074 intel_dp->compliance.test_active = 1;
4075
4076 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004077}
4078
4079static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
4080{
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004081 uint8_t test_result = DP_TEST_ACK;
Todd Previte559be302015-05-04 07:48:20 -07004082 struct intel_connector *intel_connector = intel_dp->attached_connector;
4083 struct drm_connector *connector = &intel_connector->base;
4084
4085 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02004086 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07004087 intel_dp->aux.i2c_defer_count > 6) {
4088 /* Check EDID read for NACKs, DEFERs and corruption
4089 * (DP CTS 1.2 Core r1.1)
4090 * 4.2.2.4 : Failed EDID read, I2C_NAK
4091 * 4.2.2.5 : Failed EDID read, I2C_DEFER
4092 * 4.2.2.6 : EDID corruption detected
4093 * Use failsafe mode for all cases
4094 */
4095 if (intel_dp->aux.i2c_nack_count > 0 ||
4096 intel_dp->aux.i2c_defer_count > 0)
4097 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
4098 intel_dp->aux.i2c_nack_count,
4099 intel_dp->aux.i2c_defer_count);
Manasi Navarec1617ab2016-12-09 16:22:50 -08004100 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
Todd Previte559be302015-05-04 07:48:20 -07004101 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05304102 struct edid *block = intel_connector->detect_edid;
4103
4104 /* We have to write the checksum
4105 * of the last block read
4106 */
4107 block += intel_connector->detect_edid->extensions;
4108
Jani Nikula010b9b32017-04-06 16:44:16 +03004109 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_EDID_CHECKSUM,
4110 block->checksum) <= 0)
Todd Previte559be302015-05-04 07:48:20 -07004111 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
4112
4113 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004114 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED;
Todd Previte559be302015-05-04 07:48:20 -07004115 }
4116
4117 /* Set test active flag here so userspace doesn't interrupt things */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004118 intel_dp->compliance.test_active = 1;
Todd Previte559be302015-05-04 07:48:20 -07004119
Todd Previtec5d5ab72015-04-15 08:38:38 -07004120 return test_result;
4121}
4122
4123static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
4124{
4125 uint8_t test_result = DP_TEST_NAK;
4126 return test_result;
4127}
4128
4129static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
4130{
4131 uint8_t response = DP_TEST_NAK;
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004132 uint8_t request = 0;
4133 int status;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004134
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004135 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004136 if (status <= 0) {
4137 DRM_DEBUG_KMS("Could not read test request from sink\n");
4138 goto update_status;
4139 }
4140
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004141 switch (request) {
Todd Previtec5d5ab72015-04-15 08:38:38 -07004142 case DP_TEST_LINK_TRAINING:
4143 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004144 response = intel_dp_autotest_link_training(intel_dp);
4145 break;
4146 case DP_TEST_LINK_VIDEO_PATTERN:
4147 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004148 response = intel_dp_autotest_video_pattern(intel_dp);
4149 break;
4150 case DP_TEST_LINK_EDID_READ:
4151 DRM_DEBUG_KMS("EDID test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004152 response = intel_dp_autotest_edid(intel_dp);
4153 break;
4154 case DP_TEST_LINK_PHY_TEST_PATTERN:
4155 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004156 response = intel_dp_autotest_phy_pattern(intel_dp);
4157 break;
4158 default:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004159 DRM_DEBUG_KMS("Invalid test request '%02x'\n", request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004160 break;
4161 }
4162
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004163 if (response & DP_TEST_ACK)
4164 intel_dp->compliance.test_type = request;
4165
Todd Previtec5d5ab72015-04-15 08:38:38 -07004166update_status:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004167 status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004168 if (status <= 0)
4169 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004170}
4171
Dave Airlie0e32b392014-05-02 14:02:48 +10004172static int
4173intel_dp_check_mst_status(struct intel_dp *intel_dp)
4174{
4175 bool bret;
4176
4177 if (intel_dp->is_mst) {
4178 u8 esi[16] = { 0 };
4179 int ret = 0;
4180 int retry;
4181 bool handled;
4182 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4183go_again:
4184 if (bret == true) {
4185
4186 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03004187 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03004188 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10004189 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4190 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004191 intel_dp_stop_link_train(intel_dp);
4192 }
4193
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004194 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004195 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4196
4197 if (handled) {
4198 for (retry = 0; retry < 3; retry++) {
4199 int wret;
4200 wret = drm_dp_dpcd_write(&intel_dp->aux,
4201 DP_SINK_COUNT_ESI+1,
4202 &esi[1], 3);
4203 if (wret == 3) {
4204 break;
4205 }
4206 }
4207
4208 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4209 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004210 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004211 goto go_again;
4212 }
4213 } else
4214 ret = 0;
4215
4216 return ret;
4217 } else {
4218 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4219 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4220 intel_dp->is_mst = false;
4221 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4222 /* send a hotplug event */
4223 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4224 }
4225 }
4226 return -EINVAL;
4227}
4228
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304229static void
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004230intel_dp_retrain_link(struct intel_dp *intel_dp)
4231{
4232 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4233 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4234 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
4235
4236 /* Suppress underruns caused by re-training */
4237 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4238 if (crtc->config->has_pch_encoder)
4239 intel_set_pch_fifo_underrun_reporting(dev_priv,
4240 intel_crtc_pch_transcoder(crtc), false);
4241
4242 intel_dp_start_link_train(intel_dp);
4243 intel_dp_stop_link_train(intel_dp);
4244
4245 /* Keep underrun reporting disabled until things are stable */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02004246 intel_wait_for_vblank(dev_priv, crtc->pipe);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004247
4248 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4249 if (crtc->config->has_pch_encoder)
4250 intel_set_pch_fifo_underrun_reporting(dev_priv,
4251 intel_crtc_pch_transcoder(crtc), true);
4252}
4253
4254static void
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304255intel_dp_check_link_status(struct intel_dp *intel_dp)
4256{
4257 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4258 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4259 u8 link_status[DP_LINK_STATUS_SIZE];
4260
4261 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
4262
4263 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4264 DRM_ERROR("Failed to get link status\n");
4265 return;
4266 }
4267
4268 if (!intel_encoder->base.crtc)
4269 return;
4270
4271 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4272 return;
4273
Manasi Navare14c562c2017-04-06 14:00:12 -07004274 /*
4275 * Validate the cached values of intel_dp->link_rate and
4276 * intel_dp->lane_count before attempting to retrain.
4277 */
4278 if (!intel_dp_link_params_valid(intel_dp))
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004279 return;
4280
Manasi Navareda15f7c2017-01-24 08:16:34 -08004281 /* Retrain if Channel EQ or CR not ok */
4282 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304283 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4284 intel_encoder->base.name);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004285
4286 intel_dp_retrain_link(intel_dp);
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304287 }
4288}
4289
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004290/*
4291 * According to DP spec
4292 * 5.1.2:
4293 * 1. Read DPCD
4294 * 2. Configure link according to Receiver Capabilities
4295 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4296 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304297 *
4298 * intel_dp_short_pulse - handles short pulse interrupts
4299 * when full detection is not required.
4300 * Returns %true if short pulse is handled and full detection
4301 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004302 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304303static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304304intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004305{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004306 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004307 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004308 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304309 u8 old_sink_count = intel_dp->sink_count;
4310 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004311
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304312 /*
4313 * Clearing compliance test variables to allow capturing
4314 * of values for next automated test request.
4315 */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004316 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304317
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304318 /*
4319 * Now read the DPCD to see if it's actually running
4320 * If the current value of sink count doesn't match with
4321 * the value that was stored earlier or dpcd read failed
4322 * we need to do full detection
4323 */
4324 ret = intel_dp_get_dpcd(intel_dp);
4325
4326 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4327 /* No need to proceed if we are going to do full detect */
4328 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004329 }
4330
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004331 /* Try to read the source of the interrupt */
4332 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004333 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4334 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004335 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004336 drm_dp_dpcd_writeb(&intel_dp->aux,
4337 DP_DEVICE_SERVICE_IRQ_VECTOR,
4338 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004339
4340 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Manasi Navareda15f7c2017-01-24 08:16:34 -08004341 intel_dp_handle_test_request(intel_dp);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004342 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4343 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4344 }
4345
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304346 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4347 intel_dp_check_link_status(intel_dp);
4348 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004349 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
4350 DRM_DEBUG_KMS("Link Training Compliance Test requested\n");
4351 /* Send a Hotplug Uevent to userspace to start modeset */
4352 drm_kms_helper_hotplug_event(intel_encoder->base.dev);
4353 }
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304354
4355 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004356}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004357
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004358/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004359static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004360intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004361{
Imre Deake393d0d2017-02-22 17:10:52 +02004362 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004363 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004364 uint8_t type;
4365
Imre Deake393d0d2017-02-22 17:10:52 +02004366 if (lspcon->active)
4367 lspcon_resume(lspcon);
4368
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004369 if (!intel_dp_get_dpcd(intel_dp))
4370 return connector_status_disconnected;
4371
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304372 if (is_edp(intel_dp))
4373 return connector_status_connected;
4374
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004375 /* if there's no downstream port, we're done */
Imre Deakc726ad02016-10-24 19:33:24 +03004376 if (!drm_dp_is_branch(dpcd))
Keith Packard26d61aa2011-07-25 20:01:09 -07004377 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004378
4379 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004380 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4381 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004382
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304383 return intel_dp->sink_count ?
4384 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004385 }
4386
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004387 if (intel_dp_can_mst(intel_dp))
4388 return connector_status_connected;
4389
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004390 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004391 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004392 return connector_status_connected;
4393
4394 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004395 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4396 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4397 if (type == DP_DS_PORT_TYPE_VGA ||
4398 type == DP_DS_PORT_TYPE_NON_EDID)
4399 return connector_status_unknown;
4400 } else {
4401 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4402 DP_DWN_STRM_PORT_TYPE_MASK;
4403 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4404 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4405 return connector_status_unknown;
4406 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004407
4408 /* Anything else is out of spec, warn and ignore */
4409 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004410 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004411}
4412
4413static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004414edp_detect(struct intel_dp *intel_dp)
4415{
4416 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Mika Kahola1650be72016-12-13 10:02:47 +02004417 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsond410b562014-09-02 20:03:59 +01004418 enum drm_connector_status status;
4419
Mika Kahola1650be72016-12-13 10:02:47 +02004420 status = intel_panel_detect(dev_priv);
Chris Wilsond410b562014-09-02 20:03:59 +01004421 if (status == connector_status_unknown)
4422 status = connector_status_connected;
4423
4424 return status;
4425}
4426
Jani Nikulab93433c2015-08-20 10:47:36 +03004427static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4428 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004429{
Jani Nikulab93433c2015-08-20 10:47:36 +03004430 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004431
Jani Nikula0df53b72015-08-20 10:47:40 +03004432 switch (port->port) {
Jani Nikula0df53b72015-08-20 10:47:40 +03004433 case PORT_B:
4434 bit = SDE_PORTB_HOTPLUG;
4435 break;
4436 case PORT_C:
4437 bit = SDE_PORTC_HOTPLUG;
4438 break;
4439 case PORT_D:
4440 bit = SDE_PORTD_HOTPLUG;
4441 break;
4442 default:
4443 MISSING_CASE(port->port);
4444 return false;
4445 }
4446
4447 return I915_READ(SDEISR) & bit;
4448}
4449
4450static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4451 struct intel_digital_port *port)
4452{
4453 u32 bit;
4454
4455 switch (port->port) {
Jani Nikula0df53b72015-08-20 10:47:40 +03004456 case PORT_B:
4457 bit = SDE_PORTB_HOTPLUG_CPT;
4458 break;
4459 case PORT_C:
4460 bit = SDE_PORTC_HOTPLUG_CPT;
4461 break;
4462 case PORT_D:
4463 bit = SDE_PORTD_HOTPLUG_CPT;
4464 break;
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004465 default:
4466 MISSING_CASE(port->port);
4467 return false;
4468 }
4469
4470 return I915_READ(SDEISR) & bit;
4471}
4472
4473static bool spt_digital_port_connected(struct drm_i915_private *dev_priv,
4474 struct intel_digital_port *port)
4475{
4476 u32 bit;
4477
4478 switch (port->port) {
4479 case PORT_A:
4480 bit = SDE_PORTA_HOTPLUG_SPT;
4481 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004482 case PORT_E:
4483 bit = SDE_PORTE_HOTPLUG_SPT;
4484 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004485 default:
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004486 return cpt_digital_port_connected(dev_priv, port);
Jani Nikulab93433c2015-08-20 10:47:36 +03004487 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004488
Jani Nikulab93433c2015-08-20 10:47:36 +03004489 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004490}
4491
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004492static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004493 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004494{
Jani Nikula9642c812015-08-20 10:47:41 +03004495 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004496
Jani Nikula9642c812015-08-20 10:47:41 +03004497 switch (port->port) {
4498 case PORT_B:
4499 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4500 break;
4501 case PORT_C:
4502 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4503 break;
4504 case PORT_D:
4505 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4506 break;
4507 default:
4508 MISSING_CASE(port->port);
4509 return false;
4510 }
4511
4512 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4513}
4514
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004515static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4516 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004517{
4518 u32 bit;
4519
4520 switch (port->port) {
4521 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004522 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004523 break;
4524 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004525 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004526 break;
4527 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004528 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004529 break;
4530 default:
4531 MISSING_CASE(port->port);
4532 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004533 }
4534
Jani Nikula1d245982015-08-20 10:47:37 +03004535 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004536}
4537
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004538static bool ilk_digital_port_connected(struct drm_i915_private *dev_priv,
4539 struct intel_digital_port *port)
4540{
4541 if (port->port == PORT_A)
4542 return I915_READ(DEISR) & DE_DP_A_HOTPLUG;
4543 else
4544 return ibx_digital_port_connected(dev_priv, port);
4545}
4546
4547static bool snb_digital_port_connected(struct drm_i915_private *dev_priv,
4548 struct intel_digital_port *port)
4549{
4550 if (port->port == PORT_A)
4551 return I915_READ(DEISR) & DE_DP_A_HOTPLUG;
4552 else
4553 return cpt_digital_port_connected(dev_priv, port);
4554}
4555
4556static bool ivb_digital_port_connected(struct drm_i915_private *dev_priv,
4557 struct intel_digital_port *port)
4558{
4559 if (port->port == PORT_A)
4560 return I915_READ(DEISR) & DE_DP_A_HOTPLUG_IVB;
4561 else
4562 return cpt_digital_port_connected(dev_priv, port);
4563}
4564
4565static bool bdw_digital_port_connected(struct drm_i915_private *dev_priv,
4566 struct intel_digital_port *port)
4567{
4568 if (port->port == PORT_A)
4569 return I915_READ(GEN8_DE_PORT_ISR) & GEN8_PORT_DP_A_HOTPLUG;
4570 else
4571 return cpt_digital_port_connected(dev_priv, port);
4572}
4573
Jani Nikulae464bfd2015-08-20 10:47:42 +03004574static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304575 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004576{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304577 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4578 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004579 u32 bit;
4580
Rodrigo Vivi256cfdd2017-08-11 11:26:49 -07004581 port = intel_hpd_pin_to_port(intel_encoder->hpd_pin);
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304582 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004583 case PORT_A:
4584 bit = BXT_DE_PORT_HP_DDIA;
4585 break;
4586 case PORT_B:
4587 bit = BXT_DE_PORT_HP_DDIB;
4588 break;
4589 case PORT_C:
4590 bit = BXT_DE_PORT_HP_DDIC;
4591 break;
4592 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304593 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004594 return false;
4595 }
4596
4597 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4598}
4599
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004600/*
4601 * intel_digital_port_connected - is the specified port connected?
4602 * @dev_priv: i915 private structure
4603 * @port: the port to test
4604 *
4605 * Return %true if @port is connected, %false otherwise.
4606 */
Imre Deak390b4e02017-01-27 11:39:19 +02004607bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
4608 struct intel_digital_port *port)
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004609{
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004610 if (HAS_GMCH_DISPLAY(dev_priv)) {
4611 if (IS_GM45(dev_priv))
4612 return gm45_digital_port_connected(dev_priv, port);
4613 else
4614 return g4x_digital_port_connected(dev_priv, port);
4615 }
4616
4617 if (IS_GEN5(dev_priv))
4618 return ilk_digital_port_connected(dev_priv, port);
4619 else if (IS_GEN6(dev_priv))
4620 return snb_digital_port_connected(dev_priv, port);
4621 else if (IS_GEN7(dev_priv))
4622 return ivb_digital_port_connected(dev_priv, port);
4623 else if (IS_GEN8(dev_priv))
4624 return bdw_digital_port_connected(dev_priv, port);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004625 else if (IS_GEN9_LP(dev_priv))
Jani Nikulae464bfd2015-08-20 10:47:42 +03004626 return bxt_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004627 else
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004628 return spt_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004629}
4630
Keith Packard8c241fe2011-09-28 16:38:44 -07004631static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004632intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004633{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004634 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004635
Jani Nikula9cd300e2012-10-19 14:51:52 +03004636 /* use cached edid if we have one */
4637 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004638 /* invalid edid */
4639 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004640 return NULL;
4641
Jani Nikula55e9ede2013-10-01 10:38:54 +03004642 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004643 } else
4644 return drm_get_edid(&intel_connector->base,
4645 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004646}
4647
Chris Wilsonbeb60602014-09-02 20:04:00 +01004648static void
4649intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004650{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004651 struct intel_connector *intel_connector = intel_dp->attached_connector;
4652 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004653
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304654 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004655 edid = intel_dp_get_edid(intel_dp);
4656 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004657
Maarten Lankhorste6b72c92017-05-01 15:38:00 +02004658 intel_dp->has_audio = drm_detect_monitor_audio(edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004659}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004660
Chris Wilsonbeb60602014-09-02 20:04:00 +01004661static void
4662intel_dp_unset_edid(struct intel_dp *intel_dp)
4663{
4664 struct intel_connector *intel_connector = intel_dp->attached_connector;
4665
4666 kfree(intel_connector->detect_edid);
4667 intel_connector->detect_edid = NULL;
4668
4669 intel_dp->has_audio = false;
4670}
4671
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004672static int
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304673intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004674{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304675 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004676 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004677 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4678 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004679 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004680 enum drm_connector_status status;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004681 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004682
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004683 WARN_ON(!drm_modeset_is_locked(&connector->dev->mode_config.connection_mutex));
4684
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004685 intel_display_power_get(to_i915(dev), intel_dp->aux_power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004686
Chris Wilsond410b562014-09-02 20:03:59 +01004687 /* Can't disconnect eDP, but you can close the lid... */
4688 if (is_edp(intel_dp))
4689 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004690 else if (intel_digital_port_connected(to_i915(dev),
4691 dp_to_dig_port(intel_dp)))
4692 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004693 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004694 status = connector_status_disconnected;
4695
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004696 if (status == connector_status_disconnected) {
Manasi Navarec1617ab2016-12-09 16:22:50 -08004697 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304698
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004699 if (intel_dp->is_mst) {
4700 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4701 intel_dp->is_mst,
4702 intel_dp->mst_mgr.mst_state);
4703 intel_dp->is_mst = false;
4704 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4705 intel_dp->is_mst);
4706 }
4707
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004708 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304709 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004710
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304711 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004712 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304713
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004714 DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
4715 yesno(intel_dp_source_supports_hbr2(intel_dp)),
4716 yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
4717
Manasi Navared7e8ef02017-02-07 16:54:11 -08004718 if (intel_dp->reset_link_params) {
Jani Nikula540b0b7f2017-04-06 16:44:13 +03004719 /* Initial max link lane count */
4720 intel_dp->max_link_lane_count = intel_dp_max_common_lane_count(intel_dp);
Manasi Navaref4829842016-12-05 16:27:36 -08004721
Jani Nikula540b0b7f2017-04-06 16:44:13 +03004722 /* Initial max link rate */
4723 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
Manasi Navared7e8ef02017-02-07 16:54:11 -08004724
4725 intel_dp->reset_link_params = false;
4726 }
Manasi Navaref4829842016-12-05 16:27:36 -08004727
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004728 intel_dp_print_rates(intel_dp);
4729
Jani Nikula84c36752017-05-18 14:10:23 +03004730 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
4731 drm_dp_is_branch(intel_dp->dpcd));
Mika Kahola0e390a32016-09-09 14:10:53 +03004732
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004733 intel_dp_configure_mst(intel_dp);
4734
4735 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304736 /*
4737 * If we are in MST mode then this connector
4738 * won't appear connected or have anything
4739 * with EDID on it
4740 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004741 status = connector_status_disconnected;
4742 goto out;
Ville Syrjälä1a361472017-04-12 22:30:17 +03004743 } else {
4744 /*
4745 * If display is now connected check links status,
4746 * there has been known issues of link loss triggerring
4747 * long pulse.
4748 *
4749 * Some sinks (eg. ASUS PB287Q) seem to perform some
4750 * weird HPD ping pong during modesets. So we can apparently
4751 * end up with HPD going low during a modeset, and then
4752 * going back up soon after. And once that happens we must
4753 * retrain the link to get a picture. That's in case no
4754 * userspace component reacted to intermittent HPD dip.
4755 */
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304756 intel_dp_check_link_status(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004757 }
4758
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304759 /*
4760 * Clearing NACK and defer counts to get their exact values
4761 * while reading EDID which are required by Compliance tests
4762 * 4.2.2.4 and 4.2.2.5
4763 */
4764 intel_dp->aux.i2c_nack_count = 0;
4765 intel_dp->aux.i2c_defer_count = 0;
4766
Chris Wilsonbeb60602014-09-02 20:04:00 +01004767 intel_dp_set_edid(intel_dp);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004768 if (is_edp(intel_dp) || intel_connector->detect_edid)
4769 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304770 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004771
Todd Previte09b1eb12015-04-20 15:27:34 -07004772 /* Try to read the source of the interrupt */
4773 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004774 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4775 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004776 /* Clear interrupt source */
4777 drm_dp_dpcd_writeb(&intel_dp->aux,
4778 DP_DEVICE_SERVICE_IRQ_VECTOR,
4779 sink_irq_vector);
4780
4781 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4782 intel_dp_handle_test_request(intel_dp);
4783 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4784 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4785 }
4786
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004787out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004788 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304789 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304790
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004791 intel_display_power_put(to_i915(dev), intel_dp->aux_power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004792 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304793}
4794
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004795static int
4796intel_dp_detect(struct drm_connector *connector,
4797 struct drm_modeset_acquire_ctx *ctx,
4798 bool force)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304799{
4800 struct intel_dp *intel_dp = intel_attached_dp(connector);
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004801 int status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304802
4803 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4804 connector->base.id, connector->name);
4805
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304806 /* If full detect is not performed yet, do a full detect */
4807 if (!intel_dp->detect_done)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004808 status = intel_dp_long_pulse(intel_dp->attached_connector);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304809
4810 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304811
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004812 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004813}
4814
Chris Wilsonbeb60602014-09-02 20:04:00 +01004815static void
4816intel_dp_force(struct drm_connector *connector)
4817{
4818 struct intel_dp *intel_dp = intel_attached_dp(connector);
4819 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004820 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004821
4822 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4823 connector->base.id, connector->name);
4824 intel_dp_unset_edid(intel_dp);
4825
4826 if (connector->status != connector_status_connected)
4827 return;
4828
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004829 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004830
4831 intel_dp_set_edid(intel_dp);
4832
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004833 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004834
4835 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004836 intel_encoder->type = INTEL_OUTPUT_DP;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004837}
4838
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004839static int intel_dp_get_modes(struct drm_connector *connector)
4840{
Jani Nikuladd06f902012-10-19 14:51:50 +03004841 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004842 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004843
Chris Wilsonbeb60602014-09-02 20:04:00 +01004844 edid = intel_connector->detect_edid;
4845 if (edid) {
4846 int ret = intel_connector_update_modes(connector, edid);
4847 if (ret)
4848 return ret;
4849 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004850
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004851 /* if eDP has no EDID, fall back to fixed mode */
Chris Wilsonbeb60602014-09-02 20:04:00 +01004852 if (is_edp(intel_attached_dp(connector)) &&
4853 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004854 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004855
4856 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004857 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004858 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004859 drm_mode_probed_add(connector, mode);
4860 return 1;
4861 }
4862 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004863
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004864 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004865}
4866
Chris Wilsonf6849602010-09-19 09:29:33 +01004867static int
Chris Wilson7a418e32016-06-24 14:00:14 +01004868intel_dp_connector_register(struct drm_connector *connector)
4869{
4870 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004871 int ret;
4872
4873 ret = intel_connector_register(connector);
4874 if (ret)
4875 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004876
4877 i915_debugfs_connector_add(connector);
4878
4879 DRM_DEBUG_KMS("registering %s bus for %s\n",
4880 intel_dp->aux.name, connector->kdev->kobj.name);
4881
4882 intel_dp->aux.dev = connector->kdev;
4883 return drm_dp_aux_register(&intel_dp->aux);
4884}
4885
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004886static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004887intel_dp_connector_unregister(struct drm_connector *connector)
4888{
4889 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4890 intel_connector_unregister(connector);
4891}
4892
4893static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004894intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004895{
Jani Nikula1d508702012-10-19 14:51:49 +03004896 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004897
Chris Wilson10e972d2014-09-04 21:43:45 +01004898 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004899
Jani Nikula9cd300e2012-10-19 14:51:52 +03004900 if (!IS_ERR_OR_NULL(intel_connector->edid))
4901 kfree(intel_connector->edid);
4902
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004903 /* Can't call is_edp() since the encoder may have been destroyed
4904 * already. */
4905 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004906 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004907
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004908 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004909 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004910}
4911
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004912void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004913{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004914 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4915 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004916
Dave Airlie0e32b392014-05-02 14:02:48 +10004917 intel_dp_mst_encoder_cleanup(intel_dig_port);
Keith Packardbd943152011-09-18 23:09:52 -07004918 if (is_edp(intel_dp)) {
4919 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004920 /*
4921 * vdd might still be enabled do to the delayed vdd off.
4922 * Make sure vdd is actually turned off here.
4923 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004924 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004925 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004926 pps_unlock(intel_dp);
4927
Clint Taylor01527b32014-07-07 13:01:46 -07004928 if (intel_dp->edp_notifier.notifier_call) {
4929 unregister_reboot_notifier(&intel_dp->edp_notifier);
4930 intel_dp->edp_notifier.notifier_call = NULL;
4931 }
Keith Packardbd943152011-09-18 23:09:52 -07004932 }
Chris Wilson99681882016-06-20 09:29:17 +01004933
4934 intel_dp_aux_fini(intel_dp);
4935
Imre Deakc8bd0e42014-12-12 17:57:38 +02004936 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004937 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004938}
4939
Imre Deakbf93ba62016-04-18 10:04:21 +03004940void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004941{
4942 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4943
4944 if (!is_edp(intel_dp))
4945 return;
4946
Ville Syrjälä951468f2014-09-04 14:55:31 +03004947 /*
4948 * vdd might still be enabled do to the delayed vdd off.
4949 * Make sure vdd is actually turned off here.
4950 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004951 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004952 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004953 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004954 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004955}
4956
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004957static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4958{
4959 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4960 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004961 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004962
4963 lockdep_assert_held(&dev_priv->pps_mutex);
4964
4965 if (!edp_have_panel_vdd(intel_dp))
4966 return;
4967
4968 /*
4969 * The VDD bit needs a power domain reference, so if the bit is
4970 * already enabled when we boot or resume, grab this reference and
4971 * schedule a vdd off, so we don't hold on to the reference
4972 * indefinitely.
4973 */
4974 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004975 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004976
4977 edp_panel_vdd_schedule_off(intel_dp);
4978}
4979
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02004980static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
4981{
4982 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
4983
4984 if ((intel_dp->DP & DP_PORT_EN) == 0)
4985 return INVALID_PIPE;
4986
4987 if (IS_CHERRYVIEW(dev_priv))
4988 return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
4989 else
4990 return PORT_TO_PIPE(intel_dp->DP);
4991}
4992
Imre Deakbf93ba62016-04-18 10:04:21 +03004993void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03004994{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03004995 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Imre Deakdd75f6d2016-11-21 21:15:05 +02004996 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
4997 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Ville Syrjälä64989ca42016-05-13 20:53:56 +03004998
4999 if (!HAS_DDI(dev_priv))
5000 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005001
Imre Deakdd75f6d2016-11-21 21:15:05 +02005002 if (lspcon->active)
Shashank Sharma910530c2016-10-14 19:56:52 +05305003 lspcon_resume(lspcon);
5004
Manasi Navared7e8ef02017-02-07 16:54:11 -08005005 intel_dp->reset_link_params = true;
5006
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005007 pps_lock(intel_dp);
5008
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005009 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5010 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5011
5012 if (is_edp(intel_dp)) {
5013 /* Reinit the power sequencer, in case BIOS did something with it. */
5014 intel_dp_pps_init(encoder->dev, intel_dp);
5015 intel_edp_panel_vdd_sanitize(intel_dp);
5016 }
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005017
5018 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03005019}
5020
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005021static const struct drm_connector_funcs intel_dp_connector_funcs = {
Chris Wilsonbeb60602014-09-02 20:04:00 +01005022 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005023 .fill_modes = drm_helper_probe_single_connector_modes,
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02005024 .atomic_get_property = intel_digital_connector_atomic_get_property,
5025 .atomic_set_property = intel_digital_connector_atomic_set_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01005026 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01005027 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03005028 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08005029 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02005030 .atomic_duplicate_state = intel_digital_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005031};
5032
5033static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02005034 .detect_ctx = intel_dp_detect,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005035 .get_modes = intel_dp_get_modes,
5036 .mode_valid = intel_dp_mode_valid,
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02005037 .atomic_check = intel_digital_connector_atomic_check,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005038};
5039
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005040static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03005041 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02005042 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005043};
5044
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005045enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10005046intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
5047{
5048 struct intel_dp *intel_dp = &intel_dig_port->dp;
Dave Airlie0e32b392014-05-02 14:02:48 +10005049 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005050 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005051 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03005052
Takashi Iwai25400582015-11-19 12:09:56 +01005053 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
5054 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Ville Syrjäläcca05022016-06-22 21:57:06 +03005055 intel_dig_port->base.type = INTEL_OUTPUT_DP;
Dave Airlie13cf5502014-06-18 11:29:35 +10005056
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005057 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
5058 /*
5059 * vdd off can generate a long pulse on eDP which
5060 * would require vdd on to handle it, and thus we
5061 * would end up in an endless cycle of
5062 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
5063 */
5064 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
5065 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d522015-02-10 14:11:46 +02005066 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005067 }
5068
Ville Syrjälä26fbb772014-08-11 18:37:37 +03005069 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
5070 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10005071 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10005072
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005073 if (long_hpd) {
Manasi Navared7e8ef02017-02-07 16:54:11 -08005074 intel_dp->reset_link_params = true;
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005075 intel_dp->detect_done = false;
5076 return IRQ_NONE;
5077 }
5078
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005079 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005080
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005081 if (intel_dp->is_mst) {
5082 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
5083 /*
5084 * If we were in MST mode, and device is not
5085 * there, get out of MST mode
5086 */
5087 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
5088 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
5089 intel_dp->is_mst = false;
5090 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
5091 intel_dp->is_mst);
5092 intel_dp->detect_done = false;
5093 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10005094 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005095 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005096
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005097 if (!intel_dp->is_mst) {
5098 if (!intel_dp_short_pulse(intel_dp)) {
5099 intel_dp->detect_done = false;
5100 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05305101 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005102 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005103
5104 ret = IRQ_HANDLED;
5105
Imre Deak1c767b32014-08-18 14:42:42 +03005106put_power:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005107 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005108
5109 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10005110}
5111
Rodrigo Vivi477ec322015-08-06 15:51:39 +08005112/* check the VBT to see whether the eDP is on another port */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005113bool intel_dp_is_edp(struct drm_i915_private *dev_priv, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08005114{
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005115 /*
5116 * eDP not supported on g4x. so bail out early just
5117 * for a bit extra safety in case the VBT is bonkers.
5118 */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005119 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005120 return false;
5121
Imre Deaka98d9c12016-12-21 12:17:24 +02005122 if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005123 return true;
5124
Jani Nikula951d9ef2016-03-16 12:43:31 +02005125 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08005126}
5127
Maarten Lankhorst200819a2017-04-10 12:51:10 +02005128static void
Chris Wilsonf6849602010-09-19 09:29:33 +01005129intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
5130{
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005131 struct drm_i915_private *dev_priv = to_i915(connector->dev);
5132
Chris Wilson3f43c482011-05-12 22:17:24 +01005133 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00005134 intel_attach_broadcast_rgb_property(connector);
Yuly Novikov53b41832012-10-26 12:04:00 +03005135
5136 if (is_edp(intel_dp)) {
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005137 u32 allowed_scalers;
5138
5139 allowed_scalers = BIT(DRM_MODE_SCALE_ASPECT) | BIT(DRM_MODE_SCALE_FULLSCREEN);
5140 if (!HAS_GMCH_DISPLAY(dev_priv))
5141 allowed_scalers |= BIT(DRM_MODE_SCALE_CENTER);
5142
5143 drm_connector_attach_scaling_mode_property(connector, allowed_scalers);
5144
Maarten Lankhorsteead06d2017-05-01 15:37:55 +02005145 connector->state->scaling_mode = DRM_MODE_SCALE_ASPECT;
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005146
Yuly Novikov53b41832012-10-26 12:04:00 +03005147 }
Chris Wilsonf6849602010-09-19 09:29:33 +01005148}
5149
Imre Deakdada1a92014-01-29 13:25:41 +02005150static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
5151{
Abhay Kumard28d4732016-01-22 17:39:04 -08005152 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02005153 intel_dp->last_power_on = jiffies;
5154 intel_dp->last_backlight_off = jiffies;
5155}
5156
Daniel Vetter67a54562012-10-20 20:57:45 +02005157static void
Imre Deak54648612016-06-16 16:37:22 +03005158intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
5159 struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02005160{
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305161 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03005162 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07005163
Imre Deak8e8232d2016-06-16 16:37:21 +03005164 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02005165
5166 /* Workaround: Need to write PP_CONTROL with the unlock key as
5167 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305168 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02005169
Imre Deak8e8232d2016-06-16 16:37:21 +03005170 pp_on = I915_READ(regs.pp_on);
5171 pp_off = I915_READ(regs.pp_off);
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005172 if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005173 I915_WRITE(regs.pp_ctrl, pp_ctl);
5174 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305175 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005176
5177 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03005178 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
5179 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005180
Imre Deak54648612016-06-16 16:37:22 +03005181 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
5182 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005183
Imre Deak54648612016-06-16 16:37:22 +03005184 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
5185 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005186
Imre Deak54648612016-06-16 16:37:22 +03005187 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
5188 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005189
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005190 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) {
Manasi Navare12c8ca92017-06-26 12:21:45 -07005191 seq->t11_t12 = ((pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
5192 BXT_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305193 } else {
Imre Deak54648612016-06-16 16:37:22 +03005194 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02005195 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305196 }
Imre Deak54648612016-06-16 16:37:22 +03005197}
5198
5199static void
Imre Deakde9c1b62016-06-16 20:01:46 +03005200intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
5201{
5202 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5203 state_name,
5204 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
5205}
5206
5207static void
5208intel_pps_verify_state(struct drm_i915_private *dev_priv,
5209 struct intel_dp *intel_dp)
5210{
5211 struct edp_power_seq hw;
5212 struct edp_power_seq *sw = &intel_dp->pps_delays;
5213
5214 intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
5215
5216 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
5217 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
5218 DRM_ERROR("PPS state mismatch\n");
5219 intel_pps_dump_state("sw", sw);
5220 intel_pps_dump_state("hw", &hw);
5221 }
5222}
5223
5224static void
Imre Deak54648612016-06-16 16:37:22 +03005225intel_dp_init_panel_power_sequencer(struct drm_device *dev,
5226 struct intel_dp *intel_dp)
5227{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005228 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak54648612016-06-16 16:37:22 +03005229 struct edp_power_seq cur, vbt, spec,
5230 *final = &intel_dp->pps_delays;
5231
5232 lockdep_assert_held(&dev_priv->pps_mutex);
5233
5234 /* already initialized? */
5235 if (final->t11_t12 != 0)
5236 return;
5237
5238 intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005239
Imre Deakde9c1b62016-06-16 20:01:46 +03005240 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005241
Jani Nikula6aa23e62016-03-24 17:50:20 +02005242 vbt = dev_priv->vbt.edp.pps;
Manasi Navarec99a2592017-06-30 09:33:48 -07005243 /* On Toshiba Satellite P50-C-18C system the VBT T12 delay
5244 * of 500ms appears to be too short. Ocassionally the panel
5245 * just fails to power back on. Increasing the delay to 800ms
5246 * seems sufficient to avoid this problem.
5247 */
5248 if (dev_priv->quirks & QUIRK_INCREASE_T12_DELAY) {
5249 vbt.t11_t12 = max_t(u16, vbt.t11_t12, 800 * 10);
5250 DRM_DEBUG_KMS("Increasing T12 panel delay as per the quirk to %d\n",
5251 vbt.t11_t12);
5252 }
Manasi Navare770a17a2017-06-26 12:21:44 -07005253 /* T11_T12 delay is special and actually in units of 100ms, but zero
5254 * based in the hw (so we need to add 100 ms). But the sw vbt
5255 * table multiplies it with 1000 to make it in units of 100usec,
5256 * too. */
5257 vbt.t11_t12 += 100 * 10;
Daniel Vetter67a54562012-10-20 20:57:45 +02005258
5259 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5260 * our hw here, which are all in 100usec. */
5261 spec.t1_t3 = 210 * 10;
5262 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5263 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5264 spec.t10 = 500 * 10;
5265 /* This one is special and actually in units of 100ms, but zero
5266 * based in the hw (so we need to add 100 ms). But the sw vbt
5267 * table multiplies it with 1000 to make it in units of 100usec,
5268 * too. */
5269 spec.t11_t12 = (510 + 100) * 10;
5270
Imre Deakde9c1b62016-06-16 20:01:46 +03005271 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005272
5273 /* Use the max of the register settings and vbt. If both are
5274 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005275#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005276 spec.field : \
5277 max(cur.field, vbt.field))
5278 assign_final(t1_t3);
5279 assign_final(t8);
5280 assign_final(t9);
5281 assign_final(t10);
5282 assign_final(t11_t12);
5283#undef assign_final
5284
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005285#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005286 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5287 intel_dp->backlight_on_delay = get_delay(t8);
5288 intel_dp->backlight_off_delay = get_delay(t9);
5289 intel_dp->panel_power_down_delay = get_delay(t10);
5290 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5291#undef get_delay
5292
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005293 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5294 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5295 intel_dp->panel_power_cycle_delay);
5296
5297 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5298 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005299
5300 /*
5301 * We override the HW backlight delays to 1 because we do manual waits
5302 * on them. For T8, even BSpec recommends doing it. For T9, if we
5303 * don't do this, we'll end up waiting for the backlight off delay
5304 * twice: once when we do the manual sleep, and once when we disable
5305 * the panel and wait for the PP_STATUS bit to become zero.
5306 */
5307 final->t8 = 1;
5308 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005309}
5310
5311static void
5312intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005313 struct intel_dp *intel_dp,
5314 bool force_disable_vdd)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005315{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005316 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07005317 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005318 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005319 struct pps_registers regs;
Ville Syrjäläad933b52014-08-18 22:15:56 +03005320 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005321 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005322
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005323 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005324
Imre Deak8e8232d2016-06-16 16:37:21 +03005325 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005326
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005327 /*
5328 * On some VLV machines the BIOS can leave the VDD
5329 * enabled even on power seqeuencers which aren't
5330 * hooked up to any port. This would mess up the
5331 * power domain tracking the first time we pick
5332 * one of these power sequencers for use since
5333 * edp_panel_vdd_on() would notice that the VDD was
5334 * already on and therefore wouldn't grab the power
5335 * domain reference. Disable VDD first to avoid this.
5336 * This also avoids spuriously turning the VDD on as
5337 * soon as the new power seqeuencer gets initialized.
5338 */
5339 if (force_disable_vdd) {
5340 u32 pp = ironlake_get_pp_control(intel_dp);
5341
5342 WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
5343
5344 if (pp & EDP_FORCE_VDD)
5345 DRM_DEBUG_KMS("VDD already on, disabling first\n");
5346
5347 pp &= ~EDP_FORCE_VDD;
5348
5349 I915_WRITE(regs.pp_ctrl, pp);
5350 }
5351
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005352 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005353 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5354 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005355 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005356 /* Compute the divisor for the pp clock, simply match the Bspec
5357 * formula. */
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005358 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005359 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305360 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
Manasi Navare12c8ca92017-06-26 12:21:45 -07005361 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305362 << BXT_POWER_CYCLE_DELAY_SHIFT);
5363 } else {
5364 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5365 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5366 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5367 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005368
5369 /* Haswell doesn't have any port selection bits for the panel
5370 * power sequencer any more. */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005371 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005372 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005373 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005374 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005375 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005376 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005377 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005378 }
5379
Jesse Barnes453c5422013-03-28 09:55:41 -07005380 pp_on |= port_sel;
5381
Imre Deak8e8232d2016-06-16 16:37:21 +03005382 I915_WRITE(regs.pp_on, pp_on);
5383 I915_WRITE(regs.pp_off, pp_off);
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005384 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005385 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305386 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005387 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005388
Daniel Vetter67a54562012-10-20 20:57:45 +02005389 DRM_DEBUG_KMS("panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n",
Imre Deak8e8232d2016-06-16 16:37:21 +03005390 I915_READ(regs.pp_on),
5391 I915_READ(regs.pp_off),
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005392 (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005393 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5394 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005395}
5396
Imre Deak335f7522016-08-10 14:07:32 +03005397static void intel_dp_pps_init(struct drm_device *dev,
5398 struct intel_dp *intel_dp)
5399{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005400 struct drm_i915_private *dev_priv = to_i915(dev);
5401
5402 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Imre Deak335f7522016-08-10 14:07:32 +03005403 vlv_initial_power_sequencer_setup(intel_dp);
5404 } else {
5405 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005406 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak335f7522016-08-10 14:07:32 +03005407 }
5408}
5409
Vandana Kannanb33a2812015-02-13 15:33:03 +05305410/**
5411 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005412 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005413 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305414 * @refresh_rate: RR to be programmed
5415 *
5416 * This function gets called when refresh rate (RR) has to be changed from
5417 * one frequency to another. Switches can be between high and low RR
5418 * supported by the panel or to any other RR based on media playback (in
5419 * this case, RR value needs to be passed from user space).
5420 *
5421 * The caller of this function needs to take a lock on dev_priv->drrs.
5422 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005423static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
5424 struct intel_crtc_state *crtc_state,
5425 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305426{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305427 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305428 struct intel_digital_port *dig_port = NULL;
5429 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005430 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305431 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305432
5433 if (refresh_rate <= 0) {
5434 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5435 return;
5436 }
5437
Vandana Kannan96178ee2015-01-10 02:25:56 +05305438 if (intel_dp == NULL) {
5439 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305440 return;
5441 }
5442
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005443 /*
Rodrigo Vivie4d59f62014-11-20 02:22:08 -08005444 * FIXME: This needs proper synchronization with psr state for some
5445 * platforms that cannot have PSR and DRRS enabled at the same time.
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005446 */
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305447
Vandana Kannan96178ee2015-01-10 02:25:56 +05305448 dig_port = dp_to_dig_port(intel_dp);
5449 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02005450 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305451
5452 if (!intel_crtc) {
5453 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5454 return;
5455 }
5456
Vandana Kannan96178ee2015-01-10 02:25:56 +05305457 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305458 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5459 return;
5460 }
5461
Vandana Kannan96178ee2015-01-10 02:25:56 +05305462 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5463 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305464 index = DRRS_LOW_RR;
5465
Vandana Kannan96178ee2015-01-10 02:25:56 +05305466 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305467 DRM_DEBUG_KMS(
5468 "DRRS requested for previously set RR...ignoring\n");
5469 return;
5470 }
5471
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005472 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305473 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5474 return;
5475 }
5476
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005477 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305478 switch (index) {
5479 case DRRS_HIGH_RR:
5480 intel_dp_set_m_n(intel_crtc, M1_N1);
5481 break;
5482 case DRRS_LOW_RR:
5483 intel_dp_set_m_n(intel_crtc, M2_N2);
5484 break;
5485 case DRRS_MAX_RR:
5486 default:
5487 DRM_ERROR("Unsupported refreshrate type\n");
5488 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005489 } else if (INTEL_GEN(dev_priv) > 6) {
5490 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005491 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305492
Ville Syrjälä649636e2015-09-22 19:50:01 +03005493 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305494 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005495 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305496 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5497 else
5498 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305499 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005500 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305501 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5502 else
5503 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305504 }
5505 I915_WRITE(reg, val);
5506 }
5507
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305508 dev_priv->drrs.refresh_rate_type = index;
5509
5510 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5511}
5512
Vandana Kannanb33a2812015-02-13 15:33:03 +05305513/**
5514 * intel_edp_drrs_enable - init drrs struct if supported
5515 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005516 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305517 *
5518 * Initializes frontbuffer_bits and drrs.dp
5519 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005520void intel_edp_drrs_enable(struct intel_dp *intel_dp,
5521 struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305522{
5523 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005524 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305525
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005526 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305527 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5528 return;
5529 }
5530
5531 mutex_lock(&dev_priv->drrs.mutex);
5532 if (WARN_ON(dev_priv->drrs.dp)) {
5533 DRM_ERROR("DRRS already enabled\n");
5534 goto unlock;
5535 }
5536
5537 dev_priv->drrs.busy_frontbuffer_bits = 0;
5538
5539 dev_priv->drrs.dp = intel_dp;
5540
5541unlock:
5542 mutex_unlock(&dev_priv->drrs.mutex);
5543}
5544
Vandana Kannanb33a2812015-02-13 15:33:03 +05305545/**
5546 * intel_edp_drrs_disable - Disable DRRS
5547 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005548 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305549 *
5550 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005551void intel_edp_drrs_disable(struct intel_dp *intel_dp,
5552 struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305553{
5554 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005555 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305556
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005557 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305558 return;
5559
5560 mutex_lock(&dev_priv->drrs.mutex);
5561 if (!dev_priv->drrs.dp) {
5562 mutex_unlock(&dev_priv->drrs.mutex);
5563 return;
5564 }
5565
5566 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005567 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5568 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305569
5570 dev_priv->drrs.dp = NULL;
5571 mutex_unlock(&dev_priv->drrs.mutex);
5572
5573 cancel_delayed_work_sync(&dev_priv->drrs.work);
5574}
5575
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305576static void intel_edp_drrs_downclock_work(struct work_struct *work)
5577{
5578 struct drm_i915_private *dev_priv =
5579 container_of(work, typeof(*dev_priv), drrs.work.work);
5580 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305581
Vandana Kannan96178ee2015-01-10 02:25:56 +05305582 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305583
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305584 intel_dp = dev_priv->drrs.dp;
5585
5586 if (!intel_dp)
5587 goto unlock;
5588
5589 /*
5590 * The delayed work can race with an invalidate hence we need to
5591 * recheck.
5592 */
5593
5594 if (dev_priv->drrs.busy_frontbuffer_bits)
5595 goto unlock;
5596
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005597 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5598 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5599
5600 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5601 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5602 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305603
5604unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305605 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305606}
5607
Vandana Kannanb33a2812015-02-13 15:33:03 +05305608/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305609 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005610 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305611 * @frontbuffer_bits: frontbuffer plane tracking bits
5612 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305613 * This function gets called everytime rendering on the given planes start.
5614 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305615 *
5616 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5617 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005618void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5619 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305620{
Vandana Kannana93fad02015-01-10 02:25:59 +05305621 struct drm_crtc *crtc;
5622 enum pipe pipe;
5623
Daniel Vetter9da7d692015-04-09 16:44:15 +02005624 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305625 return;
5626
Daniel Vetter88f933a2015-04-09 16:44:16 +02005627 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305628
Vandana Kannana93fad02015-01-10 02:25:59 +05305629 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005630 if (!dev_priv->drrs.dp) {
5631 mutex_unlock(&dev_priv->drrs.mutex);
5632 return;
5633 }
5634
Vandana Kannana93fad02015-01-10 02:25:59 +05305635 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5636 pipe = to_intel_crtc(crtc)->pipe;
5637
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005638 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5639 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5640
Ramalingam C0ddfd202015-06-15 20:50:05 +05305641 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005642 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005643 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5644 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305645
Vandana Kannana93fad02015-01-10 02:25:59 +05305646 mutex_unlock(&dev_priv->drrs.mutex);
5647}
5648
Vandana Kannanb33a2812015-02-13 15:33:03 +05305649/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305650 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005651 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305652 * @frontbuffer_bits: frontbuffer plane tracking bits
5653 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305654 * This function gets called every time rendering on the given planes has
5655 * completed or flip on a crtc is completed. So DRRS should be upclocked
5656 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5657 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305658 *
5659 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5660 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005661void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5662 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305663{
Vandana Kannana93fad02015-01-10 02:25:59 +05305664 struct drm_crtc *crtc;
5665 enum pipe pipe;
5666
Daniel Vetter9da7d692015-04-09 16:44:15 +02005667 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305668 return;
5669
Daniel Vetter88f933a2015-04-09 16:44:16 +02005670 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305671
Vandana Kannana93fad02015-01-10 02:25:59 +05305672 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005673 if (!dev_priv->drrs.dp) {
5674 mutex_unlock(&dev_priv->drrs.mutex);
5675 return;
5676 }
5677
Vandana Kannana93fad02015-01-10 02:25:59 +05305678 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5679 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005680
5681 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305682 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5683
Ramalingam C0ddfd202015-06-15 20:50:05 +05305684 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005685 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005686 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5687 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305688
5689 /*
5690 * flush also means no more activity hence schedule downclock, if all
5691 * other fbs are quiescent too
5692 */
5693 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305694 schedule_delayed_work(&dev_priv->drrs.work,
5695 msecs_to_jiffies(1000));
5696 mutex_unlock(&dev_priv->drrs.mutex);
5697}
5698
Vandana Kannanb33a2812015-02-13 15:33:03 +05305699/**
5700 * DOC: Display Refresh Rate Switching (DRRS)
5701 *
5702 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5703 * which enables swtching between low and high refresh rates,
5704 * dynamically, based on the usage scenario. This feature is applicable
5705 * for internal panels.
5706 *
5707 * Indication that the panel supports DRRS is given by the panel EDID, which
5708 * would list multiple refresh rates for one resolution.
5709 *
5710 * DRRS is of 2 types - static and seamless.
5711 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5712 * (may appear as a blink on screen) and is used in dock-undock scenario.
5713 * Seamless DRRS involves changing RR without any visual effect to the user
5714 * and can be used during normal system usage. This is done by programming
5715 * certain registers.
5716 *
5717 * Support for static/seamless DRRS may be indicated in the VBT based on
5718 * inputs from the panel spec.
5719 *
5720 * DRRS saves power by switching to low RR based on usage scenarios.
5721 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005722 * The implementation is based on frontbuffer tracking implementation. When
5723 * there is a disturbance on the screen triggered by user activity or a periodic
5724 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5725 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5726 * made.
5727 *
5728 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5729 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305730 *
5731 * DRRS can be further extended to support other internal panels and also
5732 * the scenario of video playback wherein RR is set based on the rate
5733 * requested by userspace.
5734 */
5735
5736/**
5737 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5738 * @intel_connector: eDP connector
5739 * @fixed_mode: preferred mode of panel
5740 *
5741 * This function is called only once at driver load to initialize basic
5742 * DRRS stuff.
5743 *
5744 * Returns:
5745 * Downclock mode if panel supports it, else return NULL.
5746 * DRRS support is determined by the presence of downclock mode (apart
5747 * from VBT setting).
5748 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305749static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305750intel_dp_drrs_init(struct intel_connector *intel_connector,
5751 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305752{
5753 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305754 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005755 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305756 struct drm_display_mode *downclock_mode = NULL;
5757
Daniel Vetter9da7d692015-04-09 16:44:15 +02005758 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5759 mutex_init(&dev_priv->drrs.mutex);
5760
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005761 if (INTEL_GEN(dev_priv) <= 6) {
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305762 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5763 return NULL;
5764 }
5765
5766 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005767 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305768 return NULL;
5769 }
5770
5771 downclock_mode = intel_find_panel_downclock
Mika Kaholaa318b4c2016-12-13 10:02:48 +02005772 (dev_priv, fixed_mode, connector);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305773
5774 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305775 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305776 return NULL;
5777 }
5778
Vandana Kannan96178ee2015-01-10 02:25:56 +05305779 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305780
Vandana Kannan96178ee2015-01-10 02:25:56 +05305781 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005782 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305783 return downclock_mode;
5784}
5785
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005786static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005787 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005788{
5789 struct drm_connector *connector = &intel_connector->base;
5790 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005791 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5792 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005793 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005794 struct drm_display_mode *fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305795 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005796 bool has_dpcd;
5797 struct drm_display_mode *scan;
5798 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005799 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005800
5801 if (!is_edp(intel_dp))
5802 return true;
5803
Imre Deak97a824e12016-06-21 11:51:47 +03005804 /*
5805 * On IBX/CPT we may get here with LVDS already registered. Since the
5806 * driver uses the only internal power sequencer available for both
5807 * eDP and LVDS bail out early in this case to prevent interfering
5808 * with an already powered-on LVDS power sequencer.
5809 */
5810 if (intel_get_lvds_encoder(dev)) {
5811 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5812 DRM_INFO("LVDS was detected, not registering eDP\n");
5813
5814 return false;
5815 }
5816
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005817 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005818
5819 intel_dp_init_panel_power_timestamps(intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +03005820 intel_dp_pps_init(dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005821 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005822
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005823 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005824
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005825 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005826 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005827
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005828 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005829 /* if this fails, presume the device is a ghost */
5830 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005831 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005832 }
5833
Daniel Vetter060c8772014-03-21 23:22:35 +01005834 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005835 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005836 if (edid) {
5837 if (drm_add_edid_modes(connector, edid)) {
5838 drm_mode_connector_update_edid_property(connector,
5839 edid);
5840 drm_edid_to_eld(connector, edid);
5841 } else {
5842 kfree(edid);
5843 edid = ERR_PTR(-EINVAL);
5844 }
5845 } else {
5846 edid = ERR_PTR(-ENOENT);
5847 }
5848 intel_connector->edid = edid;
5849
5850 /* prefer fixed mode from EDID if available */
5851 list_for_each_entry(scan, &connector->probed_modes, head) {
5852 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5853 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305854 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305855 intel_connector, fixed_mode);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005856 break;
5857 }
5858 }
5859
5860 /* fallback to VBT if available for eDP */
5861 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5862 fixed_mode = drm_mode_duplicate(dev,
5863 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005864 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005865 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005866 connector->display_info.width_mm = fixed_mode->width_mm;
5867 connector->display_info.height_mm = fixed_mode->height_mm;
5868 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005869 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005870 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005871
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005872 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005873 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5874 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005875
5876 /*
5877 * Figure out the current pipe for the initial backlight setup.
5878 * If the current pipe isn't valid, try the PPS pipe, and if that
5879 * fails just assume pipe A.
5880 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005881 pipe = vlv_active_pipe(intel_dp);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005882
5883 if (pipe != PIPE_A && pipe != PIPE_B)
5884 pipe = intel_dp->pps_pipe;
5885
5886 if (pipe != PIPE_A && pipe != PIPE_B)
5887 pipe = PIPE_A;
5888
5889 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5890 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005891 }
5892
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305893 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005894 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005895 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005896
5897 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005898
5899out_vdd_off:
5900 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5901 /*
5902 * vdd might still be enabled do to the delayed vdd off.
5903 * Make sure vdd is actually turned off here.
5904 */
5905 pps_lock(intel_dp);
5906 edp_panel_vdd_off_sync(intel_dp);
5907 pps_unlock(intel_dp);
5908
5909 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005910}
5911
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005912/* Set up the hotplug pin and aux power domain. */
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005913static void
5914intel_dp_init_connector_port_info(struct intel_digital_port *intel_dig_port)
5915{
5916 struct intel_encoder *encoder = &intel_dig_port->base;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005917 struct intel_dp *intel_dp = &intel_dig_port->dp;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005918
Rodrigo Vivif761bef22017-08-11 11:26:50 -07005919 encoder->hpd_pin = intel_hpd_pin(intel_dig_port->port);
5920
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005921 switch (intel_dig_port->port) {
5922 case PORT_A:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005923 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_A;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005924 break;
5925 case PORT_B:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005926 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_B;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005927 break;
5928 case PORT_C:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005929 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_C;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005930 break;
5931 case PORT_D:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005932 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005933 break;
5934 case PORT_E:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005935 /* FIXME: Check VBT for actual wiring of PORT E */
5936 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005937 break;
5938 default:
5939 MISSING_CASE(intel_dig_port->port);
5940 }
5941}
5942
Manasi Navare93013972017-04-06 16:44:19 +03005943static void intel_dp_modeset_retry_work_fn(struct work_struct *work)
5944{
5945 struct intel_connector *intel_connector;
5946 struct drm_connector *connector;
5947
5948 intel_connector = container_of(work, typeof(*intel_connector),
5949 modeset_retry_work);
5950 connector = &intel_connector->base;
5951 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
5952 connector->name);
5953
5954 /* Grab the locks before changing connector property*/
5955 mutex_lock(&connector->dev->mode_config.mutex);
5956 /* Set connector link status to BAD and send a Uevent to notify
5957 * userspace to do a modeset.
5958 */
5959 drm_mode_connector_set_link_status_property(connector,
5960 DRM_MODE_LINK_STATUS_BAD);
5961 mutex_unlock(&connector->dev->mode_config.mutex);
5962 /* Send Hotplug uevent so userspace can reprobe */
5963 drm_kms_helper_hotplug_event(connector->dev);
5964}
5965
Paulo Zanoni16c25532013-06-12 17:27:25 -03005966bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005967intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5968 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005969{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005970 struct drm_connector *connector = &intel_connector->base;
5971 struct intel_dp *intel_dp = &intel_dig_port->dp;
5972 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5973 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005974 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02005975 enum port port = intel_dig_port->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01005976 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005977
Manasi Navare93013972017-04-06 16:44:19 +03005978 /* Initialize the work for modeset in case of link train failure */
5979 INIT_WORK(&intel_connector->modeset_retry_work,
5980 intel_dp_modeset_retry_work_fn);
5981
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005982 if (WARN(intel_dig_port->max_lanes < 1,
5983 "Not enough lanes (%d) for DP on port %c\n",
5984 intel_dig_port->max_lanes, port_name(port)))
5985 return false;
5986
Jani Nikula55cfc582017-03-28 17:59:04 +03005987 intel_dp_set_source_rates(intel_dp);
5988
Manasi Navared7e8ef02017-02-07 16:54:11 -08005989 intel_dp->reset_link_params = true;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005990 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005991 intel_dp->active_pipe = INVALID_PIPE;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005992
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005993 /* intel_dp vfuncs */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005994 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub6b5e382014-01-20 16:00:59 +00005995 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005996 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005997 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005998 else if (HAS_PCH_SPLIT(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005999 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
6000 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02006001 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006002
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006003 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00006004 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
6005 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02006006 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00006007
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006008 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03006009 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
6010
Daniel Vetter07679352012-09-06 22:15:42 +02006011 /* Preserve the current hw state. */
6012 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03006013 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00006014
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006015 if (intel_dp_is_edp(dev_priv, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05306016 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02006017 else
6018 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04006019
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02006020 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
6021 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
6022
Imre Deakf7d24902013-05-08 13:14:05 +03006023 /*
6024 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
6025 * for DP the encoder type can be set by the caller to
6026 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
6027 */
6028 if (type == DRM_MODE_CONNECTOR_eDP)
6029 intel_encoder->type = INTEL_OUTPUT_EDP;
6030
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006031 /* eDP only on port B and/or C on vlv/chv */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006032 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08006033 is_edp(intel_dp) && port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006034 return false;
6035
Imre Deake7281ea2013-05-08 13:14:08 +03006036 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
6037 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
6038 port_name(port));
6039
Adam Jacksonb3295302010-07-16 14:46:28 -04006040 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006041 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
6042
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006043 connector->interlace_allowed = true;
6044 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08006045
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02006046 intel_dp_init_connector_port_info(intel_dig_port);
6047
Mika Kaholab6339582016-09-09 14:10:52 +03006048 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01006049
Daniel Vetter66a92782012-07-12 20:08:18 +02006050 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01006051 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08006052
Chris Wilsondf0e9242010-09-09 16:20:55 +01006053 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006054
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006055 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02006056 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
6057 else
6058 intel_connector->get_hw_state = intel_connector_get_hw_state;
6059
Dave Airlie0e32b392014-05-02 14:02:48 +10006060 /* init MST on ports that can support it */
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00006061 if (HAS_DP_MST(dev_priv) && !is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03006062 (port == PORT_B || port == PORT_C || port == PORT_D))
6063 intel_dp_mst_encoder_init(intel_dig_port,
6064 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10006065
Ville Syrjälä36b5f422014-10-16 21:27:30 +03006066 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006067 intel_dp_aux_fini(intel_dp);
6068 intel_dp_mst_encoder_cleanup(intel_dig_port);
6069 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03006070 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08006071
Chris Wilsonf6849602010-09-19 09:29:33 +01006072 intel_dp_add_properties(intel_dp, connector);
6073
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006074 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
6075 * 0xd. Failure to do so will result in spurious interrupts being
6076 * generated on the port when a cable is not attached.
6077 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01006078 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006079 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
6080 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
6081 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03006082
6083 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006084
6085fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006086 drm_connector_cleanup(connector);
6087
6088 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006089}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006090
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006091bool intel_dp_init(struct drm_i915_private *dev_priv,
Chris Wilson457c52d2016-06-01 08:27:50 +01006092 i915_reg_t output_reg,
6093 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006094{
6095 struct intel_digital_port *intel_dig_port;
6096 struct intel_encoder *intel_encoder;
6097 struct drm_encoder *encoder;
6098 struct intel_connector *intel_connector;
6099
Daniel Vetterb14c5672013-09-19 12:18:32 +02006100 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006101 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01006102 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006103
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03006104 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306105 if (!intel_connector)
6106 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006107
6108 intel_encoder = &intel_dig_port->base;
6109 encoder = &intel_encoder->base;
6110
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006111 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
6112 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
6113 "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306114 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006115
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01006116 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006117 intel_encoder->disable = intel_disable_dp;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006118 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07006119 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03006120 intel_encoder->suspend = intel_dp_encoder_suspend;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006121 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03006122 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03006123 intel_encoder->pre_enable = chv_pre_enable_dp;
6124 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03006125 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03006126 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01006127 } else if (IS_VALLEYVIEW(dev_priv)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006128 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006129 intel_encoder->pre_enable = vlv_pre_enable_dp;
6130 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03006131 intel_encoder->post_disable = vlv_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006132 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006133 intel_encoder->pre_enable = g4x_pre_enable_dp;
6134 intel_encoder->enable = g4x_enable_dp;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006135 if (INTEL_GEN(dev_priv) >= 5)
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03006136 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006137 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006138
Paulo Zanoni174edf12012-10-26 19:05:50 -02006139 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006140 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02006141 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006142
Ville Syrjäläcca05022016-06-22 21:57:06 +03006143 intel_encoder->type = INTEL_OUTPUT_DP;
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02006144 intel_encoder->power_domain = intel_port_to_power_domain(port);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006145 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03006146 if (port == PORT_D)
6147 intel_encoder->crtc_mask = 1 << 2;
6148 else
6149 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
6150 } else {
6151 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
6152 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02006153 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07006154 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006155
Dave Airlie13cf5502014-06-18 11:29:35 +10006156 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03006157 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10006158
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306159 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
6160 goto err_init_connector;
6161
Chris Wilson457c52d2016-06-01 08:27:50 +01006162 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306163
6164err_init_connector:
6165 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306166err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306167 kfree(intel_connector);
6168err_connector_alloc:
6169 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01006170 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006171}
Dave Airlie0e32b392014-05-02 14:02:48 +10006172
6173void intel_dp_mst_suspend(struct drm_device *dev)
6174{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006175 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006176 int i;
6177
6178 /* disable MST */
6179 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006180 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006181
6182 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006183 continue;
6184
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006185 if (intel_dig_port->dp.is_mst)
6186 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10006187 }
6188}
6189
6190void intel_dp_mst_resume(struct drm_device *dev)
6191{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006192 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006193 int i;
6194
6195 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006196 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006197 int ret;
6198
6199 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006200 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10006201
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006202 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
6203 if (ret)
6204 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10006205 }
6206}