blob: 8c061c54d481322d6511263000aed6869a7b82a6 [file] [log] [blame]
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Keith Packard <keithp@keithp.com>
25 *
26 */
27
28#include <linux/i2c.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040030#include <linux/export.h>
Manasi Navare611032b2017-01-24 08:21:49 -080031#include <linux/types.h>
Clint Taylor01527b32014-07-07 13:01:46 -070032#include <linux/notifier.h>
33#include <linux/reboot.h>
Manasi Navare611032b2017-01-24 08:21:49 -080034#include <asm/byteorder.h>
David Howells760285e2012-10-02 18:01:07 +010035#include <drm/drmP.h>
Matt Roperc6f95f22015-01-22 16:50:32 -080036#include <drm/drm_atomic_helper.h>
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/drm_crtc.h>
38#include <drm/drm_crtc_helper.h>
39#include <drm/drm_edid.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070040#include "intel_drv.h"
David Howells760285e2012-10-02 18:01:07 +010041#include <drm/i915_drm.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070042#include "i915_drv.h"
Keith Packarda4fc5ed2009-04-07 16:16:42 -070043
Keith Packarda4fc5ed2009-04-07 16:16:42 -070044#define DP_LINK_CHECK_TIMEOUT (10 * 1000)
45
Todd Previte559be302015-05-04 07:48:20 -070046/* Compliance test status bits */
47#define INTEL_DP_RESOLUTION_SHIFT_MASK 0
48#define INTEL_DP_RESOLUTION_PREFERRED (1 << INTEL_DP_RESOLUTION_SHIFT_MASK)
49#define INTEL_DP_RESOLUTION_STANDARD (2 << INTEL_DP_RESOLUTION_SHIFT_MASK)
50#define INTEL_DP_RESOLUTION_FAILSAFE (3 << INTEL_DP_RESOLUTION_SHIFT_MASK)
51
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080052struct dp_link_dpll {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030053 int clock;
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080054 struct dpll dpll;
55};
56
57static const struct dp_link_dpll gen4_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030058 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080059 { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030060 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080061 { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
62};
63
64static const struct dp_link_dpll pch_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030065 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080066 { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030067 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080068 { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
69};
70
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080071static const struct dp_link_dpll vlv_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030072 { 162000,
Chon Ming Lee58f6e632013-09-25 15:47:51 +080073 { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030074 { 270000,
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080075 { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } }
76};
77
Chon Ming Leeef9348c2014-04-09 13:28:18 +030078/*
79 * CHV supports eDP 1.4 that have more link rates.
80 * Below only provides the fixed rate but exclude variable rate.
81 */
82static const struct dp_link_dpll chv_dpll[] = {
83 /*
84 * CHV requires to program fractional division for m2.
85 * m2 is stored in fixed point format using formula below
86 * (m2_int << 22) | m2_fraction
87 */
Ville Syrjälä840b32b2015-08-11 20:21:46 +030088 { 162000, /* m2_int = 32, m2_fraction = 1677722 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030089 { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030090 { 270000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030091 { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030092 { 540000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030093 { .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }
94};
Sonika Jindal637a9c62015-05-07 09:52:08 +053095
Sonika Jindal64987fc2015-05-26 17:50:13 +053096static const int bxt_rates[] = { 162000, 216000, 243000, 270000,
97 324000, 432000, 540000 };
Sonika Jindal637a9c62015-05-07 09:52:08 +053098static const int skl_rates[] = { 162000, 216000, 270000,
Ville Syrjäläf4896f12015-03-12 17:10:27 +020099 324000, 432000, 540000 };
100static const int default_rates[] = { 162000, 270000, 540000 };
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300101
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700102/**
103 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
104 * @intel_dp: DP struct
105 *
106 * If a CPU or PCH DP output is attached to an eDP panel, this function
107 * will return true, and false otherwise.
108 */
109static bool is_edp(struct intel_dp *intel_dp)
110{
Paulo Zanonida63a9f2012-10-26 19:05:46 -0200111 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
112
113 return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700114}
115
Imre Deak68b4d822013-05-08 13:14:06 +0300116static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp)
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700117{
Imre Deak68b4d822013-05-08 13:14:06 +0300118 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
119
120 return intel_dig_port->base.base.dev;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700121}
122
Chris Wilsondf0e9242010-09-09 16:20:55 +0100123static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
124{
Paulo Zanonifa90ece2012-10-26 19:05:44 -0200125 return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
Chris Wilsondf0e9242010-09-09 16:20:55 +0100126}
127
Chris Wilsonea5b2132010-08-04 13:50:23 +0100128static void intel_dp_link_down(struct intel_dp *intel_dp);
Ville Syrjälä1e0560e2014-08-19 13:24:25 +0300129static bool edp_panel_vdd_on(struct intel_dp *intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +0100130static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
Ville Syrjälä093e3f12014-10-16 21:27:33 +0300131static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300132static void vlv_steal_power_sequencer(struct drm_device *dev,
133 enum pipe pipe);
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +0530134static void intel_dp_unset_edid(struct intel_dp *intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700135
Jani Nikula68f357c2017-03-28 17:59:05 +0300136static int intel_dp_num_rates(u8 link_bw_code)
137{
138 switch (link_bw_code) {
139 default:
140 WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
141 link_bw_code);
142 case DP_LINK_BW_1_62:
143 return 1;
144 case DP_LINK_BW_2_7:
145 return 2;
146 case DP_LINK_BW_5_4:
147 return 3;
148 }
149}
150
151/* update sink rates from dpcd */
152static void intel_dp_set_sink_rates(struct intel_dp *intel_dp)
153{
154 int i, num_rates;
155
156 num_rates = intel_dp_num_rates(intel_dp->dpcd[DP_MAX_LINK_RATE]);
157
158 for (i = 0; i < num_rates; i++)
159 intel_dp->sink_rates[i] = default_rates[i];
160
161 intel_dp->num_sink_rates = num_rates;
162}
163
Jani Nikulaa079d102017-04-06 16:44:09 +0300164static int intel_dp_max_sink_rate(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700165{
Jani Nikulaa079d102017-04-06 16:44:09 +0300166 return intel_dp->sink_rates[intel_dp->num_sink_rates - 1];
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700167}
168
Paulo Zanonieeb63242014-05-06 14:56:50 +0300169static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
170{
171 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300172 u8 source_max, sink_max;
173
Ville Syrjäläccb1a832015-12-08 19:59:38 +0200174 source_max = intel_dig_port->max_lanes;
Manasi Navaref4829842016-12-05 16:27:36 -0800175 sink_max = intel_dp->max_sink_lane_count;
Paulo Zanonieeb63242014-05-06 14:56:50 +0300176
177 return min(source_max, sink_max);
178}
179
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800180int
Keith Packardc8982612012-01-25 08:16:25 -0800181intel_dp_link_required(int pixel_clock, int bpp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700182{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800183 /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
184 return DIV_ROUND_UP(pixel_clock * bpp, 8);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700185}
186
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800187int
Dave Airliefe27d532010-06-30 11:46:17 +1000188intel_dp_max_data_rate(int max_link_clock, int max_lanes)
189{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800190 /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
191 * link rate that is generally expressed in Gbps. Since, 8 bits of data
192 * is transmitted every LS_Clk per lane, there is no need to account for
193 * the channel encoding that is done in the PHY layer here.
194 */
195
196 return max_link_clock * max_lanes;
Dave Airliefe27d532010-06-30 11:46:17 +1000197}
198
Mika Kahola70ec0642016-09-09 14:10:55 +0300199static int
200intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp)
201{
202 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
203 struct intel_encoder *encoder = &intel_dig_port->base;
204 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
205 int max_dotclk = dev_priv->max_dotclk_freq;
206 int ds_max_dotclk;
207
208 int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
209
210 if (type != DP_DS_PORT_TYPE_VGA)
211 return max_dotclk;
212
213 ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd,
214 intel_dp->downstream_ports);
215
216 if (ds_max_dotclk != 0)
217 max_dotclk = min(max_dotclk, ds_max_dotclk);
218
219 return max_dotclk;
220}
221
Jani Nikula55cfc582017-03-28 17:59:04 +0300222static void
223intel_dp_set_source_rates(struct intel_dp *intel_dp)
Navare, Manasi D40dba342016-10-26 16:25:55 -0700224{
225 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
226 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Jani Nikula55cfc582017-03-28 17:59:04 +0300227 const int *source_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700228 int size;
229
Jani Nikula55cfc582017-03-28 17:59:04 +0300230 /* This should only be done once */
231 WARN_ON(intel_dp->source_rates || intel_dp->num_source_rates);
232
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200233 if (IS_GEN9_LP(dev_priv)) {
Jani Nikula55cfc582017-03-28 17:59:04 +0300234 source_rates = bxt_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700235 size = ARRAY_SIZE(bxt_rates);
Rodrigo Vivib976dc52017-01-23 10:32:37 -0800236 } else if (IS_GEN9_BC(dev_priv)) {
Jani Nikula55cfc582017-03-28 17:59:04 +0300237 source_rates = skl_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700238 size = ARRAY_SIZE(skl_rates);
239 } else {
Jani Nikula55cfc582017-03-28 17:59:04 +0300240 source_rates = default_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700241 size = ARRAY_SIZE(default_rates);
242 }
243
244 /* This depends on the fact that 5.4 is last value in the array */
245 if (!intel_dp_source_supports_hbr2(intel_dp))
246 size--;
247
Jani Nikula55cfc582017-03-28 17:59:04 +0300248 intel_dp->source_rates = source_rates;
249 intel_dp->num_source_rates = size;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700250}
251
252static int intersect_rates(const int *source_rates, int source_len,
253 const int *sink_rates, int sink_len,
254 int *common_rates)
255{
256 int i = 0, j = 0, k = 0;
257
258 while (i < source_len && j < sink_len) {
259 if (source_rates[i] == sink_rates[j]) {
260 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
261 return k;
262 common_rates[k] = source_rates[i];
263 ++k;
264 ++i;
265 ++j;
266 } else if (source_rates[i] < sink_rates[j]) {
267 ++i;
268 } else {
269 ++j;
270 }
271 }
272 return k;
273}
274
Jani Nikula8001b752017-03-28 17:59:03 +0300275/* return index of rate in rates array, or -1 if not found */
276static int intel_dp_rate_index(const int *rates, int len, int rate)
277{
278 int i;
279
280 for (i = 0; i < len; i++)
281 if (rate == rates[i])
282 return i;
283
284 return -1;
285}
286
Jani Nikula975ee5fca2017-04-06 16:44:10 +0300287static void intel_dp_set_common_rates(struct intel_dp *intel_dp)
Navare, Manasi D40dba342016-10-26 16:25:55 -0700288{
Jani Nikula975ee5fca2017-04-06 16:44:10 +0300289 WARN_ON(!intel_dp->num_source_rates || !intel_dp->num_sink_rates);
Navare, Manasi D40dba342016-10-26 16:25:55 -0700290
Jani Nikula975ee5fca2017-04-06 16:44:10 +0300291 intel_dp->num_common_rates = intersect_rates(intel_dp->source_rates,
292 intel_dp->num_source_rates,
293 intel_dp->sink_rates,
294 intel_dp->num_sink_rates,
295 intel_dp->common_rates);
296
297 /* Paranoia, there should always be something in common. */
298 if (WARN_ON(intel_dp->num_common_rates == 0)) {
299 intel_dp->common_rates[0] = default_rates[0];
300 intel_dp->num_common_rates = 1;
301 }
302}
303
304/* get length of common rates potentially limited by max_rate */
305static int intel_dp_common_len_rate_limit(struct intel_dp *intel_dp,
306 int max_rate)
307{
308 const int *common_rates = intel_dp->common_rates;
309 int i, common_len = intel_dp->num_common_rates;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700310
Jani Nikula68f357c2017-03-28 17:59:05 +0300311 /* Limit results by potentially reduced max rate */
312 for (i = 0; i < common_len; i++) {
313 if (common_rates[common_len - i - 1] <= max_rate)
314 return common_len - i;
315 }
316
317 return 0;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700318}
319
Manasi Navarefdb14d32016-12-08 19:05:12 -0800320int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
321 int link_rate, uint8_t lane_count)
322{
Jani Nikulab1810a72017-04-06 16:44:11 +0300323 int index;
Manasi Navarefdb14d32016-12-08 19:05:12 -0800324
Jani Nikulab1810a72017-04-06 16:44:11 +0300325 index = intel_dp_rate_index(intel_dp->common_rates,
326 intel_dp->num_common_rates,
327 link_rate);
328 if (index > 0) {
329 intel_dp->max_sink_link_rate = intel_dp->common_rates[index - 1];
Manasi Navarefdb14d32016-12-08 19:05:12 -0800330 intel_dp->max_sink_lane_count = lane_count;
331 } else if (lane_count > 1) {
Jani Nikulaa079d102017-04-06 16:44:09 +0300332 intel_dp->max_sink_link_rate = intel_dp_max_sink_rate(intel_dp);
Manasi Navarefdb14d32016-12-08 19:05:12 -0800333 intel_dp->max_sink_lane_count = lane_count >> 1;
334 } else {
335 DRM_ERROR("Link Training Unsuccessful\n");
336 return -1;
337 }
338
339 return 0;
340}
341
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000342static enum drm_mode_status
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700343intel_dp_mode_valid(struct drm_connector *connector,
344 struct drm_display_mode *mode)
345{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100346 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300347 struct intel_connector *intel_connector = to_intel_connector(connector);
348 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Daniel Vetter36008362013-03-27 00:44:59 +0100349 int target_clock = mode->clock;
350 int max_rate, mode_rate, max_lanes, max_link_clock;
Mika Kahola70ec0642016-09-09 14:10:55 +0300351 int max_dotclk;
352
353 max_dotclk = intel_dp_downstream_max_dotclock(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700354
Jani Nikuladd06f902012-10-19 14:51:50 +0300355 if (is_edp(intel_dp) && fixed_mode) {
356 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100357 return MODE_PANEL;
358
Jani Nikuladd06f902012-10-19 14:51:50 +0300359 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100360 return MODE_PANEL;
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200361
362 target_clock = fixed_mode->clock;
Zhao Yakui7de56f42010-07-19 09:43:14 +0100363 }
364
Ville Syrjälä50fec212015-03-12 17:10:34 +0200365 max_link_clock = intel_dp_max_link_rate(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300366 max_lanes = intel_dp_max_lane_count(intel_dp);
Daniel Vetter36008362013-03-27 00:44:59 +0100367
368 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
369 mode_rate = intel_dp_link_required(target_clock, 18);
370
Mika Kahola799487f2016-02-02 15:16:38 +0200371 if (mode_rate > max_rate || target_clock > max_dotclk)
Daniel Vetterc4867932012-04-10 10:42:36 +0200372 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700373
374 if (mode->clock < 10000)
375 return MODE_CLOCK_LOW;
376
Daniel Vetter0af78a22012-05-23 11:30:55 +0200377 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
378 return MODE_H_ILLEGAL;
379
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700380 return MODE_OK;
381}
382
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800383uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700384{
385 int i;
386 uint32_t v = 0;
387
388 if (src_bytes > 4)
389 src_bytes = 4;
390 for (i = 0; i < src_bytes; i++)
391 v |= ((uint32_t) src[i]) << ((3-i) * 8);
392 return v;
393}
394
Damien Lespiauc2af70e2015-02-10 19:32:23 +0000395static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700396{
397 int i;
398 if (dst_bytes > 4)
399 dst_bytes = 4;
400 for (i = 0; i < dst_bytes; i++)
401 dst[i] = src >> ((3-i) * 8);
402}
403
Jani Nikulabf13e812013-09-06 07:40:05 +0300404static void
405intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300406 struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300407static void
408intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200409 struct intel_dp *intel_dp,
410 bool force_disable_vdd);
Imre Deak335f7522016-08-10 14:07:32 +0300411static void
412intel_dp_pps_init(struct drm_device *dev, struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300413
Ville Syrjälä773538e82014-09-04 14:54:56 +0300414static void pps_lock(struct intel_dp *intel_dp)
415{
416 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
417 struct intel_encoder *encoder = &intel_dig_port->base;
418 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100419 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300420
421 /*
422 * See vlv_power_sequencer_reset() why we need
423 * a power domain reference here.
424 */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +0200425 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300426
427 mutex_lock(&dev_priv->pps_mutex);
428}
429
430static void pps_unlock(struct intel_dp *intel_dp)
431{
432 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
433 struct intel_encoder *encoder = &intel_dig_port->base;
434 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100435 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300436
437 mutex_unlock(&dev_priv->pps_mutex);
438
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +0200439 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300440}
441
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300442static void
443vlv_power_sequencer_kick(struct intel_dp *intel_dp)
444{
445 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200446 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300447 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300448 bool pll_enabled, release_cl_override = false;
449 enum dpio_phy phy = DPIO_PHY(pipe);
450 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300451 uint32_t DP;
452
453 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
454 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
455 pipe_name(pipe), port_name(intel_dig_port->port)))
456 return;
457
458 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
459 pipe_name(pipe), port_name(intel_dig_port->port));
460
461 /* Preserve the BIOS-computed detected bit. This is
462 * supposed to be read-only.
463 */
464 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
465 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
466 DP |= DP_PORT_WIDTH(1);
467 DP |= DP_LINK_TRAIN_PAT_1;
468
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100469 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300470 DP |= DP_PIPE_SELECT_CHV(pipe);
471 else if (pipe == PIPE_B)
472 DP |= DP_PIPEB_SELECT;
473
Ville Syrjäläd288f652014-10-28 13:20:22 +0200474 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
475
476 /*
477 * The DPLL for the pipe must be enabled for this to work.
478 * So enable temporarily it if it's not already enabled.
479 */
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300480 if (!pll_enabled) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100481 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300482 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
483
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200484 if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ?
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000485 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
486 DRM_ERROR("Failed to force on pll for pipe %c!\n",
487 pipe_name(pipe));
488 return;
489 }
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300490 }
Ville Syrjäläd288f652014-10-28 13:20:22 +0200491
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300492 /*
493 * Similar magic as in intel_dp_enable_port().
494 * We _must_ do this port enable + disable trick
495 * to make this power seqeuencer lock onto the port.
496 * Otherwise even VDD force bit won't work.
497 */
498 I915_WRITE(intel_dp->output_reg, DP);
499 POSTING_READ(intel_dp->output_reg);
500
501 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
502 POSTING_READ(intel_dp->output_reg);
503
504 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
505 POSTING_READ(intel_dp->output_reg);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200506
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300507 if (!pll_enabled) {
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200508 vlv_force_pll_off(dev_priv, pipe);
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300509
510 if (release_cl_override)
511 chv_phy_powergate_ch(dev_priv, phy, ch, false);
512 }
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300513}
514
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200515static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv)
516{
517 struct intel_encoder *encoder;
518 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
519
520 /*
521 * We don't have power sequencer currently.
522 * Pick one that's not used by other ports.
523 */
524 for_each_intel_encoder(&dev_priv->drm, encoder) {
525 struct intel_dp *intel_dp;
526
527 if (encoder->type != INTEL_OUTPUT_DP &&
528 encoder->type != INTEL_OUTPUT_EDP)
529 continue;
530
531 intel_dp = enc_to_intel_dp(&encoder->base);
532
533 if (encoder->type == INTEL_OUTPUT_EDP) {
534 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
535 intel_dp->active_pipe != intel_dp->pps_pipe);
536
537 if (intel_dp->pps_pipe != INVALID_PIPE)
538 pipes &= ~(1 << intel_dp->pps_pipe);
539 } else {
540 WARN_ON(intel_dp->pps_pipe != INVALID_PIPE);
541
542 if (intel_dp->active_pipe != INVALID_PIPE)
543 pipes &= ~(1 << intel_dp->active_pipe);
544 }
545 }
546
547 if (pipes == 0)
548 return INVALID_PIPE;
549
550 return ffs(pipes) - 1;
551}
552
Jani Nikulabf13e812013-09-06 07:40:05 +0300553static enum pipe
554vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
555{
556 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300557 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100558 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300559 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300560
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300561 lockdep_assert_held(&dev_priv->pps_mutex);
562
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300563 /* We should never land here with regular DP ports */
564 WARN_ON(!is_edp(intel_dp));
565
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200566 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
567 intel_dp->active_pipe != intel_dp->pps_pipe);
568
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300569 if (intel_dp->pps_pipe != INVALID_PIPE)
570 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300571
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200572 pipe = vlv_find_free_pps(dev_priv);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300573
574 /*
575 * Didn't find one. This should not happen since there
576 * are two power sequencers and up to two eDP ports.
577 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200578 if (WARN_ON(pipe == INVALID_PIPE))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300579 pipe = PIPE_A;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300580
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300581 vlv_steal_power_sequencer(dev, pipe);
582 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300583
584 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
585 pipe_name(intel_dp->pps_pipe),
586 port_name(intel_dig_port->port));
587
588 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300589 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200590 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300591
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300592 /*
593 * Even vdd force doesn't work until we've made
594 * the power sequencer lock in on the port.
595 */
596 vlv_power_sequencer_kick(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300597
598 return intel_dp->pps_pipe;
599}
600
Imre Deak78597992016-06-16 16:37:20 +0300601static int
602bxt_power_sequencer_idx(struct intel_dp *intel_dp)
603{
604 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
605 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100606 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak78597992016-06-16 16:37:20 +0300607
608 lockdep_assert_held(&dev_priv->pps_mutex);
609
610 /* We should never land here with regular DP ports */
611 WARN_ON(!is_edp(intel_dp));
612
613 /*
614 * TODO: BXT has 2 PPS instances. The correct port->PPS instance
615 * mapping needs to be retrieved from VBT, for now just hard-code to
616 * use instance #0 always.
617 */
618 if (!intel_dp->pps_reset)
619 return 0;
620
621 intel_dp->pps_reset = false;
622
623 /*
624 * Only the HW needs to be reprogrammed, the SW state is fixed and
625 * has been setup during connector init.
626 */
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200627 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak78597992016-06-16 16:37:20 +0300628
629 return 0;
630}
631
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300632typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
633 enum pipe pipe);
634
635static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
636 enum pipe pipe)
637{
Imre Deak44cb7342016-08-10 14:07:29 +0300638 return I915_READ(PP_STATUS(pipe)) & PP_ON;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300639}
640
641static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
642 enum pipe pipe)
643{
Imre Deak44cb7342016-08-10 14:07:29 +0300644 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300645}
646
647static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
648 enum pipe pipe)
649{
650 return true;
651}
652
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300653static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300654vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
655 enum port port,
656 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300657{
Jani Nikulabf13e812013-09-06 07:40:05 +0300658 enum pipe pipe;
659
Jani Nikulabf13e812013-09-06 07:40:05 +0300660 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
Imre Deak44cb7342016-08-10 14:07:29 +0300661 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
Jani Nikulabf13e812013-09-06 07:40:05 +0300662 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300663
664 if (port_sel != PANEL_PORT_SELECT_VLV(port))
665 continue;
666
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300667 if (!pipe_check(dev_priv, pipe))
668 continue;
669
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300670 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300671 }
672
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300673 return INVALID_PIPE;
674}
675
676static void
677vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
678{
679 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
680 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100681 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300682 enum port port = intel_dig_port->port;
683
684 lockdep_assert_held(&dev_priv->pps_mutex);
685
686 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300687 /* first pick one where the panel is on */
688 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
689 vlv_pipe_has_pp_on);
690 /* didn't find one? pick one where vdd is on */
691 if (intel_dp->pps_pipe == INVALID_PIPE)
692 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
693 vlv_pipe_has_vdd_on);
694 /* didn't find one? pick one with just the correct port */
695 if (intel_dp->pps_pipe == INVALID_PIPE)
696 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
697 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300698
699 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
700 if (intel_dp->pps_pipe == INVALID_PIPE) {
701 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
702 port_name(port));
703 return;
704 }
705
706 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
707 port_name(port), pipe_name(intel_dp->pps_pipe));
708
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300709 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200710 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Jani Nikulabf13e812013-09-06 07:40:05 +0300711}
712
Imre Deak78597992016-06-16 16:37:20 +0300713void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300714{
Chris Wilson91c8a322016-07-05 10:40:23 +0100715 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300716 struct intel_encoder *encoder;
717
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100718 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200719 !IS_GEN9_LP(dev_priv)))
Ville Syrjälä773538e82014-09-04 14:54:56 +0300720 return;
721
722 /*
723 * We can't grab pps_mutex here due to deadlock with power_domain
724 * mutex when power_domain functions are called while holding pps_mutex.
725 * That also means that in order to use pps_pipe the code needs to
726 * hold both a power domain reference and pps_mutex, and the power domain
727 * reference get/put must be done while _not_ holding pps_mutex.
728 * pps_{lock,unlock}() do these steps in the correct order, so one
729 * should use them always.
730 */
731
Jani Nikula19c80542015-12-16 12:48:16 +0200732 for_each_intel_encoder(dev, encoder) {
Ville Syrjälä773538e82014-09-04 14:54:56 +0300733 struct intel_dp *intel_dp;
734
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200735 if (encoder->type != INTEL_OUTPUT_DP &&
736 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300737 continue;
738
739 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200740
741 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
742
743 if (encoder->type != INTEL_OUTPUT_EDP)
744 continue;
745
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200746 if (IS_GEN9_LP(dev_priv))
Imre Deak78597992016-06-16 16:37:20 +0300747 intel_dp->pps_reset = true;
748 else
749 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300750 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300751}
752
Imre Deak8e8232d2016-06-16 16:37:21 +0300753struct pps_registers {
754 i915_reg_t pp_ctrl;
755 i915_reg_t pp_stat;
756 i915_reg_t pp_on;
757 i915_reg_t pp_off;
758 i915_reg_t pp_div;
759};
760
761static void intel_pps_get_registers(struct drm_i915_private *dev_priv,
762 struct intel_dp *intel_dp,
763 struct pps_registers *regs)
764{
Imre Deak44cb7342016-08-10 14:07:29 +0300765 int pps_idx = 0;
766
Imre Deak8e8232d2016-06-16 16:37:21 +0300767 memset(regs, 0, sizeof(*regs));
768
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200769 if (IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300770 pps_idx = bxt_power_sequencer_idx(intel_dp);
771 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
772 pps_idx = vlv_power_sequencer_pipe(intel_dp);
Imre Deak8e8232d2016-06-16 16:37:21 +0300773
Imre Deak44cb7342016-08-10 14:07:29 +0300774 regs->pp_ctrl = PP_CONTROL(pps_idx);
775 regs->pp_stat = PP_STATUS(pps_idx);
776 regs->pp_on = PP_ON_DELAYS(pps_idx);
777 regs->pp_off = PP_OFF_DELAYS(pps_idx);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200778 if (!IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300779 regs->pp_div = PP_DIVISOR(pps_idx);
Imre Deak8e8232d2016-06-16 16:37:21 +0300780}
781
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200782static i915_reg_t
783_pp_ctrl_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300784{
Imre Deak8e8232d2016-06-16 16:37:21 +0300785 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300786
Imre Deak8e8232d2016-06-16 16:37:21 +0300787 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
788 &regs);
789
790 return regs.pp_ctrl;
Jani Nikulabf13e812013-09-06 07:40:05 +0300791}
792
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200793static i915_reg_t
794_pp_stat_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300795{
Imre Deak8e8232d2016-06-16 16:37:21 +0300796 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300797
Imre Deak8e8232d2016-06-16 16:37:21 +0300798 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
799 &regs);
800
801 return regs.pp_stat;
Jani Nikulabf13e812013-09-06 07:40:05 +0300802}
803
Clint Taylor01527b32014-07-07 13:01:46 -0700804/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
805 This function only applicable when panel PM state is not to be tracked */
806static int edp_notify_handler(struct notifier_block *this, unsigned long code,
807 void *unused)
808{
809 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
810 edp_notifier);
811 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100812 struct drm_i915_private *dev_priv = to_i915(dev);
Clint Taylor01527b32014-07-07 13:01:46 -0700813
814 if (!is_edp(intel_dp) || code != SYS_RESTART)
815 return 0;
816
Ville Syrjälä773538e82014-09-04 14:54:56 +0300817 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300818
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100819 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300820 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200821 i915_reg_t pp_ctrl_reg, pp_div_reg;
Ville Syrjälä649636e2015-09-22 19:50:01 +0300822 u32 pp_div;
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300823
Imre Deak44cb7342016-08-10 14:07:29 +0300824 pp_ctrl_reg = PP_CONTROL(pipe);
825 pp_div_reg = PP_DIVISOR(pipe);
Clint Taylor01527b32014-07-07 13:01:46 -0700826 pp_div = I915_READ(pp_div_reg);
827 pp_div &= PP_REFERENCE_DIVIDER_MASK;
828
829 /* 0x1F write to PP_DIV_REG sets max cycle delay */
830 I915_WRITE(pp_div_reg, pp_div | 0x1F);
831 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
832 msleep(intel_dp->panel_power_cycle_delay);
833 }
834
Ville Syrjälä773538e82014-09-04 14:54:56 +0300835 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300836
Clint Taylor01527b32014-07-07 13:01:46 -0700837 return 0;
838}
839
Daniel Vetter4be73782014-01-17 14:39:48 +0100840static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700841{
Paulo Zanoni30add222012-10-26 19:05:45 -0200842 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100843 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700844
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300845 lockdep_assert_held(&dev_priv->pps_mutex);
846
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100847 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300848 intel_dp->pps_pipe == INVALID_PIPE)
849 return false;
850
Jani Nikulabf13e812013-09-06 07:40:05 +0300851 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700852}
853
Daniel Vetter4be73782014-01-17 14:39:48 +0100854static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700855{
Paulo Zanoni30add222012-10-26 19:05:45 -0200856 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100857 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700858
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300859 lockdep_assert_held(&dev_priv->pps_mutex);
860
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100861 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300862 intel_dp->pps_pipe == INVALID_PIPE)
863 return false;
864
Ville Syrjälä773538e82014-09-04 14:54:56 +0300865 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700866}
867
Keith Packard9b984da2011-09-19 13:54:47 -0700868static void
869intel_dp_check_edp(struct intel_dp *intel_dp)
870{
Paulo Zanoni30add222012-10-26 19:05:45 -0200871 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100872 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700873
Keith Packard9b984da2011-09-19 13:54:47 -0700874 if (!is_edp(intel_dp))
875 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700876
Daniel Vetter4be73782014-01-17 14:39:48 +0100877 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700878 WARN(1, "eDP powered off while attempting aux channel communication.\n");
879 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300880 I915_READ(_pp_stat_reg(intel_dp)),
881 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700882 }
883}
884
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100885static uint32_t
886intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
887{
888 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
889 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100890 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200891 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100892 uint32_t status;
893 bool done;
894
Daniel Vetteref04f002012-12-01 21:03:59 +0100895#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100896 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300897 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300898 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100899 else
Imre Deak713a6b662016-06-28 13:37:33 +0300900 done = wait_for(C, 10) == 0;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100901 if (!done)
902 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
903 has_aux_irq);
904#undef C
905
906 return status;
907}
908
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200909static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000910{
911 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200912 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000913
Ville Syrjäläa457f542016-03-02 17:22:17 +0200914 if (index)
915 return 0;
916
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000917 /*
918 * The clock divider is based off the hrawclk, and would like to run at
Ville Syrjäläa457f542016-03-02 17:22:17 +0200919 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000920 */
Ville Syrjäläa457f542016-03-02 17:22:17 +0200921 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000922}
923
924static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
925{
926 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200927 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000928
929 if (index)
930 return 0;
931
Ville Syrjäläa457f542016-03-02 17:22:17 +0200932 /*
933 * The clock divider is based off the cdclk or PCH rawclk, and would
934 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
935 * divide by 2000 and use that
936 */
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200937 if (intel_dig_port->port == PORT_A)
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200938 return DIV_ROUND_CLOSEST(dev_priv->cdclk.hw.cdclk, 2000);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200939 else
940 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000941}
942
943static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300944{
945 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200946 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300947
Ville Syrjäläa457f542016-03-02 17:22:17 +0200948 if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300949 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100950 switch (index) {
951 case 0: return 63;
952 case 1: return 72;
953 default: return 0;
954 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300955 }
Ville Syrjäläa457f542016-03-02 17:22:17 +0200956
957 return ilk_get_aux_clock_divider(intel_dp, index);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300958}
959
Damien Lespiaub6b5e382014-01-20 16:00:59 +0000960static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
961{
962 /*
963 * SKL doesn't need us to program the AUX clock divider (Hardware will
964 * derive the clock from CDCLK automatically). We still implement the
965 * get_aux_clock_divider vfunc to plug-in into the existing code.
966 */
967 return index ? 0 : 1;
968}
969
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200970static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
971 bool has_aux_irq,
972 int send_bytes,
973 uint32_t aux_clock_divider)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000974{
975 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100976 struct drm_i915_private *dev_priv =
977 to_i915(intel_dig_port->base.base.dev);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000978 uint32_t precharge, timeout;
979
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100980 if (IS_GEN6(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000981 precharge = 3;
982 else
983 precharge = 5;
984
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100985 if (IS_BROADWELL(dev_priv) && intel_dig_port->port == PORT_A)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000986 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
987 else
988 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
989
990 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +0000991 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000992 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000993 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000994 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +0000995 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000996 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
997 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000998 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000999}
1000
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00001001static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
1002 bool has_aux_irq,
1003 int send_bytes,
1004 uint32_t unused)
1005{
1006 return DP_AUX_CH_CTL_SEND_BUSY |
1007 DP_AUX_CH_CTL_DONE |
1008 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
1009 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1010 DP_AUX_CH_CTL_TIME_OUT_1600us |
1011 DP_AUX_CH_CTL_RECEIVE_ERROR |
1012 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Daniel Vetterd4dcbdc2016-05-18 18:47:15 +02001013 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00001014 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
1015}
1016
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001017static int
Chris Wilsonea5b2132010-08-04 13:50:23 +01001018intel_dp_aux_ch(struct intel_dp *intel_dp,
Daniel Vetterbd9f74a2014-10-02 09:45:35 +02001019 const uint8_t *send, int send_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001020 uint8_t *recv, int recv_size)
1021{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001022 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001023 struct drm_i915_private *dev_priv =
1024 to_i915(intel_dig_port->base.base.dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001025 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Chris Wilsonbc866252013-07-21 16:00:03 +01001026 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001027 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001028 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001029 int try, clock = 0;
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001030 bool has_aux_irq = HAS_AUX_IRQ(dev_priv);
Jani Nikula884f19e2014-03-14 16:51:14 +02001031 bool vdd;
1032
Ville Syrjälä773538e82014-09-04 14:54:56 +03001033 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001034
Ville Syrjälä72c35002014-08-18 22:16:00 +03001035 /*
1036 * We will be called with VDD already enabled for dpcd/edid/oui reads.
1037 * In such cases we want to leave VDD enabled and it's up to upper layers
1038 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
1039 * ourselves.
1040 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001041 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001042
1043 /* dp aux is extremely sensitive to irq latency, hence request the
1044 * lowest possible wakeup latency and so prevent the cpu from going into
1045 * deep sleep states.
1046 */
1047 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001048
Keith Packard9b984da2011-09-19 13:54:47 -07001049 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001050
Jesse Barnes11bee432011-08-01 15:02:20 -07001051 /* Try to wait for any previous AUX channel activity */
1052 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +01001053 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -07001054 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
1055 break;
1056 msleep(1);
1057 }
1058
1059 if (try == 3) {
Mika Kuoppala02196c72015-08-06 16:48:58 +03001060 static u32 last_status = -1;
1061 const u32 status = I915_READ(ch_ctl);
1062
1063 if (status != last_status) {
1064 WARN(1, "dp_aux_ch not started status 0x%08x\n",
1065 status);
1066 last_status = status;
1067 }
1068
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001069 ret = -EBUSY;
1070 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001071 }
1072
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001073 /* Only 5 data registers! */
1074 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
1075 ret = -E2BIG;
1076 goto out;
1077 }
1078
Damien Lespiauec5b01d2014-01-21 13:35:39 +00001079 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +00001080 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
1081 has_aux_irq,
1082 send_bytes,
1083 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001084
Chris Wilsonbc866252013-07-21 16:00:03 +01001085 /* Must try at least 3 times according to DP spec */
1086 for (try = 0; try < 5; try++) {
1087 /* Load the send data into the aux channel data registers */
1088 for (i = 0; i < send_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001089 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001090 intel_dp_pack_aux(send + i,
1091 send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -04001092
Chris Wilsonbc866252013-07-21 16:00:03 +01001093 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001094 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001095
Chris Wilsonbc866252013-07-21 16:00:03 +01001096 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -04001097
Chris Wilsonbc866252013-07-21 16:00:03 +01001098 /* Clear done status and any errors */
1099 I915_WRITE(ch_ctl,
1100 status |
1101 DP_AUX_CH_CTL_DONE |
1102 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1103 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -04001104
Todd Previte74ebf292015-04-15 08:38:41 -07001105 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
Chris Wilsonbc866252013-07-21 16:00:03 +01001106 continue;
Todd Previte74ebf292015-04-15 08:38:41 -07001107
1108 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
1109 * 400us delay required for errors and timeouts
1110 * Timeout errors from the HW already meet this
1111 * requirement so skip to next iteration
1112 */
1113 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1114 usleep_range(400, 500);
1115 continue;
1116 }
Chris Wilsonbc866252013-07-21 16:00:03 +01001117 if (status & DP_AUX_CH_CTL_DONE)
Jim Bridee058c942015-05-27 10:21:48 -07001118 goto done;
Chris Wilsonbc866252013-07-21 16:00:03 +01001119 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001120 }
1121
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001122 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001123 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001124 ret = -EBUSY;
1125 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001126 }
1127
Jim Bridee058c942015-05-27 10:21:48 -07001128done:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001129 /* Check for timeout or receive error.
1130 * Timeouts occur when the sink is not connected
1131 */
Keith Packarda5b3da52009-06-11 22:30:32 -07001132 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001133 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001134 ret = -EIO;
1135 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -07001136 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001137
1138 /* Timeouts occur when the device isn't connected, so they're
1139 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -07001140 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Chris Wilsona5570fe2017-02-23 11:51:02 +00001141 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001142 ret = -ETIMEDOUT;
1143 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001144 }
1145
1146 /* Unload any bytes sent back from the other side */
1147 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
1148 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Rodrigo Vivi14e01882015-12-10 11:12:27 -08001149
1150 /*
1151 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1152 * We have no idea of what happened so we return -EBUSY so
1153 * drm layer takes care for the necessary retries.
1154 */
1155 if (recv_bytes == 0 || recv_bytes > 20) {
1156 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1157 recv_bytes);
1158 /*
1159 * FIXME: This patch was created on top of a series that
1160 * organize the retries at drm level. There EBUSY should
1161 * also take care for 1ms wait before retrying.
1162 * That aux retries re-org is still needed and after that is
1163 * merged we remove this sleep from here.
1164 */
1165 usleep_range(1000, 1500);
1166 ret = -EBUSY;
1167 goto out;
1168 }
1169
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001170 if (recv_bytes > recv_size)
1171 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -04001172
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001173 for (i = 0; i < recv_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001174 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001175 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001176
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001177 ret = recv_bytes;
1178out:
1179 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1180
Jani Nikula884f19e2014-03-14 16:51:14 +02001181 if (vdd)
1182 edp_panel_vdd_off(intel_dp, false);
1183
Ville Syrjälä773538e82014-09-04 14:54:56 +03001184 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001185
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001186 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001187}
1188
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001189#define BARE_ADDRESS_SIZE 3
1190#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +02001191static ssize_t
1192intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001193{
Jani Nikula9d1a1032014-03-14 16:51:15 +02001194 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1195 uint8_t txbuf[20], rxbuf[20];
1196 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001197 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001198
Ville Syrjäläd2d9cbb2015-03-19 11:44:06 +02001199 txbuf[0] = (msg->request << 4) |
1200 ((msg->address >> 16) & 0xf);
1201 txbuf[1] = (msg->address >> 8) & 0xff;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001202 txbuf[2] = msg->address & 0xff;
1203 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001204
Jani Nikula9d1a1032014-03-14 16:51:15 +02001205 switch (msg->request & ~DP_AUX_I2C_MOT) {
1206 case DP_AUX_NATIVE_WRITE:
1207 case DP_AUX_I2C_WRITE:
Ville Syrjäläc1e741222015-08-27 17:23:27 +03001208 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001209 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001210 rxsize = 2; /* 0 or 1 data bytes */
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001211
Jani Nikula9d1a1032014-03-14 16:51:15 +02001212 if (WARN_ON(txsize > 20))
1213 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001214
Ville Syrjälädd788092016-07-28 17:55:04 +03001215 WARN_ON(!msg->buffer != !msg->size);
1216
Imre Deakd81a67c2016-01-29 14:52:26 +02001217 if (msg->buffer)
1218 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001219
Jani Nikula9d1a1032014-03-14 16:51:15 +02001220 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1221 if (ret > 0) {
1222 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001223
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001224 if (ret > 1) {
1225 /* Number of bytes written in a short write. */
1226 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1227 } else {
1228 /* Return payload size. */
1229 ret = msg->size;
1230 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001231 }
Jani Nikula9d1a1032014-03-14 16:51:15 +02001232 break;
1233
1234 case DP_AUX_NATIVE_READ:
1235 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001236 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001237 rxsize = msg->size + 1;
1238
1239 if (WARN_ON(rxsize > 20))
1240 return -E2BIG;
1241
1242 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1243 if (ret > 0) {
1244 msg->reply = rxbuf[0] >> 4;
1245 /*
1246 * Assume happy day, and copy the data. The caller is
1247 * expected to check msg->reply before touching it.
1248 *
1249 * Return payload size.
1250 */
1251 ret--;
1252 memcpy(msg->buffer, rxbuf + 1, ret);
1253 }
1254 break;
1255
1256 default:
1257 ret = -EINVAL;
1258 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001259 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001260
Jani Nikula9d1a1032014-03-14 16:51:15 +02001261 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001262}
1263
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001264static enum port intel_aux_port(struct drm_i915_private *dev_priv,
1265 enum port port)
1266{
1267 const struct ddi_vbt_port_info *info =
1268 &dev_priv->vbt.ddi_port_info[port];
1269 enum port aux_port;
1270
1271 if (!info->alternate_aux_channel) {
1272 DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
1273 port_name(port), port_name(port));
1274 return port;
1275 }
1276
1277 switch (info->alternate_aux_channel) {
1278 case DP_AUX_A:
1279 aux_port = PORT_A;
1280 break;
1281 case DP_AUX_B:
1282 aux_port = PORT_B;
1283 break;
1284 case DP_AUX_C:
1285 aux_port = PORT_C;
1286 break;
1287 case DP_AUX_D:
1288 aux_port = PORT_D;
1289 break;
1290 default:
1291 MISSING_CASE(info->alternate_aux_channel);
1292 aux_port = PORT_A;
1293 break;
1294 }
1295
1296 DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
1297 port_name(aux_port), port_name(port));
1298
1299 return aux_port;
1300}
1301
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001302static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001303 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001304{
1305 switch (port) {
1306 case PORT_B:
1307 case PORT_C:
1308 case PORT_D:
1309 return DP_AUX_CH_CTL(port);
1310 default:
1311 MISSING_CASE(port);
1312 return DP_AUX_CH_CTL(PORT_B);
1313 }
1314}
1315
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001316static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001317 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001318{
1319 switch (port) {
1320 case PORT_B:
1321 case PORT_C:
1322 case PORT_D:
1323 return DP_AUX_CH_DATA(port, index);
1324 default:
1325 MISSING_CASE(port);
1326 return DP_AUX_CH_DATA(PORT_B, index);
1327 }
1328}
1329
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001330static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001331 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001332{
1333 switch (port) {
1334 case PORT_A:
1335 return DP_AUX_CH_CTL(port);
1336 case PORT_B:
1337 case PORT_C:
1338 case PORT_D:
1339 return PCH_DP_AUX_CH_CTL(port);
1340 default:
1341 MISSING_CASE(port);
1342 return DP_AUX_CH_CTL(PORT_A);
1343 }
1344}
1345
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001346static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001347 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001348{
1349 switch (port) {
1350 case PORT_A:
1351 return DP_AUX_CH_DATA(port, index);
1352 case PORT_B:
1353 case PORT_C:
1354 case PORT_D:
1355 return PCH_DP_AUX_CH_DATA(port, index);
1356 default:
1357 MISSING_CASE(port);
1358 return DP_AUX_CH_DATA(PORT_A, index);
1359 }
1360}
1361
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001362static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001363 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001364{
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001365 switch (port) {
1366 case PORT_A:
1367 case PORT_B:
1368 case PORT_C:
1369 case PORT_D:
1370 return DP_AUX_CH_CTL(port);
1371 default:
1372 MISSING_CASE(port);
1373 return DP_AUX_CH_CTL(PORT_A);
1374 }
1375}
1376
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001377static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001378 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001379{
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001380 switch (port) {
1381 case PORT_A:
1382 case PORT_B:
1383 case PORT_C:
1384 case PORT_D:
1385 return DP_AUX_CH_DATA(port, index);
1386 default:
1387 MISSING_CASE(port);
1388 return DP_AUX_CH_DATA(PORT_A, index);
1389 }
1390}
1391
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001392static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001393 enum port port)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001394{
1395 if (INTEL_INFO(dev_priv)->gen >= 9)
1396 return skl_aux_ctl_reg(dev_priv, port);
1397 else if (HAS_PCH_SPLIT(dev_priv))
1398 return ilk_aux_ctl_reg(dev_priv, port);
1399 else
1400 return g4x_aux_ctl_reg(dev_priv, port);
1401}
1402
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001403static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001404 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001405{
1406 if (INTEL_INFO(dev_priv)->gen >= 9)
1407 return skl_aux_data_reg(dev_priv, port, index);
1408 else if (HAS_PCH_SPLIT(dev_priv))
1409 return ilk_aux_data_reg(dev_priv, port, index);
1410 else
1411 return g4x_aux_data_reg(dev_priv, port, index);
1412}
1413
1414static void intel_aux_reg_init(struct intel_dp *intel_dp)
1415{
1416 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001417 enum port port = intel_aux_port(dev_priv,
1418 dp_to_dig_port(intel_dp)->port);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001419 int i;
1420
1421 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1422 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1423 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1424}
1425
Jani Nikula9d1a1032014-03-14 16:51:15 +02001426static void
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001427intel_dp_aux_fini(struct intel_dp *intel_dp)
1428{
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001429 kfree(intel_dp->aux.name);
1430}
1431
Chris Wilson7a418e32016-06-24 14:00:14 +01001432static void
Mika Kaholab6339582016-09-09 14:10:52 +03001433intel_dp_aux_init(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001434{
Jani Nikula33ad6622014-03-14 16:51:16 +02001435 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1436 enum port port = intel_dig_port->port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001437
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001438 intel_aux_reg_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01001439 drm_dp_aux_init(&intel_dp->aux);
David Flynn8316f332010-12-08 16:10:21 +00001440
Chris Wilson7a418e32016-06-24 14:00:14 +01001441 /* Failure to allocate our preferred name is not critical */
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001442 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
Jani Nikula9d1a1032014-03-14 16:51:15 +02001443 intel_dp->aux.transfer = intel_dp_aux_transfer;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001444}
1445
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001446bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301447{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001448 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Navare, Manasi D577c5432016-09-27 16:36:53 -07001449 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001450
Navare, Manasi D577c5432016-09-27 16:36:53 -07001451 if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
1452 IS_BROADWELL(dev_priv) || (INTEL_GEN(dev_priv) >= 9))
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301453 return true;
1454 else
1455 return false;
1456}
1457
Daniel Vetter0e503382014-07-04 11:26:04 -03001458static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001459intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001460 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001461{
1462 struct drm_device *dev = encoder->base.dev;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001463 struct drm_i915_private *dev_priv = to_i915(dev);
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001464 const struct dp_link_dpll *divisor = NULL;
1465 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001466
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001467 if (IS_G4X(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001468 divisor = gen4_dpll;
1469 count = ARRAY_SIZE(gen4_dpll);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001470 } else if (HAS_PCH_SPLIT(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001471 divisor = pch_dpll;
1472 count = ARRAY_SIZE(pch_dpll);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001473 } else if (IS_CHERRYVIEW(dev_priv)) {
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001474 divisor = chv_dpll;
1475 count = ARRAY_SIZE(chv_dpll);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001476 } else if (IS_VALLEYVIEW(dev_priv)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001477 divisor = vlv_dpll;
1478 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001479 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001480
1481 if (divisor && count) {
1482 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001483 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001484 pipe_config->dpll = divisor[i].dpll;
1485 pipe_config->clock_set = true;
1486 break;
1487 }
1488 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001489 }
1490}
1491
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001492static void snprintf_int_array(char *str, size_t len,
1493 const int *array, int nelem)
1494{
1495 int i;
1496
1497 str[0] = '\0';
1498
1499 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001500 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001501 if (r >= len)
1502 return;
1503 str += r;
1504 len -= r;
1505 }
1506}
1507
1508static void intel_dp_print_rates(struct intel_dp *intel_dp)
1509{
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001510 char str[128]; /* FIXME: too big for stack? */
1511
1512 if ((drm_debug & DRM_UT_KMS) == 0)
1513 return;
1514
Jani Nikula55cfc582017-03-28 17:59:04 +03001515 snprintf_int_array(str, sizeof(str),
1516 intel_dp->source_rates, intel_dp->num_source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001517 DRM_DEBUG_KMS("source rates: %s\n", str);
1518
Jani Nikula68f357c2017-03-28 17:59:05 +03001519 snprintf_int_array(str, sizeof(str),
1520 intel_dp->sink_rates, intel_dp->num_sink_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001521 DRM_DEBUG_KMS("sink rates: %s\n", str);
1522
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001523 snprintf_int_array(str, sizeof(str),
1524 intel_dp->common_rates, intel_dp->num_common_rates);
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001525 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001526}
1527
Imre Deak489375c2016-10-24 19:33:31 +03001528bool
Imre Deak7b3fc172016-10-25 16:12:39 +03001529__intel_dp_read_desc(struct intel_dp *intel_dp, struct intel_dp_desc *desc)
Mika Kahola0e390a32016-09-09 14:10:53 +03001530{
Imre Deak7b3fc172016-10-25 16:12:39 +03001531 u32 base = drm_dp_is_branch(intel_dp->dpcd) ? DP_BRANCH_OUI :
1532 DP_SINK_OUI;
Mika Kahola0e390a32016-09-09 14:10:53 +03001533
Imre Deak7b3fc172016-10-25 16:12:39 +03001534 return drm_dp_dpcd_read(&intel_dp->aux, base, desc, sizeof(*desc)) ==
1535 sizeof(*desc);
Mika Kahola0e390a32016-09-09 14:10:53 +03001536}
1537
Imre Deak12a47a422016-10-24 19:33:29 +03001538bool intel_dp_read_desc(struct intel_dp *intel_dp)
Mika Kahola1a2724f2016-09-09 14:10:54 +03001539{
Imre Deak7b3fc172016-10-25 16:12:39 +03001540 struct intel_dp_desc *desc = &intel_dp->desc;
1541 bool oui_sup = intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] &
1542 DP_OUI_SUPPORT;
1543 int dev_id_len;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001544
Imre Deak7b3fc172016-10-25 16:12:39 +03001545 if (!__intel_dp_read_desc(intel_dp, desc))
1546 return false;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001547
Imre Deak7b3fc172016-10-25 16:12:39 +03001548 dev_id_len = strnlen(desc->device_id, sizeof(desc->device_id));
1549 DRM_DEBUG_KMS("DP %s: OUI %*phD%s dev-ID %*pE HW-rev %d.%d SW-rev %d.%d\n",
1550 drm_dp_is_branch(intel_dp->dpcd) ? "branch" : "sink",
1551 (int)sizeof(desc->oui), desc->oui, oui_sup ? "" : "(NS)",
1552 dev_id_len, desc->device_id,
1553 desc->hw_rev >> 4, desc->hw_rev & 0xf,
1554 desc->sw_major_rev, desc->sw_minor_rev);
Mika Kahola1a2724f2016-09-09 14:10:54 +03001555
Imre Deak7b3fc172016-10-25 16:12:39 +03001556 return true;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001557}
1558
Ville Syrjälä50fec212015-03-12 17:10:34 +02001559int
1560intel_dp_max_link_rate(struct intel_dp *intel_dp)
1561{
Ville Syrjälä50fec212015-03-12 17:10:34 +02001562 int len;
1563
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001564 len = intel_dp_common_len_rate_limit(intel_dp,
1565 intel_dp->max_sink_link_rate);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001566 if (WARN_ON(len <= 0))
1567 return 162000;
1568
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001569 return intel_dp->common_rates[len - 1];
Ville Syrjälä50fec212015-03-12 17:10:34 +02001570}
1571
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001572int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1573{
Jani Nikula8001b752017-03-28 17:59:03 +03001574 int i = intel_dp_rate_index(intel_dp->sink_rates,
1575 intel_dp->num_sink_rates, rate);
Jani Nikulab5c72b22017-03-28 17:59:02 +03001576
1577 if (WARN_ON(i < 0))
1578 i = 0;
1579
1580 return i;
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001581}
1582
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001583void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1584 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001585{
Jani Nikula68f357c2017-03-28 17:59:05 +03001586 /* eDP 1.4 rate select method. */
1587 if (intel_dp->use_rate_select) {
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001588 *link_bw = 0;
1589 *rate_select =
1590 intel_dp_rate_select(intel_dp, port_clock);
1591 } else {
1592 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1593 *rate_select = 0;
1594 }
1595}
1596
Jani Nikulaf580bea2016-09-15 16:28:52 +03001597static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1598 struct intel_crtc_state *pipe_config)
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001599{
1600 int bpp, bpc;
1601
1602 bpp = pipe_config->pipe_bpp;
1603 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1604
1605 if (bpc > 0)
1606 bpp = min(bpp, 3*bpc);
1607
Manasi Navare611032b2017-01-24 08:21:49 -08001608 /* For DP Compliance we override the computed bpp for the pipe */
1609 if (intel_dp->compliance.test_data.bpc != 0) {
1610 pipe_config->pipe_bpp = 3*intel_dp->compliance.test_data.bpc;
1611 pipe_config->dither_force_disable = pipe_config->pipe_bpp == 6*3;
1612 DRM_DEBUG_KMS("Setting pipe_bpp to %d\n",
1613 pipe_config->pipe_bpp);
1614 }
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001615 return bpp;
1616}
1617
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001618bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001619intel_dp_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001620 struct intel_crtc_state *pipe_config,
1621 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001622{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001623 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001624 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001625 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001626 enum port port = dp_to_dig_port(intel_dp)->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001627 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001628 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001629 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001630 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001631 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001632 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001633 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301634 int max_clock;
Manasi Navareda15f7c2017-01-24 08:16:34 -08001635 int link_rate_index;
Daniel Vetter083f9562012-04-20 20:23:49 +02001636 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001637 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001638 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001639 uint8_t link_bw, rate_select;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301640
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001641 common_len = intel_dp_common_len_rate_limit(intel_dp,
1642 intel_dp->max_sink_link_rate);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301643
1644 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001645 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301646
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001647 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001648
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001649 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001650 pipe_config->has_pch_encoder = true;
1651
Vandana Kannanf769cd22014-08-05 07:51:22 -07001652 pipe_config->has_drrs = false;
Jani Nikula9fcb1702015-05-05 16:32:12 +03001653 pipe_config->has_audio = intel_dp->has_audio && port != PORT_A;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001654
Jani Nikuladd06f902012-10-19 14:51:50 +03001655 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1656 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
1657 adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001658
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001659 if (INTEL_GEN(dev_priv) >= 9) {
Chandra Kondurua1b22782015-04-07 15:28:45 -07001660 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001661 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001662 if (ret)
1663 return ret;
1664 }
1665
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001666 if (HAS_GMCH_DISPLAY(dev_priv))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001667 intel_gmch_panel_fitting(intel_crtc, pipe_config,
1668 intel_connector->panel.fitting_mode);
1669 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001670 intel_pch_panel_fitting(intel_crtc, pipe_config,
1671 intel_connector->panel.fitting_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001672 }
1673
Daniel Vettercb1793c2012-06-04 18:39:21 +02001674 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001675 return false;
1676
Manasi Navareda15f7c2017-01-24 08:16:34 -08001677 /* Use values requested by Compliance Test Request */
1678 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
Jani Nikulab1810a72017-04-06 16:44:11 +03001679 link_rate_index = intel_dp_rate_index(intel_dp->common_rates,
1680 intel_dp->num_common_rates,
1681 intel_dp->compliance.test_link_rate);
Manasi Navareda15f7c2017-01-24 08:16:34 -08001682 if (link_rate_index >= 0)
1683 min_clock = max_clock = link_rate_index;
1684 min_lane_count = max_lane_count = intel_dp->compliance.test_lane_count;
1685 }
Daniel Vetter083f9562012-04-20 20:23:49 +02001686 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301687 "max bw %d pixel clock %iKHz\n",
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001688 max_lane_count, intel_dp->common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001689 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001690
Daniel Vetter36008362013-03-27 00:44:59 +01001691 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1692 * bpc in between. */
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001693 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
Jani Nikula56071a22014-05-06 14:56:52 +03001694 if (is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301695
1696 /* Get bpp from vbt only for panels that dont have bpp in edid */
1697 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001698 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001699 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001700 dev_priv->vbt.edp.bpp);
1701 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001702 }
1703
Jani Nikula344c5bb2014-09-09 11:25:13 +03001704 /*
1705 * Use the maximum clock and number of lanes the eDP panel
1706 * advertizes being capable of. The panels are generally
1707 * designed to support only a single clock and lane
1708 * configuration, and typically these values correspond to the
1709 * native resolution of the panel.
1710 */
1711 min_lane_count = max_lane_count;
1712 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001713 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001714
Daniel Vetter36008362013-03-27 00:44:59 +01001715 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001716 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1717 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001718
Dave Airliec6930992014-07-14 11:04:39 +10001719 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301720 for (lane_count = min_lane_count;
1721 lane_count <= max_lane_count;
1722 lane_count <<= 1) {
1723
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001724 link_clock = intel_dp->common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001725 link_avail = intel_dp_max_data_rate(link_clock,
1726 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001727
Daniel Vetter36008362013-03-27 00:44:59 +01001728 if (mode_rate <= link_avail) {
1729 goto found;
1730 }
1731 }
1732 }
1733 }
1734
1735 return false;
1736
1737found:
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001738 if (intel_dp->color_range_auto) {
1739 /*
1740 * See:
1741 * CEA-861-E - 5.1 Default Encoding Parameters
1742 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1743 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001744 pipe_config->limited_color_range =
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02001745 bpp != 18 &&
1746 drm_default_rgb_quant_range(adjusted_mode) ==
1747 HDMI_QUANTIZATION_RANGE_LIMITED;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001748 } else {
1749 pipe_config->limited_color_range =
1750 intel_dp->limited_color_range;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001751 }
1752
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001753 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301754
Daniel Vetter657445f2013-05-04 10:09:18 +02001755 pipe_config->pipe_bpp = bpp;
Jani Nikula975ee5fca2017-04-06 16:44:10 +03001756 pipe_config->port_clock = intel_dp->common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001757
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001758 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1759 &link_bw, &rate_select);
1760
1761 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1762 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001763 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001764 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1765 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001766
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001767 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001768 adjusted_mode->crtc_clock,
1769 pipe_config->port_clock,
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001770 &pipe_config->dp_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001771
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301772 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301773 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001774 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301775 intel_link_compute_m_n(bpp, lane_count,
1776 intel_connector->panel.downclock_mode->clock,
1777 pipe_config->port_clock,
1778 &pipe_config->dp_m2_n2);
1779 }
1780
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001781 /*
1782 * DPLL0 VCO may need to be adjusted to get the correct
1783 * clock for eDP. This will affect cdclk as well.
1784 */
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001785 if (is_edp(intel_dp) && IS_GEN9_BC(dev_priv)) {
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001786 int vco;
1787
1788 switch (pipe_config->port_clock / 2) {
1789 case 108000:
1790 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001791 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001792 break;
1793 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001794 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001795 break;
1796 }
1797
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +02001798 to_intel_atomic_state(pipe_config->base.state)->cdclk.logical.vco = vco;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001799 }
1800
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001801 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001802 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001803
Daniel Vetter36008362013-03-27 00:44:59 +01001804 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001805}
1806
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001807void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001808 int link_rate, uint8_t lane_count,
1809 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001810{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001811 intel_dp->link_rate = link_rate;
1812 intel_dp->lane_count = lane_count;
1813 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001814}
1815
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001816static void intel_dp_prepare(struct intel_encoder *encoder,
1817 struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001818{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001819 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001820 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001821 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001822 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001823 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001824 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001825
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001826 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1827 pipe_config->lane_count,
1828 intel_crtc_has_type(pipe_config,
1829 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001830
Keith Packard417e8222011-11-01 19:54:11 -07001831 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001832 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001833 *
1834 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001835 * SNB CPU
1836 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001837 * CPT PCH
1838 *
1839 * IBX PCH and CPU are the same for almost everything,
1840 * except that the CPU DP PLL is configured in this
1841 * register
1842 *
1843 * CPT PCH is quite different, having many bits moved
1844 * to the TRANS_DP_CTL register instead. That
1845 * configuration happens (oddly) in ironlake_pch_enable
1846 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001847
Keith Packard417e8222011-11-01 19:54:11 -07001848 /* Preserve the BIOS-computed detected bit. This is
1849 * supposed to be read-only.
1850 */
1851 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001852
Keith Packard417e8222011-11-01 19:54:11 -07001853 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001854 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001855 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001856
Keith Packard417e8222011-11-01 19:54:11 -07001857 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001858
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001859 if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001860 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1861 intel_dp->DP |= DP_SYNC_HS_HIGH;
1862 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1863 intel_dp->DP |= DP_SYNC_VS_HIGH;
1864 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1865
Jani Nikula6aba5b62013-10-04 15:08:10 +03001866 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001867 intel_dp->DP |= DP_ENHANCED_FRAMING;
1868
Daniel Vetter7c62a162013-06-01 17:16:20 +02001869 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001870 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001871 u32 trans_dp;
1872
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001873 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001874
1875 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1876 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1877 trans_dp |= TRANS_DP_ENH_FRAMING;
1878 else
1879 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1880 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001881 } else {
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02001882 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001883 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001884
1885 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1886 intel_dp->DP |= DP_SYNC_HS_HIGH;
1887 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1888 intel_dp->DP |= DP_SYNC_VS_HIGH;
1889 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1890
Jani Nikula6aba5b62013-10-04 15:08:10 +03001891 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001892 intel_dp->DP |= DP_ENHANCED_FRAMING;
1893
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001894 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001895 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001896 else if (crtc->pipe == PIPE_B)
1897 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001898 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001899}
1900
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001901#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1902#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001903
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001904#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1905#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001906
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001907#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1908#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001909
Imre Deakde9c1b62016-06-16 20:01:46 +03001910static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
1911 struct intel_dp *intel_dp);
1912
Daniel Vetter4be73782014-01-17 14:39:48 +01001913static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001914 u32 mask,
1915 u32 value)
1916{
Paulo Zanoni30add222012-10-26 19:05:45 -02001917 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001918 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001919 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001920
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001921 lockdep_assert_held(&dev_priv->pps_mutex);
1922
Imre Deakde9c1b62016-06-16 20:01:46 +03001923 intel_pps_verify_state(dev_priv, intel_dp);
1924
Jani Nikulabf13e812013-09-06 07:40:05 +03001925 pp_stat_reg = _pp_stat_reg(intel_dp);
1926 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001927
1928 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001929 mask, value,
1930 I915_READ(pp_stat_reg),
1931 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001932
Chris Wilson9036ff02016-06-30 15:33:09 +01001933 if (intel_wait_for_register(dev_priv,
1934 pp_stat_reg, mask, value,
1935 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001936 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001937 I915_READ(pp_stat_reg),
1938 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001939
1940 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001941}
1942
Daniel Vetter4be73782014-01-17 14:39:48 +01001943static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001944{
1945 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001946 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001947}
1948
Daniel Vetter4be73782014-01-17 14:39:48 +01001949static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001950{
Keith Packardbd943152011-09-18 23:09:52 -07001951 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001952 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001953}
Keith Packardbd943152011-09-18 23:09:52 -07001954
Daniel Vetter4be73782014-01-17 14:39:48 +01001955static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001956{
Abhay Kumard28d4732016-01-22 17:39:04 -08001957 ktime_t panel_power_on_time;
1958 s64 panel_power_off_duration;
1959
Keith Packard99ea7122011-11-01 19:57:50 -07001960 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001961
Abhay Kumard28d4732016-01-22 17:39:04 -08001962 /* take the difference of currrent time and panel power off time
1963 * and then make panel wait for t11_t12 if needed. */
1964 panel_power_on_time = ktime_get_boottime();
1965 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1966
Paulo Zanonidce56b32013-12-19 14:29:40 -02001967 /* When we disable the VDD override bit last we have to do the manual
1968 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08001969 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
1970 wait_remaining_ms_from_jiffies(jiffies,
1971 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001972
Daniel Vetter4be73782014-01-17 14:39:48 +01001973 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001974}
Keith Packardbd943152011-09-18 23:09:52 -07001975
Daniel Vetter4be73782014-01-17 14:39:48 +01001976static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001977{
1978 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1979 intel_dp->backlight_on_delay);
1980}
1981
Daniel Vetter4be73782014-01-17 14:39:48 +01001982static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001983{
1984 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
1985 intel_dp->backlight_off_delay);
1986}
Keith Packard99ea7122011-11-01 19:57:50 -07001987
Keith Packard832dd3c2011-11-01 19:34:06 -07001988/* Read the current pp_control value, unlocking the register if it
1989 * is locked
1990 */
1991
Jesse Barnes453c5422013-03-28 09:55:41 -07001992static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07001993{
Jesse Barnes453c5422013-03-28 09:55:41 -07001994 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001995 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07001996 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07001997
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001998 lockdep_assert_held(&dev_priv->pps_mutex);
1999
Jani Nikulabf13e812013-09-06 07:40:05 +03002000 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03002001 if (WARN_ON(!HAS_DDI(dev_priv) &&
2002 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05302003 control &= ~PANEL_UNLOCK_MASK;
2004 control |= PANEL_UNLOCK_REGS;
2005 }
Keith Packard832dd3c2011-11-01 19:34:06 -07002006 return control;
Keith Packardbd943152011-09-18 23:09:52 -07002007}
2008
Ville Syrjälä951468f2014-09-04 14:55:31 +03002009/*
2010 * Must be paired with edp_panel_vdd_off().
2011 * Must hold pps_mutex around the whole on/off sequence.
2012 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2013 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03002014static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002015{
Paulo Zanoni30add222012-10-26 19:05:45 -02002016 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002017 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002018 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes5d613502011-01-24 17:10:54 -08002019 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002020 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002021 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08002022
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002023 lockdep_assert_held(&dev_priv->pps_mutex);
2024
Keith Packard97af61f572011-09-28 16:23:51 -07002025 if (!is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002026 return false;
Keith Packardbd943152011-09-18 23:09:52 -07002027
Egbert Eich2c623c12014-11-25 12:54:57 +01002028 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002029 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07002030
Daniel Vetter4be73782014-01-17 14:39:48 +01002031 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002032 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002033
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002034 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002035
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002036 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
2037 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07002038
Daniel Vetter4be73782014-01-17 14:39:48 +01002039 if (!edp_have_panel_power(intel_dp))
2040 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07002041
Jesse Barnes453c5422013-03-28 09:55:41 -07002042 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002043 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07002044
Jani Nikulabf13e812013-09-06 07:40:05 +03002045 pp_stat_reg = _pp_stat_reg(intel_dp);
2046 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002047
2048 I915_WRITE(pp_ctrl_reg, pp);
2049 POSTING_READ(pp_ctrl_reg);
2050 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2051 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07002052 /*
2053 * If the panel wasn't on, delay before accessing aux channel
2054 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002055 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002056 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
2057 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07002058 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07002059 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002060
2061 return need_to_disable;
2062}
2063
Ville Syrjälä951468f2014-09-04 14:55:31 +03002064/*
2065 * Must be paired with intel_edp_panel_vdd_off() or
2066 * intel_edp_panel_off().
2067 * Nested calls to these functions are not allowed since
2068 * we drop the lock. Caller must use some higher level
2069 * locking to prevent nested calls from other threads.
2070 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01002071void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002072{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002073 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002074
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002075 if (!is_edp(intel_dp))
2076 return;
2077
Ville Syrjälä773538e82014-09-04 14:54:56 +03002078 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002079 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002080 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002081
Rob Clarke2c719b2014-12-15 13:56:32 -05002082 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002083 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08002084}
2085
Daniel Vetter4be73782014-01-17 14:39:48 +01002086static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002087{
Paulo Zanoni30add222012-10-26 19:05:45 -02002088 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002089 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002090 struct intel_digital_port *intel_dig_port =
2091 dp_to_dig_port(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002092 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002093 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002094
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002095 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002096
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002097 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002098
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002099 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002100 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002101
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002102 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2103 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002104
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002105 pp = ironlake_get_pp_control(intel_dp);
2106 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002107
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002108 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2109 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002110
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002111 I915_WRITE(pp_ctrl_reg, pp);
2112 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002113
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002114 /* Make sure sequencer is idle before allowing subsequent activity */
2115 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2116 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002117
Imre Deak5a162e22016-08-10 14:07:30 +03002118 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002119 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002120
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002121 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002122}
2123
Daniel Vetter4be73782014-01-17 14:39:48 +01002124static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002125{
2126 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2127 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002128
Ville Syrjälä773538e82014-09-04 14:54:56 +03002129 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002130 if (!intel_dp->want_panel_vdd)
2131 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002132 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002133}
2134
Imre Deakaba86892014-07-30 15:57:31 +03002135static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2136{
2137 unsigned long delay;
2138
2139 /*
2140 * Queue the timer to fire a long time from now (relative to the power
2141 * down delay) to keep the panel power up across a sequence of
2142 * operations.
2143 */
2144 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2145 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2146}
2147
Ville Syrjälä951468f2014-09-04 14:55:31 +03002148/*
2149 * Must be paired with edp_panel_vdd_on().
2150 * Must hold pps_mutex around the whole on/off sequence.
2151 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2152 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002153static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002154{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002155 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002156
2157 lockdep_assert_held(&dev_priv->pps_mutex);
2158
Keith Packard97af61f572011-09-28 16:23:51 -07002159 if (!is_edp(intel_dp))
2160 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002161
Rob Clarke2c719b2014-12-15 13:56:32 -05002162 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002163 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002164
Keith Packardbd943152011-09-18 23:09:52 -07002165 intel_dp->want_panel_vdd = false;
2166
Imre Deakaba86892014-07-30 15:57:31 +03002167 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002168 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002169 else
2170 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002171}
2172
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002173static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002174{
Paulo Zanoni30add222012-10-26 19:05:45 -02002175 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002176 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002177 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002178 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002179
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002180 lockdep_assert_held(&dev_priv->pps_mutex);
2181
Keith Packard97af61f572011-09-28 16:23:51 -07002182 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002183 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002184
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002185 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2186 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002187
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002188 if (WARN(edp_have_panel_power(intel_dp),
2189 "eDP port %c panel power already on\n",
2190 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002191 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002192
Daniel Vetter4be73782014-01-17 14:39:48 +01002193 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002194
Jani Nikulabf13e812013-09-06 07:40:05 +03002195 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002196 pp = ironlake_get_pp_control(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002197 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002198 /* ILK workaround: disable reset around power sequence */
2199 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002200 I915_WRITE(pp_ctrl_reg, pp);
2201 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002202 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002203
Imre Deak5a162e22016-08-10 14:07:30 +03002204 pp |= PANEL_POWER_ON;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002205 if (!IS_GEN5(dev_priv))
Keith Packard99ea7122011-11-01 19:57:50 -07002206 pp |= PANEL_POWER_RESET;
2207
Jesse Barnes453c5422013-03-28 09:55:41 -07002208 I915_WRITE(pp_ctrl_reg, pp);
2209 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002210
Daniel Vetter4be73782014-01-17 14:39:48 +01002211 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002212 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002213
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002214 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002215 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002216 I915_WRITE(pp_ctrl_reg, pp);
2217 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002218 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002219}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002220
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002221void intel_edp_panel_on(struct intel_dp *intel_dp)
2222{
2223 if (!is_edp(intel_dp))
2224 return;
2225
2226 pps_lock(intel_dp);
2227 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002228 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002229}
2230
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002231
2232static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002233{
Paulo Zanoni30add222012-10-26 19:05:45 -02002234 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002235 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002236 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002237 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002238
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002239 lockdep_assert_held(&dev_priv->pps_mutex);
2240
Keith Packard97af61f572011-09-28 16:23:51 -07002241 if (!is_edp(intel_dp))
2242 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002243
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002244 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2245 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002246
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002247 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2248 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002249
Jesse Barnes453c5422013-03-28 09:55:41 -07002250 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002251 /* We need to switch off panel power _and_ force vdd, for otherwise some
2252 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002253 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002254 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002255
Jani Nikulabf13e812013-09-06 07:40:05 +03002256 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002257
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002258 intel_dp->want_panel_vdd = false;
2259
Jesse Barnes453c5422013-03-28 09:55:41 -07002260 I915_WRITE(pp_ctrl_reg, pp);
2261 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002262
Abhay Kumard28d4732016-01-22 17:39:04 -08002263 intel_dp->panel_power_off_time = ktime_get_boottime();
Daniel Vetter4be73782014-01-17 14:39:48 +01002264 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002265
2266 /* We got a reference when we enabled the VDD. */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002267 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002268}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002269
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002270void intel_edp_panel_off(struct intel_dp *intel_dp)
2271{
2272 if (!is_edp(intel_dp))
2273 return;
2274
2275 pps_lock(intel_dp);
2276 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002277 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002278}
2279
Jani Nikula1250d102014-08-12 17:11:39 +03002280/* Enable backlight in the panel power control. */
2281static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002282{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002283 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2284 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002285 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002286 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002287 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002288
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002289 /*
2290 * If we enable the backlight right away following a panel power
2291 * on, we may see slight flicker as the panel syncs with the eDP
2292 * link. So delay a bit to make sure the image is solid before
2293 * allowing it to appear.
2294 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002295 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002296
Ville Syrjälä773538e82014-09-04 14:54:56 +03002297 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002298
Jesse Barnes453c5422013-03-28 09:55:41 -07002299 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002300 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002301
Jani Nikulabf13e812013-09-06 07:40:05 +03002302 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002303
2304 I915_WRITE(pp_ctrl_reg, pp);
2305 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002306
Ville Syrjälä773538e82014-09-04 14:54:56 +03002307 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002308}
2309
Jani Nikula1250d102014-08-12 17:11:39 +03002310/* Enable backlight PWM and backlight PP control. */
2311void intel_edp_backlight_on(struct intel_dp *intel_dp)
2312{
2313 if (!is_edp(intel_dp))
2314 return;
2315
2316 DRM_DEBUG_KMS("\n");
2317
2318 intel_panel_enable_backlight(intel_dp->attached_connector);
2319 _intel_edp_backlight_on(intel_dp);
2320}
2321
2322/* Disable backlight in the panel power control. */
2323static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002324{
Paulo Zanoni30add222012-10-26 19:05:45 -02002325 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002326 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002327 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002328 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002329
Keith Packardf01eca22011-09-28 16:48:10 -07002330 if (!is_edp(intel_dp))
2331 return;
2332
Ville Syrjälä773538e82014-09-04 14:54:56 +03002333 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002334
Jesse Barnes453c5422013-03-28 09:55:41 -07002335 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002336 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002337
Jani Nikulabf13e812013-09-06 07:40:05 +03002338 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002339
2340 I915_WRITE(pp_ctrl_reg, pp);
2341 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002342
Ville Syrjälä773538e82014-09-04 14:54:56 +03002343 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002344
Paulo Zanonidce56b32013-12-19 14:29:40 -02002345 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002346 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002347}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002348
Jani Nikula1250d102014-08-12 17:11:39 +03002349/* Disable backlight PP control and backlight PWM. */
2350void intel_edp_backlight_off(struct intel_dp *intel_dp)
2351{
2352 if (!is_edp(intel_dp))
2353 return;
2354
2355 DRM_DEBUG_KMS("\n");
2356
2357 _intel_edp_backlight_off(intel_dp);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002358 intel_panel_disable_backlight(intel_dp->attached_connector);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002359}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002360
Jani Nikula73580fb72014-08-12 17:11:41 +03002361/*
2362 * Hook for controlling the panel power control backlight through the bl_power
2363 * sysfs attribute. Take care to handle multiple calls.
2364 */
2365static void intel_edp_backlight_power(struct intel_connector *connector,
2366 bool enable)
2367{
2368 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002369 bool is_enabled;
2370
Ville Syrjälä773538e82014-09-04 14:54:56 +03002371 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002372 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002373 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002374
2375 if (is_enabled == enable)
2376 return;
2377
Jani Nikula23ba9372014-08-27 14:08:43 +03002378 DRM_DEBUG_KMS("panel power control backlight %s\n",
2379 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002380
2381 if (enable)
2382 _intel_edp_backlight_on(intel_dp);
2383 else
2384 _intel_edp_backlight_off(intel_dp);
2385}
2386
Ville Syrjälä64e10772015-10-29 21:26:01 +02002387static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2388{
2389 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2390 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2391 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2392
2393 I915_STATE_WARN(cur_state != state,
2394 "DP port %c state assertion failure (expected %s, current %s)\n",
2395 port_name(dig_port->port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002396 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002397}
2398#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2399
2400static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2401{
2402 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2403
2404 I915_STATE_WARN(cur_state != state,
2405 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002406 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002407}
2408#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2409#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2410
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002411static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2412 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002413{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002414 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002415 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002416
Ville Syrjälä64e10772015-10-29 21:26:01 +02002417 assert_pipe_disabled(dev_priv, crtc->pipe);
2418 assert_dp_port_disabled(intel_dp);
2419 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002420
Ville Syrjäläabfce942015-10-29 21:26:03 +02002421 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002422 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002423
2424 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2425
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002426 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002427 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2428 else
2429 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2430
2431 I915_WRITE(DP_A, intel_dp->DP);
2432 POSTING_READ(DP_A);
2433 udelay(500);
2434
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002435 /*
2436 * [DevILK] Work around required when enabling DP PLL
2437 * while a pipe is enabled going to FDI:
2438 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2439 * 2. Program DP PLL enable
2440 */
2441 if (IS_GEN5(dev_priv))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02002442 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002443
Daniel Vetter07679352012-09-06 22:15:42 +02002444 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002445
Daniel Vetter07679352012-09-06 22:15:42 +02002446 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002447 POSTING_READ(DP_A);
2448 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002449}
2450
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002451static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002452{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002453 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002454 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2455 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002456
Ville Syrjälä64e10772015-10-29 21:26:01 +02002457 assert_pipe_disabled(dev_priv, crtc->pipe);
2458 assert_dp_port_disabled(intel_dp);
2459 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002460
Ville Syrjäläabfce942015-10-29 21:26:03 +02002461 DRM_DEBUG_KMS("disabling eDP PLL\n");
2462
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002463 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002464
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002465 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002466 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002467 udelay(200);
2468}
2469
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002470/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002471void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002472{
2473 int ret, i;
2474
2475 /* Should have a valid DPCD by this point */
2476 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2477 return;
2478
2479 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002480 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2481 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002482 } else {
Imre Deak357c0ae2016-11-21 21:15:06 +02002483 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
2484
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002485 /*
2486 * When turning on, we need to retry for 1ms to give the sink
2487 * time to wake up.
2488 */
2489 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002490 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2491 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002492 if (ret == 1)
2493 break;
2494 msleep(1);
2495 }
Imre Deak357c0ae2016-11-21 21:15:06 +02002496
2497 if (ret == 1 && lspcon->active)
2498 lspcon_wait_pcon_mode(lspcon);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002499 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002500
2501 if (ret != 1)
2502 DRM_DEBUG_KMS("failed to %s sink power state\n",
2503 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002504}
2505
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002506static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2507 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002508{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002509 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002510 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002511 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002512 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002513 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002514 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002515
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002516 if (!intel_display_power_get_if_enabled(dev_priv,
2517 encoder->power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002518 return false;
2519
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002520 ret = false;
2521
Imre Deak6d129be2014-03-05 16:20:54 +02002522 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002523
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002524 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002525 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002526
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002527 if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002528 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002529 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002530 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002531
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002532 for_each_pipe(dev_priv, p) {
2533 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2534 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2535 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002536 ret = true;
2537
2538 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002539 }
2540 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002541
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002542 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002543 i915_mmio_reg_offset(intel_dp->output_reg));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002544 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002545 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2546 } else {
2547 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002548 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002549
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002550 ret = true;
2551
2552out:
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002553 intel_display_power_put(dev_priv, encoder->power_domain);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002554
2555 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002556}
2557
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002558static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002559 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002560{
2561 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002562 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002563 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002564 struct drm_i915_private *dev_priv = to_i915(dev);
Xiong Zhang63000ef2013-06-28 12:59:06 +08002565 enum port port = dp_to_dig_port(intel_dp)->port;
2566 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002567
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002568 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002569
2570 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002571
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002572 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002573 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2574
2575 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002576 flags |= DRM_MODE_FLAG_PHSYNC;
2577 else
2578 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002579
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002580 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002581 flags |= DRM_MODE_FLAG_PVSYNC;
2582 else
2583 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002584 } else {
2585 if (tmp & DP_SYNC_HS_HIGH)
2586 flags |= DRM_MODE_FLAG_PHSYNC;
2587 else
2588 flags |= DRM_MODE_FLAG_NHSYNC;
2589
2590 if (tmp & DP_SYNC_VS_HIGH)
2591 flags |= DRM_MODE_FLAG_PVSYNC;
2592 else
2593 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002594 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002595
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002596 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002597
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02002598 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002599 pipe_config->limited_color_range = true;
2600
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002601 pipe_config->lane_count =
2602 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2603
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002604 intel_dp_get_m_n(crtc, pipe_config);
2605
Ville Syrjälä18442d02013-09-13 16:00:08 +03002606 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002607 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002608 pipe_config->port_clock = 162000;
2609 else
2610 pipe_config->port_clock = 270000;
2611 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002612
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002613 pipe_config->base.adjusted_mode.crtc_clock =
2614 intel_dotclock_calculate(pipe_config->port_clock,
2615 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002616
Jani Nikula6aa23e62016-03-24 17:50:20 +02002617 if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
2618 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002619 /*
2620 * This is a big fat ugly hack.
2621 *
2622 * Some machines in UEFI boot mode provide us a VBT that has 18
2623 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2624 * unknown we fail to light up. Yet the same BIOS boots up with
2625 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2626 * max, not what it tells us to use.
2627 *
2628 * Note: This will still be broken if the eDP panel is not lit
2629 * up by the BIOS, and thus we can't get the mode at module
2630 * load.
2631 */
2632 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002633 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2634 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002635 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002636}
2637
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002638static void intel_disable_dp(struct intel_encoder *encoder,
2639 struct intel_crtc_state *old_crtc_state,
2640 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002641{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002642 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002643 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002644
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002645 if (old_crtc_state->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002646 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002647
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002648 if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv))
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002649 intel_psr_disable(intel_dp);
2650
Daniel Vetter6cb49832012-05-20 17:14:50 +02002651 /* Make sure the panel is off before trying to change the mode. But also
2652 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002653 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01002654 intel_edp_backlight_off(intel_dp);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002655 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002656 intel_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02002657
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002658 /* disable the port before the pipe on g4x */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002659 if (INTEL_GEN(dev_priv) < 5)
Daniel Vetter37398502012-09-06 22:15:44 +02002660 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07002661}
2662
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002663static void ilk_post_disable_dp(struct intel_encoder *encoder,
2664 struct intel_crtc_state *old_crtc_state,
2665 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002666{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002667 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002668 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002669
Ville Syrjälä49277c32014-03-31 18:21:26 +03002670 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002671
2672 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002673 if (port == PORT_A)
2674 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002675}
2676
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002677static void vlv_post_disable_dp(struct intel_encoder *encoder,
2678 struct intel_crtc_state *old_crtc_state,
2679 struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002680{
2681 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2682
2683 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002684}
2685
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002686static void chv_post_disable_dp(struct intel_encoder *encoder,
2687 struct intel_crtc_state *old_crtc_state,
2688 struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002689{
2690 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002691 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002692 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002693
2694 intel_dp_link_down(intel_dp);
2695
Ville Syrjäläa5805162015-05-26 20:42:30 +03002696 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002697
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002698 /* Assert data lane reset */
2699 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002700
Ville Syrjäläa5805162015-05-26 20:42:30 +03002701 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002702}
2703
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002704static void
2705_intel_dp_set_link_train(struct intel_dp *intel_dp,
2706 uint32_t *DP,
2707 uint8_t dp_train_pat)
2708{
2709 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2710 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002711 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002712 enum port port = intel_dig_port->port;
2713
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002714 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2715 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2716 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2717
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002718 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002719 uint32_t temp = I915_READ(DP_TP_CTL(port));
2720
2721 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2722 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2723 else
2724 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2725
2726 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2727 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2728 case DP_TRAINING_PATTERN_DISABLE:
2729 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2730
2731 break;
2732 case DP_TRAINING_PATTERN_1:
2733 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2734 break;
2735 case DP_TRAINING_PATTERN_2:
2736 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2737 break;
2738 case DP_TRAINING_PATTERN_3:
2739 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2740 break;
2741 }
2742 I915_WRITE(DP_TP_CTL(port), temp);
2743
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002744 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002745 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002746 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2747
2748 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2749 case DP_TRAINING_PATTERN_DISABLE:
2750 *DP |= DP_LINK_TRAIN_OFF_CPT;
2751 break;
2752 case DP_TRAINING_PATTERN_1:
2753 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2754 break;
2755 case DP_TRAINING_PATTERN_2:
2756 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2757 break;
2758 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002759 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002760 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2761 break;
2762 }
2763
2764 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002765 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002766 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2767 else
2768 *DP &= ~DP_LINK_TRAIN_MASK;
2769
2770 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2771 case DP_TRAINING_PATTERN_DISABLE:
2772 *DP |= DP_LINK_TRAIN_OFF;
2773 break;
2774 case DP_TRAINING_PATTERN_1:
2775 *DP |= DP_LINK_TRAIN_PAT_1;
2776 break;
2777 case DP_TRAINING_PATTERN_2:
2778 *DP |= DP_LINK_TRAIN_PAT_2;
2779 break;
2780 case DP_TRAINING_PATTERN_3:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002781 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002782 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2783 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002784 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002785 *DP |= DP_LINK_TRAIN_PAT_2;
2786 }
2787 break;
2788 }
2789 }
2790}
2791
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002792static void intel_dp_enable_port(struct intel_dp *intel_dp,
2793 struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002794{
2795 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002796 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002797
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002798 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002799
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002800 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002801
2802 /*
2803 * Magic for VLV/CHV. We _must_ first set up the register
2804 * without actually enabling the port, and then do another
2805 * write to enable the port. Otherwise link training will
2806 * fail when the power sequencer is freshly used for this port.
2807 */
2808 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002809 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002810 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002811
2812 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2813 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002814}
2815
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002816static void intel_enable_dp(struct intel_encoder *encoder,
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002817 struct intel_crtc_state *pipe_config,
2818 struct drm_connector_state *conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002819{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002820 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2821 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002822 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulac1dec792014-10-27 16:26:56 +02002823 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002824 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002825 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002826
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002827 if (WARN_ON(dp_reg & DP_PORT_EN))
2828 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002829
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002830 pps_lock(intel_dp);
2831
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002832 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002833 vlv_init_panel_power_sequencer(intel_dp);
2834
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002835 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002836
2837 edp_panel_vdd_on(intel_dp);
2838 edp_panel_on(intel_dp);
2839 edp_panel_vdd_off(intel_dp, true);
2840
2841 pps_unlock(intel_dp);
2842
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002843 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002844 unsigned int lane_mask = 0x0;
2845
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002846 if (IS_CHERRYVIEW(dev_priv))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002847 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002848
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002849 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2850 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002851 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002852
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002853 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2854 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002855 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002856
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002857 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002858 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002859 pipe_name(pipe));
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002860 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Jani Nikulac1dec792014-10-27 16:26:56 +02002861 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002862}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002863
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002864static void g4x_enable_dp(struct intel_encoder *encoder,
2865 struct intel_crtc_state *pipe_config,
2866 struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03002867{
Jani Nikula828f5c62013-09-05 16:44:45 +03002868 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2869
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002870 intel_enable_dp(encoder, pipe_config, conn_state);
Daniel Vetter4be73782014-01-17 14:39:48 +01002871 intel_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002872}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002873
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002874static void vlv_enable_dp(struct intel_encoder *encoder,
2875 struct intel_crtc_state *pipe_config,
2876 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002877{
Jani Nikula828f5c62013-09-05 16:44:45 +03002878 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2879
Daniel Vetter4be73782014-01-17 14:39:48 +01002880 intel_edp_backlight_on(intel_dp);
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002881 intel_psr_enable(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002882}
2883
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002884static void g4x_pre_enable_dp(struct intel_encoder *encoder,
2885 struct intel_crtc_state *pipe_config,
2886 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002887{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002888 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002889 enum port port = dp_to_dig_port(intel_dp)->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002890
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002891 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002892
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002893 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002894 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002895 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002896}
2897
Ville Syrjälä83b84592014-10-16 21:29:51 +03002898static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2899{
2900 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002901 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002902 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03002903 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002904
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002905 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
2906
Ville Syrjäläd1586942017-02-08 19:52:54 +02002907 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2908 return;
2909
Ville Syrjälä83b84592014-10-16 21:29:51 +03002910 edp_panel_vdd_off_sync(intel_dp);
2911
2912 /*
2913 * VLV seems to get confused when multiple power seqeuencers
2914 * have the same port selected (even if only one has power/vdd
2915 * enabled). The failure manifests as vlv_wait_port_ready() failing
2916 * CHV on the other hand doesn't seem to mind having the same port
2917 * selected in multiple power seqeuencers, but let's clear the
2918 * port select always when logically disconnecting a power sequencer
2919 * from a port.
2920 */
2921 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2922 pipe_name(pipe), port_name(intel_dig_port->port));
2923 I915_WRITE(pp_on_reg, 0);
2924 POSTING_READ(pp_on_reg);
2925
2926 intel_dp->pps_pipe = INVALID_PIPE;
2927}
2928
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002929static void vlv_steal_power_sequencer(struct drm_device *dev,
2930 enum pipe pipe)
2931{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002932 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002933 struct intel_encoder *encoder;
2934
2935 lockdep_assert_held(&dev_priv->pps_mutex);
2936
Jani Nikula19c80542015-12-16 12:48:16 +02002937 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002938 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002939 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002940
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002941 if (encoder->type != INTEL_OUTPUT_DP &&
2942 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002943 continue;
2944
2945 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002946 port = dp_to_dig_port(intel_dp)->port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002947
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002948 WARN(intel_dp->active_pipe == pipe,
2949 "stealing pipe %c power sequencer from active (e)DP port %c\n",
2950 pipe_name(pipe), port_name(port));
2951
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002952 if (intel_dp->pps_pipe != pipe)
2953 continue;
2954
2955 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03002956 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002957
2958 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002959 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002960 }
2961}
2962
2963static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
2964{
2965 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2966 struct intel_encoder *encoder = &intel_dig_port->base;
2967 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002968 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002969 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002970
2971 lockdep_assert_held(&dev_priv->pps_mutex);
2972
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002973 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002974
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002975 if (intel_dp->pps_pipe != INVALID_PIPE &&
2976 intel_dp->pps_pipe != crtc->pipe) {
2977 /*
2978 * If another power sequencer was being used on this
2979 * port previously make sure to turn off vdd there while
2980 * we still have control of it.
2981 */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002982 vlv_detach_power_sequencer(intel_dp);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002983 }
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002984
2985 /*
2986 * We may be stealing the power
2987 * sequencer from another port.
2988 */
2989 vlv_steal_power_sequencer(dev, crtc->pipe);
2990
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002991 intel_dp->active_pipe = crtc->pipe;
2992
2993 if (!is_edp(intel_dp))
2994 return;
2995
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002996 /* now it's all ours */
2997 intel_dp->pps_pipe = crtc->pipe;
2998
2999 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
3000 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
3001
3002 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03003003 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02003004 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003005}
3006
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003007static void vlv_pre_enable_dp(struct intel_encoder *encoder,
3008 struct intel_crtc_state *pipe_config,
3009 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03003010{
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03003011 vlv_phy_pre_encoder_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003012
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003013 intel_enable_dp(encoder, pipe_config, conn_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003014}
3015
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003016static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
3017 struct intel_crtc_state *pipe_config,
3018 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07003019{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003020 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02003021
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03003022 vlv_phy_pre_pll_enable(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003023}
3024
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003025static void chv_pre_enable_dp(struct intel_encoder *encoder,
3026 struct intel_crtc_state *pipe_config,
3027 struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003028{
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003029 chv_phy_pre_encoder_enable(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003030
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003031 intel_enable_dp(encoder, pipe_config, conn_state);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03003032
3033 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003034 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003035}
3036
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003037static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
3038 struct intel_crtc_state *pipe_config,
3039 struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03003040{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003041 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03003042
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03003043 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03003044}
3045
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003046static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
3047 struct intel_crtc_state *pipe_config,
3048 struct drm_connector_state *conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003049{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03003050 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003051}
3052
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003053/*
3054 * Fetch AUX CH registers 0x202 - 0x207 which contain
3055 * link status information
3056 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003057bool
Keith Packard93f62da2011-11-01 19:45:03 -07003058intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003059{
Lyude9f085eb2016-04-13 10:58:33 -04003060 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
3061 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003062}
3063
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303064static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp)
3065{
3066 uint8_t psr_caps = 0;
3067
3068 drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps);
3069 return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED;
3070}
3071
3072static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp)
3073{
3074 uint8_t dprx = 0;
3075
3076 drm_dp_dpcd_readb(&intel_dp->aux,
3077 DP_DPRX_FEATURE_ENUMERATION_LIST,
3078 &dprx);
3079 return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED;
3080}
3081
Chris Wilsona76f73d2017-01-14 10:51:13 +00003082static bool intel_dp_get_alpm_status(struct intel_dp *intel_dp)
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303083{
3084 uint8_t alpm_caps = 0;
3085
3086 drm_dp_dpcd_readb(&intel_dp->aux, DP_RECEIVER_ALPM_CAP, &alpm_caps);
3087 return alpm_caps & DP_ALPM_CAP;
3088}
3089
Paulo Zanoni11002442014-06-13 18:45:41 -03003090/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003091uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003092intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003093{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003094 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003095 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003096
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003097 if (IS_GEN9_LP(dev_priv))
Vandana Kannan93147262014-11-18 15:45:29 +05303098 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003099 else if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjäläffe51112017-02-23 19:49:01 +02003100 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3101 return intel_ddi_dp_voltage_max(encoder);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003102 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Sonika Jindalbd600182014-08-08 16:23:41 +05303103 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003104 else if (IS_GEN7(dev_priv) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303105 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003106 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303107 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08003108 else
Sonika Jindalbd600182014-08-08 16:23:41 +05303109 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08003110}
3111
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003112uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003113intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3114{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003115 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003116 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003117
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003118 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003119 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3120 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3121 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3122 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3123 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3124 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3125 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303126 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3127 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003128 default:
3129 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3130 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003131 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003132 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303133 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3134 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3135 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3136 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3137 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3138 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3139 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003140 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303141 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003142 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003143 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003144 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303145 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3146 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3147 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3148 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3149 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3150 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3151 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003152 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303153 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003154 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003155 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003156 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303157 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3158 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3159 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3160 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3161 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003162 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303163 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003164 }
3165 } else {
3166 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303167 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3168 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3169 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3170 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3171 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3172 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3173 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003174 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303175 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003176 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003177 }
3178}
3179
Daniel Vetter5829975c2015-04-16 11:36:52 +02003180static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003181{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003182 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003183 unsigned long demph_reg_value, preemph_reg_value,
3184 uniqtranscale_reg_value;
3185 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003186
3187 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303188 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003189 preemph_reg_value = 0x0004000;
3190 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303191 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003192 demph_reg_value = 0x2B405555;
3193 uniqtranscale_reg_value = 0x552AB83A;
3194 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303195 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003196 demph_reg_value = 0x2B404040;
3197 uniqtranscale_reg_value = 0x5548B83A;
3198 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303199 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003200 demph_reg_value = 0x2B245555;
3201 uniqtranscale_reg_value = 0x5560B83A;
3202 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303203 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003204 demph_reg_value = 0x2B405555;
3205 uniqtranscale_reg_value = 0x5598DA3A;
3206 break;
3207 default:
3208 return 0;
3209 }
3210 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303211 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003212 preemph_reg_value = 0x0002000;
3213 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303214 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003215 demph_reg_value = 0x2B404040;
3216 uniqtranscale_reg_value = 0x5552B83A;
3217 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303218 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003219 demph_reg_value = 0x2B404848;
3220 uniqtranscale_reg_value = 0x5580B83A;
3221 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303222 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003223 demph_reg_value = 0x2B404040;
3224 uniqtranscale_reg_value = 0x55ADDA3A;
3225 break;
3226 default:
3227 return 0;
3228 }
3229 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303230 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003231 preemph_reg_value = 0x0000000;
3232 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303233 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003234 demph_reg_value = 0x2B305555;
3235 uniqtranscale_reg_value = 0x5570B83A;
3236 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303237 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003238 demph_reg_value = 0x2B2B4040;
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_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003246 preemph_reg_value = 0x0006000;
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 = 0x1B405555;
3250 uniqtranscale_reg_value = 0x55ADDA3A;
3251 break;
3252 default:
3253 return 0;
3254 }
3255 break;
3256 default:
3257 return 0;
3258 }
3259
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003260 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3261 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003262
3263 return 0;
3264}
3265
Daniel Vetter5829975c2015-04-16 11:36:52 +02003266static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003267{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003268 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3269 u32 deemph_reg_value, margin_reg_value;
3270 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003271 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003272
3273 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303274 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003275 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303276 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003277 deemph_reg_value = 128;
3278 margin_reg_value = 52;
3279 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303280 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003281 deemph_reg_value = 128;
3282 margin_reg_value = 77;
3283 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303284 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003285 deemph_reg_value = 128;
3286 margin_reg_value = 102;
3287 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303288 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003289 deemph_reg_value = 128;
3290 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003291 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003292 break;
3293 default:
3294 return 0;
3295 }
3296 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303297 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003298 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303299 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003300 deemph_reg_value = 85;
3301 margin_reg_value = 78;
3302 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303303 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003304 deemph_reg_value = 85;
3305 margin_reg_value = 116;
3306 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303307 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003308 deemph_reg_value = 85;
3309 margin_reg_value = 154;
3310 break;
3311 default:
3312 return 0;
3313 }
3314 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303315 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003316 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303317 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003318 deemph_reg_value = 64;
3319 margin_reg_value = 104;
3320 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303321 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003322 deemph_reg_value = 64;
3323 margin_reg_value = 154;
3324 break;
3325 default:
3326 return 0;
3327 }
3328 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303329 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003330 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303331 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003332 deemph_reg_value = 43;
3333 margin_reg_value = 154;
3334 break;
3335 default:
3336 return 0;
3337 }
3338 break;
3339 default:
3340 return 0;
3341 }
3342
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003343 chv_set_phy_signal_level(encoder, deemph_reg_value,
3344 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003345
3346 return 0;
3347}
3348
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003349static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003350gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003351{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003352 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003353
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003354 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303355 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003356 default:
3357 signal_levels |= DP_VOLTAGE_0_4;
3358 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303359 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003360 signal_levels |= DP_VOLTAGE_0_6;
3361 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303362 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003363 signal_levels |= DP_VOLTAGE_0_8;
3364 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303365 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003366 signal_levels |= DP_VOLTAGE_1_2;
3367 break;
3368 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003369 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303370 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003371 default:
3372 signal_levels |= DP_PRE_EMPHASIS_0;
3373 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303374 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003375 signal_levels |= DP_PRE_EMPHASIS_3_5;
3376 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303377 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003378 signal_levels |= DP_PRE_EMPHASIS_6;
3379 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303380 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003381 signal_levels |= DP_PRE_EMPHASIS_9_5;
3382 break;
3383 }
3384 return signal_levels;
3385}
3386
Zhenyu Wange3421a12010-04-08 09:43:27 +08003387/* Gen6's DP voltage swing and pre-emphasis control */
3388static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003389gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003390{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003391 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3392 DP_TRAIN_PRE_EMPHASIS_MASK);
3393 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303394 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3395 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003396 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303397 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003398 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303399 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3400 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003401 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303402 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3403 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003404 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303405 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3406 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003407 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003408 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003409 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3410 "0x%x\n", signal_levels);
3411 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003412 }
3413}
3414
Keith Packard1a2eb462011-11-16 16:26:07 -08003415/* Gen7's DP voltage swing and pre-emphasis control */
3416static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003417gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003418{
3419 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3420 DP_TRAIN_PRE_EMPHASIS_MASK);
3421 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303422 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003423 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303424 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003425 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303426 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003427 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3428
Sonika Jindalbd600182014-08-08 16:23:41 +05303429 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003430 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303431 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003432 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3433
Sonika Jindalbd600182014-08-08 16:23:41 +05303434 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003435 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303436 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003437 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3438
3439 default:
3440 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3441 "0x%x\n", signal_levels);
3442 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3443 }
3444}
3445
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003446void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003447intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003448{
3449 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003450 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003451 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003452 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003453 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003454 uint8_t train_set = intel_dp->train_set[0];
3455
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003456 if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003457 signal_levels = ddi_signal_levels(intel_dp);
3458
Michel Thierry254e0932017-01-09 16:51:35 +02003459 if (IS_GEN9_LP(dev_priv))
David Weinehallf8896f52015-06-25 11:11:03 +03003460 signal_levels = 0;
3461 else
3462 mask = DDI_BUF_EMP_MASK;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003463 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003464 signal_levels = chv_signal_levels(intel_dp);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003465 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003466 signal_levels = vlv_signal_levels(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003467 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003468 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003469 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003470 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003471 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003472 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3473 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003474 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003475 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3476 }
3477
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303478 if (mask)
3479 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3480
3481 DRM_DEBUG_KMS("Using vswing level %d\n",
3482 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3483 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3484 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3485 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003486
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003487 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003488
3489 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3490 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003491}
3492
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003493void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003494intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3495 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003496{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003497 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003498 struct drm_i915_private *dev_priv =
3499 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003500
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003501 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003502
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003503 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003504 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003505}
3506
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003507void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003508{
3509 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3510 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003511 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak3ab9c632013-05-03 12:57:41 +03003512 enum port port = intel_dig_port->port;
3513 uint32_t val;
3514
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003515 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003516 return;
3517
3518 val = I915_READ(DP_TP_CTL(port));
3519 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3520 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3521 I915_WRITE(DP_TP_CTL(port), val);
3522
3523 /*
3524 * On PORT_A we can have only eDP in SST mode. There the only reason
3525 * we need to set idle transmission mode is to work around a HW issue
3526 * where we enable the pipe while not in idle link-training mode.
3527 * In this case there is requirement to wait for a minimum number of
3528 * idle patterns to be sent.
3529 */
3530 if (port == PORT_A)
3531 return;
3532
Chris Wilsona7670172016-06-30 15:33:10 +01003533 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3534 DP_TP_STATUS_IDLE_DONE,
3535 DP_TP_STATUS_IDLE_DONE,
3536 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003537 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3538}
3539
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003540static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003541intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003542{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003543 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003544 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003545 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003546 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003547 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003548 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003549
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003550 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003551 return;
3552
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003553 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003554 return;
3555
Zhao Yakui28c97732009-10-09 11:39:41 +08003556 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003557
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003558 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003559 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003560 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003561 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003562 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003563 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003564 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3565 else
3566 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003567 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003568 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003569 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003570 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003571
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003572 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3573 I915_WRITE(intel_dp->output_reg, DP);
3574 POSTING_READ(intel_dp->output_reg);
3575
3576 /*
3577 * HW workaround for IBX, we need to move the port
3578 * to transcoder A after disabling it to allow the
3579 * matching HDMI port to be enabled on transcoder A.
3580 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003581 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003582 /*
3583 * We get CPU/PCH FIFO underruns on the other pipe when
3584 * doing the workaround. Sweep them under the rug.
3585 */
3586 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3587 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3588
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003589 /* always enable with pattern 1 (as per spec) */
3590 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3591 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3592 I915_WRITE(intel_dp->output_reg, DP);
3593 POSTING_READ(intel_dp->output_reg);
3594
3595 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003596 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003597 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003598
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003599 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003600 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3601 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003602 }
3603
Keith Packardf01eca22011-09-28 16:48:10 -07003604 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003605
3606 intel_dp->DP = DP;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003607
3608 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3609 pps_lock(intel_dp);
3610 intel_dp->active_pipe = INVALID_PIPE;
3611 pps_unlock(intel_dp);
3612 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003613}
3614
Imre Deak24e807e2016-10-24 19:33:28 +03003615bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003616intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003617{
Lyude9f085eb2016-04-13 10:58:33 -04003618 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3619 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003620 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003621
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003622 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003623
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003624 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3625}
3626
3627static bool
3628intel_edp_init_dpcd(struct intel_dp *intel_dp)
3629{
3630 struct drm_i915_private *dev_priv =
3631 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3632
3633 /* this function is meant to be called only once */
3634 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3635
3636 if (!intel_dp_read_dpcd(intel_dp))
3637 return false;
3638
Imre Deak12a47a422016-10-24 19:33:29 +03003639 intel_dp_read_desc(intel_dp);
3640
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003641 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3642 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3643 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3644
3645 /* Check if the panel supports PSR */
3646 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3647 intel_dp->psr_dpcd,
3648 sizeof(intel_dp->psr_dpcd));
3649 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3650 dev_priv->psr.sink_support = true;
3651 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3652 }
3653
3654 if (INTEL_GEN(dev_priv) >= 9 &&
3655 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3656 uint8_t frame_sync_cap;
3657
3658 dev_priv->psr.sink_support = true;
3659 drm_dp_dpcd_read(&intel_dp->aux,
3660 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3661 &frame_sync_cap, 1);
3662 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3663 /* PSR2 needs frame sync as well */
3664 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3665 DRM_DEBUG_KMS("PSR2 %s on sink",
3666 dev_priv->psr.psr2_support ? "supported" : "not supported");
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303667
3668 if (dev_priv->psr.psr2_support) {
3669 dev_priv->psr.y_cord_support =
3670 intel_dp_get_y_cord_status(intel_dp);
3671 dev_priv->psr.colorimetry_support =
3672 intel_dp_get_colorimetry_status(intel_dp);
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303673 dev_priv->psr.alpm =
3674 intel_dp_get_alpm_status(intel_dp);
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303675 }
3676
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003677 }
3678
3679 /* Read the eDP Display control capabilities registers */
3680 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
3681 drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003682 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3683 sizeof(intel_dp->edp_dpcd))
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003684 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3685 intel_dp->edp_dpcd);
3686
3687 /* Intermediate frequency support */
3688 if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */
3689 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3690 int i;
3691
3692 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3693 sink_rates, sizeof(sink_rates));
3694
3695 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3696 int val = le16_to_cpu(sink_rates[i]);
3697
3698 if (val == 0)
3699 break;
3700
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -08003701 /* Value read multiplied by 200kHz gives the per-lane
3702 * link rate in kHz. The source rates are, however,
3703 * stored in terms of LS_Clk kHz. The full conversion
3704 * back to symbols is
3705 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
3706 */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003707 intel_dp->sink_rates[i] = (val * 200) / 10;
3708 }
3709 intel_dp->num_sink_rates = i;
3710 }
3711
Jani Nikula68f357c2017-03-28 17:59:05 +03003712 if (intel_dp->num_sink_rates)
3713 intel_dp->use_rate_select = true;
3714 else
3715 intel_dp_set_sink_rates(intel_dp);
3716
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003717 intel_dp_set_common_rates(intel_dp);
3718
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003719 return true;
3720}
3721
3722
3723static bool
3724intel_dp_get_dpcd(struct intel_dp *intel_dp)
3725{
3726 if (!intel_dp_read_dpcd(intel_dp))
3727 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003728
Jani Nikula68f357c2017-03-28 17:59:05 +03003729 /* Don't clobber cached eDP rates. */
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003730 if (!is_edp(intel_dp)) {
Jani Nikula68f357c2017-03-28 17:59:05 +03003731 intel_dp_set_sink_rates(intel_dp);
Jani Nikula975ee5fca2017-04-06 16:44:10 +03003732 intel_dp_set_common_rates(intel_dp);
3733 }
Jani Nikula68f357c2017-03-28 17:59:05 +03003734
Lyude9f085eb2016-04-13 10:58:33 -04003735 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT,
3736 &intel_dp->sink_count, 1) < 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303737 return false;
3738
3739 /*
3740 * Sink count can change between short pulse hpd hence
3741 * a member variable in intel_dp will track any changes
3742 * between short pulse interrupts.
3743 */
3744 intel_dp->sink_count = DP_GET_SINK_COUNT(intel_dp->sink_count);
3745
3746 /*
3747 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3748 * a dongle is present but no display. Unless we require to know
3749 * if a dongle is present or not, we don't need to update
3750 * downstream port information. So, an early return here saves
3751 * time from performing other operations which are not required.
3752 */
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05303753 if (!is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303754 return false;
3755
Imre Deakc726ad02016-10-24 19:33:24 +03003756 if (!drm_dp_is_branch(intel_dp->dpcd))
Adam Jacksonedb39242012-09-18 10:58:49 -04003757 return true; /* native DP sink */
3758
3759 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3760 return true; /* no per-port downstream info */
3761
Lyude9f085eb2016-04-13 10:58:33 -04003762 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3763 intel_dp->downstream_ports,
3764 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003765 return false; /* downstream port status fetch failed */
3766
3767 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003768}
3769
Dave Airlie0e32b392014-05-02 14:02:48 +10003770static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003771intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003772{
3773 u8 buf[1];
3774
Nathan Schulte7cc96132016-03-15 10:14:05 -05003775 if (!i915.enable_dp_mst)
3776 return false;
3777
Dave Airlie0e32b392014-05-02 14:02:48 +10003778 if (!intel_dp->can_mst)
3779 return false;
3780
3781 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3782 return false;
3783
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003784 if (drm_dp_dpcd_read(&intel_dp->aux, DP_MSTM_CAP, buf, 1) != 1)
3785 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003786
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003787 return buf[0] & DP_MST_CAP;
3788}
3789
3790static void
3791intel_dp_configure_mst(struct intel_dp *intel_dp)
3792{
3793 if (!i915.enable_dp_mst)
3794 return;
3795
3796 if (!intel_dp->can_mst)
3797 return;
3798
3799 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3800
3801 if (intel_dp->is_mst)
3802 DRM_DEBUG_KMS("Sink is MST capable\n");
3803 else
3804 DRM_DEBUG_KMS("Sink is not MST capable\n");
3805
3806 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3807 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003808}
3809
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003810static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003811{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003812 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003813 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003814 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003815 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003816 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003817 int count = 0;
3818 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003819
3820 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003821 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003822 ret = -EIO;
3823 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003824 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003825
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003826 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003827 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003828 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003829 ret = -EIO;
3830 goto out;
3831 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003832
Rodrigo Vivic6297842015-11-05 10:50:20 -08003833 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003834 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivic6297842015-11-05 10:50:20 -08003835
3836 if (drm_dp_dpcd_readb(&intel_dp->aux,
3837 DP_TEST_SINK_MISC, &buf) < 0) {
3838 ret = -EIO;
3839 goto out;
3840 }
3841 count = buf & DP_TEST_COUNT_MASK;
3842 } while (--attempts && count);
3843
3844 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003845 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003846 ret = -ETIMEDOUT;
3847 }
3848
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003849 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003850 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003851 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003852}
3853
3854static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3855{
3856 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003857 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003858 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3859 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003860 int ret;
3861
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003862 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3863 return -EIO;
3864
3865 if (!(buf & DP_TEST_CRC_SUPPORTED))
3866 return -ENOTTY;
3867
3868 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3869 return -EIO;
3870
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003871 if (buf & DP_TEST_SINK_START) {
3872 ret = intel_dp_sink_crc_stop(intel_dp);
3873 if (ret)
3874 return ret;
3875 }
3876
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003877 hsw_disable_ips(intel_crtc);
3878
3879 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3880 buf | DP_TEST_SINK_START) < 0) {
3881 hsw_enable_ips(intel_crtc);
3882 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003883 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003884
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003885 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003886 return 0;
3887}
3888
3889int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3890{
3891 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003892 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003893 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3894 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003895 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003896 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003897
3898 ret = intel_dp_sink_crc_start(intel_dp);
3899 if (ret)
3900 return ret;
3901
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003902 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003903 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003904
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003905 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003906 DP_TEST_SINK_MISC, &buf) < 0) {
3907 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003908 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003909 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003910 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07003911
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003912 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003913
3914 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003915 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
3916 ret = -ETIMEDOUT;
3917 goto stop;
3918 }
3919
3920 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
3921 ret = -EIO;
3922 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003923 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003924
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003925stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003926 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003927 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003928}
3929
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003930static bool
3931intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3932{
Lyude9f085eb2016-04-13 10:58:33 -04003933 return drm_dp_dpcd_read(&intel_dp->aux,
Jani Nikula9d1a1032014-03-14 16:51:15 +02003934 DP_DEVICE_SERVICE_IRQ_VECTOR,
3935 sink_irq_vector, 1) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003936}
3937
Dave Airlie0e32b392014-05-02 14:02:48 +10003938static bool
3939intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3940{
3941 int ret;
3942
Lyude9f085eb2016-04-13 10:58:33 -04003943 ret = drm_dp_dpcd_read(&intel_dp->aux,
Dave Airlie0e32b392014-05-02 14:02:48 +10003944 DP_SINK_COUNT_ESI,
3945 sink_irq_vector, 14);
3946 if (ret != 14)
3947 return false;
3948
3949 return true;
3950}
3951
Todd Previtec5d5ab72015-04-15 08:38:38 -07003952static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003953{
Manasi Navareda15f7c2017-01-24 08:16:34 -08003954 int status = 0;
3955 int min_lane_count = 1;
Manasi Navareda15f7c2017-01-24 08:16:34 -08003956 int link_rate_index, test_link_rate;
3957 uint8_t test_lane_count, test_link_bw;
3958 /* (DP CTS 1.2)
3959 * 4.3.1.11
3960 */
3961 /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */
3962 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT,
3963 &test_lane_count);
3964
3965 if (status <= 0) {
3966 DRM_DEBUG_KMS("Lane count read failed\n");
3967 return DP_TEST_NAK;
3968 }
3969 test_lane_count &= DP_MAX_LANE_COUNT_MASK;
3970 /* Validate the requested lane count */
3971 if (test_lane_count < min_lane_count ||
3972 test_lane_count > intel_dp->max_sink_lane_count)
3973 return DP_TEST_NAK;
3974
3975 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE,
3976 &test_link_bw);
3977 if (status <= 0) {
3978 DRM_DEBUG_KMS("Link Rate read failed\n");
3979 return DP_TEST_NAK;
3980 }
3981 /* Validate the requested link rate */
3982 test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw);
Jani Nikulab1810a72017-04-06 16:44:11 +03003983 link_rate_index = intel_dp_rate_index(intel_dp->common_rates,
3984 intel_dp->num_common_rates,
3985 test_link_rate);
Manasi Navareda15f7c2017-01-24 08:16:34 -08003986 if (link_rate_index < 0)
3987 return DP_TEST_NAK;
3988
3989 intel_dp->compliance.test_lane_count = test_lane_count;
3990 intel_dp->compliance.test_link_rate = test_link_rate;
3991
3992 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07003993}
3994
3995static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
3996{
Manasi Navare611032b2017-01-24 08:21:49 -08003997 uint8_t test_pattern;
3998 uint16_t test_misc;
3999 __be16 h_width, v_height;
4000 int status = 0;
4001
4002 /* Read the TEST_PATTERN (DP CTS 3.1.5) */
4003 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_PATTERN,
4004 &test_pattern, 1);
4005 if (status <= 0) {
4006 DRM_DEBUG_KMS("Test pattern read failed\n");
4007 return DP_TEST_NAK;
4008 }
4009 if (test_pattern != DP_COLOR_RAMP)
4010 return DP_TEST_NAK;
4011
4012 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI,
4013 &h_width, 2);
4014 if (status <= 0) {
4015 DRM_DEBUG_KMS("H Width read failed\n");
4016 return DP_TEST_NAK;
4017 }
4018
4019 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI,
4020 &v_height, 2);
4021 if (status <= 0) {
4022 DRM_DEBUG_KMS("V Height read failed\n");
4023 return DP_TEST_NAK;
4024 }
4025
4026 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_MISC0,
4027 &test_misc, 1);
4028 if (status <= 0) {
4029 DRM_DEBUG_KMS("TEST MISC read failed\n");
4030 return DP_TEST_NAK;
4031 }
4032 if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB)
4033 return DP_TEST_NAK;
4034 if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA)
4035 return DP_TEST_NAK;
4036 switch (test_misc & DP_TEST_BIT_DEPTH_MASK) {
4037 case DP_TEST_BIT_DEPTH_6:
4038 intel_dp->compliance.test_data.bpc = 6;
4039 break;
4040 case DP_TEST_BIT_DEPTH_8:
4041 intel_dp->compliance.test_data.bpc = 8;
4042 break;
4043 default:
4044 return DP_TEST_NAK;
4045 }
4046
4047 intel_dp->compliance.test_data.video_pattern = test_pattern;
4048 intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width);
4049 intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height);
4050 /* Set test active flag here so userspace doesn't interrupt things */
4051 intel_dp->compliance.test_active = 1;
4052
4053 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004054}
4055
4056static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
4057{
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004058 uint8_t test_result = DP_TEST_ACK;
Todd Previte559be302015-05-04 07:48:20 -07004059 struct intel_connector *intel_connector = intel_dp->attached_connector;
4060 struct drm_connector *connector = &intel_connector->base;
4061
4062 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02004063 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07004064 intel_dp->aux.i2c_defer_count > 6) {
4065 /* Check EDID read for NACKs, DEFERs and corruption
4066 * (DP CTS 1.2 Core r1.1)
4067 * 4.2.2.4 : Failed EDID read, I2C_NAK
4068 * 4.2.2.5 : Failed EDID read, I2C_DEFER
4069 * 4.2.2.6 : EDID corruption detected
4070 * Use failsafe mode for all cases
4071 */
4072 if (intel_dp->aux.i2c_nack_count > 0 ||
4073 intel_dp->aux.i2c_defer_count > 0)
4074 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
4075 intel_dp->aux.i2c_nack_count,
4076 intel_dp->aux.i2c_defer_count);
Manasi Navarec1617ab2016-12-09 16:22:50 -08004077 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
Todd Previte559be302015-05-04 07:48:20 -07004078 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05304079 struct edid *block = intel_connector->detect_edid;
4080
4081 /* We have to write the checksum
4082 * of the last block read
4083 */
4084 block += intel_connector->detect_edid->extensions;
4085
Todd Previte559be302015-05-04 07:48:20 -07004086 if (!drm_dp_dpcd_write(&intel_dp->aux,
4087 DP_TEST_EDID_CHECKSUM,
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05304088 &block->checksum,
Dan Carpenter5a1cc652015-05-12 21:07:37 +03004089 1))
Todd Previte559be302015-05-04 07:48:20 -07004090 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
4091
4092 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004093 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED;
Todd Previte559be302015-05-04 07:48:20 -07004094 }
4095
4096 /* Set test active flag here so userspace doesn't interrupt things */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004097 intel_dp->compliance.test_active = 1;
Todd Previte559be302015-05-04 07:48:20 -07004098
Todd Previtec5d5ab72015-04-15 08:38:38 -07004099 return test_result;
4100}
4101
4102static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
4103{
4104 uint8_t test_result = DP_TEST_NAK;
4105 return test_result;
4106}
4107
4108static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
4109{
4110 uint8_t response = DP_TEST_NAK;
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004111 uint8_t request = 0;
4112 int status;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004113
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004114 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004115 if (status <= 0) {
4116 DRM_DEBUG_KMS("Could not read test request from sink\n");
4117 goto update_status;
4118 }
4119
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004120 switch (request) {
Todd Previtec5d5ab72015-04-15 08:38:38 -07004121 case DP_TEST_LINK_TRAINING:
4122 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004123 response = intel_dp_autotest_link_training(intel_dp);
4124 break;
4125 case DP_TEST_LINK_VIDEO_PATTERN:
4126 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004127 response = intel_dp_autotest_video_pattern(intel_dp);
4128 break;
4129 case DP_TEST_LINK_EDID_READ:
4130 DRM_DEBUG_KMS("EDID test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004131 response = intel_dp_autotest_edid(intel_dp);
4132 break;
4133 case DP_TEST_LINK_PHY_TEST_PATTERN:
4134 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004135 response = intel_dp_autotest_phy_pattern(intel_dp);
4136 break;
4137 default:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004138 DRM_DEBUG_KMS("Invalid test request '%02x'\n", request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004139 break;
4140 }
4141
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004142 if (response & DP_TEST_ACK)
4143 intel_dp->compliance.test_type = request;
4144
Todd Previtec5d5ab72015-04-15 08:38:38 -07004145update_status:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004146 status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004147 if (status <= 0)
4148 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004149}
4150
Dave Airlie0e32b392014-05-02 14:02:48 +10004151static int
4152intel_dp_check_mst_status(struct intel_dp *intel_dp)
4153{
4154 bool bret;
4155
4156 if (intel_dp->is_mst) {
4157 u8 esi[16] = { 0 };
4158 int ret = 0;
4159 int retry;
4160 bool handled;
4161 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4162go_again:
4163 if (bret == true) {
4164
4165 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03004166 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03004167 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10004168 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4169 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004170 intel_dp_stop_link_train(intel_dp);
4171 }
4172
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004173 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004174 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4175
4176 if (handled) {
4177 for (retry = 0; retry < 3; retry++) {
4178 int wret;
4179 wret = drm_dp_dpcd_write(&intel_dp->aux,
4180 DP_SINK_COUNT_ESI+1,
4181 &esi[1], 3);
4182 if (wret == 3) {
4183 break;
4184 }
4185 }
4186
4187 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4188 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004189 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004190 goto go_again;
4191 }
4192 } else
4193 ret = 0;
4194
4195 return ret;
4196 } else {
4197 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4198 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4199 intel_dp->is_mst = false;
4200 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4201 /* send a hotplug event */
4202 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4203 }
4204 }
4205 return -EINVAL;
4206}
4207
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304208static void
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004209intel_dp_retrain_link(struct intel_dp *intel_dp)
4210{
4211 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4212 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4213 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
4214
4215 /* Suppress underruns caused by re-training */
4216 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4217 if (crtc->config->has_pch_encoder)
4218 intel_set_pch_fifo_underrun_reporting(dev_priv,
4219 intel_crtc_pch_transcoder(crtc), false);
4220
4221 intel_dp_start_link_train(intel_dp);
4222 intel_dp_stop_link_train(intel_dp);
4223
4224 /* Keep underrun reporting disabled until things are stable */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02004225 intel_wait_for_vblank(dev_priv, crtc->pipe);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004226
4227 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4228 if (crtc->config->has_pch_encoder)
4229 intel_set_pch_fifo_underrun_reporting(dev_priv,
4230 intel_crtc_pch_transcoder(crtc), true);
4231}
4232
4233static void
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304234intel_dp_check_link_status(struct intel_dp *intel_dp)
4235{
4236 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4237 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4238 u8 link_status[DP_LINK_STATUS_SIZE];
4239
4240 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
4241
4242 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4243 DRM_ERROR("Failed to get link status\n");
4244 return;
4245 }
4246
4247 if (!intel_encoder->base.crtc)
4248 return;
4249
4250 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4251 return;
4252
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004253 /* FIXME: we need to synchronize this sort of stuff with hardware
Daniel Vetter2dd85ae2016-12-13 20:54:14 +01004254 * readout. Currently fast link training doesn't work on boot-up. */
4255 if (!intel_dp->lane_count)
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004256 return;
4257
Manasi Navareda15f7c2017-01-24 08:16:34 -08004258 /* Retrain if Channel EQ or CR not ok */
4259 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304260 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4261 intel_encoder->base.name);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004262
4263 intel_dp_retrain_link(intel_dp);
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304264 }
4265}
4266
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004267/*
4268 * According to DP spec
4269 * 5.1.2:
4270 * 1. Read DPCD
4271 * 2. Configure link according to Receiver Capabilities
4272 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4273 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304274 *
4275 * intel_dp_short_pulse - handles short pulse interrupts
4276 * when full detection is not required.
4277 * Returns %true if short pulse is handled and full detection
4278 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004279 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304280static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304281intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004282{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004283 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004284 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004285 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304286 u8 old_sink_count = intel_dp->sink_count;
4287 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004288
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304289 /*
4290 * Clearing compliance test variables to allow capturing
4291 * of values for next automated test request.
4292 */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004293 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304294
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304295 /*
4296 * Now read the DPCD to see if it's actually running
4297 * If the current value of sink count doesn't match with
4298 * the value that was stored earlier or dpcd read failed
4299 * we need to do full detection
4300 */
4301 ret = intel_dp_get_dpcd(intel_dp);
4302
4303 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4304 /* No need to proceed if we are going to do full detect */
4305 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004306 }
4307
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004308 /* Try to read the source of the interrupt */
4309 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004310 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4311 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004312 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004313 drm_dp_dpcd_writeb(&intel_dp->aux,
4314 DP_DEVICE_SERVICE_IRQ_VECTOR,
4315 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004316
4317 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Manasi Navareda15f7c2017-01-24 08:16:34 -08004318 intel_dp_handle_test_request(intel_dp);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004319 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4320 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4321 }
4322
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304323 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4324 intel_dp_check_link_status(intel_dp);
4325 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004326 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
4327 DRM_DEBUG_KMS("Link Training Compliance Test requested\n");
4328 /* Send a Hotplug Uevent to userspace to start modeset */
4329 drm_kms_helper_hotplug_event(intel_encoder->base.dev);
4330 }
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304331
4332 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004333}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004334
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004335/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004336static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004337intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004338{
Imre Deake393d0d2017-02-22 17:10:52 +02004339 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004340 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004341 uint8_t type;
4342
Imre Deake393d0d2017-02-22 17:10:52 +02004343 if (lspcon->active)
4344 lspcon_resume(lspcon);
4345
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004346 if (!intel_dp_get_dpcd(intel_dp))
4347 return connector_status_disconnected;
4348
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304349 if (is_edp(intel_dp))
4350 return connector_status_connected;
4351
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004352 /* if there's no downstream port, we're done */
Imre Deakc726ad02016-10-24 19:33:24 +03004353 if (!drm_dp_is_branch(dpcd))
Keith Packard26d61aa2011-07-25 20:01:09 -07004354 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004355
4356 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004357 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4358 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004359
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304360 return intel_dp->sink_count ?
4361 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004362 }
4363
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004364 if (intel_dp_can_mst(intel_dp))
4365 return connector_status_connected;
4366
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004367 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004368 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004369 return connector_status_connected;
4370
4371 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004372 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4373 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4374 if (type == DP_DS_PORT_TYPE_VGA ||
4375 type == DP_DS_PORT_TYPE_NON_EDID)
4376 return connector_status_unknown;
4377 } else {
4378 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4379 DP_DWN_STRM_PORT_TYPE_MASK;
4380 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4381 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4382 return connector_status_unknown;
4383 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004384
4385 /* Anything else is out of spec, warn and ignore */
4386 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004387 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004388}
4389
4390static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004391edp_detect(struct intel_dp *intel_dp)
4392{
4393 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Mika Kahola1650be72016-12-13 10:02:47 +02004394 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsond410b562014-09-02 20:03:59 +01004395 enum drm_connector_status status;
4396
Mika Kahola1650be72016-12-13 10:02:47 +02004397 status = intel_panel_detect(dev_priv);
Chris Wilsond410b562014-09-02 20:03:59 +01004398 if (status == connector_status_unknown)
4399 status = connector_status_connected;
4400
4401 return status;
4402}
4403
Jani Nikulab93433c2015-08-20 10:47:36 +03004404static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4405 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004406{
Jani Nikulab93433c2015-08-20 10:47:36 +03004407 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004408
Jani Nikula0df53b72015-08-20 10:47:40 +03004409 switch (port->port) {
4410 case PORT_A:
4411 return true;
4412 case PORT_B:
4413 bit = SDE_PORTB_HOTPLUG;
4414 break;
4415 case PORT_C:
4416 bit = SDE_PORTC_HOTPLUG;
4417 break;
4418 case PORT_D:
4419 bit = SDE_PORTD_HOTPLUG;
4420 break;
4421 default:
4422 MISSING_CASE(port->port);
4423 return false;
4424 }
4425
4426 return I915_READ(SDEISR) & bit;
4427}
4428
4429static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4430 struct intel_digital_port *port)
4431{
4432 u32 bit;
4433
4434 switch (port->port) {
4435 case PORT_A:
4436 return true;
4437 case PORT_B:
4438 bit = SDE_PORTB_HOTPLUG_CPT;
4439 break;
4440 case PORT_C:
4441 bit = SDE_PORTC_HOTPLUG_CPT;
4442 break;
4443 case PORT_D:
4444 bit = SDE_PORTD_HOTPLUG_CPT;
4445 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004446 case PORT_E:
4447 bit = SDE_PORTE_HOTPLUG_SPT;
4448 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004449 default:
4450 MISSING_CASE(port->port);
4451 return false;
Jani Nikulab93433c2015-08-20 10:47:36 +03004452 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004453
Jani Nikulab93433c2015-08-20 10:47:36 +03004454 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004455}
4456
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004457static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004458 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004459{
Jani Nikula9642c812015-08-20 10:47:41 +03004460 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004461
Jani Nikula9642c812015-08-20 10:47:41 +03004462 switch (port->port) {
4463 case PORT_B:
4464 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4465 break;
4466 case PORT_C:
4467 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4468 break;
4469 case PORT_D:
4470 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4471 break;
4472 default:
4473 MISSING_CASE(port->port);
4474 return false;
4475 }
4476
4477 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4478}
4479
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004480static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4481 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004482{
4483 u32 bit;
4484
4485 switch (port->port) {
4486 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004487 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004488 break;
4489 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004490 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004491 break;
4492 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004493 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004494 break;
4495 default:
4496 MISSING_CASE(port->port);
4497 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004498 }
4499
Jani Nikula1d245982015-08-20 10:47:37 +03004500 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004501}
4502
Jani Nikulae464bfd2015-08-20 10:47:42 +03004503static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304504 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004505{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304506 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4507 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004508 u32 bit;
4509
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304510 intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port);
4511 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004512 case PORT_A:
4513 bit = BXT_DE_PORT_HP_DDIA;
4514 break;
4515 case PORT_B:
4516 bit = BXT_DE_PORT_HP_DDIB;
4517 break;
4518 case PORT_C:
4519 bit = BXT_DE_PORT_HP_DDIC;
4520 break;
4521 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304522 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004523 return false;
4524 }
4525
4526 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4527}
4528
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004529/*
4530 * intel_digital_port_connected - is the specified port connected?
4531 * @dev_priv: i915 private structure
4532 * @port: the port to test
4533 *
4534 * Return %true if @port is connected, %false otherwise.
4535 */
Imre Deak390b4e02017-01-27 11:39:19 +02004536bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
4537 struct intel_digital_port *port)
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004538{
Jani Nikula0df53b72015-08-20 10:47:40 +03004539 if (HAS_PCH_IBX(dev_priv))
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004540 return ibx_digital_port_connected(dev_priv, port);
Ville Syrjälä22824fa2016-02-11 16:44:28 +02004541 else if (HAS_PCH_SPLIT(dev_priv))
Jani Nikula0df53b72015-08-20 10:47:40 +03004542 return cpt_digital_port_connected(dev_priv, port);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004543 else if (IS_GEN9_LP(dev_priv))
Jani Nikulae464bfd2015-08-20 10:47:42 +03004544 return bxt_digital_port_connected(dev_priv, port);
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004545 else if (IS_GM45(dev_priv))
4546 return gm45_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004547 else
4548 return g4x_digital_port_connected(dev_priv, port);
4549}
4550
Keith Packard8c241fe2011-09-28 16:38:44 -07004551static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004552intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004553{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004554 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004555
Jani Nikula9cd300e2012-10-19 14:51:52 +03004556 /* use cached edid if we have one */
4557 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004558 /* invalid edid */
4559 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004560 return NULL;
4561
Jani Nikula55e9ede2013-10-01 10:38:54 +03004562 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004563 } else
4564 return drm_get_edid(&intel_connector->base,
4565 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004566}
4567
Chris Wilsonbeb60602014-09-02 20:04:00 +01004568static void
4569intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004570{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004571 struct intel_connector *intel_connector = intel_dp->attached_connector;
4572 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004573
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304574 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004575 edid = intel_dp_get_edid(intel_dp);
4576 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004577
Chris Wilsonbeb60602014-09-02 20:04:00 +01004578 if (intel_dp->force_audio != HDMI_AUDIO_AUTO)
4579 intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON;
4580 else
4581 intel_dp->has_audio = drm_detect_monitor_audio(edid);
4582}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004583
Chris Wilsonbeb60602014-09-02 20:04:00 +01004584static void
4585intel_dp_unset_edid(struct intel_dp *intel_dp)
4586{
4587 struct intel_connector *intel_connector = intel_dp->attached_connector;
4588
4589 kfree(intel_connector->detect_edid);
4590 intel_connector->detect_edid = NULL;
4591
4592 intel_dp->has_audio = false;
4593}
4594
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004595static enum drm_connector_status
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304596intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004597{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304598 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004599 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004600 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4601 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004602 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004603 enum drm_connector_status status;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004604 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004605
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004606 intel_display_power_get(to_i915(dev), intel_dp->aux_power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004607
Chris Wilsond410b562014-09-02 20:03:59 +01004608 /* Can't disconnect eDP, but you can close the lid... */
4609 if (is_edp(intel_dp))
4610 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004611 else if (intel_digital_port_connected(to_i915(dev),
4612 dp_to_dig_port(intel_dp)))
4613 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004614 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004615 status = connector_status_disconnected;
4616
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004617 if (status == connector_status_disconnected) {
Manasi Navarec1617ab2016-12-09 16:22:50 -08004618 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304619
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004620 if (intel_dp->is_mst) {
4621 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4622 intel_dp->is_mst,
4623 intel_dp->mst_mgr.mst_state);
4624 intel_dp->is_mst = false;
4625 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4626 intel_dp->is_mst);
4627 }
4628
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004629 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304630 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004631
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304632 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004633 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304634
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004635 DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
4636 yesno(intel_dp_source_supports_hbr2(intel_dp)),
4637 yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
4638
Manasi Navared7e8ef02017-02-07 16:54:11 -08004639 if (intel_dp->reset_link_params) {
4640 /* Set the max lane count for sink */
4641 intel_dp->max_sink_lane_count = drm_dp_max_lane_count(intel_dp->dpcd);
Manasi Navaref4829842016-12-05 16:27:36 -08004642
Jani Nikulaa079d102017-04-06 16:44:09 +03004643 /* Set the max link rate for sink */
4644 intel_dp->max_sink_link_rate = intel_dp_max_sink_rate(intel_dp);
Manasi Navared7e8ef02017-02-07 16:54:11 -08004645
4646 intel_dp->reset_link_params = false;
4647 }
Manasi Navaref4829842016-12-05 16:27:36 -08004648
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004649 intel_dp_print_rates(intel_dp);
4650
Imre Deak7b3fc172016-10-25 16:12:39 +03004651 intel_dp_read_desc(intel_dp);
Mika Kahola0e390a32016-09-09 14:10:53 +03004652
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004653 intel_dp_configure_mst(intel_dp);
4654
4655 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304656 /*
4657 * If we are in MST mode then this connector
4658 * won't appear connected or have anything
4659 * with EDID on it
4660 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004661 status = connector_status_disconnected;
4662 goto out;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304663 } else if (connector->status == connector_status_connected) {
4664 /*
4665 * If display was connected already and is still connected
4666 * check links status, there has been known issues of
4667 * link loss triggerring long pulse!!!!
4668 */
4669 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4670 intel_dp_check_link_status(intel_dp);
4671 drm_modeset_unlock(&dev->mode_config.connection_mutex);
4672 goto out;
Dave Airlie0e32b392014-05-02 14:02:48 +10004673 }
4674
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304675 /*
4676 * Clearing NACK and defer counts to get their exact values
4677 * while reading EDID which are required by Compliance tests
4678 * 4.2.2.4 and 4.2.2.5
4679 */
4680 intel_dp->aux.i2c_nack_count = 0;
4681 intel_dp->aux.i2c_defer_count = 0;
4682
Chris Wilsonbeb60602014-09-02 20:04:00 +01004683 intel_dp_set_edid(intel_dp);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004684 if (is_edp(intel_dp) || intel_connector->detect_edid)
4685 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304686 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004687
Todd Previte09b1eb12015-04-20 15:27:34 -07004688 /* Try to read the source of the interrupt */
4689 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004690 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4691 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004692 /* Clear interrupt source */
4693 drm_dp_dpcd_writeb(&intel_dp->aux,
4694 DP_DEVICE_SERVICE_IRQ_VECTOR,
4695 sink_irq_vector);
4696
4697 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4698 intel_dp_handle_test_request(intel_dp);
4699 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4700 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4701 }
4702
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004703out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004704 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304705 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304706
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004707 intel_display_power_put(to_i915(dev), intel_dp->aux_power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004708 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304709}
4710
4711static enum drm_connector_status
4712intel_dp_detect(struct drm_connector *connector, bool force)
4713{
4714 struct intel_dp *intel_dp = intel_attached_dp(connector);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004715 enum drm_connector_status status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304716
4717 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4718 connector->base.id, connector->name);
4719
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304720 /* If full detect is not performed yet, do a full detect */
4721 if (!intel_dp->detect_done)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004722 status = intel_dp_long_pulse(intel_dp->attached_connector);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304723
4724 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304725
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004726 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004727}
4728
Chris Wilsonbeb60602014-09-02 20:04:00 +01004729static void
4730intel_dp_force(struct drm_connector *connector)
4731{
4732 struct intel_dp *intel_dp = intel_attached_dp(connector);
4733 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004734 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004735
4736 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4737 connector->base.id, connector->name);
4738 intel_dp_unset_edid(intel_dp);
4739
4740 if (connector->status != connector_status_connected)
4741 return;
4742
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004743 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004744
4745 intel_dp_set_edid(intel_dp);
4746
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004747 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004748
4749 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004750 intel_encoder->type = INTEL_OUTPUT_DP;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004751}
4752
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004753static int intel_dp_get_modes(struct drm_connector *connector)
4754{
Jani Nikuladd06f902012-10-19 14:51:50 +03004755 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004756 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004757
Chris Wilsonbeb60602014-09-02 20:04:00 +01004758 edid = intel_connector->detect_edid;
4759 if (edid) {
4760 int ret = intel_connector_update_modes(connector, edid);
4761 if (ret)
4762 return ret;
4763 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004764
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004765 /* if eDP has no EDID, fall back to fixed mode */
Chris Wilsonbeb60602014-09-02 20:04:00 +01004766 if (is_edp(intel_attached_dp(connector)) &&
4767 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004768 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004769
4770 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004771 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004772 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004773 drm_mode_probed_add(connector, mode);
4774 return 1;
4775 }
4776 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004777
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004778 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004779}
4780
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004781static bool
4782intel_dp_detect_audio(struct drm_connector *connector)
4783{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004784 bool has_audio = false;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004785 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004786
Chris Wilsonbeb60602014-09-02 20:04:00 +01004787 edid = to_intel_connector(connector)->detect_edid;
4788 if (edid)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004789 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02004790
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004791 return has_audio;
4792}
4793
Chris Wilsonf6849602010-09-19 09:29:33 +01004794static int
4795intel_dp_set_property(struct drm_connector *connector,
4796 struct drm_property *property,
4797 uint64_t val)
4798{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004799 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Yuly Novikov53b41832012-10-26 12:04:00 +03004800 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004801 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
4802 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01004803 int ret;
4804
Rob Clark662595d2012-10-11 20:36:04 -05004805 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01004806 if (ret)
4807 return ret;
4808
Chris Wilson3f43c482011-05-12 22:17:24 +01004809 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004810 int i = val;
4811 bool has_audio;
4812
4813 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004814 return 0;
4815
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004816 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01004817
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004818 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004819 has_audio = intel_dp_detect_audio(connector);
4820 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004821 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004822
4823 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004824 return 0;
4825
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004826 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01004827 goto done;
4828 }
4829
Chris Wilsone953fd72011-02-21 22:23:52 +00004830 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02004831 bool old_auto = intel_dp->color_range_auto;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004832 bool old_range = intel_dp->limited_color_range;
Daniel Vetterae4edb82013-04-22 17:07:23 +02004833
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004834 switch (val) {
4835 case INTEL_BROADCAST_RGB_AUTO:
4836 intel_dp->color_range_auto = true;
4837 break;
4838 case INTEL_BROADCAST_RGB_FULL:
4839 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004840 intel_dp->limited_color_range = false;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004841 break;
4842 case INTEL_BROADCAST_RGB_LIMITED:
4843 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004844 intel_dp->limited_color_range = true;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004845 break;
4846 default:
4847 return -EINVAL;
4848 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02004849
4850 if (old_auto == intel_dp->color_range_auto &&
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004851 old_range == intel_dp->limited_color_range)
Daniel Vetterae4edb82013-04-22 17:07:23 +02004852 return 0;
4853
Chris Wilsone953fd72011-02-21 22:23:52 +00004854 goto done;
4855 }
4856
Yuly Novikov53b41832012-10-26 12:04:00 +03004857 if (is_edp(intel_dp) &&
4858 property == connector->dev->mode_config.scaling_mode_property) {
4859 if (val == DRM_MODE_SCALE_NONE) {
4860 DRM_DEBUG_KMS("no scaling not supported\n");
4861 return -EINVAL;
4862 }
Ville Syrjälä234126c2016-04-12 22:14:38 +03004863 if (HAS_GMCH_DISPLAY(dev_priv) &&
4864 val == DRM_MODE_SCALE_CENTER) {
4865 DRM_DEBUG_KMS("centering not supported\n");
4866 return -EINVAL;
4867 }
Yuly Novikov53b41832012-10-26 12:04:00 +03004868
4869 if (intel_connector->panel.fitting_mode == val) {
4870 /* the eDP scaling property is not changed */
4871 return 0;
4872 }
4873 intel_connector->panel.fitting_mode = val;
4874
4875 goto done;
4876 }
4877
Chris Wilsonf6849602010-09-19 09:29:33 +01004878 return -EINVAL;
4879
4880done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00004881 if (intel_encoder->base.crtc)
4882 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01004883
4884 return 0;
4885}
4886
Chris Wilson7a418e32016-06-24 14:00:14 +01004887static int
4888intel_dp_connector_register(struct drm_connector *connector)
4889{
4890 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004891 int ret;
4892
4893 ret = intel_connector_register(connector);
4894 if (ret)
4895 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004896
4897 i915_debugfs_connector_add(connector);
4898
4899 DRM_DEBUG_KMS("registering %s bus for %s\n",
4900 intel_dp->aux.name, connector->kdev->kobj.name);
4901
4902 intel_dp->aux.dev = connector->kdev;
4903 return drm_dp_aux_register(&intel_dp->aux);
4904}
4905
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004906static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004907intel_dp_connector_unregister(struct drm_connector *connector)
4908{
4909 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4910 intel_connector_unregister(connector);
4911}
4912
4913static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004914intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004915{
Jani Nikula1d508702012-10-19 14:51:49 +03004916 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004917
Chris Wilson10e972d2014-09-04 21:43:45 +01004918 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004919
Jani Nikula9cd300e2012-10-19 14:51:52 +03004920 if (!IS_ERR_OR_NULL(intel_connector->edid))
4921 kfree(intel_connector->edid);
4922
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004923 /* Can't call is_edp() since the encoder may have been destroyed
4924 * already. */
4925 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004926 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004927
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004928 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004929 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004930}
4931
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004932void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004933{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004934 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4935 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004936
Dave Airlie0e32b392014-05-02 14:02:48 +10004937 intel_dp_mst_encoder_cleanup(intel_dig_port);
Keith Packardbd943152011-09-18 23:09:52 -07004938 if (is_edp(intel_dp)) {
4939 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004940 /*
4941 * vdd might still be enabled do to the delayed vdd off.
4942 * Make sure vdd is actually turned off here.
4943 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004944 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004945 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004946 pps_unlock(intel_dp);
4947
Clint Taylor01527b32014-07-07 13:01:46 -07004948 if (intel_dp->edp_notifier.notifier_call) {
4949 unregister_reboot_notifier(&intel_dp->edp_notifier);
4950 intel_dp->edp_notifier.notifier_call = NULL;
4951 }
Keith Packardbd943152011-09-18 23:09:52 -07004952 }
Chris Wilson99681882016-06-20 09:29:17 +01004953
4954 intel_dp_aux_fini(intel_dp);
4955
Imre Deakc8bd0e42014-12-12 17:57:38 +02004956 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004957 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004958}
4959
Imre Deakbf93ba62016-04-18 10:04:21 +03004960void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004961{
4962 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4963
4964 if (!is_edp(intel_dp))
4965 return;
4966
Ville Syrjälä951468f2014-09-04 14:55:31 +03004967 /*
4968 * vdd might still be enabled do to the delayed vdd off.
4969 * Make sure vdd is actually turned off here.
4970 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004971 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004972 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004973 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004974 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004975}
4976
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004977static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4978{
4979 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4980 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004981 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004982
4983 lockdep_assert_held(&dev_priv->pps_mutex);
4984
4985 if (!edp_have_panel_vdd(intel_dp))
4986 return;
4987
4988 /*
4989 * The VDD bit needs a power domain reference, so if the bit is
4990 * already enabled when we boot or resume, grab this reference and
4991 * schedule a vdd off, so we don't hold on to the reference
4992 * indefinitely.
4993 */
4994 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004995 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004996
4997 edp_panel_vdd_schedule_off(intel_dp);
4998}
4999
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005000static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
5001{
5002 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5003
5004 if ((intel_dp->DP & DP_PORT_EN) == 0)
5005 return INVALID_PIPE;
5006
5007 if (IS_CHERRYVIEW(dev_priv))
5008 return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
5009 else
5010 return PORT_TO_PIPE(intel_dp->DP);
5011}
5012
Imre Deakbf93ba62016-04-18 10:04:21 +03005013void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03005014{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005015 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Imre Deakdd75f6d2016-11-21 21:15:05 +02005016 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
5017 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005018
5019 if (!HAS_DDI(dev_priv))
5020 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005021
Imre Deakdd75f6d2016-11-21 21:15:05 +02005022 if (lspcon->active)
Shashank Sharma910530c2016-10-14 19:56:52 +05305023 lspcon_resume(lspcon);
5024
Manasi Navared7e8ef02017-02-07 16:54:11 -08005025 intel_dp->reset_link_params = true;
5026
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005027 pps_lock(intel_dp);
5028
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005029 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5030 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5031
5032 if (is_edp(intel_dp)) {
5033 /* Reinit the power sequencer, in case BIOS did something with it. */
5034 intel_dp_pps_init(encoder->dev, intel_dp);
5035 intel_edp_panel_vdd_sanitize(intel_dp);
5036 }
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005037
5038 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03005039}
5040
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005041static const struct drm_connector_funcs intel_dp_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02005042 .dpms = drm_atomic_helper_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005043 .detect = intel_dp_detect,
Chris Wilsonbeb60602014-09-02 20:04:00 +01005044 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005045 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01005046 .set_property = intel_dp_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -08005047 .atomic_get_property = intel_connector_atomic_get_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01005048 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01005049 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03005050 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08005051 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02005052 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005053};
5054
5055static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
5056 .get_modes = intel_dp_get_modes,
5057 .mode_valid = intel_dp_mode_valid,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005058};
5059
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005060static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03005061 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02005062 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005063};
5064
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005065enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10005066intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
5067{
5068 struct intel_dp *intel_dp = &intel_dig_port->dp;
Dave Airlie0e32b392014-05-02 14:02:48 +10005069 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005070 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005071 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03005072
Takashi Iwai25400582015-11-19 12:09:56 +01005073 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
5074 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Ville Syrjäläcca05022016-06-22 21:57:06 +03005075 intel_dig_port->base.type = INTEL_OUTPUT_DP;
Dave Airlie13cf5502014-06-18 11:29:35 +10005076
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005077 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
5078 /*
5079 * vdd off can generate a long pulse on eDP which
5080 * would require vdd on to handle it, and thus we
5081 * would end up in an endless cycle of
5082 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
5083 */
5084 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
5085 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d522015-02-10 14:11:46 +02005086 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005087 }
5088
Ville Syrjälä26fbb772014-08-11 18:37:37 +03005089 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
5090 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10005091 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10005092
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005093 if (long_hpd) {
Manasi Navared7e8ef02017-02-07 16:54:11 -08005094 intel_dp->reset_link_params = true;
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005095 intel_dp->detect_done = false;
5096 return IRQ_NONE;
5097 }
5098
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005099 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005100
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005101 if (intel_dp->is_mst) {
5102 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
5103 /*
5104 * If we were in MST mode, and device is not
5105 * there, get out of MST mode
5106 */
5107 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
5108 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
5109 intel_dp->is_mst = false;
5110 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
5111 intel_dp->is_mst);
5112 intel_dp->detect_done = false;
5113 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10005114 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005115 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005116
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005117 if (!intel_dp->is_mst) {
5118 if (!intel_dp_short_pulse(intel_dp)) {
5119 intel_dp->detect_done = false;
5120 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05305121 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005122 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005123
5124 ret = IRQ_HANDLED;
5125
Imre Deak1c767b32014-08-18 14:42:42 +03005126put_power:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005127 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005128
5129 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10005130}
5131
Rodrigo Vivi477ec322015-08-06 15:51:39 +08005132/* check the VBT to see whether the eDP is on another port */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005133bool intel_dp_is_edp(struct drm_i915_private *dev_priv, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08005134{
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005135 /*
5136 * eDP not supported on g4x. so bail out early just
5137 * for a bit extra safety in case the VBT is bonkers.
5138 */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005139 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005140 return false;
5141
Imre Deaka98d9c12016-12-21 12:17:24 +02005142 if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005143 return true;
5144
Jani Nikula951d9ef2016-03-16 12:43:31 +02005145 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08005146}
5147
Dave Airlie0e32b392014-05-02 14:02:48 +10005148void
Chris Wilsonf6849602010-09-19 09:29:33 +01005149intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
5150{
Yuly Novikov53b41832012-10-26 12:04:00 +03005151 struct intel_connector *intel_connector = to_intel_connector(connector);
5152
Chris Wilson3f43c482011-05-12 22:17:24 +01005153 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00005154 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02005155 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03005156
5157 if (is_edp(intel_dp)) {
5158 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05005159 drm_object_attach_property(
5160 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03005161 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03005162 DRM_MODE_SCALE_ASPECT);
5163 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03005164 }
Chris Wilsonf6849602010-09-19 09:29:33 +01005165}
5166
Imre Deakdada1a92014-01-29 13:25:41 +02005167static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
5168{
Abhay Kumard28d4732016-01-22 17:39:04 -08005169 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02005170 intel_dp->last_power_on = jiffies;
5171 intel_dp->last_backlight_off = jiffies;
5172}
5173
Daniel Vetter67a54562012-10-20 20:57:45 +02005174static void
Imre Deak54648612016-06-16 16:37:22 +03005175intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
5176 struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02005177{
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305178 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03005179 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07005180
Imre Deak8e8232d2016-06-16 16:37:21 +03005181 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02005182
5183 /* Workaround: Need to write PP_CONTROL with the unlock key as
5184 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305185 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02005186
Imre Deak8e8232d2016-06-16 16:37:21 +03005187 pp_on = I915_READ(regs.pp_on);
5188 pp_off = I915_READ(regs.pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005189 if (!IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005190 I915_WRITE(regs.pp_ctrl, pp_ctl);
5191 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305192 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005193
5194 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03005195 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
5196 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005197
Imre Deak54648612016-06-16 16:37:22 +03005198 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
5199 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005200
Imre Deak54648612016-06-16 16:37:22 +03005201 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
5202 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005203
Imre Deak54648612016-06-16 16:37:22 +03005204 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
5205 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005206
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005207 if (IS_GEN9_LP(dev_priv)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305208 u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
5209 BXT_POWER_CYCLE_DELAY_SHIFT;
5210 if (tmp > 0)
Imre Deak54648612016-06-16 16:37:22 +03005211 seq->t11_t12 = (tmp - 1) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305212 else
Imre Deak54648612016-06-16 16:37:22 +03005213 seq->t11_t12 = 0;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305214 } else {
Imre Deak54648612016-06-16 16:37:22 +03005215 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02005216 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305217 }
Imre Deak54648612016-06-16 16:37:22 +03005218}
5219
5220static void
Imre Deakde9c1b62016-06-16 20:01:46 +03005221intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
5222{
5223 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5224 state_name,
5225 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
5226}
5227
5228static void
5229intel_pps_verify_state(struct drm_i915_private *dev_priv,
5230 struct intel_dp *intel_dp)
5231{
5232 struct edp_power_seq hw;
5233 struct edp_power_seq *sw = &intel_dp->pps_delays;
5234
5235 intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
5236
5237 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
5238 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
5239 DRM_ERROR("PPS state mismatch\n");
5240 intel_pps_dump_state("sw", sw);
5241 intel_pps_dump_state("hw", &hw);
5242 }
5243}
5244
5245static void
Imre Deak54648612016-06-16 16:37:22 +03005246intel_dp_init_panel_power_sequencer(struct drm_device *dev,
5247 struct intel_dp *intel_dp)
5248{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005249 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak54648612016-06-16 16:37:22 +03005250 struct edp_power_seq cur, vbt, spec,
5251 *final = &intel_dp->pps_delays;
5252
5253 lockdep_assert_held(&dev_priv->pps_mutex);
5254
5255 /* already initialized? */
5256 if (final->t11_t12 != 0)
5257 return;
5258
5259 intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005260
Imre Deakde9c1b62016-06-16 20:01:46 +03005261 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005262
Jani Nikula6aa23e62016-03-24 17:50:20 +02005263 vbt = dev_priv->vbt.edp.pps;
Daniel Vetter67a54562012-10-20 20:57:45 +02005264
5265 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5266 * our hw here, which are all in 100usec. */
5267 spec.t1_t3 = 210 * 10;
5268 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5269 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5270 spec.t10 = 500 * 10;
5271 /* This one is special and actually in units of 100ms, but zero
5272 * based in the hw (so we need to add 100 ms). But the sw vbt
5273 * table multiplies it with 1000 to make it in units of 100usec,
5274 * too. */
5275 spec.t11_t12 = (510 + 100) * 10;
5276
Imre Deakde9c1b62016-06-16 20:01:46 +03005277 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005278
5279 /* Use the max of the register settings and vbt. If both are
5280 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005281#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005282 spec.field : \
5283 max(cur.field, vbt.field))
5284 assign_final(t1_t3);
5285 assign_final(t8);
5286 assign_final(t9);
5287 assign_final(t10);
5288 assign_final(t11_t12);
5289#undef assign_final
5290
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005291#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005292 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5293 intel_dp->backlight_on_delay = get_delay(t8);
5294 intel_dp->backlight_off_delay = get_delay(t9);
5295 intel_dp->panel_power_down_delay = get_delay(t10);
5296 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5297#undef get_delay
5298
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005299 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5300 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5301 intel_dp->panel_power_cycle_delay);
5302
5303 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5304 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005305
5306 /*
5307 * We override the HW backlight delays to 1 because we do manual waits
5308 * on them. For T8, even BSpec recommends doing it. For T9, if we
5309 * don't do this, we'll end up waiting for the backlight off delay
5310 * twice: once when we do the manual sleep, and once when we disable
5311 * the panel and wait for the PP_STATUS bit to become zero.
5312 */
5313 final->t8 = 1;
5314 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005315}
5316
5317static void
5318intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005319 struct intel_dp *intel_dp,
5320 bool force_disable_vdd)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005321{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005322 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07005323 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005324 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005325 struct pps_registers regs;
Ville Syrjäläad933b52014-08-18 22:15:56 +03005326 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005327 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005328
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005329 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005330
Imre Deak8e8232d2016-06-16 16:37:21 +03005331 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005332
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005333 /*
5334 * On some VLV machines the BIOS can leave the VDD
5335 * enabled even on power seqeuencers which aren't
5336 * hooked up to any port. This would mess up the
5337 * power domain tracking the first time we pick
5338 * one of these power sequencers for use since
5339 * edp_panel_vdd_on() would notice that the VDD was
5340 * already on and therefore wouldn't grab the power
5341 * domain reference. Disable VDD first to avoid this.
5342 * This also avoids spuriously turning the VDD on as
5343 * soon as the new power seqeuencer gets initialized.
5344 */
5345 if (force_disable_vdd) {
5346 u32 pp = ironlake_get_pp_control(intel_dp);
5347
5348 WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
5349
5350 if (pp & EDP_FORCE_VDD)
5351 DRM_DEBUG_KMS("VDD already on, disabling first\n");
5352
5353 pp &= ~EDP_FORCE_VDD;
5354
5355 I915_WRITE(regs.pp_ctrl, pp);
5356 }
5357
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005358 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005359 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5360 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005361 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005362 /* Compute the divisor for the pp clock, simply match the Bspec
5363 * formula. */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005364 if (IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005365 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305366 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
5367 pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
5368 << BXT_POWER_CYCLE_DELAY_SHIFT);
5369 } else {
5370 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5371 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5372 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5373 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005374
5375 /* Haswell doesn't have any port selection bits for the panel
5376 * power sequencer any more. */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005377 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005378 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005379 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005380 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005381 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005382 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005383 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005384 }
5385
Jesse Barnes453c5422013-03-28 09:55:41 -07005386 pp_on |= port_sel;
5387
Imre Deak8e8232d2016-06-16 16:37:21 +03005388 I915_WRITE(regs.pp_on, pp_on);
5389 I915_WRITE(regs.pp_off, pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005390 if (IS_GEN9_LP(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005391 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305392 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005393 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005394
Daniel Vetter67a54562012-10-20 20:57:45 +02005395 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 +03005396 I915_READ(regs.pp_on),
5397 I915_READ(regs.pp_off),
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005398 IS_GEN9_LP(dev_priv) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005399 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5400 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005401}
5402
Imre Deak335f7522016-08-10 14:07:32 +03005403static void intel_dp_pps_init(struct drm_device *dev,
5404 struct intel_dp *intel_dp)
5405{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005406 struct drm_i915_private *dev_priv = to_i915(dev);
5407
5408 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Imre Deak335f7522016-08-10 14:07:32 +03005409 vlv_initial_power_sequencer_setup(intel_dp);
5410 } else {
5411 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005412 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak335f7522016-08-10 14:07:32 +03005413 }
5414}
5415
Vandana Kannanb33a2812015-02-13 15:33:03 +05305416/**
5417 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005418 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005419 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305420 * @refresh_rate: RR to be programmed
5421 *
5422 * This function gets called when refresh rate (RR) has to be changed from
5423 * one frequency to another. Switches can be between high and low RR
5424 * supported by the panel or to any other RR based on media playback (in
5425 * this case, RR value needs to be passed from user space).
5426 *
5427 * The caller of this function needs to take a lock on dev_priv->drrs.
5428 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005429static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
5430 struct intel_crtc_state *crtc_state,
5431 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305432{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305433 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305434 struct intel_digital_port *dig_port = NULL;
5435 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005436 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305437 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305438
5439 if (refresh_rate <= 0) {
5440 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5441 return;
5442 }
5443
Vandana Kannan96178ee2015-01-10 02:25:56 +05305444 if (intel_dp == NULL) {
5445 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305446 return;
5447 }
5448
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005449 /*
Rodrigo Vivie4d59f62014-11-20 02:22:08 -08005450 * FIXME: This needs proper synchronization with psr state for some
5451 * platforms that cannot have PSR and DRRS enabled at the same time.
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005452 */
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305453
Vandana Kannan96178ee2015-01-10 02:25:56 +05305454 dig_port = dp_to_dig_port(intel_dp);
5455 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02005456 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305457
5458 if (!intel_crtc) {
5459 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5460 return;
5461 }
5462
Vandana Kannan96178ee2015-01-10 02:25:56 +05305463 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305464 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5465 return;
5466 }
5467
Vandana Kannan96178ee2015-01-10 02:25:56 +05305468 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5469 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305470 index = DRRS_LOW_RR;
5471
Vandana Kannan96178ee2015-01-10 02:25:56 +05305472 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305473 DRM_DEBUG_KMS(
5474 "DRRS requested for previously set RR...ignoring\n");
5475 return;
5476 }
5477
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005478 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305479 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5480 return;
5481 }
5482
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005483 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305484 switch (index) {
5485 case DRRS_HIGH_RR:
5486 intel_dp_set_m_n(intel_crtc, M1_N1);
5487 break;
5488 case DRRS_LOW_RR:
5489 intel_dp_set_m_n(intel_crtc, M2_N2);
5490 break;
5491 case DRRS_MAX_RR:
5492 default:
5493 DRM_ERROR("Unsupported refreshrate type\n");
5494 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005495 } else if (INTEL_GEN(dev_priv) > 6) {
5496 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005497 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305498
Ville Syrjälä649636e2015-09-22 19:50:01 +03005499 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305500 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005501 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305502 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5503 else
5504 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305505 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005506 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305507 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5508 else
5509 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305510 }
5511 I915_WRITE(reg, val);
5512 }
5513
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305514 dev_priv->drrs.refresh_rate_type = index;
5515
5516 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5517}
5518
Vandana Kannanb33a2812015-02-13 15:33:03 +05305519/**
5520 * intel_edp_drrs_enable - init drrs struct if supported
5521 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005522 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305523 *
5524 * Initializes frontbuffer_bits and drrs.dp
5525 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005526void intel_edp_drrs_enable(struct intel_dp *intel_dp,
5527 struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305528{
5529 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005530 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305531
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005532 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305533 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5534 return;
5535 }
5536
5537 mutex_lock(&dev_priv->drrs.mutex);
5538 if (WARN_ON(dev_priv->drrs.dp)) {
5539 DRM_ERROR("DRRS already enabled\n");
5540 goto unlock;
5541 }
5542
5543 dev_priv->drrs.busy_frontbuffer_bits = 0;
5544
5545 dev_priv->drrs.dp = intel_dp;
5546
5547unlock:
5548 mutex_unlock(&dev_priv->drrs.mutex);
5549}
5550
Vandana Kannanb33a2812015-02-13 15:33:03 +05305551/**
5552 * intel_edp_drrs_disable - Disable DRRS
5553 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005554 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305555 *
5556 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005557void intel_edp_drrs_disable(struct intel_dp *intel_dp,
5558 struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305559{
5560 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005561 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305562
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005563 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305564 return;
5565
5566 mutex_lock(&dev_priv->drrs.mutex);
5567 if (!dev_priv->drrs.dp) {
5568 mutex_unlock(&dev_priv->drrs.mutex);
5569 return;
5570 }
5571
5572 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005573 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5574 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305575
5576 dev_priv->drrs.dp = NULL;
5577 mutex_unlock(&dev_priv->drrs.mutex);
5578
5579 cancel_delayed_work_sync(&dev_priv->drrs.work);
5580}
5581
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305582static void intel_edp_drrs_downclock_work(struct work_struct *work)
5583{
5584 struct drm_i915_private *dev_priv =
5585 container_of(work, typeof(*dev_priv), drrs.work.work);
5586 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305587
Vandana Kannan96178ee2015-01-10 02:25:56 +05305588 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305589
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305590 intel_dp = dev_priv->drrs.dp;
5591
5592 if (!intel_dp)
5593 goto unlock;
5594
5595 /*
5596 * The delayed work can race with an invalidate hence we need to
5597 * recheck.
5598 */
5599
5600 if (dev_priv->drrs.busy_frontbuffer_bits)
5601 goto unlock;
5602
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005603 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5604 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5605
5606 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5607 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5608 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305609
5610unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305611 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305612}
5613
Vandana Kannanb33a2812015-02-13 15:33:03 +05305614/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305615 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005616 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305617 * @frontbuffer_bits: frontbuffer plane tracking bits
5618 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305619 * This function gets called everytime rendering on the given planes start.
5620 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305621 *
5622 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5623 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005624void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5625 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305626{
Vandana Kannana93fad02015-01-10 02:25:59 +05305627 struct drm_crtc *crtc;
5628 enum pipe pipe;
5629
Daniel Vetter9da7d692015-04-09 16:44:15 +02005630 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305631 return;
5632
Daniel Vetter88f933a2015-04-09 16:44:16 +02005633 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305634
Vandana Kannana93fad02015-01-10 02:25:59 +05305635 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005636 if (!dev_priv->drrs.dp) {
5637 mutex_unlock(&dev_priv->drrs.mutex);
5638 return;
5639 }
5640
Vandana Kannana93fad02015-01-10 02:25:59 +05305641 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5642 pipe = to_intel_crtc(crtc)->pipe;
5643
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005644 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5645 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5646
Ramalingam C0ddfd202015-06-15 20:50:05 +05305647 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005648 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005649 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5650 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305651
Vandana Kannana93fad02015-01-10 02:25:59 +05305652 mutex_unlock(&dev_priv->drrs.mutex);
5653}
5654
Vandana Kannanb33a2812015-02-13 15:33:03 +05305655/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305656 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005657 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305658 * @frontbuffer_bits: frontbuffer plane tracking bits
5659 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305660 * This function gets called every time rendering on the given planes has
5661 * completed or flip on a crtc is completed. So DRRS should be upclocked
5662 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5663 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305664 *
5665 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5666 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005667void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5668 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305669{
Vandana Kannana93fad02015-01-10 02:25:59 +05305670 struct drm_crtc *crtc;
5671 enum pipe pipe;
5672
Daniel Vetter9da7d692015-04-09 16:44:15 +02005673 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305674 return;
5675
Daniel Vetter88f933a2015-04-09 16:44:16 +02005676 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305677
Vandana Kannana93fad02015-01-10 02:25:59 +05305678 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005679 if (!dev_priv->drrs.dp) {
5680 mutex_unlock(&dev_priv->drrs.mutex);
5681 return;
5682 }
5683
Vandana Kannana93fad02015-01-10 02:25:59 +05305684 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5685 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005686
5687 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305688 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5689
Ramalingam C0ddfd202015-06-15 20:50:05 +05305690 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005691 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005692 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5693 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305694
5695 /*
5696 * flush also means no more activity hence schedule downclock, if all
5697 * other fbs are quiescent too
5698 */
5699 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305700 schedule_delayed_work(&dev_priv->drrs.work,
5701 msecs_to_jiffies(1000));
5702 mutex_unlock(&dev_priv->drrs.mutex);
5703}
5704
Vandana Kannanb33a2812015-02-13 15:33:03 +05305705/**
5706 * DOC: Display Refresh Rate Switching (DRRS)
5707 *
5708 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5709 * which enables swtching between low and high refresh rates,
5710 * dynamically, based on the usage scenario. This feature is applicable
5711 * for internal panels.
5712 *
5713 * Indication that the panel supports DRRS is given by the panel EDID, which
5714 * would list multiple refresh rates for one resolution.
5715 *
5716 * DRRS is of 2 types - static and seamless.
5717 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5718 * (may appear as a blink on screen) and is used in dock-undock scenario.
5719 * Seamless DRRS involves changing RR without any visual effect to the user
5720 * and can be used during normal system usage. This is done by programming
5721 * certain registers.
5722 *
5723 * Support for static/seamless DRRS may be indicated in the VBT based on
5724 * inputs from the panel spec.
5725 *
5726 * DRRS saves power by switching to low RR based on usage scenarios.
5727 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005728 * The implementation is based on frontbuffer tracking implementation. When
5729 * there is a disturbance on the screen triggered by user activity or a periodic
5730 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5731 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5732 * made.
5733 *
5734 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5735 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305736 *
5737 * DRRS can be further extended to support other internal panels and also
5738 * the scenario of video playback wherein RR is set based on the rate
5739 * requested by userspace.
5740 */
5741
5742/**
5743 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5744 * @intel_connector: eDP connector
5745 * @fixed_mode: preferred mode of panel
5746 *
5747 * This function is called only once at driver load to initialize basic
5748 * DRRS stuff.
5749 *
5750 * Returns:
5751 * Downclock mode if panel supports it, else return NULL.
5752 * DRRS support is determined by the presence of downclock mode (apart
5753 * from VBT setting).
5754 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305755static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305756intel_dp_drrs_init(struct intel_connector *intel_connector,
5757 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305758{
5759 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305760 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005761 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305762 struct drm_display_mode *downclock_mode = NULL;
5763
Daniel Vetter9da7d692015-04-09 16:44:15 +02005764 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5765 mutex_init(&dev_priv->drrs.mutex);
5766
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005767 if (INTEL_GEN(dev_priv) <= 6) {
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305768 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5769 return NULL;
5770 }
5771
5772 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005773 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305774 return NULL;
5775 }
5776
5777 downclock_mode = intel_find_panel_downclock
Mika Kaholaa318b4c2016-12-13 10:02:48 +02005778 (dev_priv, fixed_mode, connector);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305779
5780 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305781 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305782 return NULL;
5783 }
5784
Vandana Kannan96178ee2015-01-10 02:25:56 +05305785 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305786
Vandana Kannan96178ee2015-01-10 02:25:56 +05305787 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005788 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305789 return downclock_mode;
5790}
5791
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005792static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005793 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005794{
5795 struct drm_connector *connector = &intel_connector->base;
5796 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005797 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5798 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005799 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005800 struct drm_display_mode *fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305801 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005802 bool has_dpcd;
5803 struct drm_display_mode *scan;
5804 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005805 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005806
5807 if (!is_edp(intel_dp))
5808 return true;
5809
Imre Deak97a824e12016-06-21 11:51:47 +03005810 /*
5811 * On IBX/CPT we may get here with LVDS already registered. Since the
5812 * driver uses the only internal power sequencer available for both
5813 * eDP and LVDS bail out early in this case to prevent interfering
5814 * with an already powered-on LVDS power sequencer.
5815 */
5816 if (intel_get_lvds_encoder(dev)) {
5817 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5818 DRM_INFO("LVDS was detected, not registering eDP\n");
5819
5820 return false;
5821 }
5822
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005823 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005824
5825 intel_dp_init_panel_power_timestamps(intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +03005826 intel_dp_pps_init(dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005827 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005828
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005829 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005830
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005831 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005832 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005833
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005834 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005835 /* if this fails, presume the device is a ghost */
5836 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005837 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005838 }
5839
Daniel Vetter060c8772014-03-21 23:22:35 +01005840 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005841 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005842 if (edid) {
5843 if (drm_add_edid_modes(connector, edid)) {
5844 drm_mode_connector_update_edid_property(connector,
5845 edid);
5846 drm_edid_to_eld(connector, edid);
5847 } else {
5848 kfree(edid);
5849 edid = ERR_PTR(-EINVAL);
5850 }
5851 } else {
5852 edid = ERR_PTR(-ENOENT);
5853 }
5854 intel_connector->edid = edid;
5855
5856 /* prefer fixed mode from EDID if available */
5857 list_for_each_entry(scan, &connector->probed_modes, head) {
5858 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5859 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305860 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305861 intel_connector, fixed_mode);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005862 break;
5863 }
5864 }
5865
5866 /* fallback to VBT if available for eDP */
5867 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5868 fixed_mode = drm_mode_duplicate(dev,
5869 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005870 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005871 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005872 connector->display_info.width_mm = fixed_mode->width_mm;
5873 connector->display_info.height_mm = fixed_mode->height_mm;
5874 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005875 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005876 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005877
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005878 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005879 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5880 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005881
5882 /*
5883 * Figure out the current pipe for the initial backlight setup.
5884 * If the current pipe isn't valid, try the PPS pipe, and if that
5885 * fails just assume pipe A.
5886 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005887 pipe = vlv_active_pipe(intel_dp);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005888
5889 if (pipe != PIPE_A && pipe != PIPE_B)
5890 pipe = intel_dp->pps_pipe;
5891
5892 if (pipe != PIPE_A && pipe != PIPE_B)
5893 pipe = PIPE_A;
5894
5895 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5896 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005897 }
5898
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305899 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005900 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005901 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005902
5903 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005904
5905out_vdd_off:
5906 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5907 /*
5908 * vdd might still be enabled do to the delayed vdd off.
5909 * Make sure vdd is actually turned off here.
5910 */
5911 pps_lock(intel_dp);
5912 edp_panel_vdd_off_sync(intel_dp);
5913 pps_unlock(intel_dp);
5914
5915 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005916}
5917
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005918/* Set up the hotplug pin and aux power domain. */
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005919static void
5920intel_dp_init_connector_port_info(struct intel_digital_port *intel_dig_port)
5921{
5922 struct intel_encoder *encoder = &intel_dig_port->base;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005923 struct intel_dp *intel_dp = &intel_dig_port->dp;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005924
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005925 switch (intel_dig_port->port) {
5926 case PORT_A:
5927 encoder->hpd_pin = HPD_PORT_A;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005928 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_A;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005929 break;
5930 case PORT_B:
5931 encoder->hpd_pin = HPD_PORT_B;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005932 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_B;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005933 break;
5934 case PORT_C:
5935 encoder->hpd_pin = HPD_PORT_C;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005936 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_C;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005937 break;
5938 case PORT_D:
5939 encoder->hpd_pin = HPD_PORT_D;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005940 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005941 break;
5942 case PORT_E:
5943 encoder->hpd_pin = HPD_PORT_E;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005944
5945 /* FIXME: Check VBT for actual wiring of PORT E */
5946 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005947 break;
5948 default:
5949 MISSING_CASE(intel_dig_port->port);
5950 }
5951}
5952
Paulo Zanoni16c25532013-06-12 17:27:25 -03005953bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005954intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5955 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005956{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005957 struct drm_connector *connector = &intel_connector->base;
5958 struct intel_dp *intel_dp = &intel_dig_port->dp;
5959 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5960 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005961 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02005962 enum port port = intel_dig_port->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01005963 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005964
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005965 if (WARN(intel_dig_port->max_lanes < 1,
5966 "Not enough lanes (%d) for DP on port %c\n",
5967 intel_dig_port->max_lanes, port_name(port)))
5968 return false;
5969
Jani Nikula55cfc582017-03-28 17:59:04 +03005970 intel_dp_set_source_rates(intel_dp);
5971
Manasi Navared7e8ef02017-02-07 16:54:11 -08005972 intel_dp->reset_link_params = true;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005973 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005974 intel_dp->active_pipe = INVALID_PIPE;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005975
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005976 /* intel_dp vfuncs */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005977 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub6b5e382014-01-20 16:00:59 +00005978 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005979 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005980 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005981 else if (HAS_PCH_SPLIT(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005982 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
5983 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005984 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005985
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005986 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00005987 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
5988 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005989 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00005990
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005991 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03005992 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
5993
Daniel Vetter07679352012-09-06 22:15:42 +02005994 /* Preserve the current hw state. */
5995 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03005996 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00005997
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005998 if (intel_dp_is_edp(dev_priv, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05305999 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02006000 else
6001 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04006002
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02006003 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
6004 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
6005
Imre Deakf7d24902013-05-08 13:14:05 +03006006 /*
6007 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
6008 * for DP the encoder type can be set by the caller to
6009 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
6010 */
6011 if (type == DRM_MODE_CONNECTOR_eDP)
6012 intel_encoder->type = INTEL_OUTPUT_EDP;
6013
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006014 /* eDP only on port B and/or C on vlv/chv */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006015 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08006016 is_edp(intel_dp) && port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006017 return false;
6018
Imre Deake7281ea2013-05-08 13:14:08 +03006019 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
6020 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
6021 port_name(port));
6022
Adam Jacksonb3295302010-07-16 14:46:28 -04006023 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006024 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
6025
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006026 connector->interlace_allowed = true;
6027 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08006028
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02006029 intel_dp_init_connector_port_info(intel_dig_port);
6030
Mika Kaholab6339582016-09-09 14:10:52 +03006031 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01006032
Daniel Vetter66a92782012-07-12 20:08:18 +02006033 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01006034 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08006035
Chris Wilsondf0e9242010-09-09 16:20:55 +01006036 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006037
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006038 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02006039 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
6040 else
6041 intel_connector->get_hw_state = intel_connector_get_hw_state;
6042
Dave Airlie0e32b392014-05-02 14:02:48 +10006043 /* init MST on ports that can support it */
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00006044 if (HAS_DP_MST(dev_priv) && !is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03006045 (port == PORT_B || port == PORT_C || port == PORT_D))
6046 intel_dp_mst_encoder_init(intel_dig_port,
6047 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10006048
Ville Syrjälä36b5f422014-10-16 21:27:30 +03006049 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006050 intel_dp_aux_fini(intel_dp);
6051 intel_dp_mst_encoder_cleanup(intel_dig_port);
6052 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03006053 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08006054
Chris Wilsonf6849602010-09-19 09:29:33 +01006055 intel_dp_add_properties(intel_dp, connector);
6056
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006057 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
6058 * 0xd. Failure to do so will result in spurious interrupts being
6059 * generated on the port when a cable is not attached.
6060 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01006061 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006062 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
6063 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
6064 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03006065
6066 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006067
6068fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006069 drm_connector_cleanup(connector);
6070
6071 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006072}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006073
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006074bool intel_dp_init(struct drm_i915_private *dev_priv,
Chris Wilson457c52d2016-06-01 08:27:50 +01006075 i915_reg_t output_reg,
6076 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006077{
6078 struct intel_digital_port *intel_dig_port;
6079 struct intel_encoder *intel_encoder;
6080 struct drm_encoder *encoder;
6081 struct intel_connector *intel_connector;
6082
Daniel Vetterb14c5672013-09-19 12:18:32 +02006083 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006084 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01006085 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006086
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03006087 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306088 if (!intel_connector)
6089 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006090
6091 intel_encoder = &intel_dig_port->base;
6092 encoder = &intel_encoder->base;
6093
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006094 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
6095 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
6096 "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306097 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006098
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01006099 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006100 intel_encoder->disable = intel_disable_dp;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006101 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07006102 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03006103 intel_encoder->suspend = intel_dp_encoder_suspend;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006104 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03006105 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03006106 intel_encoder->pre_enable = chv_pre_enable_dp;
6107 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03006108 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03006109 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01006110 } else if (IS_VALLEYVIEW(dev_priv)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006111 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006112 intel_encoder->pre_enable = vlv_pre_enable_dp;
6113 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03006114 intel_encoder->post_disable = vlv_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006115 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006116 intel_encoder->pre_enable = g4x_pre_enable_dp;
6117 intel_encoder->enable = g4x_enable_dp;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006118 if (INTEL_GEN(dev_priv) >= 5)
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03006119 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006120 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006121
Paulo Zanoni174edf12012-10-26 19:05:50 -02006122 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006123 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02006124 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006125
Ville Syrjäläcca05022016-06-22 21:57:06 +03006126 intel_encoder->type = INTEL_OUTPUT_DP;
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02006127 intel_encoder->power_domain = intel_port_to_power_domain(port);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006128 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03006129 if (port == PORT_D)
6130 intel_encoder->crtc_mask = 1 << 2;
6131 else
6132 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
6133 } else {
6134 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
6135 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02006136 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07006137 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006138
Dave Airlie13cf5502014-06-18 11:29:35 +10006139 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03006140 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10006141
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306142 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
6143 goto err_init_connector;
6144
Chris Wilson457c52d2016-06-01 08:27:50 +01006145 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306146
6147err_init_connector:
6148 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306149err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306150 kfree(intel_connector);
6151err_connector_alloc:
6152 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01006153 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006154}
Dave Airlie0e32b392014-05-02 14:02:48 +10006155
6156void intel_dp_mst_suspend(struct drm_device *dev)
6157{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006158 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006159 int i;
6160
6161 /* disable MST */
6162 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006163 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006164
6165 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006166 continue;
6167
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006168 if (intel_dig_port->dp.is_mst)
6169 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10006170 }
6171}
6172
6173void intel_dp_mst_resume(struct drm_device *dev)
6174{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006175 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006176 int i;
6177
6178 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006179 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006180 int ret;
6181
6182 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006183 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10006184
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006185 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
6186 if (ret)
6187 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10006188 }
6189}