blob: 16b7bf7af5378fdaea5af4c9af209771da9d9e38 [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);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200801 if (!IS_GEN9_LP(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;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001651 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001652 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001653 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001654 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001655 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301656 int max_clock;
Daniel Vetter083f9562012-04-20 20:23:49 +02001657 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001658 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001659 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001660 uint8_t link_bw, rate_select;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301661
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001662 common_len = intel_dp_common_len_rate_limit(intel_dp,
Jani Nikulae6c0c642017-04-06 16:44:12 +03001663 intel_dp->max_link_rate);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301664
1665 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001666 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301667
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001668 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001669
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001670 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001671 pipe_config->has_pch_encoder = true;
1672
Vandana Kannanf769cd22014-08-05 07:51:22 -07001673 pipe_config->has_drrs = false;
Jani Nikula9fcb1702015-05-05 16:32:12 +03001674 pipe_config->has_audio = intel_dp->has_audio && port != PORT_A;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001675
Jani Nikuladd06f902012-10-19 14:51:50 +03001676 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1677 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
1678 adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001679
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001680 if (INTEL_GEN(dev_priv) >= 9) {
Chandra Kondurua1b22782015-04-07 15:28:45 -07001681 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001682 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001683 if (ret)
1684 return ret;
1685 }
1686
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001687 if (HAS_GMCH_DISPLAY(dev_priv))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001688 intel_gmch_panel_fitting(intel_crtc, pipe_config,
1689 intel_connector->panel.fitting_mode);
1690 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001691 intel_pch_panel_fitting(intel_crtc, pipe_config,
1692 intel_connector->panel.fitting_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001693 }
1694
Daniel Vettercb1793c2012-06-04 18:39:21 +02001695 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001696 return false;
1697
Manasi Navareda15f7c2017-01-24 08:16:34 -08001698 /* Use values requested by Compliance Test Request */
1699 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
Jani Nikulaec990e22017-04-06 16:44:15 +03001700 int index;
1701
1702 index = intel_dp_rate_index(intel_dp->common_rates,
1703 intel_dp->num_common_rates,
1704 intel_dp->compliance.test_link_rate);
1705 if (index >= 0)
1706 min_clock = max_clock = index;
Manasi Navareda15f7c2017-01-24 08:16:34 -08001707 min_lane_count = max_lane_count = intel_dp->compliance.test_lane_count;
1708 }
Daniel Vetter083f9562012-04-20 20:23:49 +02001709 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301710 "max bw %d pixel clock %iKHz\n",
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001711 max_lane_count, intel_dp->common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001712 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001713
Daniel Vetter36008362013-03-27 00:44:59 +01001714 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1715 * bpc in between. */
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001716 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
Jani Nikula56071a22014-05-06 14:56:52 +03001717 if (is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301718
1719 /* Get bpp from vbt only for panels that dont have bpp in edid */
1720 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001721 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001722 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001723 dev_priv->vbt.edp.bpp);
1724 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001725 }
1726
Jani Nikula344c5bb2014-09-09 11:25:13 +03001727 /*
1728 * Use the maximum clock and number of lanes the eDP panel
1729 * advertizes being capable of. The panels are generally
1730 * designed to support only a single clock and lane
1731 * configuration, and typically these values correspond to the
1732 * native resolution of the panel.
1733 */
1734 min_lane_count = max_lane_count;
1735 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001736 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001737
Daniel Vetter36008362013-03-27 00:44:59 +01001738 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001739 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1740 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001741
Dave Airliec6930992014-07-14 11:04:39 +10001742 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301743 for (lane_count = min_lane_count;
1744 lane_count <= max_lane_count;
1745 lane_count <<= 1) {
1746
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001747 link_clock = intel_dp->common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001748 link_avail = intel_dp_max_data_rate(link_clock,
1749 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001750
Daniel Vetter36008362013-03-27 00:44:59 +01001751 if (mode_rate <= link_avail) {
1752 goto found;
1753 }
1754 }
1755 }
1756 }
1757
1758 return false;
1759
1760found:
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001761 if (intel_dp->color_range_auto) {
1762 /*
1763 * See:
1764 * CEA-861-E - 5.1 Default Encoding Parameters
1765 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1766 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001767 pipe_config->limited_color_range =
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02001768 bpp != 18 &&
1769 drm_default_rgb_quant_range(adjusted_mode) ==
1770 HDMI_QUANTIZATION_RANGE_LIMITED;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001771 } else {
1772 pipe_config->limited_color_range =
1773 intel_dp->limited_color_range;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001774 }
1775
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001776 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301777
Daniel Vetter657445f2013-05-04 10:09:18 +02001778 pipe_config->pipe_bpp = bpp;
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001779 pipe_config->port_clock = intel_dp->common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001780
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001781 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1782 &link_bw, &rate_select);
1783
1784 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1785 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001786 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001787 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1788 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001789
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001790 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001791 adjusted_mode->crtc_clock,
1792 pipe_config->port_clock,
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001793 &pipe_config->dp_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001794
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301795 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301796 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001797 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301798 intel_link_compute_m_n(bpp, lane_count,
1799 intel_connector->panel.downclock_mode->clock,
1800 pipe_config->port_clock,
1801 &pipe_config->dp_m2_n2);
1802 }
1803
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001804 /*
1805 * DPLL0 VCO may need to be adjusted to get the correct
1806 * clock for eDP. This will affect cdclk as well.
1807 */
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001808 if (is_edp(intel_dp) && IS_GEN9_BC(dev_priv)) {
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001809 int vco;
1810
1811 switch (pipe_config->port_clock / 2) {
1812 case 108000:
1813 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001814 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001815 break;
1816 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001817 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001818 break;
1819 }
1820
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +02001821 to_intel_atomic_state(pipe_config->base.state)->cdclk.logical.vco = vco;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001822 }
1823
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001824 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001825 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001826
Daniel Vetter36008362013-03-27 00:44:59 +01001827 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001828}
1829
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001830void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001831 int link_rate, uint8_t lane_count,
1832 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001833{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001834 intel_dp->link_rate = link_rate;
1835 intel_dp->lane_count = lane_count;
1836 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001837}
1838
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001839static void intel_dp_prepare(struct intel_encoder *encoder,
1840 struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001841{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001842 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001843 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001844 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001845 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001846 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001847 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001848
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001849 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1850 pipe_config->lane_count,
1851 intel_crtc_has_type(pipe_config,
1852 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001853
Keith Packard417e8222011-11-01 19:54:11 -07001854 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001855 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001856 *
1857 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001858 * SNB CPU
1859 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001860 * CPT PCH
1861 *
1862 * IBX PCH and CPU are the same for almost everything,
1863 * except that the CPU DP PLL is configured in this
1864 * register
1865 *
1866 * CPT PCH is quite different, having many bits moved
1867 * to the TRANS_DP_CTL register instead. That
1868 * configuration happens (oddly) in ironlake_pch_enable
1869 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001870
Keith Packard417e8222011-11-01 19:54:11 -07001871 /* Preserve the BIOS-computed detected bit. This is
1872 * supposed to be read-only.
1873 */
1874 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001875
Keith Packard417e8222011-11-01 19:54:11 -07001876 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001877 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001878 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001879
Keith Packard417e8222011-11-01 19:54:11 -07001880 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001881
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001882 if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001883 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1884 intel_dp->DP |= DP_SYNC_HS_HIGH;
1885 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1886 intel_dp->DP |= DP_SYNC_VS_HIGH;
1887 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1888
Jani Nikula6aba5b62013-10-04 15:08:10 +03001889 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001890 intel_dp->DP |= DP_ENHANCED_FRAMING;
1891
Daniel Vetter7c62a162013-06-01 17:16:20 +02001892 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001893 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001894 u32 trans_dp;
1895
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001896 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001897
1898 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1899 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1900 trans_dp |= TRANS_DP_ENH_FRAMING;
1901 else
1902 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1903 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001904 } else {
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02001905 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001906 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001907
1908 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1909 intel_dp->DP |= DP_SYNC_HS_HIGH;
1910 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1911 intel_dp->DP |= DP_SYNC_VS_HIGH;
1912 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1913
Jani Nikula6aba5b62013-10-04 15:08:10 +03001914 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001915 intel_dp->DP |= DP_ENHANCED_FRAMING;
1916
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001917 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001918 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001919 else if (crtc->pipe == PIPE_B)
1920 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001921 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001922}
1923
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001924#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1925#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001926
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001927#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1928#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001929
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001930#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1931#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001932
Imre Deakde9c1b62016-06-16 20:01:46 +03001933static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
1934 struct intel_dp *intel_dp);
1935
Daniel Vetter4be73782014-01-17 14:39:48 +01001936static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001937 u32 mask,
1938 u32 value)
1939{
Paulo Zanoni30add222012-10-26 19:05:45 -02001940 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001941 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001942 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001943
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001944 lockdep_assert_held(&dev_priv->pps_mutex);
1945
Imre Deakde9c1b62016-06-16 20:01:46 +03001946 intel_pps_verify_state(dev_priv, intel_dp);
1947
Jani Nikulabf13e812013-09-06 07:40:05 +03001948 pp_stat_reg = _pp_stat_reg(intel_dp);
1949 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001950
1951 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001952 mask, value,
1953 I915_READ(pp_stat_reg),
1954 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001955
Chris Wilson9036ff02016-06-30 15:33:09 +01001956 if (intel_wait_for_register(dev_priv,
1957 pp_stat_reg, mask, value,
1958 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001959 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001960 I915_READ(pp_stat_reg),
1961 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001962
1963 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001964}
1965
Daniel Vetter4be73782014-01-17 14:39:48 +01001966static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001967{
1968 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001969 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001970}
1971
Daniel Vetter4be73782014-01-17 14:39:48 +01001972static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001973{
Keith Packardbd943152011-09-18 23:09:52 -07001974 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001975 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001976}
Keith Packardbd943152011-09-18 23:09:52 -07001977
Daniel Vetter4be73782014-01-17 14:39:48 +01001978static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001979{
Abhay Kumard28d4732016-01-22 17:39:04 -08001980 ktime_t panel_power_on_time;
1981 s64 panel_power_off_duration;
1982
Keith Packard99ea7122011-11-01 19:57:50 -07001983 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001984
Abhay Kumard28d4732016-01-22 17:39:04 -08001985 /* take the difference of currrent time and panel power off time
1986 * and then make panel wait for t11_t12 if needed. */
1987 panel_power_on_time = ktime_get_boottime();
1988 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1989
Paulo Zanonidce56b32013-12-19 14:29:40 -02001990 /* When we disable the VDD override bit last we have to do the manual
1991 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08001992 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
1993 wait_remaining_ms_from_jiffies(jiffies,
1994 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001995
Daniel Vetter4be73782014-01-17 14:39:48 +01001996 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001997}
Keith Packardbd943152011-09-18 23:09:52 -07001998
Daniel Vetter4be73782014-01-17 14:39:48 +01001999static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02002000{
2001 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
2002 intel_dp->backlight_on_delay);
2003}
2004
Daniel Vetter4be73782014-01-17 14:39:48 +01002005static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02002006{
2007 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
2008 intel_dp->backlight_off_delay);
2009}
Keith Packard99ea7122011-11-01 19:57:50 -07002010
Keith Packard832dd3c2011-11-01 19:34:06 -07002011/* Read the current pp_control value, unlocking the register if it
2012 * is locked
2013 */
2014
Jesse Barnes453c5422013-03-28 09:55:41 -07002015static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07002016{
Jesse Barnes453c5422013-03-28 09:55:41 -07002017 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002018 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07002019 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07002020
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002021 lockdep_assert_held(&dev_priv->pps_mutex);
2022
Jani Nikulabf13e812013-09-06 07:40:05 +03002023 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03002024 if (WARN_ON(!HAS_DDI(dev_priv) &&
2025 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05302026 control &= ~PANEL_UNLOCK_MASK;
2027 control |= PANEL_UNLOCK_REGS;
2028 }
Keith Packard832dd3c2011-11-01 19:34:06 -07002029 return control;
Keith Packardbd943152011-09-18 23:09:52 -07002030}
2031
Ville Syrjälä951468f2014-09-04 14:55:31 +03002032/*
2033 * Must be paired with edp_panel_vdd_off().
2034 * Must hold pps_mutex around the whole on/off sequence.
2035 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2036 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03002037static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002038{
Paulo Zanoni30add222012-10-26 19:05:45 -02002039 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002040 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002041 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes5d613502011-01-24 17:10:54 -08002042 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002043 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002044 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08002045
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002046 lockdep_assert_held(&dev_priv->pps_mutex);
2047
Keith Packard97af61f572011-09-28 16:23:51 -07002048 if (!is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002049 return false;
Keith Packardbd943152011-09-18 23:09:52 -07002050
Egbert Eich2c623c12014-11-25 12:54:57 +01002051 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002052 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07002053
Daniel Vetter4be73782014-01-17 14:39:48 +01002054 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002055 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002056
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002057 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002058
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002059 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
2060 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07002061
Daniel Vetter4be73782014-01-17 14:39:48 +01002062 if (!edp_have_panel_power(intel_dp))
2063 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07002064
Jesse Barnes453c5422013-03-28 09:55:41 -07002065 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002066 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07002067
Jani Nikulabf13e812013-09-06 07:40:05 +03002068 pp_stat_reg = _pp_stat_reg(intel_dp);
2069 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002070
2071 I915_WRITE(pp_ctrl_reg, pp);
2072 POSTING_READ(pp_ctrl_reg);
2073 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2074 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07002075 /*
2076 * If the panel wasn't on, delay before accessing aux channel
2077 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002078 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002079 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
2080 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07002081 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07002082 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002083
2084 return need_to_disable;
2085}
2086
Ville Syrjälä951468f2014-09-04 14:55:31 +03002087/*
2088 * Must be paired with intel_edp_panel_vdd_off() or
2089 * intel_edp_panel_off().
2090 * Nested calls to these functions are not allowed since
2091 * we drop the lock. Caller must use some higher level
2092 * locking to prevent nested calls from other threads.
2093 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01002094void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002095{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002096 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002097
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002098 if (!is_edp(intel_dp))
2099 return;
2100
Ville Syrjälä773538e82014-09-04 14:54:56 +03002101 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002102 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002103 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002104
Rob Clarke2c719b2014-12-15 13:56:32 -05002105 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002106 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08002107}
2108
Daniel Vetter4be73782014-01-17 14:39:48 +01002109static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002110{
Paulo Zanoni30add222012-10-26 19:05:45 -02002111 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002112 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002113 struct intel_digital_port *intel_dig_port =
2114 dp_to_dig_port(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002115 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002116 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002117
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002118 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002119
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002120 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002121
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002122 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002123 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002124
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002125 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2126 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002127
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002128 pp = ironlake_get_pp_control(intel_dp);
2129 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002130
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002131 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2132 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002133
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002134 I915_WRITE(pp_ctrl_reg, pp);
2135 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002136
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002137 /* Make sure sequencer is idle before allowing subsequent activity */
2138 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2139 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002140
Imre Deak5a162e22016-08-10 14:07:30 +03002141 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002142 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002143
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002144 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002145}
2146
Daniel Vetter4be73782014-01-17 14:39:48 +01002147static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002148{
2149 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2150 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002151
Ville Syrjälä773538e82014-09-04 14:54:56 +03002152 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002153 if (!intel_dp->want_panel_vdd)
2154 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002155 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002156}
2157
Imre Deakaba86892014-07-30 15:57:31 +03002158static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2159{
2160 unsigned long delay;
2161
2162 /*
2163 * Queue the timer to fire a long time from now (relative to the power
2164 * down delay) to keep the panel power up across a sequence of
2165 * operations.
2166 */
2167 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2168 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2169}
2170
Ville Syrjälä951468f2014-09-04 14:55:31 +03002171/*
2172 * Must be paired with edp_panel_vdd_on().
2173 * Must hold pps_mutex around the whole on/off sequence.
2174 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2175 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002176static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002177{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002178 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002179
2180 lockdep_assert_held(&dev_priv->pps_mutex);
2181
Keith Packard97af61f572011-09-28 16:23:51 -07002182 if (!is_edp(intel_dp))
2183 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002184
Rob Clarke2c719b2014-12-15 13:56:32 -05002185 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002186 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002187
Keith Packardbd943152011-09-18 23:09:52 -07002188 intel_dp->want_panel_vdd = false;
2189
Imre Deakaba86892014-07-30 15:57:31 +03002190 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002191 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002192 else
2193 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002194}
2195
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002196static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002197{
Paulo Zanoni30add222012-10-26 19:05:45 -02002198 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002199 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002200 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002201 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002202
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002203 lockdep_assert_held(&dev_priv->pps_mutex);
2204
Keith Packard97af61f572011-09-28 16:23:51 -07002205 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002206 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002207
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002208 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2209 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002210
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002211 if (WARN(edp_have_panel_power(intel_dp),
2212 "eDP port %c panel power already on\n",
2213 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002214 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002215
Daniel Vetter4be73782014-01-17 14:39:48 +01002216 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002217
Jani Nikulabf13e812013-09-06 07:40:05 +03002218 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002219 pp = ironlake_get_pp_control(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002220 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002221 /* ILK workaround: disable reset around power sequence */
2222 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002223 I915_WRITE(pp_ctrl_reg, pp);
2224 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002225 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002226
Imre Deak5a162e22016-08-10 14:07:30 +03002227 pp |= PANEL_POWER_ON;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002228 if (!IS_GEN5(dev_priv))
Keith Packard99ea7122011-11-01 19:57:50 -07002229 pp |= PANEL_POWER_RESET;
2230
Jesse Barnes453c5422013-03-28 09:55:41 -07002231 I915_WRITE(pp_ctrl_reg, pp);
2232 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002233
Daniel Vetter4be73782014-01-17 14:39:48 +01002234 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002235 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002236
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002237 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002238 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002239 I915_WRITE(pp_ctrl_reg, pp);
2240 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002241 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002242}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002243
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002244void intel_edp_panel_on(struct intel_dp *intel_dp)
2245{
2246 if (!is_edp(intel_dp))
2247 return;
2248
2249 pps_lock(intel_dp);
2250 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002251 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002252}
2253
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002254
2255static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002256{
Paulo Zanoni30add222012-10-26 19:05:45 -02002257 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002258 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002259 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002260 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002261
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002262 lockdep_assert_held(&dev_priv->pps_mutex);
2263
Keith Packard97af61f572011-09-28 16:23:51 -07002264 if (!is_edp(intel_dp))
2265 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002266
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002267 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2268 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002269
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002270 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2271 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002272
Jesse Barnes453c5422013-03-28 09:55:41 -07002273 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002274 /* We need to switch off panel power _and_ force vdd, for otherwise some
2275 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002276 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002277 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002278
Jani Nikulabf13e812013-09-06 07:40:05 +03002279 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002280
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002281 intel_dp->want_panel_vdd = false;
2282
Jesse Barnes453c5422013-03-28 09:55:41 -07002283 I915_WRITE(pp_ctrl_reg, pp);
2284 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002285
Abhay Kumard28d4732016-01-22 17:39:04 -08002286 intel_dp->panel_power_off_time = ktime_get_boottime();
Daniel Vetter4be73782014-01-17 14:39:48 +01002287 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002288
2289 /* We got a reference when we enabled the VDD. */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002290 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002291}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002292
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002293void intel_edp_panel_off(struct intel_dp *intel_dp)
2294{
2295 if (!is_edp(intel_dp))
2296 return;
2297
2298 pps_lock(intel_dp);
2299 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002300 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002301}
2302
Jani Nikula1250d102014-08-12 17:11:39 +03002303/* Enable backlight in the panel power control. */
2304static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002305{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002306 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2307 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002308 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002309 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002310 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002311
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002312 /*
2313 * If we enable the backlight right away following a panel power
2314 * on, we may see slight flicker as the panel syncs with the eDP
2315 * link. So delay a bit to make sure the image is solid before
2316 * allowing it to appear.
2317 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002318 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002319
Ville Syrjälä773538e82014-09-04 14:54:56 +03002320 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002321
Jesse Barnes453c5422013-03-28 09:55:41 -07002322 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002323 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002324
Jani Nikulabf13e812013-09-06 07:40:05 +03002325 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002326
2327 I915_WRITE(pp_ctrl_reg, pp);
2328 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002329
Ville Syrjälä773538e82014-09-04 14:54:56 +03002330 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002331}
2332
Jani Nikula1250d102014-08-12 17:11:39 +03002333/* Enable backlight PWM and backlight PP control. */
2334void intel_edp_backlight_on(struct intel_dp *intel_dp)
2335{
2336 if (!is_edp(intel_dp))
2337 return;
2338
2339 DRM_DEBUG_KMS("\n");
2340
2341 intel_panel_enable_backlight(intel_dp->attached_connector);
2342 _intel_edp_backlight_on(intel_dp);
2343}
2344
2345/* Disable backlight in the panel power control. */
2346static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002347{
Paulo Zanoni30add222012-10-26 19:05:45 -02002348 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002349 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002350 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002351 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002352
Keith Packardf01eca22011-09-28 16:48:10 -07002353 if (!is_edp(intel_dp))
2354 return;
2355
Ville Syrjälä773538e82014-09-04 14:54:56 +03002356 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002357
Jesse Barnes453c5422013-03-28 09:55:41 -07002358 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002359 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002360
Jani Nikulabf13e812013-09-06 07:40:05 +03002361 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002362
2363 I915_WRITE(pp_ctrl_reg, pp);
2364 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002365
Ville Syrjälä773538e82014-09-04 14:54:56 +03002366 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002367
Paulo Zanonidce56b32013-12-19 14:29:40 -02002368 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002369 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002370}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002371
Jani Nikula1250d102014-08-12 17:11:39 +03002372/* Disable backlight PP control and backlight PWM. */
2373void intel_edp_backlight_off(struct intel_dp *intel_dp)
2374{
2375 if (!is_edp(intel_dp))
2376 return;
2377
2378 DRM_DEBUG_KMS("\n");
2379
2380 _intel_edp_backlight_off(intel_dp);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002381 intel_panel_disable_backlight(intel_dp->attached_connector);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002382}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002383
Jani Nikula73580fb72014-08-12 17:11:41 +03002384/*
2385 * Hook for controlling the panel power control backlight through the bl_power
2386 * sysfs attribute. Take care to handle multiple calls.
2387 */
2388static void intel_edp_backlight_power(struct intel_connector *connector,
2389 bool enable)
2390{
2391 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002392 bool is_enabled;
2393
Ville Syrjälä773538e82014-09-04 14:54:56 +03002394 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002395 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002396 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002397
2398 if (is_enabled == enable)
2399 return;
2400
Jani Nikula23ba9372014-08-27 14:08:43 +03002401 DRM_DEBUG_KMS("panel power control backlight %s\n",
2402 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002403
2404 if (enable)
2405 _intel_edp_backlight_on(intel_dp);
2406 else
2407 _intel_edp_backlight_off(intel_dp);
2408}
2409
Ville Syrjälä64e10772015-10-29 21:26:01 +02002410static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2411{
2412 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2413 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2414 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2415
2416 I915_STATE_WARN(cur_state != state,
2417 "DP port %c state assertion failure (expected %s, current %s)\n",
2418 port_name(dig_port->port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002419 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002420}
2421#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2422
2423static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2424{
2425 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2426
2427 I915_STATE_WARN(cur_state != state,
2428 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002429 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002430}
2431#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2432#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2433
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002434static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2435 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002436{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002437 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002438 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002439
Ville Syrjälä64e10772015-10-29 21:26:01 +02002440 assert_pipe_disabled(dev_priv, crtc->pipe);
2441 assert_dp_port_disabled(intel_dp);
2442 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002443
Ville Syrjäläabfce942015-10-29 21:26:03 +02002444 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002445 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002446
2447 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2448
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002449 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002450 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2451 else
2452 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2453
2454 I915_WRITE(DP_A, intel_dp->DP);
2455 POSTING_READ(DP_A);
2456 udelay(500);
2457
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002458 /*
2459 * [DevILK] Work around required when enabling DP PLL
2460 * while a pipe is enabled going to FDI:
2461 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2462 * 2. Program DP PLL enable
2463 */
2464 if (IS_GEN5(dev_priv))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02002465 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002466
Daniel Vetter07679352012-09-06 22:15:42 +02002467 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002468
Daniel Vetter07679352012-09-06 22:15:42 +02002469 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002470 POSTING_READ(DP_A);
2471 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002472}
2473
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002474static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002475{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002476 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002477 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2478 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002479
Ville Syrjälä64e10772015-10-29 21:26:01 +02002480 assert_pipe_disabled(dev_priv, crtc->pipe);
2481 assert_dp_port_disabled(intel_dp);
2482 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002483
Ville Syrjäläabfce942015-10-29 21:26:03 +02002484 DRM_DEBUG_KMS("disabling eDP PLL\n");
2485
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002486 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002487
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002488 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002489 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002490 udelay(200);
2491}
2492
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002493/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002494void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002495{
2496 int ret, i;
2497
2498 /* Should have a valid DPCD by this point */
2499 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2500 return;
2501
2502 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002503 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2504 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002505 } else {
Imre Deak357c0ae2016-11-21 21:15:06 +02002506 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
2507
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002508 /*
2509 * When turning on, we need to retry for 1ms to give the sink
2510 * time to wake up.
2511 */
2512 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002513 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2514 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002515 if (ret == 1)
2516 break;
2517 msleep(1);
2518 }
Imre Deak357c0ae2016-11-21 21:15:06 +02002519
2520 if (ret == 1 && lspcon->active)
2521 lspcon_wait_pcon_mode(lspcon);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002522 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002523
2524 if (ret != 1)
2525 DRM_DEBUG_KMS("failed to %s sink power state\n",
2526 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002527}
2528
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002529static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2530 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002531{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002532 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002533 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002534 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002535 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002536 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002537 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002538
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002539 if (!intel_display_power_get_if_enabled(dev_priv,
2540 encoder->power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002541 return false;
2542
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002543 ret = false;
2544
Imre Deak6d129be2014-03-05 16:20:54 +02002545 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002546
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002547 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002548 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002549
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002550 if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002551 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002552 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002553 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002554
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002555 for_each_pipe(dev_priv, p) {
2556 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2557 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2558 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002559 ret = true;
2560
2561 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002562 }
2563 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002564
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002565 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002566 i915_mmio_reg_offset(intel_dp->output_reg));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002567 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002568 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2569 } else {
2570 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002571 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002572
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002573 ret = true;
2574
2575out:
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002576 intel_display_power_put(dev_priv, encoder->power_domain);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002577
2578 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002579}
2580
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002581static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002582 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002583{
2584 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002585 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002586 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002587 struct drm_i915_private *dev_priv = to_i915(dev);
Xiong Zhang63000ef2013-06-28 12:59:06 +08002588 enum port port = dp_to_dig_port(intel_dp)->port;
2589 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002590
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002591 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002592
2593 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002594
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002595 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002596 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2597
2598 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002599 flags |= DRM_MODE_FLAG_PHSYNC;
2600 else
2601 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002602
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002603 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002604 flags |= DRM_MODE_FLAG_PVSYNC;
2605 else
2606 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002607 } else {
2608 if (tmp & DP_SYNC_HS_HIGH)
2609 flags |= DRM_MODE_FLAG_PHSYNC;
2610 else
2611 flags |= DRM_MODE_FLAG_NHSYNC;
2612
2613 if (tmp & DP_SYNC_VS_HIGH)
2614 flags |= DRM_MODE_FLAG_PVSYNC;
2615 else
2616 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002617 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002618
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002619 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002620
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02002621 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002622 pipe_config->limited_color_range = true;
2623
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002624 pipe_config->lane_count =
2625 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2626
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002627 intel_dp_get_m_n(crtc, pipe_config);
2628
Ville Syrjälä18442d02013-09-13 16:00:08 +03002629 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002630 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002631 pipe_config->port_clock = 162000;
2632 else
2633 pipe_config->port_clock = 270000;
2634 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002635
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002636 pipe_config->base.adjusted_mode.crtc_clock =
2637 intel_dotclock_calculate(pipe_config->port_clock,
2638 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002639
Jani Nikula6aa23e62016-03-24 17:50:20 +02002640 if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
2641 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002642 /*
2643 * This is a big fat ugly hack.
2644 *
2645 * Some machines in UEFI boot mode provide us a VBT that has 18
2646 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2647 * unknown we fail to light up. Yet the same BIOS boots up with
2648 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2649 * max, not what it tells us to use.
2650 *
2651 * Note: This will still be broken if the eDP panel is not lit
2652 * up by the BIOS, and thus we can't get the mode at module
2653 * load.
2654 */
2655 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002656 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2657 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002658 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002659}
2660
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002661static void intel_disable_dp(struct intel_encoder *encoder,
2662 struct intel_crtc_state *old_crtc_state,
2663 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002664{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002665 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002666 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002667
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002668 if (old_crtc_state->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002669 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002670
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002671 if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv))
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002672 intel_psr_disable(intel_dp);
2673
Daniel Vetter6cb49832012-05-20 17:14:50 +02002674 /* Make sure the panel is off before trying to change the mode. But also
2675 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002676 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01002677 intel_edp_backlight_off(intel_dp);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002678 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002679 intel_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02002680
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002681 /* disable the port before the pipe on g4x */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002682 if (INTEL_GEN(dev_priv) < 5)
Daniel Vetter37398502012-09-06 22:15:44 +02002683 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07002684}
2685
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002686static void ilk_post_disable_dp(struct intel_encoder *encoder,
2687 struct intel_crtc_state *old_crtc_state,
2688 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002689{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002690 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002691 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002692
Ville Syrjälä49277c32014-03-31 18:21:26 +03002693 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002694
2695 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002696 if (port == PORT_A)
2697 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002698}
2699
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002700static void vlv_post_disable_dp(struct intel_encoder *encoder,
2701 struct intel_crtc_state *old_crtc_state,
2702 struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002703{
2704 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2705
2706 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002707}
2708
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002709static void chv_post_disable_dp(struct intel_encoder *encoder,
2710 struct intel_crtc_state *old_crtc_state,
2711 struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002712{
2713 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002714 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002715 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002716
2717 intel_dp_link_down(intel_dp);
2718
Ville Syrjäläa5805162015-05-26 20:42:30 +03002719 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002720
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002721 /* Assert data lane reset */
2722 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002723
Ville Syrjäläa5805162015-05-26 20:42:30 +03002724 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002725}
2726
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002727static void
2728_intel_dp_set_link_train(struct intel_dp *intel_dp,
2729 uint32_t *DP,
2730 uint8_t dp_train_pat)
2731{
2732 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2733 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002734 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002735 enum port port = intel_dig_port->port;
2736
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002737 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2738 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2739 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2740
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002741 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002742 uint32_t temp = I915_READ(DP_TP_CTL(port));
2743
2744 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2745 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2746 else
2747 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2748
2749 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2750 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2751 case DP_TRAINING_PATTERN_DISABLE:
2752 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2753
2754 break;
2755 case DP_TRAINING_PATTERN_1:
2756 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2757 break;
2758 case DP_TRAINING_PATTERN_2:
2759 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2760 break;
2761 case DP_TRAINING_PATTERN_3:
2762 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2763 break;
2764 }
2765 I915_WRITE(DP_TP_CTL(port), temp);
2766
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002767 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002768 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002769 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2770
2771 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2772 case DP_TRAINING_PATTERN_DISABLE:
2773 *DP |= DP_LINK_TRAIN_OFF_CPT;
2774 break;
2775 case DP_TRAINING_PATTERN_1:
2776 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2777 break;
2778 case DP_TRAINING_PATTERN_2:
2779 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2780 break;
2781 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002782 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002783 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2784 break;
2785 }
2786
2787 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002788 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002789 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2790 else
2791 *DP &= ~DP_LINK_TRAIN_MASK;
2792
2793 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2794 case DP_TRAINING_PATTERN_DISABLE:
2795 *DP |= DP_LINK_TRAIN_OFF;
2796 break;
2797 case DP_TRAINING_PATTERN_1:
2798 *DP |= DP_LINK_TRAIN_PAT_1;
2799 break;
2800 case DP_TRAINING_PATTERN_2:
2801 *DP |= DP_LINK_TRAIN_PAT_2;
2802 break;
2803 case DP_TRAINING_PATTERN_3:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002804 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002805 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2806 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002807 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002808 *DP |= DP_LINK_TRAIN_PAT_2;
2809 }
2810 break;
2811 }
2812 }
2813}
2814
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002815static void intel_dp_enable_port(struct intel_dp *intel_dp,
2816 struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002817{
2818 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002819 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002820
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002821 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002822
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002823 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002824
2825 /*
2826 * Magic for VLV/CHV. We _must_ first set up the register
2827 * without actually enabling the port, and then do another
2828 * write to enable the port. Otherwise link training will
2829 * fail when the power sequencer is freshly used for this port.
2830 */
2831 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002832 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002833 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002834
2835 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2836 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002837}
2838
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002839static void intel_enable_dp(struct intel_encoder *encoder,
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002840 struct intel_crtc_state *pipe_config,
2841 struct drm_connector_state *conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002842{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002843 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2844 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002845 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulac1dec792014-10-27 16:26:56 +02002846 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002847 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002848 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002849
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002850 if (WARN_ON(dp_reg & DP_PORT_EN))
2851 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002852
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002853 pps_lock(intel_dp);
2854
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002855 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002856 vlv_init_panel_power_sequencer(intel_dp);
2857
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002858 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002859
2860 edp_panel_vdd_on(intel_dp);
2861 edp_panel_on(intel_dp);
2862 edp_panel_vdd_off(intel_dp, true);
2863
2864 pps_unlock(intel_dp);
2865
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002866 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002867 unsigned int lane_mask = 0x0;
2868
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002869 if (IS_CHERRYVIEW(dev_priv))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002870 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002871
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002872 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2873 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002874 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002875
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002876 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2877 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002878 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002879
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002880 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002881 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002882 pipe_name(pipe));
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002883 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Jani Nikulac1dec792014-10-27 16:26:56 +02002884 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002885}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002886
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002887static void g4x_enable_dp(struct intel_encoder *encoder,
2888 struct intel_crtc_state *pipe_config,
2889 struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03002890{
Jani Nikula828f5c62013-09-05 16:44:45 +03002891 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2892
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002893 intel_enable_dp(encoder, pipe_config, conn_state);
Daniel Vetter4be73782014-01-17 14:39:48 +01002894 intel_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002895}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002896
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002897static void vlv_enable_dp(struct intel_encoder *encoder,
2898 struct intel_crtc_state *pipe_config,
2899 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002900{
Jani Nikula828f5c62013-09-05 16:44:45 +03002901 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2902
Daniel Vetter4be73782014-01-17 14:39:48 +01002903 intel_edp_backlight_on(intel_dp);
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002904 intel_psr_enable(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002905}
2906
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002907static void g4x_pre_enable_dp(struct intel_encoder *encoder,
2908 struct intel_crtc_state *pipe_config,
2909 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002910{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002911 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002912 enum port port = dp_to_dig_port(intel_dp)->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002913
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002914 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002915
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002916 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002917 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002918 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002919}
2920
Ville Syrjälä83b84592014-10-16 21:29:51 +03002921static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2922{
2923 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002924 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002925 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03002926 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002927
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002928 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
2929
Ville Syrjäläd1586942017-02-08 19:52:54 +02002930 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2931 return;
2932
Ville Syrjälä83b84592014-10-16 21:29:51 +03002933 edp_panel_vdd_off_sync(intel_dp);
2934
2935 /*
2936 * VLV seems to get confused when multiple power seqeuencers
2937 * have the same port selected (even if only one has power/vdd
2938 * enabled). The failure manifests as vlv_wait_port_ready() failing
2939 * CHV on the other hand doesn't seem to mind having the same port
2940 * selected in multiple power seqeuencers, but let's clear the
2941 * port select always when logically disconnecting a power sequencer
2942 * from a port.
2943 */
2944 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2945 pipe_name(pipe), port_name(intel_dig_port->port));
2946 I915_WRITE(pp_on_reg, 0);
2947 POSTING_READ(pp_on_reg);
2948
2949 intel_dp->pps_pipe = INVALID_PIPE;
2950}
2951
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002952static void vlv_steal_power_sequencer(struct drm_device *dev,
2953 enum pipe pipe)
2954{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002955 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002956 struct intel_encoder *encoder;
2957
2958 lockdep_assert_held(&dev_priv->pps_mutex);
2959
Jani Nikula19c80542015-12-16 12:48:16 +02002960 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002961 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002962 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002963
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002964 if (encoder->type != INTEL_OUTPUT_DP &&
2965 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002966 continue;
2967
2968 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002969 port = dp_to_dig_port(intel_dp)->port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002970
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002971 WARN(intel_dp->active_pipe == pipe,
2972 "stealing pipe %c power sequencer from active (e)DP port %c\n",
2973 pipe_name(pipe), port_name(port));
2974
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002975 if (intel_dp->pps_pipe != pipe)
2976 continue;
2977
2978 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03002979 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002980
2981 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002982 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002983 }
2984}
2985
2986static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
2987{
2988 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2989 struct intel_encoder *encoder = &intel_dig_port->base;
2990 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002991 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002992 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002993
2994 lockdep_assert_held(&dev_priv->pps_mutex);
2995
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002996 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002997
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002998 if (intel_dp->pps_pipe != INVALID_PIPE &&
2999 intel_dp->pps_pipe != crtc->pipe) {
3000 /*
3001 * If another power sequencer was being used on this
3002 * port previously make sure to turn off vdd there while
3003 * we still have control of it.
3004 */
Ville Syrjälä83b84592014-10-16 21:29:51 +03003005 vlv_detach_power_sequencer(intel_dp);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003006 }
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003007
3008 /*
3009 * We may be stealing the power
3010 * sequencer from another port.
3011 */
3012 vlv_steal_power_sequencer(dev, crtc->pipe);
3013
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003014 intel_dp->active_pipe = crtc->pipe;
3015
3016 if (!is_edp(intel_dp))
3017 return;
3018
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003019 /* now it's all ours */
3020 intel_dp->pps_pipe = crtc->pipe;
3021
3022 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
3023 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
3024
3025 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03003026 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02003027 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003028}
3029
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003030static void vlv_pre_enable_dp(struct intel_encoder *encoder,
3031 struct intel_crtc_state *pipe_config,
3032 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03003033{
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03003034 vlv_phy_pre_encoder_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003035
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003036 intel_enable_dp(encoder, pipe_config, conn_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003037}
3038
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003039static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
3040 struct intel_crtc_state *pipe_config,
3041 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07003042{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003043 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02003044
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03003045 vlv_phy_pre_pll_enable(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003046}
3047
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003048static void chv_pre_enable_dp(struct intel_encoder *encoder,
3049 struct intel_crtc_state *pipe_config,
3050 struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003051{
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003052 chv_phy_pre_encoder_enable(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003053
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003054 intel_enable_dp(encoder, pipe_config, conn_state);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03003055
3056 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003057 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003058}
3059
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003060static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
3061 struct intel_crtc_state *pipe_config,
3062 struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03003063{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003064 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03003065
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03003066 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03003067}
3068
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003069static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
3070 struct intel_crtc_state *pipe_config,
3071 struct drm_connector_state *conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003072{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03003073 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003074}
3075
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003076/*
3077 * Fetch AUX CH registers 0x202 - 0x207 which contain
3078 * link status information
3079 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003080bool
Keith Packard93f62da2011-11-01 19:45:03 -07003081intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003082{
Lyude9f085eb2016-04-13 10:58:33 -04003083 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
3084 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003085}
3086
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303087static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp)
3088{
3089 uint8_t psr_caps = 0;
3090
3091 drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps);
3092 return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED;
3093}
3094
3095static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp)
3096{
3097 uint8_t dprx = 0;
3098
3099 drm_dp_dpcd_readb(&intel_dp->aux,
3100 DP_DPRX_FEATURE_ENUMERATION_LIST,
3101 &dprx);
3102 return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED;
3103}
3104
Chris Wilsona76f73d2017-01-14 10:51:13 +00003105static bool intel_dp_get_alpm_status(struct intel_dp *intel_dp)
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303106{
3107 uint8_t alpm_caps = 0;
3108
3109 drm_dp_dpcd_readb(&intel_dp->aux, DP_RECEIVER_ALPM_CAP, &alpm_caps);
3110 return alpm_caps & DP_ALPM_CAP;
3111}
3112
Paulo Zanoni11002442014-06-13 18:45:41 -03003113/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003114uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003115intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003116{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003117 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003118 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003119
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003120 if (IS_GEN9_LP(dev_priv))
Vandana Kannan93147262014-11-18 15:45:29 +05303121 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003122 else if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjäläffe51112017-02-23 19:49:01 +02003123 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3124 return intel_ddi_dp_voltage_max(encoder);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003125 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Sonika Jindalbd600182014-08-08 16:23:41 +05303126 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003127 else if (IS_GEN7(dev_priv) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303128 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003129 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303130 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08003131 else
Sonika Jindalbd600182014-08-08 16:23:41 +05303132 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08003133}
3134
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003135uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003136intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3137{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003138 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003139 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003140
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003141 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003142 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3143 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3144 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3145 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3146 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3147 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3148 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303149 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3150 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003151 default:
3152 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3153 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003154 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003155 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303156 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;
3162 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003163 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303164 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003165 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003166 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003167 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303168 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3169 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3170 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3171 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3172 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3173 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3174 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003175 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303176 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003177 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003178 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003179 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303180 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3181 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3182 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3183 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3184 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003185 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303186 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003187 }
3188 } else {
3189 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303190 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3191 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3192 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3193 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3194 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3195 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3196 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003197 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303198 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003199 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003200 }
3201}
3202
Daniel Vetter5829975c2015-04-16 11:36:52 +02003203static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003204{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003205 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003206 unsigned long demph_reg_value, preemph_reg_value,
3207 uniqtranscale_reg_value;
3208 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003209
3210 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303211 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003212 preemph_reg_value = 0x0004000;
3213 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303214 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003215 demph_reg_value = 0x2B405555;
3216 uniqtranscale_reg_value = 0x552AB83A;
3217 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303218 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003219 demph_reg_value = 0x2B404040;
3220 uniqtranscale_reg_value = 0x5548B83A;
3221 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303222 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003223 demph_reg_value = 0x2B245555;
3224 uniqtranscale_reg_value = 0x5560B83A;
3225 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303226 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003227 demph_reg_value = 0x2B405555;
3228 uniqtranscale_reg_value = 0x5598DA3A;
3229 break;
3230 default:
3231 return 0;
3232 }
3233 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303234 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003235 preemph_reg_value = 0x0002000;
3236 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303237 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003238 demph_reg_value = 0x2B404040;
3239 uniqtranscale_reg_value = 0x5552B83A;
3240 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303241 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003242 demph_reg_value = 0x2B404848;
3243 uniqtranscale_reg_value = 0x5580B83A;
3244 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303245 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003246 demph_reg_value = 0x2B404040;
3247 uniqtranscale_reg_value = 0x55ADDA3A;
3248 break;
3249 default:
3250 return 0;
3251 }
3252 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303253 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003254 preemph_reg_value = 0x0000000;
3255 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303256 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003257 demph_reg_value = 0x2B305555;
3258 uniqtranscale_reg_value = 0x5570B83A;
3259 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303260 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003261 demph_reg_value = 0x2B2B4040;
3262 uniqtranscale_reg_value = 0x55ADDA3A;
3263 break;
3264 default:
3265 return 0;
3266 }
3267 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303268 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003269 preemph_reg_value = 0x0006000;
3270 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303271 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003272 demph_reg_value = 0x1B405555;
3273 uniqtranscale_reg_value = 0x55ADDA3A;
3274 break;
3275 default:
3276 return 0;
3277 }
3278 break;
3279 default:
3280 return 0;
3281 }
3282
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003283 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3284 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003285
3286 return 0;
3287}
3288
Daniel Vetter5829975c2015-04-16 11:36:52 +02003289static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003290{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003291 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3292 u32 deemph_reg_value, margin_reg_value;
3293 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003294 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003295
3296 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303297 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003298 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303299 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003300 deemph_reg_value = 128;
3301 margin_reg_value = 52;
3302 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303303 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003304 deemph_reg_value = 128;
3305 margin_reg_value = 77;
3306 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303307 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003308 deemph_reg_value = 128;
3309 margin_reg_value = 102;
3310 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303311 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003312 deemph_reg_value = 128;
3313 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003314 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003315 break;
3316 default:
3317 return 0;
3318 }
3319 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303320 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003321 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303322 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003323 deemph_reg_value = 85;
3324 margin_reg_value = 78;
3325 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303326 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003327 deemph_reg_value = 85;
3328 margin_reg_value = 116;
3329 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303330 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003331 deemph_reg_value = 85;
3332 margin_reg_value = 154;
3333 break;
3334 default:
3335 return 0;
3336 }
3337 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303338 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003339 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303340 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003341 deemph_reg_value = 64;
3342 margin_reg_value = 104;
3343 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303344 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003345 deemph_reg_value = 64;
3346 margin_reg_value = 154;
3347 break;
3348 default:
3349 return 0;
3350 }
3351 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303352 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003353 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303354 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003355 deemph_reg_value = 43;
3356 margin_reg_value = 154;
3357 break;
3358 default:
3359 return 0;
3360 }
3361 break;
3362 default:
3363 return 0;
3364 }
3365
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003366 chv_set_phy_signal_level(encoder, deemph_reg_value,
3367 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003368
3369 return 0;
3370}
3371
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003372static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003373gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003374{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003375 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003376
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003377 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303378 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003379 default:
3380 signal_levels |= DP_VOLTAGE_0_4;
3381 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303382 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003383 signal_levels |= DP_VOLTAGE_0_6;
3384 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303385 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003386 signal_levels |= DP_VOLTAGE_0_8;
3387 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303388 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003389 signal_levels |= DP_VOLTAGE_1_2;
3390 break;
3391 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003392 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303393 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003394 default:
3395 signal_levels |= DP_PRE_EMPHASIS_0;
3396 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303397 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003398 signal_levels |= DP_PRE_EMPHASIS_3_5;
3399 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303400 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003401 signal_levels |= DP_PRE_EMPHASIS_6;
3402 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303403 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003404 signal_levels |= DP_PRE_EMPHASIS_9_5;
3405 break;
3406 }
3407 return signal_levels;
3408}
3409
Zhenyu Wange3421a12010-04-08 09:43:27 +08003410/* Gen6's DP voltage swing and pre-emphasis control */
3411static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003412gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003413{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003414 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3415 DP_TRAIN_PRE_EMPHASIS_MASK);
3416 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303417 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3418 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003419 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303420 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003421 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303422 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3423 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003424 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303425 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3426 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003427 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303428 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3429 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003430 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003431 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003432 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3433 "0x%x\n", signal_levels);
3434 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003435 }
3436}
3437
Keith Packard1a2eb462011-11-16 16:26:07 -08003438/* Gen7's DP voltage swing and pre-emphasis control */
3439static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003440gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003441{
3442 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3443 DP_TRAIN_PRE_EMPHASIS_MASK);
3444 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303445 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003446 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303447 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003448 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303449 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003450 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3451
Sonika Jindalbd600182014-08-08 16:23:41 +05303452 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003453 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303454 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003455 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3456
Sonika Jindalbd600182014-08-08 16:23:41 +05303457 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003458 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303459 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003460 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3461
3462 default:
3463 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3464 "0x%x\n", signal_levels);
3465 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3466 }
3467}
3468
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003469void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003470intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003471{
3472 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003473 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003474 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003475 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003476 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003477 uint8_t train_set = intel_dp->train_set[0];
3478
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003479 if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003480 signal_levels = ddi_signal_levels(intel_dp);
3481
Michel Thierry254e0932017-01-09 16:51:35 +02003482 if (IS_GEN9_LP(dev_priv))
David Weinehallf8896f52015-06-25 11:11:03 +03003483 signal_levels = 0;
3484 else
3485 mask = DDI_BUF_EMP_MASK;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003486 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003487 signal_levels = chv_signal_levels(intel_dp);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003488 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003489 signal_levels = vlv_signal_levels(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003490 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003491 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003492 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003493 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003494 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003495 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3496 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003497 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003498 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3499 }
3500
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303501 if (mask)
3502 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3503
3504 DRM_DEBUG_KMS("Using vswing level %d\n",
3505 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3506 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3507 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3508 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003509
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003510 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003511
3512 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3513 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003514}
3515
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003516void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003517intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3518 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003519{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003520 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003521 struct drm_i915_private *dev_priv =
3522 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003523
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003524 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003525
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003526 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003527 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003528}
3529
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003530void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003531{
3532 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3533 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003534 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak3ab9c632013-05-03 12:57:41 +03003535 enum port port = intel_dig_port->port;
3536 uint32_t val;
3537
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003538 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003539 return;
3540
3541 val = I915_READ(DP_TP_CTL(port));
3542 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3543 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3544 I915_WRITE(DP_TP_CTL(port), val);
3545
3546 /*
3547 * On PORT_A we can have only eDP in SST mode. There the only reason
3548 * we need to set idle transmission mode is to work around a HW issue
3549 * where we enable the pipe while not in idle link-training mode.
3550 * In this case there is requirement to wait for a minimum number of
3551 * idle patterns to be sent.
3552 */
3553 if (port == PORT_A)
3554 return;
3555
Chris Wilsona7670172016-06-30 15:33:10 +01003556 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3557 DP_TP_STATUS_IDLE_DONE,
3558 DP_TP_STATUS_IDLE_DONE,
3559 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003560 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3561}
3562
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003563static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003564intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003565{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003566 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003567 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003568 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003569 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003570 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003571 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003572
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003573 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003574 return;
3575
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003576 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003577 return;
3578
Zhao Yakui28c97732009-10-09 11:39:41 +08003579 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003580
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003581 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003582 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003583 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003584 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003585 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003586 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003587 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3588 else
3589 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003590 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003591 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003592 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003593 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003594
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003595 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3596 I915_WRITE(intel_dp->output_reg, DP);
3597 POSTING_READ(intel_dp->output_reg);
3598
3599 /*
3600 * HW workaround for IBX, we need to move the port
3601 * to transcoder A after disabling it to allow the
3602 * matching HDMI port to be enabled on transcoder A.
3603 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003604 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003605 /*
3606 * We get CPU/PCH FIFO underruns on the other pipe when
3607 * doing the workaround. Sweep them under the rug.
3608 */
3609 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3610 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3611
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003612 /* always enable with pattern 1 (as per spec) */
3613 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3614 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3615 I915_WRITE(intel_dp->output_reg, DP);
3616 POSTING_READ(intel_dp->output_reg);
3617
3618 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003619 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003620 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003621
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003622 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003623 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3624 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003625 }
3626
Keith Packardf01eca22011-09-28 16:48:10 -07003627 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003628
3629 intel_dp->DP = DP;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003630
3631 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3632 pps_lock(intel_dp);
3633 intel_dp->active_pipe = INVALID_PIPE;
3634 pps_unlock(intel_dp);
3635 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003636}
3637
Imre Deak24e807e2016-10-24 19:33:28 +03003638bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003639intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003640{
Lyude9f085eb2016-04-13 10:58:33 -04003641 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3642 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003643 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003644
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003645 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003646
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003647 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3648}
3649
3650static bool
3651intel_edp_init_dpcd(struct intel_dp *intel_dp)
3652{
3653 struct drm_i915_private *dev_priv =
3654 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3655
3656 /* this function is meant to be called only once */
3657 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3658
3659 if (!intel_dp_read_dpcd(intel_dp))
3660 return false;
3661
Imre Deak12a47a422016-10-24 19:33:29 +03003662 intel_dp_read_desc(intel_dp);
3663
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003664 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3665 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3666 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3667
3668 /* Check if the panel supports PSR */
3669 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3670 intel_dp->psr_dpcd,
3671 sizeof(intel_dp->psr_dpcd));
3672 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3673 dev_priv->psr.sink_support = true;
3674 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3675 }
3676
3677 if (INTEL_GEN(dev_priv) >= 9 &&
3678 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3679 uint8_t frame_sync_cap;
3680
3681 dev_priv->psr.sink_support = true;
Jani Nikula010b9b32017-04-06 16:44:16 +03003682 drm_dp_dpcd_readb(&intel_dp->aux,
3683 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3684 &frame_sync_cap);
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003685 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3686 /* PSR2 needs frame sync as well */
3687 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3688 DRM_DEBUG_KMS("PSR2 %s on sink",
3689 dev_priv->psr.psr2_support ? "supported" : "not supported");
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303690
3691 if (dev_priv->psr.psr2_support) {
3692 dev_priv->psr.y_cord_support =
3693 intel_dp_get_y_cord_status(intel_dp);
3694 dev_priv->psr.colorimetry_support =
3695 intel_dp_get_colorimetry_status(intel_dp);
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303696 dev_priv->psr.alpm =
3697 intel_dp_get_alpm_status(intel_dp);
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303698 }
3699
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003700 }
3701
3702 /* Read the eDP Display control capabilities registers */
3703 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
3704 drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003705 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3706 sizeof(intel_dp->edp_dpcd))
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003707 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3708 intel_dp->edp_dpcd);
3709
3710 /* Intermediate frequency support */
3711 if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */
3712 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3713 int i;
3714
3715 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3716 sink_rates, sizeof(sink_rates));
3717
3718 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3719 int val = le16_to_cpu(sink_rates[i]);
3720
3721 if (val == 0)
3722 break;
3723
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -08003724 /* Value read multiplied by 200kHz gives the per-lane
3725 * link rate in kHz. The source rates are, however,
3726 * stored in terms of LS_Clk kHz. The full conversion
3727 * back to symbols is
3728 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
3729 */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003730 intel_dp->sink_rates[i] = (val * 200) / 10;
3731 }
3732 intel_dp->num_sink_rates = i;
3733 }
3734
Jani Nikula68f357c2017-03-28 17:59:05 +03003735 if (intel_dp->num_sink_rates)
3736 intel_dp->use_rate_select = true;
3737 else
3738 intel_dp_set_sink_rates(intel_dp);
3739
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003740 intel_dp_set_common_rates(intel_dp);
3741
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003742 return true;
3743}
3744
3745
3746static bool
3747intel_dp_get_dpcd(struct intel_dp *intel_dp)
3748{
Jani Nikula27dbefb2017-04-06 16:44:17 +03003749 u8 sink_count;
3750
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003751 if (!intel_dp_read_dpcd(intel_dp))
3752 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003753
Jani Nikula68f357c2017-03-28 17:59:05 +03003754 /* Don't clobber cached eDP rates. */
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003755 if (!is_edp(intel_dp)) {
Jani Nikula68f357c2017-03-28 17:59:05 +03003756 intel_dp_set_sink_rates(intel_dp);
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003757 intel_dp_set_common_rates(intel_dp);
3758 }
Jani Nikula68f357c2017-03-28 17:59:05 +03003759
Jani Nikula27dbefb2017-04-06 16:44:17 +03003760 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_SINK_COUNT, &sink_count) <= 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303761 return false;
3762
3763 /*
3764 * Sink count can change between short pulse hpd hence
3765 * a member variable in intel_dp will track any changes
3766 * between short pulse interrupts.
3767 */
Jani Nikula27dbefb2017-04-06 16:44:17 +03003768 intel_dp->sink_count = DP_GET_SINK_COUNT(sink_count);
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303769
3770 /*
3771 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3772 * a dongle is present but no display. Unless we require to know
3773 * if a dongle is present or not, we don't need to update
3774 * downstream port information. So, an early return here saves
3775 * time from performing other operations which are not required.
3776 */
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05303777 if (!is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303778 return false;
3779
Imre Deakc726ad02016-10-24 19:33:24 +03003780 if (!drm_dp_is_branch(intel_dp->dpcd))
Adam Jacksonedb39242012-09-18 10:58:49 -04003781 return true; /* native DP sink */
3782
3783 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3784 return true; /* no per-port downstream info */
3785
Lyude9f085eb2016-04-13 10:58:33 -04003786 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3787 intel_dp->downstream_ports,
3788 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003789 return false; /* downstream port status fetch failed */
3790
3791 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003792}
3793
Dave Airlie0e32b392014-05-02 14:02:48 +10003794static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003795intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003796{
Jani Nikula010b9b32017-04-06 16:44:16 +03003797 u8 mstm_cap;
Dave Airlie0e32b392014-05-02 14:02:48 +10003798
Nathan Schulte7cc96132016-03-15 10:14:05 -05003799 if (!i915.enable_dp_mst)
3800 return false;
3801
Dave Airlie0e32b392014-05-02 14:02:48 +10003802 if (!intel_dp->can_mst)
3803 return false;
3804
3805 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3806 return false;
3807
Jani Nikula010b9b32017-04-06 16:44:16 +03003808 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_MSTM_CAP, &mstm_cap) != 1)
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003809 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003810
Jani Nikula010b9b32017-04-06 16:44:16 +03003811 return mstm_cap & DP_MST_CAP;
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003812}
3813
3814static void
3815intel_dp_configure_mst(struct intel_dp *intel_dp)
3816{
3817 if (!i915.enable_dp_mst)
3818 return;
3819
3820 if (!intel_dp->can_mst)
3821 return;
3822
3823 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3824
3825 if (intel_dp->is_mst)
3826 DRM_DEBUG_KMS("Sink is MST capable\n");
3827 else
3828 DRM_DEBUG_KMS("Sink is not MST capable\n");
3829
3830 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3831 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003832}
3833
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003834static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003835{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003836 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003837 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003838 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003839 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003840 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003841 int count = 0;
3842 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003843
3844 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003845 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003846 ret = -EIO;
3847 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003848 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003849
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003850 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003851 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003852 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003853 ret = -EIO;
3854 goto out;
3855 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003856
Rodrigo Vivic6297842015-11-05 10:50:20 -08003857 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003858 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivic6297842015-11-05 10:50:20 -08003859
3860 if (drm_dp_dpcd_readb(&intel_dp->aux,
3861 DP_TEST_SINK_MISC, &buf) < 0) {
3862 ret = -EIO;
3863 goto out;
3864 }
3865 count = buf & DP_TEST_COUNT_MASK;
3866 } while (--attempts && count);
3867
3868 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003869 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003870 ret = -ETIMEDOUT;
3871 }
3872
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003873 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003874 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003875 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003876}
3877
3878static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3879{
3880 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003881 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003882 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3883 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003884 int ret;
3885
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003886 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3887 return -EIO;
3888
3889 if (!(buf & DP_TEST_CRC_SUPPORTED))
3890 return -ENOTTY;
3891
3892 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3893 return -EIO;
3894
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003895 if (buf & DP_TEST_SINK_START) {
3896 ret = intel_dp_sink_crc_stop(intel_dp);
3897 if (ret)
3898 return ret;
3899 }
3900
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003901 hsw_disable_ips(intel_crtc);
3902
3903 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3904 buf | DP_TEST_SINK_START) < 0) {
3905 hsw_enable_ips(intel_crtc);
3906 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003907 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003908
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003909 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003910 return 0;
3911}
3912
3913int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3914{
3915 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003916 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003917 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3918 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003919 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003920 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003921
3922 ret = intel_dp_sink_crc_start(intel_dp);
3923 if (ret)
3924 return ret;
3925
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003926 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003927 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003928
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003929 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003930 DP_TEST_SINK_MISC, &buf) < 0) {
3931 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003932 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003933 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003934 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07003935
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003936 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003937
3938 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003939 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
3940 ret = -ETIMEDOUT;
3941 goto stop;
3942 }
3943
3944 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
3945 ret = -EIO;
3946 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003947 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003948
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003949stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003950 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003951 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003952}
3953
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003954static bool
3955intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3956{
Jani Nikula010b9b32017-04-06 16:44:16 +03003957 return drm_dp_dpcd_readb(&intel_dp->aux, DP_DEVICE_SERVICE_IRQ_VECTOR,
3958 sink_irq_vector) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003959}
3960
Dave Airlie0e32b392014-05-02 14:02:48 +10003961static bool
3962intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3963{
3964 int ret;
3965
Lyude9f085eb2016-04-13 10:58:33 -04003966 ret = drm_dp_dpcd_read(&intel_dp->aux,
Dave Airlie0e32b392014-05-02 14:02:48 +10003967 DP_SINK_COUNT_ESI,
3968 sink_irq_vector, 14);
3969 if (ret != 14)
3970 return false;
3971
3972 return true;
3973}
3974
Todd Previtec5d5ab72015-04-15 08:38:38 -07003975static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003976{
Manasi Navareda15f7c2017-01-24 08:16:34 -08003977 int status = 0;
3978 int min_lane_count = 1;
Manasi Navareda15f7c2017-01-24 08:16:34 -08003979 int link_rate_index, test_link_rate;
3980 uint8_t test_lane_count, test_link_bw;
3981 /* (DP CTS 1.2)
3982 * 4.3.1.11
3983 */
3984 /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */
3985 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT,
3986 &test_lane_count);
3987
3988 if (status <= 0) {
3989 DRM_DEBUG_KMS("Lane count read failed\n");
3990 return DP_TEST_NAK;
3991 }
3992 test_lane_count &= DP_MAX_LANE_COUNT_MASK;
3993 /* Validate the requested lane count */
3994 if (test_lane_count < min_lane_count ||
Jani Nikulae6c0c642017-04-06 16:44:12 +03003995 test_lane_count > intel_dp->max_link_lane_count)
Manasi Navareda15f7c2017-01-24 08:16:34 -08003996 return DP_TEST_NAK;
3997
3998 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE,
3999 &test_link_bw);
4000 if (status <= 0) {
4001 DRM_DEBUG_KMS("Link Rate read failed\n");
4002 return DP_TEST_NAK;
4003 }
4004 /* Validate the requested link rate */
4005 test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw);
Jani Nikulab1810a72017-04-06 16:44:11 +03004006 link_rate_index = intel_dp_rate_index(intel_dp->common_rates,
4007 intel_dp->num_common_rates,
4008 test_link_rate);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004009 if (link_rate_index < 0)
4010 return DP_TEST_NAK;
4011
4012 intel_dp->compliance.test_lane_count = test_lane_count;
4013 intel_dp->compliance.test_link_rate = test_link_rate;
4014
4015 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004016}
4017
4018static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
4019{
Manasi Navare611032b2017-01-24 08:21:49 -08004020 uint8_t test_pattern;
Jani Nikula010b9b32017-04-06 16:44:16 +03004021 uint8_t test_misc;
Manasi Navare611032b2017-01-24 08:21:49 -08004022 __be16 h_width, v_height;
4023 int status = 0;
4024
4025 /* Read the TEST_PATTERN (DP CTS 3.1.5) */
Jani Nikula010b9b32017-04-06 16:44:16 +03004026 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_PATTERN,
4027 &test_pattern);
Manasi Navare611032b2017-01-24 08:21:49 -08004028 if (status <= 0) {
4029 DRM_DEBUG_KMS("Test pattern read failed\n");
4030 return DP_TEST_NAK;
4031 }
4032 if (test_pattern != DP_COLOR_RAMP)
4033 return DP_TEST_NAK;
4034
4035 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI,
4036 &h_width, 2);
4037 if (status <= 0) {
4038 DRM_DEBUG_KMS("H Width read failed\n");
4039 return DP_TEST_NAK;
4040 }
4041
4042 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI,
4043 &v_height, 2);
4044 if (status <= 0) {
4045 DRM_DEBUG_KMS("V Height read failed\n");
4046 return DP_TEST_NAK;
4047 }
4048
Jani Nikula010b9b32017-04-06 16:44:16 +03004049 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_MISC0,
4050 &test_misc);
Manasi Navare611032b2017-01-24 08:21:49 -08004051 if (status <= 0) {
4052 DRM_DEBUG_KMS("TEST MISC read failed\n");
4053 return DP_TEST_NAK;
4054 }
4055 if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB)
4056 return DP_TEST_NAK;
4057 if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA)
4058 return DP_TEST_NAK;
4059 switch (test_misc & DP_TEST_BIT_DEPTH_MASK) {
4060 case DP_TEST_BIT_DEPTH_6:
4061 intel_dp->compliance.test_data.bpc = 6;
4062 break;
4063 case DP_TEST_BIT_DEPTH_8:
4064 intel_dp->compliance.test_data.bpc = 8;
4065 break;
4066 default:
4067 return DP_TEST_NAK;
4068 }
4069
4070 intel_dp->compliance.test_data.video_pattern = test_pattern;
4071 intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width);
4072 intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height);
4073 /* Set test active flag here so userspace doesn't interrupt things */
4074 intel_dp->compliance.test_active = 1;
4075
4076 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004077}
4078
4079static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
4080{
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004081 uint8_t test_result = DP_TEST_ACK;
Todd Previte559be302015-05-04 07:48:20 -07004082 struct intel_connector *intel_connector = intel_dp->attached_connector;
4083 struct drm_connector *connector = &intel_connector->base;
4084
4085 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02004086 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07004087 intel_dp->aux.i2c_defer_count > 6) {
4088 /* Check EDID read for NACKs, DEFERs and corruption
4089 * (DP CTS 1.2 Core r1.1)
4090 * 4.2.2.4 : Failed EDID read, I2C_NAK
4091 * 4.2.2.5 : Failed EDID read, I2C_DEFER
4092 * 4.2.2.6 : EDID corruption detected
4093 * Use failsafe mode for all cases
4094 */
4095 if (intel_dp->aux.i2c_nack_count > 0 ||
4096 intel_dp->aux.i2c_defer_count > 0)
4097 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
4098 intel_dp->aux.i2c_nack_count,
4099 intel_dp->aux.i2c_defer_count);
Manasi Navarec1617ab2016-12-09 16:22:50 -08004100 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
Todd Previte559be302015-05-04 07:48:20 -07004101 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05304102 struct edid *block = intel_connector->detect_edid;
4103
4104 /* We have to write the checksum
4105 * of the last block read
4106 */
4107 block += intel_connector->detect_edid->extensions;
4108
Jani Nikula010b9b32017-04-06 16:44:16 +03004109 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_EDID_CHECKSUM,
4110 block->checksum) <= 0)
Todd Previte559be302015-05-04 07:48:20 -07004111 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
4112
4113 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004114 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED;
Todd Previte559be302015-05-04 07:48:20 -07004115 }
4116
4117 /* Set test active flag here so userspace doesn't interrupt things */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004118 intel_dp->compliance.test_active = 1;
Todd Previte559be302015-05-04 07:48:20 -07004119
Todd Previtec5d5ab72015-04-15 08:38:38 -07004120 return test_result;
4121}
4122
4123static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
4124{
4125 uint8_t test_result = DP_TEST_NAK;
4126 return test_result;
4127}
4128
4129static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
4130{
4131 uint8_t response = DP_TEST_NAK;
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004132 uint8_t request = 0;
4133 int status;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004134
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004135 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004136 if (status <= 0) {
4137 DRM_DEBUG_KMS("Could not read test request from sink\n");
4138 goto update_status;
4139 }
4140
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004141 switch (request) {
Todd Previtec5d5ab72015-04-15 08:38:38 -07004142 case DP_TEST_LINK_TRAINING:
4143 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004144 response = intel_dp_autotest_link_training(intel_dp);
4145 break;
4146 case DP_TEST_LINK_VIDEO_PATTERN:
4147 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004148 response = intel_dp_autotest_video_pattern(intel_dp);
4149 break;
4150 case DP_TEST_LINK_EDID_READ:
4151 DRM_DEBUG_KMS("EDID test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004152 response = intel_dp_autotest_edid(intel_dp);
4153 break;
4154 case DP_TEST_LINK_PHY_TEST_PATTERN:
4155 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004156 response = intel_dp_autotest_phy_pattern(intel_dp);
4157 break;
4158 default:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004159 DRM_DEBUG_KMS("Invalid test request '%02x'\n", request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004160 break;
4161 }
4162
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004163 if (response & DP_TEST_ACK)
4164 intel_dp->compliance.test_type = request;
4165
Todd Previtec5d5ab72015-04-15 08:38:38 -07004166update_status:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004167 status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004168 if (status <= 0)
4169 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004170}
4171
Dave Airlie0e32b392014-05-02 14:02:48 +10004172static int
4173intel_dp_check_mst_status(struct intel_dp *intel_dp)
4174{
4175 bool bret;
4176
4177 if (intel_dp->is_mst) {
4178 u8 esi[16] = { 0 };
4179 int ret = 0;
4180 int retry;
4181 bool handled;
4182 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4183go_again:
4184 if (bret == true) {
4185
4186 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03004187 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03004188 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10004189 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4190 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004191 intel_dp_stop_link_train(intel_dp);
4192 }
4193
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004194 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004195 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4196
4197 if (handled) {
4198 for (retry = 0; retry < 3; retry++) {
4199 int wret;
4200 wret = drm_dp_dpcd_write(&intel_dp->aux,
4201 DP_SINK_COUNT_ESI+1,
4202 &esi[1], 3);
4203 if (wret == 3) {
4204 break;
4205 }
4206 }
4207
4208 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4209 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004210 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004211 goto go_again;
4212 }
4213 } else
4214 ret = 0;
4215
4216 return ret;
4217 } else {
4218 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4219 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4220 intel_dp->is_mst = false;
4221 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4222 /* send a hotplug event */
4223 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4224 }
4225 }
4226 return -EINVAL;
4227}
4228
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304229static void
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004230intel_dp_retrain_link(struct intel_dp *intel_dp)
4231{
4232 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4233 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4234 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
4235
4236 /* Suppress underruns caused by re-training */
4237 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4238 if (crtc->config->has_pch_encoder)
4239 intel_set_pch_fifo_underrun_reporting(dev_priv,
4240 intel_crtc_pch_transcoder(crtc), false);
4241
4242 intel_dp_start_link_train(intel_dp);
4243 intel_dp_stop_link_train(intel_dp);
4244
4245 /* Keep underrun reporting disabled until things are stable */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02004246 intel_wait_for_vblank(dev_priv, crtc->pipe);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004247
4248 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4249 if (crtc->config->has_pch_encoder)
4250 intel_set_pch_fifo_underrun_reporting(dev_priv,
4251 intel_crtc_pch_transcoder(crtc), true);
4252}
4253
4254static void
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304255intel_dp_check_link_status(struct intel_dp *intel_dp)
4256{
4257 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4258 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4259 u8 link_status[DP_LINK_STATUS_SIZE];
4260
4261 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
4262
4263 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4264 DRM_ERROR("Failed to get link status\n");
4265 return;
4266 }
4267
4268 if (!intel_encoder->base.crtc)
4269 return;
4270
4271 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4272 return;
4273
Manasi Navare14c562c2017-04-06 14:00:12 -07004274 /*
4275 * Validate the cached values of intel_dp->link_rate and
4276 * intel_dp->lane_count before attempting to retrain.
4277 */
4278 if (!intel_dp_link_params_valid(intel_dp))
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004279 return;
4280
Manasi Navareda15f7c2017-01-24 08:16:34 -08004281 /* Retrain if Channel EQ or CR not ok */
4282 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304283 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4284 intel_encoder->base.name);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004285
4286 intel_dp_retrain_link(intel_dp);
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304287 }
4288}
4289
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004290/*
4291 * According to DP spec
4292 * 5.1.2:
4293 * 1. Read DPCD
4294 * 2. Configure link according to Receiver Capabilities
4295 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4296 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304297 *
4298 * intel_dp_short_pulse - handles short pulse interrupts
4299 * when full detection is not required.
4300 * Returns %true if short pulse is handled and full detection
4301 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004302 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304303static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304304intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004305{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004306 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004307 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004308 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304309 u8 old_sink_count = intel_dp->sink_count;
4310 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004311
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304312 /*
4313 * Clearing compliance test variables to allow capturing
4314 * of values for next automated test request.
4315 */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004316 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304317
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304318 /*
4319 * Now read the DPCD to see if it's actually running
4320 * If the current value of sink count doesn't match with
4321 * the value that was stored earlier or dpcd read failed
4322 * we need to do full detection
4323 */
4324 ret = intel_dp_get_dpcd(intel_dp);
4325
4326 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4327 /* No need to proceed if we are going to do full detect */
4328 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004329 }
4330
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004331 /* Try to read the source of the interrupt */
4332 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004333 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4334 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004335 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004336 drm_dp_dpcd_writeb(&intel_dp->aux,
4337 DP_DEVICE_SERVICE_IRQ_VECTOR,
4338 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004339
4340 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Manasi Navareda15f7c2017-01-24 08:16:34 -08004341 intel_dp_handle_test_request(intel_dp);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004342 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4343 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4344 }
4345
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304346 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4347 intel_dp_check_link_status(intel_dp);
4348 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004349 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
4350 DRM_DEBUG_KMS("Link Training Compliance Test requested\n");
4351 /* Send a Hotplug Uevent to userspace to start modeset */
4352 drm_kms_helper_hotplug_event(intel_encoder->base.dev);
4353 }
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304354
4355 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004356}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004357
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004358/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004359static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004360intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004361{
Imre Deake393d0d2017-02-22 17:10:52 +02004362 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004363 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004364 uint8_t type;
4365
Imre Deake393d0d2017-02-22 17:10:52 +02004366 if (lspcon->active)
4367 lspcon_resume(lspcon);
4368
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004369 if (!intel_dp_get_dpcd(intel_dp))
4370 return connector_status_disconnected;
4371
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304372 if (is_edp(intel_dp))
4373 return connector_status_connected;
4374
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004375 /* if there's no downstream port, we're done */
Imre Deakc726ad02016-10-24 19:33:24 +03004376 if (!drm_dp_is_branch(dpcd))
Keith Packard26d61aa2011-07-25 20:01:09 -07004377 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004378
4379 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004380 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4381 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004382
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304383 return intel_dp->sink_count ?
4384 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004385 }
4386
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004387 if (intel_dp_can_mst(intel_dp))
4388 return connector_status_connected;
4389
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004390 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004391 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004392 return connector_status_connected;
4393
4394 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004395 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4396 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4397 if (type == DP_DS_PORT_TYPE_VGA ||
4398 type == DP_DS_PORT_TYPE_NON_EDID)
4399 return connector_status_unknown;
4400 } else {
4401 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4402 DP_DWN_STRM_PORT_TYPE_MASK;
4403 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4404 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4405 return connector_status_unknown;
4406 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004407
4408 /* Anything else is out of spec, warn and ignore */
4409 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004410 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004411}
4412
4413static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004414edp_detect(struct intel_dp *intel_dp)
4415{
4416 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Mika Kahola1650be72016-12-13 10:02:47 +02004417 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsond410b562014-09-02 20:03:59 +01004418 enum drm_connector_status status;
4419
Mika Kahola1650be72016-12-13 10:02:47 +02004420 status = intel_panel_detect(dev_priv);
Chris Wilsond410b562014-09-02 20:03:59 +01004421 if (status == connector_status_unknown)
4422 status = connector_status_connected;
4423
4424 return status;
4425}
4426
Jani Nikulab93433c2015-08-20 10:47:36 +03004427static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4428 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004429{
Jani Nikulab93433c2015-08-20 10:47:36 +03004430 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004431
Jani Nikula0df53b72015-08-20 10:47:40 +03004432 switch (port->port) {
4433 case PORT_A:
4434 return true;
4435 case PORT_B:
4436 bit = SDE_PORTB_HOTPLUG;
4437 break;
4438 case PORT_C:
4439 bit = SDE_PORTC_HOTPLUG;
4440 break;
4441 case PORT_D:
4442 bit = SDE_PORTD_HOTPLUG;
4443 break;
4444 default:
4445 MISSING_CASE(port->port);
4446 return false;
4447 }
4448
4449 return I915_READ(SDEISR) & bit;
4450}
4451
4452static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4453 struct intel_digital_port *port)
4454{
4455 u32 bit;
4456
4457 switch (port->port) {
4458 case PORT_A:
4459 return true;
4460 case PORT_B:
4461 bit = SDE_PORTB_HOTPLUG_CPT;
4462 break;
4463 case PORT_C:
4464 bit = SDE_PORTC_HOTPLUG_CPT;
4465 break;
4466 case PORT_D:
4467 bit = SDE_PORTD_HOTPLUG_CPT;
4468 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004469 case PORT_E:
4470 bit = SDE_PORTE_HOTPLUG_SPT;
4471 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004472 default:
4473 MISSING_CASE(port->port);
4474 return false;
Jani Nikulab93433c2015-08-20 10:47:36 +03004475 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004476
Jani Nikulab93433c2015-08-20 10:47:36 +03004477 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004478}
4479
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004480static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004481 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004482{
Jani Nikula9642c812015-08-20 10:47:41 +03004483 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004484
Jani Nikula9642c812015-08-20 10:47:41 +03004485 switch (port->port) {
4486 case PORT_B:
4487 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4488 break;
4489 case PORT_C:
4490 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4491 break;
4492 case PORT_D:
4493 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4494 break;
4495 default:
4496 MISSING_CASE(port->port);
4497 return false;
4498 }
4499
4500 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4501}
4502
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004503static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4504 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004505{
4506 u32 bit;
4507
4508 switch (port->port) {
4509 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004510 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004511 break;
4512 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004513 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004514 break;
4515 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004516 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004517 break;
4518 default:
4519 MISSING_CASE(port->port);
4520 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004521 }
4522
Jani Nikula1d245982015-08-20 10:47:37 +03004523 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004524}
4525
Jani Nikulae464bfd2015-08-20 10:47:42 +03004526static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304527 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004528{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304529 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4530 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004531 u32 bit;
4532
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304533 intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port);
4534 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004535 case PORT_A:
4536 bit = BXT_DE_PORT_HP_DDIA;
4537 break;
4538 case PORT_B:
4539 bit = BXT_DE_PORT_HP_DDIB;
4540 break;
4541 case PORT_C:
4542 bit = BXT_DE_PORT_HP_DDIC;
4543 break;
4544 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304545 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004546 return false;
4547 }
4548
4549 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4550}
4551
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004552/*
4553 * intel_digital_port_connected - is the specified port connected?
4554 * @dev_priv: i915 private structure
4555 * @port: the port to test
4556 *
4557 * Return %true if @port is connected, %false otherwise.
4558 */
Imre Deak390b4e02017-01-27 11:39:19 +02004559bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
4560 struct intel_digital_port *port)
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004561{
Jani Nikula0df53b72015-08-20 10:47:40 +03004562 if (HAS_PCH_IBX(dev_priv))
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004563 return ibx_digital_port_connected(dev_priv, port);
Ville Syrjälä22824fa2016-02-11 16:44:28 +02004564 else if (HAS_PCH_SPLIT(dev_priv))
Jani Nikula0df53b72015-08-20 10:47:40 +03004565 return cpt_digital_port_connected(dev_priv, port);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004566 else if (IS_GEN9_LP(dev_priv))
Jani Nikulae464bfd2015-08-20 10:47:42 +03004567 return bxt_digital_port_connected(dev_priv, port);
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004568 else if (IS_GM45(dev_priv))
4569 return gm45_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004570 else
4571 return g4x_digital_port_connected(dev_priv, port);
4572}
4573
Keith Packard8c241fe2011-09-28 16:38:44 -07004574static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004575intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004576{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004577 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004578
Jani Nikula9cd300e2012-10-19 14:51:52 +03004579 /* use cached edid if we have one */
4580 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004581 /* invalid edid */
4582 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004583 return NULL;
4584
Jani Nikula55e9ede2013-10-01 10:38:54 +03004585 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004586 } else
4587 return drm_get_edid(&intel_connector->base,
4588 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004589}
4590
Chris Wilsonbeb60602014-09-02 20:04:00 +01004591static void
4592intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004593{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004594 struct intel_connector *intel_connector = intel_dp->attached_connector;
4595 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004596
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304597 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004598 edid = intel_dp_get_edid(intel_dp);
4599 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004600
Chris Wilsonbeb60602014-09-02 20:04:00 +01004601 if (intel_dp->force_audio != HDMI_AUDIO_AUTO)
4602 intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON;
4603 else
4604 intel_dp->has_audio = drm_detect_monitor_audio(edid);
4605}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004606
Chris Wilsonbeb60602014-09-02 20:04:00 +01004607static void
4608intel_dp_unset_edid(struct intel_dp *intel_dp)
4609{
4610 struct intel_connector *intel_connector = intel_dp->attached_connector;
4611
4612 kfree(intel_connector->detect_edid);
4613 intel_connector->detect_edid = NULL;
4614
4615 intel_dp->has_audio = false;
4616}
4617
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004618static int
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304619intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004620{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304621 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004622 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004623 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4624 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004625 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004626 enum drm_connector_status status;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004627 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004628
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004629 WARN_ON(!drm_modeset_is_locked(&connector->dev->mode_config.connection_mutex));
4630
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004631 intel_display_power_get(to_i915(dev), intel_dp->aux_power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004632
Chris Wilsond410b562014-09-02 20:03:59 +01004633 /* Can't disconnect eDP, but you can close the lid... */
4634 if (is_edp(intel_dp))
4635 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004636 else if (intel_digital_port_connected(to_i915(dev),
4637 dp_to_dig_port(intel_dp)))
4638 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004639 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004640 status = connector_status_disconnected;
4641
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004642 if (status == connector_status_disconnected) {
Manasi Navarec1617ab2016-12-09 16:22:50 -08004643 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304644
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004645 if (intel_dp->is_mst) {
4646 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4647 intel_dp->is_mst,
4648 intel_dp->mst_mgr.mst_state);
4649 intel_dp->is_mst = false;
4650 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4651 intel_dp->is_mst);
4652 }
4653
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004654 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304655 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004656
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304657 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004658 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304659
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004660 DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
4661 yesno(intel_dp_source_supports_hbr2(intel_dp)),
4662 yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
4663
Manasi Navared7e8ef02017-02-07 16:54:11 -08004664 if (intel_dp->reset_link_params) {
Jani Nikula540b0b7f2017-04-06 16:44:13 +03004665 /* Initial max link lane count */
4666 intel_dp->max_link_lane_count = intel_dp_max_common_lane_count(intel_dp);
Manasi Navaref4829842016-12-05 16:27:36 -08004667
Jani Nikula540b0b7f2017-04-06 16:44:13 +03004668 /* Initial max link rate */
4669 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
Manasi Navared7e8ef02017-02-07 16:54:11 -08004670
4671 intel_dp->reset_link_params = false;
4672 }
Manasi Navaref4829842016-12-05 16:27:36 -08004673
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004674 intel_dp_print_rates(intel_dp);
4675
Imre Deak7b3fc172016-10-25 16:12:39 +03004676 intel_dp_read_desc(intel_dp);
Mika Kahola0e390a32016-09-09 14:10:53 +03004677
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004678 intel_dp_configure_mst(intel_dp);
4679
4680 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304681 /*
4682 * If we are in MST mode then this connector
4683 * won't appear connected or have anything
4684 * with EDID on it
4685 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004686 status = connector_status_disconnected;
4687 goto out;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304688 } else if (connector->status == connector_status_connected) {
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304689 intel_dp_check_link_status(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304690 goto out;
Dave Airlie0e32b392014-05-02 14:02:48 +10004691 }
4692
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304693 /*
4694 * Clearing NACK and defer counts to get their exact values
4695 * while reading EDID which are required by Compliance tests
4696 * 4.2.2.4 and 4.2.2.5
4697 */
4698 intel_dp->aux.i2c_nack_count = 0;
4699 intel_dp->aux.i2c_defer_count = 0;
4700
Chris Wilsonbeb60602014-09-02 20:04:00 +01004701 intel_dp_set_edid(intel_dp);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004702 if (is_edp(intel_dp) || intel_connector->detect_edid)
4703 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304704 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004705
Todd Previte09b1eb12015-04-20 15:27:34 -07004706 /* Try to read the source of the interrupt */
4707 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004708 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4709 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004710 /* Clear interrupt source */
4711 drm_dp_dpcd_writeb(&intel_dp->aux,
4712 DP_DEVICE_SERVICE_IRQ_VECTOR,
4713 sink_irq_vector);
4714
4715 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4716 intel_dp_handle_test_request(intel_dp);
4717 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4718 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4719 }
4720
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004721out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004722 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304723 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304724
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004725 intel_display_power_put(to_i915(dev), intel_dp->aux_power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004726 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304727}
4728
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004729static int
4730intel_dp_detect(struct drm_connector *connector,
4731 struct drm_modeset_acquire_ctx *ctx,
4732 bool force)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304733{
4734 struct intel_dp *intel_dp = intel_attached_dp(connector);
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004735 int status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304736
4737 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4738 connector->base.id, connector->name);
4739
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304740 /* If full detect is not performed yet, do a full detect */
4741 if (!intel_dp->detect_done)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004742 status = intel_dp_long_pulse(intel_dp->attached_connector);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304743
4744 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304745
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004746 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004747}
4748
Chris Wilsonbeb60602014-09-02 20:04:00 +01004749static void
4750intel_dp_force(struct drm_connector *connector)
4751{
4752 struct intel_dp *intel_dp = intel_attached_dp(connector);
4753 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004754 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004755
4756 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4757 connector->base.id, connector->name);
4758 intel_dp_unset_edid(intel_dp);
4759
4760 if (connector->status != connector_status_connected)
4761 return;
4762
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004763 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004764
4765 intel_dp_set_edid(intel_dp);
4766
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004767 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004768
4769 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004770 intel_encoder->type = INTEL_OUTPUT_DP;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004771}
4772
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004773static int intel_dp_get_modes(struct drm_connector *connector)
4774{
Jani Nikuladd06f902012-10-19 14:51:50 +03004775 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004776 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004777
Chris Wilsonbeb60602014-09-02 20:04:00 +01004778 edid = intel_connector->detect_edid;
4779 if (edid) {
4780 int ret = intel_connector_update_modes(connector, edid);
4781 if (ret)
4782 return ret;
4783 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004784
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004785 /* if eDP has no EDID, fall back to fixed mode */
Chris Wilsonbeb60602014-09-02 20:04:00 +01004786 if (is_edp(intel_attached_dp(connector)) &&
4787 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004788 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004789
4790 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004791 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004792 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004793 drm_mode_probed_add(connector, mode);
4794 return 1;
4795 }
4796 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004797
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004798 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004799}
4800
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004801static bool
4802intel_dp_detect_audio(struct drm_connector *connector)
4803{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004804 bool has_audio = false;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004805 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004806
Chris Wilsonbeb60602014-09-02 20:04:00 +01004807 edid = to_intel_connector(connector)->detect_edid;
4808 if (edid)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004809 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02004810
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004811 return has_audio;
4812}
4813
Chris Wilsonf6849602010-09-19 09:29:33 +01004814static int
4815intel_dp_set_property(struct drm_connector *connector,
4816 struct drm_property *property,
4817 uint64_t val)
4818{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004819 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Yuly Novikov53b41832012-10-26 12:04:00 +03004820 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004821 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
4822 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01004823 int ret;
4824
Rob Clark662595d2012-10-11 20:36:04 -05004825 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01004826 if (ret)
4827 return ret;
4828
Chris Wilson3f43c482011-05-12 22:17:24 +01004829 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004830 int i = val;
4831 bool has_audio;
4832
4833 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004834 return 0;
4835
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004836 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01004837
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004838 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004839 has_audio = intel_dp_detect_audio(connector);
4840 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004841 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004842
4843 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004844 return 0;
4845
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004846 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01004847 goto done;
4848 }
4849
Chris Wilsone953fd72011-02-21 22:23:52 +00004850 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02004851 bool old_auto = intel_dp->color_range_auto;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004852 bool old_range = intel_dp->limited_color_range;
Daniel Vetterae4edb82013-04-22 17:07:23 +02004853
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004854 switch (val) {
4855 case INTEL_BROADCAST_RGB_AUTO:
4856 intel_dp->color_range_auto = true;
4857 break;
4858 case INTEL_BROADCAST_RGB_FULL:
4859 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004860 intel_dp->limited_color_range = false;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004861 break;
4862 case INTEL_BROADCAST_RGB_LIMITED:
4863 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004864 intel_dp->limited_color_range = true;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004865 break;
4866 default:
4867 return -EINVAL;
4868 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02004869
4870 if (old_auto == intel_dp->color_range_auto &&
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004871 old_range == intel_dp->limited_color_range)
Daniel Vetterae4edb82013-04-22 17:07:23 +02004872 return 0;
4873
Chris Wilsone953fd72011-02-21 22:23:52 +00004874 goto done;
4875 }
4876
Yuly Novikov53b41832012-10-26 12:04:00 +03004877 if (is_edp(intel_dp) &&
4878 property == connector->dev->mode_config.scaling_mode_property) {
4879 if (val == DRM_MODE_SCALE_NONE) {
4880 DRM_DEBUG_KMS("no scaling not supported\n");
4881 return -EINVAL;
4882 }
Ville Syrjälä234126c2016-04-12 22:14:38 +03004883 if (HAS_GMCH_DISPLAY(dev_priv) &&
4884 val == DRM_MODE_SCALE_CENTER) {
4885 DRM_DEBUG_KMS("centering not supported\n");
4886 return -EINVAL;
4887 }
Yuly Novikov53b41832012-10-26 12:04:00 +03004888
4889 if (intel_connector->panel.fitting_mode == val) {
4890 /* the eDP scaling property is not changed */
4891 return 0;
4892 }
4893 intel_connector->panel.fitting_mode = val;
4894
4895 goto done;
4896 }
4897
Chris Wilsonf6849602010-09-19 09:29:33 +01004898 return -EINVAL;
4899
4900done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00004901 if (intel_encoder->base.crtc)
4902 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01004903
4904 return 0;
4905}
4906
Chris Wilson7a418e32016-06-24 14:00:14 +01004907static int
4908intel_dp_connector_register(struct drm_connector *connector)
4909{
4910 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004911 int ret;
4912
4913 ret = intel_connector_register(connector);
4914 if (ret)
4915 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004916
4917 i915_debugfs_connector_add(connector);
4918
4919 DRM_DEBUG_KMS("registering %s bus for %s\n",
4920 intel_dp->aux.name, connector->kdev->kobj.name);
4921
4922 intel_dp->aux.dev = connector->kdev;
4923 return drm_dp_aux_register(&intel_dp->aux);
4924}
4925
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004926static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004927intel_dp_connector_unregister(struct drm_connector *connector)
4928{
4929 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4930 intel_connector_unregister(connector);
4931}
4932
4933static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004934intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004935{
Jani Nikula1d508702012-10-19 14:51:49 +03004936 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004937
Chris Wilson10e972d2014-09-04 21:43:45 +01004938 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004939
Jani Nikula9cd300e2012-10-19 14:51:52 +03004940 if (!IS_ERR_OR_NULL(intel_connector->edid))
4941 kfree(intel_connector->edid);
4942
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004943 /* Can't call is_edp() since the encoder may have been destroyed
4944 * already. */
4945 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004946 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004947
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004948 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004949 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004950}
4951
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004952void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004953{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004954 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4955 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004956
Dave Airlie0e32b392014-05-02 14:02:48 +10004957 intel_dp_mst_encoder_cleanup(intel_dig_port);
Keith Packardbd943152011-09-18 23:09:52 -07004958 if (is_edp(intel_dp)) {
4959 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
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ä773538e82014-09-04 14:54:56 +03004964 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004965 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004966 pps_unlock(intel_dp);
4967
Clint Taylor01527b32014-07-07 13:01:46 -07004968 if (intel_dp->edp_notifier.notifier_call) {
4969 unregister_reboot_notifier(&intel_dp->edp_notifier);
4970 intel_dp->edp_notifier.notifier_call = NULL;
4971 }
Keith Packardbd943152011-09-18 23:09:52 -07004972 }
Chris Wilson99681882016-06-20 09:29:17 +01004973
4974 intel_dp_aux_fini(intel_dp);
4975
Imre Deakc8bd0e42014-12-12 17:57:38 +02004976 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004977 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004978}
4979
Imre Deakbf93ba62016-04-18 10:04:21 +03004980void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004981{
4982 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4983
4984 if (!is_edp(intel_dp))
4985 return;
4986
Ville Syrjälä951468f2014-09-04 14:55:31 +03004987 /*
4988 * vdd might still be enabled do to the delayed vdd off.
4989 * Make sure vdd is actually turned off here.
4990 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004991 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004992 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004993 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004994 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004995}
4996
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004997static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4998{
4999 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
5000 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005001 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005002
5003 lockdep_assert_held(&dev_priv->pps_mutex);
5004
5005 if (!edp_have_panel_vdd(intel_dp))
5006 return;
5007
5008 /*
5009 * The VDD bit needs a power domain reference, so if the bit is
5010 * already enabled when we boot or resume, grab this reference and
5011 * schedule a vdd off, so we don't hold on to the reference
5012 * indefinitely.
5013 */
5014 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005015 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005016
5017 edp_panel_vdd_schedule_off(intel_dp);
5018}
5019
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005020static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
5021{
5022 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5023
5024 if ((intel_dp->DP & DP_PORT_EN) == 0)
5025 return INVALID_PIPE;
5026
5027 if (IS_CHERRYVIEW(dev_priv))
5028 return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
5029 else
5030 return PORT_TO_PIPE(intel_dp->DP);
5031}
5032
Imre Deakbf93ba62016-04-18 10:04:21 +03005033void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03005034{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005035 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Imre Deakdd75f6d2016-11-21 21:15:05 +02005036 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
5037 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005038
5039 if (!HAS_DDI(dev_priv))
5040 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005041
Imre Deakdd75f6d2016-11-21 21:15:05 +02005042 if (lspcon->active)
Shashank Sharma910530c2016-10-14 19:56:52 +05305043 lspcon_resume(lspcon);
5044
Manasi Navared7e8ef02017-02-07 16:54:11 -08005045 intel_dp->reset_link_params = true;
5046
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005047 pps_lock(intel_dp);
5048
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005049 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5050 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5051
5052 if (is_edp(intel_dp)) {
5053 /* Reinit the power sequencer, in case BIOS did something with it. */
5054 intel_dp_pps_init(encoder->dev, intel_dp);
5055 intel_edp_panel_vdd_sanitize(intel_dp);
5056 }
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005057
5058 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03005059}
5060
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005061static const struct drm_connector_funcs intel_dp_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02005062 .dpms = drm_atomic_helper_connector_dpms,
Chris Wilsonbeb60602014-09-02 20:04:00 +01005063 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005064 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01005065 .set_property = intel_dp_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -08005066 .atomic_get_property = intel_connector_atomic_get_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01005067 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01005068 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03005069 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08005070 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02005071 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005072};
5073
5074static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02005075 .detect_ctx = intel_dp_detect,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005076 .get_modes = intel_dp_get_modes,
5077 .mode_valid = intel_dp_mode_valid,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005078};
5079
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005080static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03005081 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02005082 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005083};
5084
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005085enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10005086intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
5087{
5088 struct intel_dp *intel_dp = &intel_dig_port->dp;
Dave Airlie0e32b392014-05-02 14:02:48 +10005089 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005090 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005091 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03005092
Takashi Iwai25400582015-11-19 12:09:56 +01005093 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
5094 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Ville Syrjäläcca05022016-06-22 21:57:06 +03005095 intel_dig_port->base.type = INTEL_OUTPUT_DP;
Dave Airlie13cf5502014-06-18 11:29:35 +10005096
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005097 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
5098 /*
5099 * vdd off can generate a long pulse on eDP which
5100 * would require vdd on to handle it, and thus we
5101 * would end up in an endless cycle of
5102 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
5103 */
5104 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
5105 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d522015-02-10 14:11:46 +02005106 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005107 }
5108
Ville Syrjälä26fbb772014-08-11 18:37:37 +03005109 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
5110 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10005111 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10005112
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005113 if (long_hpd) {
Manasi Navared7e8ef02017-02-07 16:54:11 -08005114 intel_dp->reset_link_params = true;
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005115 intel_dp->detect_done = false;
5116 return IRQ_NONE;
5117 }
5118
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005119 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005120
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005121 if (intel_dp->is_mst) {
5122 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
5123 /*
5124 * If we were in MST mode, and device is not
5125 * there, get out of MST mode
5126 */
5127 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
5128 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
5129 intel_dp->is_mst = false;
5130 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
5131 intel_dp->is_mst);
5132 intel_dp->detect_done = false;
5133 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10005134 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005135 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005136
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005137 if (!intel_dp->is_mst) {
5138 if (!intel_dp_short_pulse(intel_dp)) {
5139 intel_dp->detect_done = false;
5140 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05305141 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005142 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005143
5144 ret = IRQ_HANDLED;
5145
Imre Deak1c767b32014-08-18 14:42:42 +03005146put_power:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005147 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005148
5149 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10005150}
5151
Rodrigo Vivi477ec322015-08-06 15:51:39 +08005152/* check the VBT to see whether the eDP is on another port */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005153bool intel_dp_is_edp(struct drm_i915_private *dev_priv, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08005154{
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005155 /*
5156 * eDP not supported on g4x. so bail out early just
5157 * for a bit extra safety in case the VBT is bonkers.
5158 */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005159 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005160 return false;
5161
Imre Deaka98d9c12016-12-21 12:17:24 +02005162 if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005163 return true;
5164
Jani Nikula951d9ef2016-03-16 12:43:31 +02005165 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08005166}
5167
Maarten Lankhorst200819a2017-04-10 12:51:10 +02005168static void
Chris Wilsonf6849602010-09-19 09:29:33 +01005169intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
5170{
Yuly Novikov53b41832012-10-26 12:04:00 +03005171 struct intel_connector *intel_connector = to_intel_connector(connector);
5172
Chris Wilson3f43c482011-05-12 22:17:24 +01005173 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00005174 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02005175 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03005176
5177 if (is_edp(intel_dp)) {
5178 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05005179 drm_object_attach_property(
5180 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03005181 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03005182 DRM_MODE_SCALE_ASPECT);
5183 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03005184 }
Chris Wilsonf6849602010-09-19 09:29:33 +01005185}
5186
Imre Deakdada1a92014-01-29 13:25:41 +02005187static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
5188{
Abhay Kumard28d4732016-01-22 17:39:04 -08005189 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02005190 intel_dp->last_power_on = jiffies;
5191 intel_dp->last_backlight_off = jiffies;
5192}
5193
Daniel Vetter67a54562012-10-20 20:57:45 +02005194static void
Imre Deak54648612016-06-16 16:37:22 +03005195intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
5196 struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02005197{
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305198 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03005199 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07005200
Imre Deak8e8232d2016-06-16 16:37:21 +03005201 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02005202
5203 /* Workaround: Need to write PP_CONTROL with the unlock key as
5204 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305205 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02005206
Imre Deak8e8232d2016-06-16 16:37:21 +03005207 pp_on = I915_READ(regs.pp_on);
5208 pp_off = I915_READ(regs.pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005209 if (!IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005210 I915_WRITE(regs.pp_ctrl, pp_ctl);
5211 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305212 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005213
5214 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03005215 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
5216 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005217
Imre Deak54648612016-06-16 16:37:22 +03005218 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
5219 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005220
Imre Deak54648612016-06-16 16:37:22 +03005221 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
5222 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005223
Imre Deak54648612016-06-16 16:37:22 +03005224 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
5225 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005226
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005227 if (IS_GEN9_LP(dev_priv)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305228 u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
5229 BXT_POWER_CYCLE_DELAY_SHIFT;
5230 if (tmp > 0)
Imre Deak54648612016-06-16 16:37:22 +03005231 seq->t11_t12 = (tmp - 1) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305232 else
Imre Deak54648612016-06-16 16:37:22 +03005233 seq->t11_t12 = 0;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305234 } else {
Imre Deak54648612016-06-16 16:37:22 +03005235 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02005236 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305237 }
Imre Deak54648612016-06-16 16:37:22 +03005238}
5239
5240static void
Imre Deakde9c1b62016-06-16 20:01:46 +03005241intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
5242{
5243 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5244 state_name,
5245 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
5246}
5247
5248static void
5249intel_pps_verify_state(struct drm_i915_private *dev_priv,
5250 struct intel_dp *intel_dp)
5251{
5252 struct edp_power_seq hw;
5253 struct edp_power_seq *sw = &intel_dp->pps_delays;
5254
5255 intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
5256
5257 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
5258 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
5259 DRM_ERROR("PPS state mismatch\n");
5260 intel_pps_dump_state("sw", sw);
5261 intel_pps_dump_state("hw", &hw);
5262 }
5263}
5264
5265static void
Imre Deak54648612016-06-16 16:37:22 +03005266intel_dp_init_panel_power_sequencer(struct drm_device *dev,
5267 struct intel_dp *intel_dp)
5268{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005269 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak54648612016-06-16 16:37:22 +03005270 struct edp_power_seq cur, vbt, spec,
5271 *final = &intel_dp->pps_delays;
5272
5273 lockdep_assert_held(&dev_priv->pps_mutex);
5274
5275 /* already initialized? */
5276 if (final->t11_t12 != 0)
5277 return;
5278
5279 intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005280
Imre Deakde9c1b62016-06-16 20:01:46 +03005281 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005282
Jani Nikula6aa23e62016-03-24 17:50:20 +02005283 vbt = dev_priv->vbt.edp.pps;
Daniel Vetter67a54562012-10-20 20:57:45 +02005284
5285 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5286 * our hw here, which are all in 100usec. */
5287 spec.t1_t3 = 210 * 10;
5288 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5289 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5290 spec.t10 = 500 * 10;
5291 /* This one is special and actually in units of 100ms, but zero
5292 * based in the hw (so we need to add 100 ms). But the sw vbt
5293 * table multiplies it with 1000 to make it in units of 100usec,
5294 * too. */
5295 spec.t11_t12 = (510 + 100) * 10;
5296
Imre Deakde9c1b62016-06-16 20:01:46 +03005297 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005298
5299 /* Use the max of the register settings and vbt. If both are
5300 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005301#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005302 spec.field : \
5303 max(cur.field, vbt.field))
5304 assign_final(t1_t3);
5305 assign_final(t8);
5306 assign_final(t9);
5307 assign_final(t10);
5308 assign_final(t11_t12);
5309#undef assign_final
5310
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005311#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005312 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5313 intel_dp->backlight_on_delay = get_delay(t8);
5314 intel_dp->backlight_off_delay = get_delay(t9);
5315 intel_dp->panel_power_down_delay = get_delay(t10);
5316 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5317#undef get_delay
5318
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005319 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5320 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5321 intel_dp->panel_power_cycle_delay);
5322
5323 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5324 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005325
5326 /*
5327 * We override the HW backlight delays to 1 because we do manual waits
5328 * on them. For T8, even BSpec recommends doing it. For T9, if we
5329 * don't do this, we'll end up waiting for the backlight off delay
5330 * twice: once when we do the manual sleep, and once when we disable
5331 * the panel and wait for the PP_STATUS bit to become zero.
5332 */
5333 final->t8 = 1;
5334 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005335}
5336
5337static void
5338intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005339 struct intel_dp *intel_dp,
5340 bool force_disable_vdd)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005341{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005342 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07005343 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005344 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005345 struct pps_registers regs;
Ville Syrjäläad933b52014-08-18 22:15:56 +03005346 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005347 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005348
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005349 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005350
Imre Deak8e8232d2016-06-16 16:37:21 +03005351 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005352
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005353 /*
5354 * On some VLV machines the BIOS can leave the VDD
5355 * enabled even on power seqeuencers which aren't
5356 * hooked up to any port. This would mess up the
5357 * power domain tracking the first time we pick
5358 * one of these power sequencers for use since
5359 * edp_panel_vdd_on() would notice that the VDD was
5360 * already on and therefore wouldn't grab the power
5361 * domain reference. Disable VDD first to avoid this.
5362 * This also avoids spuriously turning the VDD on as
5363 * soon as the new power seqeuencer gets initialized.
5364 */
5365 if (force_disable_vdd) {
5366 u32 pp = ironlake_get_pp_control(intel_dp);
5367
5368 WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
5369
5370 if (pp & EDP_FORCE_VDD)
5371 DRM_DEBUG_KMS("VDD already on, disabling first\n");
5372
5373 pp &= ~EDP_FORCE_VDD;
5374
5375 I915_WRITE(regs.pp_ctrl, pp);
5376 }
5377
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005378 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005379 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5380 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005381 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005382 /* Compute the divisor for the pp clock, simply match the Bspec
5383 * formula. */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005384 if (IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005385 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305386 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
5387 pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
5388 << BXT_POWER_CYCLE_DELAY_SHIFT);
5389 } else {
5390 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5391 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5392 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5393 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005394
5395 /* Haswell doesn't have any port selection bits for the panel
5396 * power sequencer any more. */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005397 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005398 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005399 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005400 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005401 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005402 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005403 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005404 }
5405
Jesse Barnes453c5422013-03-28 09:55:41 -07005406 pp_on |= port_sel;
5407
Imre Deak8e8232d2016-06-16 16:37:21 +03005408 I915_WRITE(regs.pp_on, pp_on);
5409 I915_WRITE(regs.pp_off, pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005410 if (IS_GEN9_LP(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005411 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305412 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005413 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005414
Daniel Vetter67a54562012-10-20 20:57:45 +02005415 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 +03005416 I915_READ(regs.pp_on),
5417 I915_READ(regs.pp_off),
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005418 IS_GEN9_LP(dev_priv) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005419 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5420 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005421}
5422
Imre Deak335f7522016-08-10 14:07:32 +03005423static void intel_dp_pps_init(struct drm_device *dev,
5424 struct intel_dp *intel_dp)
5425{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005426 struct drm_i915_private *dev_priv = to_i915(dev);
5427
5428 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Imre Deak335f7522016-08-10 14:07:32 +03005429 vlv_initial_power_sequencer_setup(intel_dp);
5430 } else {
5431 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005432 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak335f7522016-08-10 14:07:32 +03005433 }
5434}
5435
Vandana Kannanb33a2812015-02-13 15:33:03 +05305436/**
5437 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005438 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005439 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305440 * @refresh_rate: RR to be programmed
5441 *
5442 * This function gets called when refresh rate (RR) has to be changed from
5443 * one frequency to another. Switches can be between high and low RR
5444 * supported by the panel or to any other RR based on media playback (in
5445 * this case, RR value needs to be passed from user space).
5446 *
5447 * The caller of this function needs to take a lock on dev_priv->drrs.
5448 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005449static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
5450 struct intel_crtc_state *crtc_state,
5451 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305452{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305453 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305454 struct intel_digital_port *dig_port = NULL;
5455 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005456 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305457 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305458
5459 if (refresh_rate <= 0) {
5460 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5461 return;
5462 }
5463
Vandana Kannan96178ee2015-01-10 02:25:56 +05305464 if (intel_dp == NULL) {
5465 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305466 return;
5467 }
5468
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005469 /*
Rodrigo Vivie4d59f62014-11-20 02:22:08 -08005470 * FIXME: This needs proper synchronization with psr state for some
5471 * platforms that cannot have PSR and DRRS enabled at the same time.
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005472 */
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305473
Vandana Kannan96178ee2015-01-10 02:25:56 +05305474 dig_port = dp_to_dig_port(intel_dp);
5475 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02005476 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305477
5478 if (!intel_crtc) {
5479 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5480 return;
5481 }
5482
Vandana Kannan96178ee2015-01-10 02:25:56 +05305483 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305484 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5485 return;
5486 }
5487
Vandana Kannan96178ee2015-01-10 02:25:56 +05305488 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5489 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305490 index = DRRS_LOW_RR;
5491
Vandana Kannan96178ee2015-01-10 02:25:56 +05305492 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305493 DRM_DEBUG_KMS(
5494 "DRRS requested for previously set RR...ignoring\n");
5495 return;
5496 }
5497
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005498 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305499 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5500 return;
5501 }
5502
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005503 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305504 switch (index) {
5505 case DRRS_HIGH_RR:
5506 intel_dp_set_m_n(intel_crtc, M1_N1);
5507 break;
5508 case DRRS_LOW_RR:
5509 intel_dp_set_m_n(intel_crtc, M2_N2);
5510 break;
5511 case DRRS_MAX_RR:
5512 default:
5513 DRM_ERROR("Unsupported refreshrate type\n");
5514 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005515 } else if (INTEL_GEN(dev_priv) > 6) {
5516 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005517 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305518
Ville Syrjälä649636e2015-09-22 19:50:01 +03005519 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305520 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005521 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305522 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5523 else
5524 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305525 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005526 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305527 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5528 else
5529 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305530 }
5531 I915_WRITE(reg, val);
5532 }
5533
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305534 dev_priv->drrs.refresh_rate_type = index;
5535
5536 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5537}
5538
Vandana Kannanb33a2812015-02-13 15:33:03 +05305539/**
5540 * intel_edp_drrs_enable - init drrs struct if supported
5541 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005542 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305543 *
5544 * Initializes frontbuffer_bits and drrs.dp
5545 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005546void intel_edp_drrs_enable(struct intel_dp *intel_dp,
5547 struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305548{
5549 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005550 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305551
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005552 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305553 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5554 return;
5555 }
5556
5557 mutex_lock(&dev_priv->drrs.mutex);
5558 if (WARN_ON(dev_priv->drrs.dp)) {
5559 DRM_ERROR("DRRS already enabled\n");
5560 goto unlock;
5561 }
5562
5563 dev_priv->drrs.busy_frontbuffer_bits = 0;
5564
5565 dev_priv->drrs.dp = intel_dp;
5566
5567unlock:
5568 mutex_unlock(&dev_priv->drrs.mutex);
5569}
5570
Vandana Kannanb33a2812015-02-13 15:33:03 +05305571/**
5572 * intel_edp_drrs_disable - Disable DRRS
5573 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005574 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305575 *
5576 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005577void intel_edp_drrs_disable(struct intel_dp *intel_dp,
5578 struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305579{
5580 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005581 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305582
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005583 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305584 return;
5585
5586 mutex_lock(&dev_priv->drrs.mutex);
5587 if (!dev_priv->drrs.dp) {
5588 mutex_unlock(&dev_priv->drrs.mutex);
5589 return;
5590 }
5591
5592 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005593 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5594 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305595
5596 dev_priv->drrs.dp = NULL;
5597 mutex_unlock(&dev_priv->drrs.mutex);
5598
5599 cancel_delayed_work_sync(&dev_priv->drrs.work);
5600}
5601
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305602static void intel_edp_drrs_downclock_work(struct work_struct *work)
5603{
5604 struct drm_i915_private *dev_priv =
5605 container_of(work, typeof(*dev_priv), drrs.work.work);
5606 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305607
Vandana Kannan96178ee2015-01-10 02:25:56 +05305608 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305609
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305610 intel_dp = dev_priv->drrs.dp;
5611
5612 if (!intel_dp)
5613 goto unlock;
5614
5615 /*
5616 * The delayed work can race with an invalidate hence we need to
5617 * recheck.
5618 */
5619
5620 if (dev_priv->drrs.busy_frontbuffer_bits)
5621 goto unlock;
5622
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005623 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5624 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5625
5626 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5627 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5628 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305629
5630unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305631 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305632}
5633
Vandana Kannanb33a2812015-02-13 15:33:03 +05305634/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305635 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005636 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305637 * @frontbuffer_bits: frontbuffer plane tracking bits
5638 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305639 * This function gets called everytime rendering on the given planes start.
5640 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305641 *
5642 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5643 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005644void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5645 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305646{
Vandana Kannana93fad02015-01-10 02:25:59 +05305647 struct drm_crtc *crtc;
5648 enum pipe pipe;
5649
Daniel Vetter9da7d692015-04-09 16:44:15 +02005650 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305651 return;
5652
Daniel Vetter88f933a2015-04-09 16:44:16 +02005653 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305654
Vandana Kannana93fad02015-01-10 02:25:59 +05305655 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005656 if (!dev_priv->drrs.dp) {
5657 mutex_unlock(&dev_priv->drrs.mutex);
5658 return;
5659 }
5660
Vandana Kannana93fad02015-01-10 02:25:59 +05305661 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5662 pipe = to_intel_crtc(crtc)->pipe;
5663
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005664 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5665 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5666
Ramalingam C0ddfd202015-06-15 20:50:05 +05305667 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005668 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005669 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5670 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305671
Vandana Kannana93fad02015-01-10 02:25:59 +05305672 mutex_unlock(&dev_priv->drrs.mutex);
5673}
5674
Vandana Kannanb33a2812015-02-13 15:33:03 +05305675/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305676 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005677 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305678 * @frontbuffer_bits: frontbuffer plane tracking bits
5679 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305680 * This function gets called every time rendering on the given planes has
5681 * completed or flip on a crtc is completed. So DRRS should be upclocked
5682 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5683 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305684 *
5685 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5686 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005687void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5688 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305689{
Vandana Kannana93fad02015-01-10 02:25:59 +05305690 struct drm_crtc *crtc;
5691 enum pipe pipe;
5692
Daniel Vetter9da7d692015-04-09 16:44:15 +02005693 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305694 return;
5695
Daniel Vetter88f933a2015-04-09 16:44:16 +02005696 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305697
Vandana Kannana93fad02015-01-10 02:25:59 +05305698 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005699 if (!dev_priv->drrs.dp) {
5700 mutex_unlock(&dev_priv->drrs.mutex);
5701 return;
5702 }
5703
Vandana Kannana93fad02015-01-10 02:25:59 +05305704 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5705 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005706
5707 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305708 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5709
Ramalingam C0ddfd202015-06-15 20:50:05 +05305710 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005711 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005712 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5713 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305714
5715 /*
5716 * flush also means no more activity hence schedule downclock, if all
5717 * other fbs are quiescent too
5718 */
5719 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305720 schedule_delayed_work(&dev_priv->drrs.work,
5721 msecs_to_jiffies(1000));
5722 mutex_unlock(&dev_priv->drrs.mutex);
5723}
5724
Vandana Kannanb33a2812015-02-13 15:33:03 +05305725/**
5726 * DOC: Display Refresh Rate Switching (DRRS)
5727 *
5728 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5729 * which enables swtching between low and high refresh rates,
5730 * dynamically, based on the usage scenario. This feature is applicable
5731 * for internal panels.
5732 *
5733 * Indication that the panel supports DRRS is given by the panel EDID, which
5734 * would list multiple refresh rates for one resolution.
5735 *
5736 * DRRS is of 2 types - static and seamless.
5737 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5738 * (may appear as a blink on screen) and is used in dock-undock scenario.
5739 * Seamless DRRS involves changing RR without any visual effect to the user
5740 * and can be used during normal system usage. This is done by programming
5741 * certain registers.
5742 *
5743 * Support for static/seamless DRRS may be indicated in the VBT based on
5744 * inputs from the panel spec.
5745 *
5746 * DRRS saves power by switching to low RR based on usage scenarios.
5747 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005748 * The implementation is based on frontbuffer tracking implementation. When
5749 * there is a disturbance on the screen triggered by user activity or a periodic
5750 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5751 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5752 * made.
5753 *
5754 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5755 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305756 *
5757 * DRRS can be further extended to support other internal panels and also
5758 * the scenario of video playback wherein RR is set based on the rate
5759 * requested by userspace.
5760 */
5761
5762/**
5763 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5764 * @intel_connector: eDP connector
5765 * @fixed_mode: preferred mode of panel
5766 *
5767 * This function is called only once at driver load to initialize basic
5768 * DRRS stuff.
5769 *
5770 * Returns:
5771 * Downclock mode if panel supports it, else return NULL.
5772 * DRRS support is determined by the presence of downclock mode (apart
5773 * from VBT setting).
5774 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305775static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305776intel_dp_drrs_init(struct intel_connector *intel_connector,
5777 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305778{
5779 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305780 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005781 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305782 struct drm_display_mode *downclock_mode = NULL;
5783
Daniel Vetter9da7d692015-04-09 16:44:15 +02005784 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5785 mutex_init(&dev_priv->drrs.mutex);
5786
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005787 if (INTEL_GEN(dev_priv) <= 6) {
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305788 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5789 return NULL;
5790 }
5791
5792 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005793 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305794 return NULL;
5795 }
5796
5797 downclock_mode = intel_find_panel_downclock
Mika Kaholaa318b4c2016-12-13 10:02:48 +02005798 (dev_priv, fixed_mode, connector);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305799
5800 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305801 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305802 return NULL;
5803 }
5804
Vandana Kannan96178ee2015-01-10 02:25:56 +05305805 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305806
Vandana Kannan96178ee2015-01-10 02:25:56 +05305807 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005808 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305809 return downclock_mode;
5810}
5811
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005812static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005813 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005814{
5815 struct drm_connector *connector = &intel_connector->base;
5816 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005817 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5818 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005819 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005820 struct drm_display_mode *fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305821 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005822 bool has_dpcd;
5823 struct drm_display_mode *scan;
5824 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005825 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005826
5827 if (!is_edp(intel_dp))
5828 return true;
5829
Imre Deak97a824e12016-06-21 11:51:47 +03005830 /*
5831 * On IBX/CPT we may get here with LVDS already registered. Since the
5832 * driver uses the only internal power sequencer available for both
5833 * eDP and LVDS bail out early in this case to prevent interfering
5834 * with an already powered-on LVDS power sequencer.
5835 */
5836 if (intel_get_lvds_encoder(dev)) {
5837 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5838 DRM_INFO("LVDS was detected, not registering eDP\n");
5839
5840 return false;
5841 }
5842
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005843 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005844
5845 intel_dp_init_panel_power_timestamps(intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +03005846 intel_dp_pps_init(dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005847 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005848
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005849 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005850
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005851 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005852 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005853
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005854 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005855 /* if this fails, presume the device is a ghost */
5856 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005857 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005858 }
5859
Daniel Vetter060c8772014-03-21 23:22:35 +01005860 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005861 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005862 if (edid) {
5863 if (drm_add_edid_modes(connector, edid)) {
5864 drm_mode_connector_update_edid_property(connector,
5865 edid);
5866 drm_edid_to_eld(connector, edid);
5867 } else {
5868 kfree(edid);
5869 edid = ERR_PTR(-EINVAL);
5870 }
5871 } else {
5872 edid = ERR_PTR(-ENOENT);
5873 }
5874 intel_connector->edid = edid;
5875
5876 /* prefer fixed mode from EDID if available */
5877 list_for_each_entry(scan, &connector->probed_modes, head) {
5878 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5879 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305880 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305881 intel_connector, fixed_mode);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005882 break;
5883 }
5884 }
5885
5886 /* fallback to VBT if available for eDP */
5887 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5888 fixed_mode = drm_mode_duplicate(dev,
5889 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005890 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005891 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005892 connector->display_info.width_mm = fixed_mode->width_mm;
5893 connector->display_info.height_mm = fixed_mode->height_mm;
5894 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005895 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005896 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005897
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005898 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005899 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5900 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005901
5902 /*
5903 * Figure out the current pipe for the initial backlight setup.
5904 * If the current pipe isn't valid, try the PPS pipe, and if that
5905 * fails just assume pipe A.
5906 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005907 pipe = vlv_active_pipe(intel_dp);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005908
5909 if (pipe != PIPE_A && pipe != PIPE_B)
5910 pipe = intel_dp->pps_pipe;
5911
5912 if (pipe != PIPE_A && pipe != PIPE_B)
5913 pipe = PIPE_A;
5914
5915 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5916 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005917 }
5918
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305919 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005920 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005921 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005922
5923 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005924
5925out_vdd_off:
5926 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5927 /*
5928 * vdd might still be enabled do to the delayed vdd off.
5929 * Make sure vdd is actually turned off here.
5930 */
5931 pps_lock(intel_dp);
5932 edp_panel_vdd_off_sync(intel_dp);
5933 pps_unlock(intel_dp);
5934
5935 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005936}
5937
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005938/* Set up the hotplug pin and aux power domain. */
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005939static void
5940intel_dp_init_connector_port_info(struct intel_digital_port *intel_dig_port)
5941{
5942 struct intel_encoder *encoder = &intel_dig_port->base;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005943 struct intel_dp *intel_dp = &intel_dig_port->dp;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005944
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005945 switch (intel_dig_port->port) {
5946 case PORT_A:
5947 encoder->hpd_pin = HPD_PORT_A;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005948 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_A;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005949 break;
5950 case PORT_B:
5951 encoder->hpd_pin = HPD_PORT_B;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005952 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_B;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005953 break;
5954 case PORT_C:
5955 encoder->hpd_pin = HPD_PORT_C;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005956 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_C;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005957 break;
5958 case PORT_D:
5959 encoder->hpd_pin = HPD_PORT_D;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005960 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005961 break;
5962 case PORT_E:
5963 encoder->hpd_pin = HPD_PORT_E;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005964
5965 /* FIXME: Check VBT for actual wiring of PORT E */
5966 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005967 break;
5968 default:
5969 MISSING_CASE(intel_dig_port->port);
5970 }
5971}
5972
Paulo Zanoni16c25532013-06-12 17:27:25 -03005973bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005974intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5975 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005976{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005977 struct drm_connector *connector = &intel_connector->base;
5978 struct intel_dp *intel_dp = &intel_dig_port->dp;
5979 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5980 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005981 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02005982 enum port port = intel_dig_port->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01005983 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005984
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005985 if (WARN(intel_dig_port->max_lanes < 1,
5986 "Not enough lanes (%d) for DP on port %c\n",
5987 intel_dig_port->max_lanes, port_name(port)))
5988 return false;
5989
Jani Nikula55cfc582017-03-28 17:59:04 +03005990 intel_dp_set_source_rates(intel_dp);
5991
Manasi Navared7e8ef02017-02-07 16:54:11 -08005992 intel_dp->reset_link_params = true;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005993 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005994 intel_dp->active_pipe = INVALID_PIPE;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005995
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005996 /* intel_dp vfuncs */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005997 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub6b5e382014-01-20 16:00:59 +00005998 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005999 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006000 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01006001 else if (HAS_PCH_SPLIT(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006002 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
6003 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02006004 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00006005
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006006 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00006007 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
6008 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02006009 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00006010
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006011 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03006012 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
6013
Daniel Vetter07679352012-09-06 22:15:42 +02006014 /* Preserve the current hw state. */
6015 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03006016 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00006017
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006018 if (intel_dp_is_edp(dev_priv, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05306019 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02006020 else
6021 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04006022
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02006023 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
6024 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
6025
Imre Deakf7d24902013-05-08 13:14:05 +03006026 /*
6027 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
6028 * for DP the encoder type can be set by the caller to
6029 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
6030 */
6031 if (type == DRM_MODE_CONNECTOR_eDP)
6032 intel_encoder->type = INTEL_OUTPUT_EDP;
6033
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006034 /* eDP only on port B and/or C on vlv/chv */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006035 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08006036 is_edp(intel_dp) && port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006037 return false;
6038
Imre Deake7281ea2013-05-08 13:14:08 +03006039 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
6040 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
6041 port_name(port));
6042
Adam Jacksonb3295302010-07-16 14:46:28 -04006043 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006044 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
6045
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006046 connector->interlace_allowed = true;
6047 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08006048
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02006049 intel_dp_init_connector_port_info(intel_dig_port);
6050
Mika Kaholab6339582016-09-09 14:10:52 +03006051 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01006052
Daniel Vetter66a92782012-07-12 20:08:18 +02006053 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01006054 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08006055
Chris Wilsondf0e9242010-09-09 16:20:55 +01006056 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006057
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006058 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02006059 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
6060 else
6061 intel_connector->get_hw_state = intel_connector_get_hw_state;
6062
Dave Airlie0e32b392014-05-02 14:02:48 +10006063 /* init MST on ports that can support it */
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00006064 if (HAS_DP_MST(dev_priv) && !is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03006065 (port == PORT_B || port == PORT_C || port == PORT_D))
6066 intel_dp_mst_encoder_init(intel_dig_port,
6067 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10006068
Ville Syrjälä36b5f422014-10-16 21:27:30 +03006069 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006070 intel_dp_aux_fini(intel_dp);
6071 intel_dp_mst_encoder_cleanup(intel_dig_port);
6072 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03006073 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08006074
Chris Wilsonf6849602010-09-19 09:29:33 +01006075 intel_dp_add_properties(intel_dp, connector);
6076
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006077 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
6078 * 0xd. Failure to do so will result in spurious interrupts being
6079 * generated on the port when a cable is not attached.
6080 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01006081 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006082 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
6083 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
6084 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03006085
6086 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006087
6088fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006089 drm_connector_cleanup(connector);
6090
6091 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006092}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006093
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006094bool intel_dp_init(struct drm_i915_private *dev_priv,
Chris Wilson457c52d2016-06-01 08:27:50 +01006095 i915_reg_t output_reg,
6096 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006097{
6098 struct intel_digital_port *intel_dig_port;
6099 struct intel_encoder *intel_encoder;
6100 struct drm_encoder *encoder;
6101 struct intel_connector *intel_connector;
6102
Daniel Vetterb14c5672013-09-19 12:18:32 +02006103 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006104 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01006105 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006106
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03006107 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306108 if (!intel_connector)
6109 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006110
6111 intel_encoder = &intel_dig_port->base;
6112 encoder = &intel_encoder->base;
6113
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006114 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
6115 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
6116 "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306117 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006118
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01006119 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006120 intel_encoder->disable = intel_disable_dp;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006121 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07006122 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03006123 intel_encoder->suspend = intel_dp_encoder_suspend;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006124 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03006125 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03006126 intel_encoder->pre_enable = chv_pre_enable_dp;
6127 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03006128 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03006129 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01006130 } else if (IS_VALLEYVIEW(dev_priv)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006131 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006132 intel_encoder->pre_enable = vlv_pre_enable_dp;
6133 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03006134 intel_encoder->post_disable = vlv_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006135 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006136 intel_encoder->pre_enable = g4x_pre_enable_dp;
6137 intel_encoder->enable = g4x_enable_dp;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006138 if (INTEL_GEN(dev_priv) >= 5)
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03006139 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006140 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006141
Paulo Zanoni174edf12012-10-26 19:05:50 -02006142 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006143 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02006144 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006145
Ville Syrjäläcca05022016-06-22 21:57:06 +03006146 intel_encoder->type = INTEL_OUTPUT_DP;
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02006147 intel_encoder->power_domain = intel_port_to_power_domain(port);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006148 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03006149 if (port == PORT_D)
6150 intel_encoder->crtc_mask = 1 << 2;
6151 else
6152 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
6153 } else {
6154 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
6155 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02006156 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07006157 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006158
Dave Airlie13cf5502014-06-18 11:29:35 +10006159 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03006160 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10006161
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306162 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
6163 goto err_init_connector;
6164
Chris Wilson457c52d2016-06-01 08:27:50 +01006165 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306166
6167err_init_connector:
6168 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306169err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306170 kfree(intel_connector);
6171err_connector_alloc:
6172 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01006173 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006174}
Dave Airlie0e32b392014-05-02 14:02:48 +10006175
6176void intel_dp_mst_suspend(struct drm_device *dev)
6177{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006178 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006179 int i;
6180
6181 /* disable MST */
6182 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006183 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006184
6185 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006186 continue;
6187
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006188 if (intel_dig_port->dp.is_mst)
6189 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10006190 }
6191}
6192
6193void intel_dp_mst_resume(struct drm_device *dev)
6194{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006195 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006196 int i;
6197
6198 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006199 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006200 int ret;
6201
6202 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006203 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10006204
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006205 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
6206 if (ret)
6207 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10006208 }
6209}