blob: b38cba7d5abc7e1bdd6fa495de7b4a43a995ea41 [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
Ville Syrjäläed4e9c12015-03-12 17:10:36 +0200164static int
165intel_dp_max_link_bw(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700166{
Jesse Barnes7183dc22011-07-07 11:10:58 -0700167 int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700168
169 switch (max_link_bw) {
170 case DP_LINK_BW_1_62:
171 case DP_LINK_BW_2_7:
Ville Syrjälä1db10e22015-03-12 17:10:32 +0200172 case DP_LINK_BW_5_4:
Imre Deakd4eead52013-07-09 17:05:26 +0300173 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700174 default:
Imre Deakd4eead52013-07-09 17:05:26 +0300175 WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
176 max_link_bw);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700177 max_link_bw = DP_LINK_BW_1_62;
178 break;
179 }
180 return max_link_bw;
181}
182
Paulo Zanonieeb63242014-05-06 14:56:50 +0300183static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
184{
185 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300186 u8 source_max, sink_max;
187
Ville Syrjäläccb1a832015-12-08 19:59:38 +0200188 source_max = intel_dig_port->max_lanes;
Manasi Navaref4829842016-12-05 16:27:36 -0800189 sink_max = intel_dp->max_sink_lane_count;
Paulo Zanonieeb63242014-05-06 14:56:50 +0300190
191 return min(source_max, sink_max);
192}
193
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800194int
Keith Packardc8982612012-01-25 08:16:25 -0800195intel_dp_link_required(int pixel_clock, int bpp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700196{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800197 /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
198 return DIV_ROUND_UP(pixel_clock * bpp, 8);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700199}
200
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800201int
Dave Airliefe27d532010-06-30 11:46:17 +1000202intel_dp_max_data_rate(int max_link_clock, int max_lanes)
203{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800204 /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
205 * link rate that is generally expressed in Gbps. Since, 8 bits of data
206 * is transmitted every LS_Clk per lane, there is no need to account for
207 * the channel encoding that is done in the PHY layer here.
208 */
209
210 return max_link_clock * max_lanes;
Dave Airliefe27d532010-06-30 11:46:17 +1000211}
212
Mika Kahola70ec0642016-09-09 14:10:55 +0300213static int
214intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp)
215{
216 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
217 struct intel_encoder *encoder = &intel_dig_port->base;
218 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
219 int max_dotclk = dev_priv->max_dotclk_freq;
220 int ds_max_dotclk;
221
222 int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
223
224 if (type != DP_DS_PORT_TYPE_VGA)
225 return max_dotclk;
226
227 ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd,
228 intel_dp->downstream_ports);
229
230 if (ds_max_dotclk != 0)
231 max_dotclk = min(max_dotclk, ds_max_dotclk);
232
233 return max_dotclk;
234}
235
Jani Nikula55cfc582017-03-28 17:59:04 +0300236static void
237intel_dp_set_source_rates(struct intel_dp *intel_dp)
Navare, Manasi D40dba342016-10-26 16:25:55 -0700238{
239 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
240 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Jani Nikula55cfc582017-03-28 17:59:04 +0300241 const int *source_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700242 int size;
243
Jani Nikula55cfc582017-03-28 17:59:04 +0300244 /* This should only be done once */
245 WARN_ON(intel_dp->source_rates || intel_dp->num_source_rates);
246
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200247 if (IS_GEN9_LP(dev_priv)) {
Jani Nikula55cfc582017-03-28 17:59:04 +0300248 source_rates = bxt_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700249 size = ARRAY_SIZE(bxt_rates);
Rodrigo Vivib976dc52017-01-23 10:32:37 -0800250 } else if (IS_GEN9_BC(dev_priv)) {
Jani Nikula55cfc582017-03-28 17:59:04 +0300251 source_rates = skl_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700252 size = ARRAY_SIZE(skl_rates);
253 } else {
Jani Nikula55cfc582017-03-28 17:59:04 +0300254 source_rates = default_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700255 size = ARRAY_SIZE(default_rates);
256 }
257
258 /* This depends on the fact that 5.4 is last value in the array */
259 if (!intel_dp_source_supports_hbr2(intel_dp))
260 size--;
261
Jani Nikula55cfc582017-03-28 17:59:04 +0300262 intel_dp->source_rates = source_rates;
263 intel_dp->num_source_rates = size;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700264}
265
266static int intersect_rates(const int *source_rates, int source_len,
267 const int *sink_rates, int sink_len,
268 int *common_rates)
269{
270 int i = 0, j = 0, k = 0;
271
272 while (i < source_len && j < sink_len) {
273 if (source_rates[i] == sink_rates[j]) {
274 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
275 return k;
276 common_rates[k] = source_rates[i];
277 ++k;
278 ++i;
279 ++j;
280 } else if (source_rates[i] < sink_rates[j]) {
281 ++i;
282 } else {
283 ++j;
284 }
285 }
286 return k;
287}
288
Jani Nikula8001b752017-03-28 17:59:03 +0300289/* return index of rate in rates array, or -1 if not found */
290static int intel_dp_rate_index(const int *rates, int len, int rate)
291{
292 int i;
293
294 for (i = 0; i < len; i++)
295 if (rate == rates[i])
296 return i;
297
298 return -1;
299}
300
Navare, Manasi D40dba342016-10-26 16:25:55 -0700301static int intel_dp_common_rates(struct intel_dp *intel_dp,
302 int *common_rates)
303{
Jani Nikula68f357c2017-03-28 17:59:05 +0300304 int max_rate = drm_dp_bw_code_to_link_rate(intel_dp->max_sink_link_bw);
305 int i, common_len;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700306
Jani Nikula68f357c2017-03-28 17:59:05 +0300307 common_len = intersect_rates(intel_dp->source_rates,
308 intel_dp->num_source_rates,
309 intel_dp->sink_rates,
310 intel_dp->num_sink_rates,
311 common_rates);
Navare, Manasi D40dba342016-10-26 16:25:55 -0700312
Jani Nikula68f357c2017-03-28 17:59:05 +0300313 /* Limit results by potentially reduced max rate */
314 for (i = 0; i < common_len; i++) {
315 if (common_rates[common_len - i - 1] <= max_rate)
316 return common_len - i;
317 }
318
319 return 0;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700320}
321
Manasi Navarefdb14d32016-12-08 19:05:12 -0800322static int intel_dp_link_rate_index(struct intel_dp *intel_dp,
323 int *common_rates, int link_rate)
324{
325 int common_len;
Manasi Navarefdb14d32016-12-08 19:05:12 -0800326
327 common_len = intel_dp_common_rates(intel_dp, common_rates);
Manasi Navarefdb14d32016-12-08 19:05:12 -0800328
Jani Nikula8001b752017-03-28 17:59:03 +0300329 return intel_dp_rate_index(common_rates, common_len, link_rate);
Manasi Navarefdb14d32016-12-08 19:05:12 -0800330}
331
332int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
333 int link_rate, uint8_t lane_count)
334{
335 int common_rates[DP_MAX_SUPPORTED_RATES];
336 int link_rate_index;
337
338 link_rate_index = intel_dp_link_rate_index(intel_dp,
339 common_rates,
340 link_rate);
341 if (link_rate_index > 0) {
342 intel_dp->max_sink_link_bw = drm_dp_link_rate_to_bw_code(common_rates[link_rate_index - 1]);
343 intel_dp->max_sink_lane_count = lane_count;
344 } else if (lane_count > 1) {
345 intel_dp->max_sink_link_bw = intel_dp_max_link_bw(intel_dp);
346 intel_dp->max_sink_lane_count = lane_count >> 1;
347 } else {
348 DRM_ERROR("Link Training Unsuccessful\n");
349 return -1;
350 }
351
352 return 0;
353}
354
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000355static enum drm_mode_status
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700356intel_dp_mode_valid(struct drm_connector *connector,
357 struct drm_display_mode *mode)
358{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100359 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300360 struct intel_connector *intel_connector = to_intel_connector(connector);
361 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Daniel Vetter36008362013-03-27 00:44:59 +0100362 int target_clock = mode->clock;
363 int max_rate, mode_rate, max_lanes, max_link_clock;
Mika Kahola70ec0642016-09-09 14:10:55 +0300364 int max_dotclk;
365
366 max_dotclk = intel_dp_downstream_max_dotclock(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700367
Jani Nikuladd06f902012-10-19 14:51:50 +0300368 if (is_edp(intel_dp) && fixed_mode) {
369 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100370 return MODE_PANEL;
371
Jani Nikuladd06f902012-10-19 14:51:50 +0300372 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100373 return MODE_PANEL;
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200374
375 target_clock = fixed_mode->clock;
Zhao Yakui7de56f42010-07-19 09:43:14 +0100376 }
377
Ville Syrjälä50fec212015-03-12 17:10:34 +0200378 max_link_clock = intel_dp_max_link_rate(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300379 max_lanes = intel_dp_max_lane_count(intel_dp);
Daniel Vetter36008362013-03-27 00:44:59 +0100380
381 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
382 mode_rate = intel_dp_link_required(target_clock, 18);
383
Mika Kahola799487f2016-02-02 15:16:38 +0200384 if (mode_rate > max_rate || target_clock > max_dotclk)
Daniel Vetterc4867932012-04-10 10:42:36 +0200385 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700386
387 if (mode->clock < 10000)
388 return MODE_CLOCK_LOW;
389
Daniel Vetter0af78a22012-05-23 11:30:55 +0200390 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
391 return MODE_H_ILLEGAL;
392
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700393 return MODE_OK;
394}
395
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800396uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700397{
398 int i;
399 uint32_t v = 0;
400
401 if (src_bytes > 4)
402 src_bytes = 4;
403 for (i = 0; i < src_bytes; i++)
404 v |= ((uint32_t) src[i]) << ((3-i) * 8);
405 return v;
406}
407
Damien Lespiauc2af70e2015-02-10 19:32:23 +0000408static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700409{
410 int i;
411 if (dst_bytes > 4)
412 dst_bytes = 4;
413 for (i = 0; i < dst_bytes; i++)
414 dst[i] = src >> ((3-i) * 8);
415}
416
Jani Nikulabf13e812013-09-06 07:40:05 +0300417static void
418intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300419 struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300420static void
421intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200422 struct intel_dp *intel_dp,
423 bool force_disable_vdd);
Imre Deak335f7522016-08-10 14:07:32 +0300424static void
425intel_dp_pps_init(struct drm_device *dev, struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300426
Ville Syrjälä773538e82014-09-04 14:54:56 +0300427static void pps_lock(struct intel_dp *intel_dp)
428{
429 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
430 struct intel_encoder *encoder = &intel_dig_port->base;
431 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100432 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300433
434 /*
435 * See vlv_power_sequencer_reset() why we need
436 * a power domain reference here.
437 */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +0200438 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300439
440 mutex_lock(&dev_priv->pps_mutex);
441}
442
443static void pps_unlock(struct intel_dp *intel_dp)
444{
445 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
446 struct intel_encoder *encoder = &intel_dig_port->base;
447 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100448 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300449
450 mutex_unlock(&dev_priv->pps_mutex);
451
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +0200452 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300453}
454
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300455static void
456vlv_power_sequencer_kick(struct intel_dp *intel_dp)
457{
458 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200459 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300460 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300461 bool pll_enabled, release_cl_override = false;
462 enum dpio_phy phy = DPIO_PHY(pipe);
463 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300464 uint32_t DP;
465
466 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
467 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
468 pipe_name(pipe), port_name(intel_dig_port->port)))
469 return;
470
471 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
472 pipe_name(pipe), port_name(intel_dig_port->port));
473
474 /* Preserve the BIOS-computed detected bit. This is
475 * supposed to be read-only.
476 */
477 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
478 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
479 DP |= DP_PORT_WIDTH(1);
480 DP |= DP_LINK_TRAIN_PAT_1;
481
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100482 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300483 DP |= DP_PIPE_SELECT_CHV(pipe);
484 else if (pipe == PIPE_B)
485 DP |= DP_PIPEB_SELECT;
486
Ville Syrjäläd288f652014-10-28 13:20:22 +0200487 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
488
489 /*
490 * The DPLL for the pipe must be enabled for this to work.
491 * So enable temporarily it if it's not already enabled.
492 */
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300493 if (!pll_enabled) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100494 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300495 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
496
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200497 if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ?
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000498 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
499 DRM_ERROR("Failed to force on pll for pipe %c!\n",
500 pipe_name(pipe));
501 return;
502 }
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300503 }
Ville Syrjäläd288f652014-10-28 13:20:22 +0200504
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300505 /*
506 * Similar magic as in intel_dp_enable_port().
507 * We _must_ do this port enable + disable trick
508 * to make this power seqeuencer lock onto the port.
509 * Otherwise even VDD force bit won't work.
510 */
511 I915_WRITE(intel_dp->output_reg, DP);
512 POSTING_READ(intel_dp->output_reg);
513
514 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
515 POSTING_READ(intel_dp->output_reg);
516
517 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
518 POSTING_READ(intel_dp->output_reg);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200519
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300520 if (!pll_enabled) {
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200521 vlv_force_pll_off(dev_priv, pipe);
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300522
523 if (release_cl_override)
524 chv_phy_powergate_ch(dev_priv, phy, ch, false);
525 }
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300526}
527
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200528static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv)
529{
530 struct intel_encoder *encoder;
531 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
532
533 /*
534 * We don't have power sequencer currently.
535 * Pick one that's not used by other ports.
536 */
537 for_each_intel_encoder(&dev_priv->drm, encoder) {
538 struct intel_dp *intel_dp;
539
540 if (encoder->type != INTEL_OUTPUT_DP &&
541 encoder->type != INTEL_OUTPUT_EDP)
542 continue;
543
544 intel_dp = enc_to_intel_dp(&encoder->base);
545
546 if (encoder->type == INTEL_OUTPUT_EDP) {
547 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
548 intel_dp->active_pipe != intel_dp->pps_pipe);
549
550 if (intel_dp->pps_pipe != INVALID_PIPE)
551 pipes &= ~(1 << intel_dp->pps_pipe);
552 } else {
553 WARN_ON(intel_dp->pps_pipe != INVALID_PIPE);
554
555 if (intel_dp->active_pipe != INVALID_PIPE)
556 pipes &= ~(1 << intel_dp->active_pipe);
557 }
558 }
559
560 if (pipes == 0)
561 return INVALID_PIPE;
562
563 return ffs(pipes) - 1;
564}
565
Jani Nikulabf13e812013-09-06 07:40:05 +0300566static enum pipe
567vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
568{
569 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300570 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100571 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300572 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300573
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300574 lockdep_assert_held(&dev_priv->pps_mutex);
575
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300576 /* We should never land here with regular DP ports */
577 WARN_ON(!is_edp(intel_dp));
578
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200579 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
580 intel_dp->active_pipe != intel_dp->pps_pipe);
581
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300582 if (intel_dp->pps_pipe != INVALID_PIPE)
583 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300584
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200585 pipe = vlv_find_free_pps(dev_priv);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300586
587 /*
588 * Didn't find one. This should not happen since there
589 * are two power sequencers and up to two eDP ports.
590 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200591 if (WARN_ON(pipe == INVALID_PIPE))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300592 pipe = PIPE_A;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300593
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300594 vlv_steal_power_sequencer(dev, pipe);
595 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300596
597 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
598 pipe_name(intel_dp->pps_pipe),
599 port_name(intel_dig_port->port));
600
601 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300602 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200603 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300604
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300605 /*
606 * Even vdd force doesn't work until we've made
607 * the power sequencer lock in on the port.
608 */
609 vlv_power_sequencer_kick(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300610
611 return intel_dp->pps_pipe;
612}
613
Imre Deak78597992016-06-16 16:37:20 +0300614static int
615bxt_power_sequencer_idx(struct intel_dp *intel_dp)
616{
617 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
618 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100619 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak78597992016-06-16 16:37:20 +0300620
621 lockdep_assert_held(&dev_priv->pps_mutex);
622
623 /* We should never land here with regular DP ports */
624 WARN_ON(!is_edp(intel_dp));
625
626 /*
627 * TODO: BXT has 2 PPS instances. The correct port->PPS instance
628 * mapping needs to be retrieved from VBT, for now just hard-code to
629 * use instance #0 always.
630 */
631 if (!intel_dp->pps_reset)
632 return 0;
633
634 intel_dp->pps_reset = false;
635
636 /*
637 * Only the HW needs to be reprogrammed, the SW state is fixed and
638 * has been setup during connector init.
639 */
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200640 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak78597992016-06-16 16:37:20 +0300641
642 return 0;
643}
644
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300645typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
646 enum pipe pipe);
647
648static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
649 enum pipe pipe)
650{
Imre Deak44cb7342016-08-10 14:07:29 +0300651 return I915_READ(PP_STATUS(pipe)) & PP_ON;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300652}
653
654static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
655 enum pipe pipe)
656{
Imre Deak44cb7342016-08-10 14:07:29 +0300657 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300658}
659
660static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
661 enum pipe pipe)
662{
663 return true;
664}
665
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300666static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300667vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
668 enum port port,
669 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300670{
Jani Nikulabf13e812013-09-06 07:40:05 +0300671 enum pipe pipe;
672
Jani Nikulabf13e812013-09-06 07:40:05 +0300673 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
Imre Deak44cb7342016-08-10 14:07:29 +0300674 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
Jani Nikulabf13e812013-09-06 07:40:05 +0300675 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300676
677 if (port_sel != PANEL_PORT_SELECT_VLV(port))
678 continue;
679
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300680 if (!pipe_check(dev_priv, pipe))
681 continue;
682
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300683 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300684 }
685
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300686 return INVALID_PIPE;
687}
688
689static void
690vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
691{
692 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
693 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100694 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300695 enum port port = intel_dig_port->port;
696
697 lockdep_assert_held(&dev_priv->pps_mutex);
698
699 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300700 /* first pick one where the panel is on */
701 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
702 vlv_pipe_has_pp_on);
703 /* didn't find one? pick one where vdd is on */
704 if (intel_dp->pps_pipe == INVALID_PIPE)
705 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
706 vlv_pipe_has_vdd_on);
707 /* didn't find one? pick one with just the correct port */
708 if (intel_dp->pps_pipe == INVALID_PIPE)
709 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
710 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300711
712 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
713 if (intel_dp->pps_pipe == INVALID_PIPE) {
714 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
715 port_name(port));
716 return;
717 }
718
719 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
720 port_name(port), pipe_name(intel_dp->pps_pipe));
721
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300722 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200723 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Jani Nikulabf13e812013-09-06 07:40:05 +0300724}
725
Imre Deak78597992016-06-16 16:37:20 +0300726void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300727{
Chris Wilson91c8a322016-07-05 10:40:23 +0100728 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300729 struct intel_encoder *encoder;
730
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100731 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200732 !IS_GEN9_LP(dev_priv)))
Ville Syrjälä773538e82014-09-04 14:54:56 +0300733 return;
734
735 /*
736 * We can't grab pps_mutex here due to deadlock with power_domain
737 * mutex when power_domain functions are called while holding pps_mutex.
738 * That also means that in order to use pps_pipe the code needs to
739 * hold both a power domain reference and pps_mutex, and the power domain
740 * reference get/put must be done while _not_ holding pps_mutex.
741 * pps_{lock,unlock}() do these steps in the correct order, so one
742 * should use them always.
743 */
744
Jani Nikula19c80542015-12-16 12:48:16 +0200745 for_each_intel_encoder(dev, encoder) {
Ville Syrjälä773538e82014-09-04 14:54:56 +0300746 struct intel_dp *intel_dp;
747
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200748 if (encoder->type != INTEL_OUTPUT_DP &&
749 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300750 continue;
751
752 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200753
754 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
755
756 if (encoder->type != INTEL_OUTPUT_EDP)
757 continue;
758
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200759 if (IS_GEN9_LP(dev_priv))
Imre Deak78597992016-06-16 16:37:20 +0300760 intel_dp->pps_reset = true;
761 else
762 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300763 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300764}
765
Imre Deak8e8232d2016-06-16 16:37:21 +0300766struct pps_registers {
767 i915_reg_t pp_ctrl;
768 i915_reg_t pp_stat;
769 i915_reg_t pp_on;
770 i915_reg_t pp_off;
771 i915_reg_t pp_div;
772};
773
774static void intel_pps_get_registers(struct drm_i915_private *dev_priv,
775 struct intel_dp *intel_dp,
776 struct pps_registers *regs)
777{
Imre Deak44cb7342016-08-10 14:07:29 +0300778 int pps_idx = 0;
779
Imre Deak8e8232d2016-06-16 16:37:21 +0300780 memset(regs, 0, sizeof(*regs));
781
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200782 if (IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300783 pps_idx = bxt_power_sequencer_idx(intel_dp);
784 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
785 pps_idx = vlv_power_sequencer_pipe(intel_dp);
Imre Deak8e8232d2016-06-16 16:37:21 +0300786
Imre Deak44cb7342016-08-10 14:07:29 +0300787 regs->pp_ctrl = PP_CONTROL(pps_idx);
788 regs->pp_stat = PP_STATUS(pps_idx);
789 regs->pp_on = PP_ON_DELAYS(pps_idx);
790 regs->pp_off = PP_OFF_DELAYS(pps_idx);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200791 if (!IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300792 regs->pp_div = PP_DIVISOR(pps_idx);
Imre Deak8e8232d2016-06-16 16:37:21 +0300793}
794
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200795static i915_reg_t
796_pp_ctrl_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300797{
Imre Deak8e8232d2016-06-16 16:37:21 +0300798 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300799
Imre Deak8e8232d2016-06-16 16:37:21 +0300800 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
801 &regs);
802
803 return regs.pp_ctrl;
Jani Nikulabf13e812013-09-06 07:40:05 +0300804}
805
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200806static i915_reg_t
807_pp_stat_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300808{
Imre Deak8e8232d2016-06-16 16:37:21 +0300809 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300810
Imre Deak8e8232d2016-06-16 16:37:21 +0300811 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
812 &regs);
813
814 return regs.pp_stat;
Jani Nikulabf13e812013-09-06 07:40:05 +0300815}
816
Clint Taylor01527b32014-07-07 13:01:46 -0700817/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
818 This function only applicable when panel PM state is not to be tracked */
819static int edp_notify_handler(struct notifier_block *this, unsigned long code,
820 void *unused)
821{
822 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
823 edp_notifier);
824 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100825 struct drm_i915_private *dev_priv = to_i915(dev);
Clint Taylor01527b32014-07-07 13:01:46 -0700826
827 if (!is_edp(intel_dp) || code != SYS_RESTART)
828 return 0;
829
Ville Syrjälä773538e82014-09-04 14:54:56 +0300830 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300831
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100832 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300833 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200834 i915_reg_t pp_ctrl_reg, pp_div_reg;
Ville Syrjälä649636e2015-09-22 19:50:01 +0300835 u32 pp_div;
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300836
Imre Deak44cb7342016-08-10 14:07:29 +0300837 pp_ctrl_reg = PP_CONTROL(pipe);
838 pp_div_reg = PP_DIVISOR(pipe);
Clint Taylor01527b32014-07-07 13:01:46 -0700839 pp_div = I915_READ(pp_div_reg);
840 pp_div &= PP_REFERENCE_DIVIDER_MASK;
841
842 /* 0x1F write to PP_DIV_REG sets max cycle delay */
843 I915_WRITE(pp_div_reg, pp_div | 0x1F);
844 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
845 msleep(intel_dp->panel_power_cycle_delay);
846 }
847
Ville Syrjälä773538e82014-09-04 14:54:56 +0300848 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300849
Clint Taylor01527b32014-07-07 13:01:46 -0700850 return 0;
851}
852
Daniel Vetter4be73782014-01-17 14:39:48 +0100853static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700854{
Paulo Zanoni30add222012-10-26 19:05:45 -0200855 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100856 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700857
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300858 lockdep_assert_held(&dev_priv->pps_mutex);
859
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100860 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300861 intel_dp->pps_pipe == INVALID_PIPE)
862 return false;
863
Jani Nikulabf13e812013-09-06 07:40:05 +0300864 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700865}
866
Daniel Vetter4be73782014-01-17 14:39:48 +0100867static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700868{
Paulo Zanoni30add222012-10-26 19:05:45 -0200869 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100870 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700871
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300872 lockdep_assert_held(&dev_priv->pps_mutex);
873
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100874 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300875 intel_dp->pps_pipe == INVALID_PIPE)
876 return false;
877
Ville Syrjälä773538e82014-09-04 14:54:56 +0300878 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700879}
880
Keith Packard9b984da2011-09-19 13:54:47 -0700881static void
882intel_dp_check_edp(struct intel_dp *intel_dp)
883{
Paulo Zanoni30add222012-10-26 19:05:45 -0200884 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100885 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700886
Keith Packard9b984da2011-09-19 13:54:47 -0700887 if (!is_edp(intel_dp))
888 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700889
Daniel Vetter4be73782014-01-17 14:39:48 +0100890 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700891 WARN(1, "eDP powered off while attempting aux channel communication.\n");
892 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300893 I915_READ(_pp_stat_reg(intel_dp)),
894 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700895 }
896}
897
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100898static uint32_t
899intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
900{
901 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
902 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100903 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200904 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100905 uint32_t status;
906 bool done;
907
Daniel Vetteref04f002012-12-01 21:03:59 +0100908#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100909 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300910 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300911 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100912 else
Imre Deak713a6b662016-06-28 13:37:33 +0300913 done = wait_for(C, 10) == 0;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100914 if (!done)
915 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
916 has_aux_irq);
917#undef C
918
919 return status;
920}
921
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200922static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000923{
924 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200925 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000926
Ville Syrjäläa457f542016-03-02 17:22:17 +0200927 if (index)
928 return 0;
929
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000930 /*
931 * The clock divider is based off the hrawclk, and would like to run at
Ville Syrjäläa457f542016-03-02 17:22:17 +0200932 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000933 */
Ville Syrjäläa457f542016-03-02 17:22:17 +0200934 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000935}
936
937static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
938{
939 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200940 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000941
942 if (index)
943 return 0;
944
Ville Syrjäläa457f542016-03-02 17:22:17 +0200945 /*
946 * The clock divider is based off the cdclk or PCH rawclk, and would
947 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
948 * divide by 2000 and use that
949 */
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200950 if (intel_dig_port->port == PORT_A)
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200951 return DIV_ROUND_CLOSEST(dev_priv->cdclk.hw.cdclk, 2000);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200952 else
953 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000954}
955
956static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300957{
958 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200959 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300960
Ville Syrjäläa457f542016-03-02 17:22:17 +0200961 if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300962 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100963 switch (index) {
964 case 0: return 63;
965 case 1: return 72;
966 default: return 0;
967 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300968 }
Ville Syrjäläa457f542016-03-02 17:22:17 +0200969
970 return ilk_get_aux_clock_divider(intel_dp, index);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300971}
972
Damien Lespiaub6b5e382014-01-20 16:00:59 +0000973static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
974{
975 /*
976 * SKL doesn't need us to program the AUX clock divider (Hardware will
977 * derive the clock from CDCLK automatically). We still implement the
978 * get_aux_clock_divider vfunc to plug-in into the existing code.
979 */
980 return index ? 0 : 1;
981}
982
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200983static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
984 bool has_aux_irq,
985 int send_bytes,
986 uint32_t aux_clock_divider)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000987{
988 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100989 struct drm_i915_private *dev_priv =
990 to_i915(intel_dig_port->base.base.dev);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000991 uint32_t precharge, timeout;
992
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100993 if (IS_GEN6(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000994 precharge = 3;
995 else
996 precharge = 5;
997
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100998 if (IS_BROADWELL(dev_priv) && intel_dig_port->port == PORT_A)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000999 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
1000 else
1001 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
1002
1003 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +00001004 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001005 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +00001006 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001007 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +00001008 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001009 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
1010 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +00001011 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001012}
1013
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00001014static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
1015 bool has_aux_irq,
1016 int send_bytes,
1017 uint32_t unused)
1018{
1019 return DP_AUX_CH_CTL_SEND_BUSY |
1020 DP_AUX_CH_CTL_DONE |
1021 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
1022 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1023 DP_AUX_CH_CTL_TIME_OUT_1600us |
1024 DP_AUX_CH_CTL_RECEIVE_ERROR |
1025 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Daniel Vetterd4dcbdc2016-05-18 18:47:15 +02001026 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00001027 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
1028}
1029
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001030static int
Chris Wilsonea5b2132010-08-04 13:50:23 +01001031intel_dp_aux_ch(struct intel_dp *intel_dp,
Daniel Vetterbd9f74a2014-10-02 09:45:35 +02001032 const uint8_t *send, int send_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001033 uint8_t *recv, int recv_size)
1034{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001035 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001036 struct drm_i915_private *dev_priv =
1037 to_i915(intel_dig_port->base.base.dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001038 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Chris Wilsonbc866252013-07-21 16:00:03 +01001039 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001040 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001041 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001042 int try, clock = 0;
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001043 bool has_aux_irq = HAS_AUX_IRQ(dev_priv);
Jani Nikula884f19e2014-03-14 16:51:14 +02001044 bool vdd;
1045
Ville Syrjälä773538e82014-09-04 14:54:56 +03001046 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001047
Ville Syrjälä72c35002014-08-18 22:16:00 +03001048 /*
1049 * We will be called with VDD already enabled for dpcd/edid/oui reads.
1050 * In such cases we want to leave VDD enabled and it's up to upper layers
1051 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
1052 * ourselves.
1053 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001054 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001055
1056 /* dp aux is extremely sensitive to irq latency, hence request the
1057 * lowest possible wakeup latency and so prevent the cpu from going into
1058 * deep sleep states.
1059 */
1060 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001061
Keith Packard9b984da2011-09-19 13:54:47 -07001062 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001063
Jesse Barnes11bee432011-08-01 15:02:20 -07001064 /* Try to wait for any previous AUX channel activity */
1065 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +01001066 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -07001067 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
1068 break;
1069 msleep(1);
1070 }
1071
1072 if (try == 3) {
Mika Kuoppala02196c72015-08-06 16:48:58 +03001073 static u32 last_status = -1;
1074 const u32 status = I915_READ(ch_ctl);
1075
1076 if (status != last_status) {
1077 WARN(1, "dp_aux_ch not started status 0x%08x\n",
1078 status);
1079 last_status = status;
1080 }
1081
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001082 ret = -EBUSY;
1083 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001084 }
1085
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001086 /* Only 5 data registers! */
1087 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
1088 ret = -E2BIG;
1089 goto out;
1090 }
1091
Damien Lespiauec5b01d2014-01-21 13:35:39 +00001092 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +00001093 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
1094 has_aux_irq,
1095 send_bytes,
1096 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001097
Chris Wilsonbc866252013-07-21 16:00:03 +01001098 /* Must try at least 3 times according to DP spec */
1099 for (try = 0; try < 5; try++) {
1100 /* Load the send data into the aux channel data registers */
1101 for (i = 0; i < send_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001102 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001103 intel_dp_pack_aux(send + i,
1104 send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -04001105
Chris Wilsonbc866252013-07-21 16:00:03 +01001106 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001107 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001108
Chris Wilsonbc866252013-07-21 16:00:03 +01001109 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -04001110
Chris Wilsonbc866252013-07-21 16:00:03 +01001111 /* Clear done status and any errors */
1112 I915_WRITE(ch_ctl,
1113 status |
1114 DP_AUX_CH_CTL_DONE |
1115 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1116 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -04001117
Todd Previte74ebf292015-04-15 08:38:41 -07001118 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
Chris Wilsonbc866252013-07-21 16:00:03 +01001119 continue;
Todd Previte74ebf292015-04-15 08:38:41 -07001120
1121 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
1122 * 400us delay required for errors and timeouts
1123 * Timeout errors from the HW already meet this
1124 * requirement so skip to next iteration
1125 */
1126 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1127 usleep_range(400, 500);
1128 continue;
1129 }
Chris Wilsonbc866252013-07-21 16:00:03 +01001130 if (status & DP_AUX_CH_CTL_DONE)
Jim Bridee058c942015-05-27 10:21:48 -07001131 goto done;
Chris Wilsonbc866252013-07-21 16:00:03 +01001132 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001133 }
1134
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001135 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001136 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001137 ret = -EBUSY;
1138 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001139 }
1140
Jim Bridee058c942015-05-27 10:21:48 -07001141done:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001142 /* Check for timeout or receive error.
1143 * Timeouts occur when the sink is not connected
1144 */
Keith Packarda5b3da52009-06-11 22:30:32 -07001145 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001146 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001147 ret = -EIO;
1148 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -07001149 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001150
1151 /* Timeouts occur when the device isn't connected, so they're
1152 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -07001153 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Chris Wilsona5570fe2017-02-23 11:51:02 +00001154 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001155 ret = -ETIMEDOUT;
1156 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001157 }
1158
1159 /* Unload any bytes sent back from the other side */
1160 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
1161 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Rodrigo Vivi14e01882015-12-10 11:12:27 -08001162
1163 /*
1164 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1165 * We have no idea of what happened so we return -EBUSY so
1166 * drm layer takes care for the necessary retries.
1167 */
1168 if (recv_bytes == 0 || recv_bytes > 20) {
1169 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1170 recv_bytes);
1171 /*
1172 * FIXME: This patch was created on top of a series that
1173 * organize the retries at drm level. There EBUSY should
1174 * also take care for 1ms wait before retrying.
1175 * That aux retries re-org is still needed and after that is
1176 * merged we remove this sleep from here.
1177 */
1178 usleep_range(1000, 1500);
1179 ret = -EBUSY;
1180 goto out;
1181 }
1182
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001183 if (recv_bytes > recv_size)
1184 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -04001185
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001186 for (i = 0; i < recv_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001187 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001188 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001189
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001190 ret = recv_bytes;
1191out:
1192 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1193
Jani Nikula884f19e2014-03-14 16:51:14 +02001194 if (vdd)
1195 edp_panel_vdd_off(intel_dp, false);
1196
Ville Syrjälä773538e82014-09-04 14:54:56 +03001197 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001198
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001199 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001200}
1201
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001202#define BARE_ADDRESS_SIZE 3
1203#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +02001204static ssize_t
1205intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001206{
Jani Nikula9d1a1032014-03-14 16:51:15 +02001207 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1208 uint8_t txbuf[20], rxbuf[20];
1209 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001210 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001211
Ville Syrjäläd2d9cbb2015-03-19 11:44:06 +02001212 txbuf[0] = (msg->request << 4) |
1213 ((msg->address >> 16) & 0xf);
1214 txbuf[1] = (msg->address >> 8) & 0xff;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001215 txbuf[2] = msg->address & 0xff;
1216 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001217
Jani Nikula9d1a1032014-03-14 16:51:15 +02001218 switch (msg->request & ~DP_AUX_I2C_MOT) {
1219 case DP_AUX_NATIVE_WRITE:
1220 case DP_AUX_I2C_WRITE:
Ville Syrjäläc1e741222015-08-27 17:23:27 +03001221 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001222 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001223 rxsize = 2; /* 0 or 1 data bytes */
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001224
Jani Nikula9d1a1032014-03-14 16:51:15 +02001225 if (WARN_ON(txsize > 20))
1226 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001227
Ville Syrjälädd788092016-07-28 17:55:04 +03001228 WARN_ON(!msg->buffer != !msg->size);
1229
Imre Deakd81a67c2016-01-29 14:52:26 +02001230 if (msg->buffer)
1231 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001232
Jani Nikula9d1a1032014-03-14 16:51:15 +02001233 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1234 if (ret > 0) {
1235 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001236
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001237 if (ret > 1) {
1238 /* Number of bytes written in a short write. */
1239 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1240 } else {
1241 /* Return payload size. */
1242 ret = msg->size;
1243 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001244 }
Jani Nikula9d1a1032014-03-14 16:51:15 +02001245 break;
1246
1247 case DP_AUX_NATIVE_READ:
1248 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001249 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001250 rxsize = msg->size + 1;
1251
1252 if (WARN_ON(rxsize > 20))
1253 return -E2BIG;
1254
1255 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1256 if (ret > 0) {
1257 msg->reply = rxbuf[0] >> 4;
1258 /*
1259 * Assume happy day, and copy the data. The caller is
1260 * expected to check msg->reply before touching it.
1261 *
1262 * Return payload size.
1263 */
1264 ret--;
1265 memcpy(msg->buffer, rxbuf + 1, ret);
1266 }
1267 break;
1268
1269 default:
1270 ret = -EINVAL;
1271 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001272 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001273
Jani Nikula9d1a1032014-03-14 16:51:15 +02001274 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001275}
1276
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001277static enum port intel_aux_port(struct drm_i915_private *dev_priv,
1278 enum port port)
1279{
1280 const struct ddi_vbt_port_info *info =
1281 &dev_priv->vbt.ddi_port_info[port];
1282 enum port aux_port;
1283
1284 if (!info->alternate_aux_channel) {
1285 DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
1286 port_name(port), port_name(port));
1287 return port;
1288 }
1289
1290 switch (info->alternate_aux_channel) {
1291 case DP_AUX_A:
1292 aux_port = PORT_A;
1293 break;
1294 case DP_AUX_B:
1295 aux_port = PORT_B;
1296 break;
1297 case DP_AUX_C:
1298 aux_port = PORT_C;
1299 break;
1300 case DP_AUX_D:
1301 aux_port = PORT_D;
1302 break;
1303 default:
1304 MISSING_CASE(info->alternate_aux_channel);
1305 aux_port = PORT_A;
1306 break;
1307 }
1308
1309 DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
1310 port_name(aux_port), port_name(port));
1311
1312 return aux_port;
1313}
1314
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001315static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001316 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001317{
1318 switch (port) {
1319 case PORT_B:
1320 case PORT_C:
1321 case PORT_D:
1322 return DP_AUX_CH_CTL(port);
1323 default:
1324 MISSING_CASE(port);
1325 return DP_AUX_CH_CTL(PORT_B);
1326 }
1327}
1328
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001329static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001330 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001331{
1332 switch (port) {
1333 case PORT_B:
1334 case PORT_C:
1335 case PORT_D:
1336 return DP_AUX_CH_DATA(port, index);
1337 default:
1338 MISSING_CASE(port);
1339 return DP_AUX_CH_DATA(PORT_B, index);
1340 }
1341}
1342
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001343static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001344 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001345{
1346 switch (port) {
1347 case PORT_A:
1348 return DP_AUX_CH_CTL(port);
1349 case PORT_B:
1350 case PORT_C:
1351 case PORT_D:
1352 return PCH_DP_AUX_CH_CTL(port);
1353 default:
1354 MISSING_CASE(port);
1355 return DP_AUX_CH_CTL(PORT_A);
1356 }
1357}
1358
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001359static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001360 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001361{
1362 switch (port) {
1363 case PORT_A:
1364 return DP_AUX_CH_DATA(port, index);
1365 case PORT_B:
1366 case PORT_C:
1367 case PORT_D:
1368 return PCH_DP_AUX_CH_DATA(port, index);
1369 default:
1370 MISSING_CASE(port);
1371 return DP_AUX_CH_DATA(PORT_A, index);
1372 }
1373}
1374
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001375static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001376 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001377{
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001378 switch (port) {
1379 case PORT_A:
1380 case PORT_B:
1381 case PORT_C:
1382 case PORT_D:
1383 return DP_AUX_CH_CTL(port);
1384 default:
1385 MISSING_CASE(port);
1386 return DP_AUX_CH_CTL(PORT_A);
1387 }
1388}
1389
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001390static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001391 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001392{
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001393 switch (port) {
1394 case PORT_A:
1395 case PORT_B:
1396 case PORT_C:
1397 case PORT_D:
1398 return DP_AUX_CH_DATA(port, index);
1399 default:
1400 MISSING_CASE(port);
1401 return DP_AUX_CH_DATA(PORT_A, index);
1402 }
1403}
1404
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001405static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001406 enum port port)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001407{
1408 if (INTEL_INFO(dev_priv)->gen >= 9)
1409 return skl_aux_ctl_reg(dev_priv, port);
1410 else if (HAS_PCH_SPLIT(dev_priv))
1411 return ilk_aux_ctl_reg(dev_priv, port);
1412 else
1413 return g4x_aux_ctl_reg(dev_priv, port);
1414}
1415
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001416static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001417 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001418{
1419 if (INTEL_INFO(dev_priv)->gen >= 9)
1420 return skl_aux_data_reg(dev_priv, port, index);
1421 else if (HAS_PCH_SPLIT(dev_priv))
1422 return ilk_aux_data_reg(dev_priv, port, index);
1423 else
1424 return g4x_aux_data_reg(dev_priv, port, index);
1425}
1426
1427static void intel_aux_reg_init(struct intel_dp *intel_dp)
1428{
1429 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001430 enum port port = intel_aux_port(dev_priv,
1431 dp_to_dig_port(intel_dp)->port);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001432 int i;
1433
1434 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1435 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1436 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1437}
1438
Jani Nikula9d1a1032014-03-14 16:51:15 +02001439static void
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001440intel_dp_aux_fini(struct intel_dp *intel_dp)
1441{
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001442 kfree(intel_dp->aux.name);
1443}
1444
Chris Wilson7a418e32016-06-24 14:00:14 +01001445static void
Mika Kaholab6339582016-09-09 14:10:52 +03001446intel_dp_aux_init(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001447{
Jani Nikula33ad6622014-03-14 16:51:16 +02001448 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1449 enum port port = intel_dig_port->port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001450
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001451 intel_aux_reg_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01001452 drm_dp_aux_init(&intel_dp->aux);
David Flynn8316f332010-12-08 16:10:21 +00001453
Chris Wilson7a418e32016-06-24 14:00:14 +01001454 /* Failure to allocate our preferred name is not critical */
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001455 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
Jani Nikula9d1a1032014-03-14 16:51:15 +02001456 intel_dp->aux.transfer = intel_dp_aux_transfer;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001457}
1458
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001459bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301460{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001461 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Navare, Manasi D577c5432016-09-27 16:36:53 -07001462 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001463
Navare, Manasi D577c5432016-09-27 16:36:53 -07001464 if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
1465 IS_BROADWELL(dev_priv) || (INTEL_GEN(dev_priv) >= 9))
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301466 return true;
1467 else
1468 return false;
1469}
1470
Daniel Vetter0e503382014-07-04 11:26:04 -03001471static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001472intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001473 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001474{
1475 struct drm_device *dev = encoder->base.dev;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001476 struct drm_i915_private *dev_priv = to_i915(dev);
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001477 const struct dp_link_dpll *divisor = NULL;
1478 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001479
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001480 if (IS_G4X(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001481 divisor = gen4_dpll;
1482 count = ARRAY_SIZE(gen4_dpll);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001483 } else if (HAS_PCH_SPLIT(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001484 divisor = pch_dpll;
1485 count = ARRAY_SIZE(pch_dpll);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001486 } else if (IS_CHERRYVIEW(dev_priv)) {
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001487 divisor = chv_dpll;
1488 count = ARRAY_SIZE(chv_dpll);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001489 } else if (IS_VALLEYVIEW(dev_priv)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001490 divisor = vlv_dpll;
1491 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001492 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001493
1494 if (divisor && count) {
1495 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001496 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001497 pipe_config->dpll = divisor[i].dpll;
1498 pipe_config->clock_set = true;
1499 break;
1500 }
1501 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001502 }
1503}
1504
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001505static void snprintf_int_array(char *str, size_t len,
1506 const int *array, int nelem)
1507{
1508 int i;
1509
1510 str[0] = '\0';
1511
1512 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001513 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001514 if (r >= len)
1515 return;
1516 str += r;
1517 len -= r;
1518 }
1519}
1520
1521static void intel_dp_print_rates(struct intel_dp *intel_dp)
1522{
Jani Nikula68f357c2017-03-28 17:59:05 +03001523 int common_len;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001524 int common_rates[DP_MAX_SUPPORTED_RATES];
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001525 char str[128]; /* FIXME: too big for stack? */
1526
1527 if ((drm_debug & DRM_UT_KMS) == 0)
1528 return;
1529
Jani Nikula55cfc582017-03-28 17:59:04 +03001530 snprintf_int_array(str, sizeof(str),
1531 intel_dp->source_rates, intel_dp->num_source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001532 DRM_DEBUG_KMS("source rates: %s\n", str);
1533
Jani Nikula68f357c2017-03-28 17:59:05 +03001534 snprintf_int_array(str, sizeof(str),
1535 intel_dp->sink_rates, intel_dp->num_sink_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001536 DRM_DEBUG_KMS("sink rates: %s\n", str);
1537
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001538 common_len = intel_dp_common_rates(intel_dp, common_rates);
1539 snprintf_int_array(str, sizeof(str), common_rates, common_len);
1540 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001541}
1542
Imre Deak489375c2016-10-24 19:33:31 +03001543bool
Imre Deak7b3fc172016-10-25 16:12:39 +03001544__intel_dp_read_desc(struct intel_dp *intel_dp, struct intel_dp_desc *desc)
Mika Kahola0e390a32016-09-09 14:10:53 +03001545{
Imre Deak7b3fc172016-10-25 16:12:39 +03001546 u32 base = drm_dp_is_branch(intel_dp->dpcd) ? DP_BRANCH_OUI :
1547 DP_SINK_OUI;
Mika Kahola0e390a32016-09-09 14:10:53 +03001548
Imre Deak7b3fc172016-10-25 16:12:39 +03001549 return drm_dp_dpcd_read(&intel_dp->aux, base, desc, sizeof(*desc)) ==
1550 sizeof(*desc);
Mika Kahola0e390a32016-09-09 14:10:53 +03001551}
1552
Imre Deak12a47a422016-10-24 19:33:29 +03001553bool intel_dp_read_desc(struct intel_dp *intel_dp)
Mika Kahola1a2724f2016-09-09 14:10:54 +03001554{
Imre Deak7b3fc172016-10-25 16:12:39 +03001555 struct intel_dp_desc *desc = &intel_dp->desc;
1556 bool oui_sup = intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] &
1557 DP_OUI_SUPPORT;
1558 int dev_id_len;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001559
Imre Deak7b3fc172016-10-25 16:12:39 +03001560 if (!__intel_dp_read_desc(intel_dp, desc))
1561 return false;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001562
Imre Deak7b3fc172016-10-25 16:12:39 +03001563 dev_id_len = strnlen(desc->device_id, sizeof(desc->device_id));
1564 DRM_DEBUG_KMS("DP %s: OUI %*phD%s dev-ID %*pE HW-rev %d.%d SW-rev %d.%d\n",
1565 drm_dp_is_branch(intel_dp->dpcd) ? "branch" : "sink",
1566 (int)sizeof(desc->oui), desc->oui, oui_sup ? "" : "(NS)",
1567 dev_id_len, desc->device_id,
1568 desc->hw_rev >> 4, desc->hw_rev & 0xf,
1569 desc->sw_major_rev, desc->sw_minor_rev);
Mika Kahola1a2724f2016-09-09 14:10:54 +03001570
Imre Deak7b3fc172016-10-25 16:12:39 +03001571 return true;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001572}
1573
Ville Syrjälä50fec212015-03-12 17:10:34 +02001574int
1575intel_dp_max_link_rate(struct intel_dp *intel_dp)
1576{
1577 int rates[DP_MAX_SUPPORTED_RATES] = {};
1578 int len;
1579
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001580 len = intel_dp_common_rates(intel_dp, rates);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001581 if (WARN_ON(len <= 0))
1582 return 162000;
1583
Ville Syrjälä1354f732016-07-28 17:50:45 +03001584 return rates[len - 1];
Ville Syrjälä50fec212015-03-12 17:10:34 +02001585}
1586
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001587int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1588{
Jani Nikula8001b752017-03-28 17:59:03 +03001589 int i = intel_dp_rate_index(intel_dp->sink_rates,
1590 intel_dp->num_sink_rates, rate);
Jani Nikulab5c72b22017-03-28 17:59:02 +03001591
1592 if (WARN_ON(i < 0))
1593 i = 0;
1594
1595 return i;
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001596}
1597
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001598void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1599 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001600{
Jani Nikula68f357c2017-03-28 17:59:05 +03001601 /* eDP 1.4 rate select method. */
1602 if (intel_dp->use_rate_select) {
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001603 *link_bw = 0;
1604 *rate_select =
1605 intel_dp_rate_select(intel_dp, port_clock);
1606 } else {
1607 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1608 *rate_select = 0;
1609 }
1610}
1611
Jani Nikulaf580bea2016-09-15 16:28:52 +03001612static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1613 struct intel_crtc_state *pipe_config)
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001614{
1615 int bpp, bpc;
1616
1617 bpp = pipe_config->pipe_bpp;
1618 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1619
1620 if (bpc > 0)
1621 bpp = min(bpp, 3*bpc);
1622
Manasi Navare611032b2017-01-24 08:21:49 -08001623 /* For DP Compliance we override the computed bpp for the pipe */
1624 if (intel_dp->compliance.test_data.bpc != 0) {
1625 pipe_config->pipe_bpp = 3*intel_dp->compliance.test_data.bpc;
1626 pipe_config->dither_force_disable = pipe_config->pipe_bpp == 6*3;
1627 DRM_DEBUG_KMS("Setting pipe_bpp to %d\n",
1628 pipe_config->pipe_bpp);
1629 }
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001630 return bpp;
1631}
1632
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001633bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001634intel_dp_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001635 struct intel_crtc_state *pipe_config,
1636 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001637{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001638 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001639 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001640 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001641 enum port port = dp_to_dig_port(intel_dp)->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001642 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001643 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001644 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001645 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001646 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001647 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001648 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301649 int max_clock;
Manasi Navareda15f7c2017-01-24 08:16:34 -08001650 int link_rate_index;
Daniel Vetter083f9562012-04-20 20:23:49 +02001651 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001652 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001653 int common_rates[DP_MAX_SUPPORTED_RATES] = {};
1654 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001655 uint8_t link_bw, rate_select;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301656
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001657 common_len = intel_dp_common_rates(intel_dp, common_rates);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301658
1659 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001660 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301661
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001662 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001663
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001664 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001665 pipe_config->has_pch_encoder = true;
1666
Vandana Kannanf769cd22014-08-05 07:51:22 -07001667 pipe_config->has_drrs = false;
Jani Nikula9fcb1702015-05-05 16:32:12 +03001668 pipe_config->has_audio = intel_dp->has_audio && port != PORT_A;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001669
Jani Nikuladd06f902012-10-19 14:51:50 +03001670 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1671 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
1672 adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001673
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001674 if (INTEL_GEN(dev_priv) >= 9) {
Chandra Kondurua1b22782015-04-07 15:28:45 -07001675 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001676 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001677 if (ret)
1678 return ret;
1679 }
1680
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001681 if (HAS_GMCH_DISPLAY(dev_priv))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001682 intel_gmch_panel_fitting(intel_crtc, pipe_config,
1683 intel_connector->panel.fitting_mode);
1684 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001685 intel_pch_panel_fitting(intel_crtc, pipe_config,
1686 intel_connector->panel.fitting_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001687 }
1688
Daniel Vettercb1793c2012-06-04 18:39:21 +02001689 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001690 return false;
1691
Manasi Navareda15f7c2017-01-24 08:16:34 -08001692 /* Use values requested by Compliance Test Request */
1693 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
1694 link_rate_index = intel_dp_link_rate_index(intel_dp,
1695 common_rates,
1696 intel_dp->compliance.test_link_rate);
1697 if (link_rate_index >= 0)
1698 min_clock = max_clock = link_rate_index;
1699 min_lane_count = max_lane_count = intel_dp->compliance.test_lane_count;
1700 }
Daniel Vetter083f9562012-04-20 20:23:49 +02001701 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301702 "max bw %d pixel clock %iKHz\n",
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001703 max_lane_count, common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001704 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001705
Daniel Vetter36008362013-03-27 00:44:59 +01001706 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1707 * bpc in between. */
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001708 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
Jani Nikula56071a22014-05-06 14:56:52 +03001709 if (is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301710
1711 /* Get bpp from vbt only for panels that dont have bpp in edid */
1712 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001713 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001714 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001715 dev_priv->vbt.edp.bpp);
1716 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001717 }
1718
Jani Nikula344c5bb2014-09-09 11:25:13 +03001719 /*
1720 * Use the maximum clock and number of lanes the eDP panel
1721 * advertizes being capable of. The panels are generally
1722 * designed to support only a single clock and lane
1723 * configuration, and typically these values correspond to the
1724 * native resolution of the panel.
1725 */
1726 min_lane_count = max_lane_count;
1727 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001728 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001729
Daniel Vetter36008362013-03-27 00:44:59 +01001730 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001731 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1732 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001733
Dave Airliec6930992014-07-14 11:04:39 +10001734 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301735 for (lane_count = min_lane_count;
1736 lane_count <= max_lane_count;
1737 lane_count <<= 1) {
1738
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001739 link_clock = common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001740 link_avail = intel_dp_max_data_rate(link_clock,
1741 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001742
Daniel Vetter36008362013-03-27 00:44:59 +01001743 if (mode_rate <= link_avail) {
1744 goto found;
1745 }
1746 }
1747 }
1748 }
1749
1750 return false;
1751
1752found:
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001753 if (intel_dp->color_range_auto) {
1754 /*
1755 * See:
1756 * CEA-861-E - 5.1 Default Encoding Parameters
1757 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1758 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001759 pipe_config->limited_color_range =
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02001760 bpp != 18 &&
1761 drm_default_rgb_quant_range(adjusted_mode) ==
1762 HDMI_QUANTIZATION_RANGE_LIMITED;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001763 } else {
1764 pipe_config->limited_color_range =
1765 intel_dp->limited_color_range;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001766 }
1767
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001768 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301769
Daniel Vetter657445f2013-05-04 10:09:18 +02001770 pipe_config->pipe_bpp = bpp;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001771 pipe_config->port_clock = common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001772
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001773 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1774 &link_bw, &rate_select);
1775
1776 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1777 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001778 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001779 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1780 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001781
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001782 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001783 adjusted_mode->crtc_clock,
1784 pipe_config->port_clock,
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001785 &pipe_config->dp_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001786
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301787 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301788 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001789 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301790 intel_link_compute_m_n(bpp, lane_count,
1791 intel_connector->panel.downclock_mode->clock,
1792 pipe_config->port_clock,
1793 &pipe_config->dp_m2_n2);
1794 }
1795
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001796 /*
1797 * DPLL0 VCO may need to be adjusted to get the correct
1798 * clock for eDP. This will affect cdclk as well.
1799 */
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001800 if (is_edp(intel_dp) && IS_GEN9_BC(dev_priv)) {
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001801 int vco;
1802
1803 switch (pipe_config->port_clock / 2) {
1804 case 108000:
1805 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001806 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001807 break;
1808 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001809 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001810 break;
1811 }
1812
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +02001813 to_intel_atomic_state(pipe_config->base.state)->cdclk.logical.vco = vco;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001814 }
1815
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001816 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001817 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001818
Daniel Vetter36008362013-03-27 00:44:59 +01001819 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001820}
1821
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001822void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001823 int link_rate, uint8_t lane_count,
1824 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001825{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001826 intel_dp->link_rate = link_rate;
1827 intel_dp->lane_count = lane_count;
1828 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001829}
1830
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001831static void intel_dp_prepare(struct intel_encoder *encoder,
1832 struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001833{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001834 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001835 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001836 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001837 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001838 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001839 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001840
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001841 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1842 pipe_config->lane_count,
1843 intel_crtc_has_type(pipe_config,
1844 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001845
Keith Packard417e8222011-11-01 19:54:11 -07001846 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001847 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001848 *
1849 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001850 * SNB CPU
1851 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001852 * CPT PCH
1853 *
1854 * IBX PCH and CPU are the same for almost everything,
1855 * except that the CPU DP PLL is configured in this
1856 * register
1857 *
1858 * CPT PCH is quite different, having many bits moved
1859 * to the TRANS_DP_CTL register instead. That
1860 * configuration happens (oddly) in ironlake_pch_enable
1861 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001862
Keith Packard417e8222011-11-01 19:54:11 -07001863 /* Preserve the BIOS-computed detected bit. This is
1864 * supposed to be read-only.
1865 */
1866 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001867
Keith Packard417e8222011-11-01 19:54:11 -07001868 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001869 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001870 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001871
Keith Packard417e8222011-11-01 19:54:11 -07001872 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001873
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001874 if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001875 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1876 intel_dp->DP |= DP_SYNC_HS_HIGH;
1877 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1878 intel_dp->DP |= DP_SYNC_VS_HIGH;
1879 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1880
Jani Nikula6aba5b62013-10-04 15:08:10 +03001881 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001882 intel_dp->DP |= DP_ENHANCED_FRAMING;
1883
Daniel Vetter7c62a162013-06-01 17:16:20 +02001884 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001885 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001886 u32 trans_dp;
1887
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001888 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001889
1890 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1891 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1892 trans_dp |= TRANS_DP_ENH_FRAMING;
1893 else
1894 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1895 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001896 } else {
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02001897 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001898 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001899
1900 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1901 intel_dp->DP |= DP_SYNC_HS_HIGH;
1902 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1903 intel_dp->DP |= DP_SYNC_VS_HIGH;
1904 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1905
Jani Nikula6aba5b62013-10-04 15:08:10 +03001906 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001907 intel_dp->DP |= DP_ENHANCED_FRAMING;
1908
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001909 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001910 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001911 else if (crtc->pipe == PIPE_B)
1912 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001913 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001914}
1915
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001916#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1917#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001918
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001919#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1920#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001921
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001922#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1923#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001924
Imre Deakde9c1b62016-06-16 20:01:46 +03001925static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
1926 struct intel_dp *intel_dp);
1927
Daniel Vetter4be73782014-01-17 14:39:48 +01001928static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001929 u32 mask,
1930 u32 value)
1931{
Paulo Zanoni30add222012-10-26 19:05:45 -02001932 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001933 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001934 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001935
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001936 lockdep_assert_held(&dev_priv->pps_mutex);
1937
Imre Deakde9c1b62016-06-16 20:01:46 +03001938 intel_pps_verify_state(dev_priv, intel_dp);
1939
Jani Nikulabf13e812013-09-06 07:40:05 +03001940 pp_stat_reg = _pp_stat_reg(intel_dp);
1941 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001942
1943 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001944 mask, value,
1945 I915_READ(pp_stat_reg),
1946 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001947
Chris Wilson9036ff02016-06-30 15:33:09 +01001948 if (intel_wait_for_register(dev_priv,
1949 pp_stat_reg, mask, value,
1950 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001951 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001952 I915_READ(pp_stat_reg),
1953 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001954
1955 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001956}
1957
Daniel Vetter4be73782014-01-17 14:39:48 +01001958static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001959{
1960 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001961 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001962}
1963
Daniel Vetter4be73782014-01-17 14:39:48 +01001964static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001965{
Keith Packardbd943152011-09-18 23:09:52 -07001966 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001967 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001968}
Keith Packardbd943152011-09-18 23:09:52 -07001969
Daniel Vetter4be73782014-01-17 14:39:48 +01001970static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001971{
Abhay Kumard28d4732016-01-22 17:39:04 -08001972 ktime_t panel_power_on_time;
1973 s64 panel_power_off_duration;
1974
Keith Packard99ea7122011-11-01 19:57:50 -07001975 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001976
Abhay Kumard28d4732016-01-22 17:39:04 -08001977 /* take the difference of currrent time and panel power off time
1978 * and then make panel wait for t11_t12 if needed. */
1979 panel_power_on_time = ktime_get_boottime();
1980 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1981
Paulo Zanonidce56b32013-12-19 14:29:40 -02001982 /* When we disable the VDD override bit last we have to do the manual
1983 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08001984 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
1985 wait_remaining_ms_from_jiffies(jiffies,
1986 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001987
Daniel Vetter4be73782014-01-17 14:39:48 +01001988 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001989}
Keith Packardbd943152011-09-18 23:09:52 -07001990
Daniel Vetter4be73782014-01-17 14:39:48 +01001991static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001992{
1993 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1994 intel_dp->backlight_on_delay);
1995}
1996
Daniel Vetter4be73782014-01-17 14:39:48 +01001997static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001998{
1999 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
2000 intel_dp->backlight_off_delay);
2001}
Keith Packard99ea7122011-11-01 19:57:50 -07002002
Keith Packard832dd3c2011-11-01 19:34:06 -07002003/* Read the current pp_control value, unlocking the register if it
2004 * is locked
2005 */
2006
Jesse Barnes453c5422013-03-28 09:55:41 -07002007static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07002008{
Jesse Barnes453c5422013-03-28 09:55:41 -07002009 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002010 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07002011 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07002012
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002013 lockdep_assert_held(&dev_priv->pps_mutex);
2014
Jani Nikulabf13e812013-09-06 07:40:05 +03002015 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03002016 if (WARN_ON(!HAS_DDI(dev_priv) &&
2017 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05302018 control &= ~PANEL_UNLOCK_MASK;
2019 control |= PANEL_UNLOCK_REGS;
2020 }
Keith Packard832dd3c2011-11-01 19:34:06 -07002021 return control;
Keith Packardbd943152011-09-18 23:09:52 -07002022}
2023
Ville Syrjälä951468f2014-09-04 14:55:31 +03002024/*
2025 * Must be paired with edp_panel_vdd_off().
2026 * Must hold pps_mutex around the whole on/off sequence.
2027 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2028 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03002029static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002030{
Paulo Zanoni30add222012-10-26 19:05:45 -02002031 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002032 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002033 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes5d613502011-01-24 17:10:54 -08002034 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002035 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002036 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08002037
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002038 lockdep_assert_held(&dev_priv->pps_mutex);
2039
Keith Packard97af61f572011-09-28 16:23:51 -07002040 if (!is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002041 return false;
Keith Packardbd943152011-09-18 23:09:52 -07002042
Egbert Eich2c623c12014-11-25 12:54:57 +01002043 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002044 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07002045
Daniel Vetter4be73782014-01-17 14:39:48 +01002046 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002047 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002048
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002049 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002050
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002051 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
2052 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07002053
Daniel Vetter4be73782014-01-17 14:39:48 +01002054 if (!edp_have_panel_power(intel_dp))
2055 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07002056
Jesse Barnes453c5422013-03-28 09:55:41 -07002057 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002058 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07002059
Jani Nikulabf13e812013-09-06 07:40:05 +03002060 pp_stat_reg = _pp_stat_reg(intel_dp);
2061 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002062
2063 I915_WRITE(pp_ctrl_reg, pp);
2064 POSTING_READ(pp_ctrl_reg);
2065 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2066 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07002067 /*
2068 * If the panel wasn't on, delay before accessing aux channel
2069 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002070 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002071 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
2072 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07002073 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07002074 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002075
2076 return need_to_disable;
2077}
2078
Ville Syrjälä951468f2014-09-04 14:55:31 +03002079/*
2080 * Must be paired with intel_edp_panel_vdd_off() or
2081 * intel_edp_panel_off().
2082 * Nested calls to these functions are not allowed since
2083 * we drop the lock. Caller must use some higher level
2084 * locking to prevent nested calls from other threads.
2085 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01002086void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002087{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002088 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002089
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002090 if (!is_edp(intel_dp))
2091 return;
2092
Ville Syrjälä773538e82014-09-04 14:54:56 +03002093 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002094 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002095 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002096
Rob Clarke2c719b2014-12-15 13:56:32 -05002097 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002098 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08002099}
2100
Daniel Vetter4be73782014-01-17 14:39:48 +01002101static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002102{
Paulo Zanoni30add222012-10-26 19:05:45 -02002103 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002104 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002105 struct intel_digital_port *intel_dig_port =
2106 dp_to_dig_port(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002107 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002108 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002109
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002110 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002111
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002112 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002113
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002114 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002115 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002116
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002117 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2118 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002119
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002120 pp = ironlake_get_pp_control(intel_dp);
2121 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002122
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002123 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2124 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002125
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002126 I915_WRITE(pp_ctrl_reg, pp);
2127 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002128
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002129 /* Make sure sequencer is idle before allowing subsequent activity */
2130 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2131 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002132
Imre Deak5a162e22016-08-10 14:07:30 +03002133 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002134 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002135
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002136 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002137}
2138
Daniel Vetter4be73782014-01-17 14:39:48 +01002139static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002140{
2141 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2142 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002143
Ville Syrjälä773538e82014-09-04 14:54:56 +03002144 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002145 if (!intel_dp->want_panel_vdd)
2146 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002147 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002148}
2149
Imre Deakaba86892014-07-30 15:57:31 +03002150static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2151{
2152 unsigned long delay;
2153
2154 /*
2155 * Queue the timer to fire a long time from now (relative to the power
2156 * down delay) to keep the panel power up across a sequence of
2157 * operations.
2158 */
2159 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2160 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2161}
2162
Ville Syrjälä951468f2014-09-04 14:55:31 +03002163/*
2164 * Must be paired with edp_panel_vdd_on().
2165 * Must hold pps_mutex around the whole on/off sequence.
2166 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2167 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002168static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002169{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002170 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002171
2172 lockdep_assert_held(&dev_priv->pps_mutex);
2173
Keith Packard97af61f572011-09-28 16:23:51 -07002174 if (!is_edp(intel_dp))
2175 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002176
Rob Clarke2c719b2014-12-15 13:56:32 -05002177 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002178 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002179
Keith Packardbd943152011-09-18 23:09:52 -07002180 intel_dp->want_panel_vdd = false;
2181
Imre Deakaba86892014-07-30 15:57:31 +03002182 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002183 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002184 else
2185 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002186}
2187
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002188static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002189{
Paulo Zanoni30add222012-10-26 19:05:45 -02002190 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002191 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002192 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002193 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002194
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002195 lockdep_assert_held(&dev_priv->pps_mutex);
2196
Keith Packard97af61f572011-09-28 16:23:51 -07002197 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002198 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002199
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002200 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2201 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002202
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002203 if (WARN(edp_have_panel_power(intel_dp),
2204 "eDP port %c panel power already on\n",
2205 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002206 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002207
Daniel Vetter4be73782014-01-17 14:39:48 +01002208 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002209
Jani Nikulabf13e812013-09-06 07:40:05 +03002210 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002211 pp = ironlake_get_pp_control(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002212 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002213 /* ILK workaround: disable reset around power sequence */
2214 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002215 I915_WRITE(pp_ctrl_reg, pp);
2216 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002217 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002218
Imre Deak5a162e22016-08-10 14:07:30 +03002219 pp |= PANEL_POWER_ON;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002220 if (!IS_GEN5(dev_priv))
Keith Packard99ea7122011-11-01 19:57:50 -07002221 pp |= PANEL_POWER_RESET;
2222
Jesse Barnes453c5422013-03-28 09:55:41 -07002223 I915_WRITE(pp_ctrl_reg, pp);
2224 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002225
Daniel Vetter4be73782014-01-17 14:39:48 +01002226 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002227 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002228
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002229 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002230 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002231 I915_WRITE(pp_ctrl_reg, pp);
2232 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002233 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002234}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002235
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002236void intel_edp_panel_on(struct intel_dp *intel_dp)
2237{
2238 if (!is_edp(intel_dp))
2239 return;
2240
2241 pps_lock(intel_dp);
2242 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002243 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002244}
2245
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002246
2247static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002248{
Paulo Zanoni30add222012-10-26 19:05:45 -02002249 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002250 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002251 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002252 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002253
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002254 lockdep_assert_held(&dev_priv->pps_mutex);
2255
Keith Packard97af61f572011-09-28 16:23:51 -07002256 if (!is_edp(intel_dp))
2257 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002258
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002259 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2260 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002261
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002262 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2263 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002264
Jesse Barnes453c5422013-03-28 09:55:41 -07002265 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002266 /* We need to switch off panel power _and_ force vdd, for otherwise some
2267 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002268 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002269 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002270
Jani Nikulabf13e812013-09-06 07:40:05 +03002271 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002272
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002273 intel_dp->want_panel_vdd = false;
2274
Jesse Barnes453c5422013-03-28 09:55:41 -07002275 I915_WRITE(pp_ctrl_reg, pp);
2276 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002277
Abhay Kumard28d4732016-01-22 17:39:04 -08002278 intel_dp->panel_power_off_time = ktime_get_boottime();
Daniel Vetter4be73782014-01-17 14:39:48 +01002279 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002280
2281 /* We got a reference when we enabled the VDD. */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002282 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002283}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002284
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002285void intel_edp_panel_off(struct intel_dp *intel_dp)
2286{
2287 if (!is_edp(intel_dp))
2288 return;
2289
2290 pps_lock(intel_dp);
2291 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002292 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002293}
2294
Jani Nikula1250d102014-08-12 17:11:39 +03002295/* Enable backlight in the panel power control. */
2296static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002297{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002298 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2299 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002300 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002301 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002302 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002303
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002304 /*
2305 * If we enable the backlight right away following a panel power
2306 * on, we may see slight flicker as the panel syncs with the eDP
2307 * link. So delay a bit to make sure the image is solid before
2308 * allowing it to appear.
2309 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002310 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002311
Ville Syrjälä773538e82014-09-04 14:54:56 +03002312 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002313
Jesse Barnes453c5422013-03-28 09:55:41 -07002314 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002315 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002316
Jani Nikulabf13e812013-09-06 07:40:05 +03002317 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002318
2319 I915_WRITE(pp_ctrl_reg, pp);
2320 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002321
Ville Syrjälä773538e82014-09-04 14:54:56 +03002322 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002323}
2324
Jani Nikula1250d102014-08-12 17:11:39 +03002325/* Enable backlight PWM and backlight PP control. */
2326void intel_edp_backlight_on(struct intel_dp *intel_dp)
2327{
2328 if (!is_edp(intel_dp))
2329 return;
2330
2331 DRM_DEBUG_KMS("\n");
2332
2333 intel_panel_enable_backlight(intel_dp->attached_connector);
2334 _intel_edp_backlight_on(intel_dp);
2335}
2336
2337/* Disable backlight in the panel power control. */
2338static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002339{
Paulo Zanoni30add222012-10-26 19:05:45 -02002340 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002341 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002342 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002343 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002344
Keith Packardf01eca22011-09-28 16:48:10 -07002345 if (!is_edp(intel_dp))
2346 return;
2347
Ville Syrjälä773538e82014-09-04 14:54:56 +03002348 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002349
Jesse Barnes453c5422013-03-28 09:55:41 -07002350 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002351 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002352
Jani Nikulabf13e812013-09-06 07:40:05 +03002353 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002354
2355 I915_WRITE(pp_ctrl_reg, pp);
2356 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002357
Ville Syrjälä773538e82014-09-04 14:54:56 +03002358 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002359
Paulo Zanonidce56b32013-12-19 14:29:40 -02002360 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002361 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002362}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002363
Jani Nikula1250d102014-08-12 17:11:39 +03002364/* Disable backlight PP control and backlight PWM. */
2365void intel_edp_backlight_off(struct intel_dp *intel_dp)
2366{
2367 if (!is_edp(intel_dp))
2368 return;
2369
2370 DRM_DEBUG_KMS("\n");
2371
2372 _intel_edp_backlight_off(intel_dp);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002373 intel_panel_disable_backlight(intel_dp->attached_connector);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002374}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002375
Jani Nikula73580fb72014-08-12 17:11:41 +03002376/*
2377 * Hook for controlling the panel power control backlight through the bl_power
2378 * sysfs attribute. Take care to handle multiple calls.
2379 */
2380static void intel_edp_backlight_power(struct intel_connector *connector,
2381 bool enable)
2382{
2383 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002384 bool is_enabled;
2385
Ville Syrjälä773538e82014-09-04 14:54:56 +03002386 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002387 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002388 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002389
2390 if (is_enabled == enable)
2391 return;
2392
Jani Nikula23ba9372014-08-27 14:08:43 +03002393 DRM_DEBUG_KMS("panel power control backlight %s\n",
2394 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002395
2396 if (enable)
2397 _intel_edp_backlight_on(intel_dp);
2398 else
2399 _intel_edp_backlight_off(intel_dp);
2400}
2401
Ville Syrjälä64e10772015-10-29 21:26:01 +02002402static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2403{
2404 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2405 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2406 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2407
2408 I915_STATE_WARN(cur_state != state,
2409 "DP port %c state assertion failure (expected %s, current %s)\n",
2410 port_name(dig_port->port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002411 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002412}
2413#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2414
2415static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2416{
2417 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2418
2419 I915_STATE_WARN(cur_state != state,
2420 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002421 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002422}
2423#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2424#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2425
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002426static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2427 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002428{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002429 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002430 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002431
Ville Syrjälä64e10772015-10-29 21:26:01 +02002432 assert_pipe_disabled(dev_priv, crtc->pipe);
2433 assert_dp_port_disabled(intel_dp);
2434 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002435
Ville Syrjäläabfce942015-10-29 21:26:03 +02002436 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002437 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002438
2439 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2440
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002441 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002442 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2443 else
2444 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2445
2446 I915_WRITE(DP_A, intel_dp->DP);
2447 POSTING_READ(DP_A);
2448 udelay(500);
2449
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002450 /*
2451 * [DevILK] Work around required when enabling DP PLL
2452 * while a pipe is enabled going to FDI:
2453 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2454 * 2. Program DP PLL enable
2455 */
2456 if (IS_GEN5(dev_priv))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02002457 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002458
Daniel Vetter07679352012-09-06 22:15:42 +02002459 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002460
Daniel Vetter07679352012-09-06 22:15:42 +02002461 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002462 POSTING_READ(DP_A);
2463 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002464}
2465
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002466static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002467{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002468 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002469 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2470 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002471
Ville Syrjälä64e10772015-10-29 21:26:01 +02002472 assert_pipe_disabled(dev_priv, crtc->pipe);
2473 assert_dp_port_disabled(intel_dp);
2474 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002475
Ville Syrjäläabfce942015-10-29 21:26:03 +02002476 DRM_DEBUG_KMS("disabling eDP PLL\n");
2477
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002478 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002479
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002480 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002481 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002482 udelay(200);
2483}
2484
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002485/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002486void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002487{
2488 int ret, i;
2489
2490 /* Should have a valid DPCD by this point */
2491 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2492 return;
2493
2494 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002495 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2496 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002497 } else {
Imre Deak357c0ae2016-11-21 21:15:06 +02002498 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
2499
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002500 /*
2501 * When turning on, we need to retry for 1ms to give the sink
2502 * time to wake up.
2503 */
2504 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002505 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2506 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002507 if (ret == 1)
2508 break;
2509 msleep(1);
2510 }
Imre Deak357c0ae2016-11-21 21:15:06 +02002511
2512 if (ret == 1 && lspcon->active)
2513 lspcon_wait_pcon_mode(lspcon);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002514 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002515
2516 if (ret != 1)
2517 DRM_DEBUG_KMS("failed to %s sink power state\n",
2518 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002519}
2520
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002521static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2522 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002523{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002524 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002525 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002526 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002527 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002528 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002529 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002530
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002531 if (!intel_display_power_get_if_enabled(dev_priv,
2532 encoder->power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002533 return false;
2534
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002535 ret = false;
2536
Imre Deak6d129be2014-03-05 16:20:54 +02002537 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002538
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002539 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002540 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002541
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002542 if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002543 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002544 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002545 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002546
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002547 for_each_pipe(dev_priv, p) {
2548 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2549 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2550 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002551 ret = true;
2552
2553 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002554 }
2555 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002556
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002557 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002558 i915_mmio_reg_offset(intel_dp->output_reg));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002559 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002560 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2561 } else {
2562 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002563 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002564
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002565 ret = true;
2566
2567out:
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002568 intel_display_power_put(dev_priv, encoder->power_domain);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002569
2570 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002571}
2572
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002573static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002574 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002575{
2576 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002577 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002578 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002579 struct drm_i915_private *dev_priv = to_i915(dev);
Xiong Zhang63000ef2013-06-28 12:59:06 +08002580 enum port port = dp_to_dig_port(intel_dp)->port;
2581 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002582
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002583 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002584
2585 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002586
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002587 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002588 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2589
2590 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002591 flags |= DRM_MODE_FLAG_PHSYNC;
2592 else
2593 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002594
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002595 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002596 flags |= DRM_MODE_FLAG_PVSYNC;
2597 else
2598 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002599 } else {
2600 if (tmp & DP_SYNC_HS_HIGH)
2601 flags |= DRM_MODE_FLAG_PHSYNC;
2602 else
2603 flags |= DRM_MODE_FLAG_NHSYNC;
2604
2605 if (tmp & DP_SYNC_VS_HIGH)
2606 flags |= DRM_MODE_FLAG_PVSYNC;
2607 else
2608 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002609 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002610
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002611 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002612
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02002613 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002614 pipe_config->limited_color_range = true;
2615
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002616 pipe_config->lane_count =
2617 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2618
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002619 intel_dp_get_m_n(crtc, pipe_config);
2620
Ville Syrjälä18442d02013-09-13 16:00:08 +03002621 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002622 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002623 pipe_config->port_clock = 162000;
2624 else
2625 pipe_config->port_clock = 270000;
2626 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002627
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002628 pipe_config->base.adjusted_mode.crtc_clock =
2629 intel_dotclock_calculate(pipe_config->port_clock,
2630 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002631
Jani Nikula6aa23e62016-03-24 17:50:20 +02002632 if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
2633 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002634 /*
2635 * This is a big fat ugly hack.
2636 *
2637 * Some machines in UEFI boot mode provide us a VBT that has 18
2638 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2639 * unknown we fail to light up. Yet the same BIOS boots up with
2640 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2641 * max, not what it tells us to use.
2642 *
2643 * Note: This will still be broken if the eDP panel is not lit
2644 * up by the BIOS, and thus we can't get the mode at module
2645 * load.
2646 */
2647 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002648 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2649 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002650 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002651}
2652
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002653static void intel_disable_dp(struct intel_encoder *encoder,
2654 struct intel_crtc_state *old_crtc_state,
2655 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002656{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002657 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002658 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002659
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002660 if (old_crtc_state->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002661 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002662
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002663 if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv))
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002664 intel_psr_disable(intel_dp);
2665
Daniel Vetter6cb49832012-05-20 17:14:50 +02002666 /* Make sure the panel is off before trying to change the mode. But also
2667 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002668 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01002669 intel_edp_backlight_off(intel_dp);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002670 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002671 intel_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02002672
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002673 /* disable the port before the pipe on g4x */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002674 if (INTEL_GEN(dev_priv) < 5)
Daniel Vetter37398502012-09-06 22:15:44 +02002675 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07002676}
2677
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002678static void ilk_post_disable_dp(struct intel_encoder *encoder,
2679 struct intel_crtc_state *old_crtc_state,
2680 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002681{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002682 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002683 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002684
Ville Syrjälä49277c32014-03-31 18:21:26 +03002685 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002686
2687 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002688 if (port == PORT_A)
2689 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002690}
2691
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002692static void vlv_post_disable_dp(struct intel_encoder *encoder,
2693 struct intel_crtc_state *old_crtc_state,
2694 struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002695{
2696 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2697
2698 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002699}
2700
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002701static void chv_post_disable_dp(struct intel_encoder *encoder,
2702 struct intel_crtc_state *old_crtc_state,
2703 struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002704{
2705 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002706 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002707 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002708
2709 intel_dp_link_down(intel_dp);
2710
Ville Syrjäläa5805162015-05-26 20:42:30 +03002711 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002712
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002713 /* Assert data lane reset */
2714 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002715
Ville Syrjäläa5805162015-05-26 20:42:30 +03002716 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002717}
2718
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002719static void
2720_intel_dp_set_link_train(struct intel_dp *intel_dp,
2721 uint32_t *DP,
2722 uint8_t dp_train_pat)
2723{
2724 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2725 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002726 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002727 enum port port = intel_dig_port->port;
2728
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002729 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2730 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2731 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2732
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002733 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002734 uint32_t temp = I915_READ(DP_TP_CTL(port));
2735
2736 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2737 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2738 else
2739 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2740
2741 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2742 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2743 case DP_TRAINING_PATTERN_DISABLE:
2744 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2745
2746 break;
2747 case DP_TRAINING_PATTERN_1:
2748 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2749 break;
2750 case DP_TRAINING_PATTERN_2:
2751 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2752 break;
2753 case DP_TRAINING_PATTERN_3:
2754 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2755 break;
2756 }
2757 I915_WRITE(DP_TP_CTL(port), temp);
2758
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002759 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002760 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002761 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2762
2763 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2764 case DP_TRAINING_PATTERN_DISABLE:
2765 *DP |= DP_LINK_TRAIN_OFF_CPT;
2766 break;
2767 case DP_TRAINING_PATTERN_1:
2768 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2769 break;
2770 case DP_TRAINING_PATTERN_2:
2771 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2772 break;
2773 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002774 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002775 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2776 break;
2777 }
2778
2779 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002780 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002781 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2782 else
2783 *DP &= ~DP_LINK_TRAIN_MASK;
2784
2785 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2786 case DP_TRAINING_PATTERN_DISABLE:
2787 *DP |= DP_LINK_TRAIN_OFF;
2788 break;
2789 case DP_TRAINING_PATTERN_1:
2790 *DP |= DP_LINK_TRAIN_PAT_1;
2791 break;
2792 case DP_TRAINING_PATTERN_2:
2793 *DP |= DP_LINK_TRAIN_PAT_2;
2794 break;
2795 case DP_TRAINING_PATTERN_3:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002796 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002797 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2798 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002799 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002800 *DP |= DP_LINK_TRAIN_PAT_2;
2801 }
2802 break;
2803 }
2804 }
2805}
2806
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002807static void intel_dp_enable_port(struct intel_dp *intel_dp,
2808 struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002809{
2810 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002811 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002812
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002813 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002814
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002815 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002816
2817 /*
2818 * Magic for VLV/CHV. We _must_ first set up the register
2819 * without actually enabling the port, and then do another
2820 * write to enable the port. Otherwise link training will
2821 * fail when the power sequencer is freshly used for this port.
2822 */
2823 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002824 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002825 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002826
2827 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2828 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002829}
2830
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002831static void intel_enable_dp(struct intel_encoder *encoder,
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002832 struct intel_crtc_state *pipe_config,
2833 struct drm_connector_state *conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002834{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002835 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2836 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002837 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulac1dec792014-10-27 16:26:56 +02002838 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002839 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002840 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002841
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002842 if (WARN_ON(dp_reg & DP_PORT_EN))
2843 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002844
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002845 pps_lock(intel_dp);
2846
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002847 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002848 vlv_init_panel_power_sequencer(intel_dp);
2849
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002850 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002851
2852 edp_panel_vdd_on(intel_dp);
2853 edp_panel_on(intel_dp);
2854 edp_panel_vdd_off(intel_dp, true);
2855
2856 pps_unlock(intel_dp);
2857
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002858 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002859 unsigned int lane_mask = 0x0;
2860
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002861 if (IS_CHERRYVIEW(dev_priv))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002862 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002863
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002864 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2865 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002866 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002867
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002868 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2869 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002870 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002871
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002872 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002873 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002874 pipe_name(pipe));
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002875 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Jani Nikulac1dec792014-10-27 16:26:56 +02002876 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002877}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002878
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002879static void g4x_enable_dp(struct intel_encoder *encoder,
2880 struct intel_crtc_state *pipe_config,
2881 struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03002882{
Jani Nikula828f5c62013-09-05 16:44:45 +03002883 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2884
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002885 intel_enable_dp(encoder, pipe_config, conn_state);
Daniel Vetter4be73782014-01-17 14:39:48 +01002886 intel_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002887}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002888
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002889static void vlv_enable_dp(struct intel_encoder *encoder,
2890 struct intel_crtc_state *pipe_config,
2891 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002892{
Jani Nikula828f5c62013-09-05 16:44:45 +03002893 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2894
Daniel Vetter4be73782014-01-17 14:39:48 +01002895 intel_edp_backlight_on(intel_dp);
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002896 intel_psr_enable(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002897}
2898
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002899static void g4x_pre_enable_dp(struct intel_encoder *encoder,
2900 struct intel_crtc_state *pipe_config,
2901 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002902{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002903 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002904 enum port port = dp_to_dig_port(intel_dp)->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002905
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002906 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002907
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002908 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002909 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002910 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002911}
2912
Ville Syrjälä83b84592014-10-16 21:29:51 +03002913static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2914{
2915 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002916 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002917 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03002918 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002919
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002920 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
2921
Ville Syrjäläd1586942017-02-08 19:52:54 +02002922 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2923 return;
2924
Ville Syrjälä83b84592014-10-16 21:29:51 +03002925 edp_panel_vdd_off_sync(intel_dp);
2926
2927 /*
2928 * VLV seems to get confused when multiple power seqeuencers
2929 * have the same port selected (even if only one has power/vdd
2930 * enabled). The failure manifests as vlv_wait_port_ready() failing
2931 * CHV on the other hand doesn't seem to mind having the same port
2932 * selected in multiple power seqeuencers, but let's clear the
2933 * port select always when logically disconnecting a power sequencer
2934 * from a port.
2935 */
2936 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2937 pipe_name(pipe), port_name(intel_dig_port->port));
2938 I915_WRITE(pp_on_reg, 0);
2939 POSTING_READ(pp_on_reg);
2940
2941 intel_dp->pps_pipe = INVALID_PIPE;
2942}
2943
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002944static void vlv_steal_power_sequencer(struct drm_device *dev,
2945 enum pipe pipe)
2946{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002947 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002948 struct intel_encoder *encoder;
2949
2950 lockdep_assert_held(&dev_priv->pps_mutex);
2951
Jani Nikula19c80542015-12-16 12:48:16 +02002952 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002953 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002954 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002955
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002956 if (encoder->type != INTEL_OUTPUT_DP &&
2957 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002958 continue;
2959
2960 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002961 port = dp_to_dig_port(intel_dp)->port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002962
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002963 WARN(intel_dp->active_pipe == pipe,
2964 "stealing pipe %c power sequencer from active (e)DP port %c\n",
2965 pipe_name(pipe), port_name(port));
2966
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002967 if (intel_dp->pps_pipe != pipe)
2968 continue;
2969
2970 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03002971 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002972
2973 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002974 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002975 }
2976}
2977
2978static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
2979{
2980 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2981 struct intel_encoder *encoder = &intel_dig_port->base;
2982 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002983 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002984 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002985
2986 lockdep_assert_held(&dev_priv->pps_mutex);
2987
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002988 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002989
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002990 if (intel_dp->pps_pipe != INVALID_PIPE &&
2991 intel_dp->pps_pipe != crtc->pipe) {
2992 /*
2993 * If another power sequencer was being used on this
2994 * port previously make sure to turn off vdd there while
2995 * we still have control of it.
2996 */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002997 vlv_detach_power_sequencer(intel_dp);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002998 }
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002999
3000 /*
3001 * We may be stealing the power
3002 * sequencer from another port.
3003 */
3004 vlv_steal_power_sequencer(dev, crtc->pipe);
3005
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003006 intel_dp->active_pipe = crtc->pipe;
3007
3008 if (!is_edp(intel_dp))
3009 return;
3010
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003011 /* now it's all ours */
3012 intel_dp->pps_pipe = crtc->pipe;
3013
3014 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
3015 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
3016
3017 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03003018 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02003019 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003020}
3021
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003022static void vlv_pre_enable_dp(struct intel_encoder *encoder,
3023 struct intel_crtc_state *pipe_config,
3024 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03003025{
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03003026 vlv_phy_pre_encoder_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003027
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003028 intel_enable_dp(encoder, pipe_config, conn_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003029}
3030
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003031static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
3032 struct intel_crtc_state *pipe_config,
3033 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07003034{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003035 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02003036
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03003037 vlv_phy_pre_pll_enable(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003038}
3039
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003040static void chv_pre_enable_dp(struct intel_encoder *encoder,
3041 struct intel_crtc_state *pipe_config,
3042 struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003043{
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003044 chv_phy_pre_encoder_enable(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003045
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003046 intel_enable_dp(encoder, pipe_config, conn_state);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03003047
3048 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003049 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003050}
3051
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003052static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
3053 struct intel_crtc_state *pipe_config,
3054 struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03003055{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003056 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03003057
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03003058 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03003059}
3060
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003061static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
3062 struct intel_crtc_state *pipe_config,
3063 struct drm_connector_state *conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003064{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03003065 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003066}
3067
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003068/*
3069 * Fetch AUX CH registers 0x202 - 0x207 which contain
3070 * link status information
3071 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003072bool
Keith Packard93f62da2011-11-01 19:45:03 -07003073intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003074{
Lyude9f085eb2016-04-13 10:58:33 -04003075 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
3076 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003077}
3078
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303079static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp)
3080{
3081 uint8_t psr_caps = 0;
3082
3083 drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps);
3084 return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED;
3085}
3086
3087static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp)
3088{
3089 uint8_t dprx = 0;
3090
3091 drm_dp_dpcd_readb(&intel_dp->aux,
3092 DP_DPRX_FEATURE_ENUMERATION_LIST,
3093 &dprx);
3094 return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED;
3095}
3096
Chris Wilsona76f73d2017-01-14 10:51:13 +00003097static bool intel_dp_get_alpm_status(struct intel_dp *intel_dp)
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303098{
3099 uint8_t alpm_caps = 0;
3100
3101 drm_dp_dpcd_readb(&intel_dp->aux, DP_RECEIVER_ALPM_CAP, &alpm_caps);
3102 return alpm_caps & DP_ALPM_CAP;
3103}
3104
Paulo Zanoni11002442014-06-13 18:45:41 -03003105/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003106uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003107intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003108{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003109 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003110 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003111
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003112 if (IS_GEN9_LP(dev_priv))
Vandana Kannan93147262014-11-18 15:45:29 +05303113 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003114 else if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjäläffe51112017-02-23 19:49:01 +02003115 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3116 return intel_ddi_dp_voltage_max(encoder);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003117 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Sonika Jindalbd600182014-08-08 16:23:41 +05303118 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003119 else if (IS_GEN7(dev_priv) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303120 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003121 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303122 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08003123 else
Sonika Jindalbd600182014-08-08 16:23:41 +05303124 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08003125}
3126
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003127uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003128intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3129{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003130 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003131 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003132
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003133 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003134 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3135 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3136 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3137 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3138 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3139 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3140 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303141 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3142 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003143 default:
3144 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3145 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003146 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003147 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303148 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3149 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3150 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3151 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3152 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3153 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3154 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003155 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303156 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003157 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003158 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003159 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303160 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3161 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3162 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3163 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3164 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3165 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3166 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003167 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303168 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003169 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003170 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003171 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303172 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3173 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3174 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3175 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3176 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003177 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303178 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003179 }
3180 } else {
3181 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303182 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3183 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3184 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3185 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3186 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3187 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3188 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003189 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303190 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003191 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003192 }
3193}
3194
Daniel Vetter5829975c2015-04-16 11:36:52 +02003195static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003196{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003197 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003198 unsigned long demph_reg_value, preemph_reg_value,
3199 uniqtranscale_reg_value;
3200 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003201
3202 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303203 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003204 preemph_reg_value = 0x0004000;
3205 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303206 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003207 demph_reg_value = 0x2B405555;
3208 uniqtranscale_reg_value = 0x552AB83A;
3209 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303210 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003211 demph_reg_value = 0x2B404040;
3212 uniqtranscale_reg_value = 0x5548B83A;
3213 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303214 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003215 demph_reg_value = 0x2B245555;
3216 uniqtranscale_reg_value = 0x5560B83A;
3217 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303218 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003219 demph_reg_value = 0x2B405555;
3220 uniqtranscale_reg_value = 0x5598DA3A;
3221 break;
3222 default:
3223 return 0;
3224 }
3225 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303226 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003227 preemph_reg_value = 0x0002000;
3228 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303229 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003230 demph_reg_value = 0x2B404040;
3231 uniqtranscale_reg_value = 0x5552B83A;
3232 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303233 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003234 demph_reg_value = 0x2B404848;
3235 uniqtranscale_reg_value = 0x5580B83A;
3236 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303237 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003238 demph_reg_value = 0x2B404040;
3239 uniqtranscale_reg_value = 0x55ADDA3A;
3240 break;
3241 default:
3242 return 0;
3243 }
3244 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303245 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003246 preemph_reg_value = 0x0000000;
3247 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303248 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003249 demph_reg_value = 0x2B305555;
3250 uniqtranscale_reg_value = 0x5570B83A;
3251 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303252 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003253 demph_reg_value = 0x2B2B4040;
3254 uniqtranscale_reg_value = 0x55ADDA3A;
3255 break;
3256 default:
3257 return 0;
3258 }
3259 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303260 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003261 preemph_reg_value = 0x0006000;
3262 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303263 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003264 demph_reg_value = 0x1B405555;
3265 uniqtranscale_reg_value = 0x55ADDA3A;
3266 break;
3267 default:
3268 return 0;
3269 }
3270 break;
3271 default:
3272 return 0;
3273 }
3274
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003275 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3276 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003277
3278 return 0;
3279}
3280
Daniel Vetter5829975c2015-04-16 11:36:52 +02003281static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003282{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003283 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3284 u32 deemph_reg_value, margin_reg_value;
3285 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003286 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003287
3288 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303289 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003290 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303291 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003292 deemph_reg_value = 128;
3293 margin_reg_value = 52;
3294 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303295 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003296 deemph_reg_value = 128;
3297 margin_reg_value = 77;
3298 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303299 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003300 deemph_reg_value = 128;
3301 margin_reg_value = 102;
3302 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303303 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003304 deemph_reg_value = 128;
3305 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003306 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003307 break;
3308 default:
3309 return 0;
3310 }
3311 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303312 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003313 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303314 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003315 deemph_reg_value = 85;
3316 margin_reg_value = 78;
3317 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303318 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003319 deemph_reg_value = 85;
3320 margin_reg_value = 116;
3321 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303322 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003323 deemph_reg_value = 85;
3324 margin_reg_value = 154;
3325 break;
3326 default:
3327 return 0;
3328 }
3329 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303330 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003331 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303332 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003333 deemph_reg_value = 64;
3334 margin_reg_value = 104;
3335 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303336 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003337 deemph_reg_value = 64;
3338 margin_reg_value = 154;
3339 break;
3340 default:
3341 return 0;
3342 }
3343 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303344 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003345 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303346 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003347 deemph_reg_value = 43;
3348 margin_reg_value = 154;
3349 break;
3350 default:
3351 return 0;
3352 }
3353 break;
3354 default:
3355 return 0;
3356 }
3357
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003358 chv_set_phy_signal_level(encoder, deemph_reg_value,
3359 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003360
3361 return 0;
3362}
3363
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003364static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003365gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003366{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003367 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003368
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003369 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303370 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003371 default:
3372 signal_levels |= DP_VOLTAGE_0_4;
3373 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303374 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003375 signal_levels |= DP_VOLTAGE_0_6;
3376 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303377 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003378 signal_levels |= DP_VOLTAGE_0_8;
3379 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303380 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003381 signal_levels |= DP_VOLTAGE_1_2;
3382 break;
3383 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003384 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303385 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003386 default:
3387 signal_levels |= DP_PRE_EMPHASIS_0;
3388 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303389 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003390 signal_levels |= DP_PRE_EMPHASIS_3_5;
3391 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303392 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003393 signal_levels |= DP_PRE_EMPHASIS_6;
3394 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303395 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003396 signal_levels |= DP_PRE_EMPHASIS_9_5;
3397 break;
3398 }
3399 return signal_levels;
3400}
3401
Zhenyu Wange3421a12010-04-08 09:43:27 +08003402/* Gen6's DP voltage swing and pre-emphasis control */
3403static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003404gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003405{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003406 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3407 DP_TRAIN_PRE_EMPHASIS_MASK);
3408 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303409 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3410 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003411 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303412 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003413 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303414 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3415 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003416 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303417 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3418 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003419 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303420 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3421 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003422 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003423 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003424 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3425 "0x%x\n", signal_levels);
3426 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003427 }
3428}
3429
Keith Packard1a2eb462011-11-16 16:26:07 -08003430/* Gen7's DP voltage swing and pre-emphasis control */
3431static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003432gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003433{
3434 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3435 DP_TRAIN_PRE_EMPHASIS_MASK);
3436 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303437 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003438 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303439 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003440 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303441 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003442 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3443
Sonika Jindalbd600182014-08-08 16:23:41 +05303444 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003445 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303446 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003447 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3448
Sonika Jindalbd600182014-08-08 16:23:41 +05303449 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003450 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303451 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003452 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3453
3454 default:
3455 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3456 "0x%x\n", signal_levels);
3457 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3458 }
3459}
3460
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003461void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003462intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003463{
3464 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003465 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003466 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003467 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003468 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003469 uint8_t train_set = intel_dp->train_set[0];
3470
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003471 if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003472 signal_levels = ddi_signal_levels(intel_dp);
3473
Michel Thierry254e0932017-01-09 16:51:35 +02003474 if (IS_GEN9_LP(dev_priv))
David Weinehallf8896f52015-06-25 11:11:03 +03003475 signal_levels = 0;
3476 else
3477 mask = DDI_BUF_EMP_MASK;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003478 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003479 signal_levels = chv_signal_levels(intel_dp);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003480 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003481 signal_levels = vlv_signal_levels(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003482 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003483 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003484 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003485 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003486 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003487 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3488 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003489 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003490 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3491 }
3492
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303493 if (mask)
3494 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3495
3496 DRM_DEBUG_KMS("Using vswing level %d\n",
3497 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3498 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3499 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3500 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003501
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003502 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003503
3504 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3505 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003506}
3507
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003508void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003509intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3510 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003511{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003512 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003513 struct drm_i915_private *dev_priv =
3514 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003515
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003516 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003517
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003518 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003519 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003520}
3521
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003522void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003523{
3524 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3525 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003526 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak3ab9c632013-05-03 12:57:41 +03003527 enum port port = intel_dig_port->port;
3528 uint32_t val;
3529
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003530 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003531 return;
3532
3533 val = I915_READ(DP_TP_CTL(port));
3534 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3535 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3536 I915_WRITE(DP_TP_CTL(port), val);
3537
3538 /*
3539 * On PORT_A we can have only eDP in SST mode. There the only reason
3540 * we need to set idle transmission mode is to work around a HW issue
3541 * where we enable the pipe while not in idle link-training mode.
3542 * In this case there is requirement to wait for a minimum number of
3543 * idle patterns to be sent.
3544 */
3545 if (port == PORT_A)
3546 return;
3547
Chris Wilsona7670172016-06-30 15:33:10 +01003548 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3549 DP_TP_STATUS_IDLE_DONE,
3550 DP_TP_STATUS_IDLE_DONE,
3551 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003552 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3553}
3554
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003555static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003556intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003557{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003558 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003559 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003560 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003561 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003562 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003563 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003564
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003565 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003566 return;
3567
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003568 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003569 return;
3570
Zhao Yakui28c97732009-10-09 11:39:41 +08003571 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003572
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003573 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003574 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003575 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003576 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003577 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003578 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003579 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3580 else
3581 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003582 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003583 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003584 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003585 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003586
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003587 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3588 I915_WRITE(intel_dp->output_reg, DP);
3589 POSTING_READ(intel_dp->output_reg);
3590
3591 /*
3592 * HW workaround for IBX, we need to move the port
3593 * to transcoder A after disabling it to allow the
3594 * matching HDMI port to be enabled on transcoder A.
3595 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003596 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003597 /*
3598 * We get CPU/PCH FIFO underruns on the other pipe when
3599 * doing the workaround. Sweep them under the rug.
3600 */
3601 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3602 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3603
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003604 /* always enable with pattern 1 (as per spec) */
3605 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3606 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3607 I915_WRITE(intel_dp->output_reg, DP);
3608 POSTING_READ(intel_dp->output_reg);
3609
3610 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003611 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003612 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003613
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003614 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003615 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3616 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003617 }
3618
Keith Packardf01eca22011-09-28 16:48:10 -07003619 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003620
3621 intel_dp->DP = DP;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003622
3623 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3624 pps_lock(intel_dp);
3625 intel_dp->active_pipe = INVALID_PIPE;
3626 pps_unlock(intel_dp);
3627 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003628}
3629
Imre Deak24e807e2016-10-24 19:33:28 +03003630bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003631intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003632{
Lyude9f085eb2016-04-13 10:58:33 -04003633 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3634 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003635 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003636
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003637 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003638
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003639 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3640}
3641
3642static bool
3643intel_edp_init_dpcd(struct intel_dp *intel_dp)
3644{
3645 struct drm_i915_private *dev_priv =
3646 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3647
3648 /* this function is meant to be called only once */
3649 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3650
3651 if (!intel_dp_read_dpcd(intel_dp))
3652 return false;
3653
Imre Deak12a47a422016-10-24 19:33:29 +03003654 intel_dp_read_desc(intel_dp);
3655
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003656 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3657 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3658 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3659
3660 /* Check if the panel supports PSR */
3661 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3662 intel_dp->psr_dpcd,
3663 sizeof(intel_dp->psr_dpcd));
3664 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3665 dev_priv->psr.sink_support = true;
3666 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3667 }
3668
3669 if (INTEL_GEN(dev_priv) >= 9 &&
3670 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3671 uint8_t frame_sync_cap;
3672
3673 dev_priv->psr.sink_support = true;
3674 drm_dp_dpcd_read(&intel_dp->aux,
3675 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3676 &frame_sync_cap, 1);
3677 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3678 /* PSR2 needs frame sync as well */
3679 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3680 DRM_DEBUG_KMS("PSR2 %s on sink",
3681 dev_priv->psr.psr2_support ? "supported" : "not supported");
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303682
3683 if (dev_priv->psr.psr2_support) {
3684 dev_priv->psr.y_cord_support =
3685 intel_dp_get_y_cord_status(intel_dp);
3686 dev_priv->psr.colorimetry_support =
3687 intel_dp_get_colorimetry_status(intel_dp);
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303688 dev_priv->psr.alpm =
3689 intel_dp_get_alpm_status(intel_dp);
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303690 }
3691
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003692 }
3693
3694 /* Read the eDP Display control capabilities registers */
3695 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
3696 drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003697 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3698 sizeof(intel_dp->edp_dpcd))
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003699 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3700 intel_dp->edp_dpcd);
3701
3702 /* Intermediate frequency support */
3703 if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */
3704 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3705 int i;
3706
3707 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3708 sink_rates, sizeof(sink_rates));
3709
3710 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3711 int val = le16_to_cpu(sink_rates[i]);
3712
3713 if (val == 0)
3714 break;
3715
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -08003716 /* Value read multiplied by 200kHz gives the per-lane
3717 * link rate in kHz. The source rates are, however,
3718 * stored in terms of LS_Clk kHz. The full conversion
3719 * back to symbols is
3720 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
3721 */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003722 intel_dp->sink_rates[i] = (val * 200) / 10;
3723 }
3724 intel_dp->num_sink_rates = i;
3725 }
3726
Jani Nikula68f357c2017-03-28 17:59:05 +03003727 if (intel_dp->num_sink_rates)
3728 intel_dp->use_rate_select = true;
3729 else
3730 intel_dp_set_sink_rates(intel_dp);
3731
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003732 return true;
3733}
3734
3735
3736static bool
3737intel_dp_get_dpcd(struct intel_dp *intel_dp)
3738{
3739 if (!intel_dp_read_dpcd(intel_dp))
3740 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003741
Jani Nikula68f357c2017-03-28 17:59:05 +03003742 /* Don't clobber cached eDP rates. */
3743 if (!is_edp(intel_dp))
3744 intel_dp_set_sink_rates(intel_dp);
3745
Lyude9f085eb2016-04-13 10:58:33 -04003746 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT,
3747 &intel_dp->sink_count, 1) < 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303748 return false;
3749
3750 /*
3751 * Sink count can change between short pulse hpd hence
3752 * a member variable in intel_dp will track any changes
3753 * between short pulse interrupts.
3754 */
3755 intel_dp->sink_count = DP_GET_SINK_COUNT(intel_dp->sink_count);
3756
3757 /*
3758 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3759 * a dongle is present but no display. Unless we require to know
3760 * if a dongle is present or not, we don't need to update
3761 * downstream port information. So, an early return here saves
3762 * time from performing other operations which are not required.
3763 */
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05303764 if (!is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303765 return false;
3766
Imre Deakc726ad02016-10-24 19:33:24 +03003767 if (!drm_dp_is_branch(intel_dp->dpcd))
Adam Jacksonedb39242012-09-18 10:58:49 -04003768 return true; /* native DP sink */
3769
3770 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3771 return true; /* no per-port downstream info */
3772
Lyude9f085eb2016-04-13 10:58:33 -04003773 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3774 intel_dp->downstream_ports,
3775 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003776 return false; /* downstream port status fetch failed */
3777
3778 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003779}
3780
Dave Airlie0e32b392014-05-02 14:02:48 +10003781static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003782intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003783{
3784 u8 buf[1];
3785
Nathan Schulte7cc96132016-03-15 10:14:05 -05003786 if (!i915.enable_dp_mst)
3787 return false;
3788
Dave Airlie0e32b392014-05-02 14:02:48 +10003789 if (!intel_dp->can_mst)
3790 return false;
3791
3792 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3793 return false;
3794
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003795 if (drm_dp_dpcd_read(&intel_dp->aux, DP_MSTM_CAP, buf, 1) != 1)
3796 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003797
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003798 return buf[0] & DP_MST_CAP;
3799}
3800
3801static void
3802intel_dp_configure_mst(struct intel_dp *intel_dp)
3803{
3804 if (!i915.enable_dp_mst)
3805 return;
3806
3807 if (!intel_dp->can_mst)
3808 return;
3809
3810 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3811
3812 if (intel_dp->is_mst)
3813 DRM_DEBUG_KMS("Sink is MST capable\n");
3814 else
3815 DRM_DEBUG_KMS("Sink is not MST capable\n");
3816
3817 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3818 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003819}
3820
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003821static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003822{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003823 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003824 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003825 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003826 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003827 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003828 int count = 0;
3829 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003830
3831 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003832 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003833 ret = -EIO;
3834 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003835 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003836
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003837 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003838 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003839 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003840 ret = -EIO;
3841 goto out;
3842 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003843
Rodrigo Vivic6297842015-11-05 10:50:20 -08003844 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003845 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivic6297842015-11-05 10:50:20 -08003846
3847 if (drm_dp_dpcd_readb(&intel_dp->aux,
3848 DP_TEST_SINK_MISC, &buf) < 0) {
3849 ret = -EIO;
3850 goto out;
3851 }
3852 count = buf & DP_TEST_COUNT_MASK;
3853 } while (--attempts && count);
3854
3855 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003856 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003857 ret = -ETIMEDOUT;
3858 }
3859
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003860 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003861 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003862 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003863}
3864
3865static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3866{
3867 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003868 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003869 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3870 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003871 int ret;
3872
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003873 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3874 return -EIO;
3875
3876 if (!(buf & DP_TEST_CRC_SUPPORTED))
3877 return -ENOTTY;
3878
3879 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3880 return -EIO;
3881
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003882 if (buf & DP_TEST_SINK_START) {
3883 ret = intel_dp_sink_crc_stop(intel_dp);
3884 if (ret)
3885 return ret;
3886 }
3887
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003888 hsw_disable_ips(intel_crtc);
3889
3890 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3891 buf | DP_TEST_SINK_START) < 0) {
3892 hsw_enable_ips(intel_crtc);
3893 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003894 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003895
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003896 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003897 return 0;
3898}
3899
3900int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3901{
3902 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003903 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003904 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3905 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003906 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003907 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003908
3909 ret = intel_dp_sink_crc_start(intel_dp);
3910 if (ret)
3911 return ret;
3912
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003913 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003914 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003915
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003916 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003917 DP_TEST_SINK_MISC, &buf) < 0) {
3918 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003919 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003920 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003921 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07003922
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003923 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003924
3925 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003926 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
3927 ret = -ETIMEDOUT;
3928 goto stop;
3929 }
3930
3931 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
3932 ret = -EIO;
3933 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003934 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003935
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003936stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003937 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003938 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003939}
3940
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003941static bool
3942intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3943{
Lyude9f085eb2016-04-13 10:58:33 -04003944 return drm_dp_dpcd_read(&intel_dp->aux,
Jani Nikula9d1a1032014-03-14 16:51:15 +02003945 DP_DEVICE_SERVICE_IRQ_VECTOR,
3946 sink_irq_vector, 1) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003947}
3948
Dave Airlie0e32b392014-05-02 14:02:48 +10003949static bool
3950intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3951{
3952 int ret;
3953
Lyude9f085eb2016-04-13 10:58:33 -04003954 ret = drm_dp_dpcd_read(&intel_dp->aux,
Dave Airlie0e32b392014-05-02 14:02:48 +10003955 DP_SINK_COUNT_ESI,
3956 sink_irq_vector, 14);
3957 if (ret != 14)
3958 return false;
3959
3960 return true;
3961}
3962
Todd Previtec5d5ab72015-04-15 08:38:38 -07003963static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003964{
Manasi Navareda15f7c2017-01-24 08:16:34 -08003965 int status = 0;
3966 int min_lane_count = 1;
3967 int common_rates[DP_MAX_SUPPORTED_RATES] = {};
3968 int link_rate_index, test_link_rate;
3969 uint8_t test_lane_count, test_link_bw;
3970 /* (DP CTS 1.2)
3971 * 4.3.1.11
3972 */
3973 /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */
3974 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT,
3975 &test_lane_count);
3976
3977 if (status <= 0) {
3978 DRM_DEBUG_KMS("Lane count read failed\n");
3979 return DP_TEST_NAK;
3980 }
3981 test_lane_count &= DP_MAX_LANE_COUNT_MASK;
3982 /* Validate the requested lane count */
3983 if (test_lane_count < min_lane_count ||
3984 test_lane_count > intel_dp->max_sink_lane_count)
3985 return DP_TEST_NAK;
3986
3987 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE,
3988 &test_link_bw);
3989 if (status <= 0) {
3990 DRM_DEBUG_KMS("Link Rate read failed\n");
3991 return DP_TEST_NAK;
3992 }
3993 /* Validate the requested link rate */
3994 test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw);
3995 link_rate_index = intel_dp_link_rate_index(intel_dp,
3996 common_rates,
3997 test_link_rate);
3998 if (link_rate_index < 0)
3999 return DP_TEST_NAK;
4000
4001 intel_dp->compliance.test_lane_count = test_lane_count;
4002 intel_dp->compliance.test_link_rate = test_link_rate;
4003
4004 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004005}
4006
4007static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
4008{
Manasi Navare611032b2017-01-24 08:21:49 -08004009 uint8_t test_pattern;
4010 uint16_t test_misc;
4011 __be16 h_width, v_height;
4012 int status = 0;
4013
4014 /* Read the TEST_PATTERN (DP CTS 3.1.5) */
4015 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_PATTERN,
4016 &test_pattern, 1);
4017 if (status <= 0) {
4018 DRM_DEBUG_KMS("Test pattern read failed\n");
4019 return DP_TEST_NAK;
4020 }
4021 if (test_pattern != DP_COLOR_RAMP)
4022 return DP_TEST_NAK;
4023
4024 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI,
4025 &h_width, 2);
4026 if (status <= 0) {
4027 DRM_DEBUG_KMS("H Width read failed\n");
4028 return DP_TEST_NAK;
4029 }
4030
4031 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI,
4032 &v_height, 2);
4033 if (status <= 0) {
4034 DRM_DEBUG_KMS("V Height read failed\n");
4035 return DP_TEST_NAK;
4036 }
4037
4038 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_MISC0,
4039 &test_misc, 1);
4040 if (status <= 0) {
4041 DRM_DEBUG_KMS("TEST MISC read failed\n");
4042 return DP_TEST_NAK;
4043 }
4044 if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB)
4045 return DP_TEST_NAK;
4046 if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA)
4047 return DP_TEST_NAK;
4048 switch (test_misc & DP_TEST_BIT_DEPTH_MASK) {
4049 case DP_TEST_BIT_DEPTH_6:
4050 intel_dp->compliance.test_data.bpc = 6;
4051 break;
4052 case DP_TEST_BIT_DEPTH_8:
4053 intel_dp->compliance.test_data.bpc = 8;
4054 break;
4055 default:
4056 return DP_TEST_NAK;
4057 }
4058
4059 intel_dp->compliance.test_data.video_pattern = test_pattern;
4060 intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width);
4061 intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height);
4062 /* Set test active flag here so userspace doesn't interrupt things */
4063 intel_dp->compliance.test_active = 1;
4064
4065 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004066}
4067
4068static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
4069{
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004070 uint8_t test_result = DP_TEST_ACK;
Todd Previte559be302015-05-04 07:48:20 -07004071 struct intel_connector *intel_connector = intel_dp->attached_connector;
4072 struct drm_connector *connector = &intel_connector->base;
4073
4074 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02004075 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07004076 intel_dp->aux.i2c_defer_count > 6) {
4077 /* Check EDID read for NACKs, DEFERs and corruption
4078 * (DP CTS 1.2 Core r1.1)
4079 * 4.2.2.4 : Failed EDID read, I2C_NAK
4080 * 4.2.2.5 : Failed EDID read, I2C_DEFER
4081 * 4.2.2.6 : EDID corruption detected
4082 * Use failsafe mode for all cases
4083 */
4084 if (intel_dp->aux.i2c_nack_count > 0 ||
4085 intel_dp->aux.i2c_defer_count > 0)
4086 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
4087 intel_dp->aux.i2c_nack_count,
4088 intel_dp->aux.i2c_defer_count);
Manasi Navarec1617ab2016-12-09 16:22:50 -08004089 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
Todd Previte559be302015-05-04 07:48:20 -07004090 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05304091 struct edid *block = intel_connector->detect_edid;
4092
4093 /* We have to write the checksum
4094 * of the last block read
4095 */
4096 block += intel_connector->detect_edid->extensions;
4097
Todd Previte559be302015-05-04 07:48:20 -07004098 if (!drm_dp_dpcd_write(&intel_dp->aux,
4099 DP_TEST_EDID_CHECKSUM,
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05304100 &block->checksum,
Dan Carpenter5a1cc652015-05-12 21:07:37 +03004101 1))
Todd Previte559be302015-05-04 07:48:20 -07004102 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
4103
4104 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004105 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED;
Todd Previte559be302015-05-04 07:48:20 -07004106 }
4107
4108 /* Set test active flag here so userspace doesn't interrupt things */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004109 intel_dp->compliance.test_active = 1;
Todd Previte559be302015-05-04 07:48:20 -07004110
Todd Previtec5d5ab72015-04-15 08:38:38 -07004111 return test_result;
4112}
4113
4114static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
4115{
4116 uint8_t test_result = DP_TEST_NAK;
4117 return test_result;
4118}
4119
4120static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
4121{
4122 uint8_t response = DP_TEST_NAK;
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004123 uint8_t request = 0;
4124 int status;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004125
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004126 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004127 if (status <= 0) {
4128 DRM_DEBUG_KMS("Could not read test request from sink\n");
4129 goto update_status;
4130 }
4131
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004132 switch (request) {
Todd Previtec5d5ab72015-04-15 08:38:38 -07004133 case DP_TEST_LINK_TRAINING:
4134 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004135 response = intel_dp_autotest_link_training(intel_dp);
4136 break;
4137 case DP_TEST_LINK_VIDEO_PATTERN:
4138 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004139 response = intel_dp_autotest_video_pattern(intel_dp);
4140 break;
4141 case DP_TEST_LINK_EDID_READ:
4142 DRM_DEBUG_KMS("EDID test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004143 response = intel_dp_autotest_edid(intel_dp);
4144 break;
4145 case DP_TEST_LINK_PHY_TEST_PATTERN:
4146 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004147 response = intel_dp_autotest_phy_pattern(intel_dp);
4148 break;
4149 default:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004150 DRM_DEBUG_KMS("Invalid test request '%02x'\n", request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004151 break;
4152 }
4153
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004154 if (response & DP_TEST_ACK)
4155 intel_dp->compliance.test_type = request;
4156
Todd Previtec5d5ab72015-04-15 08:38:38 -07004157update_status:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004158 status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004159 if (status <= 0)
4160 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004161}
4162
Dave Airlie0e32b392014-05-02 14:02:48 +10004163static int
4164intel_dp_check_mst_status(struct intel_dp *intel_dp)
4165{
4166 bool bret;
4167
4168 if (intel_dp->is_mst) {
4169 u8 esi[16] = { 0 };
4170 int ret = 0;
4171 int retry;
4172 bool handled;
4173 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4174go_again:
4175 if (bret == true) {
4176
4177 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03004178 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03004179 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10004180 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4181 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004182 intel_dp_stop_link_train(intel_dp);
4183 }
4184
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004185 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004186 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4187
4188 if (handled) {
4189 for (retry = 0; retry < 3; retry++) {
4190 int wret;
4191 wret = drm_dp_dpcd_write(&intel_dp->aux,
4192 DP_SINK_COUNT_ESI+1,
4193 &esi[1], 3);
4194 if (wret == 3) {
4195 break;
4196 }
4197 }
4198
4199 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4200 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004201 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004202 goto go_again;
4203 }
4204 } else
4205 ret = 0;
4206
4207 return ret;
4208 } else {
4209 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4210 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4211 intel_dp->is_mst = false;
4212 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4213 /* send a hotplug event */
4214 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4215 }
4216 }
4217 return -EINVAL;
4218}
4219
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304220static void
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004221intel_dp_retrain_link(struct intel_dp *intel_dp)
4222{
4223 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4224 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4225 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
4226
4227 /* Suppress underruns caused by re-training */
4228 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4229 if (crtc->config->has_pch_encoder)
4230 intel_set_pch_fifo_underrun_reporting(dev_priv,
4231 intel_crtc_pch_transcoder(crtc), false);
4232
4233 intel_dp_start_link_train(intel_dp);
4234 intel_dp_stop_link_train(intel_dp);
4235
4236 /* Keep underrun reporting disabled until things are stable */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02004237 intel_wait_for_vblank(dev_priv, crtc->pipe);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004238
4239 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4240 if (crtc->config->has_pch_encoder)
4241 intel_set_pch_fifo_underrun_reporting(dev_priv,
4242 intel_crtc_pch_transcoder(crtc), true);
4243}
4244
4245static void
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304246intel_dp_check_link_status(struct intel_dp *intel_dp)
4247{
4248 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4249 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4250 u8 link_status[DP_LINK_STATUS_SIZE];
4251
4252 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
4253
4254 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4255 DRM_ERROR("Failed to get link status\n");
4256 return;
4257 }
4258
4259 if (!intel_encoder->base.crtc)
4260 return;
4261
4262 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4263 return;
4264
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004265 /* FIXME: we need to synchronize this sort of stuff with hardware
Daniel Vetter2dd85ae2016-12-13 20:54:14 +01004266 * readout. Currently fast link training doesn't work on boot-up. */
4267 if (!intel_dp->lane_count)
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004268 return;
4269
Manasi Navareda15f7c2017-01-24 08:16:34 -08004270 /* Retrain if Channel EQ or CR not ok */
4271 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304272 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4273 intel_encoder->base.name);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004274
4275 intel_dp_retrain_link(intel_dp);
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304276 }
4277}
4278
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004279/*
4280 * According to DP spec
4281 * 5.1.2:
4282 * 1. Read DPCD
4283 * 2. Configure link according to Receiver Capabilities
4284 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4285 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304286 *
4287 * intel_dp_short_pulse - handles short pulse interrupts
4288 * when full detection is not required.
4289 * Returns %true if short pulse is handled and full detection
4290 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004291 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304292static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304293intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004294{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004295 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004296 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004297 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304298 u8 old_sink_count = intel_dp->sink_count;
4299 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004300
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304301 /*
4302 * Clearing compliance test variables to allow capturing
4303 * of values for next automated test request.
4304 */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004305 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304306
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304307 /*
4308 * Now read the DPCD to see if it's actually running
4309 * If the current value of sink count doesn't match with
4310 * the value that was stored earlier or dpcd read failed
4311 * we need to do full detection
4312 */
4313 ret = intel_dp_get_dpcd(intel_dp);
4314
4315 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4316 /* No need to proceed if we are going to do full detect */
4317 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004318 }
4319
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004320 /* Try to read the source of the interrupt */
4321 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004322 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4323 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004324 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004325 drm_dp_dpcd_writeb(&intel_dp->aux,
4326 DP_DEVICE_SERVICE_IRQ_VECTOR,
4327 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004328
4329 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Manasi Navareda15f7c2017-01-24 08:16:34 -08004330 intel_dp_handle_test_request(intel_dp);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004331 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4332 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4333 }
4334
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304335 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4336 intel_dp_check_link_status(intel_dp);
4337 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004338 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
4339 DRM_DEBUG_KMS("Link Training Compliance Test requested\n");
4340 /* Send a Hotplug Uevent to userspace to start modeset */
4341 drm_kms_helper_hotplug_event(intel_encoder->base.dev);
4342 }
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304343
4344 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004345}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004346
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004347/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004348static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004349intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004350{
Imre Deake393d0d2017-02-22 17:10:52 +02004351 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004352 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004353 uint8_t type;
4354
Imre Deake393d0d2017-02-22 17:10:52 +02004355 if (lspcon->active)
4356 lspcon_resume(lspcon);
4357
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004358 if (!intel_dp_get_dpcd(intel_dp))
4359 return connector_status_disconnected;
4360
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304361 if (is_edp(intel_dp))
4362 return connector_status_connected;
4363
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004364 /* if there's no downstream port, we're done */
Imre Deakc726ad02016-10-24 19:33:24 +03004365 if (!drm_dp_is_branch(dpcd))
Keith Packard26d61aa2011-07-25 20:01:09 -07004366 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004367
4368 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004369 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4370 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004371
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304372 return intel_dp->sink_count ?
4373 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004374 }
4375
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004376 if (intel_dp_can_mst(intel_dp))
4377 return connector_status_connected;
4378
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004379 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004380 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004381 return connector_status_connected;
4382
4383 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004384 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4385 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4386 if (type == DP_DS_PORT_TYPE_VGA ||
4387 type == DP_DS_PORT_TYPE_NON_EDID)
4388 return connector_status_unknown;
4389 } else {
4390 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4391 DP_DWN_STRM_PORT_TYPE_MASK;
4392 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4393 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4394 return connector_status_unknown;
4395 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004396
4397 /* Anything else is out of spec, warn and ignore */
4398 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004399 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004400}
4401
4402static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004403edp_detect(struct intel_dp *intel_dp)
4404{
4405 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Mika Kahola1650be72016-12-13 10:02:47 +02004406 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsond410b562014-09-02 20:03:59 +01004407 enum drm_connector_status status;
4408
Mika Kahola1650be72016-12-13 10:02:47 +02004409 status = intel_panel_detect(dev_priv);
Chris Wilsond410b562014-09-02 20:03:59 +01004410 if (status == connector_status_unknown)
4411 status = connector_status_connected;
4412
4413 return status;
4414}
4415
Jani Nikulab93433c2015-08-20 10:47:36 +03004416static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4417 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004418{
Jani Nikulab93433c2015-08-20 10:47:36 +03004419 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004420
Jani Nikula0df53b72015-08-20 10:47:40 +03004421 switch (port->port) {
4422 case PORT_A:
4423 return true;
4424 case PORT_B:
4425 bit = SDE_PORTB_HOTPLUG;
4426 break;
4427 case PORT_C:
4428 bit = SDE_PORTC_HOTPLUG;
4429 break;
4430 case PORT_D:
4431 bit = SDE_PORTD_HOTPLUG;
4432 break;
4433 default:
4434 MISSING_CASE(port->port);
4435 return false;
4436 }
4437
4438 return I915_READ(SDEISR) & bit;
4439}
4440
4441static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4442 struct intel_digital_port *port)
4443{
4444 u32 bit;
4445
4446 switch (port->port) {
4447 case PORT_A:
4448 return true;
4449 case PORT_B:
4450 bit = SDE_PORTB_HOTPLUG_CPT;
4451 break;
4452 case PORT_C:
4453 bit = SDE_PORTC_HOTPLUG_CPT;
4454 break;
4455 case PORT_D:
4456 bit = SDE_PORTD_HOTPLUG_CPT;
4457 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004458 case PORT_E:
4459 bit = SDE_PORTE_HOTPLUG_SPT;
4460 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004461 default:
4462 MISSING_CASE(port->port);
4463 return false;
Jani Nikulab93433c2015-08-20 10:47:36 +03004464 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004465
Jani Nikulab93433c2015-08-20 10:47:36 +03004466 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004467}
4468
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004469static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004470 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004471{
Jani Nikula9642c812015-08-20 10:47:41 +03004472 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004473
Jani Nikula9642c812015-08-20 10:47:41 +03004474 switch (port->port) {
4475 case PORT_B:
4476 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4477 break;
4478 case PORT_C:
4479 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4480 break;
4481 case PORT_D:
4482 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4483 break;
4484 default:
4485 MISSING_CASE(port->port);
4486 return false;
4487 }
4488
4489 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4490}
4491
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004492static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4493 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004494{
4495 u32 bit;
4496
4497 switch (port->port) {
4498 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004499 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004500 break;
4501 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004502 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004503 break;
4504 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004505 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004506 break;
4507 default:
4508 MISSING_CASE(port->port);
4509 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004510 }
4511
Jani Nikula1d245982015-08-20 10:47:37 +03004512 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004513}
4514
Jani Nikulae464bfd2015-08-20 10:47:42 +03004515static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304516 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004517{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304518 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4519 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004520 u32 bit;
4521
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304522 intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port);
4523 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004524 case PORT_A:
4525 bit = BXT_DE_PORT_HP_DDIA;
4526 break;
4527 case PORT_B:
4528 bit = BXT_DE_PORT_HP_DDIB;
4529 break;
4530 case PORT_C:
4531 bit = BXT_DE_PORT_HP_DDIC;
4532 break;
4533 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304534 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004535 return false;
4536 }
4537
4538 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4539}
4540
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004541/*
4542 * intel_digital_port_connected - is the specified port connected?
4543 * @dev_priv: i915 private structure
4544 * @port: the port to test
4545 *
4546 * Return %true if @port is connected, %false otherwise.
4547 */
Imre Deak390b4e02017-01-27 11:39:19 +02004548bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
4549 struct intel_digital_port *port)
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004550{
Jani Nikula0df53b72015-08-20 10:47:40 +03004551 if (HAS_PCH_IBX(dev_priv))
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004552 return ibx_digital_port_connected(dev_priv, port);
Ville Syrjälä22824fa2016-02-11 16:44:28 +02004553 else if (HAS_PCH_SPLIT(dev_priv))
Jani Nikula0df53b72015-08-20 10:47:40 +03004554 return cpt_digital_port_connected(dev_priv, port);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004555 else if (IS_GEN9_LP(dev_priv))
Jani Nikulae464bfd2015-08-20 10:47:42 +03004556 return bxt_digital_port_connected(dev_priv, port);
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004557 else if (IS_GM45(dev_priv))
4558 return gm45_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004559 else
4560 return g4x_digital_port_connected(dev_priv, port);
4561}
4562
Keith Packard8c241fe2011-09-28 16:38:44 -07004563static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004564intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004565{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004566 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004567
Jani Nikula9cd300e2012-10-19 14:51:52 +03004568 /* use cached edid if we have one */
4569 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004570 /* invalid edid */
4571 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004572 return NULL;
4573
Jani Nikula55e9ede2013-10-01 10:38:54 +03004574 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004575 } else
4576 return drm_get_edid(&intel_connector->base,
4577 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004578}
4579
Chris Wilsonbeb60602014-09-02 20:04:00 +01004580static void
4581intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004582{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004583 struct intel_connector *intel_connector = intel_dp->attached_connector;
4584 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004585
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304586 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004587 edid = intel_dp_get_edid(intel_dp);
4588 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004589
Chris Wilsonbeb60602014-09-02 20:04:00 +01004590 if (intel_dp->force_audio != HDMI_AUDIO_AUTO)
4591 intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON;
4592 else
4593 intel_dp->has_audio = drm_detect_monitor_audio(edid);
4594}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004595
Chris Wilsonbeb60602014-09-02 20:04:00 +01004596static void
4597intel_dp_unset_edid(struct intel_dp *intel_dp)
4598{
4599 struct intel_connector *intel_connector = intel_dp->attached_connector;
4600
4601 kfree(intel_connector->detect_edid);
4602 intel_connector->detect_edid = NULL;
4603
4604 intel_dp->has_audio = false;
4605}
4606
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004607static enum drm_connector_status
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304608intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004609{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304610 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004611 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004612 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4613 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004614 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004615 enum drm_connector_status status;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004616 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004617
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004618 intel_display_power_get(to_i915(dev), intel_dp->aux_power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004619
Chris Wilsond410b562014-09-02 20:03:59 +01004620 /* Can't disconnect eDP, but you can close the lid... */
4621 if (is_edp(intel_dp))
4622 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004623 else if (intel_digital_port_connected(to_i915(dev),
4624 dp_to_dig_port(intel_dp)))
4625 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004626 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004627 status = connector_status_disconnected;
4628
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004629 if (status == connector_status_disconnected) {
Manasi Navarec1617ab2016-12-09 16:22:50 -08004630 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304631
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004632 if (intel_dp->is_mst) {
4633 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4634 intel_dp->is_mst,
4635 intel_dp->mst_mgr.mst_state);
4636 intel_dp->is_mst = false;
4637 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4638 intel_dp->is_mst);
4639 }
4640
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004641 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304642 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004643
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304644 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004645 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304646
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004647 DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
4648 yesno(intel_dp_source_supports_hbr2(intel_dp)),
4649 yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
4650
Manasi Navared7e8ef02017-02-07 16:54:11 -08004651 if (intel_dp->reset_link_params) {
4652 /* Set the max lane count for sink */
4653 intel_dp->max_sink_lane_count = drm_dp_max_lane_count(intel_dp->dpcd);
Manasi Navaref4829842016-12-05 16:27:36 -08004654
Manasi Navared7e8ef02017-02-07 16:54:11 -08004655 /* Set the max link BW for sink */
4656 intel_dp->max_sink_link_bw = intel_dp_max_link_bw(intel_dp);
4657
4658 intel_dp->reset_link_params = false;
4659 }
Manasi Navaref4829842016-12-05 16:27:36 -08004660
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004661 intel_dp_print_rates(intel_dp);
4662
Imre Deak7b3fc172016-10-25 16:12:39 +03004663 intel_dp_read_desc(intel_dp);
Mika Kahola0e390a32016-09-09 14:10:53 +03004664
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004665 intel_dp_configure_mst(intel_dp);
4666
4667 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304668 /*
4669 * If we are in MST mode then this connector
4670 * won't appear connected or have anything
4671 * with EDID on it
4672 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004673 status = connector_status_disconnected;
4674 goto out;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304675 } else if (connector->status == connector_status_connected) {
4676 /*
4677 * If display was connected already and is still connected
4678 * check links status, there has been known issues of
4679 * link loss triggerring long pulse!!!!
4680 */
4681 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4682 intel_dp_check_link_status(intel_dp);
4683 drm_modeset_unlock(&dev->mode_config.connection_mutex);
4684 goto out;
Dave Airlie0e32b392014-05-02 14:02:48 +10004685 }
4686
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304687 /*
4688 * Clearing NACK and defer counts to get their exact values
4689 * while reading EDID which are required by Compliance tests
4690 * 4.2.2.4 and 4.2.2.5
4691 */
4692 intel_dp->aux.i2c_nack_count = 0;
4693 intel_dp->aux.i2c_defer_count = 0;
4694
Chris Wilsonbeb60602014-09-02 20:04:00 +01004695 intel_dp_set_edid(intel_dp);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004696 if (is_edp(intel_dp) || intel_connector->detect_edid)
4697 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304698 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004699
Todd Previte09b1eb12015-04-20 15:27:34 -07004700 /* Try to read the source of the interrupt */
4701 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004702 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4703 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004704 /* Clear interrupt source */
4705 drm_dp_dpcd_writeb(&intel_dp->aux,
4706 DP_DEVICE_SERVICE_IRQ_VECTOR,
4707 sink_irq_vector);
4708
4709 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4710 intel_dp_handle_test_request(intel_dp);
4711 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4712 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4713 }
4714
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004715out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004716 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304717 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304718
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004719 intel_display_power_put(to_i915(dev), intel_dp->aux_power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004720 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304721}
4722
4723static enum drm_connector_status
4724intel_dp_detect(struct drm_connector *connector, bool force)
4725{
4726 struct intel_dp *intel_dp = intel_attached_dp(connector);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004727 enum drm_connector_status status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304728
4729 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4730 connector->base.id, connector->name);
4731
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304732 /* If full detect is not performed yet, do a full detect */
4733 if (!intel_dp->detect_done)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004734 status = intel_dp_long_pulse(intel_dp->attached_connector);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304735
4736 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304737
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004738 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004739}
4740
Chris Wilsonbeb60602014-09-02 20:04:00 +01004741static void
4742intel_dp_force(struct drm_connector *connector)
4743{
4744 struct intel_dp *intel_dp = intel_attached_dp(connector);
4745 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004746 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004747
4748 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4749 connector->base.id, connector->name);
4750 intel_dp_unset_edid(intel_dp);
4751
4752 if (connector->status != connector_status_connected)
4753 return;
4754
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004755 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004756
4757 intel_dp_set_edid(intel_dp);
4758
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004759 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004760
4761 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004762 intel_encoder->type = INTEL_OUTPUT_DP;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004763}
4764
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004765static int intel_dp_get_modes(struct drm_connector *connector)
4766{
Jani Nikuladd06f902012-10-19 14:51:50 +03004767 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004768 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004769
Chris Wilsonbeb60602014-09-02 20:04:00 +01004770 edid = intel_connector->detect_edid;
4771 if (edid) {
4772 int ret = intel_connector_update_modes(connector, edid);
4773 if (ret)
4774 return ret;
4775 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004776
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004777 /* if eDP has no EDID, fall back to fixed mode */
Chris Wilsonbeb60602014-09-02 20:04:00 +01004778 if (is_edp(intel_attached_dp(connector)) &&
4779 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004780 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004781
4782 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004783 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004784 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004785 drm_mode_probed_add(connector, mode);
4786 return 1;
4787 }
4788 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004789
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004790 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004791}
4792
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004793static bool
4794intel_dp_detect_audio(struct drm_connector *connector)
4795{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004796 bool has_audio = false;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004797 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004798
Chris Wilsonbeb60602014-09-02 20:04:00 +01004799 edid = to_intel_connector(connector)->detect_edid;
4800 if (edid)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004801 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02004802
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004803 return has_audio;
4804}
4805
Chris Wilsonf6849602010-09-19 09:29:33 +01004806static int
4807intel_dp_set_property(struct drm_connector *connector,
4808 struct drm_property *property,
4809 uint64_t val)
4810{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004811 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Yuly Novikov53b41832012-10-26 12:04:00 +03004812 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004813 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
4814 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01004815 int ret;
4816
Rob Clark662595d2012-10-11 20:36:04 -05004817 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01004818 if (ret)
4819 return ret;
4820
Chris Wilson3f43c482011-05-12 22:17:24 +01004821 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004822 int i = val;
4823 bool has_audio;
4824
4825 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004826 return 0;
4827
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004828 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01004829
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004830 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004831 has_audio = intel_dp_detect_audio(connector);
4832 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004833 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004834
4835 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004836 return 0;
4837
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004838 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01004839 goto done;
4840 }
4841
Chris Wilsone953fd72011-02-21 22:23:52 +00004842 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02004843 bool old_auto = intel_dp->color_range_auto;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004844 bool old_range = intel_dp->limited_color_range;
Daniel Vetterae4edb82013-04-22 17:07:23 +02004845
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004846 switch (val) {
4847 case INTEL_BROADCAST_RGB_AUTO:
4848 intel_dp->color_range_auto = true;
4849 break;
4850 case INTEL_BROADCAST_RGB_FULL:
4851 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004852 intel_dp->limited_color_range = false;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004853 break;
4854 case INTEL_BROADCAST_RGB_LIMITED:
4855 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004856 intel_dp->limited_color_range = true;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004857 break;
4858 default:
4859 return -EINVAL;
4860 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02004861
4862 if (old_auto == intel_dp->color_range_auto &&
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004863 old_range == intel_dp->limited_color_range)
Daniel Vetterae4edb82013-04-22 17:07:23 +02004864 return 0;
4865
Chris Wilsone953fd72011-02-21 22:23:52 +00004866 goto done;
4867 }
4868
Yuly Novikov53b41832012-10-26 12:04:00 +03004869 if (is_edp(intel_dp) &&
4870 property == connector->dev->mode_config.scaling_mode_property) {
4871 if (val == DRM_MODE_SCALE_NONE) {
4872 DRM_DEBUG_KMS("no scaling not supported\n");
4873 return -EINVAL;
4874 }
Ville Syrjälä234126c2016-04-12 22:14:38 +03004875 if (HAS_GMCH_DISPLAY(dev_priv) &&
4876 val == DRM_MODE_SCALE_CENTER) {
4877 DRM_DEBUG_KMS("centering not supported\n");
4878 return -EINVAL;
4879 }
Yuly Novikov53b41832012-10-26 12:04:00 +03004880
4881 if (intel_connector->panel.fitting_mode == val) {
4882 /* the eDP scaling property is not changed */
4883 return 0;
4884 }
4885 intel_connector->panel.fitting_mode = val;
4886
4887 goto done;
4888 }
4889
Chris Wilsonf6849602010-09-19 09:29:33 +01004890 return -EINVAL;
4891
4892done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00004893 if (intel_encoder->base.crtc)
4894 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01004895
4896 return 0;
4897}
4898
Chris Wilson7a418e32016-06-24 14:00:14 +01004899static int
4900intel_dp_connector_register(struct drm_connector *connector)
4901{
4902 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004903 int ret;
4904
4905 ret = intel_connector_register(connector);
4906 if (ret)
4907 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004908
4909 i915_debugfs_connector_add(connector);
4910
4911 DRM_DEBUG_KMS("registering %s bus for %s\n",
4912 intel_dp->aux.name, connector->kdev->kobj.name);
4913
4914 intel_dp->aux.dev = connector->kdev;
4915 return drm_dp_aux_register(&intel_dp->aux);
4916}
4917
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004918static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004919intel_dp_connector_unregister(struct drm_connector *connector)
4920{
4921 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4922 intel_connector_unregister(connector);
4923}
4924
4925static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004926intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004927{
Jani Nikula1d508702012-10-19 14:51:49 +03004928 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004929
Chris Wilson10e972d2014-09-04 21:43:45 +01004930 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004931
Jani Nikula9cd300e2012-10-19 14:51:52 +03004932 if (!IS_ERR_OR_NULL(intel_connector->edid))
4933 kfree(intel_connector->edid);
4934
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004935 /* Can't call is_edp() since the encoder may have been destroyed
4936 * already. */
4937 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004938 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004939
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004940 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004941 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004942}
4943
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004944void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004945{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004946 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4947 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004948
Dave Airlie0e32b392014-05-02 14:02:48 +10004949 intel_dp_mst_encoder_cleanup(intel_dig_port);
Keith Packardbd943152011-09-18 23:09:52 -07004950 if (is_edp(intel_dp)) {
4951 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004952 /*
4953 * vdd might still be enabled do to the delayed vdd off.
4954 * Make sure vdd is actually turned off here.
4955 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004956 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004957 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004958 pps_unlock(intel_dp);
4959
Clint Taylor01527b32014-07-07 13:01:46 -07004960 if (intel_dp->edp_notifier.notifier_call) {
4961 unregister_reboot_notifier(&intel_dp->edp_notifier);
4962 intel_dp->edp_notifier.notifier_call = NULL;
4963 }
Keith Packardbd943152011-09-18 23:09:52 -07004964 }
Chris Wilson99681882016-06-20 09:29:17 +01004965
4966 intel_dp_aux_fini(intel_dp);
4967
Imre Deakc8bd0e42014-12-12 17:57:38 +02004968 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004969 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004970}
4971
Imre Deakbf93ba62016-04-18 10:04:21 +03004972void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004973{
4974 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4975
4976 if (!is_edp(intel_dp))
4977 return;
4978
Ville Syrjälä951468f2014-09-04 14:55:31 +03004979 /*
4980 * vdd might still be enabled do to the delayed vdd off.
4981 * Make sure vdd is actually turned off here.
4982 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004983 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004984 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004985 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004986 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004987}
4988
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004989static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4990{
4991 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4992 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004993 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004994
4995 lockdep_assert_held(&dev_priv->pps_mutex);
4996
4997 if (!edp_have_panel_vdd(intel_dp))
4998 return;
4999
5000 /*
5001 * The VDD bit needs a power domain reference, so if the bit is
5002 * already enabled when we boot or resume, grab this reference and
5003 * schedule a vdd off, so we don't hold on to the reference
5004 * indefinitely.
5005 */
5006 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005007 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005008
5009 edp_panel_vdd_schedule_off(intel_dp);
5010}
5011
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005012static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
5013{
5014 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5015
5016 if ((intel_dp->DP & DP_PORT_EN) == 0)
5017 return INVALID_PIPE;
5018
5019 if (IS_CHERRYVIEW(dev_priv))
5020 return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
5021 else
5022 return PORT_TO_PIPE(intel_dp->DP);
5023}
5024
Imre Deakbf93ba62016-04-18 10:04:21 +03005025void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03005026{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005027 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Imre Deakdd75f6d2016-11-21 21:15:05 +02005028 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
5029 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005030
5031 if (!HAS_DDI(dev_priv))
5032 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005033
Imre Deakdd75f6d2016-11-21 21:15:05 +02005034 if (lspcon->active)
Shashank Sharma910530c2016-10-14 19:56:52 +05305035 lspcon_resume(lspcon);
5036
Manasi Navared7e8ef02017-02-07 16:54:11 -08005037 intel_dp->reset_link_params = true;
5038
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005039 pps_lock(intel_dp);
5040
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005041 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5042 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5043
5044 if (is_edp(intel_dp)) {
5045 /* Reinit the power sequencer, in case BIOS did something with it. */
5046 intel_dp_pps_init(encoder->dev, intel_dp);
5047 intel_edp_panel_vdd_sanitize(intel_dp);
5048 }
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005049
5050 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03005051}
5052
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005053static const struct drm_connector_funcs intel_dp_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02005054 .dpms = drm_atomic_helper_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005055 .detect = intel_dp_detect,
Chris Wilsonbeb60602014-09-02 20:04:00 +01005056 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005057 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01005058 .set_property = intel_dp_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -08005059 .atomic_get_property = intel_connector_atomic_get_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01005060 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01005061 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03005062 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08005063 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02005064 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005065};
5066
5067static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
5068 .get_modes = intel_dp_get_modes,
5069 .mode_valid = intel_dp_mode_valid,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005070};
5071
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005072static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03005073 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02005074 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005075};
5076
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005077enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10005078intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
5079{
5080 struct intel_dp *intel_dp = &intel_dig_port->dp;
Dave Airlie0e32b392014-05-02 14:02:48 +10005081 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005082 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005083 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03005084
Takashi Iwai25400582015-11-19 12:09:56 +01005085 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
5086 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Ville Syrjäläcca05022016-06-22 21:57:06 +03005087 intel_dig_port->base.type = INTEL_OUTPUT_DP;
Dave Airlie13cf5502014-06-18 11:29:35 +10005088
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005089 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
5090 /*
5091 * vdd off can generate a long pulse on eDP which
5092 * would require vdd on to handle it, and thus we
5093 * would end up in an endless cycle of
5094 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
5095 */
5096 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
5097 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d52f82015-02-10 14:11:46 +02005098 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005099 }
5100
Ville Syrjälä26fbb772014-08-11 18:37:37 +03005101 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
5102 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10005103 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10005104
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005105 if (long_hpd) {
Manasi Navared7e8ef02017-02-07 16:54:11 -08005106 intel_dp->reset_link_params = true;
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005107 intel_dp->detect_done = false;
5108 return IRQ_NONE;
5109 }
5110
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005111 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005112
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005113 if (intel_dp->is_mst) {
5114 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
5115 /*
5116 * If we were in MST mode, and device is not
5117 * there, get out of MST mode
5118 */
5119 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
5120 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
5121 intel_dp->is_mst = false;
5122 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
5123 intel_dp->is_mst);
5124 intel_dp->detect_done = false;
5125 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10005126 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005127 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005128
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005129 if (!intel_dp->is_mst) {
5130 if (!intel_dp_short_pulse(intel_dp)) {
5131 intel_dp->detect_done = false;
5132 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05305133 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005134 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005135
5136 ret = IRQ_HANDLED;
5137
Imre Deak1c767b32014-08-18 14:42:42 +03005138put_power:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005139 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005140
5141 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10005142}
5143
Rodrigo Vivi477ec322015-08-06 15:51:39 +08005144/* check the VBT to see whether the eDP is on another port */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005145bool intel_dp_is_edp(struct drm_i915_private *dev_priv, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08005146{
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005147 /*
5148 * eDP not supported on g4x. so bail out early just
5149 * for a bit extra safety in case the VBT is bonkers.
5150 */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005151 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005152 return false;
5153
Imre Deaka98d9c12016-12-21 12:17:24 +02005154 if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005155 return true;
5156
Jani Nikula951d9ef2016-03-16 12:43:31 +02005157 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08005158}
5159
Dave Airlie0e32b392014-05-02 14:02:48 +10005160void
Chris Wilsonf6849602010-09-19 09:29:33 +01005161intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
5162{
Yuly Novikov53b41832012-10-26 12:04:00 +03005163 struct intel_connector *intel_connector = to_intel_connector(connector);
5164
Chris Wilson3f43c482011-05-12 22:17:24 +01005165 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00005166 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02005167 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03005168
5169 if (is_edp(intel_dp)) {
5170 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05005171 drm_object_attach_property(
5172 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03005173 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03005174 DRM_MODE_SCALE_ASPECT);
5175 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03005176 }
Chris Wilsonf6849602010-09-19 09:29:33 +01005177}
5178
Imre Deakdada1a92014-01-29 13:25:41 +02005179static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
5180{
Abhay Kumard28d4732016-01-22 17:39:04 -08005181 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02005182 intel_dp->last_power_on = jiffies;
5183 intel_dp->last_backlight_off = jiffies;
5184}
5185
Daniel Vetter67a54562012-10-20 20:57:45 +02005186static void
Imre Deak54648612016-06-16 16:37:22 +03005187intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
5188 struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02005189{
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305190 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03005191 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07005192
Imre Deak8e8232d2016-06-16 16:37:21 +03005193 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02005194
5195 /* Workaround: Need to write PP_CONTROL with the unlock key as
5196 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305197 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02005198
Imre Deak8e8232d2016-06-16 16:37:21 +03005199 pp_on = I915_READ(regs.pp_on);
5200 pp_off = I915_READ(regs.pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005201 if (!IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005202 I915_WRITE(regs.pp_ctrl, pp_ctl);
5203 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305204 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005205
5206 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03005207 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
5208 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005209
Imre Deak54648612016-06-16 16:37:22 +03005210 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
5211 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005212
Imre Deak54648612016-06-16 16:37:22 +03005213 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
5214 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005215
Imre Deak54648612016-06-16 16:37:22 +03005216 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
5217 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005218
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005219 if (IS_GEN9_LP(dev_priv)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305220 u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
5221 BXT_POWER_CYCLE_DELAY_SHIFT;
5222 if (tmp > 0)
Imre Deak54648612016-06-16 16:37:22 +03005223 seq->t11_t12 = (tmp - 1) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305224 else
Imre Deak54648612016-06-16 16:37:22 +03005225 seq->t11_t12 = 0;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305226 } else {
Imre Deak54648612016-06-16 16:37:22 +03005227 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02005228 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305229 }
Imre Deak54648612016-06-16 16:37:22 +03005230}
5231
5232static void
Imre Deakde9c1b62016-06-16 20:01:46 +03005233intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
5234{
5235 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5236 state_name,
5237 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
5238}
5239
5240static void
5241intel_pps_verify_state(struct drm_i915_private *dev_priv,
5242 struct intel_dp *intel_dp)
5243{
5244 struct edp_power_seq hw;
5245 struct edp_power_seq *sw = &intel_dp->pps_delays;
5246
5247 intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
5248
5249 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
5250 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
5251 DRM_ERROR("PPS state mismatch\n");
5252 intel_pps_dump_state("sw", sw);
5253 intel_pps_dump_state("hw", &hw);
5254 }
5255}
5256
5257static void
Imre Deak54648612016-06-16 16:37:22 +03005258intel_dp_init_panel_power_sequencer(struct drm_device *dev,
5259 struct intel_dp *intel_dp)
5260{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005261 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak54648612016-06-16 16:37:22 +03005262 struct edp_power_seq cur, vbt, spec,
5263 *final = &intel_dp->pps_delays;
5264
5265 lockdep_assert_held(&dev_priv->pps_mutex);
5266
5267 /* already initialized? */
5268 if (final->t11_t12 != 0)
5269 return;
5270
5271 intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005272
Imre Deakde9c1b62016-06-16 20:01:46 +03005273 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005274
Jani Nikula6aa23e62016-03-24 17:50:20 +02005275 vbt = dev_priv->vbt.edp.pps;
Daniel Vetter67a54562012-10-20 20:57:45 +02005276
5277 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5278 * our hw here, which are all in 100usec. */
5279 spec.t1_t3 = 210 * 10;
5280 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5281 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5282 spec.t10 = 500 * 10;
5283 /* This one is special and actually in units of 100ms, but zero
5284 * based in the hw (so we need to add 100 ms). But the sw vbt
5285 * table multiplies it with 1000 to make it in units of 100usec,
5286 * too. */
5287 spec.t11_t12 = (510 + 100) * 10;
5288
Imre Deakde9c1b62016-06-16 20:01:46 +03005289 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005290
5291 /* Use the max of the register settings and vbt. If both are
5292 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005293#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005294 spec.field : \
5295 max(cur.field, vbt.field))
5296 assign_final(t1_t3);
5297 assign_final(t8);
5298 assign_final(t9);
5299 assign_final(t10);
5300 assign_final(t11_t12);
5301#undef assign_final
5302
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005303#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005304 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5305 intel_dp->backlight_on_delay = get_delay(t8);
5306 intel_dp->backlight_off_delay = get_delay(t9);
5307 intel_dp->panel_power_down_delay = get_delay(t10);
5308 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5309#undef get_delay
5310
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005311 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5312 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5313 intel_dp->panel_power_cycle_delay);
5314
5315 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5316 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005317
5318 /*
5319 * We override the HW backlight delays to 1 because we do manual waits
5320 * on them. For T8, even BSpec recommends doing it. For T9, if we
5321 * don't do this, we'll end up waiting for the backlight off delay
5322 * twice: once when we do the manual sleep, and once when we disable
5323 * the panel and wait for the PP_STATUS bit to become zero.
5324 */
5325 final->t8 = 1;
5326 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005327}
5328
5329static void
5330intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005331 struct intel_dp *intel_dp,
5332 bool force_disable_vdd)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005333{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005334 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07005335 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005336 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005337 struct pps_registers regs;
Ville Syrjäläad933b52014-08-18 22:15:56 +03005338 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005339 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005340
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005341 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005342
Imre Deak8e8232d2016-06-16 16:37:21 +03005343 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005344
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005345 /*
5346 * On some VLV machines the BIOS can leave the VDD
5347 * enabled even on power seqeuencers which aren't
5348 * hooked up to any port. This would mess up the
5349 * power domain tracking the first time we pick
5350 * one of these power sequencers for use since
5351 * edp_panel_vdd_on() would notice that the VDD was
5352 * already on and therefore wouldn't grab the power
5353 * domain reference. Disable VDD first to avoid this.
5354 * This also avoids spuriously turning the VDD on as
5355 * soon as the new power seqeuencer gets initialized.
5356 */
5357 if (force_disable_vdd) {
5358 u32 pp = ironlake_get_pp_control(intel_dp);
5359
5360 WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
5361
5362 if (pp & EDP_FORCE_VDD)
5363 DRM_DEBUG_KMS("VDD already on, disabling first\n");
5364
5365 pp &= ~EDP_FORCE_VDD;
5366
5367 I915_WRITE(regs.pp_ctrl, pp);
5368 }
5369
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005370 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005371 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5372 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005373 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005374 /* Compute the divisor for the pp clock, simply match the Bspec
5375 * formula. */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005376 if (IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005377 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305378 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
5379 pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
5380 << BXT_POWER_CYCLE_DELAY_SHIFT);
5381 } else {
5382 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5383 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5384 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5385 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005386
5387 /* Haswell doesn't have any port selection bits for the panel
5388 * power sequencer any more. */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005389 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005390 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005391 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005392 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005393 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005394 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005395 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005396 }
5397
Jesse Barnes453c5422013-03-28 09:55:41 -07005398 pp_on |= port_sel;
5399
Imre Deak8e8232d2016-06-16 16:37:21 +03005400 I915_WRITE(regs.pp_on, pp_on);
5401 I915_WRITE(regs.pp_off, pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005402 if (IS_GEN9_LP(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005403 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305404 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005405 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005406
Daniel Vetter67a54562012-10-20 20:57:45 +02005407 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 +03005408 I915_READ(regs.pp_on),
5409 I915_READ(regs.pp_off),
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005410 IS_GEN9_LP(dev_priv) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005411 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5412 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005413}
5414
Imre Deak335f7522016-08-10 14:07:32 +03005415static void intel_dp_pps_init(struct drm_device *dev,
5416 struct intel_dp *intel_dp)
5417{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005418 struct drm_i915_private *dev_priv = to_i915(dev);
5419
5420 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Imre Deak335f7522016-08-10 14:07:32 +03005421 vlv_initial_power_sequencer_setup(intel_dp);
5422 } else {
5423 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005424 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak335f7522016-08-10 14:07:32 +03005425 }
5426}
5427
Vandana Kannanb33a2812015-02-13 15:33:03 +05305428/**
5429 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005430 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005431 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305432 * @refresh_rate: RR to be programmed
5433 *
5434 * This function gets called when refresh rate (RR) has to be changed from
5435 * one frequency to another. Switches can be between high and low RR
5436 * supported by the panel or to any other RR based on media playback (in
5437 * this case, RR value needs to be passed from user space).
5438 *
5439 * The caller of this function needs to take a lock on dev_priv->drrs.
5440 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005441static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
5442 struct intel_crtc_state *crtc_state,
5443 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305444{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305445 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305446 struct intel_digital_port *dig_port = NULL;
5447 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005448 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305449 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305450
5451 if (refresh_rate <= 0) {
5452 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5453 return;
5454 }
5455
Vandana Kannan96178ee2015-01-10 02:25:56 +05305456 if (intel_dp == NULL) {
5457 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305458 return;
5459 }
5460
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005461 /*
Rodrigo Vivie4d59f62014-11-20 02:22:08 -08005462 * FIXME: This needs proper synchronization with psr state for some
5463 * platforms that cannot have PSR and DRRS enabled at the same time.
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005464 */
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305465
Vandana Kannan96178ee2015-01-10 02:25:56 +05305466 dig_port = dp_to_dig_port(intel_dp);
5467 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02005468 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305469
5470 if (!intel_crtc) {
5471 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5472 return;
5473 }
5474
Vandana Kannan96178ee2015-01-10 02:25:56 +05305475 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305476 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5477 return;
5478 }
5479
Vandana Kannan96178ee2015-01-10 02:25:56 +05305480 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5481 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305482 index = DRRS_LOW_RR;
5483
Vandana Kannan96178ee2015-01-10 02:25:56 +05305484 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305485 DRM_DEBUG_KMS(
5486 "DRRS requested for previously set RR...ignoring\n");
5487 return;
5488 }
5489
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005490 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305491 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5492 return;
5493 }
5494
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005495 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305496 switch (index) {
5497 case DRRS_HIGH_RR:
5498 intel_dp_set_m_n(intel_crtc, M1_N1);
5499 break;
5500 case DRRS_LOW_RR:
5501 intel_dp_set_m_n(intel_crtc, M2_N2);
5502 break;
5503 case DRRS_MAX_RR:
5504 default:
5505 DRM_ERROR("Unsupported refreshrate type\n");
5506 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005507 } else if (INTEL_GEN(dev_priv) > 6) {
5508 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005509 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305510
Ville Syrjälä649636e2015-09-22 19:50:01 +03005511 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305512 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005513 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305514 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5515 else
5516 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305517 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005518 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305519 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5520 else
5521 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305522 }
5523 I915_WRITE(reg, val);
5524 }
5525
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305526 dev_priv->drrs.refresh_rate_type = index;
5527
5528 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5529}
5530
Vandana Kannanb33a2812015-02-13 15:33:03 +05305531/**
5532 * intel_edp_drrs_enable - init drrs struct if supported
5533 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005534 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305535 *
5536 * Initializes frontbuffer_bits and drrs.dp
5537 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005538void intel_edp_drrs_enable(struct intel_dp *intel_dp,
5539 struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305540{
5541 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005542 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305543
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005544 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305545 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5546 return;
5547 }
5548
5549 mutex_lock(&dev_priv->drrs.mutex);
5550 if (WARN_ON(dev_priv->drrs.dp)) {
5551 DRM_ERROR("DRRS already enabled\n");
5552 goto unlock;
5553 }
5554
5555 dev_priv->drrs.busy_frontbuffer_bits = 0;
5556
5557 dev_priv->drrs.dp = intel_dp;
5558
5559unlock:
5560 mutex_unlock(&dev_priv->drrs.mutex);
5561}
5562
Vandana Kannanb33a2812015-02-13 15:33:03 +05305563/**
5564 * intel_edp_drrs_disable - Disable DRRS
5565 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005566 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305567 *
5568 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005569void intel_edp_drrs_disable(struct intel_dp *intel_dp,
5570 struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305571{
5572 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005573 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305574
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005575 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305576 return;
5577
5578 mutex_lock(&dev_priv->drrs.mutex);
5579 if (!dev_priv->drrs.dp) {
5580 mutex_unlock(&dev_priv->drrs.mutex);
5581 return;
5582 }
5583
5584 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005585 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5586 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305587
5588 dev_priv->drrs.dp = NULL;
5589 mutex_unlock(&dev_priv->drrs.mutex);
5590
5591 cancel_delayed_work_sync(&dev_priv->drrs.work);
5592}
5593
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305594static void intel_edp_drrs_downclock_work(struct work_struct *work)
5595{
5596 struct drm_i915_private *dev_priv =
5597 container_of(work, typeof(*dev_priv), drrs.work.work);
5598 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305599
Vandana Kannan96178ee2015-01-10 02:25:56 +05305600 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305601
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305602 intel_dp = dev_priv->drrs.dp;
5603
5604 if (!intel_dp)
5605 goto unlock;
5606
5607 /*
5608 * The delayed work can race with an invalidate hence we need to
5609 * recheck.
5610 */
5611
5612 if (dev_priv->drrs.busy_frontbuffer_bits)
5613 goto unlock;
5614
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005615 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5616 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5617
5618 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5619 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5620 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305621
5622unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305623 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305624}
5625
Vandana Kannanb33a2812015-02-13 15:33:03 +05305626/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305627 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005628 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305629 * @frontbuffer_bits: frontbuffer plane tracking bits
5630 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305631 * This function gets called everytime rendering on the given planes start.
5632 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305633 *
5634 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5635 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005636void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5637 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305638{
Vandana Kannana93fad02015-01-10 02:25:59 +05305639 struct drm_crtc *crtc;
5640 enum pipe pipe;
5641
Daniel Vetter9da7d692015-04-09 16:44:15 +02005642 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305643 return;
5644
Daniel Vetter88f933a2015-04-09 16:44:16 +02005645 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305646
Vandana Kannana93fad02015-01-10 02:25:59 +05305647 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005648 if (!dev_priv->drrs.dp) {
5649 mutex_unlock(&dev_priv->drrs.mutex);
5650 return;
5651 }
5652
Vandana Kannana93fad02015-01-10 02:25:59 +05305653 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5654 pipe = to_intel_crtc(crtc)->pipe;
5655
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005656 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5657 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5658
Ramalingam C0ddfd202015-06-15 20:50:05 +05305659 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005660 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005661 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5662 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305663
Vandana Kannana93fad02015-01-10 02:25:59 +05305664 mutex_unlock(&dev_priv->drrs.mutex);
5665}
5666
Vandana Kannanb33a2812015-02-13 15:33:03 +05305667/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305668 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005669 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305670 * @frontbuffer_bits: frontbuffer plane tracking bits
5671 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305672 * This function gets called every time rendering on the given planes has
5673 * completed or flip on a crtc is completed. So DRRS should be upclocked
5674 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5675 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305676 *
5677 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5678 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005679void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5680 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305681{
Vandana Kannana93fad02015-01-10 02:25:59 +05305682 struct drm_crtc *crtc;
5683 enum pipe pipe;
5684
Daniel Vetter9da7d692015-04-09 16:44:15 +02005685 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305686 return;
5687
Daniel Vetter88f933a2015-04-09 16:44:16 +02005688 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305689
Vandana Kannana93fad02015-01-10 02:25:59 +05305690 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005691 if (!dev_priv->drrs.dp) {
5692 mutex_unlock(&dev_priv->drrs.mutex);
5693 return;
5694 }
5695
Vandana Kannana93fad02015-01-10 02:25:59 +05305696 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5697 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005698
5699 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305700 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5701
Ramalingam C0ddfd202015-06-15 20:50:05 +05305702 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005703 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005704 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5705 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305706
5707 /*
5708 * flush also means no more activity hence schedule downclock, if all
5709 * other fbs are quiescent too
5710 */
5711 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305712 schedule_delayed_work(&dev_priv->drrs.work,
5713 msecs_to_jiffies(1000));
5714 mutex_unlock(&dev_priv->drrs.mutex);
5715}
5716
Vandana Kannanb33a2812015-02-13 15:33:03 +05305717/**
5718 * DOC: Display Refresh Rate Switching (DRRS)
5719 *
5720 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5721 * which enables swtching between low and high refresh rates,
5722 * dynamically, based on the usage scenario. This feature is applicable
5723 * for internal panels.
5724 *
5725 * Indication that the panel supports DRRS is given by the panel EDID, which
5726 * would list multiple refresh rates for one resolution.
5727 *
5728 * DRRS is of 2 types - static and seamless.
5729 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5730 * (may appear as a blink on screen) and is used in dock-undock scenario.
5731 * Seamless DRRS involves changing RR without any visual effect to the user
5732 * and can be used during normal system usage. This is done by programming
5733 * certain registers.
5734 *
5735 * Support for static/seamless DRRS may be indicated in the VBT based on
5736 * inputs from the panel spec.
5737 *
5738 * DRRS saves power by switching to low RR based on usage scenarios.
5739 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005740 * The implementation is based on frontbuffer tracking implementation. When
5741 * there is a disturbance on the screen triggered by user activity or a periodic
5742 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5743 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5744 * made.
5745 *
5746 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5747 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305748 *
5749 * DRRS can be further extended to support other internal panels and also
5750 * the scenario of video playback wherein RR is set based on the rate
5751 * requested by userspace.
5752 */
5753
5754/**
5755 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5756 * @intel_connector: eDP connector
5757 * @fixed_mode: preferred mode of panel
5758 *
5759 * This function is called only once at driver load to initialize basic
5760 * DRRS stuff.
5761 *
5762 * Returns:
5763 * Downclock mode if panel supports it, else return NULL.
5764 * DRRS support is determined by the presence of downclock mode (apart
5765 * from VBT setting).
5766 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305767static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305768intel_dp_drrs_init(struct intel_connector *intel_connector,
5769 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305770{
5771 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305772 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005773 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305774 struct drm_display_mode *downclock_mode = NULL;
5775
Daniel Vetter9da7d692015-04-09 16:44:15 +02005776 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5777 mutex_init(&dev_priv->drrs.mutex);
5778
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005779 if (INTEL_GEN(dev_priv) <= 6) {
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305780 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5781 return NULL;
5782 }
5783
5784 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005785 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305786 return NULL;
5787 }
5788
5789 downclock_mode = intel_find_panel_downclock
Mika Kaholaa318b4c2016-12-13 10:02:48 +02005790 (dev_priv, fixed_mode, connector);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305791
5792 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305793 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305794 return NULL;
5795 }
5796
Vandana Kannan96178ee2015-01-10 02:25:56 +05305797 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305798
Vandana Kannan96178ee2015-01-10 02:25:56 +05305799 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005800 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305801 return downclock_mode;
5802}
5803
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005804static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005805 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005806{
5807 struct drm_connector *connector = &intel_connector->base;
5808 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005809 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5810 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005811 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005812 struct drm_display_mode *fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305813 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005814 bool has_dpcd;
5815 struct drm_display_mode *scan;
5816 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005817 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005818
5819 if (!is_edp(intel_dp))
5820 return true;
5821
Imre Deak97a824e12016-06-21 11:51:47 +03005822 /*
5823 * On IBX/CPT we may get here with LVDS already registered. Since the
5824 * driver uses the only internal power sequencer available for both
5825 * eDP and LVDS bail out early in this case to prevent interfering
5826 * with an already powered-on LVDS power sequencer.
5827 */
5828 if (intel_get_lvds_encoder(dev)) {
5829 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5830 DRM_INFO("LVDS was detected, not registering eDP\n");
5831
5832 return false;
5833 }
5834
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005835 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005836
5837 intel_dp_init_panel_power_timestamps(intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +03005838 intel_dp_pps_init(dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005839 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005840
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005841 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005842
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005843 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005844 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005845
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005846 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005847 /* if this fails, presume the device is a ghost */
5848 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005849 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005850 }
5851
Daniel Vetter060c8772014-03-21 23:22:35 +01005852 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005853 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005854 if (edid) {
5855 if (drm_add_edid_modes(connector, edid)) {
5856 drm_mode_connector_update_edid_property(connector,
5857 edid);
5858 drm_edid_to_eld(connector, edid);
5859 } else {
5860 kfree(edid);
5861 edid = ERR_PTR(-EINVAL);
5862 }
5863 } else {
5864 edid = ERR_PTR(-ENOENT);
5865 }
5866 intel_connector->edid = edid;
5867
5868 /* prefer fixed mode from EDID if available */
5869 list_for_each_entry(scan, &connector->probed_modes, head) {
5870 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5871 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305872 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305873 intel_connector, fixed_mode);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005874 break;
5875 }
5876 }
5877
5878 /* fallback to VBT if available for eDP */
5879 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5880 fixed_mode = drm_mode_duplicate(dev,
5881 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005882 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005883 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005884 connector->display_info.width_mm = fixed_mode->width_mm;
5885 connector->display_info.height_mm = fixed_mode->height_mm;
5886 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005887 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005888 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005889
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005890 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005891 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5892 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005893
5894 /*
5895 * Figure out the current pipe for the initial backlight setup.
5896 * If the current pipe isn't valid, try the PPS pipe, and if that
5897 * fails just assume pipe A.
5898 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005899 pipe = vlv_active_pipe(intel_dp);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005900
5901 if (pipe != PIPE_A && pipe != PIPE_B)
5902 pipe = intel_dp->pps_pipe;
5903
5904 if (pipe != PIPE_A && pipe != PIPE_B)
5905 pipe = PIPE_A;
5906
5907 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5908 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005909 }
5910
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305911 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005912 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005913 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005914
5915 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005916
5917out_vdd_off:
5918 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5919 /*
5920 * vdd might still be enabled do to the delayed vdd off.
5921 * Make sure vdd is actually turned off here.
5922 */
5923 pps_lock(intel_dp);
5924 edp_panel_vdd_off_sync(intel_dp);
5925 pps_unlock(intel_dp);
5926
5927 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005928}
5929
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005930/* Set up the hotplug pin and aux power domain. */
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005931static void
5932intel_dp_init_connector_port_info(struct intel_digital_port *intel_dig_port)
5933{
5934 struct intel_encoder *encoder = &intel_dig_port->base;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005935 struct intel_dp *intel_dp = &intel_dig_port->dp;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005936
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005937 switch (intel_dig_port->port) {
5938 case PORT_A:
5939 encoder->hpd_pin = HPD_PORT_A;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005940 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_A;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005941 break;
5942 case PORT_B:
5943 encoder->hpd_pin = HPD_PORT_B;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005944 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_B;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005945 break;
5946 case PORT_C:
5947 encoder->hpd_pin = HPD_PORT_C;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005948 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_C;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005949 break;
5950 case PORT_D:
5951 encoder->hpd_pin = HPD_PORT_D;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005952 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005953 break;
5954 case PORT_E:
5955 encoder->hpd_pin = HPD_PORT_E;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005956
5957 /* FIXME: Check VBT for actual wiring of PORT E */
5958 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005959 break;
5960 default:
5961 MISSING_CASE(intel_dig_port->port);
5962 }
5963}
5964
Paulo Zanoni16c25532013-06-12 17:27:25 -03005965bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005966intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5967 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005968{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005969 struct drm_connector *connector = &intel_connector->base;
5970 struct intel_dp *intel_dp = &intel_dig_port->dp;
5971 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5972 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005973 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02005974 enum port port = intel_dig_port->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01005975 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005976
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005977 if (WARN(intel_dig_port->max_lanes < 1,
5978 "Not enough lanes (%d) for DP on port %c\n",
5979 intel_dig_port->max_lanes, port_name(port)))
5980 return false;
5981
Jani Nikula55cfc582017-03-28 17:59:04 +03005982 intel_dp_set_source_rates(intel_dp);
5983
Manasi Navared7e8ef02017-02-07 16:54:11 -08005984 intel_dp->reset_link_params = true;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005985 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005986 intel_dp->active_pipe = INVALID_PIPE;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005987
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005988 /* intel_dp vfuncs */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005989 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub6b5e382014-01-20 16:00:59 +00005990 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005991 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005992 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005993 else if (HAS_PCH_SPLIT(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005994 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
5995 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005996 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005997
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005998 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00005999 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
6000 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02006001 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00006002
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006003 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03006004 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
6005
Daniel Vetter07679352012-09-06 22:15:42 +02006006 /* Preserve the current hw state. */
6007 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03006008 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00006009
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006010 if (intel_dp_is_edp(dev_priv, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05306011 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02006012 else
6013 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04006014
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02006015 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
6016 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
6017
Imre Deakf7d24902013-05-08 13:14:05 +03006018 /*
6019 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
6020 * for DP the encoder type can be set by the caller to
6021 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
6022 */
6023 if (type == DRM_MODE_CONNECTOR_eDP)
6024 intel_encoder->type = INTEL_OUTPUT_EDP;
6025
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006026 /* eDP only on port B and/or C on vlv/chv */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006027 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08006028 is_edp(intel_dp) && port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006029 return false;
6030
Imre Deake7281ea2013-05-08 13:14:08 +03006031 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
6032 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
6033 port_name(port));
6034
Adam Jacksonb3295302010-07-16 14:46:28 -04006035 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006036 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
6037
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006038 connector->interlace_allowed = true;
6039 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08006040
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02006041 intel_dp_init_connector_port_info(intel_dig_port);
6042
Mika Kaholab6339582016-09-09 14:10:52 +03006043 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01006044
Daniel Vetter66a92782012-07-12 20:08:18 +02006045 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01006046 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08006047
Chris Wilsondf0e9242010-09-09 16:20:55 +01006048 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006049
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006050 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02006051 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
6052 else
6053 intel_connector->get_hw_state = intel_connector_get_hw_state;
6054
Dave Airlie0e32b392014-05-02 14:02:48 +10006055 /* init MST on ports that can support it */
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00006056 if (HAS_DP_MST(dev_priv) && !is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03006057 (port == PORT_B || port == PORT_C || port == PORT_D))
6058 intel_dp_mst_encoder_init(intel_dig_port,
6059 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10006060
Ville Syrjälä36b5f422014-10-16 21:27:30 +03006061 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006062 intel_dp_aux_fini(intel_dp);
6063 intel_dp_mst_encoder_cleanup(intel_dig_port);
6064 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03006065 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08006066
Chris Wilsonf6849602010-09-19 09:29:33 +01006067 intel_dp_add_properties(intel_dp, connector);
6068
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006069 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
6070 * 0xd. Failure to do so will result in spurious interrupts being
6071 * generated on the port when a cable is not attached.
6072 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01006073 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006074 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
6075 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
6076 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03006077
6078 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006079
6080fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006081 drm_connector_cleanup(connector);
6082
6083 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006084}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006085
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006086bool intel_dp_init(struct drm_i915_private *dev_priv,
Chris Wilson457c52d2016-06-01 08:27:50 +01006087 i915_reg_t output_reg,
6088 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006089{
6090 struct intel_digital_port *intel_dig_port;
6091 struct intel_encoder *intel_encoder;
6092 struct drm_encoder *encoder;
6093 struct intel_connector *intel_connector;
6094
Daniel Vetterb14c5672013-09-19 12:18:32 +02006095 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006096 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01006097 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006098
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03006099 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306100 if (!intel_connector)
6101 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006102
6103 intel_encoder = &intel_dig_port->base;
6104 encoder = &intel_encoder->base;
6105
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006106 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
6107 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
6108 "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306109 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006110
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01006111 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006112 intel_encoder->disable = intel_disable_dp;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006113 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07006114 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03006115 intel_encoder->suspend = intel_dp_encoder_suspend;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006116 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03006117 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03006118 intel_encoder->pre_enable = chv_pre_enable_dp;
6119 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03006120 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03006121 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01006122 } else if (IS_VALLEYVIEW(dev_priv)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006123 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006124 intel_encoder->pre_enable = vlv_pre_enable_dp;
6125 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03006126 intel_encoder->post_disable = vlv_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006127 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006128 intel_encoder->pre_enable = g4x_pre_enable_dp;
6129 intel_encoder->enable = g4x_enable_dp;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006130 if (INTEL_GEN(dev_priv) >= 5)
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03006131 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006132 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006133
Paulo Zanoni174edf12012-10-26 19:05:50 -02006134 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006135 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02006136 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006137
Ville Syrjäläcca05022016-06-22 21:57:06 +03006138 intel_encoder->type = INTEL_OUTPUT_DP;
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02006139 intel_encoder->power_domain = intel_port_to_power_domain(port);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006140 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03006141 if (port == PORT_D)
6142 intel_encoder->crtc_mask = 1 << 2;
6143 else
6144 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
6145 } else {
6146 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
6147 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02006148 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07006149 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006150
Dave Airlie13cf5502014-06-18 11:29:35 +10006151 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03006152 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10006153
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306154 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
6155 goto err_init_connector;
6156
Chris Wilson457c52d2016-06-01 08:27:50 +01006157 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306158
6159err_init_connector:
6160 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306161err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306162 kfree(intel_connector);
6163err_connector_alloc:
6164 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01006165 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006166}
Dave Airlie0e32b392014-05-02 14:02:48 +10006167
6168void intel_dp_mst_suspend(struct drm_device *dev)
6169{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006170 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006171 int i;
6172
6173 /* disable MST */
6174 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006175 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006176
6177 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006178 continue;
6179
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006180 if (intel_dig_port->dp.is_mst)
6181 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10006182 }
6183}
6184
6185void intel_dp_mst_resume(struct drm_device *dev)
6186{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006187 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006188 int i;
6189
6190 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006191 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006192 int ret;
6193
6194 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006195 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10006196
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006197 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
6198 if (ret)
6199 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10006200 }
6201}