blob: 2eb6e0ff143a9a17463de1a4984c370b424ee264 [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 };
100static const int default_rates[] = { 162000, 270000, 540000 };
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300101
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700102/**
103 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
104 * @intel_dp: DP struct
105 *
106 * If a CPU or PCH DP output is attached to an eDP panel, this function
107 * will return true, and false otherwise.
108 */
109static bool is_edp(struct intel_dp *intel_dp)
110{
Paulo Zanonida63a9f2012-10-26 19:05:46 -0200111 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
112
113 return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700114}
115
Imre Deak68b4d822013-05-08 13:14:06 +0300116static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp)
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700117{
Imre Deak68b4d822013-05-08 13:14:06 +0300118 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
119
120 return intel_dig_port->base.base.dev;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700121}
122
Chris Wilsondf0e9242010-09-09 16:20:55 +0100123static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
124{
Paulo Zanonifa90ece2012-10-26 19:05:44 -0200125 return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
Chris Wilsondf0e9242010-09-09 16:20:55 +0100126}
127
Chris Wilsonea5b2132010-08-04 13:50:23 +0100128static void intel_dp_link_down(struct intel_dp *intel_dp);
Ville Syrjälä1e0560e2014-08-19 13:24:25 +0300129static bool edp_panel_vdd_on(struct intel_dp *intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +0100130static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
Ville Syrjälä093e3f12014-10-16 21:27:33 +0300131static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300132static void vlv_steal_power_sequencer(struct drm_device *dev,
133 enum pipe pipe);
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +0530134static void intel_dp_unset_edid(struct intel_dp *intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700135
Jani Nikula68f357c2017-03-28 17:59:05 +0300136static int intel_dp_num_rates(u8 link_bw_code)
137{
138 switch (link_bw_code) {
139 default:
140 WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
141 link_bw_code);
142 case DP_LINK_BW_1_62:
143 return 1;
144 case DP_LINK_BW_2_7:
145 return 2;
146 case DP_LINK_BW_5_4:
147 return 3;
148 }
149}
150
151/* update sink rates from dpcd */
152static void intel_dp_set_sink_rates(struct intel_dp *intel_dp)
153{
154 int i, num_rates;
155
156 num_rates = intel_dp_num_rates(intel_dp->dpcd[DP_MAX_LINK_RATE]);
157
158 for (i = 0; i < num_rates; i++)
159 intel_dp->sink_rates[i] = default_rates[i];
160
161 intel_dp->num_sink_rates = num_rates;
162}
163
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300164/* Theoretical max between source and sink */
165static int intel_dp_max_common_rate(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700166{
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300167 return intel_dp->common_rates[intel_dp->num_common_rates - 1];
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700168}
169
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300170/* Theoretical max between source and sink */
171static int intel_dp_max_common_lane_count(struct intel_dp *intel_dp)
Paulo Zanonieeb63242014-05-06 14:56:50 +0300172{
173 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300174 int source_max = intel_dig_port->max_lanes;
175 int sink_max = drm_dp_max_lane_count(intel_dp->dpcd);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300176
177 return min(source_max, sink_max);
178}
179
Jani Nikula3d65a732017-04-06 16:44:14 +0300180int intel_dp_max_lane_count(struct intel_dp *intel_dp)
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300181{
182 return intel_dp->max_link_lane_count;
183}
184
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800185int
Keith Packardc8982612012-01-25 08:16:25 -0800186intel_dp_link_required(int pixel_clock, int bpp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700187{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800188 /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
189 return DIV_ROUND_UP(pixel_clock * bpp, 8);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700190}
191
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800192int
Dave Airliefe27d532010-06-30 11:46:17 +1000193intel_dp_max_data_rate(int max_link_clock, int max_lanes)
194{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800195 /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
196 * link rate that is generally expressed in Gbps. Since, 8 bits of data
197 * is transmitted every LS_Clk per lane, there is no need to account for
198 * the channel encoding that is done in the PHY layer here.
199 */
200
201 return max_link_clock * max_lanes;
Dave Airliefe27d532010-06-30 11:46:17 +1000202}
203
Mika Kahola70ec0642016-09-09 14:10:55 +0300204static int
205intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp)
206{
207 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
208 struct intel_encoder *encoder = &intel_dig_port->base;
209 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
210 int max_dotclk = dev_priv->max_dotclk_freq;
211 int ds_max_dotclk;
212
213 int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
214
215 if (type != DP_DS_PORT_TYPE_VGA)
216 return max_dotclk;
217
218 ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd,
219 intel_dp->downstream_ports);
220
221 if (ds_max_dotclk != 0)
222 max_dotclk = min(max_dotclk, ds_max_dotclk);
223
224 return max_dotclk;
225}
226
Jani Nikula55cfc582017-03-28 17:59:04 +0300227static void
228intel_dp_set_source_rates(struct intel_dp *intel_dp)
Navare, Manasi D40dba342016-10-26 16:25:55 -0700229{
230 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
231 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Jani Nikula55cfc582017-03-28 17:59:04 +0300232 const int *source_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700233 int size;
234
Jani Nikula55cfc582017-03-28 17:59:04 +0300235 /* This should only be done once */
236 WARN_ON(intel_dp->source_rates || intel_dp->num_source_rates);
237
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200238 if (IS_GEN9_LP(dev_priv)) {
Jani Nikula55cfc582017-03-28 17:59:04 +0300239 source_rates = bxt_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700240 size = ARRAY_SIZE(bxt_rates);
Rodrigo Vivib976dc52017-01-23 10:32:37 -0800241 } else if (IS_GEN9_BC(dev_priv)) {
Jani Nikula55cfc582017-03-28 17:59:04 +0300242 source_rates = skl_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700243 size = ARRAY_SIZE(skl_rates);
244 } else {
Jani Nikula55cfc582017-03-28 17:59:04 +0300245 source_rates = default_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700246 size = ARRAY_SIZE(default_rates);
247 }
248
249 /* This depends on the fact that 5.4 is last value in the array */
250 if (!intel_dp_source_supports_hbr2(intel_dp))
251 size--;
252
Jani Nikula55cfc582017-03-28 17:59:04 +0300253 intel_dp->source_rates = source_rates;
254 intel_dp->num_source_rates = size;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700255}
256
257static int intersect_rates(const int *source_rates, int source_len,
258 const int *sink_rates, int sink_len,
259 int *common_rates)
260{
261 int i = 0, j = 0, k = 0;
262
263 while (i < source_len && j < sink_len) {
264 if (source_rates[i] == sink_rates[j]) {
265 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
266 return k;
267 common_rates[k] = source_rates[i];
268 ++k;
269 ++i;
270 ++j;
271 } else if (source_rates[i] < sink_rates[j]) {
272 ++i;
273 } else {
274 ++j;
275 }
276 }
277 return k;
278}
279
Jani Nikula8001b752017-03-28 17:59:03 +0300280/* return index of rate in rates array, or -1 if not found */
281static int intel_dp_rate_index(const int *rates, int len, int rate)
282{
283 int i;
284
285 for (i = 0; i < len; i++)
286 if (rate == rates[i])
287 return i;
288
289 return -1;
290}
291
Jani Nikula975ee5fca2017-04-06 16:44:10 +0300292static void intel_dp_set_common_rates(struct intel_dp *intel_dp)
Navare, Manasi D40dba342016-10-26 16:25:55 -0700293{
Jani Nikula975ee5fca2017-04-06 16:44:10 +0300294 WARN_ON(!intel_dp->num_source_rates || !intel_dp->num_sink_rates);
Navare, Manasi D40dba342016-10-26 16:25:55 -0700295
Jani Nikula975ee5fca2017-04-06 16:44:10 +0300296 intel_dp->num_common_rates = intersect_rates(intel_dp->source_rates,
297 intel_dp->num_source_rates,
298 intel_dp->sink_rates,
299 intel_dp->num_sink_rates,
300 intel_dp->common_rates);
301
302 /* Paranoia, there should always be something in common. */
303 if (WARN_ON(intel_dp->num_common_rates == 0)) {
304 intel_dp->common_rates[0] = default_rates[0];
305 intel_dp->num_common_rates = 1;
306 }
307}
308
309/* get length of common rates potentially limited by max_rate */
310static int intel_dp_common_len_rate_limit(struct intel_dp *intel_dp,
311 int max_rate)
312{
313 const int *common_rates = intel_dp->common_rates;
314 int i, common_len = intel_dp->num_common_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700315
Jani Nikula68f357c2017-03-28 17:59:05 +0300316 /* Limit results by potentially reduced max rate */
317 for (i = 0; i < common_len; i++) {
318 if (common_rates[common_len - i - 1] <= max_rate)
319 return common_len - i;
320 }
321
322 return 0;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700323}
324
Manasi Navare14c562c2017-04-06 14:00:12 -0700325static bool intel_dp_link_params_valid(struct intel_dp *intel_dp)
326{
327 /*
328 * FIXME: we need to synchronize the current link parameters with
329 * hardware readout. Currently fast link training doesn't work on
330 * boot-up.
331 */
332 if (intel_dp->link_rate == 0 ||
333 intel_dp->link_rate > intel_dp->max_link_rate)
334 return false;
335
336 if (intel_dp->lane_count == 0 ||
337 intel_dp->lane_count > intel_dp_max_lane_count(intel_dp))
338 return false;
339
340 return true;
341}
342
Manasi Navarefdb14d32016-12-08 19:05:12 -0800343int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
344 int link_rate, uint8_t lane_count)
345{
Jani Nikulab1810a72017-04-06 16:44:11 +0300346 int index;
Manasi Navarefdb14d32016-12-08 19:05:12 -0800347
Jani Nikulab1810a72017-04-06 16:44:11 +0300348 index = intel_dp_rate_index(intel_dp->common_rates,
349 intel_dp->num_common_rates,
350 link_rate);
351 if (index > 0) {
Jani Nikulae6c0c642017-04-06 16:44:12 +0300352 intel_dp->max_link_rate = intel_dp->common_rates[index - 1];
353 intel_dp->max_link_lane_count = lane_count;
Manasi Navarefdb14d32016-12-08 19:05:12 -0800354 } else if (lane_count > 1) {
Jani Nikula540b0b7f2017-04-06 16:44:13 +0300355 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
Jani Nikulae6c0c642017-04-06 16:44:12 +0300356 intel_dp->max_link_lane_count = lane_count >> 1;
Manasi Navarefdb14d32016-12-08 19:05:12 -0800357 } else {
358 DRM_ERROR("Link Training Unsuccessful\n");
359 return -1;
360 }
361
362 return 0;
363}
364
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000365static enum drm_mode_status
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700366intel_dp_mode_valid(struct drm_connector *connector,
367 struct drm_display_mode *mode)
368{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100369 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300370 struct intel_connector *intel_connector = to_intel_connector(connector);
371 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Daniel Vetter36008362013-03-27 00:44:59 +0100372 int target_clock = mode->clock;
373 int max_rate, mode_rate, max_lanes, max_link_clock;
Mika Kahola70ec0642016-09-09 14:10:55 +0300374 int max_dotclk;
375
376 max_dotclk = intel_dp_downstream_max_dotclock(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700377
Jani Nikuladd06f902012-10-19 14:51:50 +0300378 if (is_edp(intel_dp) && fixed_mode) {
379 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100380 return MODE_PANEL;
381
Jani Nikuladd06f902012-10-19 14:51:50 +0300382 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100383 return MODE_PANEL;
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200384
385 target_clock = fixed_mode->clock;
Zhao Yakui7de56f42010-07-19 09:43:14 +0100386 }
387
Ville Syrjälä50fec212015-03-12 17:10:34 +0200388 max_link_clock = intel_dp_max_link_rate(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300389 max_lanes = intel_dp_max_lane_count(intel_dp);
Daniel Vetter36008362013-03-27 00:44:59 +0100390
391 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
392 mode_rate = intel_dp_link_required(target_clock, 18);
393
Mika Kahola799487f2016-02-02 15:16:38 +0200394 if (mode_rate > max_rate || target_clock > max_dotclk)
Daniel Vetterc4867932012-04-10 10:42:36 +0200395 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700396
397 if (mode->clock < 10000)
398 return MODE_CLOCK_LOW;
399
Daniel Vetter0af78a22012-05-23 11:30:55 +0200400 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
401 return MODE_H_ILLEGAL;
402
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700403 return MODE_OK;
404}
405
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800406uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700407{
408 int i;
409 uint32_t v = 0;
410
411 if (src_bytes > 4)
412 src_bytes = 4;
413 for (i = 0; i < src_bytes; i++)
414 v |= ((uint32_t) src[i]) << ((3-i) * 8);
415 return v;
416}
417
Damien Lespiauc2af70e2015-02-10 19:32:23 +0000418static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700419{
420 int i;
421 if (dst_bytes > 4)
422 dst_bytes = 4;
423 for (i = 0; i < dst_bytes; i++)
424 dst[i] = src >> ((3-i) * 8);
425}
426
Jani Nikulabf13e812013-09-06 07:40:05 +0300427static void
428intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300429 struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300430static void
431intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200432 struct intel_dp *intel_dp,
433 bool force_disable_vdd);
Imre Deak335f7522016-08-10 14:07:32 +0300434static void
435intel_dp_pps_init(struct drm_device *dev, struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300436
Ville Syrjälä773538e82014-09-04 14:54:56 +0300437static void pps_lock(struct intel_dp *intel_dp)
438{
439 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
440 struct intel_encoder *encoder = &intel_dig_port->base;
441 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100442 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300443
444 /*
445 * See vlv_power_sequencer_reset() why we need
446 * a power domain reference here.
447 */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +0200448 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300449
450 mutex_lock(&dev_priv->pps_mutex);
451}
452
453static void pps_unlock(struct intel_dp *intel_dp)
454{
455 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
456 struct intel_encoder *encoder = &intel_dig_port->base;
457 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100458 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300459
460 mutex_unlock(&dev_priv->pps_mutex);
461
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +0200462 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300463}
464
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300465static void
466vlv_power_sequencer_kick(struct intel_dp *intel_dp)
467{
468 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200469 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300470 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300471 bool pll_enabled, release_cl_override = false;
472 enum dpio_phy phy = DPIO_PHY(pipe);
473 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300474 uint32_t DP;
475
476 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
477 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
478 pipe_name(pipe), port_name(intel_dig_port->port)))
479 return;
480
481 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
482 pipe_name(pipe), port_name(intel_dig_port->port));
483
484 /* Preserve the BIOS-computed detected bit. This is
485 * supposed to be read-only.
486 */
487 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
488 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
489 DP |= DP_PORT_WIDTH(1);
490 DP |= DP_LINK_TRAIN_PAT_1;
491
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100492 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300493 DP |= DP_PIPE_SELECT_CHV(pipe);
494 else if (pipe == PIPE_B)
495 DP |= DP_PIPEB_SELECT;
496
Ville Syrjäläd288f652014-10-28 13:20:22 +0200497 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
498
499 /*
500 * The DPLL for the pipe must be enabled for this to work.
501 * So enable temporarily it if it's not already enabled.
502 */
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300503 if (!pll_enabled) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100504 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300505 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
506
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200507 if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ?
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000508 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
509 DRM_ERROR("Failed to force on pll for pipe %c!\n",
510 pipe_name(pipe));
511 return;
512 }
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300513 }
Ville Syrjäläd288f652014-10-28 13:20:22 +0200514
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300515 /*
516 * Similar magic as in intel_dp_enable_port().
517 * We _must_ do this port enable + disable trick
518 * to make this power seqeuencer lock onto the port.
519 * Otherwise even VDD force bit won't work.
520 */
521 I915_WRITE(intel_dp->output_reg, DP);
522 POSTING_READ(intel_dp->output_reg);
523
524 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
525 POSTING_READ(intel_dp->output_reg);
526
527 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
528 POSTING_READ(intel_dp->output_reg);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200529
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300530 if (!pll_enabled) {
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200531 vlv_force_pll_off(dev_priv, pipe);
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300532
533 if (release_cl_override)
534 chv_phy_powergate_ch(dev_priv, phy, ch, false);
535 }
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300536}
537
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200538static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv)
539{
540 struct intel_encoder *encoder;
541 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
542
543 /*
544 * We don't have power sequencer currently.
545 * Pick one that's not used by other ports.
546 */
547 for_each_intel_encoder(&dev_priv->drm, encoder) {
548 struct intel_dp *intel_dp;
549
550 if (encoder->type != INTEL_OUTPUT_DP &&
551 encoder->type != INTEL_OUTPUT_EDP)
552 continue;
553
554 intel_dp = enc_to_intel_dp(&encoder->base);
555
556 if (encoder->type == INTEL_OUTPUT_EDP) {
557 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
558 intel_dp->active_pipe != intel_dp->pps_pipe);
559
560 if (intel_dp->pps_pipe != INVALID_PIPE)
561 pipes &= ~(1 << intel_dp->pps_pipe);
562 } else {
563 WARN_ON(intel_dp->pps_pipe != INVALID_PIPE);
564
565 if (intel_dp->active_pipe != INVALID_PIPE)
566 pipes &= ~(1 << intel_dp->active_pipe);
567 }
568 }
569
570 if (pipes == 0)
571 return INVALID_PIPE;
572
573 return ffs(pipes) - 1;
574}
575
Jani Nikulabf13e812013-09-06 07:40:05 +0300576static enum pipe
577vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
578{
579 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300580 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100581 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300582 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300583
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300584 lockdep_assert_held(&dev_priv->pps_mutex);
585
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300586 /* We should never land here with regular DP ports */
587 WARN_ON(!is_edp(intel_dp));
588
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200589 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
590 intel_dp->active_pipe != intel_dp->pps_pipe);
591
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300592 if (intel_dp->pps_pipe != INVALID_PIPE)
593 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300594
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200595 pipe = vlv_find_free_pps(dev_priv);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300596
597 /*
598 * Didn't find one. This should not happen since there
599 * are two power sequencers and up to two eDP ports.
600 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200601 if (WARN_ON(pipe == INVALID_PIPE))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300602 pipe = PIPE_A;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300603
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300604 vlv_steal_power_sequencer(dev, pipe);
605 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300606
607 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
608 pipe_name(intel_dp->pps_pipe),
609 port_name(intel_dig_port->port));
610
611 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300612 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200613 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300614
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300615 /*
616 * Even vdd force doesn't work until we've made
617 * the power sequencer lock in on the port.
618 */
619 vlv_power_sequencer_kick(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300620
621 return intel_dp->pps_pipe;
622}
623
Imre Deak78597992016-06-16 16:37:20 +0300624static int
625bxt_power_sequencer_idx(struct intel_dp *intel_dp)
626{
627 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
628 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100629 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak78597992016-06-16 16:37:20 +0300630
631 lockdep_assert_held(&dev_priv->pps_mutex);
632
633 /* We should never land here with regular DP ports */
634 WARN_ON(!is_edp(intel_dp));
635
636 /*
637 * TODO: BXT has 2 PPS instances. The correct port->PPS instance
638 * mapping needs to be retrieved from VBT, for now just hard-code to
639 * use instance #0 always.
640 */
641 if (!intel_dp->pps_reset)
642 return 0;
643
644 intel_dp->pps_reset = false;
645
646 /*
647 * Only the HW needs to be reprogrammed, the SW state is fixed and
648 * has been setup during connector init.
649 */
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200650 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak78597992016-06-16 16:37:20 +0300651
652 return 0;
653}
654
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300655typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
656 enum pipe pipe);
657
658static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
659 enum pipe pipe)
660{
Imre Deak44cb7342016-08-10 14:07:29 +0300661 return I915_READ(PP_STATUS(pipe)) & PP_ON;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300662}
663
664static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
665 enum pipe pipe)
666{
Imre Deak44cb7342016-08-10 14:07:29 +0300667 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300668}
669
670static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
671 enum pipe pipe)
672{
673 return true;
674}
675
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300676static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300677vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
678 enum port port,
679 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300680{
Jani Nikulabf13e812013-09-06 07:40:05 +0300681 enum pipe pipe;
682
Jani Nikulabf13e812013-09-06 07:40:05 +0300683 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
Imre Deak44cb7342016-08-10 14:07:29 +0300684 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
Jani Nikulabf13e812013-09-06 07:40:05 +0300685 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300686
687 if (port_sel != PANEL_PORT_SELECT_VLV(port))
688 continue;
689
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300690 if (!pipe_check(dev_priv, pipe))
691 continue;
692
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300693 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300694 }
695
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300696 return INVALID_PIPE;
697}
698
699static void
700vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
701{
702 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
703 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100704 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300705 enum port port = intel_dig_port->port;
706
707 lockdep_assert_held(&dev_priv->pps_mutex);
708
709 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300710 /* first pick one where the panel is on */
711 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
712 vlv_pipe_has_pp_on);
713 /* didn't find one? pick one where vdd is on */
714 if (intel_dp->pps_pipe == INVALID_PIPE)
715 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
716 vlv_pipe_has_vdd_on);
717 /* didn't find one? pick one with just the correct port */
718 if (intel_dp->pps_pipe == INVALID_PIPE)
719 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
720 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300721
722 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
723 if (intel_dp->pps_pipe == INVALID_PIPE) {
724 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
725 port_name(port));
726 return;
727 }
728
729 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
730 port_name(port), pipe_name(intel_dp->pps_pipe));
731
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300732 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200733 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Jani Nikulabf13e812013-09-06 07:40:05 +0300734}
735
Imre Deak78597992016-06-16 16:37:20 +0300736void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300737{
Chris Wilson91c8a322016-07-05 10:40:23 +0100738 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300739 struct intel_encoder *encoder;
740
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100741 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200742 !IS_GEN9_LP(dev_priv)))
Ville Syrjälä773538e82014-09-04 14:54:56 +0300743 return;
744
745 /*
746 * We can't grab pps_mutex here due to deadlock with power_domain
747 * mutex when power_domain functions are called while holding pps_mutex.
748 * That also means that in order to use pps_pipe the code needs to
749 * hold both a power domain reference and pps_mutex, and the power domain
750 * reference get/put must be done while _not_ holding pps_mutex.
751 * pps_{lock,unlock}() do these steps in the correct order, so one
752 * should use them always.
753 */
754
Jani Nikula19c80542015-12-16 12:48:16 +0200755 for_each_intel_encoder(dev, encoder) {
Ville Syrjälä773538e82014-09-04 14:54:56 +0300756 struct intel_dp *intel_dp;
757
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200758 if (encoder->type != INTEL_OUTPUT_DP &&
759 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300760 continue;
761
762 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200763
764 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
765
766 if (encoder->type != INTEL_OUTPUT_EDP)
767 continue;
768
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200769 if (IS_GEN9_LP(dev_priv))
Imre Deak78597992016-06-16 16:37:20 +0300770 intel_dp->pps_reset = true;
771 else
772 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300773 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300774}
775
Imre Deak8e8232d2016-06-16 16:37:21 +0300776struct pps_registers {
777 i915_reg_t pp_ctrl;
778 i915_reg_t pp_stat;
779 i915_reg_t pp_on;
780 i915_reg_t pp_off;
781 i915_reg_t pp_div;
782};
783
784static void intel_pps_get_registers(struct drm_i915_private *dev_priv,
785 struct intel_dp *intel_dp,
786 struct pps_registers *regs)
787{
Imre Deak44cb7342016-08-10 14:07:29 +0300788 int pps_idx = 0;
789
Imre Deak8e8232d2016-06-16 16:37:21 +0300790 memset(regs, 0, sizeof(*regs));
791
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200792 if (IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300793 pps_idx = bxt_power_sequencer_idx(intel_dp);
794 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
795 pps_idx = vlv_power_sequencer_pipe(intel_dp);
Imre Deak8e8232d2016-06-16 16:37:21 +0300796
Imre Deak44cb7342016-08-10 14:07:29 +0300797 regs->pp_ctrl = PP_CONTROL(pps_idx);
798 regs->pp_stat = PP_STATUS(pps_idx);
799 regs->pp_on = PP_ON_DELAYS(pps_idx);
800 regs->pp_off = PP_OFF_DELAYS(pps_idx);
Rodrigo Vivi938361e2017-06-02 13:06:44 -0700801 if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300802 regs->pp_div = PP_DIVISOR(pps_idx);
Imre Deak8e8232d2016-06-16 16:37:21 +0300803}
804
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200805static i915_reg_t
806_pp_ctrl_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300807{
Imre Deak8e8232d2016-06-16 16:37:21 +0300808 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300809
Imre Deak8e8232d2016-06-16 16:37:21 +0300810 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
811 &regs);
812
813 return regs.pp_ctrl;
Jani Nikulabf13e812013-09-06 07:40:05 +0300814}
815
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200816static i915_reg_t
817_pp_stat_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300818{
Imre Deak8e8232d2016-06-16 16:37:21 +0300819 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300820
Imre Deak8e8232d2016-06-16 16:37:21 +0300821 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
822 &regs);
823
824 return regs.pp_stat;
Jani Nikulabf13e812013-09-06 07:40:05 +0300825}
826
Clint Taylor01527b32014-07-07 13:01:46 -0700827/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
828 This function only applicable when panel PM state is not to be tracked */
829static int edp_notify_handler(struct notifier_block *this, unsigned long code,
830 void *unused)
831{
832 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
833 edp_notifier);
834 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100835 struct drm_i915_private *dev_priv = to_i915(dev);
Clint Taylor01527b32014-07-07 13:01:46 -0700836
837 if (!is_edp(intel_dp) || code != SYS_RESTART)
838 return 0;
839
Ville Syrjälä773538e82014-09-04 14:54:56 +0300840 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300841
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100842 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300843 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200844 i915_reg_t pp_ctrl_reg, pp_div_reg;
Ville Syrjälä649636e2015-09-22 19:50:01 +0300845 u32 pp_div;
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300846
Imre Deak44cb7342016-08-10 14:07:29 +0300847 pp_ctrl_reg = PP_CONTROL(pipe);
848 pp_div_reg = PP_DIVISOR(pipe);
Clint Taylor01527b32014-07-07 13:01:46 -0700849 pp_div = I915_READ(pp_div_reg);
850 pp_div &= PP_REFERENCE_DIVIDER_MASK;
851
852 /* 0x1F write to PP_DIV_REG sets max cycle delay */
853 I915_WRITE(pp_div_reg, pp_div | 0x1F);
854 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
855 msleep(intel_dp->panel_power_cycle_delay);
856 }
857
Ville Syrjälä773538e82014-09-04 14:54:56 +0300858 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300859
Clint Taylor01527b32014-07-07 13:01:46 -0700860 return 0;
861}
862
Daniel Vetter4be73782014-01-17 14:39:48 +0100863static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700864{
Paulo Zanoni30add222012-10-26 19:05:45 -0200865 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100866 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700867
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300868 lockdep_assert_held(&dev_priv->pps_mutex);
869
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100870 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300871 intel_dp->pps_pipe == INVALID_PIPE)
872 return false;
873
Jani Nikulabf13e812013-09-06 07:40:05 +0300874 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700875}
876
Daniel Vetter4be73782014-01-17 14:39:48 +0100877static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700878{
Paulo Zanoni30add222012-10-26 19:05:45 -0200879 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100880 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700881
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300882 lockdep_assert_held(&dev_priv->pps_mutex);
883
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100884 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300885 intel_dp->pps_pipe == INVALID_PIPE)
886 return false;
887
Ville Syrjälä773538e82014-09-04 14:54:56 +0300888 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700889}
890
Keith Packard9b984da2011-09-19 13:54:47 -0700891static void
892intel_dp_check_edp(struct intel_dp *intel_dp)
893{
Paulo Zanoni30add222012-10-26 19:05:45 -0200894 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100895 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700896
Keith Packard9b984da2011-09-19 13:54:47 -0700897 if (!is_edp(intel_dp))
898 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700899
Daniel Vetter4be73782014-01-17 14:39:48 +0100900 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700901 WARN(1, "eDP powered off while attempting aux channel communication.\n");
902 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300903 I915_READ(_pp_stat_reg(intel_dp)),
904 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700905 }
906}
907
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100908static uint32_t
909intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
910{
911 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
912 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100913 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200914 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100915 uint32_t status;
916 bool done;
917
Daniel Vetteref04f002012-12-01 21:03:59 +0100918#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100919 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300920 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300921 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100922 else
Imre Deak713a6b662016-06-28 13:37:33 +0300923 done = wait_for(C, 10) == 0;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100924 if (!done)
925 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
926 has_aux_irq);
927#undef C
928
929 return status;
930}
931
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200932static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000933{
934 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200935 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000936
Ville Syrjäläa457f542016-03-02 17:22:17 +0200937 if (index)
938 return 0;
939
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000940 /*
941 * The clock divider is based off the hrawclk, and would like to run at
Ville Syrjäläa457f542016-03-02 17:22:17 +0200942 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000943 */
Ville Syrjäläa457f542016-03-02 17:22:17 +0200944 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000945}
946
947static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
948{
949 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200950 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000951
952 if (index)
953 return 0;
954
Ville Syrjäläa457f542016-03-02 17:22:17 +0200955 /*
956 * The clock divider is based off the cdclk or PCH rawclk, and would
957 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
958 * divide by 2000 and use that
959 */
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200960 if (intel_dig_port->port == PORT_A)
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200961 return DIV_ROUND_CLOSEST(dev_priv->cdclk.hw.cdclk, 2000);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200962 else
963 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000964}
965
966static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300967{
968 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200969 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300970
Ville Syrjäläa457f542016-03-02 17:22:17 +0200971 if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300972 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100973 switch (index) {
974 case 0: return 63;
975 case 1: return 72;
976 default: return 0;
977 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300978 }
Ville Syrjäläa457f542016-03-02 17:22:17 +0200979
980 return ilk_get_aux_clock_divider(intel_dp, index);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300981}
982
Damien Lespiaub6b5e382014-01-20 16:00:59 +0000983static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
984{
985 /*
986 * SKL doesn't need us to program the AUX clock divider (Hardware will
987 * derive the clock from CDCLK automatically). We still implement the
988 * get_aux_clock_divider vfunc to plug-in into the existing code.
989 */
990 return index ? 0 : 1;
991}
992
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200993static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
994 bool has_aux_irq,
995 int send_bytes,
996 uint32_t aux_clock_divider)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000997{
998 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100999 struct drm_i915_private *dev_priv =
1000 to_i915(intel_dig_port->base.base.dev);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001001 uint32_t precharge, timeout;
1002
Tvrtko Ursulin86527442016-10-13 11:03:00 +01001003 if (IS_GEN6(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001004 precharge = 3;
1005 else
1006 precharge = 5;
1007
Tvrtko Ursulin86527442016-10-13 11:03:00 +01001008 if (IS_BROADWELL(dev_priv) && intel_dig_port->port == PORT_A)
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001009 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
1010 else
1011 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
1012
1013 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +00001014 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001015 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +00001016 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001017 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +00001018 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001019 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
1020 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +00001021 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001022}
1023
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00001024static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
1025 bool has_aux_irq,
1026 int send_bytes,
1027 uint32_t unused)
1028{
1029 return DP_AUX_CH_CTL_SEND_BUSY |
1030 DP_AUX_CH_CTL_DONE |
1031 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
1032 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1033 DP_AUX_CH_CTL_TIME_OUT_1600us |
1034 DP_AUX_CH_CTL_RECEIVE_ERROR |
1035 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Daniel Vetterd4dcbdc2016-05-18 18:47:15 +02001036 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00001037 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
1038}
1039
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001040static int
Chris Wilsonea5b2132010-08-04 13:50:23 +01001041intel_dp_aux_ch(struct intel_dp *intel_dp,
Daniel Vetterbd9f74a2014-10-02 09:45:35 +02001042 const uint8_t *send, int send_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001043 uint8_t *recv, int recv_size)
1044{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001045 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001046 struct drm_i915_private *dev_priv =
1047 to_i915(intel_dig_port->base.base.dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001048 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Chris Wilsonbc866252013-07-21 16:00:03 +01001049 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001050 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001051 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001052 int try, clock = 0;
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001053 bool has_aux_irq = HAS_AUX_IRQ(dev_priv);
Jani Nikula884f19e2014-03-14 16:51:14 +02001054 bool vdd;
1055
Ville Syrjälä773538e82014-09-04 14:54:56 +03001056 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001057
Ville Syrjälä72c35002014-08-18 22:16:00 +03001058 /*
1059 * We will be called with VDD already enabled for dpcd/edid/oui reads.
1060 * In such cases we want to leave VDD enabled and it's up to upper layers
1061 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
1062 * ourselves.
1063 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001064 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001065
1066 /* dp aux is extremely sensitive to irq latency, hence request the
1067 * lowest possible wakeup latency and so prevent the cpu from going into
1068 * deep sleep states.
1069 */
1070 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001071
Keith Packard9b984da2011-09-19 13:54:47 -07001072 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001073
Jesse Barnes11bee432011-08-01 15:02:20 -07001074 /* Try to wait for any previous AUX channel activity */
1075 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +01001076 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -07001077 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
1078 break;
1079 msleep(1);
1080 }
1081
1082 if (try == 3) {
Mika Kuoppala02196c72015-08-06 16:48:58 +03001083 static u32 last_status = -1;
1084 const u32 status = I915_READ(ch_ctl);
1085
1086 if (status != last_status) {
1087 WARN(1, "dp_aux_ch not started status 0x%08x\n",
1088 status);
1089 last_status = status;
1090 }
1091
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001092 ret = -EBUSY;
1093 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001094 }
1095
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001096 /* Only 5 data registers! */
1097 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
1098 ret = -E2BIG;
1099 goto out;
1100 }
1101
Damien Lespiauec5b01d2014-01-21 13:35:39 +00001102 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +00001103 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
1104 has_aux_irq,
1105 send_bytes,
1106 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001107
Chris Wilsonbc866252013-07-21 16:00:03 +01001108 /* Must try at least 3 times according to DP spec */
1109 for (try = 0; try < 5; try++) {
1110 /* Load the send data into the aux channel data registers */
1111 for (i = 0; i < send_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001112 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001113 intel_dp_pack_aux(send + i,
1114 send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -04001115
Chris Wilsonbc866252013-07-21 16:00:03 +01001116 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001117 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001118
Chris Wilsonbc866252013-07-21 16:00:03 +01001119 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -04001120
Chris Wilsonbc866252013-07-21 16:00:03 +01001121 /* Clear done status and any errors */
1122 I915_WRITE(ch_ctl,
1123 status |
1124 DP_AUX_CH_CTL_DONE |
1125 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1126 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -04001127
Todd Previte74ebf292015-04-15 08:38:41 -07001128 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
Chris Wilsonbc866252013-07-21 16:00:03 +01001129 continue;
Todd Previte74ebf292015-04-15 08:38:41 -07001130
1131 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
1132 * 400us delay required for errors and timeouts
1133 * Timeout errors from the HW already meet this
1134 * requirement so skip to next iteration
1135 */
1136 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1137 usleep_range(400, 500);
1138 continue;
1139 }
Chris Wilsonbc866252013-07-21 16:00:03 +01001140 if (status & DP_AUX_CH_CTL_DONE)
Jim Bridee058c942015-05-27 10:21:48 -07001141 goto done;
Chris Wilsonbc866252013-07-21 16:00:03 +01001142 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001143 }
1144
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001145 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001146 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001147 ret = -EBUSY;
1148 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001149 }
1150
Jim Bridee058c942015-05-27 10:21:48 -07001151done:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001152 /* Check for timeout or receive error.
1153 * Timeouts occur when the sink is not connected
1154 */
Keith Packarda5b3da52009-06-11 22:30:32 -07001155 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001156 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001157 ret = -EIO;
1158 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -07001159 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001160
1161 /* Timeouts occur when the device isn't connected, so they're
1162 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -07001163 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Chris Wilsona5570fe2017-02-23 11:51:02 +00001164 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001165 ret = -ETIMEDOUT;
1166 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001167 }
1168
1169 /* Unload any bytes sent back from the other side */
1170 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
1171 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Rodrigo Vivi14e01882015-12-10 11:12:27 -08001172
1173 /*
1174 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1175 * We have no idea of what happened so we return -EBUSY so
1176 * drm layer takes care for the necessary retries.
1177 */
1178 if (recv_bytes == 0 || recv_bytes > 20) {
1179 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1180 recv_bytes);
1181 /*
1182 * FIXME: This patch was created on top of a series that
1183 * organize the retries at drm level. There EBUSY should
1184 * also take care for 1ms wait before retrying.
1185 * That aux retries re-org is still needed and after that is
1186 * merged we remove this sleep from here.
1187 */
1188 usleep_range(1000, 1500);
1189 ret = -EBUSY;
1190 goto out;
1191 }
1192
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001193 if (recv_bytes > recv_size)
1194 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -04001195
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001196 for (i = 0; i < recv_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001197 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001198 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001199
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001200 ret = recv_bytes;
1201out:
1202 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1203
Jani Nikula884f19e2014-03-14 16:51:14 +02001204 if (vdd)
1205 edp_panel_vdd_off(intel_dp, false);
1206
Ville Syrjälä773538e82014-09-04 14:54:56 +03001207 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001208
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001209 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001210}
1211
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001212#define BARE_ADDRESS_SIZE 3
1213#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +02001214static ssize_t
1215intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001216{
Jani Nikula9d1a1032014-03-14 16:51:15 +02001217 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1218 uint8_t txbuf[20], rxbuf[20];
1219 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001220 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001221
Ville Syrjäläd2d9cbb2015-03-19 11:44:06 +02001222 txbuf[0] = (msg->request << 4) |
1223 ((msg->address >> 16) & 0xf);
1224 txbuf[1] = (msg->address >> 8) & 0xff;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001225 txbuf[2] = msg->address & 0xff;
1226 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001227
Jani Nikula9d1a1032014-03-14 16:51:15 +02001228 switch (msg->request & ~DP_AUX_I2C_MOT) {
1229 case DP_AUX_NATIVE_WRITE:
1230 case DP_AUX_I2C_WRITE:
Ville Syrjäläc1e741222015-08-27 17:23:27 +03001231 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001232 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001233 rxsize = 2; /* 0 or 1 data bytes */
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001234
Jani Nikula9d1a1032014-03-14 16:51:15 +02001235 if (WARN_ON(txsize > 20))
1236 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001237
Ville Syrjälädd788092016-07-28 17:55:04 +03001238 WARN_ON(!msg->buffer != !msg->size);
1239
Imre Deakd81a67c2016-01-29 14:52:26 +02001240 if (msg->buffer)
1241 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001242
Jani Nikula9d1a1032014-03-14 16:51:15 +02001243 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1244 if (ret > 0) {
1245 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001246
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001247 if (ret > 1) {
1248 /* Number of bytes written in a short write. */
1249 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1250 } else {
1251 /* Return payload size. */
1252 ret = msg->size;
1253 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001254 }
Jani Nikula9d1a1032014-03-14 16:51:15 +02001255 break;
1256
1257 case DP_AUX_NATIVE_READ:
1258 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001259 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001260 rxsize = msg->size + 1;
1261
1262 if (WARN_ON(rxsize > 20))
1263 return -E2BIG;
1264
1265 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1266 if (ret > 0) {
1267 msg->reply = rxbuf[0] >> 4;
1268 /*
1269 * Assume happy day, and copy the data. The caller is
1270 * expected to check msg->reply before touching it.
1271 *
1272 * Return payload size.
1273 */
1274 ret--;
1275 memcpy(msg->buffer, rxbuf + 1, ret);
1276 }
1277 break;
1278
1279 default:
1280 ret = -EINVAL;
1281 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001282 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001283
Jani Nikula9d1a1032014-03-14 16:51:15 +02001284 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001285}
1286
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001287static enum port intel_aux_port(struct drm_i915_private *dev_priv,
1288 enum port port)
1289{
1290 const struct ddi_vbt_port_info *info =
1291 &dev_priv->vbt.ddi_port_info[port];
1292 enum port aux_port;
1293
1294 if (!info->alternate_aux_channel) {
1295 DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
1296 port_name(port), port_name(port));
1297 return port;
1298 }
1299
1300 switch (info->alternate_aux_channel) {
1301 case DP_AUX_A:
1302 aux_port = PORT_A;
1303 break;
1304 case DP_AUX_B:
1305 aux_port = PORT_B;
1306 break;
1307 case DP_AUX_C:
1308 aux_port = PORT_C;
1309 break;
1310 case DP_AUX_D:
1311 aux_port = PORT_D;
1312 break;
1313 default:
1314 MISSING_CASE(info->alternate_aux_channel);
1315 aux_port = PORT_A;
1316 break;
1317 }
1318
1319 DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
1320 port_name(aux_port), port_name(port));
1321
1322 return aux_port;
1323}
1324
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001325static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001326 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001327{
1328 switch (port) {
1329 case PORT_B:
1330 case PORT_C:
1331 case PORT_D:
1332 return DP_AUX_CH_CTL(port);
1333 default:
1334 MISSING_CASE(port);
1335 return DP_AUX_CH_CTL(PORT_B);
1336 }
1337}
1338
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001339static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001340 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001341{
1342 switch (port) {
1343 case PORT_B:
1344 case PORT_C:
1345 case PORT_D:
1346 return DP_AUX_CH_DATA(port, index);
1347 default:
1348 MISSING_CASE(port);
1349 return DP_AUX_CH_DATA(PORT_B, index);
1350 }
1351}
1352
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001353static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001354 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001355{
1356 switch (port) {
1357 case PORT_A:
1358 return DP_AUX_CH_CTL(port);
1359 case PORT_B:
1360 case PORT_C:
1361 case PORT_D:
1362 return PCH_DP_AUX_CH_CTL(port);
1363 default:
1364 MISSING_CASE(port);
1365 return DP_AUX_CH_CTL(PORT_A);
1366 }
1367}
1368
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001369static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001370 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001371{
1372 switch (port) {
1373 case PORT_A:
1374 return DP_AUX_CH_DATA(port, index);
1375 case PORT_B:
1376 case PORT_C:
1377 case PORT_D:
1378 return PCH_DP_AUX_CH_DATA(port, index);
1379 default:
1380 MISSING_CASE(port);
1381 return DP_AUX_CH_DATA(PORT_A, index);
1382 }
1383}
1384
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001385static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001386 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001387{
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001388 switch (port) {
1389 case PORT_A:
1390 case PORT_B:
1391 case PORT_C:
1392 case PORT_D:
1393 return DP_AUX_CH_CTL(port);
1394 default:
1395 MISSING_CASE(port);
1396 return DP_AUX_CH_CTL(PORT_A);
1397 }
1398}
1399
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001400static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001401 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001402{
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001403 switch (port) {
1404 case PORT_A:
1405 case PORT_B:
1406 case PORT_C:
1407 case PORT_D:
1408 return DP_AUX_CH_DATA(port, index);
1409 default:
1410 MISSING_CASE(port);
1411 return DP_AUX_CH_DATA(PORT_A, index);
1412 }
1413}
1414
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001415static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001416 enum port port)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001417{
1418 if (INTEL_INFO(dev_priv)->gen >= 9)
1419 return skl_aux_ctl_reg(dev_priv, port);
1420 else if (HAS_PCH_SPLIT(dev_priv))
1421 return ilk_aux_ctl_reg(dev_priv, port);
1422 else
1423 return g4x_aux_ctl_reg(dev_priv, port);
1424}
1425
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001426static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001427 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001428{
1429 if (INTEL_INFO(dev_priv)->gen >= 9)
1430 return skl_aux_data_reg(dev_priv, port, index);
1431 else if (HAS_PCH_SPLIT(dev_priv))
1432 return ilk_aux_data_reg(dev_priv, port, index);
1433 else
1434 return g4x_aux_data_reg(dev_priv, port, index);
1435}
1436
1437static void intel_aux_reg_init(struct intel_dp *intel_dp)
1438{
1439 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001440 enum port port = intel_aux_port(dev_priv,
1441 dp_to_dig_port(intel_dp)->port);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001442 int i;
1443
1444 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1445 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1446 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1447}
1448
Jani Nikula9d1a1032014-03-14 16:51:15 +02001449static void
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001450intel_dp_aux_fini(struct intel_dp *intel_dp)
1451{
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001452 kfree(intel_dp->aux.name);
1453}
1454
Chris Wilson7a418e32016-06-24 14:00:14 +01001455static void
Mika Kaholab6339582016-09-09 14:10:52 +03001456intel_dp_aux_init(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001457{
Jani Nikula33ad6622014-03-14 16:51:16 +02001458 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1459 enum port port = intel_dig_port->port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001460
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001461 intel_aux_reg_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01001462 drm_dp_aux_init(&intel_dp->aux);
David Flynn8316f332010-12-08 16:10:21 +00001463
Chris Wilson7a418e32016-06-24 14:00:14 +01001464 /* Failure to allocate our preferred name is not critical */
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001465 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
Jani Nikula9d1a1032014-03-14 16:51:15 +02001466 intel_dp->aux.transfer = intel_dp_aux_transfer;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001467}
1468
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001469bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301470{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001471 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Navare, Manasi D577c5432016-09-27 16:36:53 -07001472 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001473
Navare, Manasi D577c5432016-09-27 16:36:53 -07001474 if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
1475 IS_BROADWELL(dev_priv) || (INTEL_GEN(dev_priv) >= 9))
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301476 return true;
1477 else
1478 return false;
1479}
1480
Daniel Vetter0e503382014-07-04 11:26:04 -03001481static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001482intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001483 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001484{
1485 struct drm_device *dev = encoder->base.dev;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001486 struct drm_i915_private *dev_priv = to_i915(dev);
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001487 const struct dp_link_dpll *divisor = NULL;
1488 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001489
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001490 if (IS_G4X(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001491 divisor = gen4_dpll;
1492 count = ARRAY_SIZE(gen4_dpll);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001493 } else if (HAS_PCH_SPLIT(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001494 divisor = pch_dpll;
1495 count = ARRAY_SIZE(pch_dpll);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001496 } else if (IS_CHERRYVIEW(dev_priv)) {
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001497 divisor = chv_dpll;
1498 count = ARRAY_SIZE(chv_dpll);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001499 } else if (IS_VALLEYVIEW(dev_priv)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001500 divisor = vlv_dpll;
1501 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001502 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001503
1504 if (divisor && count) {
1505 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001506 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001507 pipe_config->dpll = divisor[i].dpll;
1508 pipe_config->clock_set = true;
1509 break;
1510 }
1511 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001512 }
1513}
1514
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001515static void snprintf_int_array(char *str, size_t len,
1516 const int *array, int nelem)
1517{
1518 int i;
1519
1520 str[0] = '\0';
1521
1522 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001523 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001524 if (r >= len)
1525 return;
1526 str += r;
1527 len -= r;
1528 }
1529}
1530
1531static void intel_dp_print_rates(struct intel_dp *intel_dp)
1532{
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001533 char str[128]; /* FIXME: too big for stack? */
1534
1535 if ((drm_debug & DRM_UT_KMS) == 0)
1536 return;
1537
Jani Nikula55cfc582017-03-28 17:59:04 +03001538 snprintf_int_array(str, sizeof(str),
1539 intel_dp->source_rates, intel_dp->num_source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001540 DRM_DEBUG_KMS("source rates: %s\n", str);
1541
Jani Nikula68f357c2017-03-28 17:59:05 +03001542 snprintf_int_array(str, sizeof(str),
1543 intel_dp->sink_rates, intel_dp->num_sink_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001544 DRM_DEBUG_KMS("sink rates: %s\n", str);
1545
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001546 snprintf_int_array(str, sizeof(str),
1547 intel_dp->common_rates, intel_dp->num_common_rates);
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001548 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001549}
1550
Imre Deak489375c2016-10-24 19:33:31 +03001551bool
Imre Deak7b3fc172016-10-25 16:12:39 +03001552__intel_dp_read_desc(struct intel_dp *intel_dp, struct intel_dp_desc *desc)
Mika Kahola0e390a32016-09-09 14:10:53 +03001553{
Imre Deak7b3fc172016-10-25 16:12:39 +03001554 u32 base = drm_dp_is_branch(intel_dp->dpcd) ? DP_BRANCH_OUI :
1555 DP_SINK_OUI;
Mika Kahola0e390a32016-09-09 14:10:53 +03001556
Imre Deak7b3fc172016-10-25 16:12:39 +03001557 return drm_dp_dpcd_read(&intel_dp->aux, base, desc, sizeof(*desc)) ==
1558 sizeof(*desc);
Mika Kahola0e390a32016-09-09 14:10:53 +03001559}
1560
Imre Deak12a47a422016-10-24 19:33:29 +03001561bool intel_dp_read_desc(struct intel_dp *intel_dp)
Mika Kahola1a2724f2016-09-09 14:10:54 +03001562{
Imre Deak7b3fc172016-10-25 16:12:39 +03001563 struct intel_dp_desc *desc = &intel_dp->desc;
1564 bool oui_sup = intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] &
1565 DP_OUI_SUPPORT;
1566 int dev_id_len;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001567
Imre Deak7b3fc172016-10-25 16:12:39 +03001568 if (!__intel_dp_read_desc(intel_dp, desc))
1569 return false;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001570
Imre Deak7b3fc172016-10-25 16:12:39 +03001571 dev_id_len = strnlen(desc->device_id, sizeof(desc->device_id));
1572 DRM_DEBUG_KMS("DP %s: OUI %*phD%s dev-ID %*pE HW-rev %d.%d SW-rev %d.%d\n",
1573 drm_dp_is_branch(intel_dp->dpcd) ? "branch" : "sink",
1574 (int)sizeof(desc->oui), desc->oui, oui_sup ? "" : "(NS)",
1575 dev_id_len, desc->device_id,
1576 desc->hw_rev >> 4, desc->hw_rev & 0xf,
1577 desc->sw_major_rev, desc->sw_minor_rev);
Mika Kahola1a2724f2016-09-09 14:10:54 +03001578
Imre Deak7b3fc172016-10-25 16:12:39 +03001579 return true;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001580}
1581
Ville Syrjälä50fec212015-03-12 17:10:34 +02001582int
1583intel_dp_max_link_rate(struct intel_dp *intel_dp)
1584{
Ville Syrjälä50fec212015-03-12 17:10:34 +02001585 int len;
1586
Jani Nikulae6c0c642017-04-06 16:44:12 +03001587 len = intel_dp_common_len_rate_limit(intel_dp, intel_dp->max_link_rate);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001588 if (WARN_ON(len <= 0))
1589 return 162000;
1590
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001591 return intel_dp->common_rates[len - 1];
Ville Syrjälä50fec212015-03-12 17:10:34 +02001592}
1593
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001594int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1595{
Jani Nikula8001b752017-03-28 17:59:03 +03001596 int i = intel_dp_rate_index(intel_dp->sink_rates,
1597 intel_dp->num_sink_rates, rate);
Jani Nikulab5c72b22017-03-28 17:59:02 +03001598
1599 if (WARN_ON(i < 0))
1600 i = 0;
1601
1602 return i;
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001603}
1604
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001605void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1606 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001607{
Jani Nikula68f357c2017-03-28 17:59:05 +03001608 /* eDP 1.4 rate select method. */
1609 if (intel_dp->use_rate_select) {
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001610 *link_bw = 0;
1611 *rate_select =
1612 intel_dp_rate_select(intel_dp, port_clock);
1613 } else {
1614 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1615 *rate_select = 0;
1616 }
1617}
1618
Jani Nikulaf580bea2016-09-15 16:28:52 +03001619static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1620 struct intel_crtc_state *pipe_config)
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001621{
1622 int bpp, bpc;
1623
1624 bpp = pipe_config->pipe_bpp;
1625 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1626
1627 if (bpc > 0)
1628 bpp = min(bpp, 3*bpc);
1629
Manasi Navare611032b2017-01-24 08:21:49 -08001630 /* For DP Compliance we override the computed bpp for the pipe */
1631 if (intel_dp->compliance.test_data.bpc != 0) {
1632 pipe_config->pipe_bpp = 3*intel_dp->compliance.test_data.bpc;
1633 pipe_config->dither_force_disable = pipe_config->pipe_bpp == 6*3;
1634 DRM_DEBUG_KMS("Setting pipe_bpp to %d\n",
1635 pipe_config->pipe_bpp);
1636 }
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001637 return bpp;
1638}
1639
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001640bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001641intel_dp_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001642 struct intel_crtc_state *pipe_config,
1643 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001644{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001645 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001646 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001647 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001648 enum port port = dp_to_dig_port(intel_dp)->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001649 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001650 struct intel_connector *intel_connector = intel_dp->attached_connector;
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001651 struct intel_digital_connector_state *intel_conn_state =
1652 to_intel_digital_connector_state(conn_state);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001653 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001654 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001655 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001656 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001657 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301658 int max_clock;
Daniel Vetter083f9562012-04-20 20:23:49 +02001659 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001660 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001661 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001662 uint8_t link_bw, rate_select;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301663
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001664 common_len = intel_dp_common_len_rate_limit(intel_dp,
Jani Nikulae6c0c642017-04-06 16:44:12 +03001665 intel_dp->max_link_rate);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301666
1667 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001668 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301669
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001670 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001671
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001672 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001673 pipe_config->has_pch_encoder = true;
1674
Vandana Kannanf769cd22014-08-05 07:51:22 -07001675 pipe_config->has_drrs = false;
Maarten Lankhorste6b72c92017-05-01 15:38:00 +02001676 if (port == PORT_A)
1677 pipe_config->has_audio = false;
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001678 else if (intel_conn_state->force_audio == HDMI_AUDIO_AUTO)
Maarten Lankhorste6b72c92017-05-01 15:38:00 +02001679 pipe_config->has_audio = intel_dp->has_audio;
1680 else
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001681 pipe_config->has_audio = intel_conn_state->force_audio == HDMI_AUDIO_ON;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001682
Jani Nikuladd06f902012-10-19 14:51:50 +03001683 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1684 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
1685 adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001686
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001687 if (INTEL_GEN(dev_priv) >= 9) {
Chandra Kondurua1b22782015-04-07 15:28:45 -07001688 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001689 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001690 if (ret)
1691 return ret;
1692 }
1693
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001694 if (HAS_GMCH_DISPLAY(dev_priv))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001695 intel_gmch_panel_fitting(intel_crtc, pipe_config,
Maarten Lankhorsteead06d2017-05-01 15:37:55 +02001696 conn_state->scaling_mode);
Jesse Barnes2dd24552013-04-25 12:55:01 -07001697 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001698 intel_pch_panel_fitting(intel_crtc, pipe_config,
Maarten Lankhorsteead06d2017-05-01 15:37:55 +02001699 conn_state->scaling_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001700 }
1701
Daniel Vettercb1793c2012-06-04 18:39:21 +02001702 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001703 return false;
1704
Manasi Navareda15f7c2017-01-24 08:16:34 -08001705 /* Use values requested by Compliance Test Request */
1706 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
Jani Nikulaec990e22017-04-06 16:44:15 +03001707 int index;
1708
1709 index = intel_dp_rate_index(intel_dp->common_rates,
1710 intel_dp->num_common_rates,
1711 intel_dp->compliance.test_link_rate);
1712 if (index >= 0)
1713 min_clock = max_clock = index;
Manasi Navareda15f7c2017-01-24 08:16:34 -08001714 min_lane_count = max_lane_count = intel_dp->compliance.test_lane_count;
1715 }
Daniel Vetter083f9562012-04-20 20:23:49 +02001716 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301717 "max bw %d pixel clock %iKHz\n",
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001718 max_lane_count, intel_dp->common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001719 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001720
Daniel Vetter36008362013-03-27 00:44:59 +01001721 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1722 * bpc in between. */
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001723 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
Jani Nikula56071a22014-05-06 14:56:52 +03001724 if (is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301725
1726 /* Get bpp from vbt only for panels that dont have bpp in edid */
1727 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001728 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001729 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001730 dev_priv->vbt.edp.bpp);
1731 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001732 }
1733
Jani Nikula344c5bb2014-09-09 11:25:13 +03001734 /*
1735 * Use the maximum clock and number of lanes the eDP panel
1736 * advertizes being capable of. The panels are generally
1737 * designed to support only a single clock and lane
1738 * configuration, and typically these values correspond to the
1739 * native resolution of the panel.
1740 */
1741 min_lane_count = max_lane_count;
1742 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001743 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001744
Daniel Vetter36008362013-03-27 00:44:59 +01001745 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001746 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1747 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001748
Dave Airliec6930992014-07-14 11:04:39 +10001749 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301750 for (lane_count = min_lane_count;
1751 lane_count <= max_lane_count;
1752 lane_count <<= 1) {
1753
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001754 link_clock = intel_dp->common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001755 link_avail = intel_dp_max_data_rate(link_clock,
1756 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001757
Daniel Vetter36008362013-03-27 00:44:59 +01001758 if (mode_rate <= link_avail) {
1759 goto found;
1760 }
1761 }
1762 }
1763 }
1764
1765 return false;
1766
1767found:
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001768 if (intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_AUTO) {
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001769 /*
1770 * See:
1771 * CEA-861-E - 5.1 Default Encoding Parameters
1772 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1773 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001774 pipe_config->limited_color_range =
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02001775 bpp != 18 &&
1776 drm_default_rgb_quant_range(adjusted_mode) ==
1777 HDMI_QUANTIZATION_RANGE_LIMITED;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001778 } else {
1779 pipe_config->limited_color_range =
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02001780 intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_LIMITED;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001781 }
1782
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001783 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301784
Daniel Vetter657445f2013-05-04 10:09:18 +02001785 pipe_config->pipe_bpp = bpp;
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001786 pipe_config->port_clock = intel_dp->common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001787
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001788 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1789 &link_bw, &rate_select);
1790
1791 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1792 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001793 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001794 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1795 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001796
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001797 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001798 adjusted_mode->crtc_clock,
1799 pipe_config->port_clock,
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001800 &pipe_config->dp_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001801
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301802 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301803 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001804 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301805 intel_link_compute_m_n(bpp, lane_count,
1806 intel_connector->panel.downclock_mode->clock,
1807 pipe_config->port_clock,
1808 &pipe_config->dp_m2_n2);
1809 }
1810
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001811 /*
1812 * DPLL0 VCO may need to be adjusted to get the correct
1813 * clock for eDP. This will affect cdclk as well.
1814 */
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001815 if (is_edp(intel_dp) && IS_GEN9_BC(dev_priv)) {
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001816 int vco;
1817
1818 switch (pipe_config->port_clock / 2) {
1819 case 108000:
1820 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001821 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001822 break;
1823 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001824 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001825 break;
1826 }
1827
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +02001828 to_intel_atomic_state(pipe_config->base.state)->cdclk.logical.vco = vco;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001829 }
1830
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001831 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001832 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001833
Daniel Vetter36008362013-03-27 00:44:59 +01001834 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001835}
1836
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001837void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001838 int link_rate, uint8_t lane_count,
1839 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001840{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001841 intel_dp->link_rate = link_rate;
1842 intel_dp->lane_count = lane_count;
1843 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001844}
1845
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001846static void intel_dp_prepare(struct intel_encoder *encoder,
1847 struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001848{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001849 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001850 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001851 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001852 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001853 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001854 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001855
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001856 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1857 pipe_config->lane_count,
1858 intel_crtc_has_type(pipe_config,
1859 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001860
Keith Packard417e8222011-11-01 19:54:11 -07001861 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001862 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001863 *
1864 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001865 * SNB CPU
1866 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001867 * CPT PCH
1868 *
1869 * IBX PCH and CPU are the same for almost everything,
1870 * except that the CPU DP PLL is configured in this
1871 * register
1872 *
1873 * CPT PCH is quite different, having many bits moved
1874 * to the TRANS_DP_CTL register instead. That
1875 * configuration happens (oddly) in ironlake_pch_enable
1876 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001877
Keith Packard417e8222011-11-01 19:54:11 -07001878 /* Preserve the BIOS-computed detected bit. This is
1879 * supposed to be read-only.
1880 */
1881 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001882
Keith Packard417e8222011-11-01 19:54:11 -07001883 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001884 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001885 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001886
Keith Packard417e8222011-11-01 19:54:11 -07001887 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001888
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001889 if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001890 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1891 intel_dp->DP |= DP_SYNC_HS_HIGH;
1892 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1893 intel_dp->DP |= DP_SYNC_VS_HIGH;
1894 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1895
Jani Nikula6aba5b62013-10-04 15:08:10 +03001896 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001897 intel_dp->DP |= DP_ENHANCED_FRAMING;
1898
Daniel Vetter7c62a162013-06-01 17:16:20 +02001899 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001900 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001901 u32 trans_dp;
1902
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001903 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001904
1905 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1906 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1907 trans_dp |= TRANS_DP_ENH_FRAMING;
1908 else
1909 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1910 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001911 } else {
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02001912 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001913 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001914
1915 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1916 intel_dp->DP |= DP_SYNC_HS_HIGH;
1917 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1918 intel_dp->DP |= DP_SYNC_VS_HIGH;
1919 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1920
Jani Nikula6aba5b62013-10-04 15:08:10 +03001921 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001922 intel_dp->DP |= DP_ENHANCED_FRAMING;
1923
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001924 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001925 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001926 else if (crtc->pipe == PIPE_B)
1927 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001928 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001929}
1930
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001931#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1932#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001933
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001934#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1935#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001936
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001937#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1938#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001939
Imre Deakde9c1b62016-06-16 20:01:46 +03001940static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
1941 struct intel_dp *intel_dp);
1942
Daniel Vetter4be73782014-01-17 14:39:48 +01001943static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001944 u32 mask,
1945 u32 value)
1946{
Paulo Zanoni30add222012-10-26 19:05:45 -02001947 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001948 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001949 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001950
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001951 lockdep_assert_held(&dev_priv->pps_mutex);
1952
Imre Deakde9c1b62016-06-16 20:01:46 +03001953 intel_pps_verify_state(dev_priv, intel_dp);
1954
Jani Nikulabf13e812013-09-06 07:40:05 +03001955 pp_stat_reg = _pp_stat_reg(intel_dp);
1956 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001957
1958 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001959 mask, value,
1960 I915_READ(pp_stat_reg),
1961 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001962
Chris Wilson9036ff02016-06-30 15:33:09 +01001963 if (intel_wait_for_register(dev_priv,
1964 pp_stat_reg, mask, value,
1965 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001966 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001967 I915_READ(pp_stat_reg),
1968 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001969
1970 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001971}
1972
Daniel Vetter4be73782014-01-17 14:39:48 +01001973static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001974{
1975 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001976 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001977}
1978
Daniel Vetter4be73782014-01-17 14:39:48 +01001979static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001980{
Keith Packardbd943152011-09-18 23:09:52 -07001981 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001982 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001983}
Keith Packardbd943152011-09-18 23:09:52 -07001984
Daniel Vetter4be73782014-01-17 14:39:48 +01001985static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001986{
Abhay Kumard28d4732016-01-22 17:39:04 -08001987 ktime_t panel_power_on_time;
1988 s64 panel_power_off_duration;
1989
Keith Packard99ea7122011-11-01 19:57:50 -07001990 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001991
Abhay Kumard28d4732016-01-22 17:39:04 -08001992 /* take the difference of currrent time and panel power off time
1993 * and then make panel wait for t11_t12 if needed. */
1994 panel_power_on_time = ktime_get_boottime();
1995 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1996
Paulo Zanonidce56b32013-12-19 14:29:40 -02001997 /* When we disable the VDD override bit last we have to do the manual
1998 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08001999 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
2000 wait_remaining_ms_from_jiffies(jiffies,
2001 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002002
Daniel Vetter4be73782014-01-17 14:39:48 +01002003 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07002004}
Keith Packardbd943152011-09-18 23:09:52 -07002005
Daniel Vetter4be73782014-01-17 14:39:48 +01002006static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02002007{
2008 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
2009 intel_dp->backlight_on_delay);
2010}
2011
Daniel Vetter4be73782014-01-17 14:39:48 +01002012static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02002013{
2014 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
2015 intel_dp->backlight_off_delay);
2016}
Keith Packard99ea7122011-11-01 19:57:50 -07002017
Keith Packard832dd3c2011-11-01 19:34:06 -07002018/* Read the current pp_control value, unlocking the register if it
2019 * is locked
2020 */
2021
Jesse Barnes453c5422013-03-28 09:55:41 -07002022static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07002023{
Jesse Barnes453c5422013-03-28 09:55:41 -07002024 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002025 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07002026 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07002027
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002028 lockdep_assert_held(&dev_priv->pps_mutex);
2029
Jani Nikulabf13e812013-09-06 07:40:05 +03002030 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03002031 if (WARN_ON(!HAS_DDI(dev_priv) &&
2032 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05302033 control &= ~PANEL_UNLOCK_MASK;
2034 control |= PANEL_UNLOCK_REGS;
2035 }
Keith Packard832dd3c2011-11-01 19:34:06 -07002036 return control;
Keith Packardbd943152011-09-18 23:09:52 -07002037}
2038
Ville Syrjälä951468f2014-09-04 14:55:31 +03002039/*
2040 * Must be paired with edp_panel_vdd_off().
2041 * Must hold pps_mutex around the whole on/off sequence.
2042 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2043 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03002044static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002045{
Paulo Zanoni30add222012-10-26 19:05:45 -02002046 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002047 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002048 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes5d613502011-01-24 17:10:54 -08002049 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002050 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002051 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08002052
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002053 lockdep_assert_held(&dev_priv->pps_mutex);
2054
Keith Packard97af61f572011-09-28 16:23:51 -07002055 if (!is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002056 return false;
Keith Packardbd943152011-09-18 23:09:52 -07002057
Egbert Eich2c623c12014-11-25 12:54:57 +01002058 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002059 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07002060
Daniel Vetter4be73782014-01-17 14:39:48 +01002061 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002062 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002063
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002064 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002065
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002066 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
2067 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07002068
Daniel Vetter4be73782014-01-17 14:39:48 +01002069 if (!edp_have_panel_power(intel_dp))
2070 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07002071
Jesse Barnes453c5422013-03-28 09:55:41 -07002072 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002073 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07002074
Jani Nikulabf13e812013-09-06 07:40:05 +03002075 pp_stat_reg = _pp_stat_reg(intel_dp);
2076 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002077
2078 I915_WRITE(pp_ctrl_reg, pp);
2079 POSTING_READ(pp_ctrl_reg);
2080 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2081 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07002082 /*
2083 * If the panel wasn't on, delay before accessing aux channel
2084 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002085 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002086 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
2087 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07002088 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07002089 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002090
2091 return need_to_disable;
2092}
2093
Ville Syrjälä951468f2014-09-04 14:55:31 +03002094/*
2095 * Must be paired with intel_edp_panel_vdd_off() or
2096 * intel_edp_panel_off().
2097 * Nested calls to these functions are not allowed since
2098 * we drop the lock. Caller must use some higher level
2099 * locking to prevent nested calls from other threads.
2100 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01002101void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002102{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002103 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002104
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002105 if (!is_edp(intel_dp))
2106 return;
2107
Ville Syrjälä773538e82014-09-04 14:54:56 +03002108 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002109 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002110 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002111
Rob Clarke2c719b2014-12-15 13:56:32 -05002112 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002113 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08002114}
2115
Daniel Vetter4be73782014-01-17 14:39:48 +01002116static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002117{
Paulo Zanoni30add222012-10-26 19:05:45 -02002118 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002119 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002120 struct intel_digital_port *intel_dig_port =
2121 dp_to_dig_port(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002122 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002123 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002124
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002125 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002126
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002127 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002128
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002129 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002130 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002131
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002132 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2133 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002134
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002135 pp = ironlake_get_pp_control(intel_dp);
2136 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002137
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002138 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2139 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002140
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002141 I915_WRITE(pp_ctrl_reg, pp);
2142 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002143
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002144 /* Make sure sequencer is idle before allowing subsequent activity */
2145 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2146 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002147
Imre Deak5a162e22016-08-10 14:07:30 +03002148 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002149 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002150
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002151 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002152}
2153
Daniel Vetter4be73782014-01-17 14:39:48 +01002154static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002155{
2156 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2157 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002158
Ville Syrjälä773538e82014-09-04 14:54:56 +03002159 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002160 if (!intel_dp->want_panel_vdd)
2161 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002162 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002163}
2164
Imre Deakaba86892014-07-30 15:57:31 +03002165static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2166{
2167 unsigned long delay;
2168
2169 /*
2170 * Queue the timer to fire a long time from now (relative to the power
2171 * down delay) to keep the panel power up across a sequence of
2172 * operations.
2173 */
2174 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2175 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2176}
2177
Ville Syrjälä951468f2014-09-04 14:55:31 +03002178/*
2179 * Must be paired with edp_panel_vdd_on().
2180 * Must hold pps_mutex around the whole on/off sequence.
2181 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2182 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002183static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002184{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002185 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002186
2187 lockdep_assert_held(&dev_priv->pps_mutex);
2188
Keith Packard97af61f572011-09-28 16:23:51 -07002189 if (!is_edp(intel_dp))
2190 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002191
Rob Clarke2c719b2014-12-15 13:56:32 -05002192 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002193 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002194
Keith Packardbd943152011-09-18 23:09:52 -07002195 intel_dp->want_panel_vdd = false;
2196
Imre Deakaba86892014-07-30 15:57:31 +03002197 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002198 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002199 else
2200 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002201}
2202
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002203static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002204{
Paulo Zanoni30add222012-10-26 19:05:45 -02002205 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002206 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002207 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002208 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002209
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002210 lockdep_assert_held(&dev_priv->pps_mutex);
2211
Keith Packard97af61f572011-09-28 16:23:51 -07002212 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002213 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002214
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002215 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2216 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002217
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002218 if (WARN(edp_have_panel_power(intel_dp),
2219 "eDP port %c panel power already on\n",
2220 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002221 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002222
Daniel Vetter4be73782014-01-17 14:39:48 +01002223 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002224
Jani Nikulabf13e812013-09-06 07:40:05 +03002225 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002226 pp = ironlake_get_pp_control(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002227 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002228 /* ILK workaround: disable reset around power sequence */
2229 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002230 I915_WRITE(pp_ctrl_reg, pp);
2231 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002232 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002233
Imre Deak5a162e22016-08-10 14:07:30 +03002234 pp |= PANEL_POWER_ON;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002235 if (!IS_GEN5(dev_priv))
Keith Packard99ea7122011-11-01 19:57:50 -07002236 pp |= PANEL_POWER_RESET;
2237
Jesse Barnes453c5422013-03-28 09:55:41 -07002238 I915_WRITE(pp_ctrl_reg, pp);
2239 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002240
Daniel Vetter4be73782014-01-17 14:39:48 +01002241 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002242 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002243
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002244 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002245 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002246 I915_WRITE(pp_ctrl_reg, pp);
2247 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002248 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002249}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002250
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002251void intel_edp_panel_on(struct intel_dp *intel_dp)
2252{
2253 if (!is_edp(intel_dp))
2254 return;
2255
2256 pps_lock(intel_dp);
2257 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002258 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002259}
2260
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002261
2262static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002263{
Paulo Zanoni30add222012-10-26 19:05:45 -02002264 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002265 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002266 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002267 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002268
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002269 lockdep_assert_held(&dev_priv->pps_mutex);
2270
Keith Packard97af61f572011-09-28 16:23:51 -07002271 if (!is_edp(intel_dp))
2272 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002273
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002274 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2275 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002276
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002277 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2278 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002279
Jesse Barnes453c5422013-03-28 09:55:41 -07002280 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002281 /* We need to switch off panel power _and_ force vdd, for otherwise some
2282 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002283 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002284 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002285
Jani Nikulabf13e812013-09-06 07:40:05 +03002286 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002287
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002288 intel_dp->want_panel_vdd = false;
2289
Jesse Barnes453c5422013-03-28 09:55:41 -07002290 I915_WRITE(pp_ctrl_reg, pp);
2291 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002292
Abhay Kumard28d4732016-01-22 17:39:04 -08002293 intel_dp->panel_power_off_time = ktime_get_boottime();
Daniel Vetter4be73782014-01-17 14:39:48 +01002294 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002295
2296 /* We got a reference when we enabled the VDD. */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002297 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002298}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002299
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002300void intel_edp_panel_off(struct intel_dp *intel_dp)
2301{
2302 if (!is_edp(intel_dp))
2303 return;
2304
2305 pps_lock(intel_dp);
2306 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002307 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002308}
2309
Jani Nikula1250d102014-08-12 17:11:39 +03002310/* Enable backlight in the panel power control. */
2311static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002312{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002313 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2314 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002315 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002316 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002317 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002318
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002319 /*
2320 * If we enable the backlight right away following a panel power
2321 * on, we may see slight flicker as the panel syncs with the eDP
2322 * link. So delay a bit to make sure the image is solid before
2323 * allowing it to appear.
2324 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002325 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002326
Ville Syrjälä773538e82014-09-04 14:54:56 +03002327 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002328
Jesse Barnes453c5422013-03-28 09:55:41 -07002329 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002330 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002331
Jani Nikulabf13e812013-09-06 07:40:05 +03002332 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002333
2334 I915_WRITE(pp_ctrl_reg, pp);
2335 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002336
Ville Syrjälä773538e82014-09-04 14:54:56 +03002337 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002338}
2339
Jani Nikula1250d102014-08-12 17:11:39 +03002340/* Enable backlight PWM and backlight PP control. */
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002341void intel_edp_backlight_on(const struct intel_crtc_state *crtc_state,
2342 const struct drm_connector_state *conn_state)
Jani Nikula1250d102014-08-12 17:11:39 +03002343{
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002344 struct intel_dp *intel_dp = enc_to_intel_dp(conn_state->best_encoder);
2345
Jani Nikula1250d102014-08-12 17:11:39 +03002346 if (!is_edp(intel_dp))
2347 return;
2348
2349 DRM_DEBUG_KMS("\n");
2350
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002351 intel_panel_enable_backlight(crtc_state, conn_state);
Jani Nikula1250d102014-08-12 17:11:39 +03002352 _intel_edp_backlight_on(intel_dp);
2353}
2354
2355/* Disable backlight in the panel power control. */
2356static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002357{
Paulo Zanoni30add222012-10-26 19:05:45 -02002358 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002359 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002360 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002361 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002362
Keith Packardf01eca22011-09-28 16:48:10 -07002363 if (!is_edp(intel_dp))
2364 return;
2365
Ville Syrjälä773538e82014-09-04 14:54:56 +03002366 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002367
Jesse Barnes453c5422013-03-28 09:55:41 -07002368 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002369 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002370
Jani Nikulabf13e812013-09-06 07:40:05 +03002371 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002372
2373 I915_WRITE(pp_ctrl_reg, pp);
2374 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002375
Ville Syrjälä773538e82014-09-04 14:54:56 +03002376 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002377
Paulo Zanonidce56b32013-12-19 14:29:40 -02002378 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002379 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002380}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002381
Jani Nikula1250d102014-08-12 17:11:39 +03002382/* Disable backlight PP control and backlight PWM. */
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002383void intel_edp_backlight_off(const struct drm_connector_state *old_conn_state)
Jani Nikula1250d102014-08-12 17:11:39 +03002384{
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002385 struct intel_dp *intel_dp = enc_to_intel_dp(old_conn_state->best_encoder);
2386
Jani Nikula1250d102014-08-12 17:11:39 +03002387 if (!is_edp(intel_dp))
2388 return;
2389
2390 DRM_DEBUG_KMS("\n");
2391
2392 _intel_edp_backlight_off(intel_dp);
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002393 intel_panel_disable_backlight(old_conn_state);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002394}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002395
Jani Nikula73580fb72014-08-12 17:11:41 +03002396/*
2397 * Hook for controlling the panel power control backlight through the bl_power
2398 * sysfs attribute. Take care to handle multiple calls.
2399 */
2400static void intel_edp_backlight_power(struct intel_connector *connector,
2401 bool enable)
2402{
2403 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002404 bool is_enabled;
2405
Ville Syrjälä773538e82014-09-04 14:54:56 +03002406 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002407 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002408 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002409
2410 if (is_enabled == enable)
2411 return;
2412
Jani Nikula23ba9372014-08-27 14:08:43 +03002413 DRM_DEBUG_KMS("panel power control backlight %s\n",
2414 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002415
2416 if (enable)
2417 _intel_edp_backlight_on(intel_dp);
2418 else
2419 _intel_edp_backlight_off(intel_dp);
2420}
2421
Ville Syrjälä64e10772015-10-29 21:26:01 +02002422static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2423{
2424 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2425 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2426 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2427
2428 I915_STATE_WARN(cur_state != state,
2429 "DP port %c state assertion failure (expected %s, current %s)\n",
2430 port_name(dig_port->port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002431 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002432}
2433#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2434
2435static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2436{
2437 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2438
2439 I915_STATE_WARN(cur_state != state,
2440 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002441 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002442}
2443#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2444#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2445
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002446static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2447 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002448{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002449 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002450 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002451
Ville Syrjälä64e10772015-10-29 21:26:01 +02002452 assert_pipe_disabled(dev_priv, crtc->pipe);
2453 assert_dp_port_disabled(intel_dp);
2454 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002455
Ville Syrjäläabfce942015-10-29 21:26:03 +02002456 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002457 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002458
2459 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2460
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002461 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002462 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2463 else
2464 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2465
2466 I915_WRITE(DP_A, intel_dp->DP);
2467 POSTING_READ(DP_A);
2468 udelay(500);
2469
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002470 /*
2471 * [DevILK] Work around required when enabling DP PLL
2472 * while a pipe is enabled going to FDI:
2473 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2474 * 2. Program DP PLL enable
2475 */
2476 if (IS_GEN5(dev_priv))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02002477 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002478
Daniel Vetter07679352012-09-06 22:15:42 +02002479 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002480
Daniel Vetter07679352012-09-06 22:15:42 +02002481 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002482 POSTING_READ(DP_A);
2483 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002484}
2485
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002486static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002487{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002488 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002489 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2490 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002491
Ville Syrjälä64e10772015-10-29 21:26:01 +02002492 assert_pipe_disabled(dev_priv, crtc->pipe);
2493 assert_dp_port_disabled(intel_dp);
2494 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002495
Ville Syrjäläabfce942015-10-29 21:26:03 +02002496 DRM_DEBUG_KMS("disabling eDP PLL\n");
2497
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002498 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002499
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002500 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002501 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002502 udelay(200);
2503}
2504
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002505/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002506void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002507{
2508 int ret, i;
2509
2510 /* Should have a valid DPCD by this point */
2511 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2512 return;
2513
2514 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002515 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2516 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002517 } else {
Imre Deak357c0ae2016-11-21 21:15:06 +02002518 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
2519
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002520 /*
2521 * When turning on, we need to retry for 1ms to give the sink
2522 * time to wake up.
2523 */
2524 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002525 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2526 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002527 if (ret == 1)
2528 break;
2529 msleep(1);
2530 }
Imre Deak357c0ae2016-11-21 21:15:06 +02002531
2532 if (ret == 1 && lspcon->active)
2533 lspcon_wait_pcon_mode(lspcon);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002534 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002535
2536 if (ret != 1)
2537 DRM_DEBUG_KMS("failed to %s sink power state\n",
2538 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002539}
2540
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002541static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2542 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002543{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002544 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002545 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002546 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002547 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002548 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002549 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002550
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002551 if (!intel_display_power_get_if_enabled(dev_priv,
2552 encoder->power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002553 return false;
2554
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002555 ret = false;
2556
Imre Deak6d129be2014-03-05 16:20:54 +02002557 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002558
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002559 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002560 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002561
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002562 if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002563 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002564 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002565 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002566
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002567 for_each_pipe(dev_priv, p) {
2568 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2569 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2570 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002571 ret = true;
2572
2573 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002574 }
2575 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002576
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002577 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002578 i915_mmio_reg_offset(intel_dp->output_reg));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002579 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002580 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2581 } else {
2582 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002583 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002584
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002585 ret = true;
2586
2587out:
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002588 intel_display_power_put(dev_priv, encoder->power_domain);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002589
2590 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002591}
2592
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002593static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002594 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002595{
2596 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002597 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002598 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002599 struct drm_i915_private *dev_priv = to_i915(dev);
Xiong Zhang63000ef2013-06-28 12:59:06 +08002600 enum port port = dp_to_dig_port(intel_dp)->port;
2601 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002602
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002603 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002604
2605 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002606
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002607 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002608 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2609
2610 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002611 flags |= DRM_MODE_FLAG_PHSYNC;
2612 else
2613 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002614
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002615 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002616 flags |= DRM_MODE_FLAG_PVSYNC;
2617 else
2618 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002619 } else {
2620 if (tmp & DP_SYNC_HS_HIGH)
2621 flags |= DRM_MODE_FLAG_PHSYNC;
2622 else
2623 flags |= DRM_MODE_FLAG_NHSYNC;
2624
2625 if (tmp & DP_SYNC_VS_HIGH)
2626 flags |= DRM_MODE_FLAG_PVSYNC;
2627 else
2628 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002629 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002630
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002631 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002632
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02002633 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002634 pipe_config->limited_color_range = true;
2635
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002636 pipe_config->lane_count =
2637 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2638
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002639 intel_dp_get_m_n(crtc, pipe_config);
2640
Ville Syrjälä18442d02013-09-13 16:00:08 +03002641 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002642 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002643 pipe_config->port_clock = 162000;
2644 else
2645 pipe_config->port_clock = 270000;
2646 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002647
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002648 pipe_config->base.adjusted_mode.crtc_clock =
2649 intel_dotclock_calculate(pipe_config->port_clock,
2650 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002651
Jani Nikula6aa23e62016-03-24 17:50:20 +02002652 if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
2653 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002654 /*
2655 * This is a big fat ugly hack.
2656 *
2657 * Some machines in UEFI boot mode provide us a VBT that has 18
2658 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2659 * unknown we fail to light up. Yet the same BIOS boots up with
2660 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2661 * max, not what it tells us to use.
2662 *
2663 * Note: This will still be broken if the eDP panel is not lit
2664 * up by the BIOS, and thus we can't get the mode at module
2665 * load.
2666 */
2667 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002668 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2669 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002670 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002671}
2672
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002673static void intel_disable_dp(struct intel_encoder *encoder,
2674 struct intel_crtc_state *old_crtc_state,
2675 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002676{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002677 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002678 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002679
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002680 if (old_crtc_state->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002681 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002682
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002683 if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv))
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002684 intel_psr_disable(intel_dp);
2685
Daniel Vetter6cb49832012-05-20 17:14:50 +02002686 /* Make sure the panel is off before trying to change the mode. But also
2687 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002688 intel_edp_panel_vdd_on(intel_dp);
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002689 intel_edp_backlight_off(old_conn_state);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002690 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002691 intel_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02002692
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002693 /* disable the port before the pipe on g4x */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002694 if (INTEL_GEN(dev_priv) < 5)
Daniel Vetter37398502012-09-06 22:15:44 +02002695 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07002696}
2697
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002698static void ilk_post_disable_dp(struct intel_encoder *encoder,
2699 struct intel_crtc_state *old_crtc_state,
2700 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002701{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002702 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002703 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002704
Ville Syrjälä49277c32014-03-31 18:21:26 +03002705 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002706
2707 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002708 if (port == PORT_A)
2709 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002710}
2711
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002712static void vlv_post_disable_dp(struct intel_encoder *encoder,
2713 struct intel_crtc_state *old_crtc_state,
2714 struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002715{
2716 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2717
2718 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002719}
2720
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002721static void chv_post_disable_dp(struct intel_encoder *encoder,
2722 struct intel_crtc_state *old_crtc_state,
2723 struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002724{
2725 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002726 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002727 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002728
2729 intel_dp_link_down(intel_dp);
2730
Ville Syrjäläa5805162015-05-26 20:42:30 +03002731 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002732
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002733 /* Assert data lane reset */
2734 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002735
Ville Syrjäläa5805162015-05-26 20:42:30 +03002736 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002737}
2738
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002739static void
2740_intel_dp_set_link_train(struct intel_dp *intel_dp,
2741 uint32_t *DP,
2742 uint8_t dp_train_pat)
2743{
2744 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2745 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002746 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002747 enum port port = intel_dig_port->port;
2748
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002749 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2750 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2751 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2752
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002753 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002754 uint32_t temp = I915_READ(DP_TP_CTL(port));
2755
2756 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2757 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2758 else
2759 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2760
2761 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2762 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2763 case DP_TRAINING_PATTERN_DISABLE:
2764 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2765
2766 break;
2767 case DP_TRAINING_PATTERN_1:
2768 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2769 break;
2770 case DP_TRAINING_PATTERN_2:
2771 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2772 break;
2773 case DP_TRAINING_PATTERN_3:
2774 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2775 break;
2776 }
2777 I915_WRITE(DP_TP_CTL(port), temp);
2778
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002779 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002780 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002781 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2782
2783 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2784 case DP_TRAINING_PATTERN_DISABLE:
2785 *DP |= DP_LINK_TRAIN_OFF_CPT;
2786 break;
2787 case DP_TRAINING_PATTERN_1:
2788 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2789 break;
2790 case DP_TRAINING_PATTERN_2:
2791 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2792 break;
2793 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002794 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002795 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2796 break;
2797 }
2798
2799 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002800 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002801 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2802 else
2803 *DP &= ~DP_LINK_TRAIN_MASK;
2804
2805 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2806 case DP_TRAINING_PATTERN_DISABLE:
2807 *DP |= DP_LINK_TRAIN_OFF;
2808 break;
2809 case DP_TRAINING_PATTERN_1:
2810 *DP |= DP_LINK_TRAIN_PAT_1;
2811 break;
2812 case DP_TRAINING_PATTERN_2:
2813 *DP |= DP_LINK_TRAIN_PAT_2;
2814 break;
2815 case DP_TRAINING_PATTERN_3:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002816 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002817 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2818 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002819 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002820 *DP |= DP_LINK_TRAIN_PAT_2;
2821 }
2822 break;
2823 }
2824 }
2825}
2826
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002827static void intel_dp_enable_port(struct intel_dp *intel_dp,
2828 struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002829{
2830 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002831 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002832
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002833 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002834
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002835 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002836
2837 /*
2838 * Magic for VLV/CHV. We _must_ first set up the register
2839 * without actually enabling the port, and then do another
2840 * write to enable the port. Otherwise link training will
2841 * fail when the power sequencer is freshly used for this port.
2842 */
2843 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002844 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002845 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002846
2847 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2848 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002849}
2850
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002851static void intel_enable_dp(struct intel_encoder *encoder,
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002852 struct intel_crtc_state *pipe_config,
2853 struct drm_connector_state *conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002854{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002855 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2856 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002857 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulac1dec792014-10-27 16:26:56 +02002858 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002859 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002860 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002861
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002862 if (WARN_ON(dp_reg & DP_PORT_EN))
2863 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002864
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002865 pps_lock(intel_dp);
2866
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002867 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002868 vlv_init_panel_power_sequencer(intel_dp);
2869
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002870 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002871
2872 edp_panel_vdd_on(intel_dp);
2873 edp_panel_on(intel_dp);
2874 edp_panel_vdd_off(intel_dp, true);
2875
2876 pps_unlock(intel_dp);
2877
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002878 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002879 unsigned int lane_mask = 0x0;
2880
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002881 if (IS_CHERRYVIEW(dev_priv))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002882 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002883
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002884 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2885 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002886 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002887
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002888 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2889 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002890 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002891
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002892 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002893 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002894 pipe_name(pipe));
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002895 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Jani Nikulac1dec792014-10-27 16:26:56 +02002896 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002897}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002898
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002899static void g4x_enable_dp(struct intel_encoder *encoder,
2900 struct intel_crtc_state *pipe_config,
2901 struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03002902{
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002903 intel_enable_dp(encoder, pipe_config, conn_state);
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002904 intel_edp_backlight_on(pipe_config, conn_state);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002905}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002906
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002907static void vlv_enable_dp(struct intel_encoder *encoder,
2908 struct intel_crtc_state *pipe_config,
2909 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002910{
Jani Nikula828f5c62013-09-05 16:44:45 +03002911 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2912
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002913 intel_edp_backlight_on(pipe_config, conn_state);
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002914 intel_psr_enable(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002915}
2916
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002917static void g4x_pre_enable_dp(struct intel_encoder *encoder,
2918 struct intel_crtc_state *pipe_config,
2919 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002920{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002921 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002922 enum port port = dp_to_dig_port(intel_dp)->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002923
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002924 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002925
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002926 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002927 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002928 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002929}
2930
Ville Syrjälä83b84592014-10-16 21:29:51 +03002931static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2932{
2933 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002934 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002935 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03002936 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002937
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002938 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
2939
Ville Syrjäläd1586942017-02-08 19:52:54 +02002940 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2941 return;
2942
Ville Syrjälä83b84592014-10-16 21:29:51 +03002943 edp_panel_vdd_off_sync(intel_dp);
2944
2945 /*
2946 * VLV seems to get confused when multiple power seqeuencers
2947 * have the same port selected (even if only one has power/vdd
2948 * enabled). The failure manifests as vlv_wait_port_ready() failing
2949 * CHV on the other hand doesn't seem to mind having the same port
2950 * selected in multiple power seqeuencers, but let's clear the
2951 * port select always when logically disconnecting a power sequencer
2952 * from a port.
2953 */
2954 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2955 pipe_name(pipe), port_name(intel_dig_port->port));
2956 I915_WRITE(pp_on_reg, 0);
2957 POSTING_READ(pp_on_reg);
2958
2959 intel_dp->pps_pipe = INVALID_PIPE;
2960}
2961
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002962static void vlv_steal_power_sequencer(struct drm_device *dev,
2963 enum pipe pipe)
2964{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002965 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002966 struct intel_encoder *encoder;
2967
2968 lockdep_assert_held(&dev_priv->pps_mutex);
2969
Jani Nikula19c80542015-12-16 12:48:16 +02002970 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002971 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002972 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002973
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002974 if (encoder->type != INTEL_OUTPUT_DP &&
2975 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002976 continue;
2977
2978 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002979 port = dp_to_dig_port(intel_dp)->port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002980
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002981 WARN(intel_dp->active_pipe == pipe,
2982 "stealing pipe %c power sequencer from active (e)DP port %c\n",
2983 pipe_name(pipe), port_name(port));
2984
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002985 if (intel_dp->pps_pipe != pipe)
2986 continue;
2987
2988 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03002989 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002990
2991 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002992 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002993 }
2994}
2995
2996static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
2997{
2998 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2999 struct intel_encoder *encoder = &intel_dig_port->base;
3000 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003001 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003002 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003003
3004 lockdep_assert_held(&dev_priv->pps_mutex);
3005
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003006 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03003007
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003008 if (intel_dp->pps_pipe != INVALID_PIPE &&
3009 intel_dp->pps_pipe != crtc->pipe) {
3010 /*
3011 * If another power sequencer was being used on this
3012 * port previously make sure to turn off vdd there while
3013 * we still have control of it.
3014 */
Ville Syrjälä83b84592014-10-16 21:29:51 +03003015 vlv_detach_power_sequencer(intel_dp);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003016 }
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003017
3018 /*
3019 * We may be stealing the power
3020 * sequencer from another port.
3021 */
3022 vlv_steal_power_sequencer(dev, crtc->pipe);
3023
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003024 intel_dp->active_pipe = crtc->pipe;
3025
3026 if (!is_edp(intel_dp))
3027 return;
3028
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003029 /* now it's all ours */
3030 intel_dp->pps_pipe = crtc->pipe;
3031
3032 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
3033 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
3034
3035 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03003036 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02003037 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003038}
3039
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003040static void vlv_pre_enable_dp(struct intel_encoder *encoder,
3041 struct intel_crtc_state *pipe_config,
3042 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03003043{
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03003044 vlv_phy_pre_encoder_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003045
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003046 intel_enable_dp(encoder, pipe_config, conn_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003047}
3048
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003049static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
3050 struct intel_crtc_state *pipe_config,
3051 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07003052{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003053 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02003054
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03003055 vlv_phy_pre_pll_enable(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003056}
3057
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003058static void chv_pre_enable_dp(struct intel_encoder *encoder,
3059 struct intel_crtc_state *pipe_config,
3060 struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003061{
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003062 chv_phy_pre_encoder_enable(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003063
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003064 intel_enable_dp(encoder, pipe_config, conn_state);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03003065
3066 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003067 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003068}
3069
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003070static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
3071 struct intel_crtc_state *pipe_config,
3072 struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03003073{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003074 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03003075
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03003076 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03003077}
3078
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003079static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
3080 struct intel_crtc_state *pipe_config,
3081 struct drm_connector_state *conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003082{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03003083 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003084}
3085
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003086/*
3087 * Fetch AUX CH registers 0x202 - 0x207 which contain
3088 * link status information
3089 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003090bool
Keith Packard93f62da2011-11-01 19:45:03 -07003091intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003092{
Lyude9f085eb2016-04-13 10:58:33 -04003093 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
3094 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003095}
3096
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303097static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp)
3098{
3099 uint8_t psr_caps = 0;
3100
Imre Deak9bacd4b2017-05-10 12:21:48 +03003101 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps) != 1)
3102 return false;
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303103 return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED;
3104}
3105
3106static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp)
3107{
3108 uint8_t dprx = 0;
3109
Imre Deak9bacd4b2017-05-10 12:21:48 +03003110 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_DPRX_FEATURE_ENUMERATION_LIST,
3111 &dprx) != 1)
3112 return false;
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303113 return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED;
3114}
3115
Chris Wilsona76f73d2017-01-14 10:51:13 +00003116static bool intel_dp_get_alpm_status(struct intel_dp *intel_dp)
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303117{
3118 uint8_t alpm_caps = 0;
3119
Imre Deak9bacd4b2017-05-10 12:21:48 +03003120 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_RECEIVER_ALPM_CAP,
3121 &alpm_caps) != 1)
3122 return false;
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303123 return alpm_caps & DP_ALPM_CAP;
3124}
3125
Paulo Zanoni11002442014-06-13 18:45:41 -03003126/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003127uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003128intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003129{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003130 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003131 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003132
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003133 if (IS_GEN9_LP(dev_priv))
Vandana Kannan93147262014-11-18 15:45:29 +05303134 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003135 else if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjäläffe51112017-02-23 19:49:01 +02003136 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3137 return intel_ddi_dp_voltage_max(encoder);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003138 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Sonika Jindalbd600182014-08-08 16:23:41 +05303139 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003140 else if (IS_GEN7(dev_priv) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303141 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003142 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303143 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08003144 else
Sonika Jindalbd600182014-08-08 16:23:41 +05303145 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08003146}
3147
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003148uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003149intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3150{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003151 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003152 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003153
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003154 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003155 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3156 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3157 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3158 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3159 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3160 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3161 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303162 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3163 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003164 default:
3165 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3166 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003167 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003168 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303169 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3170 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3171 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3172 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3173 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3174 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3175 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003176 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303177 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003178 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003179 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003180 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303181 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3182 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3183 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3184 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3185 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3186 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3187 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003188 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303189 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003190 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003191 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003192 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303193 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3194 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3195 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3196 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3197 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003198 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303199 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003200 }
3201 } else {
3202 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303203 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3204 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3205 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3206 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3207 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3208 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3209 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003210 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303211 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003212 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003213 }
3214}
3215
Daniel Vetter5829975c2015-04-16 11:36:52 +02003216static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003217{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003218 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003219 unsigned long demph_reg_value, preemph_reg_value,
3220 uniqtranscale_reg_value;
3221 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003222
3223 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303224 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003225 preemph_reg_value = 0x0004000;
3226 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303227 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003228 demph_reg_value = 0x2B405555;
3229 uniqtranscale_reg_value = 0x552AB83A;
3230 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303231 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003232 demph_reg_value = 0x2B404040;
3233 uniqtranscale_reg_value = 0x5548B83A;
3234 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303235 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003236 demph_reg_value = 0x2B245555;
3237 uniqtranscale_reg_value = 0x5560B83A;
3238 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303239 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003240 demph_reg_value = 0x2B405555;
3241 uniqtranscale_reg_value = 0x5598DA3A;
3242 break;
3243 default:
3244 return 0;
3245 }
3246 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303247 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003248 preemph_reg_value = 0x0002000;
3249 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303250 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003251 demph_reg_value = 0x2B404040;
3252 uniqtranscale_reg_value = 0x5552B83A;
3253 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303254 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003255 demph_reg_value = 0x2B404848;
3256 uniqtranscale_reg_value = 0x5580B83A;
3257 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303258 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003259 demph_reg_value = 0x2B404040;
3260 uniqtranscale_reg_value = 0x55ADDA3A;
3261 break;
3262 default:
3263 return 0;
3264 }
3265 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303266 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003267 preemph_reg_value = 0x0000000;
3268 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303269 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003270 demph_reg_value = 0x2B305555;
3271 uniqtranscale_reg_value = 0x5570B83A;
3272 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303273 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003274 demph_reg_value = 0x2B2B4040;
3275 uniqtranscale_reg_value = 0x55ADDA3A;
3276 break;
3277 default:
3278 return 0;
3279 }
3280 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303281 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003282 preemph_reg_value = 0x0006000;
3283 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303284 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003285 demph_reg_value = 0x1B405555;
3286 uniqtranscale_reg_value = 0x55ADDA3A;
3287 break;
3288 default:
3289 return 0;
3290 }
3291 break;
3292 default:
3293 return 0;
3294 }
3295
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003296 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3297 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003298
3299 return 0;
3300}
3301
Daniel Vetter5829975c2015-04-16 11:36:52 +02003302static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003303{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003304 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3305 u32 deemph_reg_value, margin_reg_value;
3306 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003307 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003308
3309 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303310 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003311 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303312 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003313 deemph_reg_value = 128;
3314 margin_reg_value = 52;
3315 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303316 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003317 deemph_reg_value = 128;
3318 margin_reg_value = 77;
3319 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303320 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003321 deemph_reg_value = 128;
3322 margin_reg_value = 102;
3323 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303324 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003325 deemph_reg_value = 128;
3326 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003327 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003328 break;
3329 default:
3330 return 0;
3331 }
3332 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303333 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003334 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303335 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003336 deemph_reg_value = 85;
3337 margin_reg_value = 78;
3338 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303339 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003340 deemph_reg_value = 85;
3341 margin_reg_value = 116;
3342 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303343 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003344 deemph_reg_value = 85;
3345 margin_reg_value = 154;
3346 break;
3347 default:
3348 return 0;
3349 }
3350 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303351 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003352 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303353 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003354 deemph_reg_value = 64;
3355 margin_reg_value = 104;
3356 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303357 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003358 deemph_reg_value = 64;
3359 margin_reg_value = 154;
3360 break;
3361 default:
3362 return 0;
3363 }
3364 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303365 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003366 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303367 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003368 deemph_reg_value = 43;
3369 margin_reg_value = 154;
3370 break;
3371 default:
3372 return 0;
3373 }
3374 break;
3375 default:
3376 return 0;
3377 }
3378
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003379 chv_set_phy_signal_level(encoder, deemph_reg_value,
3380 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003381
3382 return 0;
3383}
3384
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003385static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003386gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003387{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003388 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003389
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003390 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303391 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003392 default:
3393 signal_levels |= DP_VOLTAGE_0_4;
3394 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303395 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003396 signal_levels |= DP_VOLTAGE_0_6;
3397 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303398 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003399 signal_levels |= DP_VOLTAGE_0_8;
3400 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303401 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003402 signal_levels |= DP_VOLTAGE_1_2;
3403 break;
3404 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003405 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303406 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003407 default:
3408 signal_levels |= DP_PRE_EMPHASIS_0;
3409 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303410 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003411 signal_levels |= DP_PRE_EMPHASIS_3_5;
3412 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303413 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003414 signal_levels |= DP_PRE_EMPHASIS_6;
3415 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303416 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003417 signal_levels |= DP_PRE_EMPHASIS_9_5;
3418 break;
3419 }
3420 return signal_levels;
3421}
3422
Zhenyu Wange3421a12010-04-08 09:43:27 +08003423/* Gen6's DP voltage swing and pre-emphasis control */
3424static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003425gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003426{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003427 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3428 DP_TRAIN_PRE_EMPHASIS_MASK);
3429 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303430 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3431 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003432 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303433 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003434 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303435 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3436 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003437 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303438 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3439 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003440 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303441 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3442 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003443 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003444 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003445 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3446 "0x%x\n", signal_levels);
3447 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003448 }
3449}
3450
Keith Packard1a2eb462011-11-16 16:26:07 -08003451/* Gen7's DP voltage swing and pre-emphasis control */
3452static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003453gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003454{
3455 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3456 DP_TRAIN_PRE_EMPHASIS_MASK);
3457 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303458 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003459 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303460 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003461 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303462 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003463 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3464
Sonika Jindalbd600182014-08-08 16:23:41 +05303465 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003466 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303467 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003468 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3469
Sonika Jindalbd600182014-08-08 16:23:41 +05303470 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003471 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303472 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003473 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3474
3475 default:
3476 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3477 "0x%x\n", signal_levels);
3478 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3479 }
3480}
3481
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003482void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003483intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003484{
3485 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003486 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003487 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003488 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003489 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003490 uint8_t train_set = intel_dp->train_set[0];
3491
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003492 if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003493 signal_levels = ddi_signal_levels(intel_dp);
3494
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07003495 if (IS_GEN9_LP(dev_priv) || IS_CANNONLAKE(dev_priv))
David Weinehallf8896f52015-06-25 11:11:03 +03003496 signal_levels = 0;
3497 else
3498 mask = DDI_BUF_EMP_MASK;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003499 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003500 signal_levels = chv_signal_levels(intel_dp);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003501 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003502 signal_levels = vlv_signal_levels(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003503 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003504 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003505 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003506 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003507 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003508 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3509 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003510 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003511 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3512 }
3513
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303514 if (mask)
3515 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3516
3517 DRM_DEBUG_KMS("Using vswing level %d\n",
3518 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3519 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3520 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3521 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003522
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003523 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003524
3525 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3526 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003527}
3528
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003529void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003530intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3531 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003532{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003533 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003534 struct drm_i915_private *dev_priv =
3535 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003536
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003537 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003538
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003539 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003540 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003541}
3542
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003543void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003544{
3545 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3546 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003547 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak3ab9c632013-05-03 12:57:41 +03003548 enum port port = intel_dig_port->port;
3549 uint32_t val;
3550
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003551 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003552 return;
3553
3554 val = I915_READ(DP_TP_CTL(port));
3555 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3556 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3557 I915_WRITE(DP_TP_CTL(port), val);
3558
3559 /*
3560 * On PORT_A we can have only eDP in SST mode. There the only reason
3561 * we need to set idle transmission mode is to work around a HW issue
3562 * where we enable the pipe while not in idle link-training mode.
3563 * In this case there is requirement to wait for a minimum number of
3564 * idle patterns to be sent.
3565 */
3566 if (port == PORT_A)
3567 return;
3568
Chris Wilsona7670172016-06-30 15:33:10 +01003569 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3570 DP_TP_STATUS_IDLE_DONE,
3571 DP_TP_STATUS_IDLE_DONE,
3572 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003573 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3574}
3575
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003576static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003577intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003578{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003579 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003580 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003581 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003582 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003583 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003584 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003585
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003586 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003587 return;
3588
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003589 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003590 return;
3591
Zhao Yakui28c97732009-10-09 11:39:41 +08003592 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003593
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003594 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003595 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003596 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003597 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003598 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003599 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003600 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3601 else
3602 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003603 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003604 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003605 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003606 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003607
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003608 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3609 I915_WRITE(intel_dp->output_reg, DP);
3610 POSTING_READ(intel_dp->output_reg);
3611
3612 /*
3613 * HW workaround for IBX, we need to move the port
3614 * to transcoder A after disabling it to allow the
3615 * matching HDMI port to be enabled on transcoder A.
3616 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003617 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003618 /*
3619 * We get CPU/PCH FIFO underruns on the other pipe when
3620 * doing the workaround. Sweep them under the rug.
3621 */
3622 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3623 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3624
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003625 /* always enable with pattern 1 (as per spec) */
3626 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3627 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3628 I915_WRITE(intel_dp->output_reg, DP);
3629 POSTING_READ(intel_dp->output_reg);
3630
3631 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003632 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003633 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003634
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003635 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003636 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3637 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003638 }
3639
Keith Packardf01eca22011-09-28 16:48:10 -07003640 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003641
3642 intel_dp->DP = DP;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003643
3644 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3645 pps_lock(intel_dp);
3646 intel_dp->active_pipe = INVALID_PIPE;
3647 pps_unlock(intel_dp);
3648 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003649}
3650
Imre Deak24e807e2016-10-24 19:33:28 +03003651bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003652intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003653{
Lyude9f085eb2016-04-13 10:58:33 -04003654 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3655 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003656 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003657
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003658 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003659
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003660 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3661}
3662
3663static bool
3664intel_edp_init_dpcd(struct intel_dp *intel_dp)
3665{
3666 struct drm_i915_private *dev_priv =
3667 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3668
3669 /* this function is meant to be called only once */
3670 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3671
3672 if (!intel_dp_read_dpcd(intel_dp))
3673 return false;
3674
Imre Deak12a47a422016-10-24 19:33:29 +03003675 intel_dp_read_desc(intel_dp);
3676
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003677 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3678 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3679 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3680
3681 /* Check if the panel supports PSR */
3682 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3683 intel_dp->psr_dpcd,
3684 sizeof(intel_dp->psr_dpcd));
3685 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3686 dev_priv->psr.sink_support = true;
3687 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3688 }
3689
3690 if (INTEL_GEN(dev_priv) >= 9 &&
3691 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3692 uint8_t frame_sync_cap;
3693
3694 dev_priv->psr.sink_support = true;
Imre Deak9bacd4b2017-05-10 12:21:48 +03003695 if (drm_dp_dpcd_readb(&intel_dp->aux,
3696 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3697 &frame_sync_cap) != 1)
3698 frame_sync_cap = 0;
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003699 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3700 /* PSR2 needs frame sync as well */
3701 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3702 DRM_DEBUG_KMS("PSR2 %s on sink",
3703 dev_priv->psr.psr2_support ? "supported" : "not supported");
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303704
3705 if (dev_priv->psr.psr2_support) {
3706 dev_priv->psr.y_cord_support =
3707 intel_dp_get_y_cord_status(intel_dp);
3708 dev_priv->psr.colorimetry_support =
3709 intel_dp_get_colorimetry_status(intel_dp);
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303710 dev_priv->psr.alpm =
3711 intel_dp_get_alpm_status(intel_dp);
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303712 }
3713
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003714 }
3715
3716 /* Read the eDP Display control capabilities registers */
3717 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
3718 drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003719 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3720 sizeof(intel_dp->edp_dpcd))
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003721 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3722 intel_dp->edp_dpcd);
3723
3724 /* Intermediate frequency support */
3725 if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */
3726 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3727 int i;
3728
3729 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3730 sink_rates, sizeof(sink_rates));
3731
3732 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3733 int val = le16_to_cpu(sink_rates[i]);
3734
3735 if (val == 0)
3736 break;
3737
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -08003738 /* Value read multiplied by 200kHz gives the per-lane
3739 * link rate in kHz. The source rates are, however,
3740 * stored in terms of LS_Clk kHz. The full conversion
3741 * back to symbols is
3742 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
3743 */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003744 intel_dp->sink_rates[i] = (val * 200) / 10;
3745 }
3746 intel_dp->num_sink_rates = i;
3747 }
3748
Jani Nikula68f357c2017-03-28 17:59:05 +03003749 if (intel_dp->num_sink_rates)
3750 intel_dp->use_rate_select = true;
3751 else
3752 intel_dp_set_sink_rates(intel_dp);
3753
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003754 intel_dp_set_common_rates(intel_dp);
3755
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003756 return true;
3757}
3758
3759
3760static bool
3761intel_dp_get_dpcd(struct intel_dp *intel_dp)
3762{
Jani Nikula27dbefb2017-04-06 16:44:17 +03003763 u8 sink_count;
3764
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003765 if (!intel_dp_read_dpcd(intel_dp))
3766 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003767
Jani Nikula68f357c2017-03-28 17:59:05 +03003768 /* Don't clobber cached eDP rates. */
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003769 if (!is_edp(intel_dp)) {
Jani Nikula68f357c2017-03-28 17:59:05 +03003770 intel_dp_set_sink_rates(intel_dp);
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003771 intel_dp_set_common_rates(intel_dp);
3772 }
Jani Nikula68f357c2017-03-28 17:59:05 +03003773
Jani Nikula27dbefb2017-04-06 16:44:17 +03003774 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_SINK_COUNT, &sink_count) <= 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303775 return false;
3776
3777 /*
3778 * Sink count can change between short pulse hpd hence
3779 * a member variable in intel_dp will track any changes
3780 * between short pulse interrupts.
3781 */
Jani Nikula27dbefb2017-04-06 16:44:17 +03003782 intel_dp->sink_count = DP_GET_SINK_COUNT(sink_count);
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303783
3784 /*
3785 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3786 * a dongle is present but no display. Unless we require to know
3787 * if a dongle is present or not, we don't need to update
3788 * downstream port information. So, an early return here saves
3789 * time from performing other operations which are not required.
3790 */
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05303791 if (!is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303792 return false;
3793
Imre Deakc726ad02016-10-24 19:33:24 +03003794 if (!drm_dp_is_branch(intel_dp->dpcd))
Adam Jacksonedb39242012-09-18 10:58:49 -04003795 return true; /* native DP sink */
3796
3797 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3798 return true; /* no per-port downstream info */
3799
Lyude9f085eb2016-04-13 10:58:33 -04003800 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3801 intel_dp->downstream_ports,
3802 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003803 return false; /* downstream port status fetch failed */
3804
3805 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003806}
3807
Dave Airlie0e32b392014-05-02 14:02:48 +10003808static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003809intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003810{
Jani Nikula010b9b32017-04-06 16:44:16 +03003811 u8 mstm_cap;
Dave Airlie0e32b392014-05-02 14:02:48 +10003812
Nathan Schulte7cc96132016-03-15 10:14:05 -05003813 if (!i915.enable_dp_mst)
3814 return false;
3815
Dave Airlie0e32b392014-05-02 14:02:48 +10003816 if (!intel_dp->can_mst)
3817 return false;
3818
3819 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3820 return false;
3821
Jani Nikula010b9b32017-04-06 16:44:16 +03003822 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_MSTM_CAP, &mstm_cap) != 1)
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003823 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003824
Jani Nikula010b9b32017-04-06 16:44:16 +03003825 return mstm_cap & DP_MST_CAP;
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003826}
3827
3828static void
3829intel_dp_configure_mst(struct intel_dp *intel_dp)
3830{
3831 if (!i915.enable_dp_mst)
3832 return;
3833
3834 if (!intel_dp->can_mst)
3835 return;
3836
3837 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3838
3839 if (intel_dp->is_mst)
3840 DRM_DEBUG_KMS("Sink is MST capable\n");
3841 else
3842 DRM_DEBUG_KMS("Sink is not MST capable\n");
3843
3844 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3845 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003846}
3847
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003848static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003849{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003850 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003851 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003852 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003853 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003854 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003855 int count = 0;
3856 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003857
3858 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003859 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003860 ret = -EIO;
3861 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003862 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003863
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003864 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003865 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003866 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003867 ret = -EIO;
3868 goto out;
3869 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003870
Rodrigo Vivic6297842015-11-05 10:50:20 -08003871 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003872 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivic6297842015-11-05 10:50:20 -08003873
3874 if (drm_dp_dpcd_readb(&intel_dp->aux,
3875 DP_TEST_SINK_MISC, &buf) < 0) {
3876 ret = -EIO;
3877 goto out;
3878 }
3879 count = buf & DP_TEST_COUNT_MASK;
3880 } while (--attempts && count);
3881
3882 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003883 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003884 ret = -ETIMEDOUT;
3885 }
3886
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003887 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003888 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003889 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003890}
3891
3892static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3893{
3894 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003895 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003896 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3897 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003898 int ret;
3899
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003900 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3901 return -EIO;
3902
3903 if (!(buf & DP_TEST_CRC_SUPPORTED))
3904 return -ENOTTY;
3905
3906 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3907 return -EIO;
3908
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003909 if (buf & DP_TEST_SINK_START) {
3910 ret = intel_dp_sink_crc_stop(intel_dp);
3911 if (ret)
3912 return ret;
3913 }
3914
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003915 hsw_disable_ips(intel_crtc);
3916
3917 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3918 buf | DP_TEST_SINK_START) < 0) {
3919 hsw_enable_ips(intel_crtc);
3920 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003921 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003922
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003923 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003924 return 0;
3925}
3926
3927int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3928{
3929 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003930 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003931 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3932 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003933 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003934 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003935
3936 ret = intel_dp_sink_crc_start(intel_dp);
3937 if (ret)
3938 return ret;
3939
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003940 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003941 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003942
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003943 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003944 DP_TEST_SINK_MISC, &buf) < 0) {
3945 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003946 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003947 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003948 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07003949
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003950 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003951
3952 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003953 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
3954 ret = -ETIMEDOUT;
3955 goto stop;
3956 }
3957
3958 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
3959 ret = -EIO;
3960 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003961 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003962
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003963stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003964 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003965 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003966}
3967
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003968static bool
3969intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3970{
Jani Nikula010b9b32017-04-06 16:44:16 +03003971 return drm_dp_dpcd_readb(&intel_dp->aux, DP_DEVICE_SERVICE_IRQ_VECTOR,
3972 sink_irq_vector) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003973}
3974
Dave Airlie0e32b392014-05-02 14:02:48 +10003975static bool
3976intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3977{
3978 int ret;
3979
Lyude9f085eb2016-04-13 10:58:33 -04003980 ret = drm_dp_dpcd_read(&intel_dp->aux,
Dave Airlie0e32b392014-05-02 14:02:48 +10003981 DP_SINK_COUNT_ESI,
3982 sink_irq_vector, 14);
3983 if (ret != 14)
3984 return false;
3985
3986 return true;
3987}
3988
Todd Previtec5d5ab72015-04-15 08:38:38 -07003989static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003990{
Manasi Navareda15f7c2017-01-24 08:16:34 -08003991 int status = 0;
3992 int min_lane_count = 1;
Manasi Navareda15f7c2017-01-24 08:16:34 -08003993 int link_rate_index, test_link_rate;
3994 uint8_t test_lane_count, test_link_bw;
3995 /* (DP CTS 1.2)
3996 * 4.3.1.11
3997 */
3998 /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */
3999 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT,
4000 &test_lane_count);
4001
4002 if (status <= 0) {
4003 DRM_DEBUG_KMS("Lane count read failed\n");
4004 return DP_TEST_NAK;
4005 }
4006 test_lane_count &= DP_MAX_LANE_COUNT_MASK;
4007 /* Validate the requested lane count */
4008 if (test_lane_count < min_lane_count ||
Jani Nikulae6c0c642017-04-06 16:44:12 +03004009 test_lane_count > intel_dp->max_link_lane_count)
Manasi Navareda15f7c2017-01-24 08:16:34 -08004010 return DP_TEST_NAK;
4011
4012 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE,
4013 &test_link_bw);
4014 if (status <= 0) {
4015 DRM_DEBUG_KMS("Link Rate read failed\n");
4016 return DP_TEST_NAK;
4017 }
4018 /* Validate the requested link rate */
4019 test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw);
Jani Nikulab1810a72017-04-06 16:44:11 +03004020 link_rate_index = intel_dp_rate_index(intel_dp->common_rates,
4021 intel_dp->num_common_rates,
4022 test_link_rate);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004023 if (link_rate_index < 0)
4024 return DP_TEST_NAK;
4025
4026 intel_dp->compliance.test_lane_count = test_lane_count;
4027 intel_dp->compliance.test_link_rate = test_link_rate;
4028
4029 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004030}
4031
4032static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
4033{
Manasi Navare611032b2017-01-24 08:21:49 -08004034 uint8_t test_pattern;
Jani Nikula010b9b32017-04-06 16:44:16 +03004035 uint8_t test_misc;
Manasi Navare611032b2017-01-24 08:21:49 -08004036 __be16 h_width, v_height;
4037 int status = 0;
4038
4039 /* Read the TEST_PATTERN (DP CTS 3.1.5) */
Jani Nikula010b9b32017-04-06 16:44:16 +03004040 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_PATTERN,
4041 &test_pattern);
Manasi Navare611032b2017-01-24 08:21:49 -08004042 if (status <= 0) {
4043 DRM_DEBUG_KMS("Test pattern read failed\n");
4044 return DP_TEST_NAK;
4045 }
4046 if (test_pattern != DP_COLOR_RAMP)
4047 return DP_TEST_NAK;
4048
4049 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI,
4050 &h_width, 2);
4051 if (status <= 0) {
4052 DRM_DEBUG_KMS("H Width read failed\n");
4053 return DP_TEST_NAK;
4054 }
4055
4056 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI,
4057 &v_height, 2);
4058 if (status <= 0) {
4059 DRM_DEBUG_KMS("V Height read failed\n");
4060 return DP_TEST_NAK;
4061 }
4062
Jani Nikula010b9b32017-04-06 16:44:16 +03004063 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_MISC0,
4064 &test_misc);
Manasi Navare611032b2017-01-24 08:21:49 -08004065 if (status <= 0) {
4066 DRM_DEBUG_KMS("TEST MISC read failed\n");
4067 return DP_TEST_NAK;
4068 }
4069 if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB)
4070 return DP_TEST_NAK;
4071 if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA)
4072 return DP_TEST_NAK;
4073 switch (test_misc & DP_TEST_BIT_DEPTH_MASK) {
4074 case DP_TEST_BIT_DEPTH_6:
4075 intel_dp->compliance.test_data.bpc = 6;
4076 break;
4077 case DP_TEST_BIT_DEPTH_8:
4078 intel_dp->compliance.test_data.bpc = 8;
4079 break;
4080 default:
4081 return DP_TEST_NAK;
4082 }
4083
4084 intel_dp->compliance.test_data.video_pattern = test_pattern;
4085 intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width);
4086 intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height);
4087 /* Set test active flag here so userspace doesn't interrupt things */
4088 intel_dp->compliance.test_active = 1;
4089
4090 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004091}
4092
4093static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
4094{
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004095 uint8_t test_result = DP_TEST_ACK;
Todd Previte559be302015-05-04 07:48:20 -07004096 struct intel_connector *intel_connector = intel_dp->attached_connector;
4097 struct drm_connector *connector = &intel_connector->base;
4098
4099 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02004100 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07004101 intel_dp->aux.i2c_defer_count > 6) {
4102 /* Check EDID read for NACKs, DEFERs and corruption
4103 * (DP CTS 1.2 Core r1.1)
4104 * 4.2.2.4 : Failed EDID read, I2C_NAK
4105 * 4.2.2.5 : Failed EDID read, I2C_DEFER
4106 * 4.2.2.6 : EDID corruption detected
4107 * Use failsafe mode for all cases
4108 */
4109 if (intel_dp->aux.i2c_nack_count > 0 ||
4110 intel_dp->aux.i2c_defer_count > 0)
4111 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
4112 intel_dp->aux.i2c_nack_count,
4113 intel_dp->aux.i2c_defer_count);
Manasi Navarec1617ab2016-12-09 16:22:50 -08004114 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
Todd Previte559be302015-05-04 07:48:20 -07004115 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05304116 struct edid *block = intel_connector->detect_edid;
4117
4118 /* We have to write the checksum
4119 * of the last block read
4120 */
4121 block += intel_connector->detect_edid->extensions;
4122
Jani Nikula010b9b32017-04-06 16:44:16 +03004123 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_EDID_CHECKSUM,
4124 block->checksum) <= 0)
Todd Previte559be302015-05-04 07:48:20 -07004125 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
4126
4127 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004128 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED;
Todd Previte559be302015-05-04 07:48:20 -07004129 }
4130
4131 /* Set test active flag here so userspace doesn't interrupt things */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004132 intel_dp->compliance.test_active = 1;
Todd Previte559be302015-05-04 07:48:20 -07004133
Todd Previtec5d5ab72015-04-15 08:38:38 -07004134 return test_result;
4135}
4136
4137static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
4138{
4139 uint8_t test_result = DP_TEST_NAK;
4140 return test_result;
4141}
4142
4143static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
4144{
4145 uint8_t response = DP_TEST_NAK;
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004146 uint8_t request = 0;
4147 int status;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004148
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004149 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004150 if (status <= 0) {
4151 DRM_DEBUG_KMS("Could not read test request from sink\n");
4152 goto update_status;
4153 }
4154
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004155 switch (request) {
Todd Previtec5d5ab72015-04-15 08:38:38 -07004156 case DP_TEST_LINK_TRAINING:
4157 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004158 response = intel_dp_autotest_link_training(intel_dp);
4159 break;
4160 case DP_TEST_LINK_VIDEO_PATTERN:
4161 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004162 response = intel_dp_autotest_video_pattern(intel_dp);
4163 break;
4164 case DP_TEST_LINK_EDID_READ:
4165 DRM_DEBUG_KMS("EDID test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004166 response = intel_dp_autotest_edid(intel_dp);
4167 break;
4168 case DP_TEST_LINK_PHY_TEST_PATTERN:
4169 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004170 response = intel_dp_autotest_phy_pattern(intel_dp);
4171 break;
4172 default:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004173 DRM_DEBUG_KMS("Invalid test request '%02x'\n", request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004174 break;
4175 }
4176
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004177 if (response & DP_TEST_ACK)
4178 intel_dp->compliance.test_type = request;
4179
Todd Previtec5d5ab72015-04-15 08:38:38 -07004180update_status:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004181 status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004182 if (status <= 0)
4183 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004184}
4185
Dave Airlie0e32b392014-05-02 14:02:48 +10004186static int
4187intel_dp_check_mst_status(struct intel_dp *intel_dp)
4188{
4189 bool bret;
4190
4191 if (intel_dp->is_mst) {
4192 u8 esi[16] = { 0 };
4193 int ret = 0;
4194 int retry;
4195 bool handled;
4196 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4197go_again:
4198 if (bret == true) {
4199
4200 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03004201 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03004202 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10004203 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4204 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004205 intel_dp_stop_link_train(intel_dp);
4206 }
4207
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004208 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004209 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4210
4211 if (handled) {
4212 for (retry = 0; retry < 3; retry++) {
4213 int wret;
4214 wret = drm_dp_dpcd_write(&intel_dp->aux,
4215 DP_SINK_COUNT_ESI+1,
4216 &esi[1], 3);
4217 if (wret == 3) {
4218 break;
4219 }
4220 }
4221
4222 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4223 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004224 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004225 goto go_again;
4226 }
4227 } else
4228 ret = 0;
4229
4230 return ret;
4231 } else {
4232 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4233 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4234 intel_dp->is_mst = false;
4235 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4236 /* send a hotplug event */
4237 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4238 }
4239 }
4240 return -EINVAL;
4241}
4242
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304243static void
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004244intel_dp_retrain_link(struct intel_dp *intel_dp)
4245{
4246 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4247 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4248 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
4249
4250 /* Suppress underruns caused by re-training */
4251 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4252 if (crtc->config->has_pch_encoder)
4253 intel_set_pch_fifo_underrun_reporting(dev_priv,
4254 intel_crtc_pch_transcoder(crtc), false);
4255
4256 intel_dp_start_link_train(intel_dp);
4257 intel_dp_stop_link_train(intel_dp);
4258
4259 /* Keep underrun reporting disabled until things are stable */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02004260 intel_wait_for_vblank(dev_priv, crtc->pipe);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004261
4262 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4263 if (crtc->config->has_pch_encoder)
4264 intel_set_pch_fifo_underrun_reporting(dev_priv,
4265 intel_crtc_pch_transcoder(crtc), true);
4266}
4267
4268static void
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304269intel_dp_check_link_status(struct intel_dp *intel_dp)
4270{
4271 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4272 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4273 u8 link_status[DP_LINK_STATUS_SIZE];
4274
4275 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
4276
4277 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4278 DRM_ERROR("Failed to get link status\n");
4279 return;
4280 }
4281
4282 if (!intel_encoder->base.crtc)
4283 return;
4284
4285 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4286 return;
4287
Manasi Navare14c562c2017-04-06 14:00:12 -07004288 /*
4289 * Validate the cached values of intel_dp->link_rate and
4290 * intel_dp->lane_count before attempting to retrain.
4291 */
4292 if (!intel_dp_link_params_valid(intel_dp))
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004293 return;
4294
Manasi Navareda15f7c2017-01-24 08:16:34 -08004295 /* Retrain if Channel EQ or CR not ok */
4296 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304297 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4298 intel_encoder->base.name);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004299
4300 intel_dp_retrain_link(intel_dp);
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304301 }
4302}
4303
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004304/*
4305 * According to DP spec
4306 * 5.1.2:
4307 * 1. Read DPCD
4308 * 2. Configure link according to Receiver Capabilities
4309 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4310 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304311 *
4312 * intel_dp_short_pulse - handles short pulse interrupts
4313 * when full detection is not required.
4314 * Returns %true if short pulse is handled and full detection
4315 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004316 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304317static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304318intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004319{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004320 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004321 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004322 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304323 u8 old_sink_count = intel_dp->sink_count;
4324 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004325
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304326 /*
4327 * Clearing compliance test variables to allow capturing
4328 * of values for next automated test request.
4329 */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004330 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304331
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304332 /*
4333 * Now read the DPCD to see if it's actually running
4334 * If the current value of sink count doesn't match with
4335 * the value that was stored earlier or dpcd read failed
4336 * we need to do full detection
4337 */
4338 ret = intel_dp_get_dpcd(intel_dp);
4339
4340 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4341 /* No need to proceed if we are going to do full detect */
4342 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004343 }
4344
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004345 /* Try to read the source of the interrupt */
4346 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004347 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4348 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004349 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004350 drm_dp_dpcd_writeb(&intel_dp->aux,
4351 DP_DEVICE_SERVICE_IRQ_VECTOR,
4352 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004353
4354 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Manasi Navareda15f7c2017-01-24 08:16:34 -08004355 intel_dp_handle_test_request(intel_dp);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004356 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4357 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4358 }
4359
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304360 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4361 intel_dp_check_link_status(intel_dp);
4362 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004363 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
4364 DRM_DEBUG_KMS("Link Training Compliance Test requested\n");
4365 /* Send a Hotplug Uevent to userspace to start modeset */
4366 drm_kms_helper_hotplug_event(intel_encoder->base.dev);
4367 }
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304368
4369 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004370}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004371
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004372/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004373static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004374intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004375{
Imre Deake393d0d2017-02-22 17:10:52 +02004376 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004377 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004378 uint8_t type;
4379
Imre Deake393d0d2017-02-22 17:10:52 +02004380 if (lspcon->active)
4381 lspcon_resume(lspcon);
4382
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004383 if (!intel_dp_get_dpcd(intel_dp))
4384 return connector_status_disconnected;
4385
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304386 if (is_edp(intel_dp))
4387 return connector_status_connected;
4388
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004389 /* if there's no downstream port, we're done */
Imre Deakc726ad02016-10-24 19:33:24 +03004390 if (!drm_dp_is_branch(dpcd))
Keith Packard26d61aa2011-07-25 20:01:09 -07004391 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004392
4393 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004394 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4395 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004396
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304397 return intel_dp->sink_count ?
4398 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004399 }
4400
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004401 if (intel_dp_can_mst(intel_dp))
4402 return connector_status_connected;
4403
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004404 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004405 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004406 return connector_status_connected;
4407
4408 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004409 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4410 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4411 if (type == DP_DS_PORT_TYPE_VGA ||
4412 type == DP_DS_PORT_TYPE_NON_EDID)
4413 return connector_status_unknown;
4414 } else {
4415 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4416 DP_DWN_STRM_PORT_TYPE_MASK;
4417 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4418 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4419 return connector_status_unknown;
4420 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004421
4422 /* Anything else is out of spec, warn and ignore */
4423 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004424 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004425}
4426
4427static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004428edp_detect(struct intel_dp *intel_dp)
4429{
4430 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Mika Kahola1650be72016-12-13 10:02:47 +02004431 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsond410b562014-09-02 20:03:59 +01004432 enum drm_connector_status status;
4433
Mika Kahola1650be72016-12-13 10:02:47 +02004434 status = intel_panel_detect(dev_priv);
Chris Wilsond410b562014-09-02 20:03:59 +01004435 if (status == connector_status_unknown)
4436 status = connector_status_connected;
4437
4438 return status;
4439}
4440
Jani Nikulab93433c2015-08-20 10:47:36 +03004441static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4442 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004443{
Jani Nikulab93433c2015-08-20 10:47:36 +03004444 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004445
Jani Nikula0df53b72015-08-20 10:47:40 +03004446 switch (port->port) {
Jani Nikula0df53b72015-08-20 10:47:40 +03004447 case PORT_B:
4448 bit = SDE_PORTB_HOTPLUG;
4449 break;
4450 case PORT_C:
4451 bit = SDE_PORTC_HOTPLUG;
4452 break;
4453 case PORT_D:
4454 bit = SDE_PORTD_HOTPLUG;
4455 break;
4456 default:
4457 MISSING_CASE(port->port);
4458 return false;
4459 }
4460
4461 return I915_READ(SDEISR) & bit;
4462}
4463
4464static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4465 struct intel_digital_port *port)
4466{
4467 u32 bit;
4468
4469 switch (port->port) {
Jani Nikula0df53b72015-08-20 10:47:40 +03004470 case PORT_B:
4471 bit = SDE_PORTB_HOTPLUG_CPT;
4472 break;
4473 case PORT_C:
4474 bit = SDE_PORTC_HOTPLUG_CPT;
4475 break;
4476 case PORT_D:
4477 bit = SDE_PORTD_HOTPLUG_CPT;
4478 break;
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004479 default:
4480 MISSING_CASE(port->port);
4481 return false;
4482 }
4483
4484 return I915_READ(SDEISR) & bit;
4485}
4486
4487static bool spt_digital_port_connected(struct drm_i915_private *dev_priv,
4488 struct intel_digital_port *port)
4489{
4490 u32 bit;
4491
4492 switch (port->port) {
4493 case PORT_A:
4494 bit = SDE_PORTA_HOTPLUG_SPT;
4495 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004496 case PORT_E:
4497 bit = SDE_PORTE_HOTPLUG_SPT;
4498 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004499 default:
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004500 return cpt_digital_port_connected(dev_priv, port);
Jani Nikulab93433c2015-08-20 10:47:36 +03004501 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004502
Jani Nikulab93433c2015-08-20 10:47:36 +03004503 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004504}
4505
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004506static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004507 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004508{
Jani Nikula9642c812015-08-20 10:47:41 +03004509 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004510
Jani Nikula9642c812015-08-20 10:47:41 +03004511 switch (port->port) {
4512 case PORT_B:
4513 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4514 break;
4515 case PORT_C:
4516 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4517 break;
4518 case PORT_D:
4519 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4520 break;
4521 default:
4522 MISSING_CASE(port->port);
4523 return false;
4524 }
4525
4526 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4527}
4528
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004529static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4530 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004531{
4532 u32 bit;
4533
4534 switch (port->port) {
4535 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004536 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004537 break;
4538 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004539 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004540 break;
4541 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004542 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004543 break;
4544 default:
4545 MISSING_CASE(port->port);
4546 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004547 }
4548
Jani Nikula1d245982015-08-20 10:47:37 +03004549 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004550}
4551
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004552static bool ilk_digital_port_connected(struct drm_i915_private *dev_priv,
4553 struct intel_digital_port *port)
4554{
4555 if (port->port == PORT_A)
4556 return I915_READ(DEISR) & DE_DP_A_HOTPLUG;
4557 else
4558 return ibx_digital_port_connected(dev_priv, port);
4559}
4560
4561static bool snb_digital_port_connected(struct drm_i915_private *dev_priv,
4562 struct intel_digital_port *port)
4563{
4564 if (port->port == PORT_A)
4565 return I915_READ(DEISR) & DE_DP_A_HOTPLUG;
4566 else
4567 return cpt_digital_port_connected(dev_priv, port);
4568}
4569
4570static bool ivb_digital_port_connected(struct drm_i915_private *dev_priv,
4571 struct intel_digital_port *port)
4572{
4573 if (port->port == PORT_A)
4574 return I915_READ(DEISR) & DE_DP_A_HOTPLUG_IVB;
4575 else
4576 return cpt_digital_port_connected(dev_priv, port);
4577}
4578
4579static bool bdw_digital_port_connected(struct drm_i915_private *dev_priv,
4580 struct intel_digital_port *port)
4581{
4582 if (port->port == PORT_A)
4583 return I915_READ(GEN8_DE_PORT_ISR) & GEN8_PORT_DP_A_HOTPLUG;
4584 else
4585 return cpt_digital_port_connected(dev_priv, port);
4586}
4587
Jani Nikulae464bfd2015-08-20 10:47:42 +03004588static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304589 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004590{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304591 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4592 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004593 u32 bit;
4594
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304595 intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port);
4596 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004597 case PORT_A:
4598 bit = BXT_DE_PORT_HP_DDIA;
4599 break;
4600 case PORT_B:
4601 bit = BXT_DE_PORT_HP_DDIB;
4602 break;
4603 case PORT_C:
4604 bit = BXT_DE_PORT_HP_DDIC;
4605 break;
4606 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304607 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004608 return false;
4609 }
4610
4611 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4612}
4613
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004614/*
4615 * intel_digital_port_connected - is the specified port connected?
4616 * @dev_priv: i915 private structure
4617 * @port: the port to test
4618 *
4619 * Return %true if @port is connected, %false otherwise.
4620 */
Imre Deak390b4e02017-01-27 11:39:19 +02004621bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
4622 struct intel_digital_port *port)
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004623{
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004624 if (HAS_GMCH_DISPLAY(dev_priv)) {
4625 if (IS_GM45(dev_priv))
4626 return gm45_digital_port_connected(dev_priv, port);
4627 else
4628 return g4x_digital_port_connected(dev_priv, port);
4629 }
4630
4631 if (IS_GEN5(dev_priv))
4632 return ilk_digital_port_connected(dev_priv, port);
4633 else if (IS_GEN6(dev_priv))
4634 return snb_digital_port_connected(dev_priv, port);
4635 else if (IS_GEN7(dev_priv))
4636 return ivb_digital_port_connected(dev_priv, port);
4637 else if (IS_GEN8(dev_priv))
4638 return bdw_digital_port_connected(dev_priv, port);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004639 else if (IS_GEN9_LP(dev_priv))
Jani Nikulae464bfd2015-08-20 10:47:42 +03004640 return bxt_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004641 else
Ville Syrjälä93e5f0b2017-06-15 20:12:52 +03004642 return spt_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004643}
4644
Keith Packard8c241fe2011-09-28 16:38:44 -07004645static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004646intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004647{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004648 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004649
Jani Nikula9cd300e2012-10-19 14:51:52 +03004650 /* use cached edid if we have one */
4651 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004652 /* invalid edid */
4653 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004654 return NULL;
4655
Jani Nikula55e9ede2013-10-01 10:38:54 +03004656 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004657 } else
4658 return drm_get_edid(&intel_connector->base,
4659 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004660}
4661
Chris Wilsonbeb60602014-09-02 20:04:00 +01004662static void
4663intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004664{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004665 struct intel_connector *intel_connector = intel_dp->attached_connector;
4666 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004667
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304668 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004669 edid = intel_dp_get_edid(intel_dp);
4670 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004671
Maarten Lankhorste6b72c92017-05-01 15:38:00 +02004672 intel_dp->has_audio = drm_detect_monitor_audio(edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004673}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004674
Chris Wilsonbeb60602014-09-02 20:04:00 +01004675static void
4676intel_dp_unset_edid(struct intel_dp *intel_dp)
4677{
4678 struct intel_connector *intel_connector = intel_dp->attached_connector;
4679
4680 kfree(intel_connector->detect_edid);
4681 intel_connector->detect_edid = NULL;
4682
4683 intel_dp->has_audio = false;
4684}
4685
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004686static int
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304687intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004688{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304689 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004690 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004691 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4692 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004693 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004694 enum drm_connector_status status;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004695 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004696
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004697 WARN_ON(!drm_modeset_is_locked(&connector->dev->mode_config.connection_mutex));
4698
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004699 intel_display_power_get(to_i915(dev), intel_dp->aux_power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004700
Chris Wilsond410b562014-09-02 20:03:59 +01004701 /* Can't disconnect eDP, but you can close the lid... */
4702 if (is_edp(intel_dp))
4703 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004704 else if (intel_digital_port_connected(to_i915(dev),
4705 dp_to_dig_port(intel_dp)))
4706 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004707 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004708 status = connector_status_disconnected;
4709
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004710 if (status == connector_status_disconnected) {
Manasi Navarec1617ab2016-12-09 16:22:50 -08004711 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304712
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004713 if (intel_dp->is_mst) {
4714 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4715 intel_dp->is_mst,
4716 intel_dp->mst_mgr.mst_state);
4717 intel_dp->is_mst = false;
4718 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4719 intel_dp->is_mst);
4720 }
4721
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004722 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304723 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004724
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304725 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004726 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304727
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004728 DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
4729 yesno(intel_dp_source_supports_hbr2(intel_dp)),
4730 yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
4731
Manasi Navared7e8ef02017-02-07 16:54:11 -08004732 if (intel_dp->reset_link_params) {
Jani Nikula540b0b7f2017-04-06 16:44:13 +03004733 /* Initial max link lane count */
4734 intel_dp->max_link_lane_count = intel_dp_max_common_lane_count(intel_dp);
Manasi Navaref4829842016-12-05 16:27:36 -08004735
Jani Nikula540b0b7f2017-04-06 16:44:13 +03004736 /* Initial max link rate */
4737 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
Manasi Navared7e8ef02017-02-07 16:54:11 -08004738
4739 intel_dp->reset_link_params = false;
4740 }
Manasi Navaref4829842016-12-05 16:27:36 -08004741
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004742 intel_dp_print_rates(intel_dp);
4743
Imre Deak7b3fc172016-10-25 16:12:39 +03004744 intel_dp_read_desc(intel_dp);
Mika Kahola0e390a32016-09-09 14:10:53 +03004745
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004746 intel_dp_configure_mst(intel_dp);
4747
4748 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304749 /*
4750 * If we are in MST mode then this connector
4751 * won't appear connected or have anything
4752 * with EDID on it
4753 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004754 status = connector_status_disconnected;
4755 goto out;
Ville Syrjälä1a361472017-04-12 22:30:17 +03004756 } else {
4757 /*
4758 * If display is now connected check links status,
4759 * there has been known issues of link loss triggerring
4760 * long pulse.
4761 *
4762 * Some sinks (eg. ASUS PB287Q) seem to perform some
4763 * weird HPD ping pong during modesets. So we can apparently
4764 * end up with HPD going low during a modeset, and then
4765 * going back up soon after. And once that happens we must
4766 * retrain the link to get a picture. That's in case no
4767 * userspace component reacted to intermittent HPD dip.
4768 */
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304769 intel_dp_check_link_status(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004770 }
4771
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304772 /*
4773 * Clearing NACK and defer counts to get their exact values
4774 * while reading EDID which are required by Compliance tests
4775 * 4.2.2.4 and 4.2.2.5
4776 */
4777 intel_dp->aux.i2c_nack_count = 0;
4778 intel_dp->aux.i2c_defer_count = 0;
4779
Chris Wilsonbeb60602014-09-02 20:04:00 +01004780 intel_dp_set_edid(intel_dp);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004781 if (is_edp(intel_dp) || intel_connector->detect_edid)
4782 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304783 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004784
Todd Previte09b1eb12015-04-20 15:27:34 -07004785 /* Try to read the source of the interrupt */
4786 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004787 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4788 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004789 /* Clear interrupt source */
4790 drm_dp_dpcd_writeb(&intel_dp->aux,
4791 DP_DEVICE_SERVICE_IRQ_VECTOR,
4792 sink_irq_vector);
4793
4794 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4795 intel_dp_handle_test_request(intel_dp);
4796 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4797 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4798 }
4799
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004800out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004801 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304802 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304803
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004804 intel_display_power_put(to_i915(dev), intel_dp->aux_power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004805 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304806}
4807
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004808static int
4809intel_dp_detect(struct drm_connector *connector,
4810 struct drm_modeset_acquire_ctx *ctx,
4811 bool force)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304812{
4813 struct intel_dp *intel_dp = intel_attached_dp(connector);
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004814 int status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304815
4816 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4817 connector->base.id, connector->name);
4818
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304819 /* If full detect is not performed yet, do a full detect */
4820 if (!intel_dp->detect_done)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004821 status = intel_dp_long_pulse(intel_dp->attached_connector);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304822
4823 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304824
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004825 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004826}
4827
Chris Wilsonbeb60602014-09-02 20:04:00 +01004828static void
4829intel_dp_force(struct drm_connector *connector)
4830{
4831 struct intel_dp *intel_dp = intel_attached_dp(connector);
4832 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004833 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004834
4835 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4836 connector->base.id, connector->name);
4837 intel_dp_unset_edid(intel_dp);
4838
4839 if (connector->status != connector_status_connected)
4840 return;
4841
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004842 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004843
4844 intel_dp_set_edid(intel_dp);
4845
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004846 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004847
4848 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004849 intel_encoder->type = INTEL_OUTPUT_DP;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004850}
4851
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004852static int intel_dp_get_modes(struct drm_connector *connector)
4853{
Jani Nikuladd06f902012-10-19 14:51:50 +03004854 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004855 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004856
Chris Wilsonbeb60602014-09-02 20:04:00 +01004857 edid = intel_connector->detect_edid;
4858 if (edid) {
4859 int ret = intel_connector_update_modes(connector, edid);
4860 if (ret)
4861 return ret;
4862 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004863
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004864 /* if eDP has no EDID, fall back to fixed mode */
Chris Wilsonbeb60602014-09-02 20:04:00 +01004865 if (is_edp(intel_attached_dp(connector)) &&
4866 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004867 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004868
4869 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004870 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004871 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004872 drm_mode_probed_add(connector, mode);
4873 return 1;
4874 }
4875 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004876
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004877 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004878}
4879
Chris Wilsonf6849602010-09-19 09:29:33 +01004880static int
Chris Wilson7a418e32016-06-24 14:00:14 +01004881intel_dp_connector_register(struct drm_connector *connector)
4882{
4883 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004884 int ret;
4885
4886 ret = intel_connector_register(connector);
4887 if (ret)
4888 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004889
4890 i915_debugfs_connector_add(connector);
4891
4892 DRM_DEBUG_KMS("registering %s bus for %s\n",
4893 intel_dp->aux.name, connector->kdev->kobj.name);
4894
4895 intel_dp->aux.dev = connector->kdev;
4896 return drm_dp_aux_register(&intel_dp->aux);
4897}
4898
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004899static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004900intel_dp_connector_unregister(struct drm_connector *connector)
4901{
4902 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4903 intel_connector_unregister(connector);
4904}
4905
4906static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004907intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004908{
Jani Nikula1d508702012-10-19 14:51:49 +03004909 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004910
Chris Wilson10e972d2014-09-04 21:43:45 +01004911 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004912
Jani Nikula9cd300e2012-10-19 14:51:52 +03004913 if (!IS_ERR_OR_NULL(intel_connector->edid))
4914 kfree(intel_connector->edid);
4915
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004916 /* Can't call is_edp() since the encoder may have been destroyed
4917 * already. */
4918 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004919 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004920
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004921 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004922 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004923}
4924
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004925void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004926{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004927 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4928 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004929
Dave Airlie0e32b392014-05-02 14:02:48 +10004930 intel_dp_mst_encoder_cleanup(intel_dig_port);
Keith Packardbd943152011-09-18 23:09:52 -07004931 if (is_edp(intel_dp)) {
4932 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004933 /*
4934 * vdd might still be enabled do to the delayed vdd off.
4935 * Make sure vdd is actually turned off here.
4936 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004937 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004938 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004939 pps_unlock(intel_dp);
4940
Clint Taylor01527b32014-07-07 13:01:46 -07004941 if (intel_dp->edp_notifier.notifier_call) {
4942 unregister_reboot_notifier(&intel_dp->edp_notifier);
4943 intel_dp->edp_notifier.notifier_call = NULL;
4944 }
Keith Packardbd943152011-09-18 23:09:52 -07004945 }
Chris Wilson99681882016-06-20 09:29:17 +01004946
4947 intel_dp_aux_fini(intel_dp);
4948
Imre Deakc8bd0e42014-12-12 17:57:38 +02004949 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004950 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004951}
4952
Imre Deakbf93ba62016-04-18 10:04:21 +03004953void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004954{
4955 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4956
4957 if (!is_edp(intel_dp))
4958 return;
4959
Ville Syrjälä951468f2014-09-04 14:55:31 +03004960 /*
4961 * vdd might still be enabled do to the delayed vdd off.
4962 * Make sure vdd is actually turned off here.
4963 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004964 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004965 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004966 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004967 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004968}
4969
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004970static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4971{
4972 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4973 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004974 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004975
4976 lockdep_assert_held(&dev_priv->pps_mutex);
4977
4978 if (!edp_have_panel_vdd(intel_dp))
4979 return;
4980
4981 /*
4982 * The VDD bit needs a power domain reference, so if the bit is
4983 * already enabled when we boot or resume, grab this reference and
4984 * schedule a vdd off, so we don't hold on to the reference
4985 * indefinitely.
4986 */
4987 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004988 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004989
4990 edp_panel_vdd_schedule_off(intel_dp);
4991}
4992
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02004993static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
4994{
4995 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
4996
4997 if ((intel_dp->DP & DP_PORT_EN) == 0)
4998 return INVALID_PIPE;
4999
5000 if (IS_CHERRYVIEW(dev_priv))
5001 return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
5002 else
5003 return PORT_TO_PIPE(intel_dp->DP);
5004}
5005
Imre Deakbf93ba62016-04-18 10:04:21 +03005006void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03005007{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005008 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Imre Deakdd75f6d2016-11-21 21:15:05 +02005009 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
5010 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005011
5012 if (!HAS_DDI(dev_priv))
5013 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005014
Imre Deakdd75f6d2016-11-21 21:15:05 +02005015 if (lspcon->active)
Shashank Sharma910530c2016-10-14 19:56:52 +05305016 lspcon_resume(lspcon);
5017
Manasi Navared7e8ef02017-02-07 16:54:11 -08005018 intel_dp->reset_link_params = true;
5019
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005020 pps_lock(intel_dp);
5021
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005022 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5023 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5024
5025 if (is_edp(intel_dp)) {
5026 /* Reinit the power sequencer, in case BIOS did something with it. */
5027 intel_dp_pps_init(encoder->dev, intel_dp);
5028 intel_edp_panel_vdd_sanitize(intel_dp);
5029 }
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005030
5031 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03005032}
5033
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005034static const struct drm_connector_funcs intel_dp_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02005035 .dpms = drm_atomic_helper_connector_dpms,
Chris Wilsonbeb60602014-09-02 20:04:00 +01005036 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005037 .fill_modes = drm_helper_probe_single_connector_modes,
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02005038 .set_property = drm_atomic_helper_connector_set_property,
5039 .atomic_get_property = intel_digital_connector_atomic_get_property,
5040 .atomic_set_property = intel_digital_connector_atomic_set_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01005041 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01005042 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03005043 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08005044 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02005045 .atomic_duplicate_state = intel_digital_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005046};
5047
5048static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02005049 .detect_ctx = intel_dp_detect,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005050 .get_modes = intel_dp_get_modes,
5051 .mode_valid = intel_dp_mode_valid,
Maarten Lankhorst8f647a02017-05-01 15:38:01 +02005052 .atomic_check = intel_digital_connector_atomic_check,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005053};
5054
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005055static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03005056 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02005057 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005058};
5059
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005060enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10005061intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
5062{
5063 struct intel_dp *intel_dp = &intel_dig_port->dp;
Dave Airlie0e32b392014-05-02 14:02:48 +10005064 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005065 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005066 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03005067
Takashi Iwai25400582015-11-19 12:09:56 +01005068 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
5069 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Ville Syrjäläcca05022016-06-22 21:57:06 +03005070 intel_dig_port->base.type = INTEL_OUTPUT_DP;
Dave Airlie13cf5502014-06-18 11:29:35 +10005071
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005072 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
5073 /*
5074 * vdd off can generate a long pulse on eDP which
5075 * would require vdd on to handle it, and thus we
5076 * would end up in an endless cycle of
5077 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
5078 */
5079 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
5080 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d522015-02-10 14:11:46 +02005081 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005082 }
5083
Ville Syrjälä26fbb772014-08-11 18:37:37 +03005084 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
5085 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10005086 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10005087
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005088 if (long_hpd) {
Manasi Navared7e8ef02017-02-07 16:54:11 -08005089 intel_dp->reset_link_params = true;
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005090 intel_dp->detect_done = false;
5091 return IRQ_NONE;
5092 }
5093
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005094 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005095
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005096 if (intel_dp->is_mst) {
5097 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
5098 /*
5099 * If we were in MST mode, and device is not
5100 * there, get out of MST mode
5101 */
5102 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
5103 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
5104 intel_dp->is_mst = false;
5105 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
5106 intel_dp->is_mst);
5107 intel_dp->detect_done = false;
5108 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10005109 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005110 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005111
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005112 if (!intel_dp->is_mst) {
5113 if (!intel_dp_short_pulse(intel_dp)) {
5114 intel_dp->detect_done = false;
5115 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05305116 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005117 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005118
5119 ret = IRQ_HANDLED;
5120
Imre Deak1c767b32014-08-18 14:42:42 +03005121put_power:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005122 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005123
5124 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10005125}
5126
Rodrigo Vivi477ec322015-08-06 15:51:39 +08005127/* check the VBT to see whether the eDP is on another port */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005128bool intel_dp_is_edp(struct drm_i915_private *dev_priv, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08005129{
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005130 /*
5131 * eDP not supported on g4x. so bail out early just
5132 * for a bit extra safety in case the VBT is bonkers.
5133 */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005134 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005135 return false;
5136
Imre Deaka98d9c12016-12-21 12:17:24 +02005137 if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005138 return true;
5139
Jani Nikula951d9ef2016-03-16 12:43:31 +02005140 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08005141}
5142
Maarten Lankhorst200819a2017-04-10 12:51:10 +02005143static void
Chris Wilsonf6849602010-09-19 09:29:33 +01005144intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
5145{
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005146 struct drm_i915_private *dev_priv = to_i915(connector->dev);
5147
Chris Wilson3f43c482011-05-12 22:17:24 +01005148 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00005149 intel_attach_broadcast_rgb_property(connector);
Yuly Novikov53b41832012-10-26 12:04:00 +03005150
5151 if (is_edp(intel_dp)) {
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005152 u32 allowed_scalers;
5153
5154 allowed_scalers = BIT(DRM_MODE_SCALE_ASPECT) | BIT(DRM_MODE_SCALE_FULLSCREEN);
5155 if (!HAS_GMCH_DISPLAY(dev_priv))
5156 allowed_scalers |= BIT(DRM_MODE_SCALE_CENTER);
5157
5158 drm_connector_attach_scaling_mode_property(connector, allowed_scalers);
5159
Maarten Lankhorsteead06d2017-05-01 15:37:55 +02005160 connector->state->scaling_mode = DRM_MODE_SCALE_ASPECT;
Maarten Lankhorst8b453302017-05-01 15:37:56 +02005161
Yuly Novikov53b41832012-10-26 12:04:00 +03005162 }
Chris Wilsonf6849602010-09-19 09:29:33 +01005163}
5164
Imre Deakdada1a92014-01-29 13:25:41 +02005165static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
5166{
Abhay Kumard28d4732016-01-22 17:39:04 -08005167 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02005168 intel_dp->last_power_on = jiffies;
5169 intel_dp->last_backlight_off = jiffies;
5170}
5171
Daniel Vetter67a54562012-10-20 20:57:45 +02005172static void
Imre Deak54648612016-06-16 16:37:22 +03005173intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
5174 struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02005175{
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305176 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03005177 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07005178
Imre Deak8e8232d2016-06-16 16:37:21 +03005179 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02005180
5181 /* Workaround: Need to write PP_CONTROL with the unlock key as
5182 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305183 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02005184
Imre Deak8e8232d2016-06-16 16:37:21 +03005185 pp_on = I915_READ(regs.pp_on);
5186 pp_off = I915_READ(regs.pp_off);
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005187 if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005188 I915_WRITE(regs.pp_ctrl, pp_ctl);
5189 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305190 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005191
5192 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03005193 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
5194 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005195
Imre Deak54648612016-06-16 16:37:22 +03005196 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
5197 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005198
Imre Deak54648612016-06-16 16:37:22 +03005199 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
5200 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005201
Imre Deak54648612016-06-16 16:37:22 +03005202 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
5203 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005204
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005205 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305206 u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
5207 BXT_POWER_CYCLE_DELAY_SHIFT;
5208 if (tmp > 0)
Imre Deak54648612016-06-16 16:37:22 +03005209 seq->t11_t12 = (tmp - 1) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305210 else
Imre Deak54648612016-06-16 16:37:22 +03005211 seq->t11_t12 = 0;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305212 } else {
Imre Deak54648612016-06-16 16:37:22 +03005213 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02005214 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305215 }
Imre Deak54648612016-06-16 16:37:22 +03005216}
5217
5218static void
Imre Deakde9c1b62016-06-16 20:01:46 +03005219intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
5220{
5221 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5222 state_name,
5223 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
5224}
5225
5226static void
5227intel_pps_verify_state(struct drm_i915_private *dev_priv,
5228 struct intel_dp *intel_dp)
5229{
5230 struct edp_power_seq hw;
5231 struct edp_power_seq *sw = &intel_dp->pps_delays;
5232
5233 intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
5234
5235 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
5236 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
5237 DRM_ERROR("PPS state mismatch\n");
5238 intel_pps_dump_state("sw", sw);
5239 intel_pps_dump_state("hw", &hw);
5240 }
5241}
5242
5243static void
Imre Deak54648612016-06-16 16:37:22 +03005244intel_dp_init_panel_power_sequencer(struct drm_device *dev,
5245 struct intel_dp *intel_dp)
5246{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005247 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak54648612016-06-16 16:37:22 +03005248 struct edp_power_seq cur, vbt, spec,
5249 *final = &intel_dp->pps_delays;
5250
5251 lockdep_assert_held(&dev_priv->pps_mutex);
5252
5253 /* already initialized? */
5254 if (final->t11_t12 != 0)
5255 return;
5256
5257 intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005258
Imre Deakde9c1b62016-06-16 20:01:46 +03005259 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005260
Jani Nikula6aa23e62016-03-24 17:50:20 +02005261 vbt = dev_priv->vbt.edp.pps;
Daniel Vetter67a54562012-10-20 20:57:45 +02005262
5263 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5264 * our hw here, which are all in 100usec. */
5265 spec.t1_t3 = 210 * 10;
5266 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5267 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5268 spec.t10 = 500 * 10;
5269 /* This one is special and actually in units of 100ms, but zero
5270 * based in the hw (so we need to add 100 ms). But the sw vbt
5271 * table multiplies it with 1000 to make it in units of 100usec,
5272 * too. */
5273 spec.t11_t12 = (510 + 100) * 10;
5274
Imre Deakde9c1b62016-06-16 20:01:46 +03005275 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005276
5277 /* Use the max of the register settings and vbt. If both are
5278 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005279#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005280 spec.field : \
5281 max(cur.field, vbt.field))
5282 assign_final(t1_t3);
5283 assign_final(t8);
5284 assign_final(t9);
5285 assign_final(t10);
5286 assign_final(t11_t12);
5287#undef assign_final
5288
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005289#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005290 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5291 intel_dp->backlight_on_delay = get_delay(t8);
5292 intel_dp->backlight_off_delay = get_delay(t9);
5293 intel_dp->panel_power_down_delay = get_delay(t10);
5294 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5295#undef get_delay
5296
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005297 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5298 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5299 intel_dp->panel_power_cycle_delay);
5300
5301 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5302 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005303
5304 /*
5305 * We override the HW backlight delays to 1 because we do manual waits
5306 * on them. For T8, even BSpec recommends doing it. For T9, if we
5307 * don't do this, we'll end up waiting for the backlight off delay
5308 * twice: once when we do the manual sleep, and once when we disable
5309 * the panel and wait for the PP_STATUS bit to become zero.
5310 */
5311 final->t8 = 1;
5312 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005313}
5314
5315static void
5316intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005317 struct intel_dp *intel_dp,
5318 bool force_disable_vdd)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005319{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005320 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07005321 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005322 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005323 struct pps_registers regs;
Ville Syrjäläad933b52014-08-18 22:15:56 +03005324 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005325 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005326
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005327 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005328
Imre Deak8e8232d2016-06-16 16:37:21 +03005329 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005330
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005331 /*
5332 * On some VLV machines the BIOS can leave the VDD
5333 * enabled even on power seqeuencers which aren't
5334 * hooked up to any port. This would mess up the
5335 * power domain tracking the first time we pick
5336 * one of these power sequencers for use since
5337 * edp_panel_vdd_on() would notice that the VDD was
5338 * already on and therefore wouldn't grab the power
5339 * domain reference. Disable VDD first to avoid this.
5340 * This also avoids spuriously turning the VDD on as
5341 * soon as the new power seqeuencer gets initialized.
5342 */
5343 if (force_disable_vdd) {
5344 u32 pp = ironlake_get_pp_control(intel_dp);
5345
5346 WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
5347
5348 if (pp & EDP_FORCE_VDD)
5349 DRM_DEBUG_KMS("VDD already on, disabling first\n");
5350
5351 pp &= ~EDP_FORCE_VDD;
5352
5353 I915_WRITE(regs.pp_ctrl, pp);
5354 }
5355
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005356 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005357 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5358 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005359 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005360 /* Compute the divisor for the pp clock, simply match the Bspec
5361 * formula. */
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005362 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005363 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305364 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
5365 pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
5366 << BXT_POWER_CYCLE_DELAY_SHIFT);
5367 } else {
5368 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5369 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5370 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5371 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005372
5373 /* Haswell doesn't have any port selection bits for the panel
5374 * power sequencer any more. */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005375 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005376 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005377 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005378 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005379 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005380 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005381 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005382 }
5383
Jesse Barnes453c5422013-03-28 09:55:41 -07005384 pp_on |= port_sel;
5385
Imre Deak8e8232d2016-06-16 16:37:21 +03005386 I915_WRITE(regs.pp_on, pp_on);
5387 I915_WRITE(regs.pp_off, pp_off);
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005388 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005389 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305390 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005391 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005392
Daniel Vetter67a54562012-10-20 20:57:45 +02005393 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 +03005394 I915_READ(regs.pp_on),
5395 I915_READ(regs.pp_off),
Rodrigo Vivi938361e2017-06-02 13:06:44 -07005396 (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005397 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5398 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005399}
5400
Imre Deak335f7522016-08-10 14:07:32 +03005401static void intel_dp_pps_init(struct drm_device *dev,
5402 struct intel_dp *intel_dp)
5403{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005404 struct drm_i915_private *dev_priv = to_i915(dev);
5405
5406 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Imre Deak335f7522016-08-10 14:07:32 +03005407 vlv_initial_power_sequencer_setup(intel_dp);
5408 } else {
5409 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005410 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak335f7522016-08-10 14:07:32 +03005411 }
5412}
5413
Vandana Kannanb33a2812015-02-13 15:33:03 +05305414/**
5415 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005416 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005417 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305418 * @refresh_rate: RR to be programmed
5419 *
5420 * This function gets called when refresh rate (RR) has to be changed from
5421 * one frequency to another. Switches can be between high and low RR
5422 * supported by the panel or to any other RR based on media playback (in
5423 * this case, RR value needs to be passed from user space).
5424 *
5425 * The caller of this function needs to take a lock on dev_priv->drrs.
5426 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005427static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
5428 struct intel_crtc_state *crtc_state,
5429 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305430{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305431 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305432 struct intel_digital_port *dig_port = NULL;
5433 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005434 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305435 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305436
5437 if (refresh_rate <= 0) {
5438 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5439 return;
5440 }
5441
Vandana Kannan96178ee2015-01-10 02:25:56 +05305442 if (intel_dp == NULL) {
5443 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305444 return;
5445 }
5446
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005447 /*
Rodrigo Vivie4d59f62014-11-20 02:22:08 -08005448 * FIXME: This needs proper synchronization with psr state for some
5449 * platforms that cannot have PSR and DRRS enabled at the same time.
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005450 */
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305451
Vandana Kannan96178ee2015-01-10 02:25:56 +05305452 dig_port = dp_to_dig_port(intel_dp);
5453 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02005454 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305455
5456 if (!intel_crtc) {
5457 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5458 return;
5459 }
5460
Vandana Kannan96178ee2015-01-10 02:25:56 +05305461 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305462 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5463 return;
5464 }
5465
Vandana Kannan96178ee2015-01-10 02:25:56 +05305466 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5467 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305468 index = DRRS_LOW_RR;
5469
Vandana Kannan96178ee2015-01-10 02:25:56 +05305470 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305471 DRM_DEBUG_KMS(
5472 "DRRS requested for previously set RR...ignoring\n");
5473 return;
5474 }
5475
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005476 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305477 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5478 return;
5479 }
5480
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005481 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305482 switch (index) {
5483 case DRRS_HIGH_RR:
5484 intel_dp_set_m_n(intel_crtc, M1_N1);
5485 break;
5486 case DRRS_LOW_RR:
5487 intel_dp_set_m_n(intel_crtc, M2_N2);
5488 break;
5489 case DRRS_MAX_RR:
5490 default:
5491 DRM_ERROR("Unsupported refreshrate type\n");
5492 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005493 } else if (INTEL_GEN(dev_priv) > 6) {
5494 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005495 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305496
Ville Syrjälä649636e2015-09-22 19:50:01 +03005497 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305498 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005499 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305500 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5501 else
5502 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305503 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005504 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305505 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5506 else
5507 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305508 }
5509 I915_WRITE(reg, val);
5510 }
5511
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305512 dev_priv->drrs.refresh_rate_type = index;
5513
5514 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5515}
5516
Vandana Kannanb33a2812015-02-13 15:33:03 +05305517/**
5518 * intel_edp_drrs_enable - init drrs struct if supported
5519 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005520 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305521 *
5522 * Initializes frontbuffer_bits and drrs.dp
5523 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005524void intel_edp_drrs_enable(struct intel_dp *intel_dp,
5525 struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305526{
5527 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005528 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305529
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005530 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305531 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5532 return;
5533 }
5534
5535 mutex_lock(&dev_priv->drrs.mutex);
5536 if (WARN_ON(dev_priv->drrs.dp)) {
5537 DRM_ERROR("DRRS already enabled\n");
5538 goto unlock;
5539 }
5540
5541 dev_priv->drrs.busy_frontbuffer_bits = 0;
5542
5543 dev_priv->drrs.dp = intel_dp;
5544
5545unlock:
5546 mutex_unlock(&dev_priv->drrs.mutex);
5547}
5548
Vandana Kannanb33a2812015-02-13 15:33:03 +05305549/**
5550 * intel_edp_drrs_disable - Disable DRRS
5551 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005552 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305553 *
5554 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005555void intel_edp_drrs_disable(struct intel_dp *intel_dp,
5556 struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305557{
5558 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005559 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305560
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005561 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305562 return;
5563
5564 mutex_lock(&dev_priv->drrs.mutex);
5565 if (!dev_priv->drrs.dp) {
5566 mutex_unlock(&dev_priv->drrs.mutex);
5567 return;
5568 }
5569
5570 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005571 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5572 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305573
5574 dev_priv->drrs.dp = NULL;
5575 mutex_unlock(&dev_priv->drrs.mutex);
5576
5577 cancel_delayed_work_sync(&dev_priv->drrs.work);
5578}
5579
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305580static void intel_edp_drrs_downclock_work(struct work_struct *work)
5581{
5582 struct drm_i915_private *dev_priv =
5583 container_of(work, typeof(*dev_priv), drrs.work.work);
5584 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305585
Vandana Kannan96178ee2015-01-10 02:25:56 +05305586 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305587
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305588 intel_dp = dev_priv->drrs.dp;
5589
5590 if (!intel_dp)
5591 goto unlock;
5592
5593 /*
5594 * The delayed work can race with an invalidate hence we need to
5595 * recheck.
5596 */
5597
5598 if (dev_priv->drrs.busy_frontbuffer_bits)
5599 goto unlock;
5600
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005601 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5602 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5603
5604 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5605 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5606 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305607
5608unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305609 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305610}
5611
Vandana Kannanb33a2812015-02-13 15:33:03 +05305612/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305613 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005614 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305615 * @frontbuffer_bits: frontbuffer plane tracking bits
5616 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305617 * This function gets called everytime rendering on the given planes start.
5618 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305619 *
5620 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5621 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005622void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5623 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305624{
Vandana Kannana93fad02015-01-10 02:25:59 +05305625 struct drm_crtc *crtc;
5626 enum pipe pipe;
5627
Daniel Vetter9da7d692015-04-09 16:44:15 +02005628 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305629 return;
5630
Daniel Vetter88f933a2015-04-09 16:44:16 +02005631 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305632
Vandana Kannana93fad02015-01-10 02:25:59 +05305633 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005634 if (!dev_priv->drrs.dp) {
5635 mutex_unlock(&dev_priv->drrs.mutex);
5636 return;
5637 }
5638
Vandana Kannana93fad02015-01-10 02:25:59 +05305639 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5640 pipe = to_intel_crtc(crtc)->pipe;
5641
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005642 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5643 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5644
Ramalingam C0ddfd202015-06-15 20:50:05 +05305645 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005646 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005647 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5648 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305649
Vandana Kannana93fad02015-01-10 02:25:59 +05305650 mutex_unlock(&dev_priv->drrs.mutex);
5651}
5652
Vandana Kannanb33a2812015-02-13 15:33:03 +05305653/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305654 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005655 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305656 * @frontbuffer_bits: frontbuffer plane tracking bits
5657 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305658 * This function gets called every time rendering on the given planes has
5659 * completed or flip on a crtc is completed. So DRRS should be upclocked
5660 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5661 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305662 *
5663 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5664 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005665void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5666 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305667{
Vandana Kannana93fad02015-01-10 02:25:59 +05305668 struct drm_crtc *crtc;
5669 enum pipe pipe;
5670
Daniel Vetter9da7d692015-04-09 16:44:15 +02005671 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305672 return;
5673
Daniel Vetter88f933a2015-04-09 16:44:16 +02005674 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305675
Vandana Kannana93fad02015-01-10 02:25:59 +05305676 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005677 if (!dev_priv->drrs.dp) {
5678 mutex_unlock(&dev_priv->drrs.mutex);
5679 return;
5680 }
5681
Vandana Kannana93fad02015-01-10 02:25:59 +05305682 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5683 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005684
5685 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305686 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5687
Ramalingam C0ddfd202015-06-15 20:50:05 +05305688 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005689 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005690 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5691 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305692
5693 /*
5694 * flush also means no more activity hence schedule downclock, if all
5695 * other fbs are quiescent too
5696 */
5697 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305698 schedule_delayed_work(&dev_priv->drrs.work,
5699 msecs_to_jiffies(1000));
5700 mutex_unlock(&dev_priv->drrs.mutex);
5701}
5702
Vandana Kannanb33a2812015-02-13 15:33:03 +05305703/**
5704 * DOC: Display Refresh Rate Switching (DRRS)
5705 *
5706 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5707 * which enables swtching between low and high refresh rates,
5708 * dynamically, based on the usage scenario. This feature is applicable
5709 * for internal panels.
5710 *
5711 * Indication that the panel supports DRRS is given by the panel EDID, which
5712 * would list multiple refresh rates for one resolution.
5713 *
5714 * DRRS is of 2 types - static and seamless.
5715 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5716 * (may appear as a blink on screen) and is used in dock-undock scenario.
5717 * Seamless DRRS involves changing RR without any visual effect to the user
5718 * and can be used during normal system usage. This is done by programming
5719 * certain registers.
5720 *
5721 * Support for static/seamless DRRS may be indicated in the VBT based on
5722 * inputs from the panel spec.
5723 *
5724 * DRRS saves power by switching to low RR based on usage scenarios.
5725 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005726 * The implementation is based on frontbuffer tracking implementation. When
5727 * there is a disturbance on the screen triggered by user activity or a periodic
5728 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5729 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5730 * made.
5731 *
5732 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5733 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305734 *
5735 * DRRS can be further extended to support other internal panels and also
5736 * the scenario of video playback wherein RR is set based on the rate
5737 * requested by userspace.
5738 */
5739
5740/**
5741 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5742 * @intel_connector: eDP connector
5743 * @fixed_mode: preferred mode of panel
5744 *
5745 * This function is called only once at driver load to initialize basic
5746 * DRRS stuff.
5747 *
5748 * Returns:
5749 * Downclock mode if panel supports it, else return NULL.
5750 * DRRS support is determined by the presence of downclock mode (apart
5751 * from VBT setting).
5752 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305753static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305754intel_dp_drrs_init(struct intel_connector *intel_connector,
5755 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305756{
5757 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305758 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005759 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305760 struct drm_display_mode *downclock_mode = NULL;
5761
Daniel Vetter9da7d692015-04-09 16:44:15 +02005762 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5763 mutex_init(&dev_priv->drrs.mutex);
5764
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005765 if (INTEL_GEN(dev_priv) <= 6) {
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305766 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5767 return NULL;
5768 }
5769
5770 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005771 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305772 return NULL;
5773 }
5774
5775 downclock_mode = intel_find_panel_downclock
Mika Kaholaa318b4c2016-12-13 10:02:48 +02005776 (dev_priv, fixed_mode, connector);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305777
5778 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305779 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305780 return NULL;
5781 }
5782
Vandana Kannan96178ee2015-01-10 02:25:56 +05305783 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305784
Vandana Kannan96178ee2015-01-10 02:25:56 +05305785 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005786 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305787 return downclock_mode;
5788}
5789
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005790static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005791 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005792{
5793 struct drm_connector *connector = &intel_connector->base;
5794 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005795 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5796 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005797 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005798 struct drm_display_mode *fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305799 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005800 bool has_dpcd;
5801 struct drm_display_mode *scan;
5802 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005803 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005804
5805 if (!is_edp(intel_dp))
5806 return true;
5807
Imre Deak97a824e12016-06-21 11:51:47 +03005808 /*
5809 * On IBX/CPT we may get here with LVDS already registered. Since the
5810 * driver uses the only internal power sequencer available for both
5811 * eDP and LVDS bail out early in this case to prevent interfering
5812 * with an already powered-on LVDS power sequencer.
5813 */
5814 if (intel_get_lvds_encoder(dev)) {
5815 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5816 DRM_INFO("LVDS was detected, not registering eDP\n");
5817
5818 return false;
5819 }
5820
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005821 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005822
5823 intel_dp_init_panel_power_timestamps(intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +03005824 intel_dp_pps_init(dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005825 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005826
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005827 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005828
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005829 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005830 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005831
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005832 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005833 /* if this fails, presume the device is a ghost */
5834 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005835 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005836 }
5837
Daniel Vetter060c8772014-03-21 23:22:35 +01005838 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005839 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005840 if (edid) {
5841 if (drm_add_edid_modes(connector, edid)) {
5842 drm_mode_connector_update_edid_property(connector,
5843 edid);
5844 drm_edid_to_eld(connector, edid);
5845 } else {
5846 kfree(edid);
5847 edid = ERR_PTR(-EINVAL);
5848 }
5849 } else {
5850 edid = ERR_PTR(-ENOENT);
5851 }
5852 intel_connector->edid = edid;
5853
5854 /* prefer fixed mode from EDID if available */
5855 list_for_each_entry(scan, &connector->probed_modes, head) {
5856 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5857 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305858 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305859 intel_connector, fixed_mode);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005860 break;
5861 }
5862 }
5863
5864 /* fallback to VBT if available for eDP */
5865 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5866 fixed_mode = drm_mode_duplicate(dev,
5867 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005868 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005869 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005870 connector->display_info.width_mm = fixed_mode->width_mm;
5871 connector->display_info.height_mm = fixed_mode->height_mm;
5872 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005873 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005874 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005875
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005876 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005877 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5878 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005879
5880 /*
5881 * Figure out the current pipe for the initial backlight setup.
5882 * If the current pipe isn't valid, try the PPS pipe, and if that
5883 * fails just assume pipe A.
5884 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005885 pipe = vlv_active_pipe(intel_dp);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005886
5887 if (pipe != PIPE_A && pipe != PIPE_B)
5888 pipe = intel_dp->pps_pipe;
5889
5890 if (pipe != PIPE_A && pipe != PIPE_B)
5891 pipe = PIPE_A;
5892
5893 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5894 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005895 }
5896
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305897 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005898 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005899 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005900
5901 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005902
5903out_vdd_off:
5904 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5905 /*
5906 * vdd might still be enabled do to the delayed vdd off.
5907 * Make sure vdd is actually turned off here.
5908 */
5909 pps_lock(intel_dp);
5910 edp_panel_vdd_off_sync(intel_dp);
5911 pps_unlock(intel_dp);
5912
5913 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005914}
5915
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005916/* Set up the hotplug pin and aux power domain. */
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005917static void
5918intel_dp_init_connector_port_info(struct intel_digital_port *intel_dig_port)
5919{
5920 struct intel_encoder *encoder = &intel_dig_port->base;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005921 struct intel_dp *intel_dp = &intel_dig_port->dp;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005922
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005923 switch (intel_dig_port->port) {
5924 case PORT_A:
5925 encoder->hpd_pin = HPD_PORT_A;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005926 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_A;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005927 break;
5928 case PORT_B:
5929 encoder->hpd_pin = HPD_PORT_B;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005930 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_B;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005931 break;
5932 case PORT_C:
5933 encoder->hpd_pin = HPD_PORT_C;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005934 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_C;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005935 break;
5936 case PORT_D:
5937 encoder->hpd_pin = HPD_PORT_D;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005938 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005939 break;
5940 case PORT_E:
5941 encoder->hpd_pin = HPD_PORT_E;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005942
5943 /* FIXME: Check VBT for actual wiring of PORT E */
5944 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005945 break;
5946 default:
5947 MISSING_CASE(intel_dig_port->port);
5948 }
5949}
5950
Manasi Navare93013972017-04-06 16:44:19 +03005951static void intel_dp_modeset_retry_work_fn(struct work_struct *work)
5952{
5953 struct intel_connector *intel_connector;
5954 struct drm_connector *connector;
5955
5956 intel_connector = container_of(work, typeof(*intel_connector),
5957 modeset_retry_work);
5958 connector = &intel_connector->base;
5959 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
5960 connector->name);
5961
5962 /* Grab the locks before changing connector property*/
5963 mutex_lock(&connector->dev->mode_config.mutex);
5964 /* Set connector link status to BAD and send a Uevent to notify
5965 * userspace to do a modeset.
5966 */
5967 drm_mode_connector_set_link_status_property(connector,
5968 DRM_MODE_LINK_STATUS_BAD);
5969 mutex_unlock(&connector->dev->mode_config.mutex);
5970 /* Send Hotplug uevent so userspace can reprobe */
5971 drm_kms_helper_hotplug_event(connector->dev);
5972}
5973
Paulo Zanoni16c25532013-06-12 17:27:25 -03005974bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005975intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5976 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005977{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005978 struct drm_connector *connector = &intel_connector->base;
5979 struct intel_dp *intel_dp = &intel_dig_port->dp;
5980 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5981 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005982 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02005983 enum port port = intel_dig_port->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01005984 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005985
Manasi Navare93013972017-04-06 16:44:19 +03005986 /* Initialize the work for modeset in case of link train failure */
5987 INIT_WORK(&intel_connector->modeset_retry_work,
5988 intel_dp_modeset_retry_work_fn);
5989
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005990 if (WARN(intel_dig_port->max_lanes < 1,
5991 "Not enough lanes (%d) for DP on port %c\n",
5992 intel_dig_port->max_lanes, port_name(port)))
5993 return false;
5994
Jani Nikula55cfc582017-03-28 17:59:04 +03005995 intel_dp_set_source_rates(intel_dp);
5996
Manasi Navared7e8ef02017-02-07 16:54:11 -08005997 intel_dp->reset_link_params = true;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005998 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005999 intel_dp->active_pipe = INVALID_PIPE;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03006000
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006001 /* intel_dp vfuncs */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006002 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub6b5e382014-01-20 16:00:59 +00006003 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01006004 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006005 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01006006 else if (HAS_PCH_SPLIT(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006007 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
6008 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02006009 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006010
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006011 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00006012 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
6013 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02006014 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00006015
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006016 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03006017 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
6018
Daniel Vetter07679352012-09-06 22:15:42 +02006019 /* Preserve the current hw state. */
6020 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03006021 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00006022
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006023 if (intel_dp_is_edp(dev_priv, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05306024 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02006025 else
6026 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04006027
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02006028 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
6029 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
6030
Imre Deakf7d24902013-05-08 13:14:05 +03006031 /*
6032 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
6033 * for DP the encoder type can be set by the caller to
6034 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
6035 */
6036 if (type == DRM_MODE_CONNECTOR_eDP)
6037 intel_encoder->type = INTEL_OUTPUT_EDP;
6038
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006039 /* eDP only on port B and/or C on vlv/chv */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006040 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08006041 is_edp(intel_dp) && port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006042 return false;
6043
Imre Deake7281ea2013-05-08 13:14:08 +03006044 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
6045 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
6046 port_name(port));
6047
Adam Jacksonb3295302010-07-16 14:46:28 -04006048 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006049 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
6050
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006051 connector->interlace_allowed = true;
6052 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08006053
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02006054 intel_dp_init_connector_port_info(intel_dig_port);
6055
Mika Kaholab6339582016-09-09 14:10:52 +03006056 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01006057
Daniel Vetter66a92782012-07-12 20:08:18 +02006058 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01006059 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08006060
Chris Wilsondf0e9242010-09-09 16:20:55 +01006061 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006062
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006063 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02006064 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
6065 else
6066 intel_connector->get_hw_state = intel_connector_get_hw_state;
6067
Dave Airlie0e32b392014-05-02 14:02:48 +10006068 /* init MST on ports that can support it */
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00006069 if (HAS_DP_MST(dev_priv) && !is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03006070 (port == PORT_B || port == PORT_C || port == PORT_D))
6071 intel_dp_mst_encoder_init(intel_dig_port,
6072 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10006073
Ville Syrjälä36b5f422014-10-16 21:27:30 +03006074 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006075 intel_dp_aux_fini(intel_dp);
6076 intel_dp_mst_encoder_cleanup(intel_dig_port);
6077 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03006078 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08006079
Chris Wilsonf6849602010-09-19 09:29:33 +01006080 intel_dp_add_properties(intel_dp, connector);
6081
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006082 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
6083 * 0xd. Failure to do so will result in spurious interrupts being
6084 * generated on the port when a cable is not attached.
6085 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01006086 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006087 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
6088 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
6089 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03006090
6091 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006092
6093fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006094 drm_connector_cleanup(connector);
6095
6096 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006097}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006098
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006099bool intel_dp_init(struct drm_i915_private *dev_priv,
Chris Wilson457c52d2016-06-01 08:27:50 +01006100 i915_reg_t output_reg,
6101 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006102{
6103 struct intel_digital_port *intel_dig_port;
6104 struct intel_encoder *intel_encoder;
6105 struct drm_encoder *encoder;
6106 struct intel_connector *intel_connector;
6107
Daniel Vetterb14c5672013-09-19 12:18:32 +02006108 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006109 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01006110 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006111
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03006112 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306113 if (!intel_connector)
6114 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006115
6116 intel_encoder = &intel_dig_port->base;
6117 encoder = &intel_encoder->base;
6118
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006119 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
6120 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
6121 "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306122 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006123
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01006124 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006125 intel_encoder->disable = intel_disable_dp;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006126 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07006127 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03006128 intel_encoder->suspend = intel_dp_encoder_suspend;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006129 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03006130 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03006131 intel_encoder->pre_enable = chv_pre_enable_dp;
6132 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03006133 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03006134 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01006135 } else if (IS_VALLEYVIEW(dev_priv)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006136 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006137 intel_encoder->pre_enable = vlv_pre_enable_dp;
6138 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03006139 intel_encoder->post_disable = vlv_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006140 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006141 intel_encoder->pre_enable = g4x_pre_enable_dp;
6142 intel_encoder->enable = g4x_enable_dp;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006143 if (INTEL_GEN(dev_priv) >= 5)
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03006144 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006145 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006146
Paulo Zanoni174edf12012-10-26 19:05:50 -02006147 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006148 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02006149 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006150
Ville Syrjäläcca05022016-06-22 21:57:06 +03006151 intel_encoder->type = INTEL_OUTPUT_DP;
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02006152 intel_encoder->power_domain = intel_port_to_power_domain(port);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006153 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03006154 if (port == PORT_D)
6155 intel_encoder->crtc_mask = 1 << 2;
6156 else
6157 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
6158 } else {
6159 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
6160 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02006161 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07006162 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006163
Dave Airlie13cf5502014-06-18 11:29:35 +10006164 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03006165 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10006166
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306167 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
6168 goto err_init_connector;
6169
Chris Wilson457c52d2016-06-01 08:27:50 +01006170 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306171
6172err_init_connector:
6173 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306174err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306175 kfree(intel_connector);
6176err_connector_alloc:
6177 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01006178 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006179}
Dave Airlie0e32b392014-05-02 14:02:48 +10006180
6181void intel_dp_mst_suspend(struct drm_device *dev)
6182{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006183 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006184 int i;
6185
6186 /* disable MST */
6187 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006188 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006189
6190 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006191 continue;
6192
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006193 if (intel_dig_port->dp.is_mst)
6194 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10006195 }
6196}
6197
6198void intel_dp_mst_resume(struct drm_device *dev)
6199{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006200 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006201 int i;
6202
6203 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006204 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006205 int ret;
6206
6207 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006208 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10006209
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006210 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
6211 if (ret)
6212 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10006213 }
6214}