blob: caa8b1e07e7e4a039cb99afdcb052b7912860553 [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/**
Jani Nikula1853a9d2017-08-18 12:30:20 +0300106 * intel_dp_is_edp - is the given port attached to an eDP panel (either CPU or PCH)
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700107 * @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 */
Jani Nikula1853a9d2017-08-18 12:30:20 +0300112bool intel_dp_is_edp(struct intel_dp *intel_dp)
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700113{
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 Navare1a92c702017-06-08 13:41:02 -0700337static bool intel_dp_link_params_valid(struct intel_dp *intel_dp, int link_rate,
338 uint8_t lane_count)
Manasi Navare14c562c2017-04-06 14:00:12 -0700339{
340 /*
341 * FIXME: we need to synchronize the current link parameters with
342 * hardware readout. Currently fast link training doesn't work on
343 * boot-up.
344 */
Manasi Navare1a92c702017-06-08 13:41:02 -0700345 if (link_rate == 0 ||
346 link_rate > intel_dp->max_link_rate)
Manasi Navare14c562c2017-04-06 14:00:12 -0700347 return false;
348
Manasi Navare1a92c702017-06-08 13:41:02 -0700349 if (lane_count == 0 ||
350 lane_count > intel_dp_max_lane_count(intel_dp))
Manasi Navare14c562c2017-04-06 14:00:12 -0700351 return false;
352
353 return true;
354}
355
Manasi Navarefdb14d32016-12-08 19:05:12 -0800356int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
357 int link_rate, uint8_t lane_count)
358{
Jani Nikulab1810a72017-04-06 16:44:11 +0300359 int index;
Manasi Navarefdb14d32016-12-08 19:05:12 -0800360
Jani Nikulab1810a72017-04-06 16:44:11 +0300361 index = intel_dp_rate_index(intel_dp->common_rates,
362 intel_dp->num_common_rates,
363 link_rate);
364 if (index > 0) {
Jani Nikulae6c0c642017-04-06 16:44:12 +0300365 intel_dp->max_link_rate = intel_dp->common_rates[index - 1];
366 intel_dp->max_link_lane_count = lane_count;
Manasi Navarefdb14d32016-12-08 19:05:12 -0800367 } else if (lane_count > 1) {
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300368 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
Jani Nikulae6c0c642017-04-06 16:44:12 +0300369 intel_dp->max_link_lane_count = lane_count >> 1;
Manasi Navarefdb14d32016-12-08 19:05:12 -0800370 } else {
371 DRM_ERROR("Link Training Unsuccessful\n");
372 return -1;
373 }
374
375 return 0;
376}
377
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000378static enum drm_mode_status
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700379intel_dp_mode_valid(struct drm_connector *connector,
380 struct drm_display_mode *mode)
381{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100382 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300383 struct intel_connector *intel_connector = to_intel_connector(connector);
384 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Daniel Vetter36008362013-03-27 00:44:59 +0100385 int target_clock = mode->clock;
386 int max_rate, mode_rate, max_lanes, max_link_clock;
Mika Kahola70ec0642016-09-09 14:10:55 +0300387 int max_dotclk;
388
389 max_dotclk = intel_dp_downstream_max_dotclock(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700390
Jani Nikula1853a9d2017-08-18 12:30:20 +0300391 if (intel_dp_is_edp(intel_dp) && fixed_mode) {
Jani Nikuladd06f902012-10-19 14:51:50 +0300392 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100393 return MODE_PANEL;
394
Jani Nikuladd06f902012-10-19 14:51:50 +0300395 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100396 return MODE_PANEL;
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200397
398 target_clock = fixed_mode->clock;
Zhao Yakui7de56f42010-07-19 09:43:14 +0100399 }
400
Ville Syrjälä50fec212015-03-12 17:10:34 +0200401 max_link_clock = intel_dp_max_link_rate(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300402 max_lanes = intel_dp_max_lane_count(intel_dp);
Daniel Vetter36008362013-03-27 00:44:59 +0100403
404 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
405 mode_rate = intel_dp_link_required(target_clock, 18);
406
Mika Kahola799487f2016-02-02 15:16:38 +0200407 if (mode_rate > max_rate || target_clock > max_dotclk)
Daniel Vetterc4867932012-04-10 10:42:36 +0200408 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700409
410 if (mode->clock < 10000)
411 return MODE_CLOCK_LOW;
412
Daniel Vetter0af78a22012-05-23 11:30:55 +0200413 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
414 return MODE_H_ILLEGAL;
415
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700416 return MODE_OK;
417}
418
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800419uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700420{
421 int i;
422 uint32_t v = 0;
423
424 if (src_bytes > 4)
425 src_bytes = 4;
426 for (i = 0; i < src_bytes; i++)
427 v |= ((uint32_t) src[i]) << ((3-i) * 8);
428 return v;
429}
430
Damien Lespiauc2af70e2015-02-10 19:32:23 +0000431static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700432{
433 int i;
434 if (dst_bytes > 4)
435 dst_bytes = 4;
436 for (i = 0; i < dst_bytes; i++)
437 dst[i] = src >> ((3-i) * 8);
438}
439
Jani Nikulabf13e812013-09-06 07:40:05 +0300440static void
441intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300442 struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300443static void
444intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200445 struct intel_dp *intel_dp,
446 bool force_disable_vdd);
Imre Deak335f7522016-08-10 14:07:32 +0300447static void
448intel_dp_pps_init(struct drm_device *dev, struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300449
Ville Syrjälä773538e82014-09-04 14:54:56 +0300450static void pps_lock(struct intel_dp *intel_dp)
451{
452 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
453 struct intel_encoder *encoder = &intel_dig_port->base;
454 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100455 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300456
457 /*
458 * See vlv_power_sequencer_reset() why we need
459 * a power domain reference here.
460 */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +0200461 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300462
463 mutex_lock(&dev_priv->pps_mutex);
464}
465
466static void pps_unlock(struct intel_dp *intel_dp)
467{
468 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
469 struct intel_encoder *encoder = &intel_dig_port->base;
470 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100471 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300472
473 mutex_unlock(&dev_priv->pps_mutex);
474
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +0200475 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300476}
477
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300478static void
479vlv_power_sequencer_kick(struct intel_dp *intel_dp)
480{
481 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200482 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300483 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300484 bool pll_enabled, release_cl_override = false;
485 enum dpio_phy phy = DPIO_PHY(pipe);
486 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300487 uint32_t DP;
488
489 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
490 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
491 pipe_name(pipe), port_name(intel_dig_port->port)))
492 return;
493
494 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
495 pipe_name(pipe), port_name(intel_dig_port->port));
496
497 /* Preserve the BIOS-computed detected bit. This is
498 * supposed to be read-only.
499 */
500 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
501 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
502 DP |= DP_PORT_WIDTH(1);
503 DP |= DP_LINK_TRAIN_PAT_1;
504
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100505 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300506 DP |= DP_PIPE_SELECT_CHV(pipe);
507 else if (pipe == PIPE_B)
508 DP |= DP_PIPEB_SELECT;
509
Ville Syrjäläd288f652014-10-28 13:20:22 +0200510 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
511
512 /*
513 * The DPLL for the pipe must be enabled for this to work.
514 * So enable temporarily it if it's not already enabled.
515 */
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300516 if (!pll_enabled) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100517 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300518 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
519
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200520 if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ?
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000521 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
522 DRM_ERROR("Failed to force on pll for pipe %c!\n",
523 pipe_name(pipe));
524 return;
525 }
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300526 }
Ville Syrjäläd288f652014-10-28 13:20:22 +0200527
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300528 /*
529 * Similar magic as in intel_dp_enable_port().
530 * We _must_ do this port enable + disable trick
531 * to make this power seqeuencer lock onto the port.
532 * Otherwise even VDD force bit won't work.
533 */
534 I915_WRITE(intel_dp->output_reg, DP);
535 POSTING_READ(intel_dp->output_reg);
536
537 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
538 POSTING_READ(intel_dp->output_reg);
539
540 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
541 POSTING_READ(intel_dp->output_reg);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200542
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300543 if (!pll_enabled) {
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200544 vlv_force_pll_off(dev_priv, pipe);
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300545
546 if (release_cl_override)
547 chv_phy_powergate_ch(dev_priv, phy, ch, false);
548 }
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300549}
550
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200551static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv)
552{
553 struct intel_encoder *encoder;
554 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
555
556 /*
557 * We don't have power sequencer currently.
558 * Pick one that's not used by other ports.
559 */
560 for_each_intel_encoder(&dev_priv->drm, encoder) {
561 struct intel_dp *intel_dp;
562
563 if (encoder->type != INTEL_OUTPUT_DP &&
564 encoder->type != INTEL_OUTPUT_EDP)
565 continue;
566
567 intel_dp = enc_to_intel_dp(&encoder->base);
568
569 if (encoder->type == INTEL_OUTPUT_EDP) {
570 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
571 intel_dp->active_pipe != intel_dp->pps_pipe);
572
573 if (intel_dp->pps_pipe != INVALID_PIPE)
574 pipes &= ~(1 << intel_dp->pps_pipe);
575 } else {
576 WARN_ON(intel_dp->pps_pipe != INVALID_PIPE);
577
578 if (intel_dp->active_pipe != INVALID_PIPE)
579 pipes &= ~(1 << intel_dp->active_pipe);
580 }
581 }
582
583 if (pipes == 0)
584 return INVALID_PIPE;
585
586 return ffs(pipes) - 1;
587}
588
Jani Nikulabf13e812013-09-06 07:40:05 +0300589static enum pipe
590vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
591{
592 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300593 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100594 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300595 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300596
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300597 lockdep_assert_held(&dev_priv->pps_mutex);
598
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300599 /* We should never land here with regular DP ports */
Jani Nikula1853a9d2017-08-18 12:30:20 +0300600 WARN_ON(!intel_dp_is_edp(intel_dp));
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300601
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200602 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
603 intel_dp->active_pipe != intel_dp->pps_pipe);
604
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300605 if (intel_dp->pps_pipe != INVALID_PIPE)
606 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300607
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200608 pipe = vlv_find_free_pps(dev_priv);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300609
610 /*
611 * Didn't find one. This should not happen since there
612 * are two power sequencers and up to two eDP ports.
613 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200614 if (WARN_ON(pipe == INVALID_PIPE))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300615 pipe = PIPE_A;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300616
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300617 vlv_steal_power_sequencer(dev, pipe);
618 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300619
620 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
621 pipe_name(intel_dp->pps_pipe),
622 port_name(intel_dig_port->port));
623
624 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300625 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200626 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300627
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300628 /*
629 * Even vdd force doesn't work until we've made
630 * the power sequencer lock in on the port.
631 */
632 vlv_power_sequencer_kick(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300633
634 return intel_dp->pps_pipe;
635}
636
Imre Deak78597992016-06-16 16:37:20 +0300637static int
638bxt_power_sequencer_idx(struct intel_dp *intel_dp)
639{
640 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
641 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100642 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak78597992016-06-16 16:37:20 +0300643
644 lockdep_assert_held(&dev_priv->pps_mutex);
645
646 /* We should never land here with regular DP ports */
Jani Nikula1853a9d2017-08-18 12:30:20 +0300647 WARN_ON(!intel_dp_is_edp(intel_dp));
Imre Deak78597992016-06-16 16:37:20 +0300648
649 /*
650 * TODO: BXT has 2 PPS instances. The correct port->PPS instance
651 * mapping needs to be retrieved from VBT, for now just hard-code to
652 * use instance #0 always.
653 */
654 if (!intel_dp->pps_reset)
655 return 0;
656
657 intel_dp->pps_reset = false;
658
659 /*
660 * Only the HW needs to be reprogrammed, the SW state is fixed and
661 * has been setup during connector init.
662 */
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200663 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak78597992016-06-16 16:37:20 +0300664
665 return 0;
666}
667
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300668typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
669 enum pipe pipe);
670
671static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
672 enum pipe pipe)
673{
Imre Deak44cb7342016-08-10 14:07:29 +0300674 return I915_READ(PP_STATUS(pipe)) & PP_ON;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300675}
676
677static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
678 enum pipe pipe)
679{
Imre Deak44cb7342016-08-10 14:07:29 +0300680 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300681}
682
683static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
684 enum pipe pipe)
685{
686 return true;
687}
688
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300689static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300690vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
691 enum port port,
692 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300693{
Jani Nikulabf13e812013-09-06 07:40:05 +0300694 enum pipe pipe;
695
Jani Nikulabf13e812013-09-06 07:40:05 +0300696 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
Imre Deak44cb7342016-08-10 14:07:29 +0300697 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
Jani Nikulabf13e812013-09-06 07:40:05 +0300698 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300699
700 if (port_sel != PANEL_PORT_SELECT_VLV(port))
701 continue;
702
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300703 if (!pipe_check(dev_priv, pipe))
704 continue;
705
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300706 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300707 }
708
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300709 return INVALID_PIPE;
710}
711
712static void
713vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
714{
715 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
716 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100717 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300718 enum port port = intel_dig_port->port;
719
720 lockdep_assert_held(&dev_priv->pps_mutex);
721
722 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300723 /* first pick one where the panel is on */
724 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
725 vlv_pipe_has_pp_on);
726 /* didn't find one? pick one where vdd is on */
727 if (intel_dp->pps_pipe == INVALID_PIPE)
728 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
729 vlv_pipe_has_vdd_on);
730 /* didn't find one? pick one with just the correct port */
731 if (intel_dp->pps_pipe == INVALID_PIPE)
732 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
733 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300734
735 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
736 if (intel_dp->pps_pipe == INVALID_PIPE) {
737 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
738 port_name(port));
739 return;
740 }
741
742 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
743 port_name(port), pipe_name(intel_dp->pps_pipe));
744
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300745 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200746 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Jani Nikulabf13e812013-09-06 07:40:05 +0300747}
748
Imre Deak78597992016-06-16 16:37:20 +0300749void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300750{
Chris Wilson91c8a322016-07-05 10:40:23 +0100751 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300752 struct intel_encoder *encoder;
753
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100754 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200755 !IS_GEN9_LP(dev_priv)))
Ville Syrjälä773538e82014-09-04 14:54:56 +0300756 return;
757
758 /*
759 * We can't grab pps_mutex here due to deadlock with power_domain
760 * mutex when power_domain functions are called while holding pps_mutex.
761 * That also means that in order to use pps_pipe the code needs to
762 * hold both a power domain reference and pps_mutex, and the power domain
763 * reference get/put must be done while _not_ holding pps_mutex.
764 * pps_{lock,unlock}() do these steps in the correct order, so one
765 * should use them always.
766 */
767
Jani Nikula19c80542015-12-16 12:48:16 +0200768 for_each_intel_encoder(dev, encoder) {
Ville Syrjälä773538e82014-09-04 14:54:56 +0300769 struct intel_dp *intel_dp;
770
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200771 if (encoder->type != INTEL_OUTPUT_DP &&
772 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300773 continue;
774
775 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200776
777 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
778
779 if (encoder->type != INTEL_OUTPUT_EDP)
780 continue;
781
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200782 if (IS_GEN9_LP(dev_priv))
Imre Deak78597992016-06-16 16:37:20 +0300783 intel_dp->pps_reset = true;
784 else
785 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300786 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300787}
788
Imre Deak8e8232d2016-06-16 16:37:21 +0300789struct pps_registers {
790 i915_reg_t pp_ctrl;
791 i915_reg_t pp_stat;
792 i915_reg_t pp_on;
793 i915_reg_t pp_off;
794 i915_reg_t pp_div;
795};
796
797static void intel_pps_get_registers(struct drm_i915_private *dev_priv,
798 struct intel_dp *intel_dp,
799 struct pps_registers *regs)
800{
Imre Deak44cb7342016-08-10 14:07:29 +0300801 int pps_idx = 0;
802
Imre Deak8e8232d2016-06-16 16:37:21 +0300803 memset(regs, 0, sizeof(*regs));
804
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200805 if (IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300806 pps_idx = bxt_power_sequencer_idx(intel_dp);
807 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
808 pps_idx = vlv_power_sequencer_pipe(intel_dp);
Imre Deak8e8232d2016-06-16 16:37:21 +0300809
Imre Deak44cb7342016-08-10 14:07:29 +0300810 regs->pp_ctrl = PP_CONTROL(pps_idx);
811 regs->pp_stat = PP_STATUS(pps_idx);
812 regs->pp_on = PP_ON_DELAYS(pps_idx);
813 regs->pp_off = PP_OFF_DELAYS(pps_idx);
Rodrigo Vivi938361e2017-06-02 13:06:44 -0700814 if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300815 regs->pp_div = PP_DIVISOR(pps_idx);
Imre Deak8e8232d2016-06-16 16:37:21 +0300816}
817
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200818static i915_reg_t
819_pp_ctrl_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300820{
Imre Deak8e8232d2016-06-16 16:37:21 +0300821 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300822
Imre Deak8e8232d2016-06-16 16:37:21 +0300823 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
824 &regs);
825
826 return regs.pp_ctrl;
Jani Nikulabf13e812013-09-06 07:40:05 +0300827}
828
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200829static i915_reg_t
830_pp_stat_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300831{
Imre Deak8e8232d2016-06-16 16:37:21 +0300832 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300833
Imre Deak8e8232d2016-06-16 16:37:21 +0300834 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
835 &regs);
836
837 return regs.pp_stat;
Jani Nikulabf13e812013-09-06 07:40:05 +0300838}
839
Clint Taylor01527b32014-07-07 13:01:46 -0700840/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
841 This function only applicable when panel PM state is not to be tracked */
842static int edp_notify_handler(struct notifier_block *this, unsigned long code,
843 void *unused)
844{
845 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
846 edp_notifier);
847 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100848 struct drm_i915_private *dev_priv = to_i915(dev);
Clint Taylor01527b32014-07-07 13:01:46 -0700849
Jani Nikula1853a9d2017-08-18 12:30:20 +0300850 if (!intel_dp_is_edp(intel_dp) || code != SYS_RESTART)
Clint Taylor01527b32014-07-07 13:01:46 -0700851 return 0;
852
Ville Syrjälä773538e82014-09-04 14:54:56 +0300853 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300854
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100855 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300856 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200857 i915_reg_t pp_ctrl_reg, pp_div_reg;
Ville Syrjälä649636e2015-09-22 19:50:01 +0300858 u32 pp_div;
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300859
Imre Deak44cb7342016-08-10 14:07:29 +0300860 pp_ctrl_reg = PP_CONTROL(pipe);
861 pp_div_reg = PP_DIVISOR(pipe);
Clint Taylor01527b32014-07-07 13:01:46 -0700862 pp_div = I915_READ(pp_div_reg);
863 pp_div &= PP_REFERENCE_DIVIDER_MASK;
864
865 /* 0x1F write to PP_DIV_REG sets max cycle delay */
866 I915_WRITE(pp_div_reg, pp_div | 0x1F);
867 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
868 msleep(intel_dp->panel_power_cycle_delay);
869 }
870
Ville Syrjälä773538e82014-09-04 14:54:56 +0300871 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300872
Clint Taylor01527b32014-07-07 13:01:46 -0700873 return 0;
874}
875
Daniel Vetter4be73782014-01-17 14:39:48 +0100876static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700877{
Paulo Zanoni30add222012-10-26 19:05:45 -0200878 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100879 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700880
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300881 lockdep_assert_held(&dev_priv->pps_mutex);
882
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100883 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300884 intel_dp->pps_pipe == INVALID_PIPE)
885 return false;
886
Jani Nikulabf13e812013-09-06 07:40:05 +0300887 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700888}
889
Daniel Vetter4be73782014-01-17 14:39:48 +0100890static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700891{
Paulo Zanoni30add222012-10-26 19:05:45 -0200892 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100893 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700894
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300895 lockdep_assert_held(&dev_priv->pps_mutex);
896
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100897 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300898 intel_dp->pps_pipe == INVALID_PIPE)
899 return false;
900
Ville Syrjälä773538e82014-09-04 14:54:56 +0300901 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700902}
903
Keith Packard9b984da2011-09-19 13:54:47 -0700904static void
905intel_dp_check_edp(struct intel_dp *intel_dp)
906{
Paulo Zanoni30add222012-10-26 19:05:45 -0200907 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100908 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700909
Jani Nikula1853a9d2017-08-18 12:30:20 +0300910 if (!intel_dp_is_edp(intel_dp))
Keith Packard9b984da2011-09-19 13:54:47 -0700911 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700912
Daniel Vetter4be73782014-01-17 14:39:48 +0100913 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700914 WARN(1, "eDP powered off while attempting aux channel communication.\n");
915 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300916 I915_READ(_pp_stat_reg(intel_dp)),
917 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700918 }
919}
920
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100921static uint32_t
922intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
923{
924 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
925 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100926 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200927 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100928 uint32_t status;
929 bool done;
930
Daniel Vetteref04f002012-12-01 21:03:59 +0100931#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100932 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300933 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300934 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100935 else
Imre Deak713a6b662016-06-28 13:37:33 +0300936 done = wait_for(C, 10) == 0;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100937 if (!done)
938 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
939 has_aux_irq);
940#undef C
941
942 return status;
943}
944
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200945static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000946{
947 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200948 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000949
Ville Syrjäläa457f542016-03-02 17:22:17 +0200950 if (index)
951 return 0;
952
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000953 /*
954 * The clock divider is based off the hrawclk, and would like to run at
Ville Syrjäläa457f542016-03-02 17:22:17 +0200955 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000956 */
Ville Syrjäläa457f542016-03-02 17:22:17 +0200957 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000958}
959
960static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
961{
962 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200963 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000964
965 if (index)
966 return 0;
967
Ville Syrjäläa457f542016-03-02 17:22:17 +0200968 /*
969 * The clock divider is based off the cdclk or PCH rawclk, and would
970 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
971 * divide by 2000 and use that
972 */
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200973 if (intel_dig_port->port == PORT_A)
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200974 return DIV_ROUND_CLOSEST(dev_priv->cdclk.hw.cdclk, 2000);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200975 else
976 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000977}
978
979static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300980{
981 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200982 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300983
Ville Syrjäläa457f542016-03-02 17:22:17 +0200984 if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300985 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100986 switch (index) {
987 case 0: return 63;
988 case 1: return 72;
989 default: return 0;
990 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300991 }
Ville Syrjäläa457f542016-03-02 17:22:17 +0200992
993 return ilk_get_aux_clock_divider(intel_dp, index);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300994}
995
Damien Lespiaub6b5e382014-01-20 16:00:59 +0000996static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
997{
998 /*
999 * SKL doesn't need us to program the AUX clock divider (Hardware will
1000 * derive the clock from CDCLK automatically). We still implement the
1001 * get_aux_clock_divider vfunc to plug-in into the existing code.
1002 */
1003 return index ? 0 : 1;
1004}
1005
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02001006static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
1007 bool has_aux_irq,
1008 int send_bytes,
1009 uint32_t aux_clock_divider)
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001010{
1011 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin86527442016-10-13 11:03:00 +01001012 struct drm_i915_private *dev_priv =
1013 to_i915(intel_dig_port->base.base.dev);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001014 uint32_t precharge, timeout;
1015
Tvrtko Ursulin86527442016-10-13 11:03:00 +01001016 if (IS_GEN6(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001017 precharge = 3;
1018 else
1019 precharge = 5;
1020
Tvrtko Ursulin86527442016-10-13 11:03:00 +01001021 if (IS_BROADWELL(dev_priv) && intel_dig_port->port == PORT_A)
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001022 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
1023 else
1024 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
1025
1026 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +00001027 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001028 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +00001029 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001030 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +00001031 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001032 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
1033 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +00001034 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001035}
1036
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00001037static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
1038 bool has_aux_irq,
1039 int send_bytes,
1040 uint32_t unused)
1041{
1042 return DP_AUX_CH_CTL_SEND_BUSY |
1043 DP_AUX_CH_CTL_DONE |
1044 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
1045 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1046 DP_AUX_CH_CTL_TIME_OUT_1600us |
1047 DP_AUX_CH_CTL_RECEIVE_ERROR |
1048 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Daniel Vetterd4dcbdc2016-05-18 18:47:15 +02001049 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00001050 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
1051}
1052
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001053static int
Chris Wilsonea5b2132010-08-04 13:50:23 +01001054intel_dp_aux_ch(struct intel_dp *intel_dp,
Daniel Vetterbd9f74a2014-10-02 09:45:35 +02001055 const uint8_t *send, int send_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001056 uint8_t *recv, int recv_size)
1057{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001058 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001059 struct drm_i915_private *dev_priv =
1060 to_i915(intel_dig_port->base.base.dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001061 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Chris Wilsonbc866252013-07-21 16:00:03 +01001062 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001063 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001064 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001065 int try, clock = 0;
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001066 bool has_aux_irq = HAS_AUX_IRQ(dev_priv);
Jani Nikula884f19e2014-03-14 16:51:14 +02001067 bool vdd;
1068
Ville Syrjälä773538e82014-09-04 14:54:56 +03001069 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001070
Ville Syrjälä72c35002014-08-18 22:16:00 +03001071 /*
1072 * We will be called with VDD already enabled for dpcd/edid/oui reads.
1073 * In such cases we want to leave VDD enabled and it's up to upper layers
1074 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
1075 * ourselves.
1076 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001077 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001078
1079 /* dp aux is extremely sensitive to irq latency, hence request the
1080 * lowest possible wakeup latency and so prevent the cpu from going into
1081 * deep sleep states.
1082 */
1083 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001084
Keith Packard9b984da2011-09-19 13:54:47 -07001085 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001086
Jesse Barnes11bee432011-08-01 15:02:20 -07001087 /* Try to wait for any previous AUX channel activity */
1088 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +01001089 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -07001090 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
1091 break;
1092 msleep(1);
1093 }
1094
1095 if (try == 3) {
Mika Kuoppala02196c72015-08-06 16:48:58 +03001096 static u32 last_status = -1;
1097 const u32 status = I915_READ(ch_ctl);
1098
1099 if (status != last_status) {
1100 WARN(1, "dp_aux_ch not started status 0x%08x\n",
1101 status);
1102 last_status = status;
1103 }
1104
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001105 ret = -EBUSY;
1106 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001107 }
1108
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001109 /* Only 5 data registers! */
1110 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
1111 ret = -E2BIG;
1112 goto out;
1113 }
1114
Damien Lespiauec5b01d2014-01-21 13:35:39 +00001115 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +00001116 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
1117 has_aux_irq,
1118 send_bytes,
1119 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001120
Chris Wilsonbc866252013-07-21 16:00:03 +01001121 /* Must try at least 3 times according to DP spec */
1122 for (try = 0; try < 5; try++) {
1123 /* Load the send data into the aux channel data registers */
1124 for (i = 0; i < send_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001125 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001126 intel_dp_pack_aux(send + i,
1127 send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -04001128
Chris Wilsonbc866252013-07-21 16:00:03 +01001129 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001130 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001131
Chris Wilsonbc866252013-07-21 16:00:03 +01001132 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -04001133
Chris Wilsonbc866252013-07-21 16:00:03 +01001134 /* Clear done status and any errors */
1135 I915_WRITE(ch_ctl,
1136 status |
1137 DP_AUX_CH_CTL_DONE |
1138 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1139 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -04001140
Todd Previte74ebf292015-04-15 08:38:41 -07001141 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
Chris Wilsonbc866252013-07-21 16:00:03 +01001142 continue;
Todd Previte74ebf292015-04-15 08:38:41 -07001143
1144 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
1145 * 400us delay required for errors and timeouts
1146 * Timeout errors from the HW already meet this
1147 * requirement so skip to next iteration
1148 */
1149 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1150 usleep_range(400, 500);
1151 continue;
1152 }
Chris Wilsonbc866252013-07-21 16:00:03 +01001153 if (status & DP_AUX_CH_CTL_DONE)
Jim Bridee058c942015-05-27 10:21:48 -07001154 goto done;
Chris Wilsonbc866252013-07-21 16:00:03 +01001155 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001156 }
1157
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001158 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001159 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001160 ret = -EBUSY;
1161 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001162 }
1163
Jim Bridee058c942015-05-27 10:21:48 -07001164done:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001165 /* Check for timeout or receive error.
1166 * Timeouts occur when the sink is not connected
1167 */
Keith Packarda5b3da52009-06-11 22:30:32 -07001168 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001169 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001170 ret = -EIO;
1171 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -07001172 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001173
1174 /* Timeouts occur when the device isn't connected, so they're
1175 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -07001176 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Chris Wilsona5570fe2017-02-23 11:51:02 +00001177 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001178 ret = -ETIMEDOUT;
1179 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001180 }
1181
1182 /* Unload any bytes sent back from the other side */
1183 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
1184 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Rodrigo Vivi14e01882015-12-10 11:12:27 -08001185
1186 /*
1187 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1188 * We have no idea of what happened so we return -EBUSY so
1189 * drm layer takes care for the necessary retries.
1190 */
1191 if (recv_bytes == 0 || recv_bytes > 20) {
1192 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1193 recv_bytes);
1194 /*
1195 * FIXME: This patch was created on top of a series that
1196 * organize the retries at drm level. There EBUSY should
1197 * also take care for 1ms wait before retrying.
1198 * That aux retries re-org is still needed and after that is
1199 * merged we remove this sleep from here.
1200 */
1201 usleep_range(1000, 1500);
1202 ret = -EBUSY;
1203 goto out;
1204 }
1205
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001206 if (recv_bytes > recv_size)
1207 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -04001208
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001209 for (i = 0; i < recv_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001210 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001211 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001212
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001213 ret = recv_bytes;
1214out:
1215 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1216
Jani Nikula884f19e2014-03-14 16:51:14 +02001217 if (vdd)
1218 edp_panel_vdd_off(intel_dp, false);
1219
Ville Syrjälä773538e82014-09-04 14:54:56 +03001220 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001221
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001222 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001223}
1224
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001225#define BARE_ADDRESS_SIZE 3
1226#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +02001227static ssize_t
1228intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001229{
Jani Nikula9d1a1032014-03-14 16:51:15 +02001230 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1231 uint8_t txbuf[20], rxbuf[20];
1232 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001233 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001234
Ville Syrjäläd2d9cbb2015-03-19 11:44:06 +02001235 txbuf[0] = (msg->request << 4) |
1236 ((msg->address >> 16) & 0xf);
1237 txbuf[1] = (msg->address >> 8) & 0xff;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001238 txbuf[2] = msg->address & 0xff;
1239 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001240
Jani Nikula9d1a1032014-03-14 16:51:15 +02001241 switch (msg->request & ~DP_AUX_I2C_MOT) {
1242 case DP_AUX_NATIVE_WRITE:
1243 case DP_AUX_I2C_WRITE:
Ville Syrjäläc1e741222015-08-27 17:23:27 +03001244 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001245 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001246 rxsize = 2; /* 0 or 1 data bytes */
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001247
Jani Nikula9d1a1032014-03-14 16:51:15 +02001248 if (WARN_ON(txsize > 20))
1249 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001250
Ville Syrjälädd788092016-07-28 17:55:04 +03001251 WARN_ON(!msg->buffer != !msg->size);
1252
Imre Deakd81a67c2016-01-29 14:52:26 +02001253 if (msg->buffer)
1254 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001255
Jani Nikula9d1a1032014-03-14 16:51:15 +02001256 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1257 if (ret > 0) {
1258 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001259
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001260 if (ret > 1) {
1261 /* Number of bytes written in a short write. */
1262 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1263 } else {
1264 /* Return payload size. */
1265 ret = msg->size;
1266 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001267 }
Jani Nikula9d1a1032014-03-14 16:51:15 +02001268 break;
1269
1270 case DP_AUX_NATIVE_READ:
1271 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001272 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001273 rxsize = msg->size + 1;
1274
1275 if (WARN_ON(rxsize > 20))
1276 return -E2BIG;
1277
1278 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1279 if (ret > 0) {
1280 msg->reply = rxbuf[0] >> 4;
1281 /*
1282 * Assume happy day, and copy the data. The caller is
1283 * expected to check msg->reply before touching it.
1284 *
1285 * Return payload size.
1286 */
1287 ret--;
1288 memcpy(msg->buffer, rxbuf + 1, ret);
1289 }
1290 break;
1291
1292 default:
1293 ret = -EINVAL;
1294 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001295 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001296
Jani Nikula9d1a1032014-03-14 16:51:15 +02001297 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001298}
1299
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001300static enum port intel_aux_port(struct drm_i915_private *dev_priv,
1301 enum port port)
1302{
1303 const struct ddi_vbt_port_info *info =
1304 &dev_priv->vbt.ddi_port_info[port];
1305 enum port aux_port;
1306
1307 if (!info->alternate_aux_channel) {
1308 DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
1309 port_name(port), port_name(port));
1310 return port;
1311 }
1312
1313 switch (info->alternate_aux_channel) {
1314 case DP_AUX_A:
1315 aux_port = PORT_A;
1316 break;
1317 case DP_AUX_B:
1318 aux_port = PORT_B;
1319 break;
1320 case DP_AUX_C:
1321 aux_port = PORT_C;
1322 break;
1323 case DP_AUX_D:
1324 aux_port = PORT_D;
1325 break;
1326 default:
1327 MISSING_CASE(info->alternate_aux_channel);
1328 aux_port = PORT_A;
1329 break;
1330 }
1331
1332 DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
1333 port_name(aux_port), port_name(port));
1334
1335 return aux_port;
1336}
1337
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001338static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001339 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001340{
1341 switch (port) {
1342 case PORT_B:
1343 case PORT_C:
1344 case PORT_D:
1345 return DP_AUX_CH_CTL(port);
1346 default:
1347 MISSING_CASE(port);
1348 return DP_AUX_CH_CTL(PORT_B);
1349 }
1350}
1351
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001352static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001353 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001354{
1355 switch (port) {
1356 case PORT_B:
1357 case PORT_C:
1358 case PORT_D:
1359 return DP_AUX_CH_DATA(port, index);
1360 default:
1361 MISSING_CASE(port);
1362 return DP_AUX_CH_DATA(PORT_B, index);
1363 }
1364}
1365
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001366static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001367 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001368{
1369 switch (port) {
1370 case PORT_A:
1371 return DP_AUX_CH_CTL(port);
1372 case PORT_B:
1373 case PORT_C:
1374 case PORT_D:
1375 return PCH_DP_AUX_CH_CTL(port);
1376 default:
1377 MISSING_CASE(port);
1378 return DP_AUX_CH_CTL(PORT_A);
1379 }
1380}
1381
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001382static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001383 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001384{
1385 switch (port) {
1386 case PORT_A:
1387 return DP_AUX_CH_DATA(port, index);
1388 case PORT_B:
1389 case PORT_C:
1390 case PORT_D:
1391 return PCH_DP_AUX_CH_DATA(port, index);
1392 default:
1393 MISSING_CASE(port);
1394 return DP_AUX_CH_DATA(PORT_A, index);
1395 }
1396}
1397
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001398static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001399 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001400{
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001401 switch (port) {
1402 case PORT_A:
1403 case PORT_B:
1404 case PORT_C:
1405 case PORT_D:
1406 return DP_AUX_CH_CTL(port);
1407 default:
1408 MISSING_CASE(port);
1409 return DP_AUX_CH_CTL(PORT_A);
1410 }
1411}
1412
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001413static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001414 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001415{
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001416 switch (port) {
1417 case PORT_A:
1418 case PORT_B:
1419 case PORT_C:
1420 case PORT_D:
1421 return DP_AUX_CH_DATA(port, index);
1422 default:
1423 MISSING_CASE(port);
1424 return DP_AUX_CH_DATA(PORT_A, index);
1425 }
1426}
1427
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001428static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001429 enum port port)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001430{
1431 if (INTEL_INFO(dev_priv)->gen >= 9)
1432 return skl_aux_ctl_reg(dev_priv, port);
1433 else if (HAS_PCH_SPLIT(dev_priv))
1434 return ilk_aux_ctl_reg(dev_priv, port);
1435 else
1436 return g4x_aux_ctl_reg(dev_priv, port);
1437}
1438
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001439static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001440 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001441{
1442 if (INTEL_INFO(dev_priv)->gen >= 9)
1443 return skl_aux_data_reg(dev_priv, port, index);
1444 else if (HAS_PCH_SPLIT(dev_priv))
1445 return ilk_aux_data_reg(dev_priv, port, index);
1446 else
1447 return g4x_aux_data_reg(dev_priv, port, index);
1448}
1449
1450static void intel_aux_reg_init(struct intel_dp *intel_dp)
1451{
1452 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001453 enum port port = intel_aux_port(dev_priv,
1454 dp_to_dig_port(intel_dp)->port);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001455 int i;
1456
1457 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1458 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1459 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1460}
1461
Jani Nikula9d1a1032014-03-14 16:51:15 +02001462static void
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001463intel_dp_aux_fini(struct intel_dp *intel_dp)
1464{
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001465 kfree(intel_dp->aux.name);
1466}
1467
Chris Wilson7a418e32016-06-24 14:00:14 +01001468static void
Mika Kaholab6339582016-09-09 14:10:52 +03001469intel_dp_aux_init(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001470{
Jani Nikula33ad6622014-03-14 16:51:16 +02001471 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1472 enum port port = intel_dig_port->port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001473
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001474 intel_aux_reg_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01001475 drm_dp_aux_init(&intel_dp->aux);
David Flynn8316f332010-12-08 16:10:21 +00001476
Chris Wilson7a418e32016-06-24 14:00:14 +01001477 /* Failure to allocate our preferred name is not critical */
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001478 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
Jani Nikula9d1a1032014-03-14 16:51:15 +02001479 intel_dp->aux.transfer = intel_dp_aux_transfer;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001480}
1481
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001482bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301483{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001484 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Navare, Manasi D577c5432016-09-27 16:36:53 -07001485 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001486
Navare, Manasi D577c5432016-09-27 16:36:53 -07001487 if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
1488 IS_BROADWELL(dev_priv) || (INTEL_GEN(dev_priv) >= 9))
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301489 return true;
1490 else
1491 return false;
1492}
1493
Daniel Vetter0e503382014-07-04 11:26:04 -03001494static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001495intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001496 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001497{
1498 struct drm_device *dev = encoder->base.dev;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001499 struct drm_i915_private *dev_priv = to_i915(dev);
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001500 const struct dp_link_dpll *divisor = NULL;
1501 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001502
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001503 if (IS_G4X(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001504 divisor = gen4_dpll;
1505 count = ARRAY_SIZE(gen4_dpll);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001506 } else if (HAS_PCH_SPLIT(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001507 divisor = pch_dpll;
1508 count = ARRAY_SIZE(pch_dpll);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001509 } else if (IS_CHERRYVIEW(dev_priv)) {
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001510 divisor = chv_dpll;
1511 count = ARRAY_SIZE(chv_dpll);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001512 } else if (IS_VALLEYVIEW(dev_priv)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001513 divisor = vlv_dpll;
1514 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001515 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001516
1517 if (divisor && count) {
1518 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001519 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001520 pipe_config->dpll = divisor[i].dpll;
1521 pipe_config->clock_set = true;
1522 break;
1523 }
1524 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001525 }
1526}
1527
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001528static void snprintf_int_array(char *str, size_t len,
1529 const int *array, int nelem)
1530{
1531 int i;
1532
1533 str[0] = '\0';
1534
1535 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001536 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001537 if (r >= len)
1538 return;
1539 str += r;
1540 len -= r;
1541 }
1542}
1543
1544static void intel_dp_print_rates(struct intel_dp *intel_dp)
1545{
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001546 char str[128]; /* FIXME: too big for stack? */
1547
1548 if ((drm_debug & DRM_UT_KMS) == 0)
1549 return;
1550
Jani Nikula55cfc582017-03-28 17:59:04 +03001551 snprintf_int_array(str, sizeof(str),
1552 intel_dp->source_rates, intel_dp->num_source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001553 DRM_DEBUG_KMS("source rates: %s\n", str);
1554
Jani Nikula68f357c2017-03-28 17:59:05 +03001555 snprintf_int_array(str, sizeof(str),
1556 intel_dp->sink_rates, intel_dp->num_sink_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001557 DRM_DEBUG_KMS("sink rates: %s\n", str);
1558
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001559 snprintf_int_array(str, sizeof(str),
1560 intel_dp->common_rates, intel_dp->num_common_rates);
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001561 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001562}
1563
Ville Syrjälä50fec212015-03-12 17:10:34 +02001564int
1565intel_dp_max_link_rate(struct intel_dp *intel_dp)
1566{
Ville Syrjälä50fec212015-03-12 17:10:34 +02001567 int len;
1568
Jani Nikulae6c0c642017-04-06 16:44:12 +03001569 len = intel_dp_common_len_rate_limit(intel_dp, intel_dp->max_link_rate);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001570 if (WARN_ON(len <= 0))
1571 return 162000;
1572
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001573 return intel_dp->common_rates[len - 1];
Ville Syrjälä50fec212015-03-12 17:10:34 +02001574}
1575
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001576int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1577{
Jani Nikula8001b752017-03-28 17:59:03 +03001578 int i = intel_dp_rate_index(intel_dp->sink_rates,
1579 intel_dp->num_sink_rates, rate);
Jani Nikulab5c72b22017-03-28 17:59:02 +03001580
1581 if (WARN_ON(i < 0))
1582 i = 0;
1583
1584 return i;
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001585}
1586
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001587void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1588 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001589{
Jani Nikula68f357c2017-03-28 17:59:05 +03001590 /* eDP 1.4 rate select method. */
1591 if (intel_dp->use_rate_select) {
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001592 *link_bw = 0;
1593 *rate_select =
1594 intel_dp_rate_select(intel_dp, port_clock);
1595 } else {
1596 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1597 *rate_select = 0;
1598 }
1599}
1600
Jani Nikulaf580bea2016-09-15 16:28:52 +03001601static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1602 struct intel_crtc_state *pipe_config)
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001603{
1604 int bpp, bpc;
1605
1606 bpp = pipe_config->pipe_bpp;
1607 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1608
1609 if (bpc > 0)
1610 bpp = min(bpp, 3*bpc);
1611
Manasi Navare611032b2017-01-24 08:21:49 -08001612 /* For DP Compliance we override the computed bpp for the pipe */
1613 if (intel_dp->compliance.test_data.bpc != 0) {
1614 pipe_config->pipe_bpp = 3*intel_dp->compliance.test_data.bpc;
1615 pipe_config->dither_force_disable = pipe_config->pipe_bpp == 6*3;
1616 DRM_DEBUG_KMS("Setting pipe_bpp to %d\n",
1617 pipe_config->pipe_bpp);
1618 }
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001619 return bpp;
1620}
1621
Jim Bridedc911f52017-08-09 12:48:53 -07001622static bool intel_edp_compare_alt_mode(struct drm_display_mode *m1,
1623 struct drm_display_mode *m2)
1624{
1625 bool bres = false;
1626
1627 if (m1 && m2)
1628 bres = (m1->hdisplay == m2->hdisplay &&
1629 m1->hsync_start == m2->hsync_start &&
1630 m1->hsync_end == m2->hsync_end &&
1631 m1->htotal == m2->htotal &&
1632 m1->vdisplay == m2->vdisplay &&
1633 m1->vsync_start == m2->vsync_start &&
1634 m1->vsync_end == m2->vsync_end &&
1635 m1->vtotal == m2->vtotal);
1636 return bres;
1637}
1638
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001639bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001640intel_dp_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001641 struct intel_crtc_state *pipe_config,
1642 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001643{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001644 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001645 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001646 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001647 enum port port = dp_to_dig_port(intel_dp)->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001648 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001649 struct intel_connector *intel_connector = intel_dp->attached_connector;
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001650 struct intel_digital_connector_state *intel_conn_state =
1651 to_intel_digital_connector_state(conn_state);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001652 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001653 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001654 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001655 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001656 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301657 int max_clock;
Daniel Vetter083f9562012-04-20 20:23:49 +02001658 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001659 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001660 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001661 uint8_t link_bw, rate_select;
Jani Nikulab31e85e2017-05-18 14:10:25 +03001662 bool reduce_m_n = drm_dp_has_quirk(&intel_dp->desc,
1663 DP_DPCD_QUIRK_LIMITED_M_N);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301664
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001665 common_len = intel_dp_common_len_rate_limit(intel_dp,
Jani Nikulae6c0c642017-04-06 16:44:12 +03001666 intel_dp->max_link_rate);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301667
1668 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001669 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301670
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001671 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001672
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001673 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001674 pipe_config->has_pch_encoder = true;
1675
Vandana Kannanf769cd22014-08-05 07:51:22 -07001676 pipe_config->has_drrs = false;
Maarten Lankhorste6b72c92017-05-01 15:38:00 +02001677 if (port == PORT_A)
1678 pipe_config->has_audio = false;
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001679 else if (intel_conn_state->force_audio == HDMI_AUDIO_AUTO)
Maarten Lankhorste6b72c92017-05-01 15:38:00 +02001680 pipe_config->has_audio = intel_dp->has_audio;
1681 else
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001682 pipe_config->has_audio = intel_conn_state->force_audio == HDMI_AUDIO_ON;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001683
Jani Nikula1853a9d2017-08-18 12:30:20 +03001684 if (intel_dp_is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
Jim Bridedc911f52017-08-09 12:48:53 -07001685 struct drm_display_mode *panel_mode =
1686 intel_connector->panel.alt_fixed_mode;
1687 struct drm_display_mode *req_mode = &pipe_config->base.mode;
1688
1689 if (!intel_edp_compare_alt_mode(req_mode, panel_mode))
1690 panel_mode = intel_connector->panel.fixed_mode;
1691
1692 drm_mode_debug_printmodeline(panel_mode);
1693
1694 intel_fixed_panel_mode(panel_mode, adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001695
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001696 if (INTEL_GEN(dev_priv) >= 9) {
Chandra Kondurua1b22782015-04-07 15:28:45 -07001697 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001698 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001699 if (ret)
1700 return ret;
1701 }
1702
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001703 if (HAS_GMCH_DISPLAY(dev_priv))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001704 intel_gmch_panel_fitting(intel_crtc, pipe_config,
Maarten Lankhorsteead06d2017-05-01 15:37:55 +02001705 conn_state->scaling_mode);
Jesse Barnes2dd24552013-04-25 12:55:01 -07001706 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001707 intel_pch_panel_fitting(intel_crtc, pipe_config,
Maarten Lankhorsteead06d2017-05-01 15:37:55 +02001708 conn_state->scaling_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001709 }
1710
Daniel Vettercb1793c2012-06-04 18:39:21 +02001711 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001712 return false;
1713
Manasi Navareda15f7c2017-01-24 08:16:34 -08001714 /* Use values requested by Compliance Test Request */
1715 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
Jani Nikulaec990e22017-04-06 16:44:15 +03001716 int index;
1717
Manasi Navare140ef132017-06-08 13:41:03 -07001718 /* Validate the compliance test data since max values
1719 * might have changed due to link train fallback.
1720 */
1721 if (intel_dp_link_params_valid(intel_dp, intel_dp->compliance.test_link_rate,
1722 intel_dp->compliance.test_lane_count)) {
1723 index = intel_dp_rate_index(intel_dp->common_rates,
1724 intel_dp->num_common_rates,
1725 intel_dp->compliance.test_link_rate);
1726 if (index >= 0)
1727 min_clock = max_clock = index;
1728 min_lane_count = max_lane_count = intel_dp->compliance.test_lane_count;
1729 }
Manasi Navareda15f7c2017-01-24 08:16:34 -08001730 }
Daniel Vetter083f9562012-04-20 20:23:49 +02001731 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301732 "max bw %d pixel clock %iKHz\n",
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001733 max_lane_count, intel_dp->common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001734 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001735
Daniel Vetter36008362013-03-27 00:44:59 +01001736 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1737 * bpc in between. */
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001738 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
Jani Nikula1853a9d2017-08-18 12:30:20 +03001739 if (intel_dp_is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301740
1741 /* Get bpp from vbt only for panels that dont have bpp in edid */
1742 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001743 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001744 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001745 dev_priv->vbt.edp.bpp);
1746 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001747 }
1748
Jani Nikula344c5bb2014-09-09 11:25:13 +03001749 /*
1750 * Use the maximum clock and number of lanes the eDP panel
1751 * advertizes being capable of. The panels are generally
1752 * designed to support only a single clock and lane
1753 * configuration, and typically these values correspond to the
1754 * native resolution of the panel.
1755 */
1756 min_lane_count = max_lane_count;
1757 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001758 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001759
Daniel Vetter36008362013-03-27 00:44:59 +01001760 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001761 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1762 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001763
Dave Airliec6930992014-07-14 11:04:39 +10001764 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301765 for (lane_count = min_lane_count;
1766 lane_count <= max_lane_count;
1767 lane_count <<= 1) {
1768
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001769 link_clock = intel_dp->common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001770 link_avail = intel_dp_max_data_rate(link_clock,
1771 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001772
Daniel Vetter36008362013-03-27 00:44:59 +01001773 if (mode_rate <= link_avail) {
1774 goto found;
1775 }
1776 }
1777 }
1778 }
1779
1780 return false;
1781
1782found:
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001783 if (intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_AUTO) {
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001784 /*
1785 * See:
1786 * CEA-861-E - 5.1 Default Encoding Parameters
1787 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1788 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001789 pipe_config->limited_color_range =
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02001790 bpp != 18 &&
1791 drm_default_rgb_quant_range(adjusted_mode) ==
1792 HDMI_QUANTIZATION_RANGE_LIMITED;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001793 } else {
1794 pipe_config->limited_color_range =
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001795 intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_LIMITED;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001796 }
1797
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001798 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301799
Daniel Vetter657445f2013-05-04 10:09:18 +02001800 pipe_config->pipe_bpp = bpp;
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001801 pipe_config->port_clock = intel_dp->common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001802
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001803 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1804 &link_bw, &rate_select);
1805
1806 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1807 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001808 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001809 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1810 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001811
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001812 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001813 adjusted_mode->crtc_clock,
1814 pipe_config->port_clock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03001815 &pipe_config->dp_m_n,
1816 reduce_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001817
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301818 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301819 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001820 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301821 intel_link_compute_m_n(bpp, lane_count,
1822 intel_connector->panel.downclock_mode->clock,
1823 pipe_config->port_clock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03001824 &pipe_config->dp_m2_n2,
1825 reduce_m_n);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301826 }
1827
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001828 /*
1829 * DPLL0 VCO may need to be adjusted to get the correct
1830 * clock for eDP. This will affect cdclk as well.
1831 */
Jani Nikula1853a9d2017-08-18 12:30:20 +03001832 if (intel_dp_is_edp(intel_dp) && IS_GEN9_BC(dev_priv)) {
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001833 int vco;
1834
1835 switch (pipe_config->port_clock / 2) {
1836 case 108000:
1837 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001838 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001839 break;
1840 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001841 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001842 break;
1843 }
1844
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +02001845 to_intel_atomic_state(pipe_config->base.state)->cdclk.logical.vco = vco;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001846 }
1847
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001848 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001849 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001850
Daniel Vetter36008362013-03-27 00:44:59 +01001851 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001852}
1853
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001854void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001855 int link_rate, uint8_t lane_count,
1856 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001857{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001858 intel_dp->link_rate = link_rate;
1859 intel_dp->lane_count = lane_count;
1860 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001861}
1862
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001863static void intel_dp_prepare(struct intel_encoder *encoder,
1864 struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001865{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001866 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001867 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001868 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001869 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001870 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001871 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001872
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001873 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1874 pipe_config->lane_count,
1875 intel_crtc_has_type(pipe_config,
1876 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001877
Keith Packard417e8222011-11-01 19:54:11 -07001878 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001879 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001880 *
1881 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001882 * SNB CPU
1883 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001884 * CPT PCH
1885 *
1886 * IBX PCH and CPU are the same for almost everything,
1887 * except that the CPU DP PLL is configured in this
1888 * register
1889 *
1890 * CPT PCH is quite different, having many bits moved
1891 * to the TRANS_DP_CTL register instead. That
1892 * configuration happens (oddly) in ironlake_pch_enable
1893 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001894
Keith Packard417e8222011-11-01 19:54:11 -07001895 /* Preserve the BIOS-computed detected bit. This is
1896 * supposed to be read-only.
1897 */
1898 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001899
Keith Packard417e8222011-11-01 19:54:11 -07001900 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001901 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001902 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001903
Keith Packard417e8222011-11-01 19:54:11 -07001904 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001905
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001906 if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001907 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1908 intel_dp->DP |= DP_SYNC_HS_HIGH;
1909 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1910 intel_dp->DP |= DP_SYNC_VS_HIGH;
1911 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1912
Jani Nikula6aba5b62013-10-04 15:08:10 +03001913 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001914 intel_dp->DP |= DP_ENHANCED_FRAMING;
1915
Daniel Vetter7c62a162013-06-01 17:16:20 +02001916 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001917 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001918 u32 trans_dp;
1919
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001920 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001921
1922 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1923 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1924 trans_dp |= TRANS_DP_ENH_FRAMING;
1925 else
1926 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1927 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001928 } else {
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02001929 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001930 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001931
1932 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1933 intel_dp->DP |= DP_SYNC_HS_HIGH;
1934 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1935 intel_dp->DP |= DP_SYNC_VS_HIGH;
1936 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1937
Jani Nikula6aba5b62013-10-04 15:08:10 +03001938 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001939 intel_dp->DP |= DP_ENHANCED_FRAMING;
1940
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001941 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001942 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001943 else if (crtc->pipe == PIPE_B)
1944 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001945 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001946}
1947
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001948#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1949#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001950
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001951#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1952#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001953
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001954#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1955#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001956
Imre Deakde9c1b62016-06-16 20:01:46 +03001957static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
1958 struct intel_dp *intel_dp);
1959
Daniel Vetter4be73782014-01-17 14:39:48 +01001960static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001961 u32 mask,
1962 u32 value)
1963{
Paulo Zanoni30add222012-10-26 19:05:45 -02001964 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001965 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001966 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001967
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001968 lockdep_assert_held(&dev_priv->pps_mutex);
1969
Imre Deakde9c1b62016-06-16 20:01:46 +03001970 intel_pps_verify_state(dev_priv, intel_dp);
1971
Jani Nikulabf13e812013-09-06 07:40:05 +03001972 pp_stat_reg = _pp_stat_reg(intel_dp);
1973 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001974
1975 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001976 mask, value,
1977 I915_READ(pp_stat_reg),
1978 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001979
Chris Wilson9036ff02016-06-30 15:33:09 +01001980 if (intel_wait_for_register(dev_priv,
1981 pp_stat_reg, mask, value,
1982 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001983 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001984 I915_READ(pp_stat_reg),
1985 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001986
1987 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001988}
1989
Daniel Vetter4be73782014-01-17 14:39:48 +01001990static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001991{
1992 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001993 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001994}
1995
Daniel Vetter4be73782014-01-17 14:39:48 +01001996static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001997{
Keith Packardbd943152011-09-18 23:09:52 -07001998 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001999 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07002000}
Keith Packardbd943152011-09-18 23:09:52 -07002001
Daniel Vetter4be73782014-01-17 14:39:48 +01002002static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07002003{
Abhay Kumard28d4732016-01-22 17:39:04 -08002004 ktime_t panel_power_on_time;
2005 s64 panel_power_off_duration;
2006
Keith Packard99ea7122011-11-01 19:57:50 -07002007 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02002008
Abhay Kumard28d4732016-01-22 17:39:04 -08002009 /* take the difference of currrent time and panel power off time
2010 * and then make panel wait for t11_t12 if needed. */
2011 panel_power_on_time = ktime_get_boottime();
2012 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
2013
Paulo Zanonidce56b32013-12-19 14:29:40 -02002014 /* When we disable the VDD override bit last we have to do the manual
2015 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08002016 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
2017 wait_remaining_ms_from_jiffies(jiffies,
2018 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002019
Daniel Vetter4be73782014-01-17 14:39:48 +01002020 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07002021}
Keith Packardbd943152011-09-18 23:09:52 -07002022
Daniel Vetter4be73782014-01-17 14:39:48 +01002023static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02002024{
2025 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
2026 intel_dp->backlight_on_delay);
2027}
2028
Daniel Vetter4be73782014-01-17 14:39:48 +01002029static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02002030{
2031 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
2032 intel_dp->backlight_off_delay);
2033}
Keith Packard99ea7122011-11-01 19:57:50 -07002034
Keith Packard832dd3c2011-11-01 19:34:06 -07002035/* Read the current pp_control value, unlocking the register if it
2036 * is locked
2037 */
2038
Jesse Barnes453c5422013-03-28 09:55:41 -07002039static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07002040{
Jesse Barnes453c5422013-03-28 09:55:41 -07002041 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002042 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07002043 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07002044
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002045 lockdep_assert_held(&dev_priv->pps_mutex);
2046
Jani Nikulabf13e812013-09-06 07:40:05 +03002047 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03002048 if (WARN_ON(!HAS_DDI(dev_priv) &&
2049 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05302050 control &= ~PANEL_UNLOCK_MASK;
2051 control |= PANEL_UNLOCK_REGS;
2052 }
Keith Packard832dd3c2011-11-01 19:34:06 -07002053 return control;
Keith Packardbd943152011-09-18 23:09:52 -07002054}
2055
Ville Syrjälä951468f2014-09-04 14:55:31 +03002056/*
2057 * Must be paired with edp_panel_vdd_off().
2058 * Must hold pps_mutex around the whole on/off sequence.
2059 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2060 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03002061static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002062{
Paulo Zanoni30add222012-10-26 19:05:45 -02002063 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002064 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002065 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes5d613502011-01-24 17:10:54 -08002066 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002067 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002068 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08002069
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002070 lockdep_assert_held(&dev_priv->pps_mutex);
2071
Jani Nikula1853a9d2017-08-18 12:30:20 +03002072 if (!intel_dp_is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002073 return false;
Keith Packardbd943152011-09-18 23:09:52 -07002074
Egbert Eich2c623c12014-11-25 12:54:57 +01002075 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002076 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07002077
Daniel Vetter4be73782014-01-17 14:39:48 +01002078 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002079 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002080
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002081 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002082
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002083 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
2084 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07002085
Daniel Vetter4be73782014-01-17 14:39:48 +01002086 if (!edp_have_panel_power(intel_dp))
2087 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07002088
Jesse Barnes453c5422013-03-28 09:55:41 -07002089 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002090 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07002091
Jani Nikulabf13e812013-09-06 07:40:05 +03002092 pp_stat_reg = _pp_stat_reg(intel_dp);
2093 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002094
2095 I915_WRITE(pp_ctrl_reg, pp);
2096 POSTING_READ(pp_ctrl_reg);
2097 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2098 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07002099 /*
2100 * If the panel wasn't on, delay before accessing aux channel
2101 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002102 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002103 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
2104 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07002105 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07002106 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002107
2108 return need_to_disable;
2109}
2110
Ville Syrjälä951468f2014-09-04 14:55:31 +03002111/*
2112 * Must be paired with intel_edp_panel_vdd_off() or
2113 * intel_edp_panel_off().
2114 * Nested calls to these functions are not allowed since
2115 * we drop the lock. Caller must use some higher level
2116 * locking to prevent nested calls from other threads.
2117 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01002118void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002119{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002120 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002121
Jani Nikula1853a9d2017-08-18 12:30:20 +03002122 if (!intel_dp_is_edp(intel_dp))
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002123 return;
2124
Ville Syrjälä773538e82014-09-04 14:54:56 +03002125 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002126 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002127 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002128
Rob Clarke2c719b2014-12-15 13:56:32 -05002129 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002130 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08002131}
2132
Daniel Vetter4be73782014-01-17 14:39:48 +01002133static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002134{
Paulo Zanoni30add222012-10-26 19:05:45 -02002135 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002136 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002137 struct intel_digital_port *intel_dig_port =
2138 dp_to_dig_port(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002139 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002140 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002141
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002142 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002143
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002144 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002145
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002146 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002147 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002148
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002149 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2150 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002151
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002152 pp = ironlake_get_pp_control(intel_dp);
2153 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002154
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002155 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2156 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002157
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002158 I915_WRITE(pp_ctrl_reg, pp);
2159 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002160
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002161 /* Make sure sequencer is idle before allowing subsequent activity */
2162 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2163 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002164
Imre Deak5a162e22016-08-10 14:07:30 +03002165 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002166 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002167
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002168 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002169}
2170
Daniel Vetter4be73782014-01-17 14:39:48 +01002171static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002172{
2173 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2174 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002175
Ville Syrjälä773538e82014-09-04 14:54:56 +03002176 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002177 if (!intel_dp->want_panel_vdd)
2178 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002179 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002180}
2181
Imre Deakaba86892014-07-30 15:57:31 +03002182static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2183{
2184 unsigned long delay;
2185
2186 /*
2187 * Queue the timer to fire a long time from now (relative to the power
2188 * down delay) to keep the panel power up across a sequence of
2189 * operations.
2190 */
2191 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2192 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2193}
2194
Ville Syrjälä951468f2014-09-04 14:55:31 +03002195/*
2196 * Must be paired with edp_panel_vdd_on().
2197 * Must hold pps_mutex around the whole on/off sequence.
2198 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2199 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002200static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002201{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002202 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002203
2204 lockdep_assert_held(&dev_priv->pps_mutex);
2205
Jani Nikula1853a9d2017-08-18 12:30:20 +03002206 if (!intel_dp_is_edp(intel_dp))
Keith Packard97af61f572011-09-28 16:23:51 -07002207 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002208
Rob Clarke2c719b2014-12-15 13:56:32 -05002209 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002210 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002211
Keith Packardbd943152011-09-18 23:09:52 -07002212 intel_dp->want_panel_vdd = false;
2213
Imre Deakaba86892014-07-30 15:57:31 +03002214 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002215 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002216 else
2217 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002218}
2219
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002220static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002221{
Paulo Zanoni30add222012-10-26 19:05:45 -02002222 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002223 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002224 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002225 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002226
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002227 lockdep_assert_held(&dev_priv->pps_mutex);
2228
Jani Nikula1853a9d2017-08-18 12:30:20 +03002229 if (!intel_dp_is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002230 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002231
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002232 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2233 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002234
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002235 if (WARN(edp_have_panel_power(intel_dp),
2236 "eDP port %c panel power already on\n",
2237 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002238 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002239
Daniel Vetter4be73782014-01-17 14:39:48 +01002240 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002241
Jani Nikulabf13e812013-09-06 07:40:05 +03002242 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002243 pp = ironlake_get_pp_control(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002244 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002245 /* ILK workaround: disable reset around power sequence */
2246 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002247 I915_WRITE(pp_ctrl_reg, pp);
2248 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002249 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002250
Imre Deak5a162e22016-08-10 14:07:30 +03002251 pp |= PANEL_POWER_ON;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002252 if (!IS_GEN5(dev_priv))
Keith Packard99ea7122011-11-01 19:57:50 -07002253 pp |= PANEL_POWER_RESET;
2254
Jesse Barnes453c5422013-03-28 09:55:41 -07002255 I915_WRITE(pp_ctrl_reg, pp);
2256 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002257
Daniel Vetter4be73782014-01-17 14:39:48 +01002258 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002259 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002260
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002261 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002262 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002263 I915_WRITE(pp_ctrl_reg, pp);
2264 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002265 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002266}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002267
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002268void intel_edp_panel_on(struct intel_dp *intel_dp)
2269{
Jani Nikula1853a9d2017-08-18 12:30:20 +03002270 if (!intel_dp_is_edp(intel_dp))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002271 return;
2272
2273 pps_lock(intel_dp);
2274 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002275 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002276}
2277
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002278
2279static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002280{
Paulo Zanoni30add222012-10-26 19:05:45 -02002281 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002282 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002283 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002284 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002285
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002286 lockdep_assert_held(&dev_priv->pps_mutex);
2287
Jani Nikula1853a9d2017-08-18 12:30:20 +03002288 if (!intel_dp_is_edp(intel_dp))
Keith Packard97af61f572011-09-28 16:23:51 -07002289 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002290
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002291 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2292 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002293
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002294 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2295 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002296
Jesse Barnes453c5422013-03-28 09:55:41 -07002297 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002298 /* We need to switch off panel power _and_ force vdd, for otherwise some
2299 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002300 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002301 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002302
Jani Nikulabf13e812013-09-06 07:40:05 +03002303 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002304
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002305 intel_dp->want_panel_vdd = false;
2306
Jesse Barnes453c5422013-03-28 09:55:41 -07002307 I915_WRITE(pp_ctrl_reg, pp);
2308 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002309
Abhay Kumard28d4732016-01-22 17:39:04 -08002310 intel_dp->panel_power_off_time = ktime_get_boottime();
Daniel Vetter4be73782014-01-17 14:39:48 +01002311 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002312
2313 /* We got a reference when we enabled the VDD. */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002314 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002315}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002316
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002317void intel_edp_panel_off(struct intel_dp *intel_dp)
2318{
Jani Nikula1853a9d2017-08-18 12:30:20 +03002319 if (!intel_dp_is_edp(intel_dp))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002320 return;
2321
2322 pps_lock(intel_dp);
2323 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002324 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002325}
2326
Jani Nikula1250d102014-08-12 17:11:39 +03002327/* Enable backlight in the panel power control. */
2328static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002329{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002330 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2331 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002332 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002333 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002334 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002335
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002336 /*
2337 * If we enable the backlight right away following a panel power
2338 * on, we may see slight flicker as the panel syncs with the eDP
2339 * link. So delay a bit to make sure the image is solid before
2340 * allowing it to appear.
2341 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002342 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002343
Ville Syrjälä773538e82014-09-04 14:54:56 +03002344 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002345
Jesse Barnes453c5422013-03-28 09:55:41 -07002346 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002347 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002348
Jani Nikulabf13e812013-09-06 07:40:05 +03002349 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002350
2351 I915_WRITE(pp_ctrl_reg, pp);
2352 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002353
Ville Syrjälä773538e82014-09-04 14:54:56 +03002354 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002355}
2356
Jani Nikula1250d102014-08-12 17:11:39 +03002357/* Enable backlight PWM and backlight PP control. */
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002358void intel_edp_backlight_on(const struct intel_crtc_state *crtc_state,
2359 const struct drm_connector_state *conn_state)
Jani Nikula1250d102014-08-12 17:11:39 +03002360{
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002361 struct intel_dp *intel_dp = enc_to_intel_dp(conn_state->best_encoder);
2362
Jani Nikula1853a9d2017-08-18 12:30:20 +03002363 if (!intel_dp_is_edp(intel_dp))
Jani Nikula1250d102014-08-12 17:11:39 +03002364 return;
2365
2366 DRM_DEBUG_KMS("\n");
2367
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002368 intel_panel_enable_backlight(crtc_state, conn_state);
Jani Nikula1250d102014-08-12 17:11:39 +03002369 _intel_edp_backlight_on(intel_dp);
2370}
2371
2372/* Disable backlight in the panel power control. */
2373static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002374{
Paulo Zanoni30add222012-10-26 19:05:45 -02002375 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002376 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002377 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002378 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002379
Jani Nikula1853a9d2017-08-18 12:30:20 +03002380 if (!intel_dp_is_edp(intel_dp))
Keith Packardf01eca22011-09-28 16:48:10 -07002381 return;
2382
Ville Syrjälä773538e82014-09-04 14:54:56 +03002383 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002384
Jesse Barnes453c5422013-03-28 09:55:41 -07002385 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002386 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002387
Jani Nikulabf13e812013-09-06 07:40:05 +03002388 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002389
2390 I915_WRITE(pp_ctrl_reg, pp);
2391 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002392
Ville Syrjälä773538e82014-09-04 14:54:56 +03002393 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002394
Paulo Zanonidce56b32013-12-19 14:29:40 -02002395 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002396 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002397}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002398
Jani Nikula1250d102014-08-12 17:11:39 +03002399/* Disable backlight PP control and backlight PWM. */
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002400void intel_edp_backlight_off(const struct drm_connector_state *old_conn_state)
Jani Nikula1250d102014-08-12 17:11:39 +03002401{
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002402 struct intel_dp *intel_dp = enc_to_intel_dp(old_conn_state->best_encoder);
2403
Jani Nikula1853a9d2017-08-18 12:30:20 +03002404 if (!intel_dp_is_edp(intel_dp))
Jani Nikula1250d102014-08-12 17:11:39 +03002405 return;
2406
2407 DRM_DEBUG_KMS("\n");
2408
2409 _intel_edp_backlight_off(intel_dp);
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002410 intel_panel_disable_backlight(old_conn_state);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002411}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002412
Jani Nikula73580fb72014-08-12 17:11:41 +03002413/*
2414 * Hook for controlling the panel power control backlight through the bl_power
2415 * sysfs attribute. Take care to handle multiple calls.
2416 */
2417static void intel_edp_backlight_power(struct intel_connector *connector,
2418 bool enable)
2419{
2420 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002421 bool is_enabled;
2422
Ville Syrjälä773538e82014-09-04 14:54:56 +03002423 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002424 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002425 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002426
2427 if (is_enabled == enable)
2428 return;
2429
Jani Nikula23ba9372014-08-27 14:08:43 +03002430 DRM_DEBUG_KMS("panel power control backlight %s\n",
2431 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002432
2433 if (enable)
2434 _intel_edp_backlight_on(intel_dp);
2435 else
2436 _intel_edp_backlight_off(intel_dp);
2437}
2438
Ville Syrjälä64e10772015-10-29 21:26:01 +02002439static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2440{
2441 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2442 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2443 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2444
2445 I915_STATE_WARN(cur_state != state,
2446 "DP port %c state assertion failure (expected %s, current %s)\n",
2447 port_name(dig_port->port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002448 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002449}
2450#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2451
2452static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2453{
2454 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2455
2456 I915_STATE_WARN(cur_state != state,
2457 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002458 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002459}
2460#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2461#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2462
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002463static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2464 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002465{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002466 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002467 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002468
Ville Syrjälä64e10772015-10-29 21:26:01 +02002469 assert_pipe_disabled(dev_priv, crtc->pipe);
2470 assert_dp_port_disabled(intel_dp);
2471 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002472
Ville Syrjäläabfce942015-10-29 21:26:03 +02002473 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002474 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002475
2476 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2477
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002478 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002479 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2480 else
2481 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2482
2483 I915_WRITE(DP_A, intel_dp->DP);
2484 POSTING_READ(DP_A);
2485 udelay(500);
2486
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002487 /*
2488 * [DevILK] Work around required when enabling DP PLL
2489 * while a pipe is enabled going to FDI:
2490 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2491 * 2. Program DP PLL enable
2492 */
2493 if (IS_GEN5(dev_priv))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02002494 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002495
Daniel Vetter07679352012-09-06 22:15:42 +02002496 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002497
Daniel Vetter07679352012-09-06 22:15:42 +02002498 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002499 POSTING_READ(DP_A);
2500 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002501}
2502
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002503static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002504{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002505 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002506 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2507 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002508
Ville Syrjälä64e10772015-10-29 21:26:01 +02002509 assert_pipe_disabled(dev_priv, crtc->pipe);
2510 assert_dp_port_disabled(intel_dp);
2511 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002512
Ville Syrjäläabfce942015-10-29 21:26:03 +02002513 DRM_DEBUG_KMS("disabling eDP PLL\n");
2514
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002515 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002516
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002517 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002518 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002519 udelay(200);
2520}
2521
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002522/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002523void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002524{
2525 int ret, i;
2526
2527 /* Should have a valid DPCD by this point */
2528 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2529 return;
2530
2531 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002532 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2533 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002534 } else {
Imre Deak357c0ae2016-11-21 21:15:06 +02002535 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
2536
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002537 /*
2538 * When turning on, we need to retry for 1ms to give the sink
2539 * time to wake up.
2540 */
2541 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002542 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2543 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002544 if (ret == 1)
2545 break;
2546 msleep(1);
2547 }
Imre Deak357c0ae2016-11-21 21:15:06 +02002548
2549 if (ret == 1 && lspcon->active)
2550 lspcon_wait_pcon_mode(lspcon);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002551 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002552
2553 if (ret != 1)
2554 DRM_DEBUG_KMS("failed to %s sink power state\n",
2555 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002556}
2557
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002558static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2559 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002560{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002561 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002562 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002563 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002564 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002565 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002566 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002567
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002568 if (!intel_display_power_get_if_enabled(dev_priv,
2569 encoder->power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002570 return false;
2571
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002572 ret = false;
2573
Imre Deak6d129be2014-03-05 16:20:54 +02002574 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002575
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002576 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002577 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002578
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002579 if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002580 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002581 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002582 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002583
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002584 for_each_pipe(dev_priv, p) {
2585 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2586 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2587 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002588 ret = true;
2589
2590 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002591 }
2592 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002593
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002594 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002595 i915_mmio_reg_offset(intel_dp->output_reg));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002596 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002597 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2598 } else {
2599 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002600 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002601
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002602 ret = true;
2603
2604out:
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002605 intel_display_power_put(dev_priv, encoder->power_domain);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002606
2607 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002608}
2609
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002610static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002611 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002612{
2613 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002614 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002615 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002616 struct drm_i915_private *dev_priv = to_i915(dev);
Xiong Zhang63000ef2013-06-28 12:59:06 +08002617 enum port port = dp_to_dig_port(intel_dp)->port;
2618 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002619
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002620 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002621
2622 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002623
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002624 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002625 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2626
2627 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002628 flags |= DRM_MODE_FLAG_PHSYNC;
2629 else
2630 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002631
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002632 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002633 flags |= DRM_MODE_FLAG_PVSYNC;
2634 else
2635 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002636 } else {
2637 if (tmp & DP_SYNC_HS_HIGH)
2638 flags |= DRM_MODE_FLAG_PHSYNC;
2639 else
2640 flags |= DRM_MODE_FLAG_NHSYNC;
2641
2642 if (tmp & DP_SYNC_VS_HIGH)
2643 flags |= DRM_MODE_FLAG_PVSYNC;
2644 else
2645 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002646 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002647
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002648 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002649
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02002650 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002651 pipe_config->limited_color_range = true;
2652
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002653 pipe_config->lane_count =
2654 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2655
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002656 intel_dp_get_m_n(crtc, pipe_config);
2657
Ville Syrjälä18442d02013-09-13 16:00:08 +03002658 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002659 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002660 pipe_config->port_clock = 162000;
2661 else
2662 pipe_config->port_clock = 270000;
2663 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002664
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002665 pipe_config->base.adjusted_mode.crtc_clock =
2666 intel_dotclock_calculate(pipe_config->port_clock,
2667 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002668
Jani Nikula1853a9d2017-08-18 12:30:20 +03002669 if (intel_dp_is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02002670 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002671 /*
2672 * This is a big fat ugly hack.
2673 *
2674 * Some machines in UEFI boot mode provide us a VBT that has 18
2675 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2676 * unknown we fail to light up. Yet the same BIOS boots up with
2677 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2678 * max, not what it tells us to use.
2679 *
2680 * Note: This will still be broken if the eDP panel is not lit
2681 * up by the BIOS, and thus we can't get the mode at module
2682 * load.
2683 */
2684 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002685 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2686 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002687 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002688}
2689
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002690static void intel_disable_dp(struct intel_encoder *encoder,
2691 struct intel_crtc_state *old_crtc_state,
2692 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002693{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002694 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002695 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002696
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002697 if (old_crtc_state->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002698 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002699
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002700 if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv))
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002701 intel_psr_disable(intel_dp);
2702
Daniel Vetter6cb49832012-05-20 17:14:50 +02002703 /* Make sure the panel is off before trying to change the mode. But also
2704 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002705 intel_edp_panel_vdd_on(intel_dp);
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002706 intel_edp_backlight_off(old_conn_state);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002707 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002708 intel_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02002709
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002710 /* disable the port before the pipe on g4x */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002711 if (INTEL_GEN(dev_priv) < 5)
Daniel Vetter37398502012-09-06 22:15:44 +02002712 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07002713}
2714
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002715static void ilk_post_disable_dp(struct intel_encoder *encoder,
2716 struct intel_crtc_state *old_crtc_state,
2717 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002718{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002719 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002720 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002721
Ville Syrjälä49277c32014-03-31 18:21:26 +03002722 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002723
2724 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002725 if (port == PORT_A)
2726 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002727}
2728
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002729static void vlv_post_disable_dp(struct intel_encoder *encoder,
2730 struct intel_crtc_state *old_crtc_state,
2731 struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002732{
2733 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2734
2735 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002736}
2737
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002738static void chv_post_disable_dp(struct intel_encoder *encoder,
2739 struct intel_crtc_state *old_crtc_state,
2740 struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002741{
2742 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002743 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002744 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002745
2746 intel_dp_link_down(intel_dp);
2747
Ville Syrjäläa5805162015-05-26 20:42:30 +03002748 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002749
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002750 /* Assert data lane reset */
2751 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002752
Ville Syrjäläa5805162015-05-26 20:42:30 +03002753 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002754}
2755
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002756static void
2757_intel_dp_set_link_train(struct intel_dp *intel_dp,
2758 uint32_t *DP,
2759 uint8_t dp_train_pat)
2760{
2761 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2762 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002763 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002764 enum port port = intel_dig_port->port;
2765
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002766 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2767 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2768 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2769
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002770 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002771 uint32_t temp = I915_READ(DP_TP_CTL(port));
2772
2773 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2774 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2775 else
2776 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2777
2778 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2779 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2780 case DP_TRAINING_PATTERN_DISABLE:
2781 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2782
2783 break;
2784 case DP_TRAINING_PATTERN_1:
2785 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2786 break;
2787 case DP_TRAINING_PATTERN_2:
2788 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2789 break;
2790 case DP_TRAINING_PATTERN_3:
2791 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2792 break;
2793 }
2794 I915_WRITE(DP_TP_CTL(port), temp);
2795
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002796 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002797 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002798 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2799
2800 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2801 case DP_TRAINING_PATTERN_DISABLE:
2802 *DP |= DP_LINK_TRAIN_OFF_CPT;
2803 break;
2804 case DP_TRAINING_PATTERN_1:
2805 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2806 break;
2807 case DP_TRAINING_PATTERN_2:
2808 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2809 break;
2810 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002811 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002812 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2813 break;
2814 }
2815
2816 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002817 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002818 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2819 else
2820 *DP &= ~DP_LINK_TRAIN_MASK;
2821
2822 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2823 case DP_TRAINING_PATTERN_DISABLE:
2824 *DP |= DP_LINK_TRAIN_OFF;
2825 break;
2826 case DP_TRAINING_PATTERN_1:
2827 *DP |= DP_LINK_TRAIN_PAT_1;
2828 break;
2829 case DP_TRAINING_PATTERN_2:
2830 *DP |= DP_LINK_TRAIN_PAT_2;
2831 break;
2832 case DP_TRAINING_PATTERN_3:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002833 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002834 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2835 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002836 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002837 *DP |= DP_LINK_TRAIN_PAT_2;
2838 }
2839 break;
2840 }
2841 }
2842}
2843
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002844static void intel_dp_enable_port(struct intel_dp *intel_dp,
2845 struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002846{
2847 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002848 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002849
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002850 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002851
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002852 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002853
2854 /*
2855 * Magic for VLV/CHV. We _must_ first set up the register
2856 * without actually enabling the port, and then do another
2857 * write to enable the port. Otherwise link training will
2858 * fail when the power sequencer is freshly used for this port.
2859 */
2860 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002861 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002862 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002863
2864 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2865 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002866}
2867
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002868static void intel_enable_dp(struct intel_encoder *encoder,
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002869 struct intel_crtc_state *pipe_config,
2870 struct drm_connector_state *conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002871{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002872 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2873 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002874 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulac1dec792014-10-27 16:26:56 +02002875 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002876 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002877 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002878
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002879 if (WARN_ON(dp_reg & DP_PORT_EN))
2880 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002881
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002882 pps_lock(intel_dp);
2883
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002884 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002885 vlv_init_panel_power_sequencer(intel_dp);
2886
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002887 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002888
2889 edp_panel_vdd_on(intel_dp);
2890 edp_panel_on(intel_dp);
2891 edp_panel_vdd_off(intel_dp, true);
2892
2893 pps_unlock(intel_dp);
2894
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002895 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002896 unsigned int lane_mask = 0x0;
2897
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002898 if (IS_CHERRYVIEW(dev_priv))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002899 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002900
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002901 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2902 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002903 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002904
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002905 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2906 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002907 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002908
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002909 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002910 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002911 pipe_name(pipe));
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002912 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Jani Nikulac1dec792014-10-27 16:26:56 +02002913 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002914}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002915
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002916static void g4x_enable_dp(struct intel_encoder *encoder,
2917 struct intel_crtc_state *pipe_config,
2918 struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03002919{
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002920 intel_enable_dp(encoder, pipe_config, conn_state);
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002921 intel_edp_backlight_on(pipe_config, conn_state);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002922}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002923
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002924static void vlv_enable_dp(struct intel_encoder *encoder,
2925 struct intel_crtc_state *pipe_config,
2926 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002927{
Jani Nikula828f5c62013-09-05 16:44:45 +03002928 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2929
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002930 intel_edp_backlight_on(pipe_config, conn_state);
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002931 intel_psr_enable(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002932}
2933
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002934static void g4x_pre_enable_dp(struct intel_encoder *encoder,
2935 struct intel_crtc_state *pipe_config,
2936 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002937{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002938 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002939 enum port port = dp_to_dig_port(intel_dp)->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002940
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002941 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002942
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002943 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002944 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002945 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002946}
2947
Ville Syrjälä83b84592014-10-16 21:29:51 +03002948static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2949{
2950 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002951 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002952 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03002953 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002954
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002955 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
2956
Ville Syrjäläd1586942017-02-08 19:52:54 +02002957 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2958 return;
2959
Ville Syrjälä83b84592014-10-16 21:29:51 +03002960 edp_panel_vdd_off_sync(intel_dp);
2961
2962 /*
2963 * VLV seems to get confused when multiple power seqeuencers
2964 * have the same port selected (even if only one has power/vdd
2965 * enabled). The failure manifests as vlv_wait_port_ready() failing
2966 * CHV on the other hand doesn't seem to mind having the same port
2967 * selected in multiple power seqeuencers, but let's clear the
2968 * port select always when logically disconnecting a power sequencer
2969 * from a port.
2970 */
2971 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2972 pipe_name(pipe), port_name(intel_dig_port->port));
2973 I915_WRITE(pp_on_reg, 0);
2974 POSTING_READ(pp_on_reg);
2975
2976 intel_dp->pps_pipe = INVALID_PIPE;
2977}
2978
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002979static void vlv_steal_power_sequencer(struct drm_device *dev,
2980 enum pipe pipe)
2981{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002982 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002983 struct intel_encoder *encoder;
2984
2985 lockdep_assert_held(&dev_priv->pps_mutex);
2986
Jani Nikula19c80542015-12-16 12:48:16 +02002987 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002988 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002989 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002990
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002991 if (encoder->type != INTEL_OUTPUT_DP &&
2992 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002993 continue;
2994
2995 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002996 port = dp_to_dig_port(intel_dp)->port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002997
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002998 WARN(intel_dp->active_pipe == pipe,
2999 "stealing pipe %c power sequencer from active (e)DP port %c\n",
3000 pipe_name(pipe), port_name(port));
3001
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003002 if (intel_dp->pps_pipe != pipe)
3003 continue;
3004
3005 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03003006 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003007
3008 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03003009 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003010 }
3011}
3012
3013static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
3014{
3015 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3016 struct intel_encoder *encoder = &intel_dig_port->base;
3017 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003018 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003019 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003020
3021 lockdep_assert_held(&dev_priv->pps_mutex);
3022
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003023 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03003024
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003025 if (intel_dp->pps_pipe != INVALID_PIPE &&
3026 intel_dp->pps_pipe != crtc->pipe) {
3027 /*
3028 * If another power sequencer was being used on this
3029 * port previously make sure to turn off vdd there while
3030 * we still have control of it.
3031 */
Ville Syrjälä83b84592014-10-16 21:29:51 +03003032 vlv_detach_power_sequencer(intel_dp);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003033 }
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003034
3035 /*
3036 * We may be stealing the power
3037 * sequencer from another port.
3038 */
3039 vlv_steal_power_sequencer(dev, crtc->pipe);
3040
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003041 intel_dp->active_pipe = crtc->pipe;
3042
Jani Nikula1853a9d2017-08-18 12:30:20 +03003043 if (!intel_dp_is_edp(intel_dp))
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003044 return;
3045
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003046 /* now it's all ours */
3047 intel_dp->pps_pipe = crtc->pipe;
3048
3049 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
3050 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
3051
3052 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03003053 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02003054 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003055}
3056
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003057static void vlv_pre_enable_dp(struct intel_encoder *encoder,
3058 struct intel_crtc_state *pipe_config,
3059 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03003060{
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03003061 vlv_phy_pre_encoder_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003062
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003063 intel_enable_dp(encoder, pipe_config, conn_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003064}
3065
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003066static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
3067 struct intel_crtc_state *pipe_config,
3068 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07003069{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003070 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02003071
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03003072 vlv_phy_pre_pll_enable(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003073}
3074
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003075static void chv_pre_enable_dp(struct intel_encoder *encoder,
3076 struct intel_crtc_state *pipe_config,
3077 struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003078{
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003079 chv_phy_pre_encoder_enable(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003080
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003081 intel_enable_dp(encoder, pipe_config, conn_state);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03003082
3083 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003084 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003085}
3086
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003087static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
3088 struct intel_crtc_state *pipe_config,
3089 struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03003090{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003091 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03003092
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03003093 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03003094}
3095
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003096static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
3097 struct intel_crtc_state *pipe_config,
3098 struct drm_connector_state *conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003099{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03003100 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003101}
3102
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003103/*
3104 * Fetch AUX CH registers 0x202 - 0x207 which contain
3105 * link status information
3106 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003107bool
Keith Packard93f62da2011-11-01 19:45:03 -07003108intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003109{
Lyude9f085eb2016-04-13 10:58:33 -04003110 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
3111 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003112}
3113
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303114static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp)
3115{
3116 uint8_t psr_caps = 0;
3117
Imre Deak9bacd4b2017-05-10 12:21:48 +03003118 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps) != 1)
3119 return false;
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303120 return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED;
3121}
3122
3123static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp)
3124{
3125 uint8_t dprx = 0;
3126
Imre Deak9bacd4b2017-05-10 12:21:48 +03003127 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_DPRX_FEATURE_ENUMERATION_LIST,
3128 &dprx) != 1)
3129 return false;
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303130 return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED;
3131}
3132
Chris Wilsona76f73d2017-01-14 10:51:13 +00003133static bool intel_dp_get_alpm_status(struct intel_dp *intel_dp)
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303134{
3135 uint8_t alpm_caps = 0;
3136
Imre Deak9bacd4b2017-05-10 12:21:48 +03003137 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_RECEIVER_ALPM_CAP,
3138 &alpm_caps) != 1)
3139 return false;
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303140 return alpm_caps & DP_ALPM_CAP;
3141}
3142
Paulo Zanoni11002442014-06-13 18:45:41 -03003143/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003144uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003145intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003146{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003147 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003148 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003149
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003150 if (IS_GEN9_LP(dev_priv))
Vandana Kannan93147262014-11-18 15:45:29 +05303151 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003152 else if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjäläffe51112017-02-23 19:49:01 +02003153 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3154 return intel_ddi_dp_voltage_max(encoder);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003155 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Sonika Jindalbd600182014-08-08 16:23:41 +05303156 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003157 else if (IS_GEN7(dev_priv) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303158 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003159 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303160 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08003161 else
Sonika Jindalbd600182014-08-08 16:23:41 +05303162 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08003163}
3164
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003165uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003166intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3167{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003168 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003169 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003170
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003171 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003172 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3173 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3174 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3175 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3176 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3177 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3178 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303179 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3180 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003181 default:
3182 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3183 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003184 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003185 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303186 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3187 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3188 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3189 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3190 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3191 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3192 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003193 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303194 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003195 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003196 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003197 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303198 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3199 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3200 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3201 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3202 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3203 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3204 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003205 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303206 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003207 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003208 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003209 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303210 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3211 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3212 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3213 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3214 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003215 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303216 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003217 }
3218 } else {
3219 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303220 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3221 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3222 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3223 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3224 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3225 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3226 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003227 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303228 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003229 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003230 }
3231}
3232
Daniel Vetter5829975c2015-04-16 11:36:52 +02003233static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003234{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003235 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003236 unsigned long demph_reg_value, preemph_reg_value,
3237 uniqtranscale_reg_value;
3238 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003239
3240 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303241 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003242 preemph_reg_value = 0x0004000;
3243 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303244 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003245 demph_reg_value = 0x2B405555;
3246 uniqtranscale_reg_value = 0x552AB83A;
3247 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303248 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003249 demph_reg_value = 0x2B404040;
3250 uniqtranscale_reg_value = 0x5548B83A;
3251 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303252 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003253 demph_reg_value = 0x2B245555;
3254 uniqtranscale_reg_value = 0x5560B83A;
3255 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303256 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003257 demph_reg_value = 0x2B405555;
3258 uniqtranscale_reg_value = 0x5598DA3A;
3259 break;
3260 default:
3261 return 0;
3262 }
3263 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303264 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003265 preemph_reg_value = 0x0002000;
3266 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303267 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003268 demph_reg_value = 0x2B404040;
3269 uniqtranscale_reg_value = 0x5552B83A;
3270 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303271 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003272 demph_reg_value = 0x2B404848;
3273 uniqtranscale_reg_value = 0x5580B83A;
3274 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303275 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003276 demph_reg_value = 0x2B404040;
3277 uniqtranscale_reg_value = 0x55ADDA3A;
3278 break;
3279 default:
3280 return 0;
3281 }
3282 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303283 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003284 preemph_reg_value = 0x0000000;
3285 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303286 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003287 demph_reg_value = 0x2B305555;
3288 uniqtranscale_reg_value = 0x5570B83A;
3289 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303290 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003291 demph_reg_value = 0x2B2B4040;
3292 uniqtranscale_reg_value = 0x55ADDA3A;
3293 break;
3294 default:
3295 return 0;
3296 }
3297 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303298 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003299 preemph_reg_value = 0x0006000;
3300 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303301 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003302 demph_reg_value = 0x1B405555;
3303 uniqtranscale_reg_value = 0x55ADDA3A;
3304 break;
3305 default:
3306 return 0;
3307 }
3308 break;
3309 default:
3310 return 0;
3311 }
3312
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003313 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3314 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003315
3316 return 0;
3317}
3318
Daniel Vetter5829975c2015-04-16 11:36:52 +02003319static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003320{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003321 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3322 u32 deemph_reg_value, margin_reg_value;
3323 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003324 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003325
3326 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303327 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003328 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303329 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003330 deemph_reg_value = 128;
3331 margin_reg_value = 52;
3332 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303333 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003334 deemph_reg_value = 128;
3335 margin_reg_value = 77;
3336 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303337 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003338 deemph_reg_value = 128;
3339 margin_reg_value = 102;
3340 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303341 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003342 deemph_reg_value = 128;
3343 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003344 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003345 break;
3346 default:
3347 return 0;
3348 }
3349 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303350 case DP_TRAIN_PRE_EMPH_LEVEL_1:
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 = 85;
3354 margin_reg_value = 78;
3355 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303356 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003357 deemph_reg_value = 85;
3358 margin_reg_value = 116;
3359 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303360 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003361 deemph_reg_value = 85;
3362 margin_reg_value = 154;
3363 break;
3364 default:
3365 return 0;
3366 }
3367 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303368 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003369 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303370 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003371 deemph_reg_value = 64;
3372 margin_reg_value = 104;
3373 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303374 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003375 deemph_reg_value = 64;
3376 margin_reg_value = 154;
3377 break;
3378 default:
3379 return 0;
3380 }
3381 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303382 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003383 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303384 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003385 deemph_reg_value = 43;
3386 margin_reg_value = 154;
3387 break;
3388 default:
3389 return 0;
3390 }
3391 break;
3392 default:
3393 return 0;
3394 }
3395
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003396 chv_set_phy_signal_level(encoder, deemph_reg_value,
3397 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003398
3399 return 0;
3400}
3401
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003402static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003403gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003404{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003405 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003406
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003407 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303408 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003409 default:
3410 signal_levels |= DP_VOLTAGE_0_4;
3411 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303412 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003413 signal_levels |= DP_VOLTAGE_0_6;
3414 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303415 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003416 signal_levels |= DP_VOLTAGE_0_8;
3417 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303418 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003419 signal_levels |= DP_VOLTAGE_1_2;
3420 break;
3421 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003422 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303423 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003424 default:
3425 signal_levels |= DP_PRE_EMPHASIS_0;
3426 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303427 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003428 signal_levels |= DP_PRE_EMPHASIS_3_5;
3429 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303430 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003431 signal_levels |= DP_PRE_EMPHASIS_6;
3432 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303433 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003434 signal_levels |= DP_PRE_EMPHASIS_9_5;
3435 break;
3436 }
3437 return signal_levels;
3438}
3439
Zhenyu Wange3421a12010-04-08 09:43:27 +08003440/* Gen6's DP voltage swing and pre-emphasis control */
3441static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003442gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003443{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003444 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3445 DP_TRAIN_PRE_EMPHASIS_MASK);
3446 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303447 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3448 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003449 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303450 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003451 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303452 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3453 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003454 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303455 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3456 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003457 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303458 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3459 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003460 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003461 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003462 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3463 "0x%x\n", signal_levels);
3464 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003465 }
3466}
3467
Keith Packard1a2eb462011-11-16 16:26:07 -08003468/* Gen7's DP voltage swing and pre-emphasis control */
3469static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003470gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003471{
3472 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3473 DP_TRAIN_PRE_EMPHASIS_MASK);
3474 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303475 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003476 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303477 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003478 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303479 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003480 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3481
Sonika Jindalbd600182014-08-08 16:23:41 +05303482 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003483 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303484 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003485 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3486
Sonika Jindalbd600182014-08-08 16:23:41 +05303487 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003488 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303489 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003490 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3491
3492 default:
3493 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3494 "0x%x\n", signal_levels);
3495 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3496 }
3497}
3498
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003499void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003500intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003501{
3502 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003503 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003504 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003505 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003506 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003507 uint8_t train_set = intel_dp->train_set[0];
3508
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003509 if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003510 signal_levels = ddi_signal_levels(intel_dp);
3511
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07003512 if (IS_GEN9_LP(dev_priv) || IS_CANNONLAKE(dev_priv))
David Weinehallf8896f52015-06-25 11:11:03 +03003513 signal_levels = 0;
3514 else
3515 mask = DDI_BUF_EMP_MASK;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003516 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003517 signal_levels = chv_signal_levels(intel_dp);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003518 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003519 signal_levels = vlv_signal_levels(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003520 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003521 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003522 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003523 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003524 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003525 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3526 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003527 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003528 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3529 }
3530
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303531 if (mask)
3532 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3533
3534 DRM_DEBUG_KMS("Using vswing level %d\n",
3535 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3536 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3537 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3538 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003539
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003540 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003541
3542 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3543 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003544}
3545
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003546void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003547intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3548 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003549{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003550 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003551 struct drm_i915_private *dev_priv =
3552 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003553
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003554 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003555
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003556 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003557 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003558}
3559
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003560void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003561{
3562 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3563 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003564 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak3ab9c632013-05-03 12:57:41 +03003565 enum port port = intel_dig_port->port;
3566 uint32_t val;
3567
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003568 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003569 return;
3570
3571 val = I915_READ(DP_TP_CTL(port));
3572 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3573 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3574 I915_WRITE(DP_TP_CTL(port), val);
3575
3576 /*
3577 * On PORT_A we can have only eDP in SST mode. There the only reason
3578 * we need to set idle transmission mode is to work around a HW issue
3579 * where we enable the pipe while not in idle link-training mode.
3580 * In this case there is requirement to wait for a minimum number of
3581 * idle patterns to be sent.
3582 */
3583 if (port == PORT_A)
3584 return;
3585
Chris Wilsona7670172016-06-30 15:33:10 +01003586 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3587 DP_TP_STATUS_IDLE_DONE,
3588 DP_TP_STATUS_IDLE_DONE,
3589 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003590 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3591}
3592
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003593static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003594intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003595{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003596 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003597 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003598 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003599 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003600 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003601 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003602
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003603 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003604 return;
3605
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003606 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003607 return;
3608
Zhao Yakui28c97732009-10-09 11:39:41 +08003609 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003610
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003611 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003612 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003613 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003614 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003615 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003616 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003617 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3618 else
3619 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003620 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003621 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003622 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003623 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003624
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003625 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3626 I915_WRITE(intel_dp->output_reg, DP);
3627 POSTING_READ(intel_dp->output_reg);
3628
3629 /*
3630 * HW workaround for IBX, we need to move the port
3631 * to transcoder A after disabling it to allow the
3632 * matching HDMI port to be enabled on transcoder A.
3633 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003634 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003635 /*
3636 * We get CPU/PCH FIFO underruns on the other pipe when
3637 * doing the workaround. Sweep them under the rug.
3638 */
3639 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3640 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3641
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003642 /* always enable with pattern 1 (as per spec) */
3643 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3644 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3645 I915_WRITE(intel_dp->output_reg, DP);
3646 POSTING_READ(intel_dp->output_reg);
3647
3648 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003649 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003650 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003651
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003652 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003653 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3654 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003655 }
3656
Keith Packardf01eca22011-09-28 16:48:10 -07003657 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003658
3659 intel_dp->DP = DP;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003660
3661 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3662 pps_lock(intel_dp);
3663 intel_dp->active_pipe = INVALID_PIPE;
3664 pps_unlock(intel_dp);
3665 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003666}
3667
Imre Deak24e807e2016-10-24 19:33:28 +03003668bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003669intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003670{
Lyude9f085eb2016-04-13 10:58:33 -04003671 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3672 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003673 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003674
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003675 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003676
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003677 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3678}
3679
3680static bool
3681intel_edp_init_dpcd(struct intel_dp *intel_dp)
3682{
3683 struct drm_i915_private *dev_priv =
3684 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3685
3686 /* this function is meant to be called only once */
3687 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3688
3689 if (!intel_dp_read_dpcd(intel_dp))
3690 return false;
3691
Jani Nikula84c36752017-05-18 14:10:23 +03003692 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
3693 drm_dp_is_branch(intel_dp->dpcd));
Imre Deak12a47a422016-10-24 19:33:29 +03003694
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003695 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3696 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3697 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3698
3699 /* Check if the panel supports PSR */
3700 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3701 intel_dp->psr_dpcd,
3702 sizeof(intel_dp->psr_dpcd));
3703 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3704 dev_priv->psr.sink_support = true;
3705 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3706 }
3707
3708 if (INTEL_GEN(dev_priv) >= 9 &&
3709 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3710 uint8_t frame_sync_cap;
3711
3712 dev_priv->psr.sink_support = true;
Imre Deak9bacd4b2017-05-10 12:21:48 +03003713 if (drm_dp_dpcd_readb(&intel_dp->aux,
3714 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3715 &frame_sync_cap) != 1)
3716 frame_sync_cap = 0;
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003717 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3718 /* PSR2 needs frame sync as well */
3719 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3720 DRM_DEBUG_KMS("PSR2 %s on sink",
3721 dev_priv->psr.psr2_support ? "supported" : "not supported");
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303722
3723 if (dev_priv->psr.psr2_support) {
3724 dev_priv->psr.y_cord_support =
3725 intel_dp_get_y_cord_status(intel_dp);
3726 dev_priv->psr.colorimetry_support =
3727 intel_dp_get_colorimetry_status(intel_dp);
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303728 dev_priv->psr.alpm =
3729 intel_dp_get_alpm_status(intel_dp);
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303730 }
3731
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003732 }
3733
3734 /* Read the eDP Display control capabilities registers */
3735 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
3736 drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003737 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3738 sizeof(intel_dp->edp_dpcd))
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003739 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3740 intel_dp->edp_dpcd);
3741
3742 /* Intermediate frequency support */
3743 if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */
3744 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3745 int i;
3746
3747 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3748 sink_rates, sizeof(sink_rates));
3749
3750 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3751 int val = le16_to_cpu(sink_rates[i]);
3752
3753 if (val == 0)
3754 break;
3755
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -08003756 /* Value read multiplied by 200kHz gives the per-lane
3757 * link rate in kHz. The source rates are, however,
3758 * stored in terms of LS_Clk kHz. The full conversion
3759 * back to symbols is
3760 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
3761 */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003762 intel_dp->sink_rates[i] = (val * 200) / 10;
3763 }
3764 intel_dp->num_sink_rates = i;
3765 }
3766
Jani Nikula68f357c2017-03-28 17:59:05 +03003767 if (intel_dp->num_sink_rates)
3768 intel_dp->use_rate_select = true;
3769 else
3770 intel_dp_set_sink_rates(intel_dp);
3771
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003772 intel_dp_set_common_rates(intel_dp);
3773
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003774 return true;
3775}
3776
3777
3778static bool
3779intel_dp_get_dpcd(struct intel_dp *intel_dp)
3780{
Jani Nikula27dbefb2017-04-06 16:44:17 +03003781 u8 sink_count;
3782
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003783 if (!intel_dp_read_dpcd(intel_dp))
3784 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003785
Jani Nikula68f357c2017-03-28 17:59:05 +03003786 /* Don't clobber cached eDP rates. */
Jani Nikula1853a9d2017-08-18 12:30:20 +03003787 if (!intel_dp_is_edp(intel_dp)) {
Jani Nikula68f357c2017-03-28 17:59:05 +03003788 intel_dp_set_sink_rates(intel_dp);
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003789 intel_dp_set_common_rates(intel_dp);
3790 }
Jani Nikula68f357c2017-03-28 17:59:05 +03003791
Jani Nikula27dbefb2017-04-06 16:44:17 +03003792 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_SINK_COUNT, &sink_count) <= 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303793 return false;
3794
3795 /*
3796 * Sink count can change between short pulse hpd hence
3797 * a member variable in intel_dp will track any changes
3798 * between short pulse interrupts.
3799 */
Jani Nikula27dbefb2017-04-06 16:44:17 +03003800 intel_dp->sink_count = DP_GET_SINK_COUNT(sink_count);
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303801
3802 /*
3803 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3804 * a dongle is present but no display. Unless we require to know
3805 * if a dongle is present or not, we don't need to update
3806 * downstream port information. So, an early return here saves
3807 * time from performing other operations which are not required.
3808 */
Jani Nikula1853a9d2017-08-18 12:30:20 +03003809 if (!intel_dp_is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303810 return false;
3811
Imre Deakc726ad02016-10-24 19:33:24 +03003812 if (!drm_dp_is_branch(intel_dp->dpcd))
Adam Jacksonedb39242012-09-18 10:58:49 -04003813 return true; /* native DP sink */
3814
3815 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3816 return true; /* no per-port downstream info */
3817
Lyude9f085eb2016-04-13 10:58:33 -04003818 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3819 intel_dp->downstream_ports,
3820 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003821 return false; /* downstream port status fetch failed */
3822
3823 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003824}
3825
Dave Airlie0e32b392014-05-02 14:02:48 +10003826static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003827intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003828{
Jani Nikula010b9b32017-04-06 16:44:16 +03003829 u8 mstm_cap;
Dave Airlie0e32b392014-05-02 14:02:48 +10003830
Nathan Schulte7cc96132016-03-15 10:14:05 -05003831 if (!i915.enable_dp_mst)
3832 return false;
3833
Dave Airlie0e32b392014-05-02 14:02:48 +10003834 if (!intel_dp->can_mst)
3835 return false;
3836
3837 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3838 return false;
3839
Jani Nikula010b9b32017-04-06 16:44:16 +03003840 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_MSTM_CAP, &mstm_cap) != 1)
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003841 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003842
Jani Nikula010b9b32017-04-06 16:44:16 +03003843 return mstm_cap & DP_MST_CAP;
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003844}
3845
3846static void
3847intel_dp_configure_mst(struct intel_dp *intel_dp)
3848{
3849 if (!i915.enable_dp_mst)
3850 return;
3851
3852 if (!intel_dp->can_mst)
3853 return;
3854
3855 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3856
3857 if (intel_dp->is_mst)
3858 DRM_DEBUG_KMS("Sink is MST capable\n");
3859 else
3860 DRM_DEBUG_KMS("Sink is not MST capable\n");
3861
3862 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3863 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003864}
3865
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003866static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003867{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003868 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003869 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003870 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003871 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003872 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003873 int count = 0;
3874 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003875
3876 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003877 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003878 ret = -EIO;
3879 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003880 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003881
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003882 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003883 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003884 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003885 ret = -EIO;
3886 goto out;
3887 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003888
Rodrigo Vivic6297842015-11-05 10:50:20 -08003889 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003890 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivic6297842015-11-05 10:50:20 -08003891
3892 if (drm_dp_dpcd_readb(&intel_dp->aux,
3893 DP_TEST_SINK_MISC, &buf) < 0) {
3894 ret = -EIO;
3895 goto out;
3896 }
3897 count = buf & DP_TEST_COUNT_MASK;
3898 } while (--attempts && count);
3899
3900 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003901 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003902 ret = -ETIMEDOUT;
3903 }
3904
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003905 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003906 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003907 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003908}
3909
3910static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3911{
3912 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003913 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003914 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3915 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003916 int ret;
3917
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003918 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3919 return -EIO;
3920
3921 if (!(buf & DP_TEST_CRC_SUPPORTED))
3922 return -ENOTTY;
3923
3924 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3925 return -EIO;
3926
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003927 if (buf & DP_TEST_SINK_START) {
3928 ret = intel_dp_sink_crc_stop(intel_dp);
3929 if (ret)
3930 return ret;
3931 }
3932
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003933 hsw_disable_ips(intel_crtc);
3934
3935 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3936 buf | DP_TEST_SINK_START) < 0) {
3937 hsw_enable_ips(intel_crtc);
3938 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003939 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003940
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003941 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003942 return 0;
3943}
3944
3945int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3946{
3947 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003948 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003949 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3950 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003951 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003952 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003953
3954 ret = intel_dp_sink_crc_start(intel_dp);
3955 if (ret)
3956 return ret;
3957
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003958 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003959 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003960
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003961 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003962 DP_TEST_SINK_MISC, &buf) < 0) {
3963 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003964 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003965 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003966 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07003967
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003968 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003969
3970 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003971 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
3972 ret = -ETIMEDOUT;
3973 goto stop;
3974 }
3975
3976 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
3977 ret = -EIO;
3978 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003979 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003980
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003981stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003982 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003983 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003984}
3985
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003986static bool
3987intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3988{
Jani Nikula010b9b32017-04-06 16:44:16 +03003989 return drm_dp_dpcd_readb(&intel_dp->aux, DP_DEVICE_SERVICE_IRQ_VECTOR,
3990 sink_irq_vector) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003991}
3992
Dave Airlie0e32b392014-05-02 14:02:48 +10003993static bool
3994intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3995{
3996 int ret;
3997
Lyude9f085eb2016-04-13 10:58:33 -04003998 ret = drm_dp_dpcd_read(&intel_dp->aux,
Dave Airlie0e32b392014-05-02 14:02:48 +10003999 DP_SINK_COUNT_ESI,
4000 sink_irq_vector, 14);
4001 if (ret != 14)
4002 return false;
4003
4004 return true;
4005}
4006
Todd Previtec5d5ab72015-04-15 08:38:38 -07004007static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004008{
Manasi Navareda15f7c2017-01-24 08:16:34 -08004009 int status = 0;
Manasi Navare140ef132017-06-08 13:41:03 -07004010 int test_link_rate;
Manasi Navareda15f7c2017-01-24 08:16:34 -08004011 uint8_t test_lane_count, test_link_bw;
4012 /* (DP CTS 1.2)
4013 * 4.3.1.11
4014 */
4015 /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */
4016 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT,
4017 &test_lane_count);
4018
4019 if (status <= 0) {
4020 DRM_DEBUG_KMS("Lane count read failed\n");
4021 return DP_TEST_NAK;
4022 }
4023 test_lane_count &= DP_MAX_LANE_COUNT_MASK;
Manasi Navareda15f7c2017-01-24 08:16:34 -08004024
4025 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE,
4026 &test_link_bw);
4027 if (status <= 0) {
4028 DRM_DEBUG_KMS("Link Rate read failed\n");
4029 return DP_TEST_NAK;
4030 }
Manasi Navareda15f7c2017-01-24 08:16:34 -08004031 test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw);
Manasi Navare140ef132017-06-08 13:41:03 -07004032
4033 /* Validate the requested link rate and lane count */
4034 if (!intel_dp_link_params_valid(intel_dp, test_link_rate,
4035 test_lane_count))
Manasi Navareda15f7c2017-01-24 08:16:34 -08004036 return DP_TEST_NAK;
4037
4038 intel_dp->compliance.test_lane_count = test_lane_count;
4039 intel_dp->compliance.test_link_rate = test_link_rate;
4040
4041 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004042}
4043
4044static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
4045{
Manasi Navare611032b2017-01-24 08:21:49 -08004046 uint8_t test_pattern;
Jani Nikula010b9b32017-04-06 16:44:16 +03004047 uint8_t test_misc;
Manasi Navare611032b2017-01-24 08:21:49 -08004048 __be16 h_width, v_height;
4049 int status = 0;
4050
4051 /* Read the TEST_PATTERN (DP CTS 3.1.5) */
Jani Nikula010b9b32017-04-06 16:44:16 +03004052 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_PATTERN,
4053 &test_pattern);
Manasi Navare611032b2017-01-24 08:21:49 -08004054 if (status <= 0) {
4055 DRM_DEBUG_KMS("Test pattern read failed\n");
4056 return DP_TEST_NAK;
4057 }
4058 if (test_pattern != DP_COLOR_RAMP)
4059 return DP_TEST_NAK;
4060
4061 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI,
4062 &h_width, 2);
4063 if (status <= 0) {
4064 DRM_DEBUG_KMS("H Width read failed\n");
4065 return DP_TEST_NAK;
4066 }
4067
4068 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI,
4069 &v_height, 2);
4070 if (status <= 0) {
4071 DRM_DEBUG_KMS("V Height read failed\n");
4072 return DP_TEST_NAK;
4073 }
4074
Jani Nikula010b9b32017-04-06 16:44:16 +03004075 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_MISC0,
4076 &test_misc);
Manasi Navare611032b2017-01-24 08:21:49 -08004077 if (status <= 0) {
4078 DRM_DEBUG_KMS("TEST MISC read failed\n");
4079 return DP_TEST_NAK;
4080 }
4081 if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB)
4082 return DP_TEST_NAK;
4083 if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA)
4084 return DP_TEST_NAK;
4085 switch (test_misc & DP_TEST_BIT_DEPTH_MASK) {
4086 case DP_TEST_BIT_DEPTH_6:
4087 intel_dp->compliance.test_data.bpc = 6;
4088 break;
4089 case DP_TEST_BIT_DEPTH_8:
4090 intel_dp->compliance.test_data.bpc = 8;
4091 break;
4092 default:
4093 return DP_TEST_NAK;
4094 }
4095
4096 intel_dp->compliance.test_data.video_pattern = test_pattern;
4097 intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width);
4098 intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height);
4099 /* Set test active flag here so userspace doesn't interrupt things */
4100 intel_dp->compliance.test_active = 1;
4101
4102 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004103}
4104
4105static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
4106{
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004107 uint8_t test_result = DP_TEST_ACK;
Todd Previte559be302015-05-04 07:48:20 -07004108 struct intel_connector *intel_connector = intel_dp->attached_connector;
4109 struct drm_connector *connector = &intel_connector->base;
4110
4111 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02004112 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07004113 intel_dp->aux.i2c_defer_count > 6) {
4114 /* Check EDID read for NACKs, DEFERs and corruption
4115 * (DP CTS 1.2 Core r1.1)
4116 * 4.2.2.4 : Failed EDID read, I2C_NAK
4117 * 4.2.2.5 : Failed EDID read, I2C_DEFER
4118 * 4.2.2.6 : EDID corruption detected
4119 * Use failsafe mode for all cases
4120 */
4121 if (intel_dp->aux.i2c_nack_count > 0 ||
4122 intel_dp->aux.i2c_defer_count > 0)
4123 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
4124 intel_dp->aux.i2c_nack_count,
4125 intel_dp->aux.i2c_defer_count);
Manasi Navarec1617ab2016-12-09 16:22:50 -08004126 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
Todd Previte559be302015-05-04 07:48:20 -07004127 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05304128 struct edid *block = intel_connector->detect_edid;
4129
4130 /* We have to write the checksum
4131 * of the last block read
4132 */
4133 block += intel_connector->detect_edid->extensions;
4134
Jani Nikula010b9b32017-04-06 16:44:16 +03004135 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_EDID_CHECKSUM,
4136 block->checksum) <= 0)
Todd Previte559be302015-05-04 07:48:20 -07004137 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
4138
4139 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004140 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED;
Todd Previte559be302015-05-04 07:48:20 -07004141 }
4142
4143 /* Set test active flag here so userspace doesn't interrupt things */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004144 intel_dp->compliance.test_active = 1;
Todd Previte559be302015-05-04 07:48:20 -07004145
Todd Previtec5d5ab72015-04-15 08:38:38 -07004146 return test_result;
4147}
4148
4149static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
4150{
4151 uint8_t test_result = DP_TEST_NAK;
4152 return test_result;
4153}
4154
4155static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
4156{
4157 uint8_t response = DP_TEST_NAK;
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004158 uint8_t request = 0;
4159 int status;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004160
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004161 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004162 if (status <= 0) {
4163 DRM_DEBUG_KMS("Could not read test request from sink\n");
4164 goto update_status;
4165 }
4166
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004167 switch (request) {
Todd Previtec5d5ab72015-04-15 08:38:38 -07004168 case DP_TEST_LINK_TRAINING:
4169 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004170 response = intel_dp_autotest_link_training(intel_dp);
4171 break;
4172 case DP_TEST_LINK_VIDEO_PATTERN:
4173 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004174 response = intel_dp_autotest_video_pattern(intel_dp);
4175 break;
4176 case DP_TEST_LINK_EDID_READ:
4177 DRM_DEBUG_KMS("EDID test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004178 response = intel_dp_autotest_edid(intel_dp);
4179 break;
4180 case DP_TEST_LINK_PHY_TEST_PATTERN:
4181 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004182 response = intel_dp_autotest_phy_pattern(intel_dp);
4183 break;
4184 default:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004185 DRM_DEBUG_KMS("Invalid test request '%02x'\n", request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004186 break;
4187 }
4188
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004189 if (response & DP_TEST_ACK)
4190 intel_dp->compliance.test_type = request;
4191
Todd Previtec5d5ab72015-04-15 08:38:38 -07004192update_status:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004193 status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004194 if (status <= 0)
4195 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004196}
4197
Dave Airlie0e32b392014-05-02 14:02:48 +10004198static int
4199intel_dp_check_mst_status(struct intel_dp *intel_dp)
4200{
4201 bool bret;
4202
4203 if (intel_dp->is_mst) {
4204 u8 esi[16] = { 0 };
4205 int ret = 0;
4206 int retry;
4207 bool handled;
4208 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4209go_again:
4210 if (bret == true) {
4211
4212 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03004213 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03004214 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10004215 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4216 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004217 intel_dp_stop_link_train(intel_dp);
4218 }
4219
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004220 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004221 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4222
4223 if (handled) {
4224 for (retry = 0; retry < 3; retry++) {
4225 int wret;
4226 wret = drm_dp_dpcd_write(&intel_dp->aux,
4227 DP_SINK_COUNT_ESI+1,
4228 &esi[1], 3);
4229 if (wret == 3) {
4230 break;
4231 }
4232 }
4233
4234 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4235 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004236 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004237 goto go_again;
4238 }
4239 } else
4240 ret = 0;
4241
4242 return ret;
4243 } else {
4244 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4245 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4246 intel_dp->is_mst = false;
4247 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4248 /* send a hotplug event */
4249 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4250 }
4251 }
4252 return -EINVAL;
4253}
4254
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304255static void
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004256intel_dp_retrain_link(struct intel_dp *intel_dp)
4257{
4258 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4259 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4260 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
4261
4262 /* Suppress underruns caused by re-training */
4263 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4264 if (crtc->config->has_pch_encoder)
4265 intel_set_pch_fifo_underrun_reporting(dev_priv,
4266 intel_crtc_pch_transcoder(crtc), false);
4267
4268 intel_dp_start_link_train(intel_dp);
4269 intel_dp_stop_link_train(intel_dp);
4270
4271 /* Keep underrun reporting disabled until things are stable */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02004272 intel_wait_for_vblank(dev_priv, crtc->pipe);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004273
4274 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4275 if (crtc->config->has_pch_encoder)
4276 intel_set_pch_fifo_underrun_reporting(dev_priv,
4277 intel_crtc_pch_transcoder(crtc), true);
4278}
4279
4280static void
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304281intel_dp_check_link_status(struct intel_dp *intel_dp)
4282{
4283 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4284 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4285 u8 link_status[DP_LINK_STATUS_SIZE];
4286
4287 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
4288
4289 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4290 DRM_ERROR("Failed to get link status\n");
4291 return;
4292 }
4293
4294 if (!intel_encoder->base.crtc)
4295 return;
4296
4297 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4298 return;
4299
Manasi Navare14c562c2017-04-06 14:00:12 -07004300 /*
4301 * Validate the cached values of intel_dp->link_rate and
4302 * intel_dp->lane_count before attempting to retrain.
4303 */
Manasi Navare1a92c702017-06-08 13:41:02 -07004304 if (!intel_dp_link_params_valid(intel_dp, intel_dp->link_rate,
4305 intel_dp->lane_count))
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004306 return;
4307
Manasi Navareda15f7c2017-01-24 08:16:34 -08004308 /* Retrain if Channel EQ or CR not ok */
4309 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304310 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4311 intel_encoder->base.name);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004312
4313 intel_dp_retrain_link(intel_dp);
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304314 }
4315}
4316
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004317/*
4318 * According to DP spec
4319 * 5.1.2:
4320 * 1. Read DPCD
4321 * 2. Configure link according to Receiver Capabilities
4322 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4323 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304324 *
4325 * intel_dp_short_pulse - handles short pulse interrupts
4326 * when full detection is not required.
4327 * Returns %true if short pulse is handled and full detection
4328 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004329 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304330static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304331intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004332{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004333 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004334 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004335 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304336 u8 old_sink_count = intel_dp->sink_count;
4337 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004338
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304339 /*
4340 * Clearing compliance test variables to allow capturing
4341 * of values for next automated test request.
4342 */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004343 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304344
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304345 /*
4346 * Now read the DPCD to see if it's actually running
4347 * If the current value of sink count doesn't match with
4348 * the value that was stored earlier or dpcd read failed
4349 * we need to do full detection
4350 */
4351 ret = intel_dp_get_dpcd(intel_dp);
4352
4353 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4354 /* No need to proceed if we are going to do full detect */
4355 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004356 }
4357
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004358 /* Try to read the source of the interrupt */
4359 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004360 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4361 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004362 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004363 drm_dp_dpcd_writeb(&intel_dp->aux,
4364 DP_DEVICE_SERVICE_IRQ_VECTOR,
4365 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004366
4367 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Manasi Navareda15f7c2017-01-24 08:16:34 -08004368 intel_dp_handle_test_request(intel_dp);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004369 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4370 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4371 }
4372
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304373 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4374 intel_dp_check_link_status(intel_dp);
4375 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004376 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
4377 DRM_DEBUG_KMS("Link Training Compliance Test requested\n");
4378 /* Send a Hotplug Uevent to userspace to start modeset */
4379 drm_kms_helper_hotplug_event(intel_encoder->base.dev);
4380 }
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304381
4382 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004383}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004384
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004385/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004386static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004387intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004388{
Imre Deake393d0d2017-02-22 17:10:52 +02004389 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004390 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004391 uint8_t type;
4392
Imre Deake393d0d2017-02-22 17:10:52 +02004393 if (lspcon->active)
4394 lspcon_resume(lspcon);
4395
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004396 if (!intel_dp_get_dpcd(intel_dp))
4397 return connector_status_disconnected;
4398
Jani Nikula1853a9d2017-08-18 12:30:20 +03004399 if (intel_dp_is_edp(intel_dp))
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304400 return connector_status_connected;
4401
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004402 /* if there's no downstream port, we're done */
Imre Deakc726ad02016-10-24 19:33:24 +03004403 if (!drm_dp_is_branch(dpcd))
Keith Packard26d61aa2011-07-25 20:01:09 -07004404 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004405
4406 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004407 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4408 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004409
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304410 return intel_dp->sink_count ?
4411 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004412 }
4413
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004414 if (intel_dp_can_mst(intel_dp))
4415 return connector_status_connected;
4416
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004417 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004418 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004419 return connector_status_connected;
4420
4421 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004422 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4423 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4424 if (type == DP_DS_PORT_TYPE_VGA ||
4425 type == DP_DS_PORT_TYPE_NON_EDID)
4426 return connector_status_unknown;
4427 } else {
4428 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4429 DP_DWN_STRM_PORT_TYPE_MASK;
4430 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4431 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4432 return connector_status_unknown;
4433 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004434
4435 /* Anything else is out of spec, warn and ignore */
4436 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004437 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004438}
4439
4440static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004441edp_detect(struct intel_dp *intel_dp)
4442{
4443 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Mika Kahola1650be72016-12-13 10:02:47 +02004444 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsond410b562014-09-02 20:03:59 +01004445 enum drm_connector_status status;
4446
Mika Kahola1650be72016-12-13 10:02:47 +02004447 status = intel_panel_detect(dev_priv);
Chris Wilsond410b562014-09-02 20:03:59 +01004448 if (status == connector_status_unknown)
4449 status = connector_status_connected;
4450
4451 return status;
4452}
4453
Jani Nikulab93433c2015-08-20 10:47:36 +03004454static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4455 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004456{
Jani Nikulab93433c2015-08-20 10:47:36 +03004457 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004458
Jani Nikula0df53b72015-08-20 10:47:40 +03004459 switch (port->port) {
Jani Nikula0df53b72015-08-20 10:47:40 +03004460 case PORT_B:
4461 bit = SDE_PORTB_HOTPLUG;
4462 break;
4463 case PORT_C:
4464 bit = SDE_PORTC_HOTPLUG;
4465 break;
4466 case PORT_D:
4467 bit = SDE_PORTD_HOTPLUG;
4468 break;
4469 default:
4470 MISSING_CASE(port->port);
4471 return false;
4472 }
4473
4474 return I915_READ(SDEISR) & bit;
4475}
4476
4477static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4478 struct intel_digital_port *port)
4479{
4480 u32 bit;
4481
4482 switch (port->port) {
Jani Nikula0df53b72015-08-20 10:47:40 +03004483 case PORT_B:
4484 bit = SDE_PORTB_HOTPLUG_CPT;
4485 break;
4486 case PORT_C:
4487 bit = SDE_PORTC_HOTPLUG_CPT;
4488 break;
4489 case PORT_D:
4490 bit = SDE_PORTD_HOTPLUG_CPT;
4491 break;
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004492 default:
4493 MISSING_CASE(port->port);
4494 return false;
4495 }
4496
4497 return I915_READ(SDEISR) & bit;
4498}
4499
4500static bool spt_digital_port_connected(struct drm_i915_private *dev_priv,
4501 struct intel_digital_port *port)
4502{
4503 u32 bit;
4504
4505 switch (port->port) {
4506 case PORT_A:
4507 bit = SDE_PORTA_HOTPLUG_SPT;
4508 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004509 case PORT_E:
4510 bit = SDE_PORTE_HOTPLUG_SPT;
4511 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004512 default:
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004513 return cpt_digital_port_connected(dev_priv, port);
Jani Nikulab93433c2015-08-20 10:47:36 +03004514 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004515
Jani Nikulab93433c2015-08-20 10:47:36 +03004516 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004517}
4518
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004519static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004520 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004521{
Jani Nikula9642c812015-08-20 10:47:41 +03004522 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004523
Jani Nikula9642c812015-08-20 10:47:41 +03004524 switch (port->port) {
4525 case PORT_B:
4526 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4527 break;
4528 case PORT_C:
4529 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4530 break;
4531 case PORT_D:
4532 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4533 break;
4534 default:
4535 MISSING_CASE(port->port);
4536 return false;
4537 }
4538
4539 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4540}
4541
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004542static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4543 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004544{
4545 u32 bit;
4546
4547 switch (port->port) {
4548 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004549 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004550 break;
4551 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004552 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004553 break;
4554 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004555 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004556 break;
4557 default:
4558 MISSING_CASE(port->port);
4559 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004560 }
4561
Jani Nikula1d245982015-08-20 10:47:37 +03004562 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004563}
4564
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004565static bool ilk_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(DEISR) & DE_DP_A_HOTPLUG;
4570 else
4571 return ibx_digital_port_connected(dev_priv, port);
4572}
4573
4574static bool snb_digital_port_connected(struct drm_i915_private *dev_priv,
4575 struct intel_digital_port *port)
4576{
4577 if (port->port == PORT_A)
4578 return I915_READ(DEISR) & DE_DP_A_HOTPLUG;
4579 else
4580 return cpt_digital_port_connected(dev_priv, port);
4581}
4582
4583static bool ivb_digital_port_connected(struct drm_i915_private *dev_priv,
4584 struct intel_digital_port *port)
4585{
4586 if (port->port == PORT_A)
4587 return I915_READ(DEISR) & DE_DP_A_HOTPLUG_IVB;
4588 else
4589 return cpt_digital_port_connected(dev_priv, port);
4590}
4591
4592static bool bdw_digital_port_connected(struct drm_i915_private *dev_priv,
4593 struct intel_digital_port *port)
4594{
4595 if (port->port == PORT_A)
4596 return I915_READ(GEN8_DE_PORT_ISR) & GEN8_PORT_DP_A_HOTPLUG;
4597 else
4598 return cpt_digital_port_connected(dev_priv, port);
4599}
4600
Jani Nikulae464bfd2015-08-20 10:47:42 +03004601static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304602 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004603{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304604 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4605 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004606 u32 bit;
4607
Rodrigo Vivi256cfdd2017-08-11 11:26:49 -07004608 port = intel_hpd_pin_to_port(intel_encoder->hpd_pin);
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304609 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004610 case PORT_A:
4611 bit = BXT_DE_PORT_HP_DDIA;
4612 break;
4613 case PORT_B:
4614 bit = BXT_DE_PORT_HP_DDIB;
4615 break;
4616 case PORT_C:
4617 bit = BXT_DE_PORT_HP_DDIC;
4618 break;
4619 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304620 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004621 return false;
4622 }
4623
4624 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4625}
4626
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004627/*
4628 * intel_digital_port_connected - is the specified port connected?
4629 * @dev_priv: i915 private structure
4630 * @port: the port to test
4631 *
4632 * Return %true if @port is connected, %false otherwise.
4633 */
Imre Deak390b4e02017-01-27 11:39:19 +02004634bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
4635 struct intel_digital_port *port)
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004636{
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004637 if (HAS_GMCH_DISPLAY(dev_priv)) {
4638 if (IS_GM45(dev_priv))
4639 return gm45_digital_port_connected(dev_priv, port);
4640 else
4641 return g4x_digital_port_connected(dev_priv, port);
4642 }
4643
4644 if (IS_GEN5(dev_priv))
4645 return ilk_digital_port_connected(dev_priv, port);
4646 else if (IS_GEN6(dev_priv))
4647 return snb_digital_port_connected(dev_priv, port);
4648 else if (IS_GEN7(dev_priv))
4649 return ivb_digital_port_connected(dev_priv, port);
4650 else if (IS_GEN8(dev_priv))
4651 return bdw_digital_port_connected(dev_priv, port);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004652 else if (IS_GEN9_LP(dev_priv))
Jani Nikulae464bfd2015-08-20 10:47:42 +03004653 return bxt_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004654 else
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004655 return spt_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004656}
4657
Keith Packard8c241fe2011-09-28 16:38:44 -07004658static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004659intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004660{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004661 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004662
Jani Nikula9cd300e2012-10-19 14:51:52 +03004663 /* use cached edid if we have one */
4664 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004665 /* invalid edid */
4666 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004667 return NULL;
4668
Jani Nikula55e9ede2013-10-01 10:38:54 +03004669 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004670 } else
4671 return drm_get_edid(&intel_connector->base,
4672 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004673}
4674
Chris Wilsonbeb60602014-09-02 20:04:00 +01004675static void
4676intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004677{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004678 struct intel_connector *intel_connector = intel_dp->attached_connector;
4679 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004680
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304681 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004682 edid = intel_dp_get_edid(intel_dp);
4683 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004684
Maarten Lankhorste6b72c92017-05-01 15:38:00 +02004685 intel_dp->has_audio = drm_detect_monitor_audio(edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004686}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004687
Chris Wilsonbeb60602014-09-02 20:04:00 +01004688static void
4689intel_dp_unset_edid(struct intel_dp *intel_dp)
4690{
4691 struct intel_connector *intel_connector = intel_dp->attached_connector;
4692
4693 kfree(intel_connector->detect_edid);
4694 intel_connector->detect_edid = NULL;
4695
4696 intel_dp->has_audio = false;
4697}
4698
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004699static int
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304700intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004701{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304702 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004703 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004704 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4705 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004706 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004707 enum drm_connector_status status;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004708 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004709
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004710 WARN_ON(!drm_modeset_is_locked(&connector->dev->mode_config.connection_mutex));
4711
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004712 intel_display_power_get(to_i915(dev), intel_dp->aux_power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004713
Chris Wilsond410b562014-09-02 20:03:59 +01004714 /* Can't disconnect eDP, but you can close the lid... */
Jani Nikula1853a9d2017-08-18 12:30:20 +03004715 if (intel_dp_is_edp(intel_dp))
Chris Wilsond410b562014-09-02 20:03:59 +01004716 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004717 else if (intel_digital_port_connected(to_i915(dev),
4718 dp_to_dig_port(intel_dp)))
4719 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004720 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004721 status = connector_status_disconnected;
4722
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004723 if (status == connector_status_disconnected) {
Manasi Navarec1617ab2016-12-09 16:22:50 -08004724 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304725
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004726 if (intel_dp->is_mst) {
4727 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4728 intel_dp->is_mst,
4729 intel_dp->mst_mgr.mst_state);
4730 intel_dp->is_mst = false;
4731 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4732 intel_dp->is_mst);
4733 }
4734
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004735 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304736 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004737
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304738 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004739 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304740
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004741 DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
4742 yesno(intel_dp_source_supports_hbr2(intel_dp)),
4743 yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
4744
Manasi Navared7e8ef02017-02-07 16:54:11 -08004745 if (intel_dp->reset_link_params) {
Jani Nikula540b0b7f2017-04-06 16:44:13 +03004746 /* Initial max link lane count */
4747 intel_dp->max_link_lane_count = intel_dp_max_common_lane_count(intel_dp);
Manasi Navaref4829842016-12-05 16:27:36 -08004748
Jani Nikula540b0b7f2017-04-06 16:44:13 +03004749 /* Initial max link rate */
4750 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
Manasi Navared7e8ef02017-02-07 16:54:11 -08004751
4752 intel_dp->reset_link_params = false;
4753 }
Manasi Navaref4829842016-12-05 16:27:36 -08004754
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004755 intel_dp_print_rates(intel_dp);
4756
Jani Nikula84c36752017-05-18 14:10:23 +03004757 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
4758 drm_dp_is_branch(intel_dp->dpcd));
Mika Kahola0e390a32016-09-09 14:10:53 +03004759
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004760 intel_dp_configure_mst(intel_dp);
4761
4762 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304763 /*
4764 * If we are in MST mode then this connector
4765 * won't appear connected or have anything
4766 * with EDID on it
4767 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004768 status = connector_status_disconnected;
4769 goto out;
Ville Syrjälä1a361472017-04-12 22:30:17 +03004770 } else {
4771 /*
4772 * If display is now connected check links status,
4773 * there has been known issues of link loss triggerring
4774 * long pulse.
4775 *
4776 * Some sinks (eg. ASUS PB287Q) seem to perform some
4777 * weird HPD ping pong during modesets. So we can apparently
4778 * end up with HPD going low during a modeset, and then
4779 * going back up soon after. And once that happens we must
4780 * retrain the link to get a picture. That's in case no
4781 * userspace component reacted to intermittent HPD dip.
4782 */
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304783 intel_dp_check_link_status(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004784 }
4785
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304786 /*
4787 * Clearing NACK and defer counts to get their exact values
4788 * while reading EDID which are required by Compliance tests
4789 * 4.2.2.4 and 4.2.2.5
4790 */
4791 intel_dp->aux.i2c_nack_count = 0;
4792 intel_dp->aux.i2c_defer_count = 0;
4793
Chris Wilsonbeb60602014-09-02 20:04:00 +01004794 intel_dp_set_edid(intel_dp);
Jani Nikula1853a9d2017-08-18 12:30:20 +03004795 if (intel_dp_is_edp(intel_dp) || intel_connector->detect_edid)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004796 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304797 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004798
Todd Previte09b1eb12015-04-20 15:27:34 -07004799 /* Try to read the source of the interrupt */
4800 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004801 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4802 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004803 /* Clear interrupt source */
4804 drm_dp_dpcd_writeb(&intel_dp->aux,
4805 DP_DEVICE_SERVICE_IRQ_VECTOR,
4806 sink_irq_vector);
4807
4808 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4809 intel_dp_handle_test_request(intel_dp);
4810 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4811 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4812 }
4813
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004814out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004815 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304816 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304817
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004818 intel_display_power_put(to_i915(dev), intel_dp->aux_power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004819 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304820}
4821
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004822static int
4823intel_dp_detect(struct drm_connector *connector,
4824 struct drm_modeset_acquire_ctx *ctx,
4825 bool force)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304826{
4827 struct intel_dp *intel_dp = intel_attached_dp(connector);
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004828 int status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304829
4830 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4831 connector->base.id, connector->name);
4832
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304833 /* If full detect is not performed yet, do a full detect */
4834 if (!intel_dp->detect_done)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004835 status = intel_dp_long_pulse(intel_dp->attached_connector);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304836
4837 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304838
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004839 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004840}
4841
Chris Wilsonbeb60602014-09-02 20:04:00 +01004842static void
4843intel_dp_force(struct drm_connector *connector)
4844{
4845 struct intel_dp *intel_dp = intel_attached_dp(connector);
4846 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004847 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004848
4849 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4850 connector->base.id, connector->name);
4851 intel_dp_unset_edid(intel_dp);
4852
4853 if (connector->status != connector_status_connected)
4854 return;
4855
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004856 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004857
4858 intel_dp_set_edid(intel_dp);
4859
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004860 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004861
4862 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004863 intel_encoder->type = INTEL_OUTPUT_DP;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004864}
4865
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004866static int intel_dp_get_modes(struct drm_connector *connector)
4867{
Jani Nikuladd06f902012-10-19 14:51:50 +03004868 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004869 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004870
Chris Wilsonbeb60602014-09-02 20:04:00 +01004871 edid = intel_connector->detect_edid;
4872 if (edid) {
4873 int ret = intel_connector_update_modes(connector, edid);
4874 if (ret)
4875 return ret;
4876 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004877
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004878 /* if eDP has no EDID, fall back to fixed mode */
Jani Nikula1853a9d2017-08-18 12:30:20 +03004879 if (intel_dp_is_edp(intel_attached_dp(connector)) &&
Chris Wilsonbeb60602014-09-02 20:04:00 +01004880 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004881 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004882
4883 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004884 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004885 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004886 drm_mode_probed_add(connector, mode);
4887 return 1;
4888 }
4889 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004890
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004891 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004892}
4893
Chris Wilsonf6849602010-09-19 09:29:33 +01004894static int
Chris Wilson7a418e32016-06-24 14:00:14 +01004895intel_dp_connector_register(struct drm_connector *connector)
4896{
4897 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004898 int ret;
4899
4900 ret = intel_connector_register(connector);
4901 if (ret)
4902 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004903
4904 i915_debugfs_connector_add(connector);
4905
4906 DRM_DEBUG_KMS("registering %s bus for %s\n",
4907 intel_dp->aux.name, connector->kdev->kobj.name);
4908
4909 intel_dp->aux.dev = connector->kdev;
4910 return drm_dp_aux_register(&intel_dp->aux);
4911}
4912
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004913static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004914intel_dp_connector_unregister(struct drm_connector *connector)
4915{
4916 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4917 intel_connector_unregister(connector);
4918}
4919
4920static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004921intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004922{
Jani Nikula1d508702012-10-19 14:51:49 +03004923 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004924
Chris Wilson10e972d2014-09-04 21:43:45 +01004925 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004926
Jani Nikula9cd300e2012-10-19 14:51:52 +03004927 if (!IS_ERR_OR_NULL(intel_connector->edid))
4928 kfree(intel_connector->edid);
4929
Jani Nikula1853a9d2017-08-18 12:30:20 +03004930 /*
4931 * Can't call intel_dp_is_edp() since the encoder may have been
4932 * destroyed already.
4933 */
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004934 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004935 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004936
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004937 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004938 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004939}
4940
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004941void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004942{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004943 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4944 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004945
Dave Airlie0e32b392014-05-02 14:02:48 +10004946 intel_dp_mst_encoder_cleanup(intel_dig_port);
Jani Nikula1853a9d2017-08-18 12:30:20 +03004947 if (intel_dp_is_edp(intel_dp)) {
Keith Packardbd943152011-09-18 23:09:52 -07004948 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004949 /*
4950 * vdd might still be enabled do to the delayed vdd off.
4951 * Make sure vdd is actually turned off here.
4952 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004953 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004954 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004955 pps_unlock(intel_dp);
4956
Clint Taylor01527b32014-07-07 13:01:46 -07004957 if (intel_dp->edp_notifier.notifier_call) {
4958 unregister_reboot_notifier(&intel_dp->edp_notifier);
4959 intel_dp->edp_notifier.notifier_call = NULL;
4960 }
Keith Packardbd943152011-09-18 23:09:52 -07004961 }
Chris Wilson99681882016-06-20 09:29:17 +01004962
4963 intel_dp_aux_fini(intel_dp);
4964
Imre Deakc8bd0e42014-12-12 17:57:38 +02004965 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004966 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004967}
4968
Imre Deakbf93ba62016-04-18 10:04:21 +03004969void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004970{
4971 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4972
Jani Nikula1853a9d2017-08-18 12:30:20 +03004973 if (!intel_dp_is_edp(intel_dp))
Imre Deak07f9cd02014-08-18 14:42:45 +03004974 return;
4975
Ville Syrjälä951468f2014-09-04 14:55:31 +03004976 /*
4977 * vdd might still be enabled do to the delayed vdd off.
4978 * Make sure vdd is actually turned off here.
4979 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004980 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004981 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004982 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004983 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004984}
4985
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004986static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4987{
4988 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4989 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004990 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004991
4992 lockdep_assert_held(&dev_priv->pps_mutex);
4993
4994 if (!edp_have_panel_vdd(intel_dp))
4995 return;
4996
4997 /*
4998 * The VDD bit needs a power domain reference, so if the bit is
4999 * already enabled when we boot or resume, grab this reference and
5000 * schedule a vdd off, so we don't hold on to the reference
5001 * indefinitely.
5002 */
5003 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005004 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005005
5006 edp_panel_vdd_schedule_off(intel_dp);
5007}
5008
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005009static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
5010{
5011 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5012
5013 if ((intel_dp->DP & DP_PORT_EN) == 0)
5014 return INVALID_PIPE;
5015
5016 if (IS_CHERRYVIEW(dev_priv))
5017 return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
5018 else
5019 return PORT_TO_PIPE(intel_dp->DP);
5020}
5021
Imre Deakbf93ba62016-04-18 10:04:21 +03005022void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03005023{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005024 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Imre Deakdd75f6d2016-11-21 21:15:05 +02005025 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
5026 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005027
5028 if (!HAS_DDI(dev_priv))
5029 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005030
Imre Deakdd75f6d2016-11-21 21:15:05 +02005031 if (lspcon->active)
Shashank Sharma910530c2016-10-14 19:56:52 +05305032 lspcon_resume(lspcon);
5033
Manasi Navared7e8ef02017-02-07 16:54:11 -08005034 intel_dp->reset_link_params = true;
5035
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005036 pps_lock(intel_dp);
5037
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005038 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5039 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5040
Jani Nikula1853a9d2017-08-18 12:30:20 +03005041 if (intel_dp_is_edp(intel_dp)) {
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005042 /* Reinit the power sequencer, in case BIOS did something with it. */
5043 intel_dp_pps_init(encoder->dev, intel_dp);
5044 intel_edp_panel_vdd_sanitize(intel_dp);
5045 }
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005046
5047 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03005048}
5049
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005050static const struct drm_connector_funcs intel_dp_connector_funcs = {
Chris Wilsonbeb60602014-09-02 20:04:00 +01005051 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005052 .fill_modes = drm_helper_probe_single_connector_modes,
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02005053 .atomic_get_property = intel_digital_connector_atomic_get_property,
5054 .atomic_set_property = intel_digital_connector_atomic_set_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01005055 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01005056 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03005057 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08005058 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02005059 .atomic_duplicate_state = intel_digital_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005060};
5061
5062static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02005063 .detect_ctx = intel_dp_detect,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005064 .get_modes = intel_dp_get_modes,
5065 .mode_valid = intel_dp_mode_valid,
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02005066 .atomic_check = intel_digital_connector_atomic_check,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005067};
5068
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005069static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03005070 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02005071 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005072};
5073
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005074enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10005075intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
5076{
5077 struct intel_dp *intel_dp = &intel_dig_port->dp;
Dave Airlie0e32b392014-05-02 14:02:48 +10005078 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005079 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005080 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03005081
Takashi Iwai25400582015-11-19 12:09:56 +01005082 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
5083 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Ville Syrjäläcca05022016-06-22 21:57:06 +03005084 intel_dig_port->base.type = INTEL_OUTPUT_DP;
Dave Airlie13cf5502014-06-18 11:29:35 +10005085
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005086 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
5087 /*
5088 * vdd off can generate a long pulse on eDP which
5089 * would require vdd on to handle it, and thus we
5090 * would end up in an endless cycle of
5091 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
5092 */
5093 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
5094 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d522015-02-10 14:11:46 +02005095 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005096 }
5097
Ville Syrjälä26fbb772014-08-11 18:37:37 +03005098 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
5099 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10005100 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10005101
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005102 if (long_hpd) {
Manasi Navared7e8ef02017-02-07 16:54:11 -08005103 intel_dp->reset_link_params = true;
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005104 intel_dp->detect_done = false;
5105 return IRQ_NONE;
5106 }
5107
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005108 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005109
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005110 if (intel_dp->is_mst) {
5111 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
5112 /*
5113 * If we were in MST mode, and device is not
5114 * there, get out of MST mode
5115 */
5116 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
5117 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
5118 intel_dp->is_mst = false;
5119 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
5120 intel_dp->is_mst);
5121 intel_dp->detect_done = false;
5122 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10005123 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005124 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005125
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005126 if (!intel_dp->is_mst) {
5127 if (!intel_dp_short_pulse(intel_dp)) {
5128 intel_dp->detect_done = false;
5129 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05305130 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005131 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005132
5133 ret = IRQ_HANDLED;
5134
Imre Deak1c767b32014-08-18 14:42:42 +03005135put_power:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005136 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005137
5138 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10005139}
5140
Rodrigo Vivi477ec322015-08-06 15:51:39 +08005141/* check the VBT to see whether the eDP is on another port */
Jani Nikula7b91bf72017-08-18 12:30:19 +03005142bool intel_dp_is_port_edp(struct drm_i915_private *dev_priv, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08005143{
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005144 /*
5145 * eDP not supported on g4x. so bail out early just
5146 * for a bit extra safety in case the VBT is bonkers.
5147 */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005148 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005149 return false;
5150
Imre Deaka98d9c12016-12-21 12:17:24 +02005151 if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005152 return true;
5153
Jani Nikula951d9ef2016-03-16 12:43:31 +02005154 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08005155}
5156
Maarten Lankhorst200819a2017-04-10 12:51:10 +02005157static void
Chris Wilsonf6849602010-09-19 09:29:33 +01005158intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
5159{
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005160 struct drm_i915_private *dev_priv = to_i915(connector->dev);
5161
Chris Wilson3f43c482011-05-12 22:17:24 +01005162 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00005163 intel_attach_broadcast_rgb_property(connector);
Yuly Novikov53b41832012-10-26 12:04:00 +03005164
Jani Nikula1853a9d2017-08-18 12:30:20 +03005165 if (intel_dp_is_edp(intel_dp)) {
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005166 u32 allowed_scalers;
5167
5168 allowed_scalers = BIT(DRM_MODE_SCALE_ASPECT) | BIT(DRM_MODE_SCALE_FULLSCREEN);
5169 if (!HAS_GMCH_DISPLAY(dev_priv))
5170 allowed_scalers |= BIT(DRM_MODE_SCALE_CENTER);
5171
5172 drm_connector_attach_scaling_mode_property(connector, allowed_scalers);
5173
Maarten Lankhorsteead06d2017-05-01 15:37:55 +02005174 connector->state->scaling_mode = DRM_MODE_SCALE_ASPECT;
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005175
Yuly Novikov53b41832012-10-26 12:04:00 +03005176 }
Chris Wilsonf6849602010-09-19 09:29:33 +01005177}
5178
Imre Deakdada1a92014-01-29 13:25:41 +02005179static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
5180{
Abhay Kumard28d4732016-01-22 17:39:04 -08005181 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02005182 intel_dp->last_power_on = jiffies;
5183 intel_dp->last_backlight_off = jiffies;
5184}
5185
Daniel Vetter67a54562012-10-20 20:57:45 +02005186static void
Imre Deak54648612016-06-16 16:37:22 +03005187intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
5188 struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02005189{
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305190 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03005191 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07005192
Imre Deak8e8232d2016-06-16 16:37:21 +03005193 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02005194
5195 /* Workaround: Need to write PP_CONTROL with the unlock key as
5196 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305197 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02005198
Imre Deak8e8232d2016-06-16 16:37:21 +03005199 pp_on = I915_READ(regs.pp_on);
5200 pp_off = I915_READ(regs.pp_off);
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005201 if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005202 I915_WRITE(regs.pp_ctrl, pp_ctl);
5203 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305204 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005205
5206 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03005207 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
5208 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005209
Imre Deak54648612016-06-16 16:37:22 +03005210 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
5211 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005212
Imre Deak54648612016-06-16 16:37:22 +03005213 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
5214 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005215
Imre Deak54648612016-06-16 16:37:22 +03005216 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
5217 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005218
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005219 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) {
Manasi Navare12c8ca92017-06-26 12:21:45 -07005220 seq->t11_t12 = ((pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
5221 BXT_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305222 } else {
Imre Deak54648612016-06-16 16:37:22 +03005223 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02005224 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305225 }
Imre Deak54648612016-06-16 16:37:22 +03005226}
5227
5228static void
Imre Deakde9c1b62016-06-16 20:01:46 +03005229intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
5230{
5231 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5232 state_name,
5233 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
5234}
5235
5236static void
5237intel_pps_verify_state(struct drm_i915_private *dev_priv,
5238 struct intel_dp *intel_dp)
5239{
5240 struct edp_power_seq hw;
5241 struct edp_power_seq *sw = &intel_dp->pps_delays;
5242
5243 intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
5244
5245 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
5246 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
5247 DRM_ERROR("PPS state mismatch\n");
5248 intel_pps_dump_state("sw", sw);
5249 intel_pps_dump_state("hw", &hw);
5250 }
5251}
5252
5253static void
Imre Deak54648612016-06-16 16:37:22 +03005254intel_dp_init_panel_power_sequencer(struct drm_device *dev,
5255 struct intel_dp *intel_dp)
5256{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005257 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak54648612016-06-16 16:37:22 +03005258 struct edp_power_seq cur, vbt, spec,
5259 *final = &intel_dp->pps_delays;
5260
5261 lockdep_assert_held(&dev_priv->pps_mutex);
5262
5263 /* already initialized? */
5264 if (final->t11_t12 != 0)
5265 return;
5266
5267 intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005268
Imre Deakde9c1b62016-06-16 20:01:46 +03005269 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005270
Jani Nikula6aa23e62016-03-24 17:50:20 +02005271 vbt = dev_priv->vbt.edp.pps;
Manasi Navarec99a2592017-06-30 09:33:48 -07005272 /* On Toshiba Satellite P50-C-18C system the VBT T12 delay
5273 * of 500ms appears to be too short. Ocassionally the panel
5274 * just fails to power back on. Increasing the delay to 800ms
5275 * seems sufficient to avoid this problem.
5276 */
5277 if (dev_priv->quirks & QUIRK_INCREASE_T12_DELAY) {
5278 vbt.t11_t12 = max_t(u16, vbt.t11_t12, 800 * 10);
5279 DRM_DEBUG_KMS("Increasing T12 panel delay as per the quirk to %d\n",
5280 vbt.t11_t12);
5281 }
Manasi Navare770a17a2017-06-26 12:21:44 -07005282 /* T11_T12 delay is special and actually in units of 100ms, but zero
5283 * based in the hw (so we need to add 100 ms). But the sw vbt
5284 * table multiplies it with 1000 to make it in units of 100usec,
5285 * too. */
5286 vbt.t11_t12 += 100 * 10;
Daniel Vetter67a54562012-10-20 20:57:45 +02005287
5288 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5289 * our hw here, which are all in 100usec. */
5290 spec.t1_t3 = 210 * 10;
5291 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5292 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5293 spec.t10 = 500 * 10;
5294 /* This one is special and actually in units of 100ms, but zero
5295 * based in the hw (so we need to add 100 ms). But the sw vbt
5296 * table multiplies it with 1000 to make it in units of 100usec,
5297 * too. */
5298 spec.t11_t12 = (510 + 100) * 10;
5299
Imre Deakde9c1b62016-06-16 20:01:46 +03005300 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005301
5302 /* Use the max of the register settings and vbt. If both are
5303 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005304#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005305 spec.field : \
5306 max(cur.field, vbt.field))
5307 assign_final(t1_t3);
5308 assign_final(t8);
5309 assign_final(t9);
5310 assign_final(t10);
5311 assign_final(t11_t12);
5312#undef assign_final
5313
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005314#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005315 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5316 intel_dp->backlight_on_delay = get_delay(t8);
5317 intel_dp->backlight_off_delay = get_delay(t9);
5318 intel_dp->panel_power_down_delay = get_delay(t10);
5319 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5320#undef get_delay
5321
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005322 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5323 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5324 intel_dp->panel_power_cycle_delay);
5325
5326 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5327 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005328
5329 /*
5330 * We override the HW backlight delays to 1 because we do manual waits
5331 * on them. For T8, even BSpec recommends doing it. For T9, if we
5332 * don't do this, we'll end up waiting for the backlight off delay
5333 * twice: once when we do the manual sleep, and once when we disable
5334 * the panel and wait for the PP_STATUS bit to become zero.
5335 */
5336 final->t8 = 1;
5337 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005338}
5339
5340static void
5341intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005342 struct intel_dp *intel_dp,
5343 bool force_disable_vdd)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005344{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005345 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07005346 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005347 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005348 struct pps_registers regs;
Ville Syrjäläad933b52014-08-18 22:15:56 +03005349 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005350 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005351
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005352 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005353
Imre Deak8e8232d2016-06-16 16:37:21 +03005354 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005355
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005356 /*
5357 * On some VLV machines the BIOS can leave the VDD
5358 * enabled even on power seqeuencers which aren't
5359 * hooked up to any port. This would mess up the
5360 * power domain tracking the first time we pick
5361 * one of these power sequencers for use since
5362 * edp_panel_vdd_on() would notice that the VDD was
5363 * already on and therefore wouldn't grab the power
5364 * domain reference. Disable VDD first to avoid this.
5365 * This also avoids spuriously turning the VDD on as
5366 * soon as the new power seqeuencer gets initialized.
5367 */
5368 if (force_disable_vdd) {
5369 u32 pp = ironlake_get_pp_control(intel_dp);
5370
5371 WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
5372
5373 if (pp & EDP_FORCE_VDD)
5374 DRM_DEBUG_KMS("VDD already on, disabling first\n");
5375
5376 pp &= ~EDP_FORCE_VDD;
5377
5378 I915_WRITE(regs.pp_ctrl, pp);
5379 }
5380
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005381 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005382 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5383 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005384 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005385 /* Compute the divisor for the pp clock, simply match the Bspec
5386 * formula. */
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005387 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005388 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305389 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
Manasi Navare12c8ca92017-06-26 12:21:45 -07005390 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305391 << BXT_POWER_CYCLE_DELAY_SHIFT);
5392 } else {
5393 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5394 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5395 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5396 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005397
5398 /* Haswell doesn't have any port selection bits for the panel
5399 * power sequencer any more. */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005400 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005401 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005402 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005403 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005404 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005405 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005406 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005407 }
5408
Jesse Barnes453c5422013-03-28 09:55:41 -07005409 pp_on |= port_sel;
5410
Imre Deak8e8232d2016-06-16 16:37:21 +03005411 I915_WRITE(regs.pp_on, pp_on);
5412 I915_WRITE(regs.pp_off, pp_off);
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005413 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005414 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305415 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005416 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005417
Daniel Vetter67a54562012-10-20 20:57:45 +02005418 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 +03005419 I915_READ(regs.pp_on),
5420 I915_READ(regs.pp_off),
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005421 (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005422 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5423 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005424}
5425
Imre Deak335f7522016-08-10 14:07:32 +03005426static void intel_dp_pps_init(struct drm_device *dev,
5427 struct intel_dp *intel_dp)
5428{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005429 struct drm_i915_private *dev_priv = to_i915(dev);
5430
5431 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Imre Deak335f7522016-08-10 14:07:32 +03005432 vlv_initial_power_sequencer_setup(intel_dp);
5433 } else {
5434 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005435 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak335f7522016-08-10 14:07:32 +03005436 }
5437}
5438
Vandana Kannanb33a2812015-02-13 15:33:03 +05305439/**
5440 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005441 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005442 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305443 * @refresh_rate: RR to be programmed
5444 *
5445 * This function gets called when refresh rate (RR) has to be changed from
5446 * one frequency to another. Switches can be between high and low RR
5447 * supported by the panel or to any other RR based on media playback (in
5448 * this case, RR value needs to be passed from user space).
5449 *
5450 * The caller of this function needs to take a lock on dev_priv->drrs.
5451 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005452static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
5453 struct intel_crtc_state *crtc_state,
5454 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305455{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305456 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305457 struct intel_digital_port *dig_port = NULL;
5458 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005459 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305460 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305461
5462 if (refresh_rate <= 0) {
5463 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5464 return;
5465 }
5466
Vandana Kannan96178ee2015-01-10 02:25:56 +05305467 if (intel_dp == NULL) {
5468 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305469 return;
5470 }
5471
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005472 /*
Rodrigo Vivie4d59f62014-11-20 02:22:08 -08005473 * FIXME: This needs proper synchronization with psr state for some
5474 * platforms that cannot have PSR and DRRS enabled at the same time.
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005475 */
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305476
Vandana Kannan96178ee2015-01-10 02:25:56 +05305477 dig_port = dp_to_dig_port(intel_dp);
5478 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02005479 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305480
5481 if (!intel_crtc) {
5482 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5483 return;
5484 }
5485
Vandana Kannan96178ee2015-01-10 02:25:56 +05305486 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305487 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5488 return;
5489 }
5490
Vandana Kannan96178ee2015-01-10 02:25:56 +05305491 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5492 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305493 index = DRRS_LOW_RR;
5494
Vandana Kannan96178ee2015-01-10 02:25:56 +05305495 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305496 DRM_DEBUG_KMS(
5497 "DRRS requested for previously set RR...ignoring\n");
5498 return;
5499 }
5500
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005501 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305502 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5503 return;
5504 }
5505
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005506 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305507 switch (index) {
5508 case DRRS_HIGH_RR:
5509 intel_dp_set_m_n(intel_crtc, M1_N1);
5510 break;
5511 case DRRS_LOW_RR:
5512 intel_dp_set_m_n(intel_crtc, M2_N2);
5513 break;
5514 case DRRS_MAX_RR:
5515 default:
5516 DRM_ERROR("Unsupported refreshrate type\n");
5517 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005518 } else if (INTEL_GEN(dev_priv) > 6) {
5519 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005520 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305521
Ville Syrjälä649636e2015-09-22 19:50:01 +03005522 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305523 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005524 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305525 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5526 else
5527 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305528 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005529 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305530 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5531 else
5532 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305533 }
5534 I915_WRITE(reg, val);
5535 }
5536
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305537 dev_priv->drrs.refresh_rate_type = index;
5538
5539 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5540}
5541
Vandana Kannanb33a2812015-02-13 15:33:03 +05305542/**
5543 * intel_edp_drrs_enable - init drrs struct if supported
5544 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005545 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305546 *
5547 * Initializes frontbuffer_bits and drrs.dp
5548 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005549void intel_edp_drrs_enable(struct intel_dp *intel_dp,
5550 struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305551{
5552 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005553 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305554
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005555 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305556 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5557 return;
5558 }
5559
5560 mutex_lock(&dev_priv->drrs.mutex);
5561 if (WARN_ON(dev_priv->drrs.dp)) {
5562 DRM_ERROR("DRRS already enabled\n");
5563 goto unlock;
5564 }
5565
5566 dev_priv->drrs.busy_frontbuffer_bits = 0;
5567
5568 dev_priv->drrs.dp = intel_dp;
5569
5570unlock:
5571 mutex_unlock(&dev_priv->drrs.mutex);
5572}
5573
Vandana Kannanb33a2812015-02-13 15:33:03 +05305574/**
5575 * intel_edp_drrs_disable - Disable DRRS
5576 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005577 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305578 *
5579 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005580void intel_edp_drrs_disable(struct intel_dp *intel_dp,
5581 struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305582{
5583 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005584 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305585
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005586 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305587 return;
5588
5589 mutex_lock(&dev_priv->drrs.mutex);
5590 if (!dev_priv->drrs.dp) {
5591 mutex_unlock(&dev_priv->drrs.mutex);
5592 return;
5593 }
5594
5595 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005596 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5597 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305598
5599 dev_priv->drrs.dp = NULL;
5600 mutex_unlock(&dev_priv->drrs.mutex);
5601
5602 cancel_delayed_work_sync(&dev_priv->drrs.work);
5603}
5604
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305605static void intel_edp_drrs_downclock_work(struct work_struct *work)
5606{
5607 struct drm_i915_private *dev_priv =
5608 container_of(work, typeof(*dev_priv), drrs.work.work);
5609 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305610
Vandana Kannan96178ee2015-01-10 02:25:56 +05305611 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305612
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305613 intel_dp = dev_priv->drrs.dp;
5614
5615 if (!intel_dp)
5616 goto unlock;
5617
5618 /*
5619 * The delayed work can race with an invalidate hence we need to
5620 * recheck.
5621 */
5622
5623 if (dev_priv->drrs.busy_frontbuffer_bits)
5624 goto unlock;
5625
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005626 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5627 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5628
5629 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5630 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5631 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305632
5633unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305634 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305635}
5636
Vandana Kannanb33a2812015-02-13 15:33:03 +05305637/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305638 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005639 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305640 * @frontbuffer_bits: frontbuffer plane tracking bits
5641 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305642 * This function gets called everytime rendering on the given planes start.
5643 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305644 *
5645 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5646 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005647void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5648 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305649{
Vandana Kannana93fad02015-01-10 02:25:59 +05305650 struct drm_crtc *crtc;
5651 enum pipe pipe;
5652
Daniel Vetter9da7d692015-04-09 16:44:15 +02005653 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305654 return;
5655
Daniel Vetter88f933a2015-04-09 16:44:16 +02005656 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305657
Vandana Kannana93fad02015-01-10 02:25:59 +05305658 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005659 if (!dev_priv->drrs.dp) {
5660 mutex_unlock(&dev_priv->drrs.mutex);
5661 return;
5662 }
5663
Vandana Kannana93fad02015-01-10 02:25:59 +05305664 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5665 pipe = to_intel_crtc(crtc)->pipe;
5666
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005667 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5668 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5669
Ramalingam C0ddfd202015-06-15 20:50:05 +05305670 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005671 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005672 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5673 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305674
Vandana Kannana93fad02015-01-10 02:25:59 +05305675 mutex_unlock(&dev_priv->drrs.mutex);
5676}
5677
Vandana Kannanb33a2812015-02-13 15:33:03 +05305678/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305679 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005680 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305681 * @frontbuffer_bits: frontbuffer plane tracking bits
5682 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305683 * This function gets called every time rendering on the given planes has
5684 * completed or flip on a crtc is completed. So DRRS should be upclocked
5685 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5686 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305687 *
5688 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5689 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005690void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5691 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305692{
Vandana Kannana93fad02015-01-10 02:25:59 +05305693 struct drm_crtc *crtc;
5694 enum pipe pipe;
5695
Daniel Vetter9da7d692015-04-09 16:44:15 +02005696 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305697 return;
5698
Daniel Vetter88f933a2015-04-09 16:44:16 +02005699 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305700
Vandana Kannana93fad02015-01-10 02:25:59 +05305701 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005702 if (!dev_priv->drrs.dp) {
5703 mutex_unlock(&dev_priv->drrs.mutex);
5704 return;
5705 }
5706
Vandana Kannana93fad02015-01-10 02:25:59 +05305707 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5708 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005709
5710 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305711 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5712
Ramalingam C0ddfd202015-06-15 20:50:05 +05305713 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005714 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005715 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5716 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305717
5718 /*
5719 * flush also means no more activity hence schedule downclock, if all
5720 * other fbs are quiescent too
5721 */
5722 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305723 schedule_delayed_work(&dev_priv->drrs.work,
5724 msecs_to_jiffies(1000));
5725 mutex_unlock(&dev_priv->drrs.mutex);
5726}
5727
Vandana Kannanb33a2812015-02-13 15:33:03 +05305728/**
5729 * DOC: Display Refresh Rate Switching (DRRS)
5730 *
5731 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5732 * which enables swtching between low and high refresh rates,
5733 * dynamically, based on the usage scenario. This feature is applicable
5734 * for internal panels.
5735 *
5736 * Indication that the panel supports DRRS is given by the panel EDID, which
5737 * would list multiple refresh rates for one resolution.
5738 *
5739 * DRRS is of 2 types - static and seamless.
5740 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5741 * (may appear as a blink on screen) and is used in dock-undock scenario.
5742 * Seamless DRRS involves changing RR without any visual effect to the user
5743 * and can be used during normal system usage. This is done by programming
5744 * certain registers.
5745 *
5746 * Support for static/seamless DRRS may be indicated in the VBT based on
5747 * inputs from the panel spec.
5748 *
5749 * DRRS saves power by switching to low RR based on usage scenarios.
5750 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005751 * The implementation is based on frontbuffer tracking implementation. When
5752 * there is a disturbance on the screen triggered by user activity or a periodic
5753 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5754 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5755 * made.
5756 *
5757 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5758 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305759 *
5760 * DRRS can be further extended to support other internal panels and also
5761 * the scenario of video playback wherein RR is set based on the rate
5762 * requested by userspace.
5763 */
5764
5765/**
5766 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5767 * @intel_connector: eDP connector
5768 * @fixed_mode: preferred mode of panel
5769 *
5770 * This function is called only once at driver load to initialize basic
5771 * DRRS stuff.
5772 *
5773 * Returns:
5774 * Downclock mode if panel supports it, else return NULL.
5775 * DRRS support is determined by the presence of downclock mode (apart
5776 * from VBT setting).
5777 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305778static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305779intel_dp_drrs_init(struct intel_connector *intel_connector,
5780 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305781{
5782 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305783 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005784 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305785 struct drm_display_mode *downclock_mode = NULL;
5786
Daniel Vetter9da7d692015-04-09 16:44:15 +02005787 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5788 mutex_init(&dev_priv->drrs.mutex);
5789
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005790 if (INTEL_GEN(dev_priv) <= 6) {
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305791 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5792 return NULL;
5793 }
5794
5795 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005796 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305797 return NULL;
5798 }
5799
5800 downclock_mode = intel_find_panel_downclock
Mika Kaholaa318b4c2016-12-13 10:02:48 +02005801 (dev_priv, fixed_mode, connector);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305802
5803 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305804 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305805 return NULL;
5806 }
5807
Vandana Kannan96178ee2015-01-10 02:25:56 +05305808 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305809
Vandana Kannan96178ee2015-01-10 02:25:56 +05305810 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005811 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305812 return downclock_mode;
5813}
5814
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005815static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005816 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005817{
5818 struct drm_connector *connector = &intel_connector->base;
5819 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005820 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5821 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005822 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005823 struct drm_display_mode *fixed_mode = NULL;
Jim Bridedc911f52017-08-09 12:48:53 -07005824 struct drm_display_mode *alt_fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305825 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005826 bool has_dpcd;
5827 struct drm_display_mode *scan;
5828 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005829 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005830
Jani Nikula1853a9d2017-08-18 12:30:20 +03005831 if (!intel_dp_is_edp(intel_dp))
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005832 return true;
5833
Imre Deak97a824e12016-06-21 11:51:47 +03005834 /*
5835 * On IBX/CPT we may get here with LVDS already registered. Since the
5836 * driver uses the only internal power sequencer available for both
5837 * eDP and LVDS bail out early in this case to prevent interfering
5838 * with an already powered-on LVDS power sequencer.
5839 */
5840 if (intel_get_lvds_encoder(dev)) {
5841 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5842 DRM_INFO("LVDS was detected, not registering eDP\n");
5843
5844 return false;
5845 }
5846
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005847 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005848
5849 intel_dp_init_panel_power_timestamps(intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +03005850 intel_dp_pps_init(dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005851 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005852
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005853 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005854
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005855 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005856 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005857
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005858 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005859 /* if this fails, presume the device is a ghost */
5860 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005861 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005862 }
5863
Daniel Vetter060c8772014-03-21 23:22:35 +01005864 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005865 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005866 if (edid) {
5867 if (drm_add_edid_modes(connector, edid)) {
5868 drm_mode_connector_update_edid_property(connector,
5869 edid);
5870 drm_edid_to_eld(connector, edid);
5871 } else {
5872 kfree(edid);
5873 edid = ERR_PTR(-EINVAL);
5874 }
5875 } else {
5876 edid = ERR_PTR(-ENOENT);
5877 }
5878 intel_connector->edid = edid;
5879
Jim Bridedc911f52017-08-09 12:48:53 -07005880 /* prefer fixed mode from EDID if available, save an alt mode also */
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005881 list_for_each_entry(scan, &connector->probed_modes, head) {
5882 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5883 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305884 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305885 intel_connector, fixed_mode);
Jim Bridedc911f52017-08-09 12:48:53 -07005886 } else if (!alt_fixed_mode) {
5887 alt_fixed_mode = drm_mode_duplicate(dev, scan);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005888 }
5889 }
5890
5891 /* fallback to VBT if available for eDP */
5892 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5893 fixed_mode = drm_mode_duplicate(dev,
5894 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005895 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005896 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005897 connector->display_info.width_mm = fixed_mode->width_mm;
5898 connector->display_info.height_mm = fixed_mode->height_mm;
5899 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005900 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005901 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005902
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005903 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005904 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5905 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005906
5907 /*
5908 * Figure out the current pipe for the initial backlight setup.
5909 * If the current pipe isn't valid, try the PPS pipe, and if that
5910 * fails just assume pipe A.
5911 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005912 pipe = vlv_active_pipe(intel_dp);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005913
5914 if (pipe != PIPE_A && pipe != PIPE_B)
5915 pipe = intel_dp->pps_pipe;
5916
5917 if (pipe != PIPE_A && pipe != PIPE_B)
5918 pipe = PIPE_A;
5919
5920 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5921 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005922 }
5923
Jim Bridedc911f52017-08-09 12:48:53 -07005924 intel_panel_init(&intel_connector->panel, fixed_mode, alt_fixed_mode,
5925 downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005926 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005927 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005928
5929 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005930
5931out_vdd_off:
5932 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5933 /*
5934 * vdd might still be enabled do to the delayed vdd off.
5935 * Make sure vdd is actually turned off here.
5936 */
5937 pps_lock(intel_dp);
5938 edp_panel_vdd_off_sync(intel_dp);
5939 pps_unlock(intel_dp);
5940
5941 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005942}
5943
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005944/* Set up the hotplug pin and aux power domain. */
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005945static void
5946intel_dp_init_connector_port_info(struct intel_digital_port *intel_dig_port)
5947{
5948 struct intel_encoder *encoder = &intel_dig_port->base;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005949 struct intel_dp *intel_dp = &intel_dig_port->dp;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005950
Rodrigo Vivif761bef22017-08-11 11:26:50 -07005951 encoder->hpd_pin = intel_hpd_pin(intel_dig_port->port);
5952
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005953 switch (intel_dig_port->port) {
5954 case PORT_A:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005955 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_A;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005956 break;
5957 case PORT_B:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005958 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_B;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005959 break;
5960 case PORT_C:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005961 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_C;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005962 break;
5963 case PORT_D:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005964 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005965 break;
5966 case PORT_E:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005967 /* FIXME: Check VBT for actual wiring of PORT E */
5968 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005969 break;
5970 default:
5971 MISSING_CASE(intel_dig_port->port);
5972 }
5973}
5974
Manasi Navare93013972017-04-06 16:44:19 +03005975static void intel_dp_modeset_retry_work_fn(struct work_struct *work)
5976{
5977 struct intel_connector *intel_connector;
5978 struct drm_connector *connector;
5979
5980 intel_connector = container_of(work, typeof(*intel_connector),
5981 modeset_retry_work);
5982 connector = &intel_connector->base;
5983 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
5984 connector->name);
5985
5986 /* Grab the locks before changing connector property*/
5987 mutex_lock(&connector->dev->mode_config.mutex);
5988 /* Set connector link status to BAD and send a Uevent to notify
5989 * userspace to do a modeset.
5990 */
5991 drm_mode_connector_set_link_status_property(connector,
5992 DRM_MODE_LINK_STATUS_BAD);
5993 mutex_unlock(&connector->dev->mode_config.mutex);
5994 /* Send Hotplug uevent so userspace can reprobe */
5995 drm_kms_helper_hotplug_event(connector->dev);
5996}
5997
Paulo Zanoni16c25532013-06-12 17:27:25 -03005998bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005999intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
6000 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006001{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006002 struct drm_connector *connector = &intel_connector->base;
6003 struct intel_dp *intel_dp = &intel_dig_port->dp;
6004 struct intel_encoder *intel_encoder = &intel_dig_port->base;
6005 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01006006 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02006007 enum port port = intel_dig_port->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01006008 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006009
Manasi Navare93013972017-04-06 16:44:19 +03006010 /* Initialize the work for modeset in case of link train failure */
6011 INIT_WORK(&intel_connector->modeset_retry_work,
6012 intel_dp_modeset_retry_work_fn);
6013
Ville Syrjäläccb1a832015-12-08 19:59:38 +02006014 if (WARN(intel_dig_port->max_lanes < 1,
6015 "Not enough lanes (%d) for DP on port %c\n",
6016 intel_dig_port->max_lanes, port_name(port)))
6017 return false;
6018
Jani Nikula55cfc582017-03-28 17:59:04 +03006019 intel_dp_set_source_rates(intel_dp);
6020
Manasi Navared7e8ef02017-02-07 16:54:11 -08006021 intel_dp->reset_link_params = true;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03006022 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02006023 intel_dp->active_pipe = INVALID_PIPE;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03006024
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006025 /* intel_dp vfuncs */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006026 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub6b5e382014-01-20 16:00:59 +00006027 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01006028 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006029 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01006030 else if (HAS_PCH_SPLIT(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006031 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
6032 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02006033 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006034
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006035 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00006036 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
6037 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02006038 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00006039
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006040 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03006041 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
6042
Daniel Vetter07679352012-09-06 22:15:42 +02006043 /* Preserve the current hw state. */
6044 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03006045 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00006046
Jani Nikula7b91bf72017-08-18 12:30:19 +03006047 if (intel_dp_is_port_edp(dev_priv, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05306048 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02006049 else
6050 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04006051
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02006052 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
6053 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
6054
Imre Deakf7d24902013-05-08 13:14:05 +03006055 /*
6056 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
6057 * for DP the encoder type can be set by the caller to
6058 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
6059 */
6060 if (type == DRM_MODE_CONNECTOR_eDP)
6061 intel_encoder->type = INTEL_OUTPUT_EDP;
6062
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006063 /* eDP only on port B and/or C on vlv/chv */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006064 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Jani Nikula1853a9d2017-08-18 12:30:20 +03006065 intel_dp_is_edp(intel_dp) &&
6066 port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006067 return false;
6068
Imre Deake7281ea2013-05-08 13:14:08 +03006069 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
6070 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
6071 port_name(port));
6072
Adam Jacksonb3295302010-07-16 14:46:28 -04006073 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006074 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
6075
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006076 connector->interlace_allowed = true;
6077 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08006078
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02006079 intel_dp_init_connector_port_info(intel_dig_port);
6080
Mika Kaholab6339582016-09-09 14:10:52 +03006081 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01006082
Daniel Vetter66a92782012-07-12 20:08:18 +02006083 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01006084 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08006085
Chris Wilsondf0e9242010-09-09 16:20:55 +01006086 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006087
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006088 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02006089 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
6090 else
6091 intel_connector->get_hw_state = intel_connector_get_hw_state;
6092
Dave Airlie0e32b392014-05-02 14:02:48 +10006093 /* init MST on ports that can support it */
Jani Nikula1853a9d2017-08-18 12:30:20 +03006094 if (HAS_DP_MST(dev_priv) && !intel_dp_is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03006095 (port == PORT_B || port == PORT_C || port == PORT_D))
6096 intel_dp_mst_encoder_init(intel_dig_port,
6097 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10006098
Ville Syrjälä36b5f422014-10-16 21:27:30 +03006099 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006100 intel_dp_aux_fini(intel_dp);
6101 intel_dp_mst_encoder_cleanup(intel_dig_port);
6102 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03006103 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08006104
Chris Wilsonf6849602010-09-19 09:29:33 +01006105 intel_dp_add_properties(intel_dp, connector);
6106
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006107 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
6108 * 0xd. Failure to do so will result in spurious interrupts being
6109 * generated on the port when a cable is not attached.
6110 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01006111 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006112 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
6113 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
6114 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03006115
6116 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006117
6118fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006119 drm_connector_cleanup(connector);
6120
6121 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006122}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006123
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006124bool intel_dp_init(struct drm_i915_private *dev_priv,
Chris Wilson457c52d2016-06-01 08:27:50 +01006125 i915_reg_t output_reg,
6126 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006127{
6128 struct intel_digital_port *intel_dig_port;
6129 struct intel_encoder *intel_encoder;
6130 struct drm_encoder *encoder;
6131 struct intel_connector *intel_connector;
6132
Daniel Vetterb14c5672013-09-19 12:18:32 +02006133 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006134 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01006135 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006136
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03006137 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306138 if (!intel_connector)
6139 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006140
6141 intel_encoder = &intel_dig_port->base;
6142 encoder = &intel_encoder->base;
6143
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006144 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
6145 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
6146 "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306147 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006148
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01006149 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006150 intel_encoder->disable = intel_disable_dp;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006151 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07006152 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03006153 intel_encoder->suspend = intel_dp_encoder_suspend;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006154 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03006155 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03006156 intel_encoder->pre_enable = chv_pre_enable_dp;
6157 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03006158 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03006159 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01006160 } else if (IS_VALLEYVIEW(dev_priv)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006161 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006162 intel_encoder->pre_enable = vlv_pre_enable_dp;
6163 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03006164 intel_encoder->post_disable = vlv_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006165 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006166 intel_encoder->pre_enable = g4x_pre_enable_dp;
6167 intel_encoder->enable = g4x_enable_dp;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006168 if (INTEL_GEN(dev_priv) >= 5)
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03006169 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006170 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006171
Paulo Zanoni174edf12012-10-26 19:05:50 -02006172 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006173 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02006174 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006175
Ville Syrjäläcca05022016-06-22 21:57:06 +03006176 intel_encoder->type = INTEL_OUTPUT_DP;
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02006177 intel_encoder->power_domain = intel_port_to_power_domain(port);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006178 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03006179 if (port == PORT_D)
6180 intel_encoder->crtc_mask = 1 << 2;
6181 else
6182 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
6183 } else {
6184 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
6185 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02006186 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07006187 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006188
Dave Airlie13cf5502014-06-18 11:29:35 +10006189 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03006190 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10006191
Ville Syrjälä385e4de2017-08-18 16:49:55 +03006192 if (port != PORT_A)
6193 intel_infoframe_init(intel_dig_port);
6194
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306195 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
6196 goto err_init_connector;
6197
Chris Wilson457c52d2016-06-01 08:27:50 +01006198 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306199
6200err_init_connector:
6201 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306202err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306203 kfree(intel_connector);
6204err_connector_alloc:
6205 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01006206 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006207}
Dave Airlie0e32b392014-05-02 14:02:48 +10006208
6209void intel_dp_mst_suspend(struct drm_device *dev)
6210{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006211 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006212 int i;
6213
6214 /* disable MST */
6215 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006216 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006217
6218 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006219 continue;
6220
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006221 if (intel_dig_port->dp.is_mst)
6222 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10006223 }
6224}
6225
6226void intel_dp_mst_resume(struct drm_device *dev)
6227{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006228 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006229 int i;
6230
6231 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006232 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006233 int ret;
6234
6235 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006236 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10006237
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006238 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
6239 if (ret)
6240 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10006241 }
6242}