blob: 9fc066dda4e0cdc70117de81d7cb0b744bde6bef [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
Ville Syrjäläed4e9c12015-03-12 17:10:36 +0200136static int
137intel_dp_max_link_bw(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700138{
Jesse Barnes7183dc22011-07-07 11:10:58 -0700139 int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700140
141 switch (max_link_bw) {
142 case DP_LINK_BW_1_62:
143 case DP_LINK_BW_2_7:
Ville Syrjälä1db10e22015-03-12 17:10:32 +0200144 case DP_LINK_BW_5_4:
Imre Deakd4eead52013-07-09 17:05:26 +0300145 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700146 default:
Imre Deakd4eead52013-07-09 17:05:26 +0300147 WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
148 max_link_bw);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700149 max_link_bw = DP_LINK_BW_1_62;
150 break;
151 }
152 return max_link_bw;
153}
154
Paulo Zanonieeb63242014-05-06 14:56:50 +0300155static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
156{
157 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300158 u8 source_max, sink_max;
159
Ville Syrjäläccb1a832015-12-08 19:59:38 +0200160 source_max = intel_dig_port->max_lanes;
Manasi Navaref4829842016-12-05 16:27:36 -0800161 sink_max = intel_dp->max_sink_lane_count;
Paulo Zanonieeb63242014-05-06 14:56:50 +0300162
163 return min(source_max, sink_max);
164}
165
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800166int
Keith Packardc8982612012-01-25 08:16:25 -0800167intel_dp_link_required(int pixel_clock, int bpp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700168{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800169 /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
170 return DIV_ROUND_UP(pixel_clock * bpp, 8);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700171}
172
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800173int
Dave Airliefe27d532010-06-30 11:46:17 +1000174intel_dp_max_data_rate(int max_link_clock, int max_lanes)
175{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800176 /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
177 * link rate that is generally expressed in Gbps. Since, 8 bits of data
178 * is transmitted every LS_Clk per lane, there is no need to account for
179 * the channel encoding that is done in the PHY layer here.
180 */
181
182 return max_link_clock * max_lanes;
Dave Airliefe27d532010-06-30 11:46:17 +1000183}
184
Mika Kahola70ec0642016-09-09 14:10:55 +0300185static int
186intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp)
187{
188 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
189 struct intel_encoder *encoder = &intel_dig_port->base;
190 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
191 int max_dotclk = dev_priv->max_dotclk_freq;
192 int ds_max_dotclk;
193
194 int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
195
196 if (type != DP_DS_PORT_TYPE_VGA)
197 return max_dotclk;
198
199 ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd,
200 intel_dp->downstream_ports);
201
202 if (ds_max_dotclk != 0)
203 max_dotclk = min(max_dotclk, ds_max_dotclk);
204
205 return max_dotclk;
206}
207
Navare, Manasi D40dba342016-10-26 16:25:55 -0700208static int
209intel_dp_sink_rates(struct intel_dp *intel_dp, const int **sink_rates)
210{
211 if (intel_dp->num_sink_rates) {
212 *sink_rates = intel_dp->sink_rates;
213 return intel_dp->num_sink_rates;
214 }
215
216 *sink_rates = default_rates;
217
Manasi Navaref4829842016-12-05 16:27:36 -0800218 return (intel_dp->max_sink_link_bw >> 3) + 1;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700219}
220
221static int
222intel_dp_source_rates(struct intel_dp *intel_dp, const int **source_rates)
223{
224 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
225 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
226 int size;
227
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200228 if (IS_GEN9_LP(dev_priv)) {
Navare, Manasi D40dba342016-10-26 16:25:55 -0700229 *source_rates = bxt_rates;
230 size = ARRAY_SIZE(bxt_rates);
Rodrigo Vivib976dc52017-01-23 10:32:37 -0800231 } else if (IS_GEN9_BC(dev_priv)) {
Navare, Manasi D40dba342016-10-26 16:25:55 -0700232 *source_rates = skl_rates;
233 size = ARRAY_SIZE(skl_rates);
234 } else {
235 *source_rates = default_rates;
236 size = ARRAY_SIZE(default_rates);
237 }
238
239 /* This depends on the fact that 5.4 is last value in the array */
240 if (!intel_dp_source_supports_hbr2(intel_dp))
241 size--;
242
243 return size;
244}
245
246static int intersect_rates(const int *source_rates, int source_len,
247 const int *sink_rates, int sink_len,
248 int *common_rates)
249{
250 int i = 0, j = 0, k = 0;
251
252 while (i < source_len && j < sink_len) {
253 if (source_rates[i] == sink_rates[j]) {
254 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
255 return k;
256 common_rates[k] = source_rates[i];
257 ++k;
258 ++i;
259 ++j;
260 } else if (source_rates[i] < sink_rates[j]) {
261 ++i;
262 } else {
263 ++j;
264 }
265 }
266 return k;
267}
268
Jani Nikula8001b752017-03-28 17:59:03 +0300269/* return index of rate in rates array, or -1 if not found */
270static int intel_dp_rate_index(const int *rates, int len, int rate)
271{
272 int i;
273
274 for (i = 0; i < len; i++)
275 if (rate == rates[i])
276 return i;
277
278 return -1;
279}
280
Navare, Manasi D40dba342016-10-26 16:25:55 -0700281static int intel_dp_common_rates(struct intel_dp *intel_dp,
282 int *common_rates)
283{
284 const int *source_rates, *sink_rates;
285 int source_len, sink_len;
286
287 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
288 source_len = intel_dp_source_rates(intel_dp, &source_rates);
289
290 return intersect_rates(source_rates, source_len,
291 sink_rates, sink_len,
292 common_rates);
293}
294
Manasi Navarefdb14d32016-12-08 19:05:12 -0800295static int intel_dp_link_rate_index(struct intel_dp *intel_dp,
296 int *common_rates, int link_rate)
297{
298 int common_len;
Manasi Navarefdb14d32016-12-08 19:05:12 -0800299
300 common_len = intel_dp_common_rates(intel_dp, common_rates);
Manasi Navarefdb14d32016-12-08 19:05:12 -0800301
Jani Nikula8001b752017-03-28 17:59:03 +0300302 return intel_dp_rate_index(common_rates, common_len, link_rate);
Manasi Navarefdb14d32016-12-08 19:05:12 -0800303}
304
305int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
306 int link_rate, uint8_t lane_count)
307{
308 int common_rates[DP_MAX_SUPPORTED_RATES];
309 int link_rate_index;
310
311 link_rate_index = intel_dp_link_rate_index(intel_dp,
312 common_rates,
313 link_rate);
314 if (link_rate_index > 0) {
315 intel_dp->max_sink_link_bw = drm_dp_link_rate_to_bw_code(common_rates[link_rate_index - 1]);
316 intel_dp->max_sink_lane_count = lane_count;
317 } else if (lane_count > 1) {
318 intel_dp->max_sink_link_bw = intel_dp_max_link_bw(intel_dp);
319 intel_dp->max_sink_lane_count = lane_count >> 1;
320 } else {
321 DRM_ERROR("Link Training Unsuccessful\n");
322 return -1;
323 }
324
325 return 0;
326}
327
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000328static enum drm_mode_status
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700329intel_dp_mode_valid(struct drm_connector *connector,
330 struct drm_display_mode *mode)
331{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100332 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300333 struct intel_connector *intel_connector = to_intel_connector(connector);
334 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Daniel Vetter36008362013-03-27 00:44:59 +0100335 int target_clock = mode->clock;
336 int max_rate, mode_rate, max_lanes, max_link_clock;
Mika Kahola70ec0642016-09-09 14:10:55 +0300337 int max_dotclk;
338
339 max_dotclk = intel_dp_downstream_max_dotclock(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700340
Jani Nikuladd06f902012-10-19 14:51:50 +0300341 if (is_edp(intel_dp) && fixed_mode) {
342 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100343 return MODE_PANEL;
344
Jani Nikuladd06f902012-10-19 14:51:50 +0300345 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100346 return MODE_PANEL;
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200347
348 target_clock = fixed_mode->clock;
Zhao Yakui7de56f42010-07-19 09:43:14 +0100349 }
350
Ville Syrjälä50fec212015-03-12 17:10:34 +0200351 max_link_clock = intel_dp_max_link_rate(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300352 max_lanes = intel_dp_max_lane_count(intel_dp);
Daniel Vetter36008362013-03-27 00:44:59 +0100353
354 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
355 mode_rate = intel_dp_link_required(target_clock, 18);
356
Mika Kahola799487f2016-02-02 15:16:38 +0200357 if (mode_rate > max_rate || target_clock > max_dotclk)
Daniel Vetterc4867932012-04-10 10:42:36 +0200358 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700359
360 if (mode->clock < 10000)
361 return MODE_CLOCK_LOW;
362
Daniel Vetter0af78a22012-05-23 11:30:55 +0200363 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
364 return MODE_H_ILLEGAL;
365
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700366 return MODE_OK;
367}
368
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800369uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700370{
371 int i;
372 uint32_t v = 0;
373
374 if (src_bytes > 4)
375 src_bytes = 4;
376 for (i = 0; i < src_bytes; i++)
377 v |= ((uint32_t) src[i]) << ((3-i) * 8);
378 return v;
379}
380
Damien Lespiauc2af70e2015-02-10 19:32:23 +0000381static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700382{
383 int i;
384 if (dst_bytes > 4)
385 dst_bytes = 4;
386 for (i = 0; i < dst_bytes; i++)
387 dst[i] = src >> ((3-i) * 8);
388}
389
Jani Nikulabf13e812013-09-06 07:40:05 +0300390static void
391intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300392 struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300393static void
394intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200395 struct intel_dp *intel_dp,
396 bool force_disable_vdd);
Imre Deak335f7522016-08-10 14:07:32 +0300397static void
398intel_dp_pps_init(struct drm_device *dev, struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300399
Ville Syrjälä773538e82014-09-04 14:54:56 +0300400static void pps_lock(struct intel_dp *intel_dp)
401{
402 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
403 struct intel_encoder *encoder = &intel_dig_port->base;
404 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100405 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300406
407 /*
408 * See vlv_power_sequencer_reset() why we need
409 * a power domain reference here.
410 */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +0200411 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300412
413 mutex_lock(&dev_priv->pps_mutex);
414}
415
416static void pps_unlock(struct intel_dp *intel_dp)
417{
418 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
419 struct intel_encoder *encoder = &intel_dig_port->base;
420 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100421 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300422
423 mutex_unlock(&dev_priv->pps_mutex);
424
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +0200425 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300426}
427
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300428static void
429vlv_power_sequencer_kick(struct intel_dp *intel_dp)
430{
431 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200432 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300433 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300434 bool pll_enabled, release_cl_override = false;
435 enum dpio_phy phy = DPIO_PHY(pipe);
436 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300437 uint32_t DP;
438
439 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
440 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
441 pipe_name(pipe), port_name(intel_dig_port->port)))
442 return;
443
444 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
445 pipe_name(pipe), port_name(intel_dig_port->port));
446
447 /* Preserve the BIOS-computed detected bit. This is
448 * supposed to be read-only.
449 */
450 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
451 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
452 DP |= DP_PORT_WIDTH(1);
453 DP |= DP_LINK_TRAIN_PAT_1;
454
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100455 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300456 DP |= DP_PIPE_SELECT_CHV(pipe);
457 else if (pipe == PIPE_B)
458 DP |= DP_PIPEB_SELECT;
459
Ville Syrjäläd288f652014-10-28 13:20:22 +0200460 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
461
462 /*
463 * The DPLL for the pipe must be enabled for this to work.
464 * So enable temporarily it if it's not already enabled.
465 */
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300466 if (!pll_enabled) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100467 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300468 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
469
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200470 if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ?
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000471 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
472 DRM_ERROR("Failed to force on pll for pipe %c!\n",
473 pipe_name(pipe));
474 return;
475 }
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300476 }
Ville Syrjäläd288f652014-10-28 13:20:22 +0200477
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300478 /*
479 * Similar magic as in intel_dp_enable_port().
480 * We _must_ do this port enable + disable trick
481 * to make this power seqeuencer lock onto the port.
482 * Otherwise even VDD force bit won't work.
483 */
484 I915_WRITE(intel_dp->output_reg, DP);
485 POSTING_READ(intel_dp->output_reg);
486
487 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
488 POSTING_READ(intel_dp->output_reg);
489
490 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
491 POSTING_READ(intel_dp->output_reg);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200492
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300493 if (!pll_enabled) {
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200494 vlv_force_pll_off(dev_priv, pipe);
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300495
496 if (release_cl_override)
497 chv_phy_powergate_ch(dev_priv, phy, ch, false);
498 }
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300499}
500
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200501static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv)
502{
503 struct intel_encoder *encoder;
504 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
505
506 /*
507 * We don't have power sequencer currently.
508 * Pick one that's not used by other ports.
509 */
510 for_each_intel_encoder(&dev_priv->drm, encoder) {
511 struct intel_dp *intel_dp;
512
513 if (encoder->type != INTEL_OUTPUT_DP &&
514 encoder->type != INTEL_OUTPUT_EDP)
515 continue;
516
517 intel_dp = enc_to_intel_dp(&encoder->base);
518
519 if (encoder->type == INTEL_OUTPUT_EDP) {
520 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
521 intel_dp->active_pipe != intel_dp->pps_pipe);
522
523 if (intel_dp->pps_pipe != INVALID_PIPE)
524 pipes &= ~(1 << intel_dp->pps_pipe);
525 } else {
526 WARN_ON(intel_dp->pps_pipe != INVALID_PIPE);
527
528 if (intel_dp->active_pipe != INVALID_PIPE)
529 pipes &= ~(1 << intel_dp->active_pipe);
530 }
531 }
532
533 if (pipes == 0)
534 return INVALID_PIPE;
535
536 return ffs(pipes) - 1;
537}
538
Jani Nikulabf13e812013-09-06 07:40:05 +0300539static enum pipe
540vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
541{
542 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300543 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100544 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300545 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300546
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300547 lockdep_assert_held(&dev_priv->pps_mutex);
548
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300549 /* We should never land here with regular DP ports */
550 WARN_ON(!is_edp(intel_dp));
551
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200552 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
553 intel_dp->active_pipe != intel_dp->pps_pipe);
554
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300555 if (intel_dp->pps_pipe != INVALID_PIPE)
556 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300557
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200558 pipe = vlv_find_free_pps(dev_priv);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300559
560 /*
561 * Didn't find one. This should not happen since there
562 * are two power sequencers and up to two eDP ports.
563 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200564 if (WARN_ON(pipe == INVALID_PIPE))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300565 pipe = PIPE_A;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300566
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300567 vlv_steal_power_sequencer(dev, pipe);
568 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300569
570 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
571 pipe_name(intel_dp->pps_pipe),
572 port_name(intel_dig_port->port));
573
574 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300575 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200576 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300577
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300578 /*
579 * Even vdd force doesn't work until we've made
580 * the power sequencer lock in on the port.
581 */
582 vlv_power_sequencer_kick(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300583
584 return intel_dp->pps_pipe;
585}
586
Imre Deak78597992016-06-16 16:37:20 +0300587static int
588bxt_power_sequencer_idx(struct intel_dp *intel_dp)
589{
590 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
591 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100592 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak78597992016-06-16 16:37:20 +0300593
594 lockdep_assert_held(&dev_priv->pps_mutex);
595
596 /* We should never land here with regular DP ports */
597 WARN_ON(!is_edp(intel_dp));
598
599 /*
600 * TODO: BXT has 2 PPS instances. The correct port->PPS instance
601 * mapping needs to be retrieved from VBT, for now just hard-code to
602 * use instance #0 always.
603 */
604 if (!intel_dp->pps_reset)
605 return 0;
606
607 intel_dp->pps_reset = false;
608
609 /*
610 * Only the HW needs to be reprogrammed, the SW state is fixed and
611 * has been setup during connector init.
612 */
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200613 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak78597992016-06-16 16:37:20 +0300614
615 return 0;
616}
617
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300618typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
619 enum pipe pipe);
620
621static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
622 enum pipe pipe)
623{
Imre Deak44cb7342016-08-10 14:07:29 +0300624 return I915_READ(PP_STATUS(pipe)) & PP_ON;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300625}
626
627static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
628 enum pipe pipe)
629{
Imre Deak44cb7342016-08-10 14:07:29 +0300630 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300631}
632
633static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
634 enum pipe pipe)
635{
636 return true;
637}
638
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300639static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300640vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
641 enum port port,
642 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300643{
Jani Nikulabf13e812013-09-06 07:40:05 +0300644 enum pipe pipe;
645
Jani Nikulabf13e812013-09-06 07:40:05 +0300646 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
Imre Deak44cb7342016-08-10 14:07:29 +0300647 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
Jani Nikulabf13e812013-09-06 07:40:05 +0300648 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300649
650 if (port_sel != PANEL_PORT_SELECT_VLV(port))
651 continue;
652
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300653 if (!pipe_check(dev_priv, pipe))
654 continue;
655
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300656 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300657 }
658
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300659 return INVALID_PIPE;
660}
661
662static void
663vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
664{
665 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
666 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100667 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300668 enum port port = intel_dig_port->port;
669
670 lockdep_assert_held(&dev_priv->pps_mutex);
671
672 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300673 /* first pick one where the panel is on */
674 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
675 vlv_pipe_has_pp_on);
676 /* didn't find one? pick one where vdd is on */
677 if (intel_dp->pps_pipe == INVALID_PIPE)
678 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
679 vlv_pipe_has_vdd_on);
680 /* didn't find one? pick one with just the correct port */
681 if (intel_dp->pps_pipe == INVALID_PIPE)
682 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
683 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300684
685 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
686 if (intel_dp->pps_pipe == INVALID_PIPE) {
687 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
688 port_name(port));
689 return;
690 }
691
692 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
693 port_name(port), pipe_name(intel_dp->pps_pipe));
694
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300695 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200696 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Jani Nikulabf13e812013-09-06 07:40:05 +0300697}
698
Imre Deak78597992016-06-16 16:37:20 +0300699void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300700{
Chris Wilson91c8a322016-07-05 10:40:23 +0100701 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300702 struct intel_encoder *encoder;
703
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100704 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200705 !IS_GEN9_LP(dev_priv)))
Ville Syrjälä773538e82014-09-04 14:54:56 +0300706 return;
707
708 /*
709 * We can't grab pps_mutex here due to deadlock with power_domain
710 * mutex when power_domain functions are called while holding pps_mutex.
711 * That also means that in order to use pps_pipe the code needs to
712 * hold both a power domain reference and pps_mutex, and the power domain
713 * reference get/put must be done while _not_ holding pps_mutex.
714 * pps_{lock,unlock}() do these steps in the correct order, so one
715 * should use them always.
716 */
717
Jani Nikula19c80542015-12-16 12:48:16 +0200718 for_each_intel_encoder(dev, encoder) {
Ville Syrjälä773538e82014-09-04 14:54:56 +0300719 struct intel_dp *intel_dp;
720
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200721 if (encoder->type != INTEL_OUTPUT_DP &&
722 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300723 continue;
724
725 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200726
727 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
728
729 if (encoder->type != INTEL_OUTPUT_EDP)
730 continue;
731
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200732 if (IS_GEN9_LP(dev_priv))
Imre Deak78597992016-06-16 16:37:20 +0300733 intel_dp->pps_reset = true;
734 else
735 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300736 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300737}
738
Imre Deak8e8232d2016-06-16 16:37:21 +0300739struct pps_registers {
740 i915_reg_t pp_ctrl;
741 i915_reg_t pp_stat;
742 i915_reg_t pp_on;
743 i915_reg_t pp_off;
744 i915_reg_t pp_div;
745};
746
747static void intel_pps_get_registers(struct drm_i915_private *dev_priv,
748 struct intel_dp *intel_dp,
749 struct pps_registers *regs)
750{
Imre Deak44cb7342016-08-10 14:07:29 +0300751 int pps_idx = 0;
752
Imre Deak8e8232d2016-06-16 16:37:21 +0300753 memset(regs, 0, sizeof(*regs));
754
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200755 if (IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300756 pps_idx = bxt_power_sequencer_idx(intel_dp);
757 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
758 pps_idx = vlv_power_sequencer_pipe(intel_dp);
Imre Deak8e8232d2016-06-16 16:37:21 +0300759
Imre Deak44cb7342016-08-10 14:07:29 +0300760 regs->pp_ctrl = PP_CONTROL(pps_idx);
761 regs->pp_stat = PP_STATUS(pps_idx);
762 regs->pp_on = PP_ON_DELAYS(pps_idx);
763 regs->pp_off = PP_OFF_DELAYS(pps_idx);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200764 if (!IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300765 regs->pp_div = PP_DIVISOR(pps_idx);
Imre Deak8e8232d2016-06-16 16:37:21 +0300766}
767
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200768static i915_reg_t
769_pp_ctrl_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300770{
Imre Deak8e8232d2016-06-16 16:37:21 +0300771 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300772
Imre Deak8e8232d2016-06-16 16:37:21 +0300773 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
774 &regs);
775
776 return regs.pp_ctrl;
Jani Nikulabf13e812013-09-06 07:40:05 +0300777}
778
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200779static i915_reg_t
780_pp_stat_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300781{
Imre Deak8e8232d2016-06-16 16:37:21 +0300782 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300783
Imre Deak8e8232d2016-06-16 16:37:21 +0300784 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
785 &regs);
786
787 return regs.pp_stat;
Jani Nikulabf13e812013-09-06 07:40:05 +0300788}
789
Clint Taylor01527b32014-07-07 13:01:46 -0700790/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
791 This function only applicable when panel PM state is not to be tracked */
792static int edp_notify_handler(struct notifier_block *this, unsigned long code,
793 void *unused)
794{
795 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
796 edp_notifier);
797 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100798 struct drm_i915_private *dev_priv = to_i915(dev);
Clint Taylor01527b32014-07-07 13:01:46 -0700799
800 if (!is_edp(intel_dp) || code != SYS_RESTART)
801 return 0;
802
Ville Syrjälä773538e82014-09-04 14:54:56 +0300803 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300804
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100805 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300806 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200807 i915_reg_t pp_ctrl_reg, pp_div_reg;
Ville Syrjälä649636e2015-09-22 19:50:01 +0300808 u32 pp_div;
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300809
Imre Deak44cb7342016-08-10 14:07:29 +0300810 pp_ctrl_reg = PP_CONTROL(pipe);
811 pp_div_reg = PP_DIVISOR(pipe);
Clint Taylor01527b32014-07-07 13:01:46 -0700812 pp_div = I915_READ(pp_div_reg);
813 pp_div &= PP_REFERENCE_DIVIDER_MASK;
814
815 /* 0x1F write to PP_DIV_REG sets max cycle delay */
816 I915_WRITE(pp_div_reg, pp_div | 0x1F);
817 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
818 msleep(intel_dp->panel_power_cycle_delay);
819 }
820
Ville Syrjälä773538e82014-09-04 14:54:56 +0300821 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300822
Clint Taylor01527b32014-07-07 13:01:46 -0700823 return 0;
824}
825
Daniel Vetter4be73782014-01-17 14:39:48 +0100826static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700827{
Paulo Zanoni30add222012-10-26 19:05:45 -0200828 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100829 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700830
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300831 lockdep_assert_held(&dev_priv->pps_mutex);
832
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100833 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300834 intel_dp->pps_pipe == INVALID_PIPE)
835 return false;
836
Jani Nikulabf13e812013-09-06 07:40:05 +0300837 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700838}
839
Daniel Vetter4be73782014-01-17 14:39:48 +0100840static bool edp_have_panel_vdd(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
Ville Syrjälä773538e82014-09-04 14:54:56 +0300851 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700852}
853
Keith Packard9b984da2011-09-19 13:54:47 -0700854static void
855intel_dp_check_edp(struct intel_dp *intel_dp)
856{
Paulo Zanoni30add222012-10-26 19:05:45 -0200857 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100858 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700859
Keith Packard9b984da2011-09-19 13:54:47 -0700860 if (!is_edp(intel_dp))
861 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700862
Daniel Vetter4be73782014-01-17 14:39:48 +0100863 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700864 WARN(1, "eDP powered off while attempting aux channel communication.\n");
865 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300866 I915_READ(_pp_stat_reg(intel_dp)),
867 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700868 }
869}
870
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100871static uint32_t
872intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
873{
874 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
875 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100876 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200877 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100878 uint32_t status;
879 bool done;
880
Daniel Vetteref04f002012-12-01 21:03:59 +0100881#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100882 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300883 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300884 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100885 else
Imre Deak713a6b662016-06-28 13:37:33 +0300886 done = wait_for(C, 10) == 0;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100887 if (!done)
888 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
889 has_aux_irq);
890#undef C
891
892 return status;
893}
894
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200895static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000896{
897 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200898 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000899
Ville Syrjäläa457f542016-03-02 17:22:17 +0200900 if (index)
901 return 0;
902
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000903 /*
904 * The clock divider is based off the hrawclk, and would like to run at
Ville Syrjäläa457f542016-03-02 17:22:17 +0200905 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000906 */
Ville Syrjäläa457f542016-03-02 17:22:17 +0200907 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000908}
909
910static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
911{
912 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200913 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000914
915 if (index)
916 return 0;
917
Ville Syrjäläa457f542016-03-02 17:22:17 +0200918 /*
919 * The clock divider is based off the cdclk or PCH rawclk, and would
920 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
921 * divide by 2000 and use that
922 */
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200923 if (intel_dig_port->port == PORT_A)
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200924 return DIV_ROUND_CLOSEST(dev_priv->cdclk.hw.cdclk, 2000);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200925 else
926 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000927}
928
929static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300930{
931 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200932 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300933
Ville Syrjäläa457f542016-03-02 17:22:17 +0200934 if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300935 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100936 switch (index) {
937 case 0: return 63;
938 case 1: return 72;
939 default: return 0;
940 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300941 }
Ville Syrjäläa457f542016-03-02 17:22:17 +0200942
943 return ilk_get_aux_clock_divider(intel_dp, index);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300944}
945
Damien Lespiaub6b5e382014-01-20 16:00:59 +0000946static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
947{
948 /*
949 * SKL doesn't need us to program the AUX clock divider (Hardware will
950 * derive the clock from CDCLK automatically). We still implement the
951 * get_aux_clock_divider vfunc to plug-in into the existing code.
952 */
953 return index ? 0 : 1;
954}
955
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200956static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
957 bool has_aux_irq,
958 int send_bytes,
959 uint32_t aux_clock_divider)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000960{
961 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100962 struct drm_i915_private *dev_priv =
963 to_i915(intel_dig_port->base.base.dev);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000964 uint32_t precharge, timeout;
965
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100966 if (IS_GEN6(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000967 precharge = 3;
968 else
969 precharge = 5;
970
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100971 if (IS_BROADWELL(dev_priv) && intel_dig_port->port == PORT_A)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000972 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
973 else
974 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
975
976 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +0000977 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000978 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000979 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000980 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +0000981 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000982 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
983 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000984 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000985}
986
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000987static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
988 bool has_aux_irq,
989 int send_bytes,
990 uint32_t unused)
991{
992 return DP_AUX_CH_CTL_SEND_BUSY |
993 DP_AUX_CH_CTL_DONE |
994 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
995 DP_AUX_CH_CTL_TIME_OUT_ERROR |
996 DP_AUX_CH_CTL_TIME_OUT_1600us |
997 DP_AUX_CH_CTL_RECEIVE_ERROR |
998 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Daniel Vetterd4dcbdc2016-05-18 18:47:15 +0200999 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00001000 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
1001}
1002
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001003static int
Chris Wilsonea5b2132010-08-04 13:50:23 +01001004intel_dp_aux_ch(struct intel_dp *intel_dp,
Daniel Vetterbd9f74a2014-10-02 09:45:35 +02001005 const uint8_t *send, int send_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001006 uint8_t *recv, int recv_size)
1007{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001008 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001009 struct drm_i915_private *dev_priv =
1010 to_i915(intel_dig_port->base.base.dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001011 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Chris Wilsonbc866252013-07-21 16:00:03 +01001012 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001013 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001014 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001015 int try, clock = 0;
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001016 bool has_aux_irq = HAS_AUX_IRQ(dev_priv);
Jani Nikula884f19e2014-03-14 16:51:14 +02001017 bool vdd;
1018
Ville Syrjälä773538e82014-09-04 14:54:56 +03001019 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001020
Ville Syrjälä72c35002014-08-18 22:16:00 +03001021 /*
1022 * We will be called with VDD already enabled for dpcd/edid/oui reads.
1023 * In such cases we want to leave VDD enabled and it's up to upper layers
1024 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
1025 * ourselves.
1026 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001027 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001028
1029 /* dp aux is extremely sensitive to irq latency, hence request the
1030 * lowest possible wakeup latency and so prevent the cpu from going into
1031 * deep sleep states.
1032 */
1033 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001034
Keith Packard9b984da2011-09-19 13:54:47 -07001035 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001036
Jesse Barnes11bee432011-08-01 15:02:20 -07001037 /* Try to wait for any previous AUX channel activity */
1038 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +01001039 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -07001040 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
1041 break;
1042 msleep(1);
1043 }
1044
1045 if (try == 3) {
Mika Kuoppala02196c72015-08-06 16:48:58 +03001046 static u32 last_status = -1;
1047 const u32 status = I915_READ(ch_ctl);
1048
1049 if (status != last_status) {
1050 WARN(1, "dp_aux_ch not started status 0x%08x\n",
1051 status);
1052 last_status = status;
1053 }
1054
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001055 ret = -EBUSY;
1056 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001057 }
1058
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001059 /* Only 5 data registers! */
1060 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
1061 ret = -E2BIG;
1062 goto out;
1063 }
1064
Damien Lespiauec5b01d2014-01-21 13:35:39 +00001065 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +00001066 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
1067 has_aux_irq,
1068 send_bytes,
1069 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001070
Chris Wilsonbc866252013-07-21 16:00:03 +01001071 /* Must try at least 3 times according to DP spec */
1072 for (try = 0; try < 5; try++) {
1073 /* Load the send data into the aux channel data registers */
1074 for (i = 0; i < send_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001075 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001076 intel_dp_pack_aux(send + i,
1077 send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -04001078
Chris Wilsonbc866252013-07-21 16:00:03 +01001079 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001080 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001081
Chris Wilsonbc866252013-07-21 16:00:03 +01001082 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -04001083
Chris Wilsonbc866252013-07-21 16:00:03 +01001084 /* Clear done status and any errors */
1085 I915_WRITE(ch_ctl,
1086 status |
1087 DP_AUX_CH_CTL_DONE |
1088 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1089 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -04001090
Todd Previte74ebf292015-04-15 08:38:41 -07001091 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
Chris Wilsonbc866252013-07-21 16:00:03 +01001092 continue;
Todd Previte74ebf292015-04-15 08:38:41 -07001093
1094 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
1095 * 400us delay required for errors and timeouts
1096 * Timeout errors from the HW already meet this
1097 * requirement so skip to next iteration
1098 */
1099 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1100 usleep_range(400, 500);
1101 continue;
1102 }
Chris Wilsonbc866252013-07-21 16:00:03 +01001103 if (status & DP_AUX_CH_CTL_DONE)
Jim Bridee058c942015-05-27 10:21:48 -07001104 goto done;
Chris Wilsonbc866252013-07-21 16:00:03 +01001105 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001106 }
1107
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001108 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001109 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001110 ret = -EBUSY;
1111 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001112 }
1113
Jim Bridee058c942015-05-27 10:21:48 -07001114done:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001115 /* Check for timeout or receive error.
1116 * Timeouts occur when the sink is not connected
1117 */
Keith Packarda5b3da52009-06-11 22:30:32 -07001118 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001119 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001120 ret = -EIO;
1121 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -07001122 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001123
1124 /* Timeouts occur when the device isn't connected, so they're
1125 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -07001126 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Chris Wilsona5570fe2017-02-23 11:51:02 +00001127 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001128 ret = -ETIMEDOUT;
1129 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001130 }
1131
1132 /* Unload any bytes sent back from the other side */
1133 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
1134 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Rodrigo Vivi14e01882015-12-10 11:12:27 -08001135
1136 /*
1137 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1138 * We have no idea of what happened so we return -EBUSY so
1139 * drm layer takes care for the necessary retries.
1140 */
1141 if (recv_bytes == 0 || recv_bytes > 20) {
1142 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1143 recv_bytes);
1144 /*
1145 * FIXME: This patch was created on top of a series that
1146 * organize the retries at drm level. There EBUSY should
1147 * also take care for 1ms wait before retrying.
1148 * That aux retries re-org is still needed and after that is
1149 * merged we remove this sleep from here.
1150 */
1151 usleep_range(1000, 1500);
1152 ret = -EBUSY;
1153 goto out;
1154 }
1155
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001156 if (recv_bytes > recv_size)
1157 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -04001158
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001159 for (i = 0; i < recv_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001160 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001161 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001162
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001163 ret = recv_bytes;
1164out:
1165 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1166
Jani Nikula884f19e2014-03-14 16:51:14 +02001167 if (vdd)
1168 edp_panel_vdd_off(intel_dp, false);
1169
Ville Syrjälä773538e82014-09-04 14:54:56 +03001170 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001171
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001172 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001173}
1174
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001175#define BARE_ADDRESS_SIZE 3
1176#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +02001177static ssize_t
1178intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001179{
Jani Nikula9d1a1032014-03-14 16:51:15 +02001180 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1181 uint8_t txbuf[20], rxbuf[20];
1182 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001183 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001184
Ville Syrjäläd2d9cbb2015-03-19 11:44:06 +02001185 txbuf[0] = (msg->request << 4) |
1186 ((msg->address >> 16) & 0xf);
1187 txbuf[1] = (msg->address >> 8) & 0xff;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001188 txbuf[2] = msg->address & 0xff;
1189 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001190
Jani Nikula9d1a1032014-03-14 16:51:15 +02001191 switch (msg->request & ~DP_AUX_I2C_MOT) {
1192 case DP_AUX_NATIVE_WRITE:
1193 case DP_AUX_I2C_WRITE:
Ville Syrjäläc1e741222015-08-27 17:23:27 +03001194 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001195 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001196 rxsize = 2; /* 0 or 1 data bytes */
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001197
Jani Nikula9d1a1032014-03-14 16:51:15 +02001198 if (WARN_ON(txsize > 20))
1199 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001200
Ville Syrjälädd788092016-07-28 17:55:04 +03001201 WARN_ON(!msg->buffer != !msg->size);
1202
Imre Deakd81a67c2016-01-29 14:52:26 +02001203 if (msg->buffer)
1204 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001205
Jani Nikula9d1a1032014-03-14 16:51:15 +02001206 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1207 if (ret > 0) {
1208 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001209
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001210 if (ret > 1) {
1211 /* Number of bytes written in a short write. */
1212 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1213 } else {
1214 /* Return payload size. */
1215 ret = msg->size;
1216 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001217 }
Jani Nikula9d1a1032014-03-14 16:51:15 +02001218 break;
1219
1220 case DP_AUX_NATIVE_READ:
1221 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001222 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001223 rxsize = msg->size + 1;
1224
1225 if (WARN_ON(rxsize > 20))
1226 return -E2BIG;
1227
1228 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1229 if (ret > 0) {
1230 msg->reply = rxbuf[0] >> 4;
1231 /*
1232 * Assume happy day, and copy the data. The caller is
1233 * expected to check msg->reply before touching it.
1234 *
1235 * Return payload size.
1236 */
1237 ret--;
1238 memcpy(msg->buffer, rxbuf + 1, ret);
1239 }
1240 break;
1241
1242 default:
1243 ret = -EINVAL;
1244 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001245 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001246
Jani Nikula9d1a1032014-03-14 16:51:15 +02001247 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001248}
1249
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001250static enum port intel_aux_port(struct drm_i915_private *dev_priv,
1251 enum port port)
1252{
1253 const struct ddi_vbt_port_info *info =
1254 &dev_priv->vbt.ddi_port_info[port];
1255 enum port aux_port;
1256
1257 if (!info->alternate_aux_channel) {
1258 DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
1259 port_name(port), port_name(port));
1260 return port;
1261 }
1262
1263 switch (info->alternate_aux_channel) {
1264 case DP_AUX_A:
1265 aux_port = PORT_A;
1266 break;
1267 case DP_AUX_B:
1268 aux_port = PORT_B;
1269 break;
1270 case DP_AUX_C:
1271 aux_port = PORT_C;
1272 break;
1273 case DP_AUX_D:
1274 aux_port = PORT_D;
1275 break;
1276 default:
1277 MISSING_CASE(info->alternate_aux_channel);
1278 aux_port = PORT_A;
1279 break;
1280 }
1281
1282 DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
1283 port_name(aux_port), port_name(port));
1284
1285 return aux_port;
1286}
1287
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001288static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001289 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001290{
1291 switch (port) {
1292 case PORT_B:
1293 case PORT_C:
1294 case PORT_D:
1295 return DP_AUX_CH_CTL(port);
1296 default:
1297 MISSING_CASE(port);
1298 return DP_AUX_CH_CTL(PORT_B);
1299 }
1300}
1301
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001302static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001303 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001304{
1305 switch (port) {
1306 case PORT_B:
1307 case PORT_C:
1308 case PORT_D:
1309 return DP_AUX_CH_DATA(port, index);
1310 default:
1311 MISSING_CASE(port);
1312 return DP_AUX_CH_DATA(PORT_B, index);
1313 }
1314}
1315
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001316static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001317 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001318{
1319 switch (port) {
1320 case PORT_A:
1321 return DP_AUX_CH_CTL(port);
1322 case PORT_B:
1323 case PORT_C:
1324 case PORT_D:
1325 return PCH_DP_AUX_CH_CTL(port);
1326 default:
1327 MISSING_CASE(port);
1328 return DP_AUX_CH_CTL(PORT_A);
1329 }
1330}
1331
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001332static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001333 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001334{
1335 switch (port) {
1336 case PORT_A:
1337 return DP_AUX_CH_DATA(port, index);
1338 case PORT_B:
1339 case PORT_C:
1340 case PORT_D:
1341 return PCH_DP_AUX_CH_DATA(port, index);
1342 default:
1343 MISSING_CASE(port);
1344 return DP_AUX_CH_DATA(PORT_A, index);
1345 }
1346}
1347
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001348static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001349 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001350{
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001351 switch (port) {
1352 case PORT_A:
1353 case PORT_B:
1354 case PORT_C:
1355 case PORT_D:
1356 return DP_AUX_CH_CTL(port);
1357 default:
1358 MISSING_CASE(port);
1359 return DP_AUX_CH_CTL(PORT_A);
1360 }
1361}
1362
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001363static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001364 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001365{
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001366 switch (port) {
1367 case PORT_A:
1368 case PORT_B:
1369 case PORT_C:
1370 case PORT_D:
1371 return DP_AUX_CH_DATA(port, index);
1372 default:
1373 MISSING_CASE(port);
1374 return DP_AUX_CH_DATA(PORT_A, index);
1375 }
1376}
1377
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001378static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001379 enum port port)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001380{
1381 if (INTEL_INFO(dev_priv)->gen >= 9)
1382 return skl_aux_ctl_reg(dev_priv, port);
1383 else if (HAS_PCH_SPLIT(dev_priv))
1384 return ilk_aux_ctl_reg(dev_priv, port);
1385 else
1386 return g4x_aux_ctl_reg(dev_priv, port);
1387}
1388
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001389static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001390 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001391{
1392 if (INTEL_INFO(dev_priv)->gen >= 9)
1393 return skl_aux_data_reg(dev_priv, port, index);
1394 else if (HAS_PCH_SPLIT(dev_priv))
1395 return ilk_aux_data_reg(dev_priv, port, index);
1396 else
1397 return g4x_aux_data_reg(dev_priv, port, index);
1398}
1399
1400static void intel_aux_reg_init(struct intel_dp *intel_dp)
1401{
1402 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001403 enum port port = intel_aux_port(dev_priv,
1404 dp_to_dig_port(intel_dp)->port);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001405 int i;
1406
1407 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1408 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1409 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1410}
1411
Jani Nikula9d1a1032014-03-14 16:51:15 +02001412static void
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001413intel_dp_aux_fini(struct intel_dp *intel_dp)
1414{
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001415 kfree(intel_dp->aux.name);
1416}
1417
Chris Wilson7a418e32016-06-24 14:00:14 +01001418static void
Mika Kaholab6339582016-09-09 14:10:52 +03001419intel_dp_aux_init(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001420{
Jani Nikula33ad6622014-03-14 16:51:16 +02001421 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1422 enum port port = intel_dig_port->port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001423
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001424 intel_aux_reg_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01001425 drm_dp_aux_init(&intel_dp->aux);
David Flynn8316f332010-12-08 16:10:21 +00001426
Chris Wilson7a418e32016-06-24 14:00:14 +01001427 /* Failure to allocate our preferred name is not critical */
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001428 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
Jani Nikula9d1a1032014-03-14 16:51:15 +02001429 intel_dp->aux.transfer = intel_dp_aux_transfer;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001430}
1431
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001432bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301433{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001434 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Navare, Manasi D577c5432016-09-27 16:36:53 -07001435 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001436
Navare, Manasi D577c5432016-09-27 16:36:53 -07001437 if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
1438 IS_BROADWELL(dev_priv) || (INTEL_GEN(dev_priv) >= 9))
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301439 return true;
1440 else
1441 return false;
1442}
1443
Daniel Vetter0e503382014-07-04 11:26:04 -03001444static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001445intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001446 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001447{
1448 struct drm_device *dev = encoder->base.dev;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001449 struct drm_i915_private *dev_priv = to_i915(dev);
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001450 const struct dp_link_dpll *divisor = NULL;
1451 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001452
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001453 if (IS_G4X(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001454 divisor = gen4_dpll;
1455 count = ARRAY_SIZE(gen4_dpll);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001456 } else if (HAS_PCH_SPLIT(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001457 divisor = pch_dpll;
1458 count = ARRAY_SIZE(pch_dpll);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001459 } else if (IS_CHERRYVIEW(dev_priv)) {
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001460 divisor = chv_dpll;
1461 count = ARRAY_SIZE(chv_dpll);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001462 } else if (IS_VALLEYVIEW(dev_priv)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001463 divisor = vlv_dpll;
1464 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001465 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001466
1467 if (divisor && count) {
1468 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001469 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001470 pipe_config->dpll = divisor[i].dpll;
1471 pipe_config->clock_set = true;
1472 break;
1473 }
1474 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001475 }
1476}
1477
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001478static void snprintf_int_array(char *str, size_t len,
1479 const int *array, int nelem)
1480{
1481 int i;
1482
1483 str[0] = '\0';
1484
1485 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001486 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001487 if (r >= len)
1488 return;
1489 str += r;
1490 len -= r;
1491 }
1492}
1493
1494static void intel_dp_print_rates(struct intel_dp *intel_dp)
1495{
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001496 const int *source_rates, *sink_rates;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001497 int source_len, sink_len, common_len;
1498 int common_rates[DP_MAX_SUPPORTED_RATES];
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001499 char str[128]; /* FIXME: too big for stack? */
1500
1501 if ((drm_debug & DRM_UT_KMS) == 0)
1502 return;
1503
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001504 source_len = intel_dp_source_rates(intel_dp, &source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001505 snprintf_int_array(str, sizeof(str), source_rates, source_len);
1506 DRM_DEBUG_KMS("source rates: %s\n", str);
1507
1508 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
1509 snprintf_int_array(str, sizeof(str), sink_rates, sink_len);
1510 DRM_DEBUG_KMS("sink rates: %s\n", str);
1511
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001512 common_len = intel_dp_common_rates(intel_dp, common_rates);
1513 snprintf_int_array(str, sizeof(str), common_rates, common_len);
1514 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001515}
1516
Imre Deak489375c2016-10-24 19:33:31 +03001517bool
Imre Deak7b3fc172016-10-25 16:12:39 +03001518__intel_dp_read_desc(struct intel_dp *intel_dp, struct intel_dp_desc *desc)
Mika Kahola0e390a32016-09-09 14:10:53 +03001519{
Imre Deak7b3fc172016-10-25 16:12:39 +03001520 u32 base = drm_dp_is_branch(intel_dp->dpcd) ? DP_BRANCH_OUI :
1521 DP_SINK_OUI;
Mika Kahola0e390a32016-09-09 14:10:53 +03001522
Imre Deak7b3fc172016-10-25 16:12:39 +03001523 return drm_dp_dpcd_read(&intel_dp->aux, base, desc, sizeof(*desc)) ==
1524 sizeof(*desc);
Mika Kahola0e390a32016-09-09 14:10:53 +03001525}
1526
Imre Deak12a47a422016-10-24 19:33:29 +03001527bool intel_dp_read_desc(struct intel_dp *intel_dp)
Mika Kahola1a2724f2016-09-09 14:10:54 +03001528{
Imre Deak7b3fc172016-10-25 16:12:39 +03001529 struct intel_dp_desc *desc = &intel_dp->desc;
1530 bool oui_sup = intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] &
1531 DP_OUI_SUPPORT;
1532 int dev_id_len;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001533
Imre Deak7b3fc172016-10-25 16:12:39 +03001534 if (!__intel_dp_read_desc(intel_dp, desc))
1535 return false;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001536
Imre Deak7b3fc172016-10-25 16:12:39 +03001537 dev_id_len = strnlen(desc->device_id, sizeof(desc->device_id));
1538 DRM_DEBUG_KMS("DP %s: OUI %*phD%s dev-ID %*pE HW-rev %d.%d SW-rev %d.%d\n",
1539 drm_dp_is_branch(intel_dp->dpcd) ? "branch" : "sink",
1540 (int)sizeof(desc->oui), desc->oui, oui_sup ? "" : "(NS)",
1541 dev_id_len, desc->device_id,
1542 desc->hw_rev >> 4, desc->hw_rev & 0xf,
1543 desc->sw_major_rev, desc->sw_minor_rev);
Mika Kahola1a2724f2016-09-09 14:10:54 +03001544
Imre Deak7b3fc172016-10-25 16:12:39 +03001545 return true;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001546}
1547
Ville Syrjälä50fec212015-03-12 17:10:34 +02001548int
1549intel_dp_max_link_rate(struct intel_dp *intel_dp)
1550{
1551 int rates[DP_MAX_SUPPORTED_RATES] = {};
1552 int len;
1553
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001554 len = intel_dp_common_rates(intel_dp, rates);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001555 if (WARN_ON(len <= 0))
1556 return 162000;
1557
Ville Syrjälä1354f732016-07-28 17:50:45 +03001558 return rates[len - 1];
Ville Syrjälä50fec212015-03-12 17:10:34 +02001559}
1560
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001561int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1562{
Jani Nikula8001b752017-03-28 17:59:03 +03001563 int i = intel_dp_rate_index(intel_dp->sink_rates,
1564 intel_dp->num_sink_rates, rate);
Jani Nikulab5c72b22017-03-28 17:59:02 +03001565
1566 if (WARN_ON(i < 0))
1567 i = 0;
1568
1569 return i;
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001570}
1571
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001572void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1573 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001574{
1575 if (intel_dp->num_sink_rates) {
1576 *link_bw = 0;
1577 *rate_select =
1578 intel_dp_rate_select(intel_dp, port_clock);
1579 } else {
1580 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1581 *rate_select = 0;
1582 }
1583}
1584
Jani Nikulaf580bea2016-09-15 16:28:52 +03001585static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1586 struct intel_crtc_state *pipe_config)
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001587{
1588 int bpp, bpc;
1589
1590 bpp = pipe_config->pipe_bpp;
1591 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1592
1593 if (bpc > 0)
1594 bpp = min(bpp, 3*bpc);
1595
Manasi Navare611032b2017-01-24 08:21:49 -08001596 /* For DP Compliance we override the computed bpp for the pipe */
1597 if (intel_dp->compliance.test_data.bpc != 0) {
1598 pipe_config->pipe_bpp = 3*intel_dp->compliance.test_data.bpc;
1599 pipe_config->dither_force_disable = pipe_config->pipe_bpp == 6*3;
1600 DRM_DEBUG_KMS("Setting pipe_bpp to %d\n",
1601 pipe_config->pipe_bpp);
1602 }
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001603 return bpp;
1604}
1605
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001606bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001607intel_dp_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001608 struct intel_crtc_state *pipe_config,
1609 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001610{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001611 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001612 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001613 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001614 enum port port = dp_to_dig_port(intel_dp)->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001615 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001616 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001617 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001618 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001619 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001620 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001621 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301622 int max_clock;
Manasi Navareda15f7c2017-01-24 08:16:34 -08001623 int link_rate_index;
Daniel Vetter083f9562012-04-20 20:23:49 +02001624 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001625 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001626 int common_rates[DP_MAX_SUPPORTED_RATES] = {};
1627 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001628 uint8_t link_bw, rate_select;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301629
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001630 common_len = intel_dp_common_rates(intel_dp, common_rates);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301631
1632 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001633 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301634
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001635 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001636
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001637 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001638 pipe_config->has_pch_encoder = true;
1639
Vandana Kannanf769cd22014-08-05 07:51:22 -07001640 pipe_config->has_drrs = false;
Jani Nikula9fcb1702015-05-05 16:32:12 +03001641 pipe_config->has_audio = intel_dp->has_audio && port != PORT_A;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001642
Jani Nikuladd06f902012-10-19 14:51:50 +03001643 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1644 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
1645 adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001646
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001647 if (INTEL_GEN(dev_priv) >= 9) {
Chandra Kondurua1b22782015-04-07 15:28:45 -07001648 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001649 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001650 if (ret)
1651 return ret;
1652 }
1653
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001654 if (HAS_GMCH_DISPLAY(dev_priv))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001655 intel_gmch_panel_fitting(intel_crtc, pipe_config,
1656 intel_connector->panel.fitting_mode);
1657 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001658 intel_pch_panel_fitting(intel_crtc, pipe_config,
1659 intel_connector->panel.fitting_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001660 }
1661
Daniel Vettercb1793c2012-06-04 18:39:21 +02001662 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001663 return false;
1664
Manasi Navareda15f7c2017-01-24 08:16:34 -08001665 /* Use values requested by Compliance Test Request */
1666 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
1667 link_rate_index = intel_dp_link_rate_index(intel_dp,
1668 common_rates,
1669 intel_dp->compliance.test_link_rate);
1670 if (link_rate_index >= 0)
1671 min_clock = max_clock = link_rate_index;
1672 min_lane_count = max_lane_count = intel_dp->compliance.test_lane_count;
1673 }
Daniel Vetter083f9562012-04-20 20:23:49 +02001674 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301675 "max bw %d pixel clock %iKHz\n",
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001676 max_lane_count, common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001677 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001678
Daniel Vetter36008362013-03-27 00:44:59 +01001679 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1680 * bpc in between. */
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001681 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
Jani Nikula56071a22014-05-06 14:56:52 +03001682 if (is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301683
1684 /* Get bpp from vbt only for panels that dont have bpp in edid */
1685 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001686 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001687 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001688 dev_priv->vbt.edp.bpp);
1689 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001690 }
1691
Jani Nikula344c5bb2014-09-09 11:25:13 +03001692 /*
1693 * Use the maximum clock and number of lanes the eDP panel
1694 * advertizes being capable of. The panels are generally
1695 * designed to support only a single clock and lane
1696 * configuration, and typically these values correspond to the
1697 * native resolution of the panel.
1698 */
1699 min_lane_count = max_lane_count;
1700 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001701 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001702
Daniel Vetter36008362013-03-27 00:44:59 +01001703 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001704 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1705 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001706
Dave Airliec6930992014-07-14 11:04:39 +10001707 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301708 for (lane_count = min_lane_count;
1709 lane_count <= max_lane_count;
1710 lane_count <<= 1) {
1711
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001712 link_clock = common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001713 link_avail = intel_dp_max_data_rate(link_clock,
1714 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001715
Daniel Vetter36008362013-03-27 00:44:59 +01001716 if (mode_rate <= link_avail) {
1717 goto found;
1718 }
1719 }
1720 }
1721 }
1722
1723 return false;
1724
1725found:
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001726 if (intel_dp->color_range_auto) {
1727 /*
1728 * See:
1729 * CEA-861-E - 5.1 Default Encoding Parameters
1730 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1731 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001732 pipe_config->limited_color_range =
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02001733 bpp != 18 &&
1734 drm_default_rgb_quant_range(adjusted_mode) ==
1735 HDMI_QUANTIZATION_RANGE_LIMITED;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001736 } else {
1737 pipe_config->limited_color_range =
1738 intel_dp->limited_color_range;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001739 }
1740
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001741 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301742
Daniel Vetter657445f2013-05-04 10:09:18 +02001743 pipe_config->pipe_bpp = bpp;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001744 pipe_config->port_clock = common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001745
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001746 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1747 &link_bw, &rate_select);
1748
1749 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1750 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001751 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001752 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1753 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001754
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001755 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001756 adjusted_mode->crtc_clock,
1757 pipe_config->port_clock,
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001758 &pipe_config->dp_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001759
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301760 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301761 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001762 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301763 intel_link_compute_m_n(bpp, lane_count,
1764 intel_connector->panel.downclock_mode->clock,
1765 pipe_config->port_clock,
1766 &pipe_config->dp_m2_n2);
1767 }
1768
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001769 /*
1770 * DPLL0 VCO may need to be adjusted to get the correct
1771 * clock for eDP. This will affect cdclk as well.
1772 */
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001773 if (is_edp(intel_dp) && IS_GEN9_BC(dev_priv)) {
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001774 int vco;
1775
1776 switch (pipe_config->port_clock / 2) {
1777 case 108000:
1778 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001779 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001780 break;
1781 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001782 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001783 break;
1784 }
1785
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +02001786 to_intel_atomic_state(pipe_config->base.state)->cdclk.logical.vco = vco;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001787 }
1788
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001789 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001790 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001791
Daniel Vetter36008362013-03-27 00:44:59 +01001792 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001793}
1794
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001795void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001796 int link_rate, uint8_t lane_count,
1797 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001798{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001799 intel_dp->link_rate = link_rate;
1800 intel_dp->lane_count = lane_count;
1801 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001802}
1803
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001804static void intel_dp_prepare(struct intel_encoder *encoder,
1805 struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001806{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001807 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001808 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001809 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001810 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001811 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001812 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001813
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001814 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1815 pipe_config->lane_count,
1816 intel_crtc_has_type(pipe_config,
1817 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001818
Keith Packard417e8222011-11-01 19:54:11 -07001819 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001820 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001821 *
1822 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001823 * SNB CPU
1824 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001825 * CPT PCH
1826 *
1827 * IBX PCH and CPU are the same for almost everything,
1828 * except that the CPU DP PLL is configured in this
1829 * register
1830 *
1831 * CPT PCH is quite different, having many bits moved
1832 * to the TRANS_DP_CTL register instead. That
1833 * configuration happens (oddly) in ironlake_pch_enable
1834 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001835
Keith Packard417e8222011-11-01 19:54:11 -07001836 /* Preserve the BIOS-computed detected bit. This is
1837 * supposed to be read-only.
1838 */
1839 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001840
Keith Packard417e8222011-11-01 19:54:11 -07001841 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001842 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001843 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001844
Keith Packard417e8222011-11-01 19:54:11 -07001845 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001846
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001847 if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001848 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1849 intel_dp->DP |= DP_SYNC_HS_HIGH;
1850 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1851 intel_dp->DP |= DP_SYNC_VS_HIGH;
1852 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1853
Jani Nikula6aba5b62013-10-04 15:08:10 +03001854 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001855 intel_dp->DP |= DP_ENHANCED_FRAMING;
1856
Daniel Vetter7c62a162013-06-01 17:16:20 +02001857 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001858 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001859 u32 trans_dp;
1860
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001861 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001862
1863 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1864 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1865 trans_dp |= TRANS_DP_ENH_FRAMING;
1866 else
1867 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1868 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001869 } else {
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02001870 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001871 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001872
1873 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1874 intel_dp->DP |= DP_SYNC_HS_HIGH;
1875 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1876 intel_dp->DP |= DP_SYNC_VS_HIGH;
1877 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1878
Jani Nikula6aba5b62013-10-04 15:08:10 +03001879 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001880 intel_dp->DP |= DP_ENHANCED_FRAMING;
1881
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001882 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001883 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001884 else if (crtc->pipe == PIPE_B)
1885 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001886 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001887}
1888
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001889#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1890#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001891
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001892#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1893#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001894
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001895#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1896#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001897
Imre Deakde9c1b62016-06-16 20:01:46 +03001898static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
1899 struct intel_dp *intel_dp);
1900
Daniel Vetter4be73782014-01-17 14:39:48 +01001901static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001902 u32 mask,
1903 u32 value)
1904{
Paulo Zanoni30add222012-10-26 19:05:45 -02001905 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001906 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001907 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001908
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001909 lockdep_assert_held(&dev_priv->pps_mutex);
1910
Imre Deakde9c1b62016-06-16 20:01:46 +03001911 intel_pps_verify_state(dev_priv, intel_dp);
1912
Jani Nikulabf13e812013-09-06 07:40:05 +03001913 pp_stat_reg = _pp_stat_reg(intel_dp);
1914 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001915
1916 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001917 mask, value,
1918 I915_READ(pp_stat_reg),
1919 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001920
Chris Wilson9036ff02016-06-30 15:33:09 +01001921 if (intel_wait_for_register(dev_priv,
1922 pp_stat_reg, mask, value,
1923 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001924 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001925 I915_READ(pp_stat_reg),
1926 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001927
1928 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001929}
1930
Daniel Vetter4be73782014-01-17 14:39:48 +01001931static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001932{
1933 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001934 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001935}
1936
Daniel Vetter4be73782014-01-17 14:39:48 +01001937static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001938{
Keith Packardbd943152011-09-18 23:09:52 -07001939 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001940 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001941}
Keith Packardbd943152011-09-18 23:09:52 -07001942
Daniel Vetter4be73782014-01-17 14:39:48 +01001943static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001944{
Abhay Kumard28d4732016-01-22 17:39:04 -08001945 ktime_t panel_power_on_time;
1946 s64 panel_power_off_duration;
1947
Keith Packard99ea7122011-11-01 19:57:50 -07001948 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001949
Abhay Kumard28d4732016-01-22 17:39:04 -08001950 /* take the difference of currrent time and panel power off time
1951 * and then make panel wait for t11_t12 if needed. */
1952 panel_power_on_time = ktime_get_boottime();
1953 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1954
Paulo Zanonidce56b32013-12-19 14:29:40 -02001955 /* When we disable the VDD override bit last we have to do the manual
1956 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08001957 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
1958 wait_remaining_ms_from_jiffies(jiffies,
1959 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001960
Daniel Vetter4be73782014-01-17 14:39:48 +01001961 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001962}
Keith Packardbd943152011-09-18 23:09:52 -07001963
Daniel Vetter4be73782014-01-17 14:39:48 +01001964static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001965{
1966 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1967 intel_dp->backlight_on_delay);
1968}
1969
Daniel Vetter4be73782014-01-17 14:39:48 +01001970static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001971{
1972 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
1973 intel_dp->backlight_off_delay);
1974}
Keith Packard99ea7122011-11-01 19:57:50 -07001975
Keith Packard832dd3c2011-11-01 19:34:06 -07001976/* Read the current pp_control value, unlocking the register if it
1977 * is locked
1978 */
1979
Jesse Barnes453c5422013-03-28 09:55:41 -07001980static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07001981{
Jesse Barnes453c5422013-03-28 09:55:41 -07001982 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001983 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07001984 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07001985
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001986 lockdep_assert_held(&dev_priv->pps_mutex);
1987
Jani Nikulabf13e812013-09-06 07:40:05 +03001988 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03001989 if (WARN_ON(!HAS_DDI(dev_priv) &&
1990 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05301991 control &= ~PANEL_UNLOCK_MASK;
1992 control |= PANEL_UNLOCK_REGS;
1993 }
Keith Packard832dd3c2011-11-01 19:34:06 -07001994 return control;
Keith Packardbd943152011-09-18 23:09:52 -07001995}
1996
Ville Syrjälä951468f2014-09-04 14:55:31 +03001997/*
1998 * Must be paired with edp_panel_vdd_off().
1999 * Must hold pps_mutex around the whole on/off sequence.
2000 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2001 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03002002static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002003{
Paulo Zanoni30add222012-10-26 19:05:45 -02002004 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002005 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002006 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes5d613502011-01-24 17:10:54 -08002007 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002008 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002009 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08002010
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002011 lockdep_assert_held(&dev_priv->pps_mutex);
2012
Keith Packard97af61f572011-09-28 16:23:51 -07002013 if (!is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002014 return false;
Keith Packardbd943152011-09-18 23:09:52 -07002015
Egbert Eich2c623c12014-11-25 12:54:57 +01002016 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002017 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07002018
Daniel Vetter4be73782014-01-17 14:39:48 +01002019 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002020 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002021
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002022 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002023
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002024 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
2025 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07002026
Daniel Vetter4be73782014-01-17 14:39:48 +01002027 if (!edp_have_panel_power(intel_dp))
2028 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07002029
Jesse Barnes453c5422013-03-28 09:55:41 -07002030 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002031 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07002032
Jani Nikulabf13e812013-09-06 07:40:05 +03002033 pp_stat_reg = _pp_stat_reg(intel_dp);
2034 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002035
2036 I915_WRITE(pp_ctrl_reg, pp);
2037 POSTING_READ(pp_ctrl_reg);
2038 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2039 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07002040 /*
2041 * If the panel wasn't on, delay before accessing aux channel
2042 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002043 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002044 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
2045 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07002046 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07002047 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002048
2049 return need_to_disable;
2050}
2051
Ville Syrjälä951468f2014-09-04 14:55:31 +03002052/*
2053 * Must be paired with intel_edp_panel_vdd_off() or
2054 * intel_edp_panel_off().
2055 * Nested calls to these functions are not allowed since
2056 * we drop the lock. Caller must use some higher level
2057 * locking to prevent nested calls from other threads.
2058 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01002059void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002060{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002061 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002062
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002063 if (!is_edp(intel_dp))
2064 return;
2065
Ville Syrjälä773538e82014-09-04 14:54:56 +03002066 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002067 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002068 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002069
Rob Clarke2c719b2014-12-15 13:56:32 -05002070 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002071 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08002072}
2073
Daniel Vetter4be73782014-01-17 14:39:48 +01002074static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002075{
Paulo Zanoni30add222012-10-26 19:05:45 -02002076 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002077 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002078 struct intel_digital_port *intel_dig_port =
2079 dp_to_dig_port(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002080 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002081 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002082
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002083 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002084
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002085 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002086
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002087 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002088 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002089
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002090 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2091 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002092
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002093 pp = ironlake_get_pp_control(intel_dp);
2094 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002095
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002096 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2097 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002098
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002099 I915_WRITE(pp_ctrl_reg, pp);
2100 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002101
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002102 /* Make sure sequencer is idle before allowing subsequent activity */
2103 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2104 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002105
Imre Deak5a162e22016-08-10 14:07:30 +03002106 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002107 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002108
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002109 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002110}
2111
Daniel Vetter4be73782014-01-17 14:39:48 +01002112static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002113{
2114 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2115 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002116
Ville Syrjälä773538e82014-09-04 14:54:56 +03002117 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002118 if (!intel_dp->want_panel_vdd)
2119 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002120 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002121}
2122
Imre Deakaba86892014-07-30 15:57:31 +03002123static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2124{
2125 unsigned long delay;
2126
2127 /*
2128 * Queue the timer to fire a long time from now (relative to the power
2129 * down delay) to keep the panel power up across a sequence of
2130 * operations.
2131 */
2132 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2133 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2134}
2135
Ville Syrjälä951468f2014-09-04 14:55:31 +03002136/*
2137 * Must be paired with edp_panel_vdd_on().
2138 * Must hold pps_mutex around the whole on/off sequence.
2139 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2140 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002141static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002142{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002143 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002144
2145 lockdep_assert_held(&dev_priv->pps_mutex);
2146
Keith Packard97af61f572011-09-28 16:23:51 -07002147 if (!is_edp(intel_dp))
2148 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002149
Rob Clarke2c719b2014-12-15 13:56:32 -05002150 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002151 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002152
Keith Packardbd943152011-09-18 23:09:52 -07002153 intel_dp->want_panel_vdd = false;
2154
Imre Deakaba86892014-07-30 15:57:31 +03002155 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002156 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002157 else
2158 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002159}
2160
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002161static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002162{
Paulo Zanoni30add222012-10-26 19:05:45 -02002163 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002164 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002165 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002166 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002167
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002168 lockdep_assert_held(&dev_priv->pps_mutex);
2169
Keith Packard97af61f572011-09-28 16:23:51 -07002170 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002171 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002172
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002173 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2174 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002175
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002176 if (WARN(edp_have_panel_power(intel_dp),
2177 "eDP port %c panel power already on\n",
2178 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002179 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002180
Daniel Vetter4be73782014-01-17 14:39:48 +01002181 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002182
Jani Nikulabf13e812013-09-06 07:40:05 +03002183 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002184 pp = ironlake_get_pp_control(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002185 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002186 /* ILK workaround: disable reset around power sequence */
2187 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002188 I915_WRITE(pp_ctrl_reg, pp);
2189 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002190 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002191
Imre Deak5a162e22016-08-10 14:07:30 +03002192 pp |= PANEL_POWER_ON;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002193 if (!IS_GEN5(dev_priv))
Keith Packard99ea7122011-11-01 19:57:50 -07002194 pp |= PANEL_POWER_RESET;
2195
Jesse Barnes453c5422013-03-28 09:55:41 -07002196 I915_WRITE(pp_ctrl_reg, pp);
2197 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002198
Daniel Vetter4be73782014-01-17 14:39:48 +01002199 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002200 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002201
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002202 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002203 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002204 I915_WRITE(pp_ctrl_reg, pp);
2205 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002206 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002207}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002208
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002209void intel_edp_panel_on(struct intel_dp *intel_dp)
2210{
2211 if (!is_edp(intel_dp))
2212 return;
2213
2214 pps_lock(intel_dp);
2215 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002216 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002217}
2218
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002219
2220static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002221{
Paulo Zanoni30add222012-10-26 19:05:45 -02002222 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002223 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002224 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002225 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002226
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002227 lockdep_assert_held(&dev_priv->pps_mutex);
2228
Keith Packard97af61f572011-09-28 16:23:51 -07002229 if (!is_edp(intel_dp))
2230 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002231
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002232 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2233 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002234
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002235 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2236 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002237
Jesse Barnes453c5422013-03-28 09:55:41 -07002238 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002239 /* We need to switch off panel power _and_ force vdd, for otherwise some
2240 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002241 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002242 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002243
Jani Nikulabf13e812013-09-06 07:40:05 +03002244 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002245
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002246 intel_dp->want_panel_vdd = false;
2247
Jesse Barnes453c5422013-03-28 09:55:41 -07002248 I915_WRITE(pp_ctrl_reg, pp);
2249 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002250
Abhay Kumard28d4732016-01-22 17:39:04 -08002251 intel_dp->panel_power_off_time = ktime_get_boottime();
Daniel Vetter4be73782014-01-17 14:39:48 +01002252 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002253
2254 /* We got a reference when we enabled the VDD. */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002255 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002256}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002257
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002258void intel_edp_panel_off(struct intel_dp *intel_dp)
2259{
2260 if (!is_edp(intel_dp))
2261 return;
2262
2263 pps_lock(intel_dp);
2264 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002265 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002266}
2267
Jani Nikula1250d102014-08-12 17:11:39 +03002268/* Enable backlight in the panel power control. */
2269static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002270{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002271 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2272 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002273 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002274 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002275 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002276
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002277 /*
2278 * If we enable the backlight right away following a panel power
2279 * on, we may see slight flicker as the panel syncs with the eDP
2280 * link. So delay a bit to make sure the image is solid before
2281 * allowing it to appear.
2282 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002283 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002284
Ville Syrjälä773538e82014-09-04 14:54:56 +03002285 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002286
Jesse Barnes453c5422013-03-28 09:55:41 -07002287 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002288 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002289
Jani Nikulabf13e812013-09-06 07:40:05 +03002290 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002291
2292 I915_WRITE(pp_ctrl_reg, pp);
2293 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002294
Ville Syrjälä773538e82014-09-04 14:54:56 +03002295 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002296}
2297
Jani Nikula1250d102014-08-12 17:11:39 +03002298/* Enable backlight PWM and backlight PP control. */
2299void intel_edp_backlight_on(struct intel_dp *intel_dp)
2300{
2301 if (!is_edp(intel_dp))
2302 return;
2303
2304 DRM_DEBUG_KMS("\n");
2305
2306 intel_panel_enable_backlight(intel_dp->attached_connector);
2307 _intel_edp_backlight_on(intel_dp);
2308}
2309
2310/* Disable backlight in the panel power control. */
2311static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002312{
Paulo Zanoni30add222012-10-26 19:05:45 -02002313 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002314 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002315 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002316 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002317
Keith Packardf01eca22011-09-28 16:48:10 -07002318 if (!is_edp(intel_dp))
2319 return;
2320
Ville Syrjälä773538e82014-09-04 14:54:56 +03002321 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002322
Jesse Barnes453c5422013-03-28 09:55:41 -07002323 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002324 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002325
Jani Nikulabf13e812013-09-06 07:40:05 +03002326 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002327
2328 I915_WRITE(pp_ctrl_reg, pp);
2329 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002330
Ville Syrjälä773538e82014-09-04 14:54:56 +03002331 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002332
Paulo Zanonidce56b32013-12-19 14:29:40 -02002333 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002334 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002335}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002336
Jani Nikula1250d102014-08-12 17:11:39 +03002337/* Disable backlight PP control and backlight PWM. */
2338void intel_edp_backlight_off(struct intel_dp *intel_dp)
2339{
2340 if (!is_edp(intel_dp))
2341 return;
2342
2343 DRM_DEBUG_KMS("\n");
2344
2345 _intel_edp_backlight_off(intel_dp);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002346 intel_panel_disable_backlight(intel_dp->attached_connector);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002347}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002348
Jani Nikula73580fb72014-08-12 17:11:41 +03002349/*
2350 * Hook for controlling the panel power control backlight through the bl_power
2351 * sysfs attribute. Take care to handle multiple calls.
2352 */
2353static void intel_edp_backlight_power(struct intel_connector *connector,
2354 bool enable)
2355{
2356 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002357 bool is_enabled;
2358
Ville Syrjälä773538e82014-09-04 14:54:56 +03002359 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002360 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002361 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002362
2363 if (is_enabled == enable)
2364 return;
2365
Jani Nikula23ba9372014-08-27 14:08:43 +03002366 DRM_DEBUG_KMS("panel power control backlight %s\n",
2367 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002368
2369 if (enable)
2370 _intel_edp_backlight_on(intel_dp);
2371 else
2372 _intel_edp_backlight_off(intel_dp);
2373}
2374
Ville Syrjälä64e10772015-10-29 21:26:01 +02002375static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2376{
2377 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2378 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2379 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2380
2381 I915_STATE_WARN(cur_state != state,
2382 "DP port %c state assertion failure (expected %s, current %s)\n",
2383 port_name(dig_port->port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002384 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002385}
2386#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2387
2388static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2389{
2390 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2391
2392 I915_STATE_WARN(cur_state != state,
2393 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002394 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002395}
2396#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2397#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2398
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002399static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2400 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002401{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002402 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002403 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002404
Ville Syrjälä64e10772015-10-29 21:26:01 +02002405 assert_pipe_disabled(dev_priv, crtc->pipe);
2406 assert_dp_port_disabled(intel_dp);
2407 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002408
Ville Syrjäläabfce942015-10-29 21:26:03 +02002409 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002410 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002411
2412 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2413
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002414 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002415 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2416 else
2417 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2418
2419 I915_WRITE(DP_A, intel_dp->DP);
2420 POSTING_READ(DP_A);
2421 udelay(500);
2422
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002423 /*
2424 * [DevILK] Work around required when enabling DP PLL
2425 * while a pipe is enabled going to FDI:
2426 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2427 * 2. Program DP PLL enable
2428 */
2429 if (IS_GEN5(dev_priv))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02002430 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002431
Daniel Vetter07679352012-09-06 22:15:42 +02002432 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002433
Daniel Vetter07679352012-09-06 22:15:42 +02002434 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002435 POSTING_READ(DP_A);
2436 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002437}
2438
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002439static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002440{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002441 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002442 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2443 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002444
Ville Syrjälä64e10772015-10-29 21:26:01 +02002445 assert_pipe_disabled(dev_priv, crtc->pipe);
2446 assert_dp_port_disabled(intel_dp);
2447 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002448
Ville Syrjäläabfce942015-10-29 21:26:03 +02002449 DRM_DEBUG_KMS("disabling eDP PLL\n");
2450
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002451 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002452
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002453 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002454 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002455 udelay(200);
2456}
2457
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002458/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002459void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002460{
2461 int ret, i;
2462
2463 /* Should have a valid DPCD by this point */
2464 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2465 return;
2466
2467 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002468 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2469 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002470 } else {
Imre Deak357c0ae2016-11-21 21:15:06 +02002471 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
2472
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002473 /*
2474 * When turning on, we need to retry for 1ms to give the sink
2475 * time to wake up.
2476 */
2477 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002478 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2479 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002480 if (ret == 1)
2481 break;
2482 msleep(1);
2483 }
Imre Deak357c0ae2016-11-21 21:15:06 +02002484
2485 if (ret == 1 && lspcon->active)
2486 lspcon_wait_pcon_mode(lspcon);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002487 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002488
2489 if (ret != 1)
2490 DRM_DEBUG_KMS("failed to %s sink power state\n",
2491 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002492}
2493
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002494static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2495 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002496{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002497 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002498 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002499 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002500 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002501 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002502 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002503
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002504 if (!intel_display_power_get_if_enabled(dev_priv,
2505 encoder->power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002506 return false;
2507
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002508 ret = false;
2509
Imre Deak6d129be2014-03-05 16:20:54 +02002510 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002511
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002512 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002513 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002514
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002515 if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002516 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002517 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002518 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002519
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002520 for_each_pipe(dev_priv, p) {
2521 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2522 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2523 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002524 ret = true;
2525
2526 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002527 }
2528 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002529
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002530 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002531 i915_mmio_reg_offset(intel_dp->output_reg));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002532 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002533 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2534 } else {
2535 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002536 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002537
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002538 ret = true;
2539
2540out:
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002541 intel_display_power_put(dev_priv, encoder->power_domain);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002542
2543 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002544}
2545
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002546static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002547 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002548{
2549 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002550 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002551 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002552 struct drm_i915_private *dev_priv = to_i915(dev);
Xiong Zhang63000ef2013-06-28 12:59:06 +08002553 enum port port = dp_to_dig_port(intel_dp)->port;
2554 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002555
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002556 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002557
2558 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002559
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002560 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002561 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2562
2563 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002564 flags |= DRM_MODE_FLAG_PHSYNC;
2565 else
2566 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002567
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002568 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002569 flags |= DRM_MODE_FLAG_PVSYNC;
2570 else
2571 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002572 } else {
2573 if (tmp & DP_SYNC_HS_HIGH)
2574 flags |= DRM_MODE_FLAG_PHSYNC;
2575 else
2576 flags |= DRM_MODE_FLAG_NHSYNC;
2577
2578 if (tmp & DP_SYNC_VS_HIGH)
2579 flags |= DRM_MODE_FLAG_PVSYNC;
2580 else
2581 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002582 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002583
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002584 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002585
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02002586 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002587 pipe_config->limited_color_range = true;
2588
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002589 pipe_config->lane_count =
2590 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2591
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002592 intel_dp_get_m_n(crtc, pipe_config);
2593
Ville Syrjälä18442d02013-09-13 16:00:08 +03002594 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002595 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002596 pipe_config->port_clock = 162000;
2597 else
2598 pipe_config->port_clock = 270000;
2599 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002600
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002601 pipe_config->base.adjusted_mode.crtc_clock =
2602 intel_dotclock_calculate(pipe_config->port_clock,
2603 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002604
Jani Nikula6aa23e62016-03-24 17:50:20 +02002605 if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
2606 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002607 /*
2608 * This is a big fat ugly hack.
2609 *
2610 * Some machines in UEFI boot mode provide us a VBT that has 18
2611 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2612 * unknown we fail to light up. Yet the same BIOS boots up with
2613 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2614 * max, not what it tells us to use.
2615 *
2616 * Note: This will still be broken if the eDP panel is not lit
2617 * up by the BIOS, and thus we can't get the mode at module
2618 * load.
2619 */
2620 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002621 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2622 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002623 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002624}
2625
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002626static void intel_disable_dp(struct intel_encoder *encoder,
2627 struct intel_crtc_state *old_crtc_state,
2628 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002629{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002630 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002631 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002632
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002633 if (old_crtc_state->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002634 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002635
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002636 if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv))
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002637 intel_psr_disable(intel_dp);
2638
Daniel Vetter6cb49832012-05-20 17:14:50 +02002639 /* Make sure the panel is off before trying to change the mode. But also
2640 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002641 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01002642 intel_edp_backlight_off(intel_dp);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002643 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002644 intel_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02002645
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002646 /* disable the port before the pipe on g4x */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002647 if (INTEL_GEN(dev_priv) < 5)
Daniel Vetter37398502012-09-06 22:15:44 +02002648 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07002649}
2650
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002651static void ilk_post_disable_dp(struct intel_encoder *encoder,
2652 struct intel_crtc_state *old_crtc_state,
2653 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002654{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002655 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002656 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002657
Ville Syrjälä49277c32014-03-31 18:21:26 +03002658 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002659
2660 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002661 if (port == PORT_A)
2662 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002663}
2664
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002665static void vlv_post_disable_dp(struct intel_encoder *encoder,
2666 struct intel_crtc_state *old_crtc_state,
2667 struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002668{
2669 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2670
2671 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002672}
2673
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002674static void chv_post_disable_dp(struct intel_encoder *encoder,
2675 struct intel_crtc_state *old_crtc_state,
2676 struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002677{
2678 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002679 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002680 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002681
2682 intel_dp_link_down(intel_dp);
2683
Ville Syrjäläa5805162015-05-26 20:42:30 +03002684 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002685
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002686 /* Assert data lane reset */
2687 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002688
Ville Syrjäläa5805162015-05-26 20:42:30 +03002689 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002690}
2691
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002692static void
2693_intel_dp_set_link_train(struct intel_dp *intel_dp,
2694 uint32_t *DP,
2695 uint8_t dp_train_pat)
2696{
2697 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2698 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002699 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002700 enum port port = intel_dig_port->port;
2701
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002702 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2703 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2704 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2705
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002706 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002707 uint32_t temp = I915_READ(DP_TP_CTL(port));
2708
2709 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2710 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2711 else
2712 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2713
2714 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2715 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2716 case DP_TRAINING_PATTERN_DISABLE:
2717 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2718
2719 break;
2720 case DP_TRAINING_PATTERN_1:
2721 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2722 break;
2723 case DP_TRAINING_PATTERN_2:
2724 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2725 break;
2726 case DP_TRAINING_PATTERN_3:
2727 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2728 break;
2729 }
2730 I915_WRITE(DP_TP_CTL(port), temp);
2731
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002732 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002733 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002734 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2735
2736 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2737 case DP_TRAINING_PATTERN_DISABLE:
2738 *DP |= DP_LINK_TRAIN_OFF_CPT;
2739 break;
2740 case DP_TRAINING_PATTERN_1:
2741 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2742 break;
2743 case DP_TRAINING_PATTERN_2:
2744 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2745 break;
2746 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002747 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002748 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2749 break;
2750 }
2751
2752 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002753 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002754 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2755 else
2756 *DP &= ~DP_LINK_TRAIN_MASK;
2757
2758 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2759 case DP_TRAINING_PATTERN_DISABLE:
2760 *DP |= DP_LINK_TRAIN_OFF;
2761 break;
2762 case DP_TRAINING_PATTERN_1:
2763 *DP |= DP_LINK_TRAIN_PAT_1;
2764 break;
2765 case DP_TRAINING_PATTERN_2:
2766 *DP |= DP_LINK_TRAIN_PAT_2;
2767 break;
2768 case DP_TRAINING_PATTERN_3:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002769 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002770 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2771 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002772 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002773 *DP |= DP_LINK_TRAIN_PAT_2;
2774 }
2775 break;
2776 }
2777 }
2778}
2779
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002780static void intel_dp_enable_port(struct intel_dp *intel_dp,
2781 struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002782{
2783 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002784 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002785
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002786 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002787
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002788 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002789
2790 /*
2791 * Magic for VLV/CHV. We _must_ first set up the register
2792 * without actually enabling the port, and then do another
2793 * write to enable the port. Otherwise link training will
2794 * fail when the power sequencer is freshly used for this port.
2795 */
2796 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002797 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002798 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002799
2800 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2801 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002802}
2803
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002804static void intel_enable_dp(struct intel_encoder *encoder,
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002805 struct intel_crtc_state *pipe_config,
2806 struct drm_connector_state *conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002807{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002808 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2809 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002810 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulac1dec792014-10-27 16:26:56 +02002811 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002812 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002813 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002814
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002815 if (WARN_ON(dp_reg & DP_PORT_EN))
2816 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002817
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002818 pps_lock(intel_dp);
2819
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002820 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002821 vlv_init_panel_power_sequencer(intel_dp);
2822
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002823 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002824
2825 edp_panel_vdd_on(intel_dp);
2826 edp_panel_on(intel_dp);
2827 edp_panel_vdd_off(intel_dp, true);
2828
2829 pps_unlock(intel_dp);
2830
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002831 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002832 unsigned int lane_mask = 0x0;
2833
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002834 if (IS_CHERRYVIEW(dev_priv))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002835 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002836
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002837 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2838 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002839 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002840
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002841 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2842 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002843 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002844
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002845 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002846 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002847 pipe_name(pipe));
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002848 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Jani Nikulac1dec792014-10-27 16:26:56 +02002849 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002850}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002851
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002852static void g4x_enable_dp(struct intel_encoder *encoder,
2853 struct intel_crtc_state *pipe_config,
2854 struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03002855{
Jani Nikula828f5c62013-09-05 16:44:45 +03002856 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2857
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002858 intel_enable_dp(encoder, pipe_config, conn_state);
Daniel Vetter4be73782014-01-17 14:39:48 +01002859 intel_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002860}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002861
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002862static void vlv_enable_dp(struct intel_encoder *encoder,
2863 struct intel_crtc_state *pipe_config,
2864 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002865{
Jani Nikula828f5c62013-09-05 16:44:45 +03002866 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2867
Daniel Vetter4be73782014-01-17 14:39:48 +01002868 intel_edp_backlight_on(intel_dp);
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002869 intel_psr_enable(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002870}
2871
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002872static void g4x_pre_enable_dp(struct intel_encoder *encoder,
2873 struct intel_crtc_state *pipe_config,
2874 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002875{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002876 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002877 enum port port = dp_to_dig_port(intel_dp)->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002878
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002879 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002880
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002881 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002882 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002883 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002884}
2885
Ville Syrjälä83b84592014-10-16 21:29:51 +03002886static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2887{
2888 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002889 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002890 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03002891 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002892
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002893 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
2894
Ville Syrjäläd1586942017-02-08 19:52:54 +02002895 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2896 return;
2897
Ville Syrjälä83b84592014-10-16 21:29:51 +03002898 edp_panel_vdd_off_sync(intel_dp);
2899
2900 /*
2901 * VLV seems to get confused when multiple power seqeuencers
2902 * have the same port selected (even if only one has power/vdd
2903 * enabled). The failure manifests as vlv_wait_port_ready() failing
2904 * CHV on the other hand doesn't seem to mind having the same port
2905 * selected in multiple power seqeuencers, but let's clear the
2906 * port select always when logically disconnecting a power sequencer
2907 * from a port.
2908 */
2909 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2910 pipe_name(pipe), port_name(intel_dig_port->port));
2911 I915_WRITE(pp_on_reg, 0);
2912 POSTING_READ(pp_on_reg);
2913
2914 intel_dp->pps_pipe = INVALID_PIPE;
2915}
2916
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002917static void vlv_steal_power_sequencer(struct drm_device *dev,
2918 enum pipe pipe)
2919{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002920 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002921 struct intel_encoder *encoder;
2922
2923 lockdep_assert_held(&dev_priv->pps_mutex);
2924
Jani Nikula19c80542015-12-16 12:48:16 +02002925 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002926 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002927 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002928
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002929 if (encoder->type != INTEL_OUTPUT_DP &&
2930 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002931 continue;
2932
2933 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002934 port = dp_to_dig_port(intel_dp)->port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002935
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002936 WARN(intel_dp->active_pipe == pipe,
2937 "stealing pipe %c power sequencer from active (e)DP port %c\n",
2938 pipe_name(pipe), port_name(port));
2939
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002940 if (intel_dp->pps_pipe != pipe)
2941 continue;
2942
2943 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03002944 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002945
2946 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002947 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002948 }
2949}
2950
2951static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
2952{
2953 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2954 struct intel_encoder *encoder = &intel_dig_port->base;
2955 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002956 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002957 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002958
2959 lockdep_assert_held(&dev_priv->pps_mutex);
2960
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002961 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002962
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002963 if (intel_dp->pps_pipe != INVALID_PIPE &&
2964 intel_dp->pps_pipe != crtc->pipe) {
2965 /*
2966 * If another power sequencer was being used on this
2967 * port previously make sure to turn off vdd there while
2968 * we still have control of it.
2969 */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002970 vlv_detach_power_sequencer(intel_dp);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002971 }
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002972
2973 /*
2974 * We may be stealing the power
2975 * sequencer from another port.
2976 */
2977 vlv_steal_power_sequencer(dev, crtc->pipe);
2978
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002979 intel_dp->active_pipe = crtc->pipe;
2980
2981 if (!is_edp(intel_dp))
2982 return;
2983
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002984 /* now it's all ours */
2985 intel_dp->pps_pipe = crtc->pipe;
2986
2987 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
2988 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
2989
2990 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03002991 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02002992 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002993}
2994
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002995static void vlv_pre_enable_dp(struct intel_encoder *encoder,
2996 struct intel_crtc_state *pipe_config,
2997 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002998{
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03002999 vlv_phy_pre_encoder_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003000
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003001 intel_enable_dp(encoder, pipe_config, conn_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003002}
3003
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003004static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
3005 struct intel_crtc_state *pipe_config,
3006 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07003007{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003008 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02003009
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03003010 vlv_phy_pre_pll_enable(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003011}
3012
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003013static void chv_pre_enable_dp(struct intel_encoder *encoder,
3014 struct intel_crtc_state *pipe_config,
3015 struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003016{
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003017 chv_phy_pre_encoder_enable(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003018
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003019 intel_enable_dp(encoder, pipe_config, conn_state);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03003020
3021 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003022 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003023}
3024
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003025static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
3026 struct intel_crtc_state *pipe_config,
3027 struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03003028{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003029 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03003030
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03003031 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03003032}
3033
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003034static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
3035 struct intel_crtc_state *pipe_config,
3036 struct drm_connector_state *conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003037{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03003038 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003039}
3040
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003041/*
3042 * Fetch AUX CH registers 0x202 - 0x207 which contain
3043 * link status information
3044 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003045bool
Keith Packard93f62da2011-11-01 19:45:03 -07003046intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003047{
Lyude9f085eb2016-04-13 10:58:33 -04003048 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
3049 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003050}
3051
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303052static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp)
3053{
3054 uint8_t psr_caps = 0;
3055
3056 drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps);
3057 return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED;
3058}
3059
3060static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp)
3061{
3062 uint8_t dprx = 0;
3063
3064 drm_dp_dpcd_readb(&intel_dp->aux,
3065 DP_DPRX_FEATURE_ENUMERATION_LIST,
3066 &dprx);
3067 return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED;
3068}
3069
Chris Wilsona76f73d2017-01-14 10:51:13 +00003070static bool intel_dp_get_alpm_status(struct intel_dp *intel_dp)
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303071{
3072 uint8_t alpm_caps = 0;
3073
3074 drm_dp_dpcd_readb(&intel_dp->aux, DP_RECEIVER_ALPM_CAP, &alpm_caps);
3075 return alpm_caps & DP_ALPM_CAP;
3076}
3077
Paulo Zanoni11002442014-06-13 18:45:41 -03003078/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003079uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003080intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003081{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003082 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003083 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003084
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003085 if (IS_GEN9_LP(dev_priv))
Vandana Kannan93147262014-11-18 15:45:29 +05303086 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003087 else if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjäläffe51112017-02-23 19:49:01 +02003088 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3089 return intel_ddi_dp_voltage_max(encoder);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003090 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Sonika Jindalbd600182014-08-08 16:23:41 +05303091 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003092 else if (IS_GEN7(dev_priv) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303093 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003094 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303095 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08003096 else
Sonika Jindalbd600182014-08-08 16:23:41 +05303097 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08003098}
3099
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003100uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003101intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3102{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003103 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003104 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003105
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003106 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003107 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3108 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3109 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3110 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3111 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3112 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3113 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303114 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3115 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003116 default:
3117 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3118 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003119 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003120 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303121 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3122 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3123 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3124 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3125 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3126 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3127 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003128 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303129 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003130 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003131 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003132 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:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003140 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303141 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003142 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003143 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003144 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_2;
3147 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3148 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3149 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003150 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303151 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003152 }
3153 } else {
3154 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303155 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3156 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3157 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3158 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3159 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3160 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3161 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
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 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003165 }
3166}
3167
Daniel Vetter5829975c2015-04-16 11:36:52 +02003168static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003169{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003170 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003171 unsigned long demph_reg_value, preemph_reg_value,
3172 uniqtranscale_reg_value;
3173 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003174
3175 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303176 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003177 preemph_reg_value = 0x0004000;
3178 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303179 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003180 demph_reg_value = 0x2B405555;
3181 uniqtranscale_reg_value = 0x552AB83A;
3182 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303183 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003184 demph_reg_value = 0x2B404040;
3185 uniqtranscale_reg_value = 0x5548B83A;
3186 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303187 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003188 demph_reg_value = 0x2B245555;
3189 uniqtranscale_reg_value = 0x5560B83A;
3190 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303191 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003192 demph_reg_value = 0x2B405555;
3193 uniqtranscale_reg_value = 0x5598DA3A;
3194 break;
3195 default:
3196 return 0;
3197 }
3198 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303199 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003200 preemph_reg_value = 0x0002000;
3201 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303202 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003203 demph_reg_value = 0x2B404040;
3204 uniqtranscale_reg_value = 0x5552B83A;
3205 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303206 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003207 demph_reg_value = 0x2B404848;
3208 uniqtranscale_reg_value = 0x5580B83A;
3209 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303210 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003211 demph_reg_value = 0x2B404040;
3212 uniqtranscale_reg_value = 0x55ADDA3A;
3213 break;
3214 default:
3215 return 0;
3216 }
3217 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303218 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003219 preemph_reg_value = 0x0000000;
3220 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303221 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003222 demph_reg_value = 0x2B305555;
3223 uniqtranscale_reg_value = 0x5570B83A;
3224 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303225 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003226 demph_reg_value = 0x2B2B4040;
3227 uniqtranscale_reg_value = 0x55ADDA3A;
3228 break;
3229 default:
3230 return 0;
3231 }
3232 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303233 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003234 preemph_reg_value = 0x0006000;
3235 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303236 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003237 demph_reg_value = 0x1B405555;
3238 uniqtranscale_reg_value = 0x55ADDA3A;
3239 break;
3240 default:
3241 return 0;
3242 }
3243 break;
3244 default:
3245 return 0;
3246 }
3247
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003248 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3249 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003250
3251 return 0;
3252}
3253
Daniel Vetter5829975c2015-04-16 11:36:52 +02003254static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003255{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003256 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3257 u32 deemph_reg_value, margin_reg_value;
3258 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003259 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003260
3261 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303262 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003263 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303264 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003265 deemph_reg_value = 128;
3266 margin_reg_value = 52;
3267 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303268 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003269 deemph_reg_value = 128;
3270 margin_reg_value = 77;
3271 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303272 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003273 deemph_reg_value = 128;
3274 margin_reg_value = 102;
3275 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303276 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003277 deemph_reg_value = 128;
3278 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003279 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003280 break;
3281 default:
3282 return 0;
3283 }
3284 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303285 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003286 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303287 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003288 deemph_reg_value = 85;
3289 margin_reg_value = 78;
3290 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303291 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003292 deemph_reg_value = 85;
3293 margin_reg_value = 116;
3294 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303295 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003296 deemph_reg_value = 85;
3297 margin_reg_value = 154;
3298 break;
3299 default:
3300 return 0;
3301 }
3302 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303303 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003304 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303305 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003306 deemph_reg_value = 64;
3307 margin_reg_value = 104;
3308 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303309 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003310 deemph_reg_value = 64;
3311 margin_reg_value = 154;
3312 break;
3313 default:
3314 return 0;
3315 }
3316 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303317 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003318 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303319 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003320 deemph_reg_value = 43;
3321 margin_reg_value = 154;
3322 break;
3323 default:
3324 return 0;
3325 }
3326 break;
3327 default:
3328 return 0;
3329 }
3330
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003331 chv_set_phy_signal_level(encoder, deemph_reg_value,
3332 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003333
3334 return 0;
3335}
3336
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003337static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003338gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003339{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003340 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003341
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003342 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303343 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003344 default:
3345 signal_levels |= DP_VOLTAGE_0_4;
3346 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303347 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003348 signal_levels |= DP_VOLTAGE_0_6;
3349 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303350 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003351 signal_levels |= DP_VOLTAGE_0_8;
3352 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303353 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003354 signal_levels |= DP_VOLTAGE_1_2;
3355 break;
3356 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003357 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303358 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003359 default:
3360 signal_levels |= DP_PRE_EMPHASIS_0;
3361 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303362 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003363 signal_levels |= DP_PRE_EMPHASIS_3_5;
3364 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303365 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003366 signal_levels |= DP_PRE_EMPHASIS_6;
3367 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303368 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003369 signal_levels |= DP_PRE_EMPHASIS_9_5;
3370 break;
3371 }
3372 return signal_levels;
3373}
3374
Zhenyu Wange3421a12010-04-08 09:43:27 +08003375/* Gen6's DP voltage swing and pre-emphasis control */
3376static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003377gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003378{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003379 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3380 DP_TRAIN_PRE_EMPHASIS_MASK);
3381 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303382 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3383 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003384 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303385 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003386 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303387 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3388 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003389 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303390 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3391 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003392 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303393 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3394 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003395 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003396 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003397 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3398 "0x%x\n", signal_levels);
3399 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003400 }
3401}
3402
Keith Packard1a2eb462011-11-16 16:26:07 -08003403/* Gen7's DP voltage swing and pre-emphasis control */
3404static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003405gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003406{
3407 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3408 DP_TRAIN_PRE_EMPHASIS_MASK);
3409 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303410 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003411 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303412 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003413 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303414 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003415 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3416
Sonika Jindalbd600182014-08-08 16:23:41 +05303417 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003418 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303419 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003420 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3421
Sonika Jindalbd600182014-08-08 16:23:41 +05303422 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003423 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303424 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003425 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3426
3427 default:
3428 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3429 "0x%x\n", signal_levels);
3430 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3431 }
3432}
3433
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003434void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003435intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003436{
3437 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003438 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003439 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003440 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003441 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003442 uint8_t train_set = intel_dp->train_set[0];
3443
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003444 if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003445 signal_levels = ddi_signal_levels(intel_dp);
3446
Michel Thierry254e0932017-01-09 16:51:35 +02003447 if (IS_GEN9_LP(dev_priv))
David Weinehallf8896f52015-06-25 11:11:03 +03003448 signal_levels = 0;
3449 else
3450 mask = DDI_BUF_EMP_MASK;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003451 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003452 signal_levels = chv_signal_levels(intel_dp);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003453 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003454 signal_levels = vlv_signal_levels(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003455 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003456 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003457 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003458 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003459 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003460 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3461 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003462 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003463 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3464 }
3465
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303466 if (mask)
3467 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3468
3469 DRM_DEBUG_KMS("Using vswing level %d\n",
3470 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3471 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3472 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3473 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003474
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003475 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003476
3477 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3478 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003479}
3480
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003481void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003482intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3483 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003484{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003485 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003486 struct drm_i915_private *dev_priv =
3487 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003488
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003489 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003490
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003491 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003492 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003493}
3494
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003495void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003496{
3497 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3498 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003499 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak3ab9c632013-05-03 12:57:41 +03003500 enum port port = intel_dig_port->port;
3501 uint32_t val;
3502
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003503 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003504 return;
3505
3506 val = I915_READ(DP_TP_CTL(port));
3507 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3508 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3509 I915_WRITE(DP_TP_CTL(port), val);
3510
3511 /*
3512 * On PORT_A we can have only eDP in SST mode. There the only reason
3513 * we need to set idle transmission mode is to work around a HW issue
3514 * where we enable the pipe while not in idle link-training mode.
3515 * In this case there is requirement to wait for a minimum number of
3516 * idle patterns to be sent.
3517 */
3518 if (port == PORT_A)
3519 return;
3520
Chris Wilsona7670172016-06-30 15:33:10 +01003521 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3522 DP_TP_STATUS_IDLE_DONE,
3523 DP_TP_STATUS_IDLE_DONE,
3524 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003525 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3526}
3527
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003528static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003529intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003530{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003531 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003532 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003533 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003534 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003535 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003536 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003537
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003538 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003539 return;
3540
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003541 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003542 return;
3543
Zhao Yakui28c97732009-10-09 11:39:41 +08003544 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003545
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003546 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003547 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003548 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003549 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003550 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003551 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003552 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3553 else
3554 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003555 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003556 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003557 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003558 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003559
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003560 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3561 I915_WRITE(intel_dp->output_reg, DP);
3562 POSTING_READ(intel_dp->output_reg);
3563
3564 /*
3565 * HW workaround for IBX, we need to move the port
3566 * to transcoder A after disabling it to allow the
3567 * matching HDMI port to be enabled on transcoder A.
3568 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003569 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003570 /*
3571 * We get CPU/PCH FIFO underruns on the other pipe when
3572 * doing the workaround. Sweep them under the rug.
3573 */
3574 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3575 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3576
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003577 /* always enable with pattern 1 (as per spec) */
3578 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3579 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3580 I915_WRITE(intel_dp->output_reg, DP);
3581 POSTING_READ(intel_dp->output_reg);
3582
3583 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003584 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003585 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003586
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003587 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003588 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3589 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003590 }
3591
Keith Packardf01eca22011-09-28 16:48:10 -07003592 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003593
3594 intel_dp->DP = DP;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003595
3596 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3597 pps_lock(intel_dp);
3598 intel_dp->active_pipe = INVALID_PIPE;
3599 pps_unlock(intel_dp);
3600 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003601}
3602
Imre Deak24e807e2016-10-24 19:33:28 +03003603bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003604intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003605{
Lyude9f085eb2016-04-13 10:58:33 -04003606 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3607 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003608 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003609
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003610 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003611
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003612 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3613}
3614
3615static bool
3616intel_edp_init_dpcd(struct intel_dp *intel_dp)
3617{
3618 struct drm_i915_private *dev_priv =
3619 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3620
3621 /* this function is meant to be called only once */
3622 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3623
3624 if (!intel_dp_read_dpcd(intel_dp))
3625 return false;
3626
Imre Deak12a47a422016-10-24 19:33:29 +03003627 intel_dp_read_desc(intel_dp);
3628
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003629 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3630 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3631 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3632
3633 /* Check if the panel supports PSR */
3634 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3635 intel_dp->psr_dpcd,
3636 sizeof(intel_dp->psr_dpcd));
3637 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3638 dev_priv->psr.sink_support = true;
3639 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3640 }
3641
3642 if (INTEL_GEN(dev_priv) >= 9 &&
3643 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3644 uint8_t frame_sync_cap;
3645
3646 dev_priv->psr.sink_support = true;
3647 drm_dp_dpcd_read(&intel_dp->aux,
3648 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3649 &frame_sync_cap, 1);
3650 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3651 /* PSR2 needs frame sync as well */
3652 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3653 DRM_DEBUG_KMS("PSR2 %s on sink",
3654 dev_priv->psr.psr2_support ? "supported" : "not supported");
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303655
3656 if (dev_priv->psr.psr2_support) {
3657 dev_priv->psr.y_cord_support =
3658 intel_dp_get_y_cord_status(intel_dp);
3659 dev_priv->psr.colorimetry_support =
3660 intel_dp_get_colorimetry_status(intel_dp);
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303661 dev_priv->psr.alpm =
3662 intel_dp_get_alpm_status(intel_dp);
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303663 }
3664
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003665 }
3666
3667 /* Read the eDP Display control capabilities registers */
3668 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
3669 drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003670 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3671 sizeof(intel_dp->edp_dpcd))
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003672 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3673 intel_dp->edp_dpcd);
3674
3675 /* Intermediate frequency support */
3676 if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */
3677 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3678 int i;
3679
3680 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3681 sink_rates, sizeof(sink_rates));
3682
3683 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3684 int val = le16_to_cpu(sink_rates[i]);
3685
3686 if (val == 0)
3687 break;
3688
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -08003689 /* Value read multiplied by 200kHz gives the per-lane
3690 * link rate in kHz. The source rates are, however,
3691 * stored in terms of LS_Clk kHz. The full conversion
3692 * back to symbols is
3693 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
3694 */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003695 intel_dp->sink_rates[i] = (val * 200) / 10;
3696 }
3697 intel_dp->num_sink_rates = i;
3698 }
3699
3700 return true;
3701}
3702
3703
3704static bool
3705intel_dp_get_dpcd(struct intel_dp *intel_dp)
3706{
3707 if (!intel_dp_read_dpcd(intel_dp))
3708 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003709
Lyude9f085eb2016-04-13 10:58:33 -04003710 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT,
3711 &intel_dp->sink_count, 1) < 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303712 return false;
3713
3714 /*
3715 * Sink count can change between short pulse hpd hence
3716 * a member variable in intel_dp will track any changes
3717 * between short pulse interrupts.
3718 */
3719 intel_dp->sink_count = DP_GET_SINK_COUNT(intel_dp->sink_count);
3720
3721 /*
3722 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3723 * a dongle is present but no display. Unless we require to know
3724 * if a dongle is present or not, we don't need to update
3725 * downstream port information. So, an early return here saves
3726 * time from performing other operations which are not required.
3727 */
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05303728 if (!is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303729 return false;
3730
Imre Deakc726ad02016-10-24 19:33:24 +03003731 if (!drm_dp_is_branch(intel_dp->dpcd))
Adam Jacksonedb39242012-09-18 10:58:49 -04003732 return true; /* native DP sink */
3733
3734 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3735 return true; /* no per-port downstream info */
3736
Lyude9f085eb2016-04-13 10:58:33 -04003737 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3738 intel_dp->downstream_ports,
3739 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003740 return false; /* downstream port status fetch failed */
3741
3742 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003743}
3744
Dave Airlie0e32b392014-05-02 14:02:48 +10003745static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003746intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003747{
3748 u8 buf[1];
3749
Nathan Schulte7cc96132016-03-15 10:14:05 -05003750 if (!i915.enable_dp_mst)
3751 return false;
3752
Dave Airlie0e32b392014-05-02 14:02:48 +10003753 if (!intel_dp->can_mst)
3754 return false;
3755
3756 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3757 return false;
3758
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003759 if (drm_dp_dpcd_read(&intel_dp->aux, DP_MSTM_CAP, buf, 1) != 1)
3760 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003761
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003762 return buf[0] & DP_MST_CAP;
3763}
3764
3765static void
3766intel_dp_configure_mst(struct intel_dp *intel_dp)
3767{
3768 if (!i915.enable_dp_mst)
3769 return;
3770
3771 if (!intel_dp->can_mst)
3772 return;
3773
3774 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3775
3776 if (intel_dp->is_mst)
3777 DRM_DEBUG_KMS("Sink is MST capable\n");
3778 else
3779 DRM_DEBUG_KMS("Sink is not MST capable\n");
3780
3781 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3782 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003783}
3784
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003785static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003786{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003787 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003788 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003789 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003790 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003791 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003792 int count = 0;
3793 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003794
3795 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003796 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003797 ret = -EIO;
3798 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003799 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003800
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003801 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003802 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003803 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003804 ret = -EIO;
3805 goto out;
3806 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003807
Rodrigo Vivic6297842015-11-05 10:50:20 -08003808 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003809 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivic6297842015-11-05 10:50:20 -08003810
3811 if (drm_dp_dpcd_readb(&intel_dp->aux,
3812 DP_TEST_SINK_MISC, &buf) < 0) {
3813 ret = -EIO;
3814 goto out;
3815 }
3816 count = buf & DP_TEST_COUNT_MASK;
3817 } while (--attempts && count);
3818
3819 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003820 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003821 ret = -ETIMEDOUT;
3822 }
3823
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003824 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003825 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003826 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003827}
3828
3829static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3830{
3831 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003832 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003833 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3834 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003835 int ret;
3836
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003837 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3838 return -EIO;
3839
3840 if (!(buf & DP_TEST_CRC_SUPPORTED))
3841 return -ENOTTY;
3842
3843 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3844 return -EIO;
3845
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003846 if (buf & DP_TEST_SINK_START) {
3847 ret = intel_dp_sink_crc_stop(intel_dp);
3848 if (ret)
3849 return ret;
3850 }
3851
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003852 hsw_disable_ips(intel_crtc);
3853
3854 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3855 buf | DP_TEST_SINK_START) < 0) {
3856 hsw_enable_ips(intel_crtc);
3857 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003858 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003859
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003860 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003861 return 0;
3862}
3863
3864int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3865{
3866 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003867 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003868 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3869 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003870 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003871 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003872
3873 ret = intel_dp_sink_crc_start(intel_dp);
3874 if (ret)
3875 return ret;
3876
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003877 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003878 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003879
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003880 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003881 DP_TEST_SINK_MISC, &buf) < 0) {
3882 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003883 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003884 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003885 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07003886
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003887 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003888
3889 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003890 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
3891 ret = -ETIMEDOUT;
3892 goto stop;
3893 }
3894
3895 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
3896 ret = -EIO;
3897 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003898 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003899
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003900stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003901 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003902 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003903}
3904
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003905static bool
3906intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3907{
Lyude9f085eb2016-04-13 10:58:33 -04003908 return drm_dp_dpcd_read(&intel_dp->aux,
Jani Nikula9d1a1032014-03-14 16:51:15 +02003909 DP_DEVICE_SERVICE_IRQ_VECTOR,
3910 sink_irq_vector, 1) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003911}
3912
Dave Airlie0e32b392014-05-02 14:02:48 +10003913static bool
3914intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3915{
3916 int ret;
3917
Lyude9f085eb2016-04-13 10:58:33 -04003918 ret = drm_dp_dpcd_read(&intel_dp->aux,
Dave Airlie0e32b392014-05-02 14:02:48 +10003919 DP_SINK_COUNT_ESI,
3920 sink_irq_vector, 14);
3921 if (ret != 14)
3922 return false;
3923
3924 return true;
3925}
3926
Todd Previtec5d5ab72015-04-15 08:38:38 -07003927static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003928{
Manasi Navareda15f7c2017-01-24 08:16:34 -08003929 int status = 0;
3930 int min_lane_count = 1;
3931 int common_rates[DP_MAX_SUPPORTED_RATES] = {};
3932 int link_rate_index, test_link_rate;
3933 uint8_t test_lane_count, test_link_bw;
3934 /* (DP CTS 1.2)
3935 * 4.3.1.11
3936 */
3937 /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */
3938 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT,
3939 &test_lane_count);
3940
3941 if (status <= 0) {
3942 DRM_DEBUG_KMS("Lane count read failed\n");
3943 return DP_TEST_NAK;
3944 }
3945 test_lane_count &= DP_MAX_LANE_COUNT_MASK;
3946 /* Validate the requested lane count */
3947 if (test_lane_count < min_lane_count ||
3948 test_lane_count > intel_dp->max_sink_lane_count)
3949 return DP_TEST_NAK;
3950
3951 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE,
3952 &test_link_bw);
3953 if (status <= 0) {
3954 DRM_DEBUG_KMS("Link Rate read failed\n");
3955 return DP_TEST_NAK;
3956 }
3957 /* Validate the requested link rate */
3958 test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw);
3959 link_rate_index = intel_dp_link_rate_index(intel_dp,
3960 common_rates,
3961 test_link_rate);
3962 if (link_rate_index < 0)
3963 return DP_TEST_NAK;
3964
3965 intel_dp->compliance.test_lane_count = test_lane_count;
3966 intel_dp->compliance.test_link_rate = test_link_rate;
3967
3968 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07003969}
3970
3971static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
3972{
Manasi Navare611032b2017-01-24 08:21:49 -08003973 uint8_t test_pattern;
3974 uint16_t test_misc;
3975 __be16 h_width, v_height;
3976 int status = 0;
3977
3978 /* Read the TEST_PATTERN (DP CTS 3.1.5) */
3979 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_PATTERN,
3980 &test_pattern, 1);
3981 if (status <= 0) {
3982 DRM_DEBUG_KMS("Test pattern read failed\n");
3983 return DP_TEST_NAK;
3984 }
3985 if (test_pattern != DP_COLOR_RAMP)
3986 return DP_TEST_NAK;
3987
3988 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI,
3989 &h_width, 2);
3990 if (status <= 0) {
3991 DRM_DEBUG_KMS("H Width read failed\n");
3992 return DP_TEST_NAK;
3993 }
3994
3995 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI,
3996 &v_height, 2);
3997 if (status <= 0) {
3998 DRM_DEBUG_KMS("V Height read failed\n");
3999 return DP_TEST_NAK;
4000 }
4001
4002 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_MISC0,
4003 &test_misc, 1);
4004 if (status <= 0) {
4005 DRM_DEBUG_KMS("TEST MISC read failed\n");
4006 return DP_TEST_NAK;
4007 }
4008 if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB)
4009 return DP_TEST_NAK;
4010 if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA)
4011 return DP_TEST_NAK;
4012 switch (test_misc & DP_TEST_BIT_DEPTH_MASK) {
4013 case DP_TEST_BIT_DEPTH_6:
4014 intel_dp->compliance.test_data.bpc = 6;
4015 break;
4016 case DP_TEST_BIT_DEPTH_8:
4017 intel_dp->compliance.test_data.bpc = 8;
4018 break;
4019 default:
4020 return DP_TEST_NAK;
4021 }
4022
4023 intel_dp->compliance.test_data.video_pattern = test_pattern;
4024 intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width);
4025 intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height);
4026 /* Set test active flag here so userspace doesn't interrupt things */
4027 intel_dp->compliance.test_active = 1;
4028
4029 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004030}
4031
4032static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
4033{
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004034 uint8_t test_result = DP_TEST_ACK;
Todd Previte559be302015-05-04 07:48:20 -07004035 struct intel_connector *intel_connector = intel_dp->attached_connector;
4036 struct drm_connector *connector = &intel_connector->base;
4037
4038 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02004039 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07004040 intel_dp->aux.i2c_defer_count > 6) {
4041 /* Check EDID read for NACKs, DEFERs and corruption
4042 * (DP CTS 1.2 Core r1.1)
4043 * 4.2.2.4 : Failed EDID read, I2C_NAK
4044 * 4.2.2.5 : Failed EDID read, I2C_DEFER
4045 * 4.2.2.6 : EDID corruption detected
4046 * Use failsafe mode for all cases
4047 */
4048 if (intel_dp->aux.i2c_nack_count > 0 ||
4049 intel_dp->aux.i2c_defer_count > 0)
4050 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
4051 intel_dp->aux.i2c_nack_count,
4052 intel_dp->aux.i2c_defer_count);
Manasi Navarec1617ab2016-12-09 16:22:50 -08004053 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
Todd Previte559be302015-05-04 07:48:20 -07004054 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05304055 struct edid *block = intel_connector->detect_edid;
4056
4057 /* We have to write the checksum
4058 * of the last block read
4059 */
4060 block += intel_connector->detect_edid->extensions;
4061
Todd Previte559be302015-05-04 07:48:20 -07004062 if (!drm_dp_dpcd_write(&intel_dp->aux,
4063 DP_TEST_EDID_CHECKSUM,
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05304064 &block->checksum,
Dan Carpenter5a1cc652015-05-12 21:07:37 +03004065 1))
Todd Previte559be302015-05-04 07:48:20 -07004066 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
4067
4068 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004069 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED;
Todd Previte559be302015-05-04 07:48:20 -07004070 }
4071
4072 /* Set test active flag here so userspace doesn't interrupt things */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004073 intel_dp->compliance.test_active = 1;
Todd Previte559be302015-05-04 07:48:20 -07004074
Todd Previtec5d5ab72015-04-15 08:38:38 -07004075 return test_result;
4076}
4077
4078static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
4079{
4080 uint8_t test_result = DP_TEST_NAK;
4081 return test_result;
4082}
4083
4084static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
4085{
4086 uint8_t response = DP_TEST_NAK;
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004087 uint8_t request = 0;
4088 int status;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004089
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004090 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004091 if (status <= 0) {
4092 DRM_DEBUG_KMS("Could not read test request from sink\n");
4093 goto update_status;
4094 }
4095
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004096 switch (request) {
Todd Previtec5d5ab72015-04-15 08:38:38 -07004097 case DP_TEST_LINK_TRAINING:
4098 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004099 response = intel_dp_autotest_link_training(intel_dp);
4100 break;
4101 case DP_TEST_LINK_VIDEO_PATTERN:
4102 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004103 response = intel_dp_autotest_video_pattern(intel_dp);
4104 break;
4105 case DP_TEST_LINK_EDID_READ:
4106 DRM_DEBUG_KMS("EDID test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004107 response = intel_dp_autotest_edid(intel_dp);
4108 break;
4109 case DP_TEST_LINK_PHY_TEST_PATTERN:
4110 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004111 response = intel_dp_autotest_phy_pattern(intel_dp);
4112 break;
4113 default:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004114 DRM_DEBUG_KMS("Invalid test request '%02x'\n", request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004115 break;
4116 }
4117
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004118 if (response & DP_TEST_ACK)
4119 intel_dp->compliance.test_type = request;
4120
Todd Previtec5d5ab72015-04-15 08:38:38 -07004121update_status:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004122 status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004123 if (status <= 0)
4124 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004125}
4126
Dave Airlie0e32b392014-05-02 14:02:48 +10004127static int
4128intel_dp_check_mst_status(struct intel_dp *intel_dp)
4129{
4130 bool bret;
4131
4132 if (intel_dp->is_mst) {
4133 u8 esi[16] = { 0 };
4134 int ret = 0;
4135 int retry;
4136 bool handled;
4137 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4138go_again:
4139 if (bret == true) {
4140
4141 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03004142 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03004143 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10004144 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4145 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004146 intel_dp_stop_link_train(intel_dp);
4147 }
4148
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004149 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004150 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4151
4152 if (handled) {
4153 for (retry = 0; retry < 3; retry++) {
4154 int wret;
4155 wret = drm_dp_dpcd_write(&intel_dp->aux,
4156 DP_SINK_COUNT_ESI+1,
4157 &esi[1], 3);
4158 if (wret == 3) {
4159 break;
4160 }
4161 }
4162
4163 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4164 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004165 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004166 goto go_again;
4167 }
4168 } else
4169 ret = 0;
4170
4171 return ret;
4172 } else {
4173 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4174 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4175 intel_dp->is_mst = false;
4176 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4177 /* send a hotplug event */
4178 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4179 }
4180 }
4181 return -EINVAL;
4182}
4183
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304184static void
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004185intel_dp_retrain_link(struct intel_dp *intel_dp)
4186{
4187 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4188 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4189 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
4190
4191 /* Suppress underruns caused by re-training */
4192 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4193 if (crtc->config->has_pch_encoder)
4194 intel_set_pch_fifo_underrun_reporting(dev_priv,
4195 intel_crtc_pch_transcoder(crtc), false);
4196
4197 intel_dp_start_link_train(intel_dp);
4198 intel_dp_stop_link_train(intel_dp);
4199
4200 /* Keep underrun reporting disabled until things are stable */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02004201 intel_wait_for_vblank(dev_priv, crtc->pipe);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004202
4203 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4204 if (crtc->config->has_pch_encoder)
4205 intel_set_pch_fifo_underrun_reporting(dev_priv,
4206 intel_crtc_pch_transcoder(crtc), true);
4207}
4208
4209static void
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304210intel_dp_check_link_status(struct intel_dp *intel_dp)
4211{
4212 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4213 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4214 u8 link_status[DP_LINK_STATUS_SIZE];
4215
4216 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
4217
4218 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4219 DRM_ERROR("Failed to get link status\n");
4220 return;
4221 }
4222
4223 if (!intel_encoder->base.crtc)
4224 return;
4225
4226 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4227 return;
4228
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004229 /* FIXME: we need to synchronize this sort of stuff with hardware
Daniel Vetter2dd85ae2016-12-13 20:54:14 +01004230 * readout. Currently fast link training doesn't work on boot-up. */
4231 if (!intel_dp->lane_count)
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004232 return;
4233
Manasi Navareda15f7c2017-01-24 08:16:34 -08004234 /* Retrain if Channel EQ or CR not ok */
4235 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304236 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4237 intel_encoder->base.name);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004238
4239 intel_dp_retrain_link(intel_dp);
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304240 }
4241}
4242
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004243/*
4244 * According to DP spec
4245 * 5.1.2:
4246 * 1. Read DPCD
4247 * 2. Configure link according to Receiver Capabilities
4248 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4249 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304250 *
4251 * intel_dp_short_pulse - handles short pulse interrupts
4252 * when full detection is not required.
4253 * Returns %true if short pulse is handled and full detection
4254 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004255 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304256static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304257intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004258{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004259 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004260 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004261 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304262 u8 old_sink_count = intel_dp->sink_count;
4263 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004264
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304265 /*
4266 * Clearing compliance test variables to allow capturing
4267 * of values for next automated test request.
4268 */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004269 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304270
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304271 /*
4272 * Now read the DPCD to see if it's actually running
4273 * If the current value of sink count doesn't match with
4274 * the value that was stored earlier or dpcd read failed
4275 * we need to do full detection
4276 */
4277 ret = intel_dp_get_dpcd(intel_dp);
4278
4279 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4280 /* No need to proceed if we are going to do full detect */
4281 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004282 }
4283
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004284 /* Try to read the source of the interrupt */
4285 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004286 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4287 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004288 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004289 drm_dp_dpcd_writeb(&intel_dp->aux,
4290 DP_DEVICE_SERVICE_IRQ_VECTOR,
4291 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004292
4293 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Manasi Navareda15f7c2017-01-24 08:16:34 -08004294 intel_dp_handle_test_request(intel_dp);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004295 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4296 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4297 }
4298
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304299 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4300 intel_dp_check_link_status(intel_dp);
4301 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004302 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
4303 DRM_DEBUG_KMS("Link Training Compliance Test requested\n");
4304 /* Send a Hotplug Uevent to userspace to start modeset */
4305 drm_kms_helper_hotplug_event(intel_encoder->base.dev);
4306 }
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304307
4308 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004309}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004310
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004311/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004312static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004313intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004314{
Imre Deake393d0d2017-02-22 17:10:52 +02004315 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004316 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004317 uint8_t type;
4318
Imre Deake393d0d2017-02-22 17:10:52 +02004319 if (lspcon->active)
4320 lspcon_resume(lspcon);
4321
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004322 if (!intel_dp_get_dpcd(intel_dp))
4323 return connector_status_disconnected;
4324
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304325 if (is_edp(intel_dp))
4326 return connector_status_connected;
4327
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004328 /* if there's no downstream port, we're done */
Imre Deakc726ad02016-10-24 19:33:24 +03004329 if (!drm_dp_is_branch(dpcd))
Keith Packard26d61aa2011-07-25 20:01:09 -07004330 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004331
4332 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004333 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4334 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004335
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304336 return intel_dp->sink_count ?
4337 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004338 }
4339
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004340 if (intel_dp_can_mst(intel_dp))
4341 return connector_status_connected;
4342
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004343 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004344 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004345 return connector_status_connected;
4346
4347 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004348 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4349 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4350 if (type == DP_DS_PORT_TYPE_VGA ||
4351 type == DP_DS_PORT_TYPE_NON_EDID)
4352 return connector_status_unknown;
4353 } else {
4354 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4355 DP_DWN_STRM_PORT_TYPE_MASK;
4356 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4357 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4358 return connector_status_unknown;
4359 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004360
4361 /* Anything else is out of spec, warn and ignore */
4362 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004363 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004364}
4365
4366static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004367edp_detect(struct intel_dp *intel_dp)
4368{
4369 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Mika Kahola1650be72016-12-13 10:02:47 +02004370 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsond410b562014-09-02 20:03:59 +01004371 enum drm_connector_status status;
4372
Mika Kahola1650be72016-12-13 10:02:47 +02004373 status = intel_panel_detect(dev_priv);
Chris Wilsond410b562014-09-02 20:03:59 +01004374 if (status == connector_status_unknown)
4375 status = connector_status_connected;
4376
4377 return status;
4378}
4379
Jani Nikulab93433c2015-08-20 10:47:36 +03004380static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4381 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004382{
Jani Nikulab93433c2015-08-20 10:47:36 +03004383 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004384
Jani Nikula0df53b72015-08-20 10:47:40 +03004385 switch (port->port) {
4386 case PORT_A:
4387 return true;
4388 case PORT_B:
4389 bit = SDE_PORTB_HOTPLUG;
4390 break;
4391 case PORT_C:
4392 bit = SDE_PORTC_HOTPLUG;
4393 break;
4394 case PORT_D:
4395 bit = SDE_PORTD_HOTPLUG;
4396 break;
4397 default:
4398 MISSING_CASE(port->port);
4399 return false;
4400 }
4401
4402 return I915_READ(SDEISR) & bit;
4403}
4404
4405static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4406 struct intel_digital_port *port)
4407{
4408 u32 bit;
4409
4410 switch (port->port) {
4411 case PORT_A:
4412 return true;
4413 case PORT_B:
4414 bit = SDE_PORTB_HOTPLUG_CPT;
4415 break;
4416 case PORT_C:
4417 bit = SDE_PORTC_HOTPLUG_CPT;
4418 break;
4419 case PORT_D:
4420 bit = SDE_PORTD_HOTPLUG_CPT;
4421 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004422 case PORT_E:
4423 bit = SDE_PORTE_HOTPLUG_SPT;
4424 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004425 default:
4426 MISSING_CASE(port->port);
4427 return false;
Jani Nikulab93433c2015-08-20 10:47:36 +03004428 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004429
Jani Nikulab93433c2015-08-20 10:47:36 +03004430 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004431}
4432
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004433static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004434 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004435{
Jani Nikula9642c812015-08-20 10:47:41 +03004436 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004437
Jani Nikula9642c812015-08-20 10:47:41 +03004438 switch (port->port) {
4439 case PORT_B:
4440 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4441 break;
4442 case PORT_C:
4443 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4444 break;
4445 case PORT_D:
4446 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4447 break;
4448 default:
4449 MISSING_CASE(port->port);
4450 return false;
4451 }
4452
4453 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4454}
4455
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004456static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4457 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004458{
4459 u32 bit;
4460
4461 switch (port->port) {
4462 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004463 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004464 break;
4465 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004466 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004467 break;
4468 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004469 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004470 break;
4471 default:
4472 MISSING_CASE(port->port);
4473 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004474 }
4475
Jani Nikula1d245982015-08-20 10:47:37 +03004476 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004477}
4478
Jani Nikulae464bfd2015-08-20 10:47:42 +03004479static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304480 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004481{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304482 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4483 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004484 u32 bit;
4485
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304486 intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port);
4487 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004488 case PORT_A:
4489 bit = BXT_DE_PORT_HP_DDIA;
4490 break;
4491 case PORT_B:
4492 bit = BXT_DE_PORT_HP_DDIB;
4493 break;
4494 case PORT_C:
4495 bit = BXT_DE_PORT_HP_DDIC;
4496 break;
4497 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304498 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004499 return false;
4500 }
4501
4502 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4503}
4504
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004505/*
4506 * intel_digital_port_connected - is the specified port connected?
4507 * @dev_priv: i915 private structure
4508 * @port: the port to test
4509 *
4510 * Return %true if @port is connected, %false otherwise.
4511 */
Imre Deak390b4e02017-01-27 11:39:19 +02004512bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
4513 struct intel_digital_port *port)
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004514{
Jani Nikula0df53b72015-08-20 10:47:40 +03004515 if (HAS_PCH_IBX(dev_priv))
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004516 return ibx_digital_port_connected(dev_priv, port);
Ville Syrjälä22824fa2016-02-11 16:44:28 +02004517 else if (HAS_PCH_SPLIT(dev_priv))
Jani Nikula0df53b72015-08-20 10:47:40 +03004518 return cpt_digital_port_connected(dev_priv, port);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004519 else if (IS_GEN9_LP(dev_priv))
Jani Nikulae464bfd2015-08-20 10:47:42 +03004520 return bxt_digital_port_connected(dev_priv, port);
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004521 else if (IS_GM45(dev_priv))
4522 return gm45_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004523 else
4524 return g4x_digital_port_connected(dev_priv, port);
4525}
4526
Keith Packard8c241fe2011-09-28 16:38:44 -07004527static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004528intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004529{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004530 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004531
Jani Nikula9cd300e2012-10-19 14:51:52 +03004532 /* use cached edid if we have one */
4533 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004534 /* invalid edid */
4535 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004536 return NULL;
4537
Jani Nikula55e9ede2013-10-01 10:38:54 +03004538 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004539 } else
4540 return drm_get_edid(&intel_connector->base,
4541 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004542}
4543
Chris Wilsonbeb60602014-09-02 20:04:00 +01004544static void
4545intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004546{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004547 struct intel_connector *intel_connector = intel_dp->attached_connector;
4548 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004549
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304550 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004551 edid = intel_dp_get_edid(intel_dp);
4552 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004553
Chris Wilsonbeb60602014-09-02 20:04:00 +01004554 if (intel_dp->force_audio != HDMI_AUDIO_AUTO)
4555 intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON;
4556 else
4557 intel_dp->has_audio = drm_detect_monitor_audio(edid);
4558}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004559
Chris Wilsonbeb60602014-09-02 20:04:00 +01004560static void
4561intel_dp_unset_edid(struct intel_dp *intel_dp)
4562{
4563 struct intel_connector *intel_connector = intel_dp->attached_connector;
4564
4565 kfree(intel_connector->detect_edid);
4566 intel_connector->detect_edid = NULL;
4567
4568 intel_dp->has_audio = false;
4569}
4570
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004571static enum drm_connector_status
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304572intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004573{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304574 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004575 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004576 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4577 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004578 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004579 enum drm_connector_status status;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004580 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004581
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004582 intel_display_power_get(to_i915(dev), intel_dp->aux_power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004583
Chris Wilsond410b562014-09-02 20:03:59 +01004584 /* Can't disconnect eDP, but you can close the lid... */
4585 if (is_edp(intel_dp))
4586 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004587 else if (intel_digital_port_connected(to_i915(dev),
4588 dp_to_dig_port(intel_dp)))
4589 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004590 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004591 status = connector_status_disconnected;
4592
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004593 if (status == connector_status_disconnected) {
Manasi Navarec1617ab2016-12-09 16:22:50 -08004594 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304595
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004596 if (intel_dp->is_mst) {
4597 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4598 intel_dp->is_mst,
4599 intel_dp->mst_mgr.mst_state);
4600 intel_dp->is_mst = false;
4601 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4602 intel_dp->is_mst);
4603 }
4604
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004605 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304606 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004607
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304608 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004609 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304610
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004611 DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
4612 yesno(intel_dp_source_supports_hbr2(intel_dp)),
4613 yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
4614
Manasi Navared7e8ef02017-02-07 16:54:11 -08004615 if (intel_dp->reset_link_params) {
4616 /* Set the max lane count for sink */
4617 intel_dp->max_sink_lane_count = drm_dp_max_lane_count(intel_dp->dpcd);
Manasi Navaref4829842016-12-05 16:27:36 -08004618
Manasi Navared7e8ef02017-02-07 16:54:11 -08004619 /* Set the max link BW for sink */
4620 intel_dp->max_sink_link_bw = intel_dp_max_link_bw(intel_dp);
4621
4622 intel_dp->reset_link_params = false;
4623 }
Manasi Navaref4829842016-12-05 16:27:36 -08004624
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004625 intel_dp_print_rates(intel_dp);
4626
Imre Deak7b3fc172016-10-25 16:12:39 +03004627 intel_dp_read_desc(intel_dp);
Mika Kahola0e390a32016-09-09 14:10:53 +03004628
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004629 intel_dp_configure_mst(intel_dp);
4630
4631 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304632 /*
4633 * If we are in MST mode then this connector
4634 * won't appear connected or have anything
4635 * with EDID on it
4636 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004637 status = connector_status_disconnected;
4638 goto out;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304639 } else if (connector->status == connector_status_connected) {
4640 /*
4641 * If display was connected already and is still connected
4642 * check links status, there has been known issues of
4643 * link loss triggerring long pulse!!!!
4644 */
4645 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4646 intel_dp_check_link_status(intel_dp);
4647 drm_modeset_unlock(&dev->mode_config.connection_mutex);
4648 goto out;
Dave Airlie0e32b392014-05-02 14:02:48 +10004649 }
4650
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304651 /*
4652 * Clearing NACK and defer counts to get their exact values
4653 * while reading EDID which are required by Compliance tests
4654 * 4.2.2.4 and 4.2.2.5
4655 */
4656 intel_dp->aux.i2c_nack_count = 0;
4657 intel_dp->aux.i2c_defer_count = 0;
4658
Chris Wilsonbeb60602014-09-02 20:04:00 +01004659 intel_dp_set_edid(intel_dp);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004660 if (is_edp(intel_dp) || intel_connector->detect_edid)
4661 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304662 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004663
Todd Previte09b1eb12015-04-20 15:27:34 -07004664 /* Try to read the source of the interrupt */
4665 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004666 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4667 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004668 /* Clear interrupt source */
4669 drm_dp_dpcd_writeb(&intel_dp->aux,
4670 DP_DEVICE_SERVICE_IRQ_VECTOR,
4671 sink_irq_vector);
4672
4673 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4674 intel_dp_handle_test_request(intel_dp);
4675 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4676 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4677 }
4678
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004679out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004680 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304681 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304682
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004683 intel_display_power_put(to_i915(dev), intel_dp->aux_power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004684 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304685}
4686
4687static enum drm_connector_status
4688intel_dp_detect(struct drm_connector *connector, bool force)
4689{
4690 struct intel_dp *intel_dp = intel_attached_dp(connector);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004691 enum drm_connector_status status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304692
4693 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4694 connector->base.id, connector->name);
4695
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304696 /* If full detect is not performed yet, do a full detect */
4697 if (!intel_dp->detect_done)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004698 status = intel_dp_long_pulse(intel_dp->attached_connector);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304699
4700 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304701
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004702 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004703}
4704
Chris Wilsonbeb60602014-09-02 20:04:00 +01004705static void
4706intel_dp_force(struct drm_connector *connector)
4707{
4708 struct intel_dp *intel_dp = intel_attached_dp(connector);
4709 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004710 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004711
4712 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4713 connector->base.id, connector->name);
4714 intel_dp_unset_edid(intel_dp);
4715
4716 if (connector->status != connector_status_connected)
4717 return;
4718
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004719 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004720
4721 intel_dp_set_edid(intel_dp);
4722
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004723 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004724
4725 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004726 intel_encoder->type = INTEL_OUTPUT_DP;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004727}
4728
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004729static int intel_dp_get_modes(struct drm_connector *connector)
4730{
Jani Nikuladd06f902012-10-19 14:51:50 +03004731 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004732 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004733
Chris Wilsonbeb60602014-09-02 20:04:00 +01004734 edid = intel_connector->detect_edid;
4735 if (edid) {
4736 int ret = intel_connector_update_modes(connector, edid);
4737 if (ret)
4738 return ret;
4739 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004740
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004741 /* if eDP has no EDID, fall back to fixed mode */
Chris Wilsonbeb60602014-09-02 20:04:00 +01004742 if (is_edp(intel_attached_dp(connector)) &&
4743 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004744 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004745
4746 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004747 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004748 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004749 drm_mode_probed_add(connector, mode);
4750 return 1;
4751 }
4752 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004753
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004754 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004755}
4756
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004757static bool
4758intel_dp_detect_audio(struct drm_connector *connector)
4759{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004760 bool has_audio = false;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004761 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004762
Chris Wilsonbeb60602014-09-02 20:04:00 +01004763 edid = to_intel_connector(connector)->detect_edid;
4764 if (edid)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004765 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02004766
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004767 return has_audio;
4768}
4769
Chris Wilsonf6849602010-09-19 09:29:33 +01004770static int
4771intel_dp_set_property(struct drm_connector *connector,
4772 struct drm_property *property,
4773 uint64_t val)
4774{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004775 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Yuly Novikov53b41832012-10-26 12:04:00 +03004776 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004777 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
4778 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01004779 int ret;
4780
Rob Clark662595d2012-10-11 20:36:04 -05004781 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01004782 if (ret)
4783 return ret;
4784
Chris Wilson3f43c482011-05-12 22:17:24 +01004785 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004786 int i = val;
4787 bool has_audio;
4788
4789 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004790 return 0;
4791
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004792 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01004793
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004794 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004795 has_audio = intel_dp_detect_audio(connector);
4796 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004797 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004798
4799 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004800 return 0;
4801
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004802 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01004803 goto done;
4804 }
4805
Chris Wilsone953fd72011-02-21 22:23:52 +00004806 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02004807 bool old_auto = intel_dp->color_range_auto;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004808 bool old_range = intel_dp->limited_color_range;
Daniel Vetterae4edb82013-04-22 17:07:23 +02004809
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004810 switch (val) {
4811 case INTEL_BROADCAST_RGB_AUTO:
4812 intel_dp->color_range_auto = true;
4813 break;
4814 case INTEL_BROADCAST_RGB_FULL:
4815 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004816 intel_dp->limited_color_range = false;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004817 break;
4818 case INTEL_BROADCAST_RGB_LIMITED:
4819 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004820 intel_dp->limited_color_range = true;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004821 break;
4822 default:
4823 return -EINVAL;
4824 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02004825
4826 if (old_auto == intel_dp->color_range_auto &&
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004827 old_range == intel_dp->limited_color_range)
Daniel Vetterae4edb82013-04-22 17:07:23 +02004828 return 0;
4829
Chris Wilsone953fd72011-02-21 22:23:52 +00004830 goto done;
4831 }
4832
Yuly Novikov53b41832012-10-26 12:04:00 +03004833 if (is_edp(intel_dp) &&
4834 property == connector->dev->mode_config.scaling_mode_property) {
4835 if (val == DRM_MODE_SCALE_NONE) {
4836 DRM_DEBUG_KMS("no scaling not supported\n");
4837 return -EINVAL;
4838 }
Ville Syrjälä234126c2016-04-12 22:14:38 +03004839 if (HAS_GMCH_DISPLAY(dev_priv) &&
4840 val == DRM_MODE_SCALE_CENTER) {
4841 DRM_DEBUG_KMS("centering not supported\n");
4842 return -EINVAL;
4843 }
Yuly Novikov53b41832012-10-26 12:04:00 +03004844
4845 if (intel_connector->panel.fitting_mode == val) {
4846 /* the eDP scaling property is not changed */
4847 return 0;
4848 }
4849 intel_connector->panel.fitting_mode = val;
4850
4851 goto done;
4852 }
4853
Chris Wilsonf6849602010-09-19 09:29:33 +01004854 return -EINVAL;
4855
4856done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00004857 if (intel_encoder->base.crtc)
4858 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01004859
4860 return 0;
4861}
4862
Chris Wilson7a418e32016-06-24 14:00:14 +01004863static int
4864intel_dp_connector_register(struct drm_connector *connector)
4865{
4866 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004867 int ret;
4868
4869 ret = intel_connector_register(connector);
4870 if (ret)
4871 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004872
4873 i915_debugfs_connector_add(connector);
4874
4875 DRM_DEBUG_KMS("registering %s bus for %s\n",
4876 intel_dp->aux.name, connector->kdev->kobj.name);
4877
4878 intel_dp->aux.dev = connector->kdev;
4879 return drm_dp_aux_register(&intel_dp->aux);
4880}
4881
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004882static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004883intel_dp_connector_unregister(struct drm_connector *connector)
4884{
4885 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4886 intel_connector_unregister(connector);
4887}
4888
4889static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004890intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004891{
Jani Nikula1d508702012-10-19 14:51:49 +03004892 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004893
Chris Wilson10e972d2014-09-04 21:43:45 +01004894 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004895
Jani Nikula9cd300e2012-10-19 14:51:52 +03004896 if (!IS_ERR_OR_NULL(intel_connector->edid))
4897 kfree(intel_connector->edid);
4898
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004899 /* Can't call is_edp() since the encoder may have been destroyed
4900 * already. */
4901 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004902 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004903
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004904 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004905 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004906}
4907
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004908void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004909{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004910 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4911 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004912
Dave Airlie0e32b392014-05-02 14:02:48 +10004913 intel_dp_mst_encoder_cleanup(intel_dig_port);
Keith Packardbd943152011-09-18 23:09:52 -07004914 if (is_edp(intel_dp)) {
4915 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004916 /*
4917 * vdd might still be enabled do to the delayed vdd off.
4918 * Make sure vdd is actually turned off here.
4919 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004920 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004921 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004922 pps_unlock(intel_dp);
4923
Clint Taylor01527b32014-07-07 13:01:46 -07004924 if (intel_dp->edp_notifier.notifier_call) {
4925 unregister_reboot_notifier(&intel_dp->edp_notifier);
4926 intel_dp->edp_notifier.notifier_call = NULL;
4927 }
Keith Packardbd943152011-09-18 23:09:52 -07004928 }
Chris Wilson99681882016-06-20 09:29:17 +01004929
4930 intel_dp_aux_fini(intel_dp);
4931
Imre Deakc8bd0e42014-12-12 17:57:38 +02004932 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004933 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004934}
4935
Imre Deakbf93ba62016-04-18 10:04:21 +03004936void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004937{
4938 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4939
4940 if (!is_edp(intel_dp))
4941 return;
4942
Ville Syrjälä951468f2014-09-04 14:55:31 +03004943 /*
4944 * vdd might still be enabled do to the delayed vdd off.
4945 * Make sure vdd is actually turned off here.
4946 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004947 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004948 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004949 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004950 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004951}
4952
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004953static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4954{
4955 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4956 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004957 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004958
4959 lockdep_assert_held(&dev_priv->pps_mutex);
4960
4961 if (!edp_have_panel_vdd(intel_dp))
4962 return;
4963
4964 /*
4965 * The VDD bit needs a power domain reference, so if the bit is
4966 * already enabled when we boot or resume, grab this reference and
4967 * schedule a vdd off, so we don't hold on to the reference
4968 * indefinitely.
4969 */
4970 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004971 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004972
4973 edp_panel_vdd_schedule_off(intel_dp);
4974}
4975
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02004976static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
4977{
4978 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
4979
4980 if ((intel_dp->DP & DP_PORT_EN) == 0)
4981 return INVALID_PIPE;
4982
4983 if (IS_CHERRYVIEW(dev_priv))
4984 return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
4985 else
4986 return PORT_TO_PIPE(intel_dp->DP);
4987}
4988
Imre Deakbf93ba62016-04-18 10:04:21 +03004989void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03004990{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03004991 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Imre Deakdd75f6d2016-11-21 21:15:05 +02004992 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
4993 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Ville Syrjälä64989ca42016-05-13 20:53:56 +03004994
4995 if (!HAS_DDI(dev_priv))
4996 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004997
Imre Deakdd75f6d2016-11-21 21:15:05 +02004998 if (lspcon->active)
Shashank Sharma910530c2016-10-14 19:56:52 +05304999 lspcon_resume(lspcon);
5000
Manasi Navared7e8ef02017-02-07 16:54:11 -08005001 intel_dp->reset_link_params = true;
5002
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005003 pps_lock(intel_dp);
5004
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005005 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5006 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5007
5008 if (is_edp(intel_dp)) {
5009 /* Reinit the power sequencer, in case BIOS did something with it. */
5010 intel_dp_pps_init(encoder->dev, intel_dp);
5011 intel_edp_panel_vdd_sanitize(intel_dp);
5012 }
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005013
5014 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03005015}
5016
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005017static const struct drm_connector_funcs intel_dp_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02005018 .dpms = drm_atomic_helper_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005019 .detect = intel_dp_detect,
Chris Wilsonbeb60602014-09-02 20:04:00 +01005020 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005021 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01005022 .set_property = intel_dp_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -08005023 .atomic_get_property = intel_connector_atomic_get_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01005024 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01005025 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03005026 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08005027 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02005028 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005029};
5030
5031static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
5032 .get_modes = intel_dp_get_modes,
5033 .mode_valid = intel_dp_mode_valid,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005034};
5035
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005036static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03005037 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02005038 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005039};
5040
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005041enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10005042intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
5043{
5044 struct intel_dp *intel_dp = &intel_dig_port->dp;
Dave Airlie0e32b392014-05-02 14:02:48 +10005045 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005046 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005047 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03005048
Takashi Iwai25400582015-11-19 12:09:56 +01005049 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
5050 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Ville Syrjäläcca05022016-06-22 21:57:06 +03005051 intel_dig_port->base.type = INTEL_OUTPUT_DP;
Dave Airlie13cf5502014-06-18 11:29:35 +10005052
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005053 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
5054 /*
5055 * vdd off can generate a long pulse on eDP which
5056 * would require vdd on to handle it, and thus we
5057 * would end up in an endless cycle of
5058 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
5059 */
5060 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
5061 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d522015-02-10 14:11:46 +02005062 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005063 }
5064
Ville Syrjälä26fbb772014-08-11 18:37:37 +03005065 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
5066 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10005067 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10005068
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005069 if (long_hpd) {
Manasi Navared7e8ef02017-02-07 16:54:11 -08005070 intel_dp->reset_link_params = true;
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005071 intel_dp->detect_done = false;
5072 return IRQ_NONE;
5073 }
5074
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005075 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005076
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005077 if (intel_dp->is_mst) {
5078 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
5079 /*
5080 * If we were in MST mode, and device is not
5081 * there, get out of MST mode
5082 */
5083 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
5084 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
5085 intel_dp->is_mst = false;
5086 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
5087 intel_dp->is_mst);
5088 intel_dp->detect_done = false;
5089 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10005090 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005091 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005092
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005093 if (!intel_dp->is_mst) {
5094 if (!intel_dp_short_pulse(intel_dp)) {
5095 intel_dp->detect_done = false;
5096 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05305097 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005098 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005099
5100 ret = IRQ_HANDLED;
5101
Imre Deak1c767b32014-08-18 14:42:42 +03005102put_power:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005103 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005104
5105 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10005106}
5107
Rodrigo Vivi477ec322015-08-06 15:51:39 +08005108/* check the VBT to see whether the eDP is on another port */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005109bool intel_dp_is_edp(struct drm_i915_private *dev_priv, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08005110{
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005111 /*
5112 * eDP not supported on g4x. so bail out early just
5113 * for a bit extra safety in case the VBT is bonkers.
5114 */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005115 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005116 return false;
5117
Imre Deaka98d9c12016-12-21 12:17:24 +02005118 if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005119 return true;
5120
Jani Nikula951d9ef2016-03-16 12:43:31 +02005121 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08005122}
5123
Dave Airlie0e32b392014-05-02 14:02:48 +10005124void
Chris Wilsonf6849602010-09-19 09:29:33 +01005125intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
5126{
Yuly Novikov53b41832012-10-26 12:04:00 +03005127 struct intel_connector *intel_connector = to_intel_connector(connector);
5128
Chris Wilson3f43c482011-05-12 22:17:24 +01005129 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00005130 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02005131 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03005132
5133 if (is_edp(intel_dp)) {
5134 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05005135 drm_object_attach_property(
5136 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03005137 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03005138 DRM_MODE_SCALE_ASPECT);
5139 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03005140 }
Chris Wilsonf6849602010-09-19 09:29:33 +01005141}
5142
Imre Deakdada1a92014-01-29 13:25:41 +02005143static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
5144{
Abhay Kumard28d4732016-01-22 17:39:04 -08005145 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02005146 intel_dp->last_power_on = jiffies;
5147 intel_dp->last_backlight_off = jiffies;
5148}
5149
Daniel Vetter67a54562012-10-20 20:57:45 +02005150static void
Imre Deak54648612016-06-16 16:37:22 +03005151intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
5152 struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02005153{
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305154 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03005155 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07005156
Imre Deak8e8232d2016-06-16 16:37:21 +03005157 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02005158
5159 /* Workaround: Need to write PP_CONTROL with the unlock key as
5160 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305161 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02005162
Imre Deak8e8232d2016-06-16 16:37:21 +03005163 pp_on = I915_READ(regs.pp_on);
5164 pp_off = I915_READ(regs.pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005165 if (!IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005166 I915_WRITE(regs.pp_ctrl, pp_ctl);
5167 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305168 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005169
5170 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03005171 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
5172 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005173
Imre Deak54648612016-06-16 16:37:22 +03005174 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
5175 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005176
Imre Deak54648612016-06-16 16:37:22 +03005177 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
5178 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005179
Imre Deak54648612016-06-16 16:37:22 +03005180 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
5181 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005182
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005183 if (IS_GEN9_LP(dev_priv)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305184 u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
5185 BXT_POWER_CYCLE_DELAY_SHIFT;
5186 if (tmp > 0)
Imre Deak54648612016-06-16 16:37:22 +03005187 seq->t11_t12 = (tmp - 1) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305188 else
Imre Deak54648612016-06-16 16:37:22 +03005189 seq->t11_t12 = 0;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305190 } else {
Imre Deak54648612016-06-16 16:37:22 +03005191 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02005192 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305193 }
Imre Deak54648612016-06-16 16:37:22 +03005194}
5195
5196static void
Imre Deakde9c1b62016-06-16 20:01:46 +03005197intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
5198{
5199 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5200 state_name,
5201 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
5202}
5203
5204static void
5205intel_pps_verify_state(struct drm_i915_private *dev_priv,
5206 struct intel_dp *intel_dp)
5207{
5208 struct edp_power_seq hw;
5209 struct edp_power_seq *sw = &intel_dp->pps_delays;
5210
5211 intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
5212
5213 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
5214 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
5215 DRM_ERROR("PPS state mismatch\n");
5216 intel_pps_dump_state("sw", sw);
5217 intel_pps_dump_state("hw", &hw);
5218 }
5219}
5220
5221static void
Imre Deak54648612016-06-16 16:37:22 +03005222intel_dp_init_panel_power_sequencer(struct drm_device *dev,
5223 struct intel_dp *intel_dp)
5224{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005225 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak54648612016-06-16 16:37:22 +03005226 struct edp_power_seq cur, vbt, spec,
5227 *final = &intel_dp->pps_delays;
5228
5229 lockdep_assert_held(&dev_priv->pps_mutex);
5230
5231 /* already initialized? */
5232 if (final->t11_t12 != 0)
5233 return;
5234
5235 intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005236
Imre Deakde9c1b62016-06-16 20:01:46 +03005237 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005238
Jani Nikula6aa23e62016-03-24 17:50:20 +02005239 vbt = dev_priv->vbt.edp.pps;
Daniel Vetter67a54562012-10-20 20:57:45 +02005240
5241 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5242 * our hw here, which are all in 100usec. */
5243 spec.t1_t3 = 210 * 10;
5244 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5245 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5246 spec.t10 = 500 * 10;
5247 /* This one is special and actually in units of 100ms, but zero
5248 * based in the hw (so we need to add 100 ms). But the sw vbt
5249 * table multiplies it with 1000 to make it in units of 100usec,
5250 * too. */
5251 spec.t11_t12 = (510 + 100) * 10;
5252
Imre Deakde9c1b62016-06-16 20:01:46 +03005253 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005254
5255 /* Use the max of the register settings and vbt. If both are
5256 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005257#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005258 spec.field : \
5259 max(cur.field, vbt.field))
5260 assign_final(t1_t3);
5261 assign_final(t8);
5262 assign_final(t9);
5263 assign_final(t10);
5264 assign_final(t11_t12);
5265#undef assign_final
5266
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005267#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005268 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5269 intel_dp->backlight_on_delay = get_delay(t8);
5270 intel_dp->backlight_off_delay = get_delay(t9);
5271 intel_dp->panel_power_down_delay = get_delay(t10);
5272 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5273#undef get_delay
5274
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005275 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5276 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5277 intel_dp->panel_power_cycle_delay);
5278
5279 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5280 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005281
5282 /*
5283 * We override the HW backlight delays to 1 because we do manual waits
5284 * on them. For T8, even BSpec recommends doing it. For T9, if we
5285 * don't do this, we'll end up waiting for the backlight off delay
5286 * twice: once when we do the manual sleep, and once when we disable
5287 * the panel and wait for the PP_STATUS bit to become zero.
5288 */
5289 final->t8 = 1;
5290 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005291}
5292
5293static void
5294intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005295 struct intel_dp *intel_dp,
5296 bool force_disable_vdd)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005297{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005298 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07005299 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005300 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005301 struct pps_registers regs;
Ville Syrjäläad933b52014-08-18 22:15:56 +03005302 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005303 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005304
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005305 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005306
Imre Deak8e8232d2016-06-16 16:37:21 +03005307 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005308
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005309 /*
5310 * On some VLV machines the BIOS can leave the VDD
5311 * enabled even on power seqeuencers which aren't
5312 * hooked up to any port. This would mess up the
5313 * power domain tracking the first time we pick
5314 * one of these power sequencers for use since
5315 * edp_panel_vdd_on() would notice that the VDD was
5316 * already on and therefore wouldn't grab the power
5317 * domain reference. Disable VDD first to avoid this.
5318 * This also avoids spuriously turning the VDD on as
5319 * soon as the new power seqeuencer gets initialized.
5320 */
5321 if (force_disable_vdd) {
5322 u32 pp = ironlake_get_pp_control(intel_dp);
5323
5324 WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
5325
5326 if (pp & EDP_FORCE_VDD)
5327 DRM_DEBUG_KMS("VDD already on, disabling first\n");
5328
5329 pp &= ~EDP_FORCE_VDD;
5330
5331 I915_WRITE(regs.pp_ctrl, pp);
5332 }
5333
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005334 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005335 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5336 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005337 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005338 /* Compute the divisor for the pp clock, simply match the Bspec
5339 * formula. */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005340 if (IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005341 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305342 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
5343 pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
5344 << BXT_POWER_CYCLE_DELAY_SHIFT);
5345 } else {
5346 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5347 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5348 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5349 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005350
5351 /* Haswell doesn't have any port selection bits for the panel
5352 * power sequencer any more. */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005353 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005354 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005355 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005356 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005357 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005358 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005359 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005360 }
5361
Jesse Barnes453c5422013-03-28 09:55:41 -07005362 pp_on |= port_sel;
5363
Imre Deak8e8232d2016-06-16 16:37:21 +03005364 I915_WRITE(regs.pp_on, pp_on);
5365 I915_WRITE(regs.pp_off, pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005366 if (IS_GEN9_LP(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005367 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305368 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005369 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005370
Daniel Vetter67a54562012-10-20 20:57:45 +02005371 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 +03005372 I915_READ(regs.pp_on),
5373 I915_READ(regs.pp_off),
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005374 IS_GEN9_LP(dev_priv) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005375 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5376 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005377}
5378
Imre Deak335f7522016-08-10 14:07:32 +03005379static void intel_dp_pps_init(struct drm_device *dev,
5380 struct intel_dp *intel_dp)
5381{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005382 struct drm_i915_private *dev_priv = to_i915(dev);
5383
5384 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Imre Deak335f7522016-08-10 14:07:32 +03005385 vlv_initial_power_sequencer_setup(intel_dp);
5386 } else {
5387 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005388 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak335f7522016-08-10 14:07:32 +03005389 }
5390}
5391
Vandana Kannanb33a2812015-02-13 15:33:03 +05305392/**
5393 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005394 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005395 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305396 * @refresh_rate: RR to be programmed
5397 *
5398 * This function gets called when refresh rate (RR) has to be changed from
5399 * one frequency to another. Switches can be between high and low RR
5400 * supported by the panel or to any other RR based on media playback (in
5401 * this case, RR value needs to be passed from user space).
5402 *
5403 * The caller of this function needs to take a lock on dev_priv->drrs.
5404 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005405static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
5406 struct intel_crtc_state *crtc_state,
5407 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305408{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305409 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305410 struct intel_digital_port *dig_port = NULL;
5411 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005412 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305413 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305414
5415 if (refresh_rate <= 0) {
5416 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5417 return;
5418 }
5419
Vandana Kannan96178ee2015-01-10 02:25:56 +05305420 if (intel_dp == NULL) {
5421 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305422 return;
5423 }
5424
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005425 /*
Rodrigo Vivie4d59f62014-11-20 02:22:08 -08005426 * FIXME: This needs proper synchronization with psr state for some
5427 * platforms that cannot have PSR and DRRS enabled at the same time.
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005428 */
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305429
Vandana Kannan96178ee2015-01-10 02:25:56 +05305430 dig_port = dp_to_dig_port(intel_dp);
5431 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02005432 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305433
5434 if (!intel_crtc) {
5435 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5436 return;
5437 }
5438
Vandana Kannan96178ee2015-01-10 02:25:56 +05305439 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305440 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5441 return;
5442 }
5443
Vandana Kannan96178ee2015-01-10 02:25:56 +05305444 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5445 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305446 index = DRRS_LOW_RR;
5447
Vandana Kannan96178ee2015-01-10 02:25:56 +05305448 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305449 DRM_DEBUG_KMS(
5450 "DRRS requested for previously set RR...ignoring\n");
5451 return;
5452 }
5453
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005454 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305455 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5456 return;
5457 }
5458
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005459 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305460 switch (index) {
5461 case DRRS_HIGH_RR:
5462 intel_dp_set_m_n(intel_crtc, M1_N1);
5463 break;
5464 case DRRS_LOW_RR:
5465 intel_dp_set_m_n(intel_crtc, M2_N2);
5466 break;
5467 case DRRS_MAX_RR:
5468 default:
5469 DRM_ERROR("Unsupported refreshrate type\n");
5470 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005471 } else if (INTEL_GEN(dev_priv) > 6) {
5472 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005473 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305474
Ville Syrjälä649636e2015-09-22 19:50:01 +03005475 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305476 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005477 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305478 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5479 else
5480 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305481 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005482 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305483 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5484 else
5485 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305486 }
5487 I915_WRITE(reg, val);
5488 }
5489
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305490 dev_priv->drrs.refresh_rate_type = index;
5491
5492 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5493}
5494
Vandana Kannanb33a2812015-02-13 15:33:03 +05305495/**
5496 * intel_edp_drrs_enable - init drrs struct if supported
5497 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005498 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305499 *
5500 * Initializes frontbuffer_bits and drrs.dp
5501 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005502void intel_edp_drrs_enable(struct intel_dp *intel_dp,
5503 struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305504{
5505 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005506 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305507
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005508 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305509 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5510 return;
5511 }
5512
5513 mutex_lock(&dev_priv->drrs.mutex);
5514 if (WARN_ON(dev_priv->drrs.dp)) {
5515 DRM_ERROR("DRRS already enabled\n");
5516 goto unlock;
5517 }
5518
5519 dev_priv->drrs.busy_frontbuffer_bits = 0;
5520
5521 dev_priv->drrs.dp = intel_dp;
5522
5523unlock:
5524 mutex_unlock(&dev_priv->drrs.mutex);
5525}
5526
Vandana Kannanb33a2812015-02-13 15:33:03 +05305527/**
5528 * intel_edp_drrs_disable - Disable DRRS
5529 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005530 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305531 *
5532 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005533void intel_edp_drrs_disable(struct intel_dp *intel_dp,
5534 struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305535{
5536 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005537 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305538
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005539 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305540 return;
5541
5542 mutex_lock(&dev_priv->drrs.mutex);
5543 if (!dev_priv->drrs.dp) {
5544 mutex_unlock(&dev_priv->drrs.mutex);
5545 return;
5546 }
5547
5548 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005549 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5550 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305551
5552 dev_priv->drrs.dp = NULL;
5553 mutex_unlock(&dev_priv->drrs.mutex);
5554
5555 cancel_delayed_work_sync(&dev_priv->drrs.work);
5556}
5557
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305558static void intel_edp_drrs_downclock_work(struct work_struct *work)
5559{
5560 struct drm_i915_private *dev_priv =
5561 container_of(work, typeof(*dev_priv), drrs.work.work);
5562 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305563
Vandana Kannan96178ee2015-01-10 02:25:56 +05305564 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305565
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305566 intel_dp = dev_priv->drrs.dp;
5567
5568 if (!intel_dp)
5569 goto unlock;
5570
5571 /*
5572 * The delayed work can race with an invalidate hence we need to
5573 * recheck.
5574 */
5575
5576 if (dev_priv->drrs.busy_frontbuffer_bits)
5577 goto unlock;
5578
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005579 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5580 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5581
5582 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5583 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5584 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305585
5586unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305587 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305588}
5589
Vandana Kannanb33a2812015-02-13 15:33:03 +05305590/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305591 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005592 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305593 * @frontbuffer_bits: frontbuffer plane tracking bits
5594 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305595 * This function gets called everytime rendering on the given planes start.
5596 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305597 *
5598 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5599 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005600void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5601 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305602{
Vandana Kannana93fad02015-01-10 02:25:59 +05305603 struct drm_crtc *crtc;
5604 enum pipe pipe;
5605
Daniel Vetter9da7d692015-04-09 16:44:15 +02005606 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305607 return;
5608
Daniel Vetter88f933a2015-04-09 16:44:16 +02005609 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305610
Vandana Kannana93fad02015-01-10 02:25:59 +05305611 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005612 if (!dev_priv->drrs.dp) {
5613 mutex_unlock(&dev_priv->drrs.mutex);
5614 return;
5615 }
5616
Vandana Kannana93fad02015-01-10 02:25:59 +05305617 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5618 pipe = to_intel_crtc(crtc)->pipe;
5619
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005620 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5621 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5622
Ramalingam C0ddfd202015-06-15 20:50:05 +05305623 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005624 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005625 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5626 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305627
Vandana Kannana93fad02015-01-10 02:25:59 +05305628 mutex_unlock(&dev_priv->drrs.mutex);
5629}
5630
Vandana Kannanb33a2812015-02-13 15:33:03 +05305631/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305632 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005633 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305634 * @frontbuffer_bits: frontbuffer plane tracking bits
5635 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305636 * This function gets called every time rendering on the given planes has
5637 * completed or flip on a crtc is completed. So DRRS should be upclocked
5638 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5639 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305640 *
5641 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5642 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005643void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5644 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305645{
Vandana Kannana93fad02015-01-10 02:25:59 +05305646 struct drm_crtc *crtc;
5647 enum pipe pipe;
5648
Daniel Vetter9da7d692015-04-09 16:44:15 +02005649 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305650 return;
5651
Daniel Vetter88f933a2015-04-09 16:44:16 +02005652 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305653
Vandana Kannana93fad02015-01-10 02:25:59 +05305654 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005655 if (!dev_priv->drrs.dp) {
5656 mutex_unlock(&dev_priv->drrs.mutex);
5657 return;
5658 }
5659
Vandana Kannana93fad02015-01-10 02:25:59 +05305660 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5661 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005662
5663 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305664 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5665
Ramalingam C0ddfd202015-06-15 20:50:05 +05305666 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005667 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005668 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5669 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305670
5671 /*
5672 * flush also means no more activity hence schedule downclock, if all
5673 * other fbs are quiescent too
5674 */
5675 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305676 schedule_delayed_work(&dev_priv->drrs.work,
5677 msecs_to_jiffies(1000));
5678 mutex_unlock(&dev_priv->drrs.mutex);
5679}
5680
Vandana Kannanb33a2812015-02-13 15:33:03 +05305681/**
5682 * DOC: Display Refresh Rate Switching (DRRS)
5683 *
5684 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5685 * which enables swtching between low and high refresh rates,
5686 * dynamically, based on the usage scenario. This feature is applicable
5687 * for internal panels.
5688 *
5689 * Indication that the panel supports DRRS is given by the panel EDID, which
5690 * would list multiple refresh rates for one resolution.
5691 *
5692 * DRRS is of 2 types - static and seamless.
5693 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5694 * (may appear as a blink on screen) and is used in dock-undock scenario.
5695 * Seamless DRRS involves changing RR without any visual effect to the user
5696 * and can be used during normal system usage. This is done by programming
5697 * certain registers.
5698 *
5699 * Support for static/seamless DRRS may be indicated in the VBT based on
5700 * inputs from the panel spec.
5701 *
5702 * DRRS saves power by switching to low RR based on usage scenarios.
5703 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005704 * The implementation is based on frontbuffer tracking implementation. When
5705 * there is a disturbance on the screen triggered by user activity or a periodic
5706 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5707 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5708 * made.
5709 *
5710 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5711 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305712 *
5713 * DRRS can be further extended to support other internal panels and also
5714 * the scenario of video playback wherein RR is set based on the rate
5715 * requested by userspace.
5716 */
5717
5718/**
5719 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5720 * @intel_connector: eDP connector
5721 * @fixed_mode: preferred mode of panel
5722 *
5723 * This function is called only once at driver load to initialize basic
5724 * DRRS stuff.
5725 *
5726 * Returns:
5727 * Downclock mode if panel supports it, else return NULL.
5728 * DRRS support is determined by the presence of downclock mode (apart
5729 * from VBT setting).
5730 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305731static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305732intel_dp_drrs_init(struct intel_connector *intel_connector,
5733 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305734{
5735 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305736 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005737 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305738 struct drm_display_mode *downclock_mode = NULL;
5739
Daniel Vetter9da7d692015-04-09 16:44:15 +02005740 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5741 mutex_init(&dev_priv->drrs.mutex);
5742
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005743 if (INTEL_GEN(dev_priv) <= 6) {
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305744 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5745 return NULL;
5746 }
5747
5748 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005749 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305750 return NULL;
5751 }
5752
5753 downclock_mode = intel_find_panel_downclock
Mika Kaholaa318b4c2016-12-13 10:02:48 +02005754 (dev_priv, fixed_mode, connector);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305755
5756 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305757 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305758 return NULL;
5759 }
5760
Vandana Kannan96178ee2015-01-10 02:25:56 +05305761 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305762
Vandana Kannan96178ee2015-01-10 02:25:56 +05305763 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005764 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305765 return downclock_mode;
5766}
5767
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005768static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005769 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005770{
5771 struct drm_connector *connector = &intel_connector->base;
5772 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005773 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5774 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005775 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005776 struct drm_display_mode *fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305777 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005778 bool has_dpcd;
5779 struct drm_display_mode *scan;
5780 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005781 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005782
5783 if (!is_edp(intel_dp))
5784 return true;
5785
Imre Deak97a824e12016-06-21 11:51:47 +03005786 /*
5787 * On IBX/CPT we may get here with LVDS already registered. Since the
5788 * driver uses the only internal power sequencer available for both
5789 * eDP and LVDS bail out early in this case to prevent interfering
5790 * with an already powered-on LVDS power sequencer.
5791 */
5792 if (intel_get_lvds_encoder(dev)) {
5793 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5794 DRM_INFO("LVDS was detected, not registering eDP\n");
5795
5796 return false;
5797 }
5798
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005799 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005800
5801 intel_dp_init_panel_power_timestamps(intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +03005802 intel_dp_pps_init(dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005803 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005804
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005805 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005806
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005807 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005808 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005809
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005810 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005811 /* if this fails, presume the device is a ghost */
5812 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005813 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005814 }
5815
Daniel Vetter060c8772014-03-21 23:22:35 +01005816 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005817 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005818 if (edid) {
5819 if (drm_add_edid_modes(connector, edid)) {
5820 drm_mode_connector_update_edid_property(connector,
5821 edid);
5822 drm_edid_to_eld(connector, edid);
5823 } else {
5824 kfree(edid);
5825 edid = ERR_PTR(-EINVAL);
5826 }
5827 } else {
5828 edid = ERR_PTR(-ENOENT);
5829 }
5830 intel_connector->edid = edid;
5831
5832 /* prefer fixed mode from EDID if available */
5833 list_for_each_entry(scan, &connector->probed_modes, head) {
5834 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5835 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305836 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305837 intel_connector, fixed_mode);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005838 break;
5839 }
5840 }
5841
5842 /* fallback to VBT if available for eDP */
5843 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5844 fixed_mode = drm_mode_duplicate(dev,
5845 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005846 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005847 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005848 connector->display_info.width_mm = fixed_mode->width_mm;
5849 connector->display_info.height_mm = fixed_mode->height_mm;
5850 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005851 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005852 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005853
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005854 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005855 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5856 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005857
5858 /*
5859 * Figure out the current pipe for the initial backlight setup.
5860 * If the current pipe isn't valid, try the PPS pipe, and if that
5861 * fails just assume pipe A.
5862 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005863 pipe = vlv_active_pipe(intel_dp);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005864
5865 if (pipe != PIPE_A && pipe != PIPE_B)
5866 pipe = intel_dp->pps_pipe;
5867
5868 if (pipe != PIPE_A && pipe != PIPE_B)
5869 pipe = PIPE_A;
5870
5871 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5872 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005873 }
5874
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305875 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005876 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005877 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005878
5879 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005880
5881out_vdd_off:
5882 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5883 /*
5884 * vdd might still be enabled do to the delayed vdd off.
5885 * Make sure vdd is actually turned off here.
5886 */
5887 pps_lock(intel_dp);
5888 edp_panel_vdd_off_sync(intel_dp);
5889 pps_unlock(intel_dp);
5890
5891 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005892}
5893
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005894/* Set up the hotplug pin and aux power domain. */
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005895static void
5896intel_dp_init_connector_port_info(struct intel_digital_port *intel_dig_port)
5897{
5898 struct intel_encoder *encoder = &intel_dig_port->base;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005899 struct intel_dp *intel_dp = &intel_dig_port->dp;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005900
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005901 switch (intel_dig_port->port) {
5902 case PORT_A:
5903 encoder->hpd_pin = HPD_PORT_A;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005904 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_A;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005905 break;
5906 case PORT_B:
5907 encoder->hpd_pin = HPD_PORT_B;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005908 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_B;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005909 break;
5910 case PORT_C:
5911 encoder->hpd_pin = HPD_PORT_C;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005912 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_C;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005913 break;
5914 case PORT_D:
5915 encoder->hpd_pin = HPD_PORT_D;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005916 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005917 break;
5918 case PORT_E:
5919 encoder->hpd_pin = HPD_PORT_E;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005920
5921 /* FIXME: Check VBT for actual wiring of PORT E */
5922 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005923 break;
5924 default:
5925 MISSING_CASE(intel_dig_port->port);
5926 }
5927}
5928
Paulo Zanoni16c25532013-06-12 17:27:25 -03005929bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005930intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5931 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005932{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005933 struct drm_connector *connector = &intel_connector->base;
5934 struct intel_dp *intel_dp = &intel_dig_port->dp;
5935 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5936 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005937 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02005938 enum port port = intel_dig_port->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01005939 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005940
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005941 if (WARN(intel_dig_port->max_lanes < 1,
5942 "Not enough lanes (%d) for DP on port %c\n",
5943 intel_dig_port->max_lanes, port_name(port)))
5944 return false;
5945
Manasi Navared7e8ef02017-02-07 16:54:11 -08005946 intel_dp->reset_link_params = true;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005947 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005948 intel_dp->active_pipe = INVALID_PIPE;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005949
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005950 /* intel_dp vfuncs */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005951 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub6b5e382014-01-20 16:00:59 +00005952 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005953 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005954 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005955 else if (HAS_PCH_SPLIT(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005956 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
5957 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005958 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005959
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005960 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00005961 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
5962 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005963 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00005964
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005965 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03005966 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
5967
Daniel Vetter07679352012-09-06 22:15:42 +02005968 /* Preserve the current hw state. */
5969 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03005970 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00005971
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005972 if (intel_dp_is_edp(dev_priv, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05305973 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005974 else
5975 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04005976
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005977 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5978 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5979
Imre Deakf7d24902013-05-08 13:14:05 +03005980 /*
5981 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
5982 * for DP the encoder type can be set by the caller to
5983 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
5984 */
5985 if (type == DRM_MODE_CONNECTOR_eDP)
5986 intel_encoder->type = INTEL_OUTPUT_EDP;
5987
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005988 /* eDP only on port B and/or C on vlv/chv */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005989 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08005990 is_edp(intel_dp) && port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005991 return false;
5992
Imre Deake7281ea2013-05-08 13:14:08 +03005993 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
5994 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
5995 port_name(port));
5996
Adam Jacksonb3295302010-07-16 14:46:28 -04005997 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005998 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
5999
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006000 connector->interlace_allowed = true;
6001 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08006002
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02006003 intel_dp_init_connector_port_info(intel_dig_port);
6004
Mika Kaholab6339582016-09-09 14:10:52 +03006005 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01006006
Daniel Vetter66a92782012-07-12 20:08:18 +02006007 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01006008 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08006009
Chris Wilsondf0e9242010-09-09 16:20:55 +01006010 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006011
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006012 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02006013 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
6014 else
6015 intel_connector->get_hw_state = intel_connector_get_hw_state;
6016
Dave Airlie0e32b392014-05-02 14:02:48 +10006017 /* init MST on ports that can support it */
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00006018 if (HAS_DP_MST(dev_priv) && !is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03006019 (port == PORT_B || port == PORT_C || port == PORT_D))
6020 intel_dp_mst_encoder_init(intel_dig_port,
6021 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10006022
Ville Syrjälä36b5f422014-10-16 21:27:30 +03006023 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006024 intel_dp_aux_fini(intel_dp);
6025 intel_dp_mst_encoder_cleanup(intel_dig_port);
6026 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03006027 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08006028
Chris Wilsonf6849602010-09-19 09:29:33 +01006029 intel_dp_add_properties(intel_dp, connector);
6030
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006031 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
6032 * 0xd. Failure to do so will result in spurious interrupts being
6033 * generated on the port when a cable is not attached.
6034 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01006035 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006036 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
6037 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
6038 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03006039
6040 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006041
6042fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006043 drm_connector_cleanup(connector);
6044
6045 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006046}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006047
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006048bool intel_dp_init(struct drm_i915_private *dev_priv,
Chris Wilson457c52d2016-06-01 08:27:50 +01006049 i915_reg_t output_reg,
6050 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006051{
6052 struct intel_digital_port *intel_dig_port;
6053 struct intel_encoder *intel_encoder;
6054 struct drm_encoder *encoder;
6055 struct intel_connector *intel_connector;
6056
Daniel Vetterb14c5672013-09-19 12:18:32 +02006057 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006058 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01006059 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006060
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03006061 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306062 if (!intel_connector)
6063 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006064
6065 intel_encoder = &intel_dig_port->base;
6066 encoder = &intel_encoder->base;
6067
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006068 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
6069 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
6070 "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306071 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006072
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01006073 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006074 intel_encoder->disable = intel_disable_dp;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006075 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07006076 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03006077 intel_encoder->suspend = intel_dp_encoder_suspend;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006078 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03006079 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03006080 intel_encoder->pre_enable = chv_pre_enable_dp;
6081 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03006082 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03006083 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01006084 } else if (IS_VALLEYVIEW(dev_priv)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006085 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006086 intel_encoder->pre_enable = vlv_pre_enable_dp;
6087 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03006088 intel_encoder->post_disable = vlv_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006089 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006090 intel_encoder->pre_enable = g4x_pre_enable_dp;
6091 intel_encoder->enable = g4x_enable_dp;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006092 if (INTEL_GEN(dev_priv) >= 5)
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03006093 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006094 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006095
Paulo Zanoni174edf12012-10-26 19:05:50 -02006096 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006097 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02006098 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006099
Ville Syrjäläcca05022016-06-22 21:57:06 +03006100 intel_encoder->type = INTEL_OUTPUT_DP;
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02006101 intel_encoder->power_domain = intel_port_to_power_domain(port);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006102 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03006103 if (port == PORT_D)
6104 intel_encoder->crtc_mask = 1 << 2;
6105 else
6106 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
6107 } else {
6108 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
6109 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02006110 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07006111 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006112
Dave Airlie13cf5502014-06-18 11:29:35 +10006113 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03006114 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10006115
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306116 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
6117 goto err_init_connector;
6118
Chris Wilson457c52d2016-06-01 08:27:50 +01006119 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306120
6121err_init_connector:
6122 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306123err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306124 kfree(intel_connector);
6125err_connector_alloc:
6126 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01006127 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006128}
Dave Airlie0e32b392014-05-02 14:02:48 +10006129
6130void intel_dp_mst_suspend(struct drm_device *dev)
6131{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006132 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006133 int i;
6134
6135 /* disable MST */
6136 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006137 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006138
6139 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006140 continue;
6141
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006142 if (intel_dig_port->dp.is_mst)
6143 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10006144 }
6145}
6146
6147void intel_dp_mst_resume(struct drm_device *dev)
6148{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006149 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006150 int i;
6151
6152 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006153 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006154 int ret;
6155
6156 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006157 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10006158
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006159 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
6160 if (ret)
6161 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10006162 }
6163}