blob: 8db6b11f103f25201434106cf29371bd7e73baef [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,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03001864 const 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,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002464 const 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,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002691 const struct intel_crtc_state *old_crtc_state,
2692 const 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))
Ville Syrjäläd2419ff2017-08-18 16:49:56 +03002701 intel_psr_disable(intel_dp, old_crtc_state);
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002702
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,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002716 const struct intel_crtc_state *old_crtc_state,
2717 const 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,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002730 const struct intel_crtc_state *old_crtc_state,
2731 const 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,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002739 const struct intel_crtc_state *old_crtc_state,
2740 const 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,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002845 const 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,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002869 const struct intel_crtc_state *pipe_config,
2870 const 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,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002917 const struct intel_crtc_state *pipe_config,
2918 const 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,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002925 const struct intel_crtc_state *pipe_config,
2926 const 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);
Ville Syrjäläd2419ff2017-08-18 16:49:56 +03002931 intel_psr_enable(intel_dp, pipe_config);
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,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002935 const struct intel_crtc_state *pipe_config,
2936 const 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,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003058 const struct intel_crtc_state *pipe_config,
3059 const 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,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003067 const struct intel_crtc_state *pipe_config,
3068 const 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,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003076 const struct intel_crtc_state *pipe_config,
3077 const 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,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003088 const struct intel_crtc_state *pipe_config,
3089 const 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,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03003097 const struct intel_crtc_state *pipe_config,
3098 const 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
Rodrigo Vivid509af62017-08-29 16:22:24 -07003509 if (IS_GEN9_LP(dev_priv) || IS_CANNONLAKE(dev_priv)) {
3510 signal_levels = bxt_signal_levels(intel_dp);
3511 } else if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003512 signal_levels = ddi_signal_levels(intel_dp);
Rodrigo Vivid509af62017-08-29 16:22:24 -07003513 mask = DDI_BUF_EMP_MASK;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003514 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003515 signal_levels = chv_signal_levels(intel_dp);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003516 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003517 signal_levels = vlv_signal_levels(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003518 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003519 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003520 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003521 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003522 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003523 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3524 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003525 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003526 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3527 }
3528
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303529 if (mask)
3530 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3531
3532 DRM_DEBUG_KMS("Using vswing level %d\n",
3533 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3534 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3535 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3536 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003537
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003538 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003539
3540 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3541 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003542}
3543
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003544void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003545intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3546 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003547{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003548 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003549 struct drm_i915_private *dev_priv =
3550 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003551
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003552 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003553
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003554 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003555 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003556}
3557
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003558void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003559{
3560 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3561 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003562 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak3ab9c632013-05-03 12:57:41 +03003563 enum port port = intel_dig_port->port;
3564 uint32_t val;
3565
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003566 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003567 return;
3568
3569 val = I915_READ(DP_TP_CTL(port));
3570 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3571 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3572 I915_WRITE(DP_TP_CTL(port), val);
3573
3574 /*
3575 * On PORT_A we can have only eDP in SST mode. There the only reason
3576 * we need to set idle transmission mode is to work around a HW issue
3577 * where we enable the pipe while not in idle link-training mode.
3578 * In this case there is requirement to wait for a minimum number of
3579 * idle patterns to be sent.
3580 */
3581 if (port == PORT_A)
3582 return;
3583
Chris Wilsona7670172016-06-30 15:33:10 +01003584 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3585 DP_TP_STATUS_IDLE_DONE,
3586 DP_TP_STATUS_IDLE_DONE,
3587 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003588 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3589}
3590
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003591static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003592intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003593{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003594 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003595 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003596 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003597 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003598 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003599 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003600
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003601 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003602 return;
3603
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003604 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003605 return;
3606
Zhao Yakui28c97732009-10-09 11:39:41 +08003607 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003608
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003609 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003610 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003611 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003612 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003613 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003614 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003615 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3616 else
3617 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003618 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003619 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003620 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003621 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003622
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003623 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3624 I915_WRITE(intel_dp->output_reg, DP);
3625 POSTING_READ(intel_dp->output_reg);
3626
3627 /*
3628 * HW workaround for IBX, we need to move the port
3629 * to transcoder A after disabling it to allow the
3630 * matching HDMI port to be enabled on transcoder A.
3631 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003632 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003633 /*
3634 * We get CPU/PCH FIFO underruns on the other pipe when
3635 * doing the workaround. Sweep them under the rug.
3636 */
3637 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3638 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3639
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003640 /* always enable with pattern 1 (as per spec) */
3641 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3642 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3643 I915_WRITE(intel_dp->output_reg, DP);
3644 POSTING_READ(intel_dp->output_reg);
3645
3646 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003647 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003648 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003649
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003650 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003651 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3652 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003653 }
3654
Keith Packardf01eca22011-09-28 16:48:10 -07003655 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003656
3657 intel_dp->DP = DP;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003658
3659 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3660 pps_lock(intel_dp);
3661 intel_dp->active_pipe = INVALID_PIPE;
3662 pps_unlock(intel_dp);
3663 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003664}
3665
Imre Deak24e807e2016-10-24 19:33:28 +03003666bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003667intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003668{
Lyude9f085eb2016-04-13 10:58:33 -04003669 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3670 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003671 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003672
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003673 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003674
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003675 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3676}
3677
3678static bool
3679intel_edp_init_dpcd(struct intel_dp *intel_dp)
3680{
3681 struct drm_i915_private *dev_priv =
3682 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3683
3684 /* this function is meant to be called only once */
3685 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3686
3687 if (!intel_dp_read_dpcd(intel_dp))
3688 return false;
3689
Jani Nikula84c36752017-05-18 14:10:23 +03003690 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
3691 drm_dp_is_branch(intel_dp->dpcd));
Imre Deak12a47a422016-10-24 19:33:29 +03003692
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003693 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3694 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3695 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3696
3697 /* Check if the panel supports PSR */
3698 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3699 intel_dp->psr_dpcd,
3700 sizeof(intel_dp->psr_dpcd));
3701 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3702 dev_priv->psr.sink_support = true;
3703 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3704 }
3705
3706 if (INTEL_GEN(dev_priv) >= 9 &&
3707 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3708 uint8_t frame_sync_cap;
3709
3710 dev_priv->psr.sink_support = true;
Imre Deak9bacd4b2017-05-10 12:21:48 +03003711 if (drm_dp_dpcd_readb(&intel_dp->aux,
3712 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3713 &frame_sync_cap) != 1)
3714 frame_sync_cap = 0;
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003715 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3716 /* PSR2 needs frame sync as well */
3717 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3718 DRM_DEBUG_KMS("PSR2 %s on sink",
3719 dev_priv->psr.psr2_support ? "supported" : "not supported");
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303720
3721 if (dev_priv->psr.psr2_support) {
3722 dev_priv->psr.y_cord_support =
3723 intel_dp_get_y_cord_status(intel_dp);
3724 dev_priv->psr.colorimetry_support =
3725 intel_dp_get_colorimetry_status(intel_dp);
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303726 dev_priv->psr.alpm =
3727 intel_dp_get_alpm_status(intel_dp);
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303728 }
3729
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003730 }
3731
3732 /* Read the eDP Display control capabilities registers */
3733 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
3734 drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003735 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3736 sizeof(intel_dp->edp_dpcd))
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003737 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3738 intel_dp->edp_dpcd);
3739
3740 /* Intermediate frequency support */
3741 if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */
3742 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3743 int i;
3744
3745 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3746 sink_rates, sizeof(sink_rates));
3747
3748 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3749 int val = le16_to_cpu(sink_rates[i]);
3750
3751 if (val == 0)
3752 break;
3753
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -08003754 /* Value read multiplied by 200kHz gives the per-lane
3755 * link rate in kHz. The source rates are, however,
3756 * stored in terms of LS_Clk kHz. The full conversion
3757 * back to symbols is
3758 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
3759 */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003760 intel_dp->sink_rates[i] = (val * 200) / 10;
3761 }
3762 intel_dp->num_sink_rates = i;
3763 }
3764
Jani Nikula68f357c2017-03-28 17:59:05 +03003765 if (intel_dp->num_sink_rates)
3766 intel_dp->use_rate_select = true;
3767 else
3768 intel_dp_set_sink_rates(intel_dp);
3769
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003770 intel_dp_set_common_rates(intel_dp);
3771
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003772 return true;
3773}
3774
3775
3776static bool
3777intel_dp_get_dpcd(struct intel_dp *intel_dp)
3778{
Jani Nikula27dbefb2017-04-06 16:44:17 +03003779 u8 sink_count;
3780
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003781 if (!intel_dp_read_dpcd(intel_dp))
3782 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003783
Jani Nikula68f357c2017-03-28 17:59:05 +03003784 /* Don't clobber cached eDP rates. */
Jani Nikula1853a9d2017-08-18 12:30:20 +03003785 if (!intel_dp_is_edp(intel_dp)) {
Jani Nikula68f357c2017-03-28 17:59:05 +03003786 intel_dp_set_sink_rates(intel_dp);
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003787 intel_dp_set_common_rates(intel_dp);
3788 }
Jani Nikula68f357c2017-03-28 17:59:05 +03003789
Jani Nikula27dbefb2017-04-06 16:44:17 +03003790 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_SINK_COUNT, &sink_count) <= 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303791 return false;
3792
3793 /*
3794 * Sink count can change between short pulse hpd hence
3795 * a member variable in intel_dp will track any changes
3796 * between short pulse interrupts.
3797 */
Jani Nikula27dbefb2017-04-06 16:44:17 +03003798 intel_dp->sink_count = DP_GET_SINK_COUNT(sink_count);
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303799
3800 /*
3801 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3802 * a dongle is present but no display. Unless we require to know
3803 * if a dongle is present or not, we don't need to update
3804 * downstream port information. So, an early return here saves
3805 * time from performing other operations which are not required.
3806 */
Jani Nikula1853a9d2017-08-18 12:30:20 +03003807 if (!intel_dp_is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303808 return false;
3809
Imre Deakc726ad02016-10-24 19:33:24 +03003810 if (!drm_dp_is_branch(intel_dp->dpcd))
Adam Jacksonedb39242012-09-18 10:58:49 -04003811 return true; /* native DP sink */
3812
3813 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3814 return true; /* no per-port downstream info */
3815
Lyude9f085eb2016-04-13 10:58:33 -04003816 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3817 intel_dp->downstream_ports,
3818 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003819 return false; /* downstream port status fetch failed */
3820
3821 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003822}
3823
Dave Airlie0e32b392014-05-02 14:02:48 +10003824static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003825intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003826{
Jani Nikula010b9b32017-04-06 16:44:16 +03003827 u8 mstm_cap;
Dave Airlie0e32b392014-05-02 14:02:48 +10003828
Nathan Schulte7cc96132016-03-15 10:14:05 -05003829 if (!i915.enable_dp_mst)
3830 return false;
3831
Dave Airlie0e32b392014-05-02 14:02:48 +10003832 if (!intel_dp->can_mst)
3833 return false;
3834
3835 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3836 return false;
3837
Jani Nikula010b9b32017-04-06 16:44:16 +03003838 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_MSTM_CAP, &mstm_cap) != 1)
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003839 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003840
Jani Nikula010b9b32017-04-06 16:44:16 +03003841 return mstm_cap & DP_MST_CAP;
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003842}
3843
3844static void
3845intel_dp_configure_mst(struct intel_dp *intel_dp)
3846{
3847 if (!i915.enable_dp_mst)
3848 return;
3849
3850 if (!intel_dp->can_mst)
3851 return;
3852
3853 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3854
3855 if (intel_dp->is_mst)
3856 DRM_DEBUG_KMS("Sink is MST capable\n");
3857 else
3858 DRM_DEBUG_KMS("Sink is not MST capable\n");
3859
3860 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3861 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003862}
3863
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003864static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003865{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003866 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003867 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003868 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003869 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003870 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003871 int count = 0;
3872 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003873
3874 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003875 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003876 ret = -EIO;
3877 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003878 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003879
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003880 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003881 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003882 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003883 ret = -EIO;
3884 goto out;
3885 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003886
Rodrigo Vivic6297842015-11-05 10:50:20 -08003887 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003888 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivic6297842015-11-05 10:50:20 -08003889
3890 if (drm_dp_dpcd_readb(&intel_dp->aux,
3891 DP_TEST_SINK_MISC, &buf) < 0) {
3892 ret = -EIO;
3893 goto out;
3894 }
3895 count = buf & DP_TEST_COUNT_MASK;
3896 } while (--attempts && count);
3897
3898 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003899 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003900 ret = -ETIMEDOUT;
3901 }
3902
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003903 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003904 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003905 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003906}
3907
3908static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3909{
3910 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003911 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003912 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3913 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003914 int ret;
3915
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003916 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3917 return -EIO;
3918
3919 if (!(buf & DP_TEST_CRC_SUPPORTED))
3920 return -ENOTTY;
3921
3922 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3923 return -EIO;
3924
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003925 if (buf & DP_TEST_SINK_START) {
3926 ret = intel_dp_sink_crc_stop(intel_dp);
3927 if (ret)
3928 return ret;
3929 }
3930
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003931 hsw_disable_ips(intel_crtc);
3932
3933 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3934 buf | DP_TEST_SINK_START) < 0) {
3935 hsw_enable_ips(intel_crtc);
3936 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003937 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003938
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003939 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003940 return 0;
3941}
3942
3943int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3944{
3945 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003946 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003947 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3948 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003949 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003950 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003951
3952 ret = intel_dp_sink_crc_start(intel_dp);
3953 if (ret)
3954 return ret;
3955
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003956 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003957 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003958
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003959 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003960 DP_TEST_SINK_MISC, &buf) < 0) {
3961 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003962 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003963 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003964 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07003965
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003966 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003967
3968 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003969 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
3970 ret = -ETIMEDOUT;
3971 goto stop;
3972 }
3973
3974 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
3975 ret = -EIO;
3976 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003977 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003978
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003979stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003980 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003981 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003982}
3983
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003984static bool
3985intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3986{
Jani Nikula010b9b32017-04-06 16:44:16 +03003987 return drm_dp_dpcd_readb(&intel_dp->aux, DP_DEVICE_SERVICE_IRQ_VECTOR,
3988 sink_irq_vector) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003989}
3990
Dave Airlie0e32b392014-05-02 14:02:48 +10003991static bool
3992intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3993{
3994 int ret;
3995
Lyude9f085eb2016-04-13 10:58:33 -04003996 ret = drm_dp_dpcd_read(&intel_dp->aux,
Dave Airlie0e32b392014-05-02 14:02:48 +10003997 DP_SINK_COUNT_ESI,
3998 sink_irq_vector, 14);
3999 if (ret != 14)
4000 return false;
4001
4002 return true;
4003}
4004
Todd Previtec5d5ab72015-04-15 08:38:38 -07004005static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004006{
Manasi Navareda15f7c2017-01-24 08:16:34 -08004007 int status = 0;
Manasi Navare140ef132017-06-08 13:41:03 -07004008 int test_link_rate;
Manasi Navareda15f7c2017-01-24 08:16:34 -08004009 uint8_t test_lane_count, test_link_bw;
4010 /* (DP CTS 1.2)
4011 * 4.3.1.11
4012 */
4013 /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */
4014 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT,
4015 &test_lane_count);
4016
4017 if (status <= 0) {
4018 DRM_DEBUG_KMS("Lane count read failed\n");
4019 return DP_TEST_NAK;
4020 }
4021 test_lane_count &= DP_MAX_LANE_COUNT_MASK;
Manasi Navareda15f7c2017-01-24 08:16:34 -08004022
4023 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE,
4024 &test_link_bw);
4025 if (status <= 0) {
4026 DRM_DEBUG_KMS("Link Rate read failed\n");
4027 return DP_TEST_NAK;
4028 }
Manasi Navareda15f7c2017-01-24 08:16:34 -08004029 test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw);
Manasi Navare140ef132017-06-08 13:41:03 -07004030
4031 /* Validate the requested link rate and lane count */
4032 if (!intel_dp_link_params_valid(intel_dp, test_link_rate,
4033 test_lane_count))
Manasi Navareda15f7c2017-01-24 08:16:34 -08004034 return DP_TEST_NAK;
4035
4036 intel_dp->compliance.test_lane_count = test_lane_count;
4037 intel_dp->compliance.test_link_rate = test_link_rate;
4038
4039 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004040}
4041
4042static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
4043{
Manasi Navare611032b2017-01-24 08:21:49 -08004044 uint8_t test_pattern;
Jani Nikula010b9b32017-04-06 16:44:16 +03004045 uint8_t test_misc;
Manasi Navare611032b2017-01-24 08:21:49 -08004046 __be16 h_width, v_height;
4047 int status = 0;
4048
4049 /* Read the TEST_PATTERN (DP CTS 3.1.5) */
Jani Nikula010b9b32017-04-06 16:44:16 +03004050 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_PATTERN,
4051 &test_pattern);
Manasi Navare611032b2017-01-24 08:21:49 -08004052 if (status <= 0) {
4053 DRM_DEBUG_KMS("Test pattern read failed\n");
4054 return DP_TEST_NAK;
4055 }
4056 if (test_pattern != DP_COLOR_RAMP)
4057 return DP_TEST_NAK;
4058
4059 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI,
4060 &h_width, 2);
4061 if (status <= 0) {
4062 DRM_DEBUG_KMS("H Width read failed\n");
4063 return DP_TEST_NAK;
4064 }
4065
4066 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI,
4067 &v_height, 2);
4068 if (status <= 0) {
4069 DRM_DEBUG_KMS("V Height read failed\n");
4070 return DP_TEST_NAK;
4071 }
4072
Jani Nikula010b9b32017-04-06 16:44:16 +03004073 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_MISC0,
4074 &test_misc);
Manasi Navare611032b2017-01-24 08:21:49 -08004075 if (status <= 0) {
4076 DRM_DEBUG_KMS("TEST MISC read failed\n");
4077 return DP_TEST_NAK;
4078 }
4079 if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB)
4080 return DP_TEST_NAK;
4081 if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA)
4082 return DP_TEST_NAK;
4083 switch (test_misc & DP_TEST_BIT_DEPTH_MASK) {
4084 case DP_TEST_BIT_DEPTH_6:
4085 intel_dp->compliance.test_data.bpc = 6;
4086 break;
4087 case DP_TEST_BIT_DEPTH_8:
4088 intel_dp->compliance.test_data.bpc = 8;
4089 break;
4090 default:
4091 return DP_TEST_NAK;
4092 }
4093
4094 intel_dp->compliance.test_data.video_pattern = test_pattern;
4095 intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width);
4096 intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height);
4097 /* Set test active flag here so userspace doesn't interrupt things */
4098 intel_dp->compliance.test_active = 1;
4099
4100 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004101}
4102
4103static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
4104{
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004105 uint8_t test_result = DP_TEST_ACK;
Todd Previte559be302015-05-04 07:48:20 -07004106 struct intel_connector *intel_connector = intel_dp->attached_connector;
4107 struct drm_connector *connector = &intel_connector->base;
4108
4109 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02004110 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07004111 intel_dp->aux.i2c_defer_count > 6) {
4112 /* Check EDID read for NACKs, DEFERs and corruption
4113 * (DP CTS 1.2 Core r1.1)
4114 * 4.2.2.4 : Failed EDID read, I2C_NAK
4115 * 4.2.2.5 : Failed EDID read, I2C_DEFER
4116 * 4.2.2.6 : EDID corruption detected
4117 * Use failsafe mode for all cases
4118 */
4119 if (intel_dp->aux.i2c_nack_count > 0 ||
4120 intel_dp->aux.i2c_defer_count > 0)
4121 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
4122 intel_dp->aux.i2c_nack_count,
4123 intel_dp->aux.i2c_defer_count);
Manasi Navarec1617ab2016-12-09 16:22:50 -08004124 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
Todd Previte559be302015-05-04 07:48:20 -07004125 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05304126 struct edid *block = intel_connector->detect_edid;
4127
4128 /* We have to write the checksum
4129 * of the last block read
4130 */
4131 block += intel_connector->detect_edid->extensions;
4132
Jani Nikula010b9b32017-04-06 16:44:16 +03004133 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_EDID_CHECKSUM,
4134 block->checksum) <= 0)
Todd Previte559be302015-05-04 07:48:20 -07004135 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
4136
4137 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004138 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED;
Todd Previte559be302015-05-04 07:48:20 -07004139 }
4140
4141 /* Set test active flag here so userspace doesn't interrupt things */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004142 intel_dp->compliance.test_active = 1;
Todd Previte559be302015-05-04 07:48:20 -07004143
Todd Previtec5d5ab72015-04-15 08:38:38 -07004144 return test_result;
4145}
4146
4147static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
4148{
4149 uint8_t test_result = DP_TEST_NAK;
4150 return test_result;
4151}
4152
4153static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
4154{
4155 uint8_t response = DP_TEST_NAK;
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004156 uint8_t request = 0;
4157 int status;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004158
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004159 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004160 if (status <= 0) {
4161 DRM_DEBUG_KMS("Could not read test request from sink\n");
4162 goto update_status;
4163 }
4164
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004165 switch (request) {
Todd Previtec5d5ab72015-04-15 08:38:38 -07004166 case DP_TEST_LINK_TRAINING:
4167 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004168 response = intel_dp_autotest_link_training(intel_dp);
4169 break;
4170 case DP_TEST_LINK_VIDEO_PATTERN:
4171 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004172 response = intel_dp_autotest_video_pattern(intel_dp);
4173 break;
4174 case DP_TEST_LINK_EDID_READ:
4175 DRM_DEBUG_KMS("EDID test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004176 response = intel_dp_autotest_edid(intel_dp);
4177 break;
4178 case DP_TEST_LINK_PHY_TEST_PATTERN:
4179 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004180 response = intel_dp_autotest_phy_pattern(intel_dp);
4181 break;
4182 default:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004183 DRM_DEBUG_KMS("Invalid test request '%02x'\n", request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004184 break;
4185 }
4186
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004187 if (response & DP_TEST_ACK)
4188 intel_dp->compliance.test_type = request;
4189
Todd Previtec5d5ab72015-04-15 08:38:38 -07004190update_status:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004191 status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004192 if (status <= 0)
4193 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004194}
4195
Dave Airlie0e32b392014-05-02 14:02:48 +10004196static int
4197intel_dp_check_mst_status(struct intel_dp *intel_dp)
4198{
4199 bool bret;
4200
4201 if (intel_dp->is_mst) {
4202 u8 esi[16] = { 0 };
4203 int ret = 0;
4204 int retry;
4205 bool handled;
4206 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4207go_again:
4208 if (bret == true) {
4209
4210 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03004211 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03004212 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10004213 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4214 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004215 intel_dp_stop_link_train(intel_dp);
4216 }
4217
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004218 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004219 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4220
4221 if (handled) {
4222 for (retry = 0; retry < 3; retry++) {
4223 int wret;
4224 wret = drm_dp_dpcd_write(&intel_dp->aux,
4225 DP_SINK_COUNT_ESI+1,
4226 &esi[1], 3);
4227 if (wret == 3) {
4228 break;
4229 }
4230 }
4231
4232 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4233 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004234 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004235 goto go_again;
4236 }
4237 } else
4238 ret = 0;
4239
4240 return ret;
4241 } else {
4242 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4243 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4244 intel_dp->is_mst = false;
4245 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4246 /* send a hotplug event */
4247 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4248 }
4249 }
4250 return -EINVAL;
4251}
4252
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304253static void
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004254intel_dp_retrain_link(struct intel_dp *intel_dp)
4255{
4256 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4257 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4258 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
4259
4260 /* Suppress underruns caused by re-training */
4261 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4262 if (crtc->config->has_pch_encoder)
4263 intel_set_pch_fifo_underrun_reporting(dev_priv,
4264 intel_crtc_pch_transcoder(crtc), false);
4265
4266 intel_dp_start_link_train(intel_dp);
4267 intel_dp_stop_link_train(intel_dp);
4268
4269 /* Keep underrun reporting disabled until things are stable */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02004270 intel_wait_for_vblank(dev_priv, crtc->pipe);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004271
4272 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4273 if (crtc->config->has_pch_encoder)
4274 intel_set_pch_fifo_underrun_reporting(dev_priv,
4275 intel_crtc_pch_transcoder(crtc), true);
4276}
4277
4278static void
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304279intel_dp_check_link_status(struct intel_dp *intel_dp)
4280{
4281 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4282 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4283 u8 link_status[DP_LINK_STATUS_SIZE];
4284
4285 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
4286
4287 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4288 DRM_ERROR("Failed to get link status\n");
4289 return;
4290 }
4291
4292 if (!intel_encoder->base.crtc)
4293 return;
4294
4295 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4296 return;
4297
Manasi Navare14c562c2017-04-06 14:00:12 -07004298 /*
4299 * Validate the cached values of intel_dp->link_rate and
4300 * intel_dp->lane_count before attempting to retrain.
4301 */
Manasi Navare1a92c702017-06-08 13:41:02 -07004302 if (!intel_dp_link_params_valid(intel_dp, intel_dp->link_rate,
4303 intel_dp->lane_count))
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004304 return;
4305
Manasi Navareda15f7c2017-01-24 08:16:34 -08004306 /* Retrain if Channel EQ or CR not ok */
4307 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304308 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4309 intel_encoder->base.name);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004310
4311 intel_dp_retrain_link(intel_dp);
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304312 }
4313}
4314
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004315/*
4316 * According to DP spec
4317 * 5.1.2:
4318 * 1. Read DPCD
4319 * 2. Configure link according to Receiver Capabilities
4320 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4321 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304322 *
4323 * intel_dp_short_pulse - handles short pulse interrupts
4324 * when full detection is not required.
4325 * Returns %true if short pulse is handled and full detection
4326 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004327 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304328static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304329intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004330{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004331 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004332 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004333 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304334 u8 old_sink_count = intel_dp->sink_count;
4335 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004336
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304337 /*
4338 * Clearing compliance test variables to allow capturing
4339 * of values for next automated test request.
4340 */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004341 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304342
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304343 /*
4344 * Now read the DPCD to see if it's actually running
4345 * If the current value of sink count doesn't match with
4346 * the value that was stored earlier or dpcd read failed
4347 * we need to do full detection
4348 */
4349 ret = intel_dp_get_dpcd(intel_dp);
4350
4351 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4352 /* No need to proceed if we are going to do full detect */
4353 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004354 }
4355
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004356 /* Try to read the source of the interrupt */
4357 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004358 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4359 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004360 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004361 drm_dp_dpcd_writeb(&intel_dp->aux,
4362 DP_DEVICE_SERVICE_IRQ_VECTOR,
4363 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004364
4365 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Manasi Navareda15f7c2017-01-24 08:16:34 -08004366 intel_dp_handle_test_request(intel_dp);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004367 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4368 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4369 }
4370
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304371 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4372 intel_dp_check_link_status(intel_dp);
4373 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004374 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
4375 DRM_DEBUG_KMS("Link Training Compliance Test requested\n");
4376 /* Send a Hotplug Uevent to userspace to start modeset */
4377 drm_kms_helper_hotplug_event(intel_encoder->base.dev);
4378 }
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304379
4380 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004381}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004382
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004383/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004384static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004385intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004386{
Imre Deake393d0d2017-02-22 17:10:52 +02004387 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004388 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004389 uint8_t type;
4390
Imre Deake393d0d2017-02-22 17:10:52 +02004391 if (lspcon->active)
4392 lspcon_resume(lspcon);
4393
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004394 if (!intel_dp_get_dpcd(intel_dp))
4395 return connector_status_disconnected;
4396
Jani Nikula1853a9d2017-08-18 12:30:20 +03004397 if (intel_dp_is_edp(intel_dp))
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304398 return connector_status_connected;
4399
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004400 /* if there's no downstream port, we're done */
Imre Deakc726ad02016-10-24 19:33:24 +03004401 if (!drm_dp_is_branch(dpcd))
Keith Packard26d61aa2011-07-25 20:01:09 -07004402 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004403
4404 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004405 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4406 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004407
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304408 return intel_dp->sink_count ?
4409 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004410 }
4411
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004412 if (intel_dp_can_mst(intel_dp))
4413 return connector_status_connected;
4414
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004415 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004416 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004417 return connector_status_connected;
4418
4419 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004420 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4421 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4422 if (type == DP_DS_PORT_TYPE_VGA ||
4423 type == DP_DS_PORT_TYPE_NON_EDID)
4424 return connector_status_unknown;
4425 } else {
4426 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4427 DP_DWN_STRM_PORT_TYPE_MASK;
4428 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4429 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4430 return connector_status_unknown;
4431 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004432
4433 /* Anything else is out of spec, warn and ignore */
4434 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004435 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004436}
4437
4438static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004439edp_detect(struct intel_dp *intel_dp)
4440{
4441 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Mika Kahola1650be72016-12-13 10:02:47 +02004442 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsond410b562014-09-02 20:03:59 +01004443 enum drm_connector_status status;
4444
Mika Kahola1650be72016-12-13 10:02:47 +02004445 status = intel_panel_detect(dev_priv);
Chris Wilsond410b562014-09-02 20:03:59 +01004446 if (status == connector_status_unknown)
4447 status = connector_status_connected;
4448
4449 return status;
4450}
4451
Jani Nikulab93433c2015-08-20 10:47:36 +03004452static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4453 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004454{
Jani Nikulab93433c2015-08-20 10:47:36 +03004455 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004456
Jani Nikula0df53b72015-08-20 10:47:40 +03004457 switch (port->port) {
Jani Nikula0df53b72015-08-20 10:47:40 +03004458 case PORT_B:
4459 bit = SDE_PORTB_HOTPLUG;
4460 break;
4461 case PORT_C:
4462 bit = SDE_PORTC_HOTPLUG;
4463 break;
4464 case PORT_D:
4465 bit = SDE_PORTD_HOTPLUG;
4466 break;
4467 default:
4468 MISSING_CASE(port->port);
4469 return false;
4470 }
4471
4472 return I915_READ(SDEISR) & bit;
4473}
4474
4475static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4476 struct intel_digital_port *port)
4477{
4478 u32 bit;
4479
4480 switch (port->port) {
Jani Nikula0df53b72015-08-20 10:47:40 +03004481 case PORT_B:
4482 bit = SDE_PORTB_HOTPLUG_CPT;
4483 break;
4484 case PORT_C:
4485 bit = SDE_PORTC_HOTPLUG_CPT;
4486 break;
4487 case PORT_D:
4488 bit = SDE_PORTD_HOTPLUG_CPT;
4489 break;
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004490 default:
4491 MISSING_CASE(port->port);
4492 return false;
4493 }
4494
4495 return I915_READ(SDEISR) & bit;
4496}
4497
4498static bool spt_digital_port_connected(struct drm_i915_private *dev_priv,
4499 struct intel_digital_port *port)
4500{
4501 u32 bit;
4502
4503 switch (port->port) {
4504 case PORT_A:
4505 bit = SDE_PORTA_HOTPLUG_SPT;
4506 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004507 case PORT_E:
4508 bit = SDE_PORTE_HOTPLUG_SPT;
4509 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004510 default:
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004511 return cpt_digital_port_connected(dev_priv, port);
Jani Nikulab93433c2015-08-20 10:47:36 +03004512 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004513
Jani Nikulab93433c2015-08-20 10:47:36 +03004514 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004515}
4516
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004517static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004518 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004519{
Jani Nikula9642c812015-08-20 10:47:41 +03004520 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004521
Jani Nikula9642c812015-08-20 10:47:41 +03004522 switch (port->port) {
4523 case PORT_B:
4524 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4525 break;
4526 case PORT_C:
4527 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4528 break;
4529 case PORT_D:
4530 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4531 break;
4532 default:
4533 MISSING_CASE(port->port);
4534 return false;
4535 }
4536
4537 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4538}
4539
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004540static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4541 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004542{
4543 u32 bit;
4544
4545 switch (port->port) {
4546 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004547 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004548 break;
4549 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004550 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004551 break;
4552 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004553 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004554 break;
4555 default:
4556 MISSING_CASE(port->port);
4557 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004558 }
4559
Jani Nikula1d245982015-08-20 10:47:37 +03004560 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004561}
4562
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004563static bool ilk_digital_port_connected(struct drm_i915_private *dev_priv,
4564 struct intel_digital_port *port)
4565{
4566 if (port->port == PORT_A)
4567 return I915_READ(DEISR) & DE_DP_A_HOTPLUG;
4568 else
4569 return ibx_digital_port_connected(dev_priv, port);
4570}
4571
4572static bool snb_digital_port_connected(struct drm_i915_private *dev_priv,
4573 struct intel_digital_port *port)
4574{
4575 if (port->port == PORT_A)
4576 return I915_READ(DEISR) & DE_DP_A_HOTPLUG;
4577 else
4578 return cpt_digital_port_connected(dev_priv, port);
4579}
4580
4581static bool ivb_digital_port_connected(struct drm_i915_private *dev_priv,
4582 struct intel_digital_port *port)
4583{
4584 if (port->port == PORT_A)
4585 return I915_READ(DEISR) & DE_DP_A_HOTPLUG_IVB;
4586 else
4587 return cpt_digital_port_connected(dev_priv, port);
4588}
4589
4590static bool bdw_digital_port_connected(struct drm_i915_private *dev_priv,
4591 struct intel_digital_port *port)
4592{
4593 if (port->port == PORT_A)
4594 return I915_READ(GEN8_DE_PORT_ISR) & GEN8_PORT_DP_A_HOTPLUG;
4595 else
4596 return cpt_digital_port_connected(dev_priv, port);
4597}
4598
Jani Nikulae464bfd2015-08-20 10:47:42 +03004599static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304600 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004601{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304602 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4603 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004604 u32 bit;
4605
Rodrigo Vivi256cfdd2017-08-11 11:26:49 -07004606 port = intel_hpd_pin_to_port(intel_encoder->hpd_pin);
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304607 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004608 case PORT_A:
4609 bit = BXT_DE_PORT_HP_DDIA;
4610 break;
4611 case PORT_B:
4612 bit = BXT_DE_PORT_HP_DDIB;
4613 break;
4614 case PORT_C:
4615 bit = BXT_DE_PORT_HP_DDIC;
4616 break;
4617 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304618 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004619 return false;
4620 }
4621
4622 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4623}
4624
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004625/*
4626 * intel_digital_port_connected - is the specified port connected?
4627 * @dev_priv: i915 private structure
4628 * @port: the port to test
4629 *
4630 * Return %true if @port is connected, %false otherwise.
4631 */
Imre Deak390b4e02017-01-27 11:39:19 +02004632bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
4633 struct intel_digital_port *port)
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004634{
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004635 if (HAS_GMCH_DISPLAY(dev_priv)) {
4636 if (IS_GM45(dev_priv))
4637 return gm45_digital_port_connected(dev_priv, port);
4638 else
4639 return g4x_digital_port_connected(dev_priv, port);
4640 }
4641
4642 if (IS_GEN5(dev_priv))
4643 return ilk_digital_port_connected(dev_priv, port);
4644 else if (IS_GEN6(dev_priv))
4645 return snb_digital_port_connected(dev_priv, port);
4646 else if (IS_GEN7(dev_priv))
4647 return ivb_digital_port_connected(dev_priv, port);
4648 else if (IS_GEN8(dev_priv))
4649 return bdw_digital_port_connected(dev_priv, port);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004650 else if (IS_GEN9_LP(dev_priv))
Jani Nikulae464bfd2015-08-20 10:47:42 +03004651 return bxt_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004652 else
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004653 return spt_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004654}
4655
Keith Packard8c241fe2011-09-28 16:38:44 -07004656static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004657intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004658{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004659 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004660
Jani Nikula9cd300e2012-10-19 14:51:52 +03004661 /* use cached edid if we have one */
4662 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004663 /* invalid edid */
4664 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004665 return NULL;
4666
Jani Nikula55e9ede2013-10-01 10:38:54 +03004667 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004668 } else
4669 return drm_get_edid(&intel_connector->base,
4670 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004671}
4672
Chris Wilsonbeb60602014-09-02 20:04:00 +01004673static void
4674intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004675{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004676 struct intel_connector *intel_connector = intel_dp->attached_connector;
4677 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004678
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304679 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004680 edid = intel_dp_get_edid(intel_dp);
4681 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004682
Maarten Lankhorste6b72c92017-05-01 15:38:00 +02004683 intel_dp->has_audio = drm_detect_monitor_audio(edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004684}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004685
Chris Wilsonbeb60602014-09-02 20:04:00 +01004686static void
4687intel_dp_unset_edid(struct intel_dp *intel_dp)
4688{
4689 struct intel_connector *intel_connector = intel_dp->attached_connector;
4690
4691 kfree(intel_connector->detect_edid);
4692 intel_connector->detect_edid = NULL;
4693
4694 intel_dp->has_audio = false;
4695}
4696
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004697static int
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304698intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004699{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304700 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004701 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004702 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4703 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004704 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004705 enum drm_connector_status status;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004706 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004707
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004708 WARN_ON(!drm_modeset_is_locked(&connector->dev->mode_config.connection_mutex));
4709
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004710 intel_display_power_get(to_i915(dev), intel_dp->aux_power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004711
Chris Wilsond410b562014-09-02 20:03:59 +01004712 /* Can't disconnect eDP, but you can close the lid... */
Jani Nikula1853a9d2017-08-18 12:30:20 +03004713 if (intel_dp_is_edp(intel_dp))
Chris Wilsond410b562014-09-02 20:03:59 +01004714 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004715 else if (intel_digital_port_connected(to_i915(dev),
4716 dp_to_dig_port(intel_dp)))
4717 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004718 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004719 status = connector_status_disconnected;
4720
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004721 if (status == connector_status_disconnected) {
Manasi Navarec1617ab2016-12-09 16:22:50 -08004722 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304723
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004724 if (intel_dp->is_mst) {
4725 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4726 intel_dp->is_mst,
4727 intel_dp->mst_mgr.mst_state);
4728 intel_dp->is_mst = false;
4729 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4730 intel_dp->is_mst);
4731 }
4732
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004733 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304734 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004735
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304736 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004737 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304738
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004739 DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
4740 yesno(intel_dp_source_supports_hbr2(intel_dp)),
4741 yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
4742
Manasi Navared7e8ef02017-02-07 16:54:11 -08004743 if (intel_dp->reset_link_params) {
Jani Nikula540b0b7f2017-04-06 16:44:13 +03004744 /* Initial max link lane count */
4745 intel_dp->max_link_lane_count = intel_dp_max_common_lane_count(intel_dp);
Manasi Navaref4829842016-12-05 16:27:36 -08004746
Jani Nikula540b0b7f2017-04-06 16:44:13 +03004747 /* Initial max link rate */
4748 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
Manasi Navared7e8ef02017-02-07 16:54:11 -08004749
4750 intel_dp->reset_link_params = false;
4751 }
Manasi Navaref4829842016-12-05 16:27:36 -08004752
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004753 intel_dp_print_rates(intel_dp);
4754
Jani Nikula84c36752017-05-18 14:10:23 +03004755 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
4756 drm_dp_is_branch(intel_dp->dpcd));
Mika Kahola0e390a32016-09-09 14:10:53 +03004757
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004758 intel_dp_configure_mst(intel_dp);
4759
4760 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304761 /*
4762 * If we are in MST mode then this connector
4763 * won't appear connected or have anything
4764 * with EDID on it
4765 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004766 status = connector_status_disconnected;
4767 goto out;
Ville Syrjälä1a361472017-04-12 22:30:17 +03004768 } else {
4769 /*
4770 * If display is now connected check links status,
4771 * there has been known issues of link loss triggerring
4772 * long pulse.
4773 *
4774 * Some sinks (eg. ASUS PB287Q) seem to perform some
4775 * weird HPD ping pong during modesets. So we can apparently
4776 * end up with HPD going low during a modeset, and then
4777 * going back up soon after. And once that happens we must
4778 * retrain the link to get a picture. That's in case no
4779 * userspace component reacted to intermittent HPD dip.
4780 */
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304781 intel_dp_check_link_status(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004782 }
4783
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304784 /*
4785 * Clearing NACK and defer counts to get their exact values
4786 * while reading EDID which are required by Compliance tests
4787 * 4.2.2.4 and 4.2.2.5
4788 */
4789 intel_dp->aux.i2c_nack_count = 0;
4790 intel_dp->aux.i2c_defer_count = 0;
4791
Chris Wilsonbeb60602014-09-02 20:04:00 +01004792 intel_dp_set_edid(intel_dp);
Jani Nikula1853a9d2017-08-18 12:30:20 +03004793 if (intel_dp_is_edp(intel_dp) || intel_connector->detect_edid)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004794 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304795 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004796
Todd Previte09b1eb12015-04-20 15:27:34 -07004797 /* Try to read the source of the interrupt */
4798 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004799 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4800 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004801 /* Clear interrupt source */
4802 drm_dp_dpcd_writeb(&intel_dp->aux,
4803 DP_DEVICE_SERVICE_IRQ_VECTOR,
4804 sink_irq_vector);
4805
4806 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4807 intel_dp_handle_test_request(intel_dp);
4808 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4809 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4810 }
4811
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004812out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004813 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304814 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304815
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004816 intel_display_power_put(to_i915(dev), intel_dp->aux_power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004817 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304818}
4819
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004820static int
4821intel_dp_detect(struct drm_connector *connector,
4822 struct drm_modeset_acquire_ctx *ctx,
4823 bool force)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304824{
4825 struct intel_dp *intel_dp = intel_attached_dp(connector);
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004826 int status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304827
4828 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4829 connector->base.id, connector->name);
4830
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304831 /* If full detect is not performed yet, do a full detect */
4832 if (!intel_dp->detect_done)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004833 status = intel_dp_long_pulse(intel_dp->attached_connector);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304834
4835 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304836
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004837 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004838}
4839
Chris Wilsonbeb60602014-09-02 20:04:00 +01004840static void
4841intel_dp_force(struct drm_connector *connector)
4842{
4843 struct intel_dp *intel_dp = intel_attached_dp(connector);
4844 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004845 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004846
4847 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4848 connector->base.id, connector->name);
4849 intel_dp_unset_edid(intel_dp);
4850
4851 if (connector->status != connector_status_connected)
4852 return;
4853
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004854 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004855
4856 intel_dp_set_edid(intel_dp);
4857
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004858 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004859
4860 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004861 intel_encoder->type = INTEL_OUTPUT_DP;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004862}
4863
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004864static int intel_dp_get_modes(struct drm_connector *connector)
4865{
Jani Nikuladd06f902012-10-19 14:51:50 +03004866 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004867 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004868
Chris Wilsonbeb60602014-09-02 20:04:00 +01004869 edid = intel_connector->detect_edid;
4870 if (edid) {
4871 int ret = intel_connector_update_modes(connector, edid);
4872 if (ret)
4873 return ret;
4874 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004875
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004876 /* if eDP has no EDID, fall back to fixed mode */
Jani Nikula1853a9d2017-08-18 12:30:20 +03004877 if (intel_dp_is_edp(intel_attached_dp(connector)) &&
Chris Wilsonbeb60602014-09-02 20:04:00 +01004878 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004879 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004880
4881 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004882 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004883 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004884 drm_mode_probed_add(connector, mode);
4885 return 1;
4886 }
4887 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004888
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004889 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004890}
4891
Chris Wilsonf6849602010-09-19 09:29:33 +01004892static int
Chris Wilson7a418e32016-06-24 14:00:14 +01004893intel_dp_connector_register(struct drm_connector *connector)
4894{
4895 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004896 int ret;
4897
4898 ret = intel_connector_register(connector);
4899 if (ret)
4900 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004901
4902 i915_debugfs_connector_add(connector);
4903
4904 DRM_DEBUG_KMS("registering %s bus for %s\n",
4905 intel_dp->aux.name, connector->kdev->kobj.name);
4906
4907 intel_dp->aux.dev = connector->kdev;
4908 return drm_dp_aux_register(&intel_dp->aux);
4909}
4910
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004911static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004912intel_dp_connector_unregister(struct drm_connector *connector)
4913{
4914 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4915 intel_connector_unregister(connector);
4916}
4917
4918static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004919intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004920{
Jani Nikula1d508702012-10-19 14:51:49 +03004921 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004922
Chris Wilson10e972d2014-09-04 21:43:45 +01004923 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004924
Jani Nikula9cd300e2012-10-19 14:51:52 +03004925 if (!IS_ERR_OR_NULL(intel_connector->edid))
4926 kfree(intel_connector->edid);
4927
Jani Nikula1853a9d2017-08-18 12:30:20 +03004928 /*
4929 * Can't call intel_dp_is_edp() since the encoder may have been
4930 * destroyed already.
4931 */
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004932 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004933 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004934
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004935 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004936 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004937}
4938
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004939void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004940{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004941 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4942 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004943
Dave Airlie0e32b392014-05-02 14:02:48 +10004944 intel_dp_mst_encoder_cleanup(intel_dig_port);
Jani Nikula1853a9d2017-08-18 12:30:20 +03004945 if (intel_dp_is_edp(intel_dp)) {
Keith Packardbd943152011-09-18 23:09:52 -07004946 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004947 /*
4948 * vdd might still be enabled do to the delayed vdd off.
4949 * Make sure vdd is actually turned off here.
4950 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004951 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004952 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004953 pps_unlock(intel_dp);
4954
Clint Taylor01527b32014-07-07 13:01:46 -07004955 if (intel_dp->edp_notifier.notifier_call) {
4956 unregister_reboot_notifier(&intel_dp->edp_notifier);
4957 intel_dp->edp_notifier.notifier_call = NULL;
4958 }
Keith Packardbd943152011-09-18 23:09:52 -07004959 }
Chris Wilson99681882016-06-20 09:29:17 +01004960
4961 intel_dp_aux_fini(intel_dp);
4962
Imre Deakc8bd0e42014-12-12 17:57:38 +02004963 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004964 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004965}
4966
Imre Deakbf93ba62016-04-18 10:04:21 +03004967void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004968{
4969 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4970
Jani Nikula1853a9d2017-08-18 12:30:20 +03004971 if (!intel_dp_is_edp(intel_dp))
Imre Deak07f9cd02014-08-18 14:42:45 +03004972 return;
4973
Ville Syrjälä951468f2014-09-04 14:55:31 +03004974 /*
4975 * vdd might still be enabled do to the delayed vdd off.
4976 * Make sure vdd is actually turned off here.
4977 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004978 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004979 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004980 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004981 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004982}
4983
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004984static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4985{
4986 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4987 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004988 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004989
4990 lockdep_assert_held(&dev_priv->pps_mutex);
4991
4992 if (!edp_have_panel_vdd(intel_dp))
4993 return;
4994
4995 /*
4996 * The VDD bit needs a power domain reference, so if the bit is
4997 * already enabled when we boot or resume, grab this reference and
4998 * schedule a vdd off, so we don't hold on to the reference
4999 * indefinitely.
5000 */
5001 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005002 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005003
5004 edp_panel_vdd_schedule_off(intel_dp);
5005}
5006
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005007static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
5008{
5009 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5010
5011 if ((intel_dp->DP & DP_PORT_EN) == 0)
5012 return INVALID_PIPE;
5013
5014 if (IS_CHERRYVIEW(dev_priv))
5015 return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
5016 else
5017 return PORT_TO_PIPE(intel_dp->DP);
5018}
5019
Imre Deakbf93ba62016-04-18 10:04:21 +03005020void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03005021{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005022 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Imre Deakdd75f6d2016-11-21 21:15:05 +02005023 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
5024 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005025
5026 if (!HAS_DDI(dev_priv))
5027 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005028
Imre Deakdd75f6d2016-11-21 21:15:05 +02005029 if (lspcon->active)
Shashank Sharma910530c2016-10-14 19:56:52 +05305030 lspcon_resume(lspcon);
5031
Manasi Navared7e8ef02017-02-07 16:54:11 -08005032 intel_dp->reset_link_params = true;
5033
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005034 pps_lock(intel_dp);
5035
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005036 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5037 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5038
Jani Nikula1853a9d2017-08-18 12:30:20 +03005039 if (intel_dp_is_edp(intel_dp)) {
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005040 /* Reinit the power sequencer, in case BIOS did something with it. */
5041 intel_dp_pps_init(encoder->dev, intel_dp);
5042 intel_edp_panel_vdd_sanitize(intel_dp);
5043 }
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005044
5045 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03005046}
5047
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005048static const struct drm_connector_funcs intel_dp_connector_funcs = {
Chris Wilsonbeb60602014-09-02 20:04:00 +01005049 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005050 .fill_modes = drm_helper_probe_single_connector_modes,
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02005051 .atomic_get_property = intel_digital_connector_atomic_get_property,
5052 .atomic_set_property = intel_digital_connector_atomic_set_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01005053 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01005054 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03005055 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08005056 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02005057 .atomic_duplicate_state = intel_digital_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005058};
5059
5060static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02005061 .detect_ctx = intel_dp_detect,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005062 .get_modes = intel_dp_get_modes,
5063 .mode_valid = intel_dp_mode_valid,
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02005064 .atomic_check = intel_digital_connector_atomic_check,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005065};
5066
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005067static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03005068 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02005069 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005070};
5071
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005072enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10005073intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
5074{
5075 struct intel_dp *intel_dp = &intel_dig_port->dp;
Dave Airlie0e32b392014-05-02 14:02:48 +10005076 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005077 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005078 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03005079
Takashi Iwai25400582015-11-19 12:09:56 +01005080 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
5081 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Ville Syrjäläcca05022016-06-22 21:57:06 +03005082 intel_dig_port->base.type = INTEL_OUTPUT_DP;
Dave Airlie13cf5502014-06-18 11:29:35 +10005083
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005084 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
5085 /*
5086 * vdd off can generate a long pulse on eDP which
5087 * would require vdd on to handle it, and thus we
5088 * would end up in an endless cycle of
5089 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
5090 */
5091 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
5092 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d522015-02-10 14:11:46 +02005093 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005094 }
5095
Ville Syrjälä26fbb772014-08-11 18:37:37 +03005096 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
5097 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10005098 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10005099
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005100 if (long_hpd) {
Manasi Navared7e8ef02017-02-07 16:54:11 -08005101 intel_dp->reset_link_params = true;
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005102 intel_dp->detect_done = false;
5103 return IRQ_NONE;
5104 }
5105
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005106 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005107
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005108 if (intel_dp->is_mst) {
5109 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
5110 /*
5111 * If we were in MST mode, and device is not
5112 * there, get out of MST mode
5113 */
5114 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
5115 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
5116 intel_dp->is_mst = false;
5117 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
5118 intel_dp->is_mst);
5119 intel_dp->detect_done = false;
5120 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10005121 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005122 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005123
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005124 if (!intel_dp->is_mst) {
5125 if (!intel_dp_short_pulse(intel_dp)) {
5126 intel_dp->detect_done = false;
5127 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05305128 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005129 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005130
5131 ret = IRQ_HANDLED;
5132
Imre Deak1c767b32014-08-18 14:42:42 +03005133put_power:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005134 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005135
5136 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10005137}
5138
Rodrigo Vivi477ec322015-08-06 15:51:39 +08005139/* check the VBT to see whether the eDP is on another port */
Jani Nikula7b91bf72017-08-18 12:30:19 +03005140bool intel_dp_is_port_edp(struct drm_i915_private *dev_priv, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08005141{
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005142 /*
5143 * eDP not supported on g4x. so bail out early just
5144 * for a bit extra safety in case the VBT is bonkers.
5145 */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005146 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005147 return false;
5148
Imre Deaka98d9c12016-12-21 12:17:24 +02005149 if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005150 return true;
5151
Jani Nikula951d9ef2016-03-16 12:43:31 +02005152 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08005153}
5154
Maarten Lankhorst200819a2017-04-10 12:51:10 +02005155static void
Chris Wilsonf6849602010-09-19 09:29:33 +01005156intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
5157{
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005158 struct drm_i915_private *dev_priv = to_i915(connector->dev);
5159
Chris Wilson3f43c482011-05-12 22:17:24 +01005160 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00005161 intel_attach_broadcast_rgb_property(connector);
Yuly Novikov53b41832012-10-26 12:04:00 +03005162
Jani Nikula1853a9d2017-08-18 12:30:20 +03005163 if (intel_dp_is_edp(intel_dp)) {
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005164 u32 allowed_scalers;
5165
5166 allowed_scalers = BIT(DRM_MODE_SCALE_ASPECT) | BIT(DRM_MODE_SCALE_FULLSCREEN);
5167 if (!HAS_GMCH_DISPLAY(dev_priv))
5168 allowed_scalers |= BIT(DRM_MODE_SCALE_CENTER);
5169
5170 drm_connector_attach_scaling_mode_property(connector, allowed_scalers);
5171
Maarten Lankhorsteead06d2017-05-01 15:37:55 +02005172 connector->state->scaling_mode = DRM_MODE_SCALE_ASPECT;
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005173
Yuly Novikov53b41832012-10-26 12:04:00 +03005174 }
Chris Wilsonf6849602010-09-19 09:29:33 +01005175}
5176
Imre Deakdada1a92014-01-29 13:25:41 +02005177static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
5178{
Abhay Kumard28d4732016-01-22 17:39:04 -08005179 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02005180 intel_dp->last_power_on = jiffies;
5181 intel_dp->last_backlight_off = jiffies;
5182}
5183
Daniel Vetter67a54562012-10-20 20:57:45 +02005184static void
Imre Deak54648612016-06-16 16:37:22 +03005185intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
5186 struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02005187{
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305188 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03005189 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07005190
Imre Deak8e8232d2016-06-16 16:37:21 +03005191 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02005192
5193 /* Workaround: Need to write PP_CONTROL with the unlock key as
5194 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305195 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02005196
Imre Deak8e8232d2016-06-16 16:37:21 +03005197 pp_on = I915_READ(regs.pp_on);
5198 pp_off = I915_READ(regs.pp_off);
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005199 if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005200 I915_WRITE(regs.pp_ctrl, pp_ctl);
5201 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305202 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005203
5204 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03005205 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
5206 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005207
Imre Deak54648612016-06-16 16:37:22 +03005208 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
5209 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005210
Imre Deak54648612016-06-16 16:37:22 +03005211 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
5212 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005213
Imre Deak54648612016-06-16 16:37:22 +03005214 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
5215 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005216
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005217 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) {
Manasi Navare12c8ca92017-06-26 12:21:45 -07005218 seq->t11_t12 = ((pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
5219 BXT_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305220 } else {
Imre Deak54648612016-06-16 16:37:22 +03005221 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02005222 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305223 }
Imre Deak54648612016-06-16 16:37:22 +03005224}
5225
5226static void
Imre Deakde9c1b62016-06-16 20:01:46 +03005227intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
5228{
5229 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5230 state_name,
5231 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
5232}
5233
5234static void
5235intel_pps_verify_state(struct drm_i915_private *dev_priv,
5236 struct intel_dp *intel_dp)
5237{
5238 struct edp_power_seq hw;
5239 struct edp_power_seq *sw = &intel_dp->pps_delays;
5240
5241 intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
5242
5243 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
5244 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
5245 DRM_ERROR("PPS state mismatch\n");
5246 intel_pps_dump_state("sw", sw);
5247 intel_pps_dump_state("hw", &hw);
5248 }
5249}
5250
5251static void
Imre Deak54648612016-06-16 16:37:22 +03005252intel_dp_init_panel_power_sequencer(struct drm_device *dev,
5253 struct intel_dp *intel_dp)
5254{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005255 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak54648612016-06-16 16:37:22 +03005256 struct edp_power_seq cur, vbt, spec,
5257 *final = &intel_dp->pps_delays;
5258
5259 lockdep_assert_held(&dev_priv->pps_mutex);
5260
5261 /* already initialized? */
5262 if (final->t11_t12 != 0)
5263 return;
5264
5265 intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005266
Imre Deakde9c1b62016-06-16 20:01:46 +03005267 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005268
Jani Nikula6aa23e62016-03-24 17:50:20 +02005269 vbt = dev_priv->vbt.edp.pps;
Manasi Navarec99a2592017-06-30 09:33:48 -07005270 /* On Toshiba Satellite P50-C-18C system the VBT T12 delay
5271 * of 500ms appears to be too short. Ocassionally the panel
5272 * just fails to power back on. Increasing the delay to 800ms
5273 * seems sufficient to avoid this problem.
5274 */
5275 if (dev_priv->quirks & QUIRK_INCREASE_T12_DELAY) {
Manasi Navaree8f345e2017-08-15 11:59:51 -07005276 vbt.t11_t12 = max_t(u16, vbt.t11_t12, 900 * 10);
Manasi Navarec99a2592017-06-30 09:33:48 -07005277 DRM_DEBUG_KMS("Increasing T12 panel delay as per the quirk to %d\n",
5278 vbt.t11_t12);
5279 }
Manasi Navare770a17a2017-06-26 12:21:44 -07005280 /* T11_T12 delay is special and actually in units of 100ms, but zero
5281 * based in the hw (so we need to add 100 ms). But the sw vbt
5282 * table multiplies it with 1000 to make it in units of 100usec,
5283 * too. */
5284 vbt.t11_t12 += 100 * 10;
Daniel Vetter67a54562012-10-20 20:57:45 +02005285
5286 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5287 * our hw here, which are all in 100usec. */
5288 spec.t1_t3 = 210 * 10;
5289 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5290 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5291 spec.t10 = 500 * 10;
5292 /* This one is special and actually in units of 100ms, but zero
5293 * based in the hw (so we need to add 100 ms). But the sw vbt
5294 * table multiplies it with 1000 to make it in units of 100usec,
5295 * too. */
5296 spec.t11_t12 = (510 + 100) * 10;
5297
Imre Deakde9c1b62016-06-16 20:01:46 +03005298 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005299
5300 /* Use the max of the register settings and vbt. If both are
5301 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005302#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005303 spec.field : \
5304 max(cur.field, vbt.field))
5305 assign_final(t1_t3);
5306 assign_final(t8);
5307 assign_final(t9);
5308 assign_final(t10);
5309 assign_final(t11_t12);
5310#undef assign_final
5311
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005312#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005313 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5314 intel_dp->backlight_on_delay = get_delay(t8);
5315 intel_dp->backlight_off_delay = get_delay(t9);
5316 intel_dp->panel_power_down_delay = get_delay(t10);
5317 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5318#undef get_delay
5319
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005320 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5321 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5322 intel_dp->panel_power_cycle_delay);
5323
5324 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5325 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005326
5327 /*
5328 * We override the HW backlight delays to 1 because we do manual waits
5329 * on them. For T8, even BSpec recommends doing it. For T9, if we
5330 * don't do this, we'll end up waiting for the backlight off delay
5331 * twice: once when we do the manual sleep, and once when we disable
5332 * the panel and wait for the PP_STATUS bit to become zero.
5333 */
5334 final->t8 = 1;
5335 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005336}
5337
5338static void
5339intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005340 struct intel_dp *intel_dp,
5341 bool force_disable_vdd)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005342{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005343 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07005344 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005345 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005346 struct pps_registers regs;
Ville Syrjäläad933b52014-08-18 22:15:56 +03005347 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005348 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005349
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005350 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005351
Imre Deak8e8232d2016-06-16 16:37:21 +03005352 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005353
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005354 /*
5355 * On some VLV machines the BIOS can leave the VDD
5356 * enabled even on power seqeuencers which aren't
5357 * hooked up to any port. This would mess up the
5358 * power domain tracking the first time we pick
5359 * one of these power sequencers for use since
5360 * edp_panel_vdd_on() would notice that the VDD was
5361 * already on and therefore wouldn't grab the power
5362 * domain reference. Disable VDD first to avoid this.
5363 * This also avoids spuriously turning the VDD on as
5364 * soon as the new power seqeuencer gets initialized.
5365 */
5366 if (force_disable_vdd) {
5367 u32 pp = ironlake_get_pp_control(intel_dp);
5368
5369 WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
5370
5371 if (pp & EDP_FORCE_VDD)
5372 DRM_DEBUG_KMS("VDD already on, disabling first\n");
5373
5374 pp &= ~EDP_FORCE_VDD;
5375
5376 I915_WRITE(regs.pp_ctrl, pp);
5377 }
5378
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005379 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005380 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5381 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005382 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005383 /* Compute the divisor for the pp clock, simply match the Bspec
5384 * formula. */
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005385 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005386 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305387 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
Manasi Navare12c8ca92017-06-26 12:21:45 -07005388 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305389 << BXT_POWER_CYCLE_DELAY_SHIFT);
5390 } else {
5391 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5392 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5393 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5394 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005395
5396 /* Haswell doesn't have any port selection bits for the panel
5397 * power sequencer any more. */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005398 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005399 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005400 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005401 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005402 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005403 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005404 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005405 }
5406
Jesse Barnes453c5422013-03-28 09:55:41 -07005407 pp_on |= port_sel;
5408
Imre Deak8e8232d2016-06-16 16:37:21 +03005409 I915_WRITE(regs.pp_on, pp_on);
5410 I915_WRITE(regs.pp_off, pp_off);
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005411 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005412 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305413 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005414 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005415
Daniel Vetter67a54562012-10-20 20:57:45 +02005416 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 +03005417 I915_READ(regs.pp_on),
5418 I915_READ(regs.pp_off),
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005419 (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005420 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5421 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005422}
5423
Imre Deak335f7522016-08-10 14:07:32 +03005424static void intel_dp_pps_init(struct drm_device *dev,
5425 struct intel_dp *intel_dp)
5426{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005427 struct drm_i915_private *dev_priv = to_i915(dev);
5428
5429 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Imre Deak335f7522016-08-10 14:07:32 +03005430 vlv_initial_power_sequencer_setup(intel_dp);
5431 } else {
5432 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005433 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak335f7522016-08-10 14:07:32 +03005434 }
5435}
5436
Vandana Kannanb33a2812015-02-13 15:33:03 +05305437/**
5438 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005439 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005440 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305441 * @refresh_rate: RR to be programmed
5442 *
5443 * This function gets called when refresh rate (RR) has to be changed from
5444 * one frequency to another. Switches can be between high and low RR
5445 * supported by the panel or to any other RR based on media playback (in
5446 * this case, RR value needs to be passed from user space).
5447 *
5448 * The caller of this function needs to take a lock on dev_priv->drrs.
5449 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005450static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03005451 const struct intel_crtc_state *crtc_state,
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005452 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305453{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305454 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305455 struct intel_digital_port *dig_port = NULL;
5456 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005457 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305458 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305459
5460 if (refresh_rate <= 0) {
5461 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5462 return;
5463 }
5464
Vandana Kannan96178ee2015-01-10 02:25:56 +05305465 if (intel_dp == NULL) {
5466 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305467 return;
5468 }
5469
Vandana Kannan96178ee2015-01-10 02:25:56 +05305470 dig_port = dp_to_dig_port(intel_dp);
5471 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02005472 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305473
5474 if (!intel_crtc) {
5475 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5476 return;
5477 }
5478
Vandana Kannan96178ee2015-01-10 02:25:56 +05305479 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305480 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5481 return;
5482 }
5483
Vandana Kannan96178ee2015-01-10 02:25:56 +05305484 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5485 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305486 index = DRRS_LOW_RR;
5487
Vandana Kannan96178ee2015-01-10 02:25:56 +05305488 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305489 DRM_DEBUG_KMS(
5490 "DRRS requested for previously set RR...ignoring\n");
5491 return;
5492 }
5493
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005494 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305495 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5496 return;
5497 }
5498
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005499 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305500 switch (index) {
5501 case DRRS_HIGH_RR:
5502 intel_dp_set_m_n(intel_crtc, M1_N1);
5503 break;
5504 case DRRS_LOW_RR:
5505 intel_dp_set_m_n(intel_crtc, M2_N2);
5506 break;
5507 case DRRS_MAX_RR:
5508 default:
5509 DRM_ERROR("Unsupported refreshrate type\n");
5510 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005511 } else if (INTEL_GEN(dev_priv) > 6) {
5512 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005513 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305514
Ville Syrjälä649636e2015-09-22 19:50:01 +03005515 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305516 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005517 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305518 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5519 else
5520 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305521 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005522 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305523 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5524 else
5525 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305526 }
5527 I915_WRITE(reg, val);
5528 }
5529
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305530 dev_priv->drrs.refresh_rate_type = index;
5531
5532 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5533}
5534
Vandana Kannanb33a2812015-02-13 15:33:03 +05305535/**
5536 * intel_edp_drrs_enable - init drrs struct if supported
5537 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005538 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305539 *
5540 * Initializes frontbuffer_bits and drrs.dp
5541 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005542void intel_edp_drrs_enable(struct intel_dp *intel_dp,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03005543 const struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305544{
5545 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005546 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305547
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005548 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305549 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5550 return;
5551 }
5552
Radhakrishna Sripadada83ef82017-09-14 11:16:41 -07005553 if (dev_priv->psr.enabled) {
5554 DRM_DEBUG_KMS("PSR enabled. Not enabling DRRS.\n");
5555 return;
5556 }
5557
Vandana Kannanc3955782015-01-22 15:17:40 +05305558 mutex_lock(&dev_priv->drrs.mutex);
5559 if (WARN_ON(dev_priv->drrs.dp)) {
5560 DRM_ERROR("DRRS already enabled\n");
5561 goto unlock;
5562 }
5563
5564 dev_priv->drrs.busy_frontbuffer_bits = 0;
5565
5566 dev_priv->drrs.dp = intel_dp;
5567
5568unlock:
5569 mutex_unlock(&dev_priv->drrs.mutex);
5570}
5571
Vandana Kannanb33a2812015-02-13 15:33:03 +05305572/**
5573 * intel_edp_drrs_disable - Disable DRRS
5574 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005575 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305576 *
5577 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005578void intel_edp_drrs_disable(struct intel_dp *intel_dp,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03005579 const struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305580{
5581 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005582 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305583
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005584 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305585 return;
5586
5587 mutex_lock(&dev_priv->drrs.mutex);
5588 if (!dev_priv->drrs.dp) {
5589 mutex_unlock(&dev_priv->drrs.mutex);
5590 return;
5591 }
5592
5593 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005594 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5595 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305596
5597 dev_priv->drrs.dp = NULL;
5598 mutex_unlock(&dev_priv->drrs.mutex);
5599
5600 cancel_delayed_work_sync(&dev_priv->drrs.work);
5601}
5602
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305603static void intel_edp_drrs_downclock_work(struct work_struct *work)
5604{
5605 struct drm_i915_private *dev_priv =
5606 container_of(work, typeof(*dev_priv), drrs.work.work);
5607 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305608
Vandana Kannan96178ee2015-01-10 02:25:56 +05305609 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305610
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305611 intel_dp = dev_priv->drrs.dp;
5612
5613 if (!intel_dp)
5614 goto unlock;
5615
5616 /*
5617 * The delayed work can race with an invalidate hence we need to
5618 * recheck.
5619 */
5620
5621 if (dev_priv->drrs.busy_frontbuffer_bits)
5622 goto unlock;
5623
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005624 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5625 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5626
5627 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5628 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5629 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305630
5631unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305632 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305633}
5634
Vandana Kannanb33a2812015-02-13 15:33:03 +05305635/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305636 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005637 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305638 * @frontbuffer_bits: frontbuffer plane tracking bits
5639 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305640 * This function gets called everytime rendering on the given planes start.
5641 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305642 *
5643 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5644 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005645void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5646 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305647{
Vandana Kannana93fad02015-01-10 02:25:59 +05305648 struct drm_crtc *crtc;
5649 enum pipe pipe;
5650
Daniel Vetter9da7d692015-04-09 16:44:15 +02005651 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305652 return;
5653
Daniel Vetter88f933a2015-04-09 16:44:16 +02005654 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305655
Vandana Kannana93fad02015-01-10 02:25:59 +05305656 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005657 if (!dev_priv->drrs.dp) {
5658 mutex_unlock(&dev_priv->drrs.mutex);
5659 return;
5660 }
5661
Vandana Kannana93fad02015-01-10 02:25:59 +05305662 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5663 pipe = to_intel_crtc(crtc)->pipe;
5664
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005665 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5666 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5667
Ramalingam C0ddfd202015-06-15 20:50:05 +05305668 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005669 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005670 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5671 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305672
Vandana Kannana93fad02015-01-10 02:25:59 +05305673 mutex_unlock(&dev_priv->drrs.mutex);
5674}
5675
Vandana Kannanb33a2812015-02-13 15:33:03 +05305676/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305677 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005678 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305679 * @frontbuffer_bits: frontbuffer plane tracking bits
5680 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305681 * This function gets called every time rendering on the given planes has
5682 * completed or flip on a crtc is completed. So DRRS should be upclocked
5683 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5684 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305685 *
5686 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5687 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005688void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5689 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305690{
Vandana Kannana93fad02015-01-10 02:25:59 +05305691 struct drm_crtc *crtc;
5692 enum pipe pipe;
5693
Daniel Vetter9da7d692015-04-09 16:44:15 +02005694 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305695 return;
5696
Daniel Vetter88f933a2015-04-09 16:44:16 +02005697 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305698
Vandana Kannana93fad02015-01-10 02:25:59 +05305699 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005700 if (!dev_priv->drrs.dp) {
5701 mutex_unlock(&dev_priv->drrs.mutex);
5702 return;
5703 }
5704
Vandana Kannana93fad02015-01-10 02:25:59 +05305705 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5706 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005707
5708 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305709 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5710
Ramalingam C0ddfd202015-06-15 20:50:05 +05305711 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005712 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005713 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5714 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305715
5716 /*
5717 * flush also means no more activity hence schedule downclock, if all
5718 * other fbs are quiescent too
5719 */
5720 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305721 schedule_delayed_work(&dev_priv->drrs.work,
5722 msecs_to_jiffies(1000));
5723 mutex_unlock(&dev_priv->drrs.mutex);
5724}
5725
Vandana Kannanb33a2812015-02-13 15:33:03 +05305726/**
5727 * DOC: Display Refresh Rate Switching (DRRS)
5728 *
5729 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5730 * which enables swtching between low and high refresh rates,
5731 * dynamically, based on the usage scenario. This feature is applicable
5732 * for internal panels.
5733 *
5734 * Indication that the panel supports DRRS is given by the panel EDID, which
5735 * would list multiple refresh rates for one resolution.
5736 *
5737 * DRRS is of 2 types - static and seamless.
5738 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5739 * (may appear as a blink on screen) and is used in dock-undock scenario.
5740 * Seamless DRRS involves changing RR without any visual effect to the user
5741 * and can be used during normal system usage. This is done by programming
5742 * certain registers.
5743 *
5744 * Support for static/seamless DRRS may be indicated in the VBT based on
5745 * inputs from the panel spec.
5746 *
5747 * DRRS saves power by switching to low RR based on usage scenarios.
5748 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005749 * The implementation is based on frontbuffer tracking implementation. When
5750 * there is a disturbance on the screen triggered by user activity or a periodic
5751 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5752 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5753 * made.
5754 *
5755 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5756 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305757 *
5758 * DRRS can be further extended to support other internal panels and also
5759 * the scenario of video playback wherein RR is set based on the rate
5760 * requested by userspace.
5761 */
5762
5763/**
5764 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5765 * @intel_connector: eDP connector
5766 * @fixed_mode: preferred mode of panel
5767 *
5768 * This function is called only once at driver load to initialize basic
5769 * DRRS stuff.
5770 *
5771 * Returns:
5772 * Downclock mode if panel supports it, else return NULL.
5773 * DRRS support is determined by the presence of downclock mode (apart
5774 * from VBT setting).
5775 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305776static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305777intel_dp_drrs_init(struct intel_connector *intel_connector,
5778 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305779{
5780 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305781 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005782 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305783 struct drm_display_mode *downclock_mode = NULL;
5784
Daniel Vetter9da7d692015-04-09 16:44:15 +02005785 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5786 mutex_init(&dev_priv->drrs.mutex);
5787
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005788 if (INTEL_GEN(dev_priv) <= 6) {
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305789 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5790 return NULL;
5791 }
5792
5793 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005794 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305795 return NULL;
5796 }
5797
5798 downclock_mode = intel_find_panel_downclock
Mika Kaholaa318b4c2016-12-13 10:02:48 +02005799 (dev_priv, fixed_mode, connector);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305800
5801 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305802 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305803 return NULL;
5804 }
5805
Vandana Kannan96178ee2015-01-10 02:25:56 +05305806 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305807
Vandana Kannan96178ee2015-01-10 02:25:56 +05305808 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005809 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305810 return downclock_mode;
5811}
5812
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005813static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005814 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005815{
5816 struct drm_connector *connector = &intel_connector->base;
5817 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005818 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5819 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005820 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005821 struct drm_display_mode *fixed_mode = NULL;
Jim Bridedc911f52017-08-09 12:48:53 -07005822 struct drm_display_mode *alt_fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305823 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005824 bool has_dpcd;
5825 struct drm_display_mode *scan;
5826 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005827 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005828
Jani Nikula1853a9d2017-08-18 12:30:20 +03005829 if (!intel_dp_is_edp(intel_dp))
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005830 return true;
5831
Imre Deak97a824e12016-06-21 11:51:47 +03005832 /*
5833 * On IBX/CPT we may get here with LVDS already registered. Since the
5834 * driver uses the only internal power sequencer available for both
5835 * eDP and LVDS bail out early in this case to prevent interfering
5836 * with an already powered-on LVDS power sequencer.
5837 */
5838 if (intel_get_lvds_encoder(dev)) {
5839 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5840 DRM_INFO("LVDS was detected, not registering eDP\n");
5841
5842 return false;
5843 }
5844
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005845 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005846
5847 intel_dp_init_panel_power_timestamps(intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +03005848 intel_dp_pps_init(dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005849 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005850
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005851 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005852
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005853 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005854 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005855
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005856 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005857 /* if this fails, presume the device is a ghost */
5858 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005859 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005860 }
5861
Daniel Vetter060c8772014-03-21 23:22:35 +01005862 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005863 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005864 if (edid) {
5865 if (drm_add_edid_modes(connector, edid)) {
5866 drm_mode_connector_update_edid_property(connector,
5867 edid);
5868 drm_edid_to_eld(connector, edid);
5869 } else {
5870 kfree(edid);
5871 edid = ERR_PTR(-EINVAL);
5872 }
5873 } else {
5874 edid = ERR_PTR(-ENOENT);
5875 }
5876 intel_connector->edid = edid;
5877
Jim Bridedc911f52017-08-09 12:48:53 -07005878 /* prefer fixed mode from EDID if available, save an alt mode also */
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005879 list_for_each_entry(scan, &connector->probed_modes, head) {
5880 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5881 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305882 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305883 intel_connector, fixed_mode);
Jim Bridedc911f52017-08-09 12:48:53 -07005884 } else if (!alt_fixed_mode) {
5885 alt_fixed_mode = drm_mode_duplicate(dev, scan);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005886 }
5887 }
5888
5889 /* fallback to VBT if available for eDP */
5890 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5891 fixed_mode = drm_mode_duplicate(dev,
5892 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005893 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005894 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005895 connector->display_info.width_mm = fixed_mode->width_mm;
5896 connector->display_info.height_mm = fixed_mode->height_mm;
5897 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005898 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005899 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005900
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005901 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005902 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5903 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005904
5905 /*
5906 * Figure out the current pipe for the initial backlight setup.
5907 * If the current pipe isn't valid, try the PPS pipe, and if that
5908 * fails just assume pipe A.
5909 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005910 pipe = vlv_active_pipe(intel_dp);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005911
5912 if (pipe != PIPE_A && pipe != PIPE_B)
5913 pipe = intel_dp->pps_pipe;
5914
5915 if (pipe != PIPE_A && pipe != PIPE_B)
5916 pipe = PIPE_A;
5917
5918 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5919 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005920 }
5921
Jim Bridedc911f52017-08-09 12:48:53 -07005922 intel_panel_init(&intel_connector->panel, fixed_mode, alt_fixed_mode,
5923 downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005924 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005925 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005926
5927 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005928
5929out_vdd_off:
5930 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5931 /*
5932 * vdd might still be enabled do to the delayed vdd off.
5933 * Make sure vdd is actually turned off here.
5934 */
5935 pps_lock(intel_dp);
5936 edp_panel_vdd_off_sync(intel_dp);
5937 pps_unlock(intel_dp);
5938
5939 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005940}
5941
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005942/* Set up the hotplug pin and aux power domain. */
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005943static void
5944intel_dp_init_connector_port_info(struct intel_digital_port *intel_dig_port)
5945{
5946 struct intel_encoder *encoder = &intel_dig_port->base;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005947 struct intel_dp *intel_dp = &intel_dig_port->dp;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005948
Rodrigo Vivif761bef22017-08-11 11:26:50 -07005949 encoder->hpd_pin = intel_hpd_pin(intel_dig_port->port);
5950
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005951 switch (intel_dig_port->port) {
5952 case PORT_A:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005953 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_A;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005954 break;
5955 case PORT_B:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005956 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_B;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005957 break;
5958 case PORT_C:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005959 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_C;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005960 break;
5961 case PORT_D:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005962 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005963 break;
5964 case PORT_E:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005965 /* FIXME: Check VBT for actual wiring of PORT E */
5966 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005967 break;
5968 default:
5969 MISSING_CASE(intel_dig_port->port);
5970 }
5971}
5972
Manasi Navare93013972017-04-06 16:44:19 +03005973static void intel_dp_modeset_retry_work_fn(struct work_struct *work)
5974{
5975 struct intel_connector *intel_connector;
5976 struct drm_connector *connector;
5977
5978 intel_connector = container_of(work, typeof(*intel_connector),
5979 modeset_retry_work);
5980 connector = &intel_connector->base;
5981 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
5982 connector->name);
5983
5984 /* Grab the locks before changing connector property*/
5985 mutex_lock(&connector->dev->mode_config.mutex);
5986 /* Set connector link status to BAD and send a Uevent to notify
5987 * userspace to do a modeset.
5988 */
5989 drm_mode_connector_set_link_status_property(connector,
5990 DRM_MODE_LINK_STATUS_BAD);
5991 mutex_unlock(&connector->dev->mode_config.mutex);
5992 /* Send Hotplug uevent so userspace can reprobe */
5993 drm_kms_helper_hotplug_event(connector->dev);
5994}
5995
Paulo Zanoni16c25532013-06-12 17:27:25 -03005996bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005997intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5998 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005999{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006000 struct drm_connector *connector = &intel_connector->base;
6001 struct intel_dp *intel_dp = &intel_dig_port->dp;
6002 struct intel_encoder *intel_encoder = &intel_dig_port->base;
6003 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01006004 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02006005 enum port port = intel_dig_port->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01006006 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006007
Manasi Navare93013972017-04-06 16:44:19 +03006008 /* Initialize the work for modeset in case of link train failure */
6009 INIT_WORK(&intel_connector->modeset_retry_work,
6010 intel_dp_modeset_retry_work_fn);
6011
Ville Syrjäläccb1a832015-12-08 19:59:38 +02006012 if (WARN(intel_dig_port->max_lanes < 1,
6013 "Not enough lanes (%d) for DP on port %c\n",
6014 intel_dig_port->max_lanes, port_name(port)))
6015 return false;
6016
Jani Nikula55cfc582017-03-28 17:59:04 +03006017 intel_dp_set_source_rates(intel_dp);
6018
Manasi Navared7e8ef02017-02-07 16:54:11 -08006019 intel_dp->reset_link_params = true;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03006020 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02006021 intel_dp->active_pipe = INVALID_PIPE;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03006022
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006023 /* intel_dp vfuncs */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006024 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub6b5e382014-01-20 16:00:59 +00006025 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01006026 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006027 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01006028 else if (HAS_PCH_SPLIT(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006029 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
6030 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02006031 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006032
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006033 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00006034 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
6035 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02006036 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00006037
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006038 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03006039 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
6040
Daniel Vetter07679352012-09-06 22:15:42 +02006041 /* Preserve the current hw state. */
6042 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03006043 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00006044
Jani Nikula7b91bf72017-08-18 12:30:19 +03006045 if (intel_dp_is_port_edp(dev_priv, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05306046 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02006047 else
6048 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04006049
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02006050 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
6051 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
6052
Imre Deakf7d24902013-05-08 13:14:05 +03006053 /*
6054 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
6055 * for DP the encoder type can be set by the caller to
6056 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
6057 */
6058 if (type == DRM_MODE_CONNECTOR_eDP)
6059 intel_encoder->type = INTEL_OUTPUT_EDP;
6060
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006061 /* eDP only on port B and/or C on vlv/chv */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006062 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Jani Nikula1853a9d2017-08-18 12:30:20 +03006063 intel_dp_is_edp(intel_dp) &&
6064 port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006065 return false;
6066
Imre Deake7281ea2013-05-08 13:14:08 +03006067 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
6068 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
6069 port_name(port));
6070
Adam Jacksonb3295302010-07-16 14:46:28 -04006071 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006072 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
6073
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006074 connector->interlace_allowed = true;
6075 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08006076
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02006077 intel_dp_init_connector_port_info(intel_dig_port);
6078
Mika Kaholab6339582016-09-09 14:10:52 +03006079 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01006080
Daniel Vetter66a92782012-07-12 20:08:18 +02006081 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01006082 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08006083
Chris Wilsondf0e9242010-09-09 16:20:55 +01006084 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006085
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006086 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02006087 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
6088 else
6089 intel_connector->get_hw_state = intel_connector_get_hw_state;
6090
Dave Airlie0e32b392014-05-02 14:02:48 +10006091 /* init MST on ports that can support it */
Jani Nikula1853a9d2017-08-18 12:30:20 +03006092 if (HAS_DP_MST(dev_priv) && !intel_dp_is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03006093 (port == PORT_B || port == PORT_C || port == PORT_D))
6094 intel_dp_mst_encoder_init(intel_dig_port,
6095 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10006096
Ville Syrjälä36b5f422014-10-16 21:27:30 +03006097 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006098 intel_dp_aux_fini(intel_dp);
6099 intel_dp_mst_encoder_cleanup(intel_dig_port);
6100 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03006101 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08006102
Chris Wilsonf6849602010-09-19 09:29:33 +01006103 intel_dp_add_properties(intel_dp, connector);
6104
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006105 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
6106 * 0xd. Failure to do so will result in spurious interrupts being
6107 * generated on the port when a cable is not attached.
6108 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01006109 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006110 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
6111 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
6112 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03006113
6114 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006115
6116fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006117 drm_connector_cleanup(connector);
6118
6119 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006120}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006121
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006122bool intel_dp_init(struct drm_i915_private *dev_priv,
Chris Wilson457c52d2016-06-01 08:27:50 +01006123 i915_reg_t output_reg,
6124 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006125{
6126 struct intel_digital_port *intel_dig_port;
6127 struct intel_encoder *intel_encoder;
6128 struct drm_encoder *encoder;
6129 struct intel_connector *intel_connector;
6130
Daniel Vetterb14c5672013-09-19 12:18:32 +02006131 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006132 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01006133 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006134
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03006135 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306136 if (!intel_connector)
6137 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006138
6139 intel_encoder = &intel_dig_port->base;
6140 encoder = &intel_encoder->base;
6141
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006142 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
6143 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
6144 "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306145 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006146
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01006147 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006148 intel_encoder->disable = intel_disable_dp;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006149 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07006150 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03006151 intel_encoder->suspend = intel_dp_encoder_suspend;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006152 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03006153 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03006154 intel_encoder->pre_enable = chv_pre_enable_dp;
6155 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03006156 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03006157 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01006158 } else if (IS_VALLEYVIEW(dev_priv)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006159 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006160 intel_encoder->pre_enable = vlv_pre_enable_dp;
6161 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03006162 intel_encoder->post_disable = vlv_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006163 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006164 intel_encoder->pre_enable = g4x_pre_enable_dp;
6165 intel_encoder->enable = g4x_enable_dp;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006166 if (INTEL_GEN(dev_priv) >= 5)
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03006167 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006168 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006169
Paulo Zanoni174edf12012-10-26 19:05:50 -02006170 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006171 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02006172 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006173
Ville Syrjäläcca05022016-06-22 21:57:06 +03006174 intel_encoder->type = INTEL_OUTPUT_DP;
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02006175 intel_encoder->power_domain = intel_port_to_power_domain(port);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006176 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03006177 if (port == PORT_D)
6178 intel_encoder->crtc_mask = 1 << 2;
6179 else
6180 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
6181 } else {
6182 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
6183 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02006184 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07006185 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006186
Dave Airlie13cf5502014-06-18 11:29:35 +10006187 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03006188 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10006189
Ville Syrjälä385e4de2017-08-18 16:49:55 +03006190 if (port != PORT_A)
6191 intel_infoframe_init(intel_dig_port);
6192
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306193 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
6194 goto err_init_connector;
6195
Chris Wilson457c52d2016-06-01 08:27:50 +01006196 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306197
6198err_init_connector:
6199 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306200err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306201 kfree(intel_connector);
6202err_connector_alloc:
6203 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01006204 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006205}
Dave Airlie0e32b392014-05-02 14:02:48 +10006206
6207void intel_dp_mst_suspend(struct drm_device *dev)
6208{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006209 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006210 int i;
6211
6212 /* disable MST */
6213 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006214 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006215
6216 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006217 continue;
6218
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006219 if (intel_dig_port->dp.is_mst)
6220 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10006221 }
6222}
6223
6224void intel_dp_mst_resume(struct drm_device *dev)
6225{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006226 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006227 int i;
6228
6229 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006230 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006231 int ret;
6232
6233 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006234 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10006235
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006236 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
6237 if (ret)
6238 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10006239 }
6240}