blob: 66b5bc80b78149f8773f5bf82db54b6fde9e4080 [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>
Clint Taylor01527b32014-07-07 13:01:46 -070031#include <linux/notifier.h>
32#include <linux/reboot.h>
David Howells760285e2012-10-02 18:01:07 +010033#include <drm/drmP.h>
Matt Roperc6f95f22015-01-22 16:50:32 -080034#include <drm/drm_atomic_helper.h>
David Howells760285e2012-10-02 18:01:07 +010035#include <drm/drm_crtc.h>
36#include <drm/drm_crtc_helper.h>
37#include <drm/drm_edid.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070038#include "intel_drv.h"
David Howells760285e2012-10-02 18:01:07 +010039#include <drm/i915_drm.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070040#include "i915_drv.h"
Keith Packarda4fc5ed2009-04-07 16:16:42 -070041
Keith Packarda4fc5ed2009-04-07 16:16:42 -070042#define DP_LINK_CHECK_TIMEOUT (10 * 1000)
43
Todd Previte559be302015-05-04 07:48:20 -070044/* Compliance test status bits */
45#define INTEL_DP_RESOLUTION_SHIFT_MASK 0
46#define INTEL_DP_RESOLUTION_PREFERRED (1 << INTEL_DP_RESOLUTION_SHIFT_MASK)
47#define INTEL_DP_RESOLUTION_STANDARD (2 << INTEL_DP_RESOLUTION_SHIFT_MASK)
48#define INTEL_DP_RESOLUTION_FAILSAFE (3 << INTEL_DP_RESOLUTION_SHIFT_MASK)
49
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080050struct dp_link_dpll {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030051 int clock;
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080052 struct dpll dpll;
53};
54
55static const struct dp_link_dpll gen4_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030056 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080057 { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030058 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080059 { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
60};
61
62static const struct dp_link_dpll pch_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030063 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080064 { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030065 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080066 { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
67};
68
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080069static const struct dp_link_dpll vlv_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030070 { 162000,
Chon Ming Lee58f6e632013-09-25 15:47:51 +080071 { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030072 { 270000,
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080073 { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } }
74};
75
Chon Ming Leeef9348c2014-04-09 13:28:18 +030076/*
77 * CHV supports eDP 1.4 that have more link rates.
78 * Below only provides the fixed rate but exclude variable rate.
79 */
80static const struct dp_link_dpll chv_dpll[] = {
81 /*
82 * CHV requires to program fractional division for m2.
83 * m2 is stored in fixed point format using formula below
84 * (m2_int << 22) | m2_fraction
85 */
Ville Syrjälä840b32b2015-08-11 20:21:46 +030086 { 162000, /* m2_int = 32, m2_fraction = 1677722 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030087 { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030088 { 270000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030089 { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030090 { 540000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030091 { .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }
92};
Sonika Jindal637a9c62015-05-07 09:52:08 +053093
Sonika Jindal64987fc2015-05-26 17:50:13 +053094static const int bxt_rates[] = { 162000, 216000, 243000, 270000,
95 324000, 432000, 540000 };
Sonika Jindal637a9c62015-05-07 09:52:08 +053096static const int skl_rates[] = { 162000, 216000, 270000,
Ville Syrjäläf4896f12015-03-12 17:10:27 +020097 324000, 432000, 540000 };
98static const int default_rates[] = { 162000, 270000, 540000 };
Chon Ming Leeef9348c2014-04-09 13:28:18 +030099
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700100/**
101 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
102 * @intel_dp: DP struct
103 *
104 * If a CPU or PCH DP output is attached to an eDP panel, this function
105 * will return true, and false otherwise.
106 */
107static bool is_edp(struct intel_dp *intel_dp)
108{
Paulo Zanonida63a9f2012-10-26 19:05:46 -0200109 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
110
111 return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700112}
113
Imre Deak68b4d822013-05-08 13:14:06 +0300114static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp)
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700115{
Imre Deak68b4d822013-05-08 13:14:06 +0300116 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
117
118 return intel_dig_port->base.base.dev;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700119}
120
Chris Wilsondf0e9242010-09-09 16:20:55 +0100121static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
122{
Paulo Zanonifa90ece2012-10-26 19:05:44 -0200123 return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
Chris Wilsondf0e9242010-09-09 16:20:55 +0100124}
125
Chris Wilsonea5b2132010-08-04 13:50:23 +0100126static void intel_dp_link_down(struct intel_dp *intel_dp);
Ville Syrjälä1e0560e2014-08-19 13:24:25 +0300127static bool edp_panel_vdd_on(struct intel_dp *intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +0100128static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
Ville Syrjälä093e3f12014-10-16 21:27:33 +0300129static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300130static void vlv_steal_power_sequencer(struct drm_device *dev,
131 enum pipe pipe);
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +0530132static void intel_dp_unset_edid(struct intel_dp *intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700133
Ville Syrjäläed4e9c12015-03-12 17:10:36 +0200134static int
135intel_dp_max_link_bw(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700136{
Jesse Barnes7183dc22011-07-07 11:10:58 -0700137 int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700138
139 switch (max_link_bw) {
140 case DP_LINK_BW_1_62:
141 case DP_LINK_BW_2_7:
Ville Syrjälä1db10e22015-03-12 17:10:32 +0200142 case DP_LINK_BW_5_4:
Imre Deakd4eead52013-07-09 17:05:26 +0300143 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700144 default:
Imre Deakd4eead52013-07-09 17:05:26 +0300145 WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
146 max_link_bw);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700147 max_link_bw = DP_LINK_BW_1_62;
148 break;
149 }
150 return max_link_bw;
151}
152
Paulo Zanonieeb63242014-05-06 14:56:50 +0300153static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
154{
155 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300156 u8 source_max, sink_max;
157
Ville Syrjäläccb1a832015-12-08 19:59:38 +0200158 source_max = intel_dig_port->max_lanes;
Manasi Navaref4829842016-12-05 16:27:36 -0800159 sink_max = intel_dp->max_sink_lane_count;
Paulo Zanonieeb63242014-05-06 14:56:50 +0300160
161 return min(source_max, sink_max);
162}
163
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800164int
Keith Packardc8982612012-01-25 08:16:25 -0800165intel_dp_link_required(int pixel_clock, int bpp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700166{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800167 /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
168 return DIV_ROUND_UP(pixel_clock * bpp, 8);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700169}
170
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800171int
Dave Airliefe27d532010-06-30 11:46:17 +1000172intel_dp_max_data_rate(int max_link_clock, int max_lanes)
173{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800174 /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
175 * link rate that is generally expressed in Gbps. Since, 8 bits of data
176 * is transmitted every LS_Clk per lane, there is no need to account for
177 * the channel encoding that is done in the PHY layer here.
178 */
179
180 return max_link_clock * max_lanes;
Dave Airliefe27d532010-06-30 11:46:17 +1000181}
182
Mika Kahola70ec0642016-09-09 14:10:55 +0300183static int
184intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp)
185{
186 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
187 struct intel_encoder *encoder = &intel_dig_port->base;
188 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
189 int max_dotclk = dev_priv->max_dotclk_freq;
190 int ds_max_dotclk;
191
192 int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
193
194 if (type != DP_DS_PORT_TYPE_VGA)
195 return max_dotclk;
196
197 ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd,
198 intel_dp->downstream_ports);
199
200 if (ds_max_dotclk != 0)
201 max_dotclk = min(max_dotclk, ds_max_dotclk);
202
203 return max_dotclk;
204}
205
Navare, Manasi D40dba342016-10-26 16:25:55 -0700206static int
207intel_dp_sink_rates(struct intel_dp *intel_dp, const int **sink_rates)
208{
209 if (intel_dp->num_sink_rates) {
210 *sink_rates = intel_dp->sink_rates;
211 return intel_dp->num_sink_rates;
212 }
213
214 *sink_rates = default_rates;
215
Manasi Navaref4829842016-12-05 16:27:36 -0800216 return (intel_dp->max_sink_link_bw >> 3) + 1;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700217}
218
219static int
220intel_dp_source_rates(struct intel_dp *intel_dp, const int **source_rates)
221{
222 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
223 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
224 int size;
225
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200226 if (IS_GEN9_LP(dev_priv)) {
Navare, Manasi D40dba342016-10-26 16:25:55 -0700227 *source_rates = bxt_rates;
228 size = ARRAY_SIZE(bxt_rates);
229 } else if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
230 *source_rates = skl_rates;
231 size = ARRAY_SIZE(skl_rates);
232 } else {
233 *source_rates = default_rates;
234 size = ARRAY_SIZE(default_rates);
235 }
236
237 /* This depends on the fact that 5.4 is last value in the array */
238 if (!intel_dp_source_supports_hbr2(intel_dp))
239 size--;
240
241 return size;
242}
243
244static int intersect_rates(const int *source_rates, int source_len,
245 const int *sink_rates, int sink_len,
246 int *common_rates)
247{
248 int i = 0, j = 0, k = 0;
249
250 while (i < source_len && j < sink_len) {
251 if (source_rates[i] == sink_rates[j]) {
252 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
253 return k;
254 common_rates[k] = source_rates[i];
255 ++k;
256 ++i;
257 ++j;
258 } else if (source_rates[i] < sink_rates[j]) {
259 ++i;
260 } else {
261 ++j;
262 }
263 }
264 return k;
265}
266
267static int intel_dp_common_rates(struct intel_dp *intel_dp,
268 int *common_rates)
269{
270 const int *source_rates, *sink_rates;
271 int source_len, sink_len;
272
273 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
274 source_len = intel_dp_source_rates(intel_dp, &source_rates);
275
276 return intersect_rates(source_rates, source_len,
277 sink_rates, sink_len,
278 common_rates);
279}
280
Manasi Navarefdb14d32016-12-08 19:05:12 -0800281static int intel_dp_link_rate_index(struct intel_dp *intel_dp,
282 int *common_rates, int link_rate)
283{
284 int common_len;
285 int index;
286
287 common_len = intel_dp_common_rates(intel_dp, common_rates);
288 for (index = 0; index < common_len; index++) {
289 if (link_rate == common_rates[common_len - index - 1])
290 return common_len - index - 1;
291 }
292
293 return -1;
294}
295
296int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
297 int link_rate, uint8_t lane_count)
298{
299 int common_rates[DP_MAX_SUPPORTED_RATES];
300 int link_rate_index;
301
302 link_rate_index = intel_dp_link_rate_index(intel_dp,
303 common_rates,
304 link_rate);
305 if (link_rate_index > 0) {
306 intel_dp->max_sink_link_bw = drm_dp_link_rate_to_bw_code(common_rates[link_rate_index - 1]);
307 intel_dp->max_sink_lane_count = lane_count;
308 } else if (lane_count > 1) {
309 intel_dp->max_sink_link_bw = intel_dp_max_link_bw(intel_dp);
310 intel_dp->max_sink_lane_count = lane_count >> 1;
311 } else {
312 DRM_ERROR("Link Training Unsuccessful\n");
313 return -1;
314 }
315
316 return 0;
317}
318
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000319static enum drm_mode_status
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700320intel_dp_mode_valid(struct drm_connector *connector,
321 struct drm_display_mode *mode)
322{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100323 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300324 struct intel_connector *intel_connector = to_intel_connector(connector);
325 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Daniel Vetter36008362013-03-27 00:44:59 +0100326 int target_clock = mode->clock;
327 int max_rate, mode_rate, max_lanes, max_link_clock;
Mika Kahola70ec0642016-09-09 14:10:55 +0300328 int max_dotclk;
329
330 max_dotclk = intel_dp_downstream_max_dotclock(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700331
Jani Nikuladd06f902012-10-19 14:51:50 +0300332 if (is_edp(intel_dp) && fixed_mode) {
333 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100334 return MODE_PANEL;
335
Jani Nikuladd06f902012-10-19 14:51:50 +0300336 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100337 return MODE_PANEL;
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200338
339 target_clock = fixed_mode->clock;
Zhao Yakui7de56f42010-07-19 09:43:14 +0100340 }
341
Ville Syrjälä50fec212015-03-12 17:10:34 +0200342 max_link_clock = intel_dp_max_link_rate(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300343 max_lanes = intel_dp_max_lane_count(intel_dp);
Daniel Vetter36008362013-03-27 00:44:59 +0100344
345 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
346 mode_rate = intel_dp_link_required(target_clock, 18);
347
Mika Kahola799487f2016-02-02 15:16:38 +0200348 if (mode_rate > max_rate || target_clock > max_dotclk)
Daniel Vetterc4867932012-04-10 10:42:36 +0200349 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700350
351 if (mode->clock < 10000)
352 return MODE_CLOCK_LOW;
353
Daniel Vetter0af78a22012-05-23 11:30:55 +0200354 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
355 return MODE_H_ILLEGAL;
356
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700357 return MODE_OK;
358}
359
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800360uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700361{
362 int i;
363 uint32_t v = 0;
364
365 if (src_bytes > 4)
366 src_bytes = 4;
367 for (i = 0; i < src_bytes; i++)
368 v |= ((uint32_t) src[i]) << ((3-i) * 8);
369 return v;
370}
371
Damien Lespiauc2af70e2015-02-10 19:32:23 +0000372static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700373{
374 int i;
375 if (dst_bytes > 4)
376 dst_bytes = 4;
377 for (i = 0; i < dst_bytes; i++)
378 dst[i] = src >> ((3-i) * 8);
379}
380
Jani Nikulabf13e812013-09-06 07:40:05 +0300381static void
382intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300383 struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300384static void
385intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300386 struct intel_dp *intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +0300387static void
388intel_dp_pps_init(struct drm_device *dev, struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300389
Ville Syrjälä773538e82014-09-04 14:54:56 +0300390static void pps_lock(struct intel_dp *intel_dp)
391{
392 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
393 struct intel_encoder *encoder = &intel_dig_port->base;
394 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100395 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300396 enum intel_display_power_domain power_domain;
397
398 /*
399 * See vlv_power_sequencer_reset() why we need
400 * a power domain reference here.
401 */
Ville Syrjälä25f78f52015-11-16 15:01:04 +0100402 power_domain = intel_display_port_aux_power_domain(encoder);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300403 intel_display_power_get(dev_priv, power_domain);
404
405 mutex_lock(&dev_priv->pps_mutex);
406}
407
408static void pps_unlock(struct intel_dp *intel_dp)
409{
410 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
411 struct intel_encoder *encoder = &intel_dig_port->base;
412 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100413 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300414 enum intel_display_power_domain power_domain;
415
416 mutex_unlock(&dev_priv->pps_mutex);
417
Ville Syrjälä25f78f52015-11-16 15:01:04 +0100418 power_domain = intel_display_port_aux_power_domain(encoder);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300419 intel_display_power_put(dev_priv, power_domain);
420}
421
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300422static void
423vlv_power_sequencer_kick(struct intel_dp *intel_dp)
424{
425 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200426 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300427 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300428 bool pll_enabled, release_cl_override = false;
429 enum dpio_phy phy = DPIO_PHY(pipe);
430 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300431 uint32_t DP;
432
433 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
434 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
435 pipe_name(pipe), port_name(intel_dig_port->port)))
436 return;
437
438 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
439 pipe_name(pipe), port_name(intel_dig_port->port));
440
441 /* Preserve the BIOS-computed detected bit. This is
442 * supposed to be read-only.
443 */
444 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
445 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
446 DP |= DP_PORT_WIDTH(1);
447 DP |= DP_LINK_TRAIN_PAT_1;
448
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100449 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300450 DP |= DP_PIPE_SELECT_CHV(pipe);
451 else if (pipe == PIPE_B)
452 DP |= DP_PIPEB_SELECT;
453
Ville Syrjäläd288f652014-10-28 13:20:22 +0200454 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
455
456 /*
457 * The DPLL for the pipe must be enabled for this to work.
458 * So enable temporarily it if it's not already enabled.
459 */
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300460 if (!pll_enabled) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100461 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300462 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
463
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200464 if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ?
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000465 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
466 DRM_ERROR("Failed to force on pll for pipe %c!\n",
467 pipe_name(pipe));
468 return;
469 }
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300470 }
Ville Syrjäläd288f652014-10-28 13:20:22 +0200471
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300472 /*
473 * Similar magic as in intel_dp_enable_port().
474 * We _must_ do this port enable + disable trick
475 * to make this power seqeuencer lock onto the port.
476 * Otherwise even VDD force bit won't work.
477 */
478 I915_WRITE(intel_dp->output_reg, DP);
479 POSTING_READ(intel_dp->output_reg);
480
481 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
482 POSTING_READ(intel_dp->output_reg);
483
484 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
485 POSTING_READ(intel_dp->output_reg);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200486
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300487 if (!pll_enabled) {
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200488 vlv_force_pll_off(dev_priv, pipe);
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300489
490 if (release_cl_override)
491 chv_phy_powergate_ch(dev_priv, phy, ch, false);
492 }
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300493}
494
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200495static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv)
496{
497 struct intel_encoder *encoder;
498 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
499
500 /*
501 * We don't have power sequencer currently.
502 * Pick one that's not used by other ports.
503 */
504 for_each_intel_encoder(&dev_priv->drm, encoder) {
505 struct intel_dp *intel_dp;
506
507 if (encoder->type != INTEL_OUTPUT_DP &&
508 encoder->type != INTEL_OUTPUT_EDP)
509 continue;
510
511 intel_dp = enc_to_intel_dp(&encoder->base);
512
513 if (encoder->type == INTEL_OUTPUT_EDP) {
514 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
515 intel_dp->active_pipe != intel_dp->pps_pipe);
516
517 if (intel_dp->pps_pipe != INVALID_PIPE)
518 pipes &= ~(1 << intel_dp->pps_pipe);
519 } else {
520 WARN_ON(intel_dp->pps_pipe != INVALID_PIPE);
521
522 if (intel_dp->active_pipe != INVALID_PIPE)
523 pipes &= ~(1 << intel_dp->active_pipe);
524 }
525 }
526
527 if (pipes == 0)
528 return INVALID_PIPE;
529
530 return ffs(pipes) - 1;
531}
532
Jani Nikulabf13e812013-09-06 07:40:05 +0300533static enum pipe
534vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
535{
536 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300537 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100538 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300539 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300540
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300541 lockdep_assert_held(&dev_priv->pps_mutex);
542
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300543 /* We should never land here with regular DP ports */
544 WARN_ON(!is_edp(intel_dp));
545
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200546 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
547 intel_dp->active_pipe != intel_dp->pps_pipe);
548
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300549 if (intel_dp->pps_pipe != INVALID_PIPE)
550 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300551
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200552 pipe = vlv_find_free_pps(dev_priv);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300553
554 /*
555 * Didn't find one. This should not happen since there
556 * are two power sequencers and up to two eDP ports.
557 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200558 if (WARN_ON(pipe == INVALID_PIPE))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300559 pipe = PIPE_A;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300560
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300561 vlv_steal_power_sequencer(dev, pipe);
562 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300563
564 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
565 pipe_name(intel_dp->pps_pipe),
566 port_name(intel_dig_port->port));
567
568 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300569 intel_dp_init_panel_power_sequencer(dev, intel_dp);
570 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300571
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300572 /*
573 * Even vdd force doesn't work until we've made
574 * the power sequencer lock in on the port.
575 */
576 vlv_power_sequencer_kick(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300577
578 return intel_dp->pps_pipe;
579}
580
Imre Deak78597992016-06-16 16:37:20 +0300581static int
582bxt_power_sequencer_idx(struct intel_dp *intel_dp)
583{
584 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
585 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100586 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak78597992016-06-16 16:37:20 +0300587
588 lockdep_assert_held(&dev_priv->pps_mutex);
589
590 /* We should never land here with regular DP ports */
591 WARN_ON(!is_edp(intel_dp));
592
593 /*
594 * TODO: BXT has 2 PPS instances. The correct port->PPS instance
595 * mapping needs to be retrieved from VBT, for now just hard-code to
596 * use instance #0 always.
597 */
598 if (!intel_dp->pps_reset)
599 return 0;
600
601 intel_dp->pps_reset = false;
602
603 /*
604 * Only the HW needs to be reprogrammed, the SW state is fixed and
605 * has been setup during connector init.
606 */
607 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
608
609 return 0;
610}
611
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300612typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
613 enum pipe pipe);
614
615static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
616 enum pipe pipe)
617{
Imre Deak44cb7342016-08-10 14:07:29 +0300618 return I915_READ(PP_STATUS(pipe)) & PP_ON;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300619}
620
621static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
622 enum pipe pipe)
623{
Imre Deak44cb7342016-08-10 14:07:29 +0300624 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300625}
626
627static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
628 enum pipe pipe)
629{
630 return true;
631}
632
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300633static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300634vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
635 enum port port,
636 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300637{
Jani Nikulabf13e812013-09-06 07:40:05 +0300638 enum pipe pipe;
639
Jani Nikulabf13e812013-09-06 07:40:05 +0300640 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
Imre Deak44cb7342016-08-10 14:07:29 +0300641 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
Jani Nikulabf13e812013-09-06 07:40:05 +0300642 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300643
644 if (port_sel != PANEL_PORT_SELECT_VLV(port))
645 continue;
646
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300647 if (!pipe_check(dev_priv, pipe))
648 continue;
649
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300650 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300651 }
652
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300653 return INVALID_PIPE;
654}
655
656static void
657vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
658{
659 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
660 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100661 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300662 enum port port = intel_dig_port->port;
663
664 lockdep_assert_held(&dev_priv->pps_mutex);
665
666 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300667 /* first pick one where the panel is on */
668 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
669 vlv_pipe_has_pp_on);
670 /* didn't find one? pick one where vdd is on */
671 if (intel_dp->pps_pipe == INVALID_PIPE)
672 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
673 vlv_pipe_has_vdd_on);
674 /* didn't find one? pick one with just the correct port */
675 if (intel_dp->pps_pipe == INVALID_PIPE)
676 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
677 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300678
679 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
680 if (intel_dp->pps_pipe == INVALID_PIPE) {
681 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
682 port_name(port));
683 return;
684 }
685
686 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
687 port_name(port), pipe_name(intel_dp->pps_pipe));
688
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300689 intel_dp_init_panel_power_sequencer(dev, intel_dp);
690 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300691}
692
Imre Deak78597992016-06-16 16:37:20 +0300693void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300694{
Chris Wilson91c8a322016-07-05 10:40:23 +0100695 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300696 struct intel_encoder *encoder;
697
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100698 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200699 !IS_GEN9_LP(dev_priv)))
Ville Syrjälä773538e82014-09-04 14:54:56 +0300700 return;
701
702 /*
703 * We can't grab pps_mutex here due to deadlock with power_domain
704 * mutex when power_domain functions are called while holding pps_mutex.
705 * That also means that in order to use pps_pipe the code needs to
706 * hold both a power domain reference and pps_mutex, and the power domain
707 * reference get/put must be done while _not_ holding pps_mutex.
708 * pps_{lock,unlock}() do these steps in the correct order, so one
709 * should use them always.
710 */
711
Jani Nikula19c80542015-12-16 12:48:16 +0200712 for_each_intel_encoder(dev, encoder) {
Ville Syrjälä773538e82014-09-04 14:54:56 +0300713 struct intel_dp *intel_dp;
714
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200715 if (encoder->type != INTEL_OUTPUT_DP &&
716 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300717 continue;
718
719 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200720
721 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
722
723 if (encoder->type != INTEL_OUTPUT_EDP)
724 continue;
725
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200726 if (IS_GEN9_LP(dev_priv))
Imre Deak78597992016-06-16 16:37:20 +0300727 intel_dp->pps_reset = true;
728 else
729 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300730 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300731}
732
Imre Deak8e8232d2016-06-16 16:37:21 +0300733struct pps_registers {
734 i915_reg_t pp_ctrl;
735 i915_reg_t pp_stat;
736 i915_reg_t pp_on;
737 i915_reg_t pp_off;
738 i915_reg_t pp_div;
739};
740
741static void intel_pps_get_registers(struct drm_i915_private *dev_priv,
742 struct intel_dp *intel_dp,
743 struct pps_registers *regs)
744{
Imre Deak44cb7342016-08-10 14:07:29 +0300745 int pps_idx = 0;
746
Imre Deak8e8232d2016-06-16 16:37:21 +0300747 memset(regs, 0, sizeof(*regs));
748
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200749 if (IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300750 pps_idx = bxt_power_sequencer_idx(intel_dp);
751 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
752 pps_idx = vlv_power_sequencer_pipe(intel_dp);
Imre Deak8e8232d2016-06-16 16:37:21 +0300753
Imre Deak44cb7342016-08-10 14:07:29 +0300754 regs->pp_ctrl = PP_CONTROL(pps_idx);
755 regs->pp_stat = PP_STATUS(pps_idx);
756 regs->pp_on = PP_ON_DELAYS(pps_idx);
757 regs->pp_off = PP_OFF_DELAYS(pps_idx);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200758 if (!IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300759 regs->pp_div = PP_DIVISOR(pps_idx);
Imre Deak8e8232d2016-06-16 16:37:21 +0300760}
761
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200762static i915_reg_t
763_pp_ctrl_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300764{
Imre Deak8e8232d2016-06-16 16:37:21 +0300765 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300766
Imre Deak8e8232d2016-06-16 16:37:21 +0300767 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
768 &regs);
769
770 return regs.pp_ctrl;
Jani Nikulabf13e812013-09-06 07:40:05 +0300771}
772
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200773static i915_reg_t
774_pp_stat_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300775{
Imre Deak8e8232d2016-06-16 16:37:21 +0300776 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300777
Imre Deak8e8232d2016-06-16 16:37:21 +0300778 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
779 &regs);
780
781 return regs.pp_stat;
Jani Nikulabf13e812013-09-06 07:40:05 +0300782}
783
Clint Taylor01527b32014-07-07 13:01:46 -0700784/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
785 This function only applicable when panel PM state is not to be tracked */
786static int edp_notify_handler(struct notifier_block *this, unsigned long code,
787 void *unused)
788{
789 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
790 edp_notifier);
791 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100792 struct drm_i915_private *dev_priv = to_i915(dev);
Clint Taylor01527b32014-07-07 13:01:46 -0700793
794 if (!is_edp(intel_dp) || code != SYS_RESTART)
795 return 0;
796
Ville Syrjälä773538e82014-09-04 14:54:56 +0300797 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300798
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100799 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300800 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200801 i915_reg_t pp_ctrl_reg, pp_div_reg;
Ville Syrjälä649636e2015-09-22 19:50:01 +0300802 u32 pp_div;
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300803
Imre Deak44cb7342016-08-10 14:07:29 +0300804 pp_ctrl_reg = PP_CONTROL(pipe);
805 pp_div_reg = PP_DIVISOR(pipe);
Clint Taylor01527b32014-07-07 13:01:46 -0700806 pp_div = I915_READ(pp_div_reg);
807 pp_div &= PP_REFERENCE_DIVIDER_MASK;
808
809 /* 0x1F write to PP_DIV_REG sets max cycle delay */
810 I915_WRITE(pp_div_reg, pp_div | 0x1F);
811 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
812 msleep(intel_dp->panel_power_cycle_delay);
813 }
814
Ville Syrjälä773538e82014-09-04 14:54:56 +0300815 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300816
Clint Taylor01527b32014-07-07 13:01:46 -0700817 return 0;
818}
819
Daniel Vetter4be73782014-01-17 14:39:48 +0100820static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700821{
Paulo Zanoni30add222012-10-26 19:05:45 -0200822 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100823 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700824
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300825 lockdep_assert_held(&dev_priv->pps_mutex);
826
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100827 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300828 intel_dp->pps_pipe == INVALID_PIPE)
829 return false;
830
Jani Nikulabf13e812013-09-06 07:40:05 +0300831 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700832}
833
Daniel Vetter4be73782014-01-17 14:39:48 +0100834static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700835{
Paulo Zanoni30add222012-10-26 19:05:45 -0200836 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100837 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700838
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300839 lockdep_assert_held(&dev_priv->pps_mutex);
840
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100841 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300842 intel_dp->pps_pipe == INVALID_PIPE)
843 return false;
844
Ville Syrjälä773538e82014-09-04 14:54:56 +0300845 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700846}
847
Keith Packard9b984da2011-09-19 13:54:47 -0700848static void
849intel_dp_check_edp(struct intel_dp *intel_dp)
850{
Paulo Zanoni30add222012-10-26 19:05:45 -0200851 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100852 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700853
Keith Packard9b984da2011-09-19 13:54:47 -0700854 if (!is_edp(intel_dp))
855 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700856
Daniel Vetter4be73782014-01-17 14:39:48 +0100857 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700858 WARN(1, "eDP powered off while attempting aux channel communication.\n");
859 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300860 I915_READ(_pp_stat_reg(intel_dp)),
861 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700862 }
863}
864
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100865static uint32_t
866intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
867{
868 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
869 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100870 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200871 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100872 uint32_t status;
873 bool done;
874
Daniel Vetteref04f002012-12-01 21:03:59 +0100875#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100876 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300877 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300878 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100879 else
Imre Deak713a6b662016-06-28 13:37:33 +0300880 done = wait_for(C, 10) == 0;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100881 if (!done)
882 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
883 has_aux_irq);
884#undef C
885
886 return status;
887}
888
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200889static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000890{
891 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200892 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000893
Ville Syrjäläa457f542016-03-02 17:22:17 +0200894 if (index)
895 return 0;
896
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000897 /*
898 * The clock divider is based off the hrawclk, and would like to run at
Ville Syrjäläa457f542016-03-02 17:22:17 +0200899 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000900 */
Ville Syrjäläa457f542016-03-02 17:22:17 +0200901 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000902}
903
904static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
905{
906 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200907 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000908
909 if (index)
910 return 0;
911
Ville Syrjäläa457f542016-03-02 17:22:17 +0200912 /*
913 * The clock divider is based off the cdclk or PCH rawclk, and would
914 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
915 * divide by 2000 and use that
916 */
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200917 if (intel_dig_port->port == PORT_A)
Ville Syrjäläfce18c42015-11-30 16:23:46 +0200918 return DIV_ROUND_CLOSEST(dev_priv->cdclk_freq, 2000);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200919 else
920 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000921}
922
923static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300924{
925 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200926 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300927
Ville Syrjäläa457f542016-03-02 17:22:17 +0200928 if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300929 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100930 switch (index) {
931 case 0: return 63;
932 case 1: return 72;
933 default: return 0;
934 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300935 }
Ville Syrjäläa457f542016-03-02 17:22:17 +0200936
937 return ilk_get_aux_clock_divider(intel_dp, index);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300938}
939
Damien Lespiaub6b5e382014-01-20 16:00:59 +0000940static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
941{
942 /*
943 * SKL doesn't need us to program the AUX clock divider (Hardware will
944 * derive the clock from CDCLK automatically). We still implement the
945 * get_aux_clock_divider vfunc to plug-in into the existing code.
946 */
947 return index ? 0 : 1;
948}
949
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200950static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
951 bool has_aux_irq,
952 int send_bytes,
953 uint32_t aux_clock_divider)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000954{
955 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100956 struct drm_i915_private *dev_priv =
957 to_i915(intel_dig_port->base.base.dev);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000958 uint32_t precharge, timeout;
959
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100960 if (IS_GEN6(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000961 precharge = 3;
962 else
963 precharge = 5;
964
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100965 if (IS_BROADWELL(dev_priv) && intel_dig_port->port == PORT_A)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000966 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
967 else
968 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
969
970 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +0000971 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000972 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000973 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000974 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +0000975 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000976 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
977 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000978 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000979}
980
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000981static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
982 bool has_aux_irq,
983 int send_bytes,
984 uint32_t unused)
985{
986 return DP_AUX_CH_CTL_SEND_BUSY |
987 DP_AUX_CH_CTL_DONE |
988 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
989 DP_AUX_CH_CTL_TIME_OUT_ERROR |
990 DP_AUX_CH_CTL_TIME_OUT_1600us |
991 DP_AUX_CH_CTL_RECEIVE_ERROR |
992 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Daniel Vetterd4dcbdc2016-05-18 18:47:15 +0200993 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000994 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
995}
996
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700997static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100998intel_dp_aux_ch(struct intel_dp *intel_dp,
Daniel Vetterbd9f74a2014-10-02 09:45:35 +0200999 const uint8_t *send, int send_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001000 uint8_t *recv, int recv_size)
1001{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001002 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001003 struct drm_i915_private *dev_priv =
1004 to_i915(intel_dig_port->base.base.dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001005 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Chris Wilsonbc866252013-07-21 16:00:03 +01001006 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001007 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001008 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001009 int try, clock = 0;
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001010 bool has_aux_irq = HAS_AUX_IRQ(dev_priv);
Jani Nikula884f19e2014-03-14 16:51:14 +02001011 bool vdd;
1012
Ville Syrjälä773538e82014-09-04 14:54:56 +03001013 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001014
Ville Syrjälä72c35002014-08-18 22:16:00 +03001015 /*
1016 * We will be called with VDD already enabled for dpcd/edid/oui reads.
1017 * In such cases we want to leave VDD enabled and it's up to upper layers
1018 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
1019 * ourselves.
1020 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001021 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001022
1023 /* dp aux is extremely sensitive to irq latency, hence request the
1024 * lowest possible wakeup latency and so prevent the cpu from going into
1025 * deep sleep states.
1026 */
1027 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001028
Keith Packard9b984da2011-09-19 13:54:47 -07001029 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001030
Jesse Barnes11bee432011-08-01 15:02:20 -07001031 /* Try to wait for any previous AUX channel activity */
1032 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +01001033 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -07001034 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
1035 break;
1036 msleep(1);
1037 }
1038
1039 if (try == 3) {
Mika Kuoppala02196c72015-08-06 16:48:58 +03001040 static u32 last_status = -1;
1041 const u32 status = I915_READ(ch_ctl);
1042
1043 if (status != last_status) {
1044 WARN(1, "dp_aux_ch not started status 0x%08x\n",
1045 status);
1046 last_status = status;
1047 }
1048
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001049 ret = -EBUSY;
1050 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001051 }
1052
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001053 /* Only 5 data registers! */
1054 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
1055 ret = -E2BIG;
1056 goto out;
1057 }
1058
Damien Lespiauec5b01d2014-01-21 13:35:39 +00001059 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +00001060 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
1061 has_aux_irq,
1062 send_bytes,
1063 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001064
Chris Wilsonbc866252013-07-21 16:00:03 +01001065 /* Must try at least 3 times according to DP spec */
1066 for (try = 0; try < 5; try++) {
1067 /* Load the send data into the aux channel data registers */
1068 for (i = 0; i < send_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001069 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001070 intel_dp_pack_aux(send + i,
1071 send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -04001072
Chris Wilsonbc866252013-07-21 16:00:03 +01001073 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001074 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001075
Chris Wilsonbc866252013-07-21 16:00:03 +01001076 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -04001077
Chris Wilsonbc866252013-07-21 16:00:03 +01001078 /* Clear done status and any errors */
1079 I915_WRITE(ch_ctl,
1080 status |
1081 DP_AUX_CH_CTL_DONE |
1082 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1083 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -04001084
Todd Previte74ebf292015-04-15 08:38:41 -07001085 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
Chris Wilsonbc866252013-07-21 16:00:03 +01001086 continue;
Todd Previte74ebf292015-04-15 08:38:41 -07001087
1088 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
1089 * 400us delay required for errors and timeouts
1090 * Timeout errors from the HW already meet this
1091 * requirement so skip to next iteration
1092 */
1093 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1094 usleep_range(400, 500);
1095 continue;
1096 }
Chris Wilsonbc866252013-07-21 16:00:03 +01001097 if (status & DP_AUX_CH_CTL_DONE)
Jim Bridee058c942015-05-27 10:21:48 -07001098 goto done;
Chris Wilsonbc866252013-07-21 16:00:03 +01001099 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001100 }
1101
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001102 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001103 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001104 ret = -EBUSY;
1105 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001106 }
1107
Jim Bridee058c942015-05-27 10:21:48 -07001108done:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001109 /* Check for timeout or receive error.
1110 * Timeouts occur when the sink is not connected
1111 */
Keith Packarda5b3da52009-06-11 22:30:32 -07001112 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001113 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001114 ret = -EIO;
1115 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -07001116 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001117
1118 /* Timeouts occur when the device isn't connected, so they're
1119 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -07001120 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Zhao Yakui28c97732009-10-09 11:39:41 +08001121 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001122 ret = -ETIMEDOUT;
1123 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001124 }
1125
1126 /* Unload any bytes sent back from the other side */
1127 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
1128 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Rodrigo Vivi14e01882015-12-10 11:12:27 -08001129
1130 /*
1131 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1132 * We have no idea of what happened so we return -EBUSY so
1133 * drm layer takes care for the necessary retries.
1134 */
1135 if (recv_bytes == 0 || recv_bytes > 20) {
1136 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1137 recv_bytes);
1138 /*
1139 * FIXME: This patch was created on top of a series that
1140 * organize the retries at drm level. There EBUSY should
1141 * also take care for 1ms wait before retrying.
1142 * That aux retries re-org is still needed and after that is
1143 * merged we remove this sleep from here.
1144 */
1145 usleep_range(1000, 1500);
1146 ret = -EBUSY;
1147 goto out;
1148 }
1149
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001150 if (recv_bytes > recv_size)
1151 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -04001152
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001153 for (i = 0; i < recv_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001154 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001155 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001156
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001157 ret = recv_bytes;
1158out:
1159 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1160
Jani Nikula884f19e2014-03-14 16:51:14 +02001161 if (vdd)
1162 edp_panel_vdd_off(intel_dp, false);
1163
Ville Syrjälä773538e82014-09-04 14:54:56 +03001164 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001165
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001166 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001167}
1168
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001169#define BARE_ADDRESS_SIZE 3
1170#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +02001171static ssize_t
1172intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001173{
Jani Nikula9d1a1032014-03-14 16:51:15 +02001174 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1175 uint8_t txbuf[20], rxbuf[20];
1176 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001177 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001178
Ville Syrjäläd2d9cbb2015-03-19 11:44:06 +02001179 txbuf[0] = (msg->request << 4) |
1180 ((msg->address >> 16) & 0xf);
1181 txbuf[1] = (msg->address >> 8) & 0xff;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001182 txbuf[2] = msg->address & 0xff;
1183 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001184
Jani Nikula9d1a1032014-03-14 16:51:15 +02001185 switch (msg->request & ~DP_AUX_I2C_MOT) {
1186 case DP_AUX_NATIVE_WRITE:
1187 case DP_AUX_I2C_WRITE:
Ville Syrjäläc1e741222015-08-27 17:23:27 +03001188 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001189 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001190 rxsize = 2; /* 0 or 1 data bytes */
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001191
Jani Nikula9d1a1032014-03-14 16:51:15 +02001192 if (WARN_ON(txsize > 20))
1193 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001194
Ville Syrjälädd788092016-07-28 17:55:04 +03001195 WARN_ON(!msg->buffer != !msg->size);
1196
Imre Deakd81a67c2016-01-29 14:52:26 +02001197 if (msg->buffer)
1198 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001199
Jani Nikula9d1a1032014-03-14 16:51:15 +02001200 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1201 if (ret > 0) {
1202 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001203
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001204 if (ret > 1) {
1205 /* Number of bytes written in a short write. */
1206 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1207 } else {
1208 /* Return payload size. */
1209 ret = msg->size;
1210 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001211 }
Jani Nikula9d1a1032014-03-14 16:51:15 +02001212 break;
1213
1214 case DP_AUX_NATIVE_READ:
1215 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001216 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001217 rxsize = msg->size + 1;
1218
1219 if (WARN_ON(rxsize > 20))
1220 return -E2BIG;
1221
1222 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1223 if (ret > 0) {
1224 msg->reply = rxbuf[0] >> 4;
1225 /*
1226 * Assume happy day, and copy the data. The caller is
1227 * expected to check msg->reply before touching it.
1228 *
1229 * Return payload size.
1230 */
1231 ret--;
1232 memcpy(msg->buffer, rxbuf + 1, ret);
1233 }
1234 break;
1235
1236 default:
1237 ret = -EINVAL;
1238 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001239 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001240
Jani Nikula9d1a1032014-03-14 16:51:15 +02001241 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001242}
1243
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001244static enum port intel_aux_port(struct drm_i915_private *dev_priv,
1245 enum port port)
1246{
1247 const struct ddi_vbt_port_info *info =
1248 &dev_priv->vbt.ddi_port_info[port];
1249 enum port aux_port;
1250
1251 if (!info->alternate_aux_channel) {
1252 DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
1253 port_name(port), port_name(port));
1254 return port;
1255 }
1256
1257 switch (info->alternate_aux_channel) {
1258 case DP_AUX_A:
1259 aux_port = PORT_A;
1260 break;
1261 case DP_AUX_B:
1262 aux_port = PORT_B;
1263 break;
1264 case DP_AUX_C:
1265 aux_port = PORT_C;
1266 break;
1267 case DP_AUX_D:
1268 aux_port = PORT_D;
1269 break;
1270 default:
1271 MISSING_CASE(info->alternate_aux_channel);
1272 aux_port = PORT_A;
1273 break;
1274 }
1275
1276 DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
1277 port_name(aux_port), port_name(port));
1278
1279 return aux_port;
1280}
1281
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001282static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001283 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001284{
1285 switch (port) {
1286 case PORT_B:
1287 case PORT_C:
1288 case PORT_D:
1289 return DP_AUX_CH_CTL(port);
1290 default:
1291 MISSING_CASE(port);
1292 return DP_AUX_CH_CTL(PORT_B);
1293 }
1294}
1295
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001296static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001297 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001298{
1299 switch (port) {
1300 case PORT_B:
1301 case PORT_C:
1302 case PORT_D:
1303 return DP_AUX_CH_DATA(port, index);
1304 default:
1305 MISSING_CASE(port);
1306 return DP_AUX_CH_DATA(PORT_B, index);
1307 }
1308}
1309
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001310static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001311 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001312{
1313 switch (port) {
1314 case PORT_A:
1315 return DP_AUX_CH_CTL(port);
1316 case PORT_B:
1317 case PORT_C:
1318 case PORT_D:
1319 return PCH_DP_AUX_CH_CTL(port);
1320 default:
1321 MISSING_CASE(port);
1322 return DP_AUX_CH_CTL(PORT_A);
1323 }
1324}
1325
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001326static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001327 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001328{
1329 switch (port) {
1330 case PORT_A:
1331 return DP_AUX_CH_DATA(port, index);
1332 case PORT_B:
1333 case PORT_C:
1334 case PORT_D:
1335 return PCH_DP_AUX_CH_DATA(port, index);
1336 default:
1337 MISSING_CASE(port);
1338 return DP_AUX_CH_DATA(PORT_A, index);
1339 }
1340}
1341
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001342static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001343 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001344{
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001345 switch (port) {
1346 case PORT_A:
1347 case PORT_B:
1348 case PORT_C:
1349 case PORT_D:
1350 return DP_AUX_CH_CTL(port);
1351 default:
1352 MISSING_CASE(port);
1353 return DP_AUX_CH_CTL(PORT_A);
1354 }
1355}
1356
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001357static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001358 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001359{
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001360 switch (port) {
1361 case PORT_A:
1362 case PORT_B:
1363 case PORT_C:
1364 case PORT_D:
1365 return DP_AUX_CH_DATA(port, index);
1366 default:
1367 MISSING_CASE(port);
1368 return DP_AUX_CH_DATA(PORT_A, index);
1369 }
1370}
1371
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001372static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001373 enum port port)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001374{
1375 if (INTEL_INFO(dev_priv)->gen >= 9)
1376 return skl_aux_ctl_reg(dev_priv, port);
1377 else if (HAS_PCH_SPLIT(dev_priv))
1378 return ilk_aux_ctl_reg(dev_priv, port);
1379 else
1380 return g4x_aux_ctl_reg(dev_priv, port);
1381}
1382
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001383static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001384 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001385{
1386 if (INTEL_INFO(dev_priv)->gen >= 9)
1387 return skl_aux_data_reg(dev_priv, port, index);
1388 else if (HAS_PCH_SPLIT(dev_priv))
1389 return ilk_aux_data_reg(dev_priv, port, index);
1390 else
1391 return g4x_aux_data_reg(dev_priv, port, index);
1392}
1393
1394static void intel_aux_reg_init(struct intel_dp *intel_dp)
1395{
1396 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001397 enum port port = intel_aux_port(dev_priv,
1398 dp_to_dig_port(intel_dp)->port);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001399 int i;
1400
1401 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1402 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1403 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1404}
1405
Jani Nikula9d1a1032014-03-14 16:51:15 +02001406static void
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001407intel_dp_aux_fini(struct intel_dp *intel_dp)
1408{
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001409 kfree(intel_dp->aux.name);
1410}
1411
Chris Wilson7a418e32016-06-24 14:00:14 +01001412static void
Mika Kaholab6339582016-09-09 14:10:52 +03001413intel_dp_aux_init(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001414{
Jani Nikula33ad6622014-03-14 16:51:16 +02001415 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1416 enum port port = intel_dig_port->port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001417
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001418 intel_aux_reg_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01001419 drm_dp_aux_init(&intel_dp->aux);
David Flynn8316f332010-12-08 16:10:21 +00001420
Chris Wilson7a418e32016-06-24 14:00:14 +01001421 /* Failure to allocate our preferred name is not critical */
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001422 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
Jani Nikula9d1a1032014-03-14 16:51:15 +02001423 intel_dp->aux.transfer = intel_dp_aux_transfer;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001424}
1425
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001426bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301427{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001428 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Navare, Manasi D577c5432016-09-27 16:36:53 -07001429 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001430
Navare, Manasi D577c5432016-09-27 16:36:53 -07001431 if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
1432 IS_BROADWELL(dev_priv) || (INTEL_GEN(dev_priv) >= 9))
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301433 return true;
1434 else
1435 return false;
1436}
1437
Daniel Vetter0e503382014-07-04 11:26:04 -03001438static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001439intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001440 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001441{
1442 struct drm_device *dev = encoder->base.dev;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001443 struct drm_i915_private *dev_priv = to_i915(dev);
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001444 const struct dp_link_dpll *divisor = NULL;
1445 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001446
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001447 if (IS_G4X(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001448 divisor = gen4_dpll;
1449 count = ARRAY_SIZE(gen4_dpll);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001450 } else if (HAS_PCH_SPLIT(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001451 divisor = pch_dpll;
1452 count = ARRAY_SIZE(pch_dpll);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001453 } else if (IS_CHERRYVIEW(dev_priv)) {
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001454 divisor = chv_dpll;
1455 count = ARRAY_SIZE(chv_dpll);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001456 } else if (IS_VALLEYVIEW(dev_priv)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001457 divisor = vlv_dpll;
1458 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001459 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001460
1461 if (divisor && count) {
1462 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001463 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001464 pipe_config->dpll = divisor[i].dpll;
1465 pipe_config->clock_set = true;
1466 break;
1467 }
1468 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001469 }
1470}
1471
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001472static void snprintf_int_array(char *str, size_t len,
1473 const int *array, int nelem)
1474{
1475 int i;
1476
1477 str[0] = '\0';
1478
1479 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001480 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001481 if (r >= len)
1482 return;
1483 str += r;
1484 len -= r;
1485 }
1486}
1487
1488static void intel_dp_print_rates(struct intel_dp *intel_dp)
1489{
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001490 const int *source_rates, *sink_rates;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001491 int source_len, sink_len, common_len;
1492 int common_rates[DP_MAX_SUPPORTED_RATES];
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001493 char str[128]; /* FIXME: too big for stack? */
1494
1495 if ((drm_debug & DRM_UT_KMS) == 0)
1496 return;
1497
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001498 source_len = intel_dp_source_rates(intel_dp, &source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001499 snprintf_int_array(str, sizeof(str), source_rates, source_len);
1500 DRM_DEBUG_KMS("source rates: %s\n", str);
1501
1502 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
1503 snprintf_int_array(str, sizeof(str), sink_rates, sink_len);
1504 DRM_DEBUG_KMS("sink rates: %s\n", str);
1505
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001506 common_len = intel_dp_common_rates(intel_dp, common_rates);
1507 snprintf_int_array(str, sizeof(str), common_rates, common_len);
1508 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001509}
1510
Imre Deak489375c2016-10-24 19:33:31 +03001511bool
Imre Deak7b3fc172016-10-25 16:12:39 +03001512__intel_dp_read_desc(struct intel_dp *intel_dp, struct intel_dp_desc *desc)
Mika Kahola0e390a32016-09-09 14:10:53 +03001513{
Imre Deak7b3fc172016-10-25 16:12:39 +03001514 u32 base = drm_dp_is_branch(intel_dp->dpcd) ? DP_BRANCH_OUI :
1515 DP_SINK_OUI;
Mika Kahola0e390a32016-09-09 14:10:53 +03001516
Imre Deak7b3fc172016-10-25 16:12:39 +03001517 return drm_dp_dpcd_read(&intel_dp->aux, base, desc, sizeof(*desc)) ==
1518 sizeof(*desc);
Mika Kahola0e390a32016-09-09 14:10:53 +03001519}
1520
Imre Deak12a47a422016-10-24 19:33:29 +03001521bool intel_dp_read_desc(struct intel_dp *intel_dp)
Mika Kahola1a2724f2016-09-09 14:10:54 +03001522{
Imre Deak7b3fc172016-10-25 16:12:39 +03001523 struct intel_dp_desc *desc = &intel_dp->desc;
1524 bool oui_sup = intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] &
1525 DP_OUI_SUPPORT;
1526 int dev_id_len;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001527
Imre Deak7b3fc172016-10-25 16:12:39 +03001528 if (!__intel_dp_read_desc(intel_dp, desc))
1529 return false;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001530
Imre Deak7b3fc172016-10-25 16:12:39 +03001531 dev_id_len = strnlen(desc->device_id, sizeof(desc->device_id));
1532 DRM_DEBUG_KMS("DP %s: OUI %*phD%s dev-ID %*pE HW-rev %d.%d SW-rev %d.%d\n",
1533 drm_dp_is_branch(intel_dp->dpcd) ? "branch" : "sink",
1534 (int)sizeof(desc->oui), desc->oui, oui_sup ? "" : "(NS)",
1535 dev_id_len, desc->device_id,
1536 desc->hw_rev >> 4, desc->hw_rev & 0xf,
1537 desc->sw_major_rev, desc->sw_minor_rev);
Mika Kahola1a2724f2016-09-09 14:10:54 +03001538
Imre Deak7b3fc172016-10-25 16:12:39 +03001539 return true;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001540}
1541
Ville Syrjäläf4896f12015-03-12 17:10:27 +02001542static int rate_to_index(int find, const int *rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301543{
1544 int i = 0;
1545
1546 for (i = 0; i < DP_MAX_SUPPORTED_RATES; ++i)
1547 if (find == rates[i])
1548 break;
1549
1550 return i;
1551}
1552
Ville Syrjälä50fec212015-03-12 17:10:34 +02001553int
1554intel_dp_max_link_rate(struct intel_dp *intel_dp)
1555{
1556 int rates[DP_MAX_SUPPORTED_RATES] = {};
1557 int len;
1558
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001559 len = intel_dp_common_rates(intel_dp, rates);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001560 if (WARN_ON(len <= 0))
1561 return 162000;
1562
Ville Syrjälä1354f732016-07-28 17:50:45 +03001563 return rates[len - 1];
Ville Syrjälä50fec212015-03-12 17:10:34 +02001564}
1565
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001566int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1567{
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001568 return rate_to_index(rate, intel_dp->sink_rates);
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001569}
1570
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001571void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1572 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001573{
1574 if (intel_dp->num_sink_rates) {
1575 *link_bw = 0;
1576 *rate_select =
1577 intel_dp_rate_select(intel_dp, port_clock);
1578 } else {
1579 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1580 *rate_select = 0;
1581 }
1582}
1583
Jani Nikulaf580bea2016-09-15 16:28:52 +03001584static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1585 struct intel_crtc_state *pipe_config)
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001586{
1587 int bpp, bpc;
1588
1589 bpp = pipe_config->pipe_bpp;
1590 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1591
1592 if (bpc > 0)
1593 bpp = min(bpp, 3*bpc);
1594
1595 return bpp;
1596}
1597
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001598bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001599intel_dp_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001600 struct intel_crtc_state *pipe_config,
1601 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001602{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001603 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001604 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001605 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001606 enum port port = dp_to_dig_port(intel_dp)->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001607 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001608 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001609 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001610 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001611 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001612 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001613 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301614 int max_clock;
Daniel Vetter083f9562012-04-20 20:23:49 +02001615 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001616 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001617 int common_rates[DP_MAX_SUPPORTED_RATES] = {};
1618 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001619 uint8_t link_bw, rate_select;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301620
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001621 common_len = intel_dp_common_rates(intel_dp, common_rates);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301622
1623 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001624 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301625
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001626 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001627
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001628 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001629 pipe_config->has_pch_encoder = true;
1630
Vandana Kannanf769cd22014-08-05 07:51:22 -07001631 pipe_config->has_drrs = false;
Jani Nikula9fcb1702015-05-05 16:32:12 +03001632 pipe_config->has_audio = intel_dp->has_audio && port != PORT_A;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001633
Jani Nikuladd06f902012-10-19 14:51:50 +03001634 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1635 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
1636 adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001637
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001638 if (INTEL_GEN(dev_priv) >= 9) {
Chandra Kondurua1b22782015-04-07 15:28:45 -07001639 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001640 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001641 if (ret)
1642 return ret;
1643 }
1644
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001645 if (HAS_GMCH_DISPLAY(dev_priv))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001646 intel_gmch_panel_fitting(intel_crtc, pipe_config,
1647 intel_connector->panel.fitting_mode);
1648 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001649 intel_pch_panel_fitting(intel_crtc, pipe_config,
1650 intel_connector->panel.fitting_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001651 }
1652
Daniel Vettercb1793c2012-06-04 18:39:21 +02001653 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001654 return false;
1655
Daniel Vetter083f9562012-04-20 20:23:49 +02001656 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301657 "max bw %d pixel clock %iKHz\n",
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001658 max_lane_count, common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001659 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001660
Daniel Vetter36008362013-03-27 00:44:59 +01001661 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1662 * bpc in between. */
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001663 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
Jani Nikula56071a22014-05-06 14:56:52 +03001664 if (is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301665
1666 /* Get bpp from vbt only for panels that dont have bpp in edid */
1667 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001668 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001669 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001670 dev_priv->vbt.edp.bpp);
1671 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001672 }
1673
Jani Nikula344c5bb2014-09-09 11:25:13 +03001674 /*
1675 * Use the maximum clock and number of lanes the eDP panel
1676 * advertizes being capable of. The panels are generally
1677 * designed to support only a single clock and lane
1678 * configuration, and typically these values correspond to the
1679 * native resolution of the panel.
1680 */
1681 min_lane_count = max_lane_count;
1682 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001683 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001684
Daniel Vetter36008362013-03-27 00:44:59 +01001685 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001686 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1687 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001688
Dave Airliec6930992014-07-14 11:04:39 +10001689 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301690 for (lane_count = min_lane_count;
1691 lane_count <= max_lane_count;
1692 lane_count <<= 1) {
1693
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001694 link_clock = common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001695 link_avail = intel_dp_max_data_rate(link_clock,
1696 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001697
Daniel Vetter36008362013-03-27 00:44:59 +01001698 if (mode_rate <= link_avail) {
1699 goto found;
1700 }
1701 }
1702 }
1703 }
1704
1705 return false;
1706
1707found:
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001708 if (intel_dp->color_range_auto) {
1709 /*
1710 * See:
1711 * CEA-861-E - 5.1 Default Encoding Parameters
1712 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1713 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001714 pipe_config->limited_color_range =
1715 bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1;
1716 } else {
1717 pipe_config->limited_color_range =
1718 intel_dp->limited_color_range;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001719 }
1720
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001721 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301722
Daniel Vetter657445f2013-05-04 10:09:18 +02001723 pipe_config->pipe_bpp = bpp;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001724 pipe_config->port_clock = common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001725
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001726 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1727 &link_bw, &rate_select);
1728
1729 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1730 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001731 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001732 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1733 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001734
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001735 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001736 adjusted_mode->crtc_clock,
1737 pipe_config->port_clock,
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001738 &pipe_config->dp_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001739
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301740 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301741 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001742 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301743 intel_link_compute_m_n(bpp, lane_count,
1744 intel_connector->panel.downclock_mode->clock,
1745 pipe_config->port_clock,
1746 &pipe_config->dp_m2_n2);
1747 }
1748
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001749 /*
1750 * DPLL0 VCO may need to be adjusted to get the correct
1751 * clock for eDP. This will affect cdclk as well.
1752 */
1753 if (is_edp(intel_dp) &&
1754 (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))) {
1755 int vco;
1756
1757 switch (pipe_config->port_clock / 2) {
1758 case 108000:
1759 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001760 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001761 break;
1762 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001763 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001764 break;
1765 }
1766
1767 to_intel_atomic_state(pipe_config->base.state)->cdclk_pll_vco = vco;
1768 }
1769
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001770 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001771 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001772
Daniel Vetter36008362013-03-27 00:44:59 +01001773 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001774}
1775
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001776void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001777 int link_rate, uint8_t lane_count,
1778 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001779{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001780 intel_dp->link_rate = link_rate;
1781 intel_dp->lane_count = lane_count;
1782 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001783}
1784
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001785static void intel_dp_prepare(struct intel_encoder *encoder,
1786 struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001787{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001788 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001789 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001790 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001791 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001792 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001793 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001794
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001795 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1796 pipe_config->lane_count,
1797 intel_crtc_has_type(pipe_config,
1798 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001799
Keith Packard417e8222011-11-01 19:54:11 -07001800 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001801 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001802 *
1803 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001804 * SNB CPU
1805 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001806 * CPT PCH
1807 *
1808 * IBX PCH and CPU are the same for almost everything,
1809 * except that the CPU DP PLL is configured in this
1810 * register
1811 *
1812 * CPT PCH is quite different, having many bits moved
1813 * to the TRANS_DP_CTL register instead. That
1814 * configuration happens (oddly) in ironlake_pch_enable
1815 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001816
Keith Packard417e8222011-11-01 19:54:11 -07001817 /* Preserve the BIOS-computed detected bit. This is
1818 * supposed to be read-only.
1819 */
1820 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001821
Keith Packard417e8222011-11-01 19:54:11 -07001822 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001823 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001824 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001825
Keith Packard417e8222011-11-01 19:54:11 -07001826 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001827
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001828 if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001829 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1830 intel_dp->DP |= DP_SYNC_HS_HIGH;
1831 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1832 intel_dp->DP |= DP_SYNC_VS_HIGH;
1833 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1834
Jani Nikula6aba5b62013-10-04 15:08:10 +03001835 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001836 intel_dp->DP |= DP_ENHANCED_FRAMING;
1837
Daniel Vetter7c62a162013-06-01 17:16:20 +02001838 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001839 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001840 u32 trans_dp;
1841
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001842 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001843
1844 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1845 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1846 trans_dp |= TRANS_DP_ENH_FRAMING;
1847 else
1848 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1849 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001850 } else {
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02001851 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001852 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001853
1854 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1855 intel_dp->DP |= DP_SYNC_HS_HIGH;
1856 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1857 intel_dp->DP |= DP_SYNC_VS_HIGH;
1858 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1859
Jani Nikula6aba5b62013-10-04 15:08:10 +03001860 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001861 intel_dp->DP |= DP_ENHANCED_FRAMING;
1862
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001863 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001864 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001865 else if (crtc->pipe == PIPE_B)
1866 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001867 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001868}
1869
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001870#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1871#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001872
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001873#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1874#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001875
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001876#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1877#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001878
Imre Deakde9c1b62016-06-16 20:01:46 +03001879static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
1880 struct intel_dp *intel_dp);
1881
Daniel Vetter4be73782014-01-17 14:39:48 +01001882static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001883 u32 mask,
1884 u32 value)
1885{
Paulo Zanoni30add222012-10-26 19:05:45 -02001886 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001887 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001888 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001889
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001890 lockdep_assert_held(&dev_priv->pps_mutex);
1891
Imre Deakde9c1b62016-06-16 20:01:46 +03001892 intel_pps_verify_state(dev_priv, intel_dp);
1893
Jani Nikulabf13e812013-09-06 07:40:05 +03001894 pp_stat_reg = _pp_stat_reg(intel_dp);
1895 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001896
1897 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001898 mask, value,
1899 I915_READ(pp_stat_reg),
1900 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001901
Chris Wilson9036ff02016-06-30 15:33:09 +01001902 if (intel_wait_for_register(dev_priv,
1903 pp_stat_reg, mask, value,
1904 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001905 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001906 I915_READ(pp_stat_reg),
1907 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001908
1909 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001910}
1911
Daniel Vetter4be73782014-01-17 14:39:48 +01001912static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001913{
1914 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001915 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001916}
1917
Daniel Vetter4be73782014-01-17 14:39:48 +01001918static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001919{
Keith Packardbd943152011-09-18 23:09:52 -07001920 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001921 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001922}
Keith Packardbd943152011-09-18 23:09:52 -07001923
Daniel Vetter4be73782014-01-17 14:39:48 +01001924static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001925{
Abhay Kumard28d4732016-01-22 17:39:04 -08001926 ktime_t panel_power_on_time;
1927 s64 panel_power_off_duration;
1928
Keith Packard99ea7122011-11-01 19:57:50 -07001929 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001930
Abhay Kumard28d4732016-01-22 17:39:04 -08001931 /* take the difference of currrent time and panel power off time
1932 * and then make panel wait for t11_t12 if needed. */
1933 panel_power_on_time = ktime_get_boottime();
1934 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1935
Paulo Zanonidce56b32013-12-19 14:29:40 -02001936 /* When we disable the VDD override bit last we have to do the manual
1937 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08001938 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
1939 wait_remaining_ms_from_jiffies(jiffies,
1940 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001941
Daniel Vetter4be73782014-01-17 14:39:48 +01001942 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001943}
Keith Packardbd943152011-09-18 23:09:52 -07001944
Daniel Vetter4be73782014-01-17 14:39:48 +01001945static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001946{
1947 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1948 intel_dp->backlight_on_delay);
1949}
1950
Daniel Vetter4be73782014-01-17 14:39:48 +01001951static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001952{
1953 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
1954 intel_dp->backlight_off_delay);
1955}
Keith Packard99ea7122011-11-01 19:57:50 -07001956
Keith Packard832dd3c2011-11-01 19:34:06 -07001957/* Read the current pp_control value, unlocking the register if it
1958 * is locked
1959 */
1960
Jesse Barnes453c5422013-03-28 09:55:41 -07001961static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07001962{
Jesse Barnes453c5422013-03-28 09:55:41 -07001963 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001964 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07001965 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07001966
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001967 lockdep_assert_held(&dev_priv->pps_mutex);
1968
Jani Nikulabf13e812013-09-06 07:40:05 +03001969 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03001970 if (WARN_ON(!HAS_DDI(dev_priv) &&
1971 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05301972 control &= ~PANEL_UNLOCK_MASK;
1973 control |= PANEL_UNLOCK_REGS;
1974 }
Keith Packard832dd3c2011-11-01 19:34:06 -07001975 return control;
Keith Packardbd943152011-09-18 23:09:52 -07001976}
1977
Ville Syrjälä951468f2014-09-04 14:55:31 +03001978/*
1979 * Must be paired with edp_panel_vdd_off().
1980 * Must hold pps_mutex around the whole on/off sequence.
1981 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
1982 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001983static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001984{
Paulo Zanoni30add222012-10-26 19:05:45 -02001985 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001986 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1987 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001988 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001989 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08001990 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001991 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001992 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08001993
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001994 lockdep_assert_held(&dev_priv->pps_mutex);
1995
Keith Packard97af61f572011-09-28 16:23:51 -07001996 if (!is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001997 return false;
Keith Packardbd943152011-09-18 23:09:52 -07001998
Egbert Eich2c623c12014-11-25 12:54:57 +01001999 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002000 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07002001
Daniel Vetter4be73782014-01-17 14:39:48 +01002002 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002003 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002004
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002005 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002006 intel_display_power_get(dev_priv, power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002007
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002008 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
2009 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07002010
Daniel Vetter4be73782014-01-17 14:39:48 +01002011 if (!edp_have_panel_power(intel_dp))
2012 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07002013
Jesse Barnes453c5422013-03-28 09:55:41 -07002014 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002015 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07002016
Jani Nikulabf13e812013-09-06 07:40:05 +03002017 pp_stat_reg = _pp_stat_reg(intel_dp);
2018 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002019
2020 I915_WRITE(pp_ctrl_reg, pp);
2021 POSTING_READ(pp_ctrl_reg);
2022 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2023 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07002024 /*
2025 * If the panel wasn't on, delay before accessing aux channel
2026 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002027 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002028 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
2029 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07002030 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07002031 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002032
2033 return need_to_disable;
2034}
2035
Ville Syrjälä951468f2014-09-04 14:55:31 +03002036/*
2037 * Must be paired with intel_edp_panel_vdd_off() or
2038 * intel_edp_panel_off().
2039 * Nested calls to these functions are not allowed since
2040 * we drop the lock. Caller must use some higher level
2041 * locking to prevent nested calls from other threads.
2042 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01002043void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002044{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002045 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002046
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002047 if (!is_edp(intel_dp))
2048 return;
2049
Ville Syrjälä773538e82014-09-04 14:54:56 +03002050 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002051 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002052 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002053
Rob Clarke2c719b2014-12-15 13:56:32 -05002054 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002055 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08002056}
2057
Daniel Vetter4be73782014-01-17 14:39:48 +01002058static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002059{
Paulo Zanoni30add222012-10-26 19:05:45 -02002060 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002061 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002062 struct intel_digital_port *intel_dig_port =
2063 dp_to_dig_port(intel_dp);
2064 struct intel_encoder *intel_encoder = &intel_dig_port->base;
2065 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08002066 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002067 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002068
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002069 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002070
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002071 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002072
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002073 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002074 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002075
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002076 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2077 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002078
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002079 pp = ironlake_get_pp_control(intel_dp);
2080 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002081
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002082 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2083 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002084
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002085 I915_WRITE(pp_ctrl_reg, pp);
2086 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002087
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002088 /* Make sure sequencer is idle before allowing subsequent activity */
2089 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2090 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002091
Imre Deak5a162e22016-08-10 14:07:30 +03002092 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002093 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002094
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002095 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002096 intel_display_power_put(dev_priv, power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002097}
2098
Daniel Vetter4be73782014-01-17 14:39:48 +01002099static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002100{
2101 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2102 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002103
Ville Syrjälä773538e82014-09-04 14:54:56 +03002104 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002105 if (!intel_dp->want_panel_vdd)
2106 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002107 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002108}
2109
Imre Deakaba86892014-07-30 15:57:31 +03002110static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2111{
2112 unsigned long delay;
2113
2114 /*
2115 * Queue the timer to fire a long time from now (relative to the power
2116 * down delay) to keep the panel power up across a sequence of
2117 * operations.
2118 */
2119 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2120 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2121}
2122
Ville Syrjälä951468f2014-09-04 14:55:31 +03002123/*
2124 * Must be paired with edp_panel_vdd_on().
2125 * Must hold pps_mutex around the whole on/off sequence.
2126 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2127 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002128static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002129{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002130 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002131
2132 lockdep_assert_held(&dev_priv->pps_mutex);
2133
Keith Packard97af61f572011-09-28 16:23:51 -07002134 if (!is_edp(intel_dp))
2135 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002136
Rob Clarke2c719b2014-12-15 13:56:32 -05002137 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002138 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002139
Keith Packardbd943152011-09-18 23:09:52 -07002140 intel_dp->want_panel_vdd = false;
2141
Imre Deakaba86892014-07-30 15:57:31 +03002142 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002143 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002144 else
2145 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002146}
2147
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002148static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002149{
Paulo Zanoni30add222012-10-26 19:05:45 -02002150 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002151 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002152 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002153 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002154
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002155 lockdep_assert_held(&dev_priv->pps_mutex);
2156
Keith Packard97af61f572011-09-28 16:23:51 -07002157 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002158 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002159
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002160 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2161 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002162
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002163 if (WARN(edp_have_panel_power(intel_dp),
2164 "eDP port %c panel power already on\n",
2165 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002166 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002167
Daniel Vetter4be73782014-01-17 14:39:48 +01002168 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002169
Jani Nikulabf13e812013-09-06 07:40:05 +03002170 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002171 pp = ironlake_get_pp_control(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002172 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002173 /* ILK workaround: disable reset around power sequence */
2174 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002175 I915_WRITE(pp_ctrl_reg, pp);
2176 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002177 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002178
Imre Deak5a162e22016-08-10 14:07:30 +03002179 pp |= PANEL_POWER_ON;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002180 if (!IS_GEN5(dev_priv))
Keith Packard99ea7122011-11-01 19:57:50 -07002181 pp |= PANEL_POWER_RESET;
2182
Jesse Barnes453c5422013-03-28 09:55:41 -07002183 I915_WRITE(pp_ctrl_reg, pp);
2184 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002185
Daniel Vetter4be73782014-01-17 14:39:48 +01002186 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002187 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002188
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002189 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002190 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002191 I915_WRITE(pp_ctrl_reg, pp);
2192 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002193 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002194}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002195
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002196void intel_edp_panel_on(struct intel_dp *intel_dp)
2197{
2198 if (!is_edp(intel_dp))
2199 return;
2200
2201 pps_lock(intel_dp);
2202 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002203 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002204}
2205
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002206
2207static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002208{
Imre Deak4e6e1a52014-03-27 17:45:11 +02002209 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2210 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanoni30add222012-10-26 19:05:45 -02002211 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002212 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002213 enum intel_display_power_domain power_domain;
Keith Packard99ea7122011-11-01 19:57:50 -07002214 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002215 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002216
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002217 lockdep_assert_held(&dev_priv->pps_mutex);
2218
Keith Packard97af61f572011-09-28 16:23:51 -07002219 if (!is_edp(intel_dp))
2220 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002221
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002222 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2223 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002224
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002225 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2226 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002227
Jesse Barnes453c5422013-03-28 09:55:41 -07002228 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002229 /* We need to switch off panel power _and_ force vdd, for otherwise some
2230 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002231 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002232 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002233
Jani Nikulabf13e812013-09-06 07:40:05 +03002234 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002235
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002236 intel_dp->want_panel_vdd = false;
2237
Jesse Barnes453c5422013-03-28 09:55:41 -07002238 I915_WRITE(pp_ctrl_reg, pp);
2239 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002240
Abhay Kumard28d4732016-01-22 17:39:04 -08002241 intel_dp->panel_power_off_time = ktime_get_boottime();
Daniel Vetter4be73782014-01-17 14:39:48 +01002242 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002243
2244 /* We got a reference when we enabled the VDD. */
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002245 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002246 intel_display_power_put(dev_priv, power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002247}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002248
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002249void intel_edp_panel_off(struct intel_dp *intel_dp)
2250{
2251 if (!is_edp(intel_dp))
2252 return;
2253
2254 pps_lock(intel_dp);
2255 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002256 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002257}
2258
Jani Nikula1250d102014-08-12 17:11:39 +03002259/* Enable backlight in the panel power control. */
2260static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002261{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002262 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2263 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002264 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002265 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002266 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002267
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002268 /*
2269 * If we enable the backlight right away following a panel power
2270 * on, we may see slight flicker as the panel syncs with the eDP
2271 * link. So delay a bit to make sure the image is solid before
2272 * allowing it to appear.
2273 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002274 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002275
Ville Syrjälä773538e82014-09-04 14:54:56 +03002276 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002277
Jesse Barnes453c5422013-03-28 09:55:41 -07002278 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002279 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002280
Jani Nikulabf13e812013-09-06 07:40:05 +03002281 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002282
2283 I915_WRITE(pp_ctrl_reg, pp);
2284 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002285
Ville Syrjälä773538e82014-09-04 14:54:56 +03002286 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002287}
2288
Jani Nikula1250d102014-08-12 17:11:39 +03002289/* Enable backlight PWM and backlight PP control. */
2290void intel_edp_backlight_on(struct intel_dp *intel_dp)
2291{
2292 if (!is_edp(intel_dp))
2293 return;
2294
2295 DRM_DEBUG_KMS("\n");
2296
2297 intel_panel_enable_backlight(intel_dp->attached_connector);
2298 _intel_edp_backlight_on(intel_dp);
2299}
2300
2301/* Disable backlight in the panel power control. */
2302static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002303{
Paulo Zanoni30add222012-10-26 19:05:45 -02002304 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002305 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002306 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002307 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002308
Keith Packardf01eca22011-09-28 16:48:10 -07002309 if (!is_edp(intel_dp))
2310 return;
2311
Ville Syrjälä773538e82014-09-04 14:54:56 +03002312 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002313
Jesse Barnes453c5422013-03-28 09:55:41 -07002314 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002315 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002316
Jani Nikulabf13e812013-09-06 07:40:05 +03002317 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002318
2319 I915_WRITE(pp_ctrl_reg, pp);
2320 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002321
Ville Syrjälä773538e82014-09-04 14:54:56 +03002322 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002323
Paulo Zanonidce56b32013-12-19 14:29:40 -02002324 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002325 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002326}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002327
Jani Nikula1250d102014-08-12 17:11:39 +03002328/* Disable backlight PP control and backlight PWM. */
2329void intel_edp_backlight_off(struct intel_dp *intel_dp)
2330{
2331 if (!is_edp(intel_dp))
2332 return;
2333
2334 DRM_DEBUG_KMS("\n");
2335
2336 _intel_edp_backlight_off(intel_dp);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002337 intel_panel_disable_backlight(intel_dp->attached_connector);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002338}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002339
Jani Nikula73580fb72014-08-12 17:11:41 +03002340/*
2341 * Hook for controlling the panel power control backlight through the bl_power
2342 * sysfs attribute. Take care to handle multiple calls.
2343 */
2344static void intel_edp_backlight_power(struct intel_connector *connector,
2345 bool enable)
2346{
2347 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002348 bool is_enabled;
2349
Ville Syrjälä773538e82014-09-04 14:54:56 +03002350 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002351 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002352 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002353
2354 if (is_enabled == enable)
2355 return;
2356
Jani Nikula23ba9372014-08-27 14:08:43 +03002357 DRM_DEBUG_KMS("panel power control backlight %s\n",
2358 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002359
2360 if (enable)
2361 _intel_edp_backlight_on(intel_dp);
2362 else
2363 _intel_edp_backlight_off(intel_dp);
2364}
2365
Ville Syrjälä64e10772015-10-29 21:26:01 +02002366static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2367{
2368 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2369 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2370 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2371
2372 I915_STATE_WARN(cur_state != state,
2373 "DP port %c state assertion failure (expected %s, current %s)\n",
2374 port_name(dig_port->port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002375 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002376}
2377#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2378
2379static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2380{
2381 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2382
2383 I915_STATE_WARN(cur_state != state,
2384 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002385 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002386}
2387#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2388#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2389
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002390static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2391 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002392{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002393 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002394 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002395
Ville Syrjälä64e10772015-10-29 21:26:01 +02002396 assert_pipe_disabled(dev_priv, crtc->pipe);
2397 assert_dp_port_disabled(intel_dp);
2398 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002399
Ville Syrjäläabfce942015-10-29 21:26:03 +02002400 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002401 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002402
2403 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2404
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002405 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002406 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2407 else
2408 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2409
2410 I915_WRITE(DP_A, intel_dp->DP);
2411 POSTING_READ(DP_A);
2412 udelay(500);
2413
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002414 /*
2415 * [DevILK] Work around required when enabling DP PLL
2416 * while a pipe is enabled going to FDI:
2417 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2418 * 2. Program DP PLL enable
2419 */
2420 if (IS_GEN5(dev_priv))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02002421 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002422
Daniel Vetter07679352012-09-06 22:15:42 +02002423 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002424
Daniel Vetter07679352012-09-06 22:15:42 +02002425 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002426 POSTING_READ(DP_A);
2427 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002428}
2429
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002430static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002431{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002432 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002433 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2434 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002435
Ville Syrjälä64e10772015-10-29 21:26:01 +02002436 assert_pipe_disabled(dev_priv, crtc->pipe);
2437 assert_dp_port_disabled(intel_dp);
2438 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002439
Ville Syrjäläabfce942015-10-29 21:26:03 +02002440 DRM_DEBUG_KMS("disabling eDP PLL\n");
2441
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002442 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002443
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002444 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002445 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002446 udelay(200);
2447}
2448
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002449/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002450void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002451{
2452 int ret, i;
2453
2454 /* Should have a valid DPCD by this point */
2455 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2456 return;
2457
2458 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002459 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2460 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002461 } else {
Imre Deak357c0ae2016-11-21 21:15:06 +02002462 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
2463
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002464 /*
2465 * When turning on, we need to retry for 1ms to give the sink
2466 * time to wake up.
2467 */
2468 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002469 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2470 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002471 if (ret == 1)
2472 break;
2473 msleep(1);
2474 }
Imre Deak357c0ae2016-11-21 21:15:06 +02002475
2476 if (ret == 1 && lspcon->active)
2477 lspcon_wait_pcon_mode(lspcon);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002478 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002479
2480 if (ret != 1)
2481 DRM_DEBUG_KMS("failed to %s sink power state\n",
2482 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002483}
2484
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002485static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2486 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002487{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002488 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002489 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002490 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002491 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002492 enum intel_display_power_domain power_domain;
2493 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002494 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002495
2496 power_domain = intel_display_port_power_domain(encoder);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002497 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002498 return false;
2499
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002500 ret = false;
2501
Imre Deak6d129be2014-03-05 16:20:54 +02002502 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002503
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002504 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002505 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002506
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002507 if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002508 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002509 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002510 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002511
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002512 for_each_pipe(dev_priv, p) {
2513 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2514 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2515 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002516 ret = true;
2517
2518 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002519 }
2520 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002521
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002522 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002523 i915_mmio_reg_offset(intel_dp->output_reg));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002524 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002525 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2526 } else {
2527 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002528 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002529
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002530 ret = true;
2531
2532out:
2533 intel_display_power_put(dev_priv, power_domain);
2534
2535 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002536}
2537
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002538static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002539 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002540{
2541 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002542 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002543 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002544 struct drm_i915_private *dev_priv = to_i915(dev);
Xiong Zhang63000ef2013-06-28 12:59:06 +08002545 enum port port = dp_to_dig_port(intel_dp)->port;
2546 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002547
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002548 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002549
2550 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002551
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002552 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002553 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2554
2555 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002556 flags |= DRM_MODE_FLAG_PHSYNC;
2557 else
2558 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002559
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002560 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002561 flags |= DRM_MODE_FLAG_PVSYNC;
2562 else
2563 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002564 } else {
2565 if (tmp & DP_SYNC_HS_HIGH)
2566 flags |= DRM_MODE_FLAG_PHSYNC;
2567 else
2568 flags |= DRM_MODE_FLAG_NHSYNC;
2569
2570 if (tmp & DP_SYNC_VS_HIGH)
2571 flags |= DRM_MODE_FLAG_PVSYNC;
2572 else
2573 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002574 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002575
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002576 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002577
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02002578 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002579 pipe_config->limited_color_range = true;
2580
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002581 pipe_config->lane_count =
2582 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2583
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002584 intel_dp_get_m_n(crtc, pipe_config);
2585
Ville Syrjälä18442d02013-09-13 16:00:08 +03002586 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002587 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002588 pipe_config->port_clock = 162000;
2589 else
2590 pipe_config->port_clock = 270000;
2591 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002592
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002593 pipe_config->base.adjusted_mode.crtc_clock =
2594 intel_dotclock_calculate(pipe_config->port_clock,
2595 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002596
Jani Nikula6aa23e62016-03-24 17:50:20 +02002597 if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
2598 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002599 /*
2600 * This is a big fat ugly hack.
2601 *
2602 * Some machines in UEFI boot mode provide us a VBT that has 18
2603 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2604 * unknown we fail to light up. Yet the same BIOS boots up with
2605 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2606 * max, not what it tells us to use.
2607 *
2608 * Note: This will still be broken if the eDP panel is not lit
2609 * up by the BIOS, and thus we can't get the mode at module
2610 * load.
2611 */
2612 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002613 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2614 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002615 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002616}
2617
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002618static void intel_disable_dp(struct intel_encoder *encoder,
2619 struct intel_crtc_state *old_crtc_state,
2620 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002621{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002622 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002623 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002624
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002625 if (old_crtc_state->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002626 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002627
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002628 if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv))
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002629 intel_psr_disable(intel_dp);
2630
Daniel Vetter6cb49832012-05-20 17:14:50 +02002631 /* Make sure the panel is off before trying to change the mode. But also
2632 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002633 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01002634 intel_edp_backlight_off(intel_dp);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002635 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002636 intel_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02002637
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002638 /* disable the port before the pipe on g4x */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002639 if (INTEL_GEN(dev_priv) < 5)
Daniel Vetter37398502012-09-06 22:15:44 +02002640 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07002641}
2642
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002643static void ilk_post_disable_dp(struct intel_encoder *encoder,
2644 struct intel_crtc_state *old_crtc_state,
2645 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002646{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002647 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002648 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002649
Ville Syrjälä49277c32014-03-31 18:21:26 +03002650 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002651
2652 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002653 if (port == PORT_A)
2654 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002655}
2656
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002657static void vlv_post_disable_dp(struct intel_encoder *encoder,
2658 struct intel_crtc_state *old_crtc_state,
2659 struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002660{
2661 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2662
2663 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002664}
2665
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002666static void chv_post_disable_dp(struct intel_encoder *encoder,
2667 struct intel_crtc_state *old_crtc_state,
2668 struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002669{
2670 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002671 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002672 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002673
2674 intel_dp_link_down(intel_dp);
2675
Ville Syrjäläa5805162015-05-26 20:42:30 +03002676 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002677
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002678 /* Assert data lane reset */
2679 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002680
Ville Syrjäläa5805162015-05-26 20:42:30 +03002681 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002682}
2683
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002684static void
2685_intel_dp_set_link_train(struct intel_dp *intel_dp,
2686 uint32_t *DP,
2687 uint8_t dp_train_pat)
2688{
2689 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2690 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002691 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002692 enum port port = intel_dig_port->port;
2693
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002694 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2695 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2696 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2697
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002698 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002699 uint32_t temp = I915_READ(DP_TP_CTL(port));
2700
2701 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2702 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2703 else
2704 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2705
2706 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2707 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2708 case DP_TRAINING_PATTERN_DISABLE:
2709 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2710
2711 break;
2712 case DP_TRAINING_PATTERN_1:
2713 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2714 break;
2715 case DP_TRAINING_PATTERN_2:
2716 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2717 break;
2718 case DP_TRAINING_PATTERN_3:
2719 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2720 break;
2721 }
2722 I915_WRITE(DP_TP_CTL(port), temp);
2723
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002724 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002725 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002726 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2727
2728 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2729 case DP_TRAINING_PATTERN_DISABLE:
2730 *DP |= DP_LINK_TRAIN_OFF_CPT;
2731 break;
2732 case DP_TRAINING_PATTERN_1:
2733 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2734 break;
2735 case DP_TRAINING_PATTERN_2:
2736 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2737 break;
2738 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002739 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002740 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2741 break;
2742 }
2743
2744 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002745 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002746 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2747 else
2748 *DP &= ~DP_LINK_TRAIN_MASK;
2749
2750 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2751 case DP_TRAINING_PATTERN_DISABLE:
2752 *DP |= DP_LINK_TRAIN_OFF;
2753 break;
2754 case DP_TRAINING_PATTERN_1:
2755 *DP |= DP_LINK_TRAIN_PAT_1;
2756 break;
2757 case DP_TRAINING_PATTERN_2:
2758 *DP |= DP_LINK_TRAIN_PAT_2;
2759 break;
2760 case DP_TRAINING_PATTERN_3:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002761 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002762 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2763 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002764 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002765 *DP |= DP_LINK_TRAIN_PAT_2;
2766 }
2767 break;
2768 }
2769 }
2770}
2771
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002772static void intel_dp_enable_port(struct intel_dp *intel_dp,
2773 struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002774{
2775 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002776 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002777
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002778 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002779
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002780 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002781
2782 /*
2783 * Magic for VLV/CHV. We _must_ first set up the register
2784 * without actually enabling the port, and then do another
2785 * write to enable the port. Otherwise link training will
2786 * fail when the power sequencer is freshly used for this port.
2787 */
2788 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002789 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002790 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002791
2792 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2793 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002794}
2795
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002796static void intel_enable_dp(struct intel_encoder *encoder,
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002797 struct intel_crtc_state *pipe_config,
2798 struct drm_connector_state *conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002799{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002800 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2801 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002802 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulac1dec792014-10-27 16:26:56 +02002803 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002804 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002805 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002806
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002807 if (WARN_ON(dp_reg & DP_PORT_EN))
2808 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002809
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002810 pps_lock(intel_dp);
2811
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002812 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002813 vlv_init_panel_power_sequencer(intel_dp);
2814
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002815 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002816
2817 edp_panel_vdd_on(intel_dp);
2818 edp_panel_on(intel_dp);
2819 edp_panel_vdd_off(intel_dp, true);
2820
2821 pps_unlock(intel_dp);
2822
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002823 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002824 unsigned int lane_mask = 0x0;
2825
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002826 if (IS_CHERRYVIEW(dev_priv))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002827 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002828
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002829 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2830 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002831 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002832
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002833 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2834 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002835 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002836
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002837 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002838 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002839 pipe_name(pipe));
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002840 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Jani Nikulac1dec792014-10-27 16:26:56 +02002841 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002842}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002843
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002844static void g4x_enable_dp(struct intel_encoder *encoder,
2845 struct intel_crtc_state *pipe_config,
2846 struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03002847{
Jani Nikula828f5c62013-09-05 16:44:45 +03002848 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2849
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002850 intel_enable_dp(encoder, pipe_config, conn_state);
Daniel Vetter4be73782014-01-17 14:39:48 +01002851 intel_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002852}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002853
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002854static void vlv_enable_dp(struct intel_encoder *encoder,
2855 struct intel_crtc_state *pipe_config,
2856 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002857{
Jani Nikula828f5c62013-09-05 16:44:45 +03002858 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2859
Daniel Vetter4be73782014-01-17 14:39:48 +01002860 intel_edp_backlight_on(intel_dp);
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002861 intel_psr_enable(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002862}
2863
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002864static void g4x_pre_enable_dp(struct intel_encoder *encoder,
2865 struct intel_crtc_state *pipe_config,
2866 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002867{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002868 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002869 enum port port = dp_to_dig_port(intel_dp)->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002870
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002871 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002872
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002873 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002874 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002875 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002876}
2877
Ville Syrjälä83b84592014-10-16 21:29:51 +03002878static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2879{
2880 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002881 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002882 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03002883 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002884
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002885 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
2886
Ville Syrjälä83b84592014-10-16 21:29:51 +03002887 edp_panel_vdd_off_sync(intel_dp);
2888
2889 /*
2890 * VLV seems to get confused when multiple power seqeuencers
2891 * have the same port selected (even if only one has power/vdd
2892 * enabled). The failure manifests as vlv_wait_port_ready() failing
2893 * CHV on the other hand doesn't seem to mind having the same port
2894 * selected in multiple power seqeuencers, but let's clear the
2895 * port select always when logically disconnecting a power sequencer
2896 * from a port.
2897 */
2898 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2899 pipe_name(pipe), port_name(intel_dig_port->port));
2900 I915_WRITE(pp_on_reg, 0);
2901 POSTING_READ(pp_on_reg);
2902
2903 intel_dp->pps_pipe = INVALID_PIPE;
2904}
2905
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002906static void vlv_steal_power_sequencer(struct drm_device *dev,
2907 enum pipe pipe)
2908{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002909 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002910 struct intel_encoder *encoder;
2911
2912 lockdep_assert_held(&dev_priv->pps_mutex);
2913
Ville Syrjäläac3c12e2014-10-16 21:29:56 +03002914 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2915 return;
2916
Jani Nikula19c80542015-12-16 12:48:16 +02002917 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002918 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002919 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002920
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002921 if (encoder->type != INTEL_OUTPUT_DP &&
2922 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002923 continue;
2924
2925 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002926 port = dp_to_dig_port(intel_dp)->port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002927
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002928 WARN(intel_dp->active_pipe == pipe,
2929 "stealing pipe %c power sequencer from active (e)DP port %c\n",
2930 pipe_name(pipe), port_name(port));
2931
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002932 if (intel_dp->pps_pipe != pipe)
2933 continue;
2934
2935 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03002936 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002937
2938 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002939 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002940 }
2941}
2942
2943static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
2944{
2945 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2946 struct intel_encoder *encoder = &intel_dig_port->base;
2947 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002948 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002949 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002950
2951 lockdep_assert_held(&dev_priv->pps_mutex);
2952
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002953 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002954
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002955 if (intel_dp->pps_pipe != INVALID_PIPE &&
2956 intel_dp->pps_pipe != crtc->pipe) {
2957 /*
2958 * If another power sequencer was being used on this
2959 * port previously make sure to turn off vdd there while
2960 * we still have control of it.
2961 */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002962 vlv_detach_power_sequencer(intel_dp);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002963 }
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002964
2965 /*
2966 * We may be stealing the power
2967 * sequencer from another port.
2968 */
2969 vlv_steal_power_sequencer(dev, crtc->pipe);
2970
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002971 intel_dp->active_pipe = crtc->pipe;
2972
2973 if (!is_edp(intel_dp))
2974 return;
2975
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002976 /* now it's all ours */
2977 intel_dp->pps_pipe = crtc->pipe;
2978
2979 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
2980 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
2981
2982 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03002983 intel_dp_init_panel_power_sequencer(dev, intel_dp);
2984 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002985}
2986
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002987static void vlv_pre_enable_dp(struct intel_encoder *encoder,
2988 struct intel_crtc_state *pipe_config,
2989 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002990{
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03002991 vlv_phy_pre_encoder_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002992
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002993 intel_enable_dp(encoder, pipe_config, conn_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002994}
2995
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002996static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
2997 struct intel_crtc_state *pipe_config,
2998 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07002999{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003000 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02003001
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03003002 vlv_phy_pre_pll_enable(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003003}
3004
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003005static void chv_pre_enable_dp(struct intel_encoder *encoder,
3006 struct intel_crtc_state *pipe_config,
3007 struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003008{
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003009 chv_phy_pre_encoder_enable(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003010
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003011 intel_enable_dp(encoder, pipe_config, conn_state);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03003012
3013 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003014 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003015}
3016
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003017static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
3018 struct intel_crtc_state *pipe_config,
3019 struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03003020{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003021 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03003022
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03003023 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03003024}
3025
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003026static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
3027 struct intel_crtc_state *pipe_config,
3028 struct drm_connector_state *conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003029{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03003030 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003031}
3032
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003033/*
3034 * Fetch AUX CH registers 0x202 - 0x207 which contain
3035 * link status information
3036 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003037bool
Keith Packard93f62da2011-11-01 19:45:03 -07003038intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003039{
Lyude9f085eb2016-04-13 10:58:33 -04003040 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
3041 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003042}
3043
Paulo Zanoni11002442014-06-13 18:45:41 -03003044/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003045uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003046intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003047{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003048 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003049 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003050
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003051 if (IS_GEN9_LP(dev_priv))
Vandana Kannan93147262014-11-18 15:45:29 +05303052 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003053 else if (INTEL_GEN(dev_priv) >= 9) {
Jani Nikula06411f02016-03-24 17:50:21 +02003054 if (dev_priv->vbt.edp.low_vswing && port == PORT_A)
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303055 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003056 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003057 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Sonika Jindalbd600182014-08-08 16:23:41 +05303058 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003059 else if (IS_GEN7(dev_priv) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303060 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003061 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303062 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08003063 else
Sonika Jindalbd600182014-08-08 16:23:41 +05303064 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08003065}
3066
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003067uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003068intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3069{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003070 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003071 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003072
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003073 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003074 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3075 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3076 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3077 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3078 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3079 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3080 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303081 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3082 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003083 default:
3084 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3085 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003086 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003087 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303088 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3089 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3090 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3091 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3092 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3093 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3094 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003095 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303096 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003097 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003098 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003099 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303100 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3101 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3102 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3103 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3104 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3105 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3106 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003107 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303108 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003109 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003110 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003111 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303112 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3113 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3114 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3115 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3116 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003117 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303118 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003119 }
3120 } else {
3121 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303122 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3123 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3124 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3125 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3126 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3127 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3128 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003129 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303130 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003131 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003132 }
3133}
3134
Daniel Vetter5829975c2015-04-16 11:36:52 +02003135static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003136{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003137 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003138 unsigned long demph_reg_value, preemph_reg_value,
3139 uniqtranscale_reg_value;
3140 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003141
3142 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303143 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003144 preemph_reg_value = 0x0004000;
3145 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303146 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003147 demph_reg_value = 0x2B405555;
3148 uniqtranscale_reg_value = 0x552AB83A;
3149 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303150 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003151 demph_reg_value = 0x2B404040;
3152 uniqtranscale_reg_value = 0x5548B83A;
3153 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303154 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003155 demph_reg_value = 0x2B245555;
3156 uniqtranscale_reg_value = 0x5560B83A;
3157 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303158 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003159 demph_reg_value = 0x2B405555;
3160 uniqtranscale_reg_value = 0x5598DA3A;
3161 break;
3162 default:
3163 return 0;
3164 }
3165 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303166 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003167 preemph_reg_value = 0x0002000;
3168 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303169 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003170 demph_reg_value = 0x2B404040;
3171 uniqtranscale_reg_value = 0x5552B83A;
3172 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303173 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003174 demph_reg_value = 0x2B404848;
3175 uniqtranscale_reg_value = 0x5580B83A;
3176 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303177 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003178 demph_reg_value = 0x2B404040;
3179 uniqtranscale_reg_value = 0x55ADDA3A;
3180 break;
3181 default:
3182 return 0;
3183 }
3184 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303185 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003186 preemph_reg_value = 0x0000000;
3187 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303188 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003189 demph_reg_value = 0x2B305555;
3190 uniqtranscale_reg_value = 0x5570B83A;
3191 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303192 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003193 demph_reg_value = 0x2B2B4040;
3194 uniqtranscale_reg_value = 0x55ADDA3A;
3195 break;
3196 default:
3197 return 0;
3198 }
3199 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303200 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003201 preemph_reg_value = 0x0006000;
3202 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303203 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003204 demph_reg_value = 0x1B405555;
3205 uniqtranscale_reg_value = 0x55ADDA3A;
3206 break;
3207 default:
3208 return 0;
3209 }
3210 break;
3211 default:
3212 return 0;
3213 }
3214
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003215 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3216 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003217
3218 return 0;
3219}
3220
Daniel Vetter5829975c2015-04-16 11:36:52 +02003221static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003222{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003223 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3224 u32 deemph_reg_value, margin_reg_value;
3225 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003226 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003227
3228 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303229 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003230 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303231 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003232 deemph_reg_value = 128;
3233 margin_reg_value = 52;
3234 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303235 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003236 deemph_reg_value = 128;
3237 margin_reg_value = 77;
3238 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303239 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003240 deemph_reg_value = 128;
3241 margin_reg_value = 102;
3242 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303243 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003244 deemph_reg_value = 128;
3245 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003246 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003247 break;
3248 default:
3249 return 0;
3250 }
3251 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303252 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003253 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303254 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003255 deemph_reg_value = 85;
3256 margin_reg_value = 78;
3257 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303258 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003259 deemph_reg_value = 85;
3260 margin_reg_value = 116;
3261 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303262 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003263 deemph_reg_value = 85;
3264 margin_reg_value = 154;
3265 break;
3266 default:
3267 return 0;
3268 }
3269 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303270 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003271 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303272 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003273 deemph_reg_value = 64;
3274 margin_reg_value = 104;
3275 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303276 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003277 deemph_reg_value = 64;
3278 margin_reg_value = 154;
3279 break;
3280 default:
3281 return 0;
3282 }
3283 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303284 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003285 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303286 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003287 deemph_reg_value = 43;
3288 margin_reg_value = 154;
3289 break;
3290 default:
3291 return 0;
3292 }
3293 break;
3294 default:
3295 return 0;
3296 }
3297
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003298 chv_set_phy_signal_level(encoder, deemph_reg_value,
3299 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003300
3301 return 0;
3302}
3303
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003304static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003305gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003306{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003307 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003308
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003309 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303310 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003311 default:
3312 signal_levels |= DP_VOLTAGE_0_4;
3313 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303314 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003315 signal_levels |= DP_VOLTAGE_0_6;
3316 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303317 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003318 signal_levels |= DP_VOLTAGE_0_8;
3319 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303320 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003321 signal_levels |= DP_VOLTAGE_1_2;
3322 break;
3323 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003324 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303325 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003326 default:
3327 signal_levels |= DP_PRE_EMPHASIS_0;
3328 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303329 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003330 signal_levels |= DP_PRE_EMPHASIS_3_5;
3331 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303332 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003333 signal_levels |= DP_PRE_EMPHASIS_6;
3334 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303335 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003336 signal_levels |= DP_PRE_EMPHASIS_9_5;
3337 break;
3338 }
3339 return signal_levels;
3340}
3341
Zhenyu Wange3421a12010-04-08 09:43:27 +08003342/* Gen6's DP voltage swing and pre-emphasis control */
3343static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003344gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003345{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003346 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3347 DP_TRAIN_PRE_EMPHASIS_MASK);
3348 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303349 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3350 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003351 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303352 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003353 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303354 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3355 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003356 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303357 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3358 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003359 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303360 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3361 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003362 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003363 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003364 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3365 "0x%x\n", signal_levels);
3366 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003367 }
3368}
3369
Keith Packard1a2eb462011-11-16 16:26:07 -08003370/* Gen7's DP voltage swing and pre-emphasis control */
3371static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003372gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003373{
3374 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3375 DP_TRAIN_PRE_EMPHASIS_MASK);
3376 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303377 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003378 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303379 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003380 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303381 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003382 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3383
Sonika Jindalbd600182014-08-08 16:23:41 +05303384 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003385 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303386 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003387 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3388
Sonika Jindalbd600182014-08-08 16:23:41 +05303389 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003390 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303391 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003392 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3393
3394 default:
3395 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3396 "0x%x\n", signal_levels);
3397 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3398 }
3399}
3400
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003401void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003402intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003403{
3404 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003405 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003406 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003407 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003408 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003409 uint8_t train_set = intel_dp->train_set[0];
3410
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003411 if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003412 signal_levels = ddi_signal_levels(intel_dp);
3413
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01003414 if (IS_BROXTON(dev_priv))
David Weinehallf8896f52015-06-25 11:11:03 +03003415 signal_levels = 0;
3416 else
3417 mask = DDI_BUF_EMP_MASK;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003418 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003419 signal_levels = chv_signal_levels(intel_dp);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003420 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003421 signal_levels = vlv_signal_levels(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003422 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003423 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003424 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003425 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003426 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003427 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3428 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003429 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003430 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3431 }
3432
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303433 if (mask)
3434 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3435
3436 DRM_DEBUG_KMS("Using vswing level %d\n",
3437 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3438 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3439 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3440 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003441
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003442 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003443
3444 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3445 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003446}
3447
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003448void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003449intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3450 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003451{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003452 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003453 struct drm_i915_private *dev_priv =
3454 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003455
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003456 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003457
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003458 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003459 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003460}
3461
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003462void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003463{
3464 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3465 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003466 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak3ab9c632013-05-03 12:57:41 +03003467 enum port port = intel_dig_port->port;
3468 uint32_t val;
3469
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003470 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003471 return;
3472
3473 val = I915_READ(DP_TP_CTL(port));
3474 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3475 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3476 I915_WRITE(DP_TP_CTL(port), val);
3477
3478 /*
3479 * On PORT_A we can have only eDP in SST mode. There the only reason
3480 * we need to set idle transmission mode is to work around a HW issue
3481 * where we enable the pipe while not in idle link-training mode.
3482 * In this case there is requirement to wait for a minimum number of
3483 * idle patterns to be sent.
3484 */
3485 if (port == PORT_A)
3486 return;
3487
Chris Wilsona7670172016-06-30 15:33:10 +01003488 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3489 DP_TP_STATUS_IDLE_DONE,
3490 DP_TP_STATUS_IDLE_DONE,
3491 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003492 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3493}
3494
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003495static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003496intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003497{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003498 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003499 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003500 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003501 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003502 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003503 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003504
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003505 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003506 return;
3507
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003508 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003509 return;
3510
Zhao Yakui28c97732009-10-09 11:39:41 +08003511 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003512
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003513 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003514 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003515 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003516 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003517 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003518 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003519 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3520 else
3521 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003522 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003523 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003524 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003525 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003526
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003527 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3528 I915_WRITE(intel_dp->output_reg, DP);
3529 POSTING_READ(intel_dp->output_reg);
3530
3531 /*
3532 * HW workaround for IBX, we need to move the port
3533 * to transcoder A after disabling it to allow the
3534 * matching HDMI port to be enabled on transcoder A.
3535 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003536 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003537 /*
3538 * We get CPU/PCH FIFO underruns on the other pipe when
3539 * doing the workaround. Sweep them under the rug.
3540 */
3541 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3542 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3543
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003544 /* always enable with pattern 1 (as per spec) */
3545 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3546 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3547 I915_WRITE(intel_dp->output_reg, DP);
3548 POSTING_READ(intel_dp->output_reg);
3549
3550 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003551 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003552 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003553
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003554 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003555 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3556 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003557 }
3558
Keith Packardf01eca22011-09-28 16:48:10 -07003559 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003560
3561 intel_dp->DP = DP;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003562
3563 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3564 pps_lock(intel_dp);
3565 intel_dp->active_pipe = INVALID_PIPE;
3566 pps_unlock(intel_dp);
3567 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003568}
3569
Imre Deak24e807e2016-10-24 19:33:28 +03003570bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003571intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003572{
Lyude9f085eb2016-04-13 10:58:33 -04003573 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3574 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003575 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003576
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003577 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003578
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003579 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3580}
3581
3582static bool
3583intel_edp_init_dpcd(struct intel_dp *intel_dp)
3584{
3585 struct drm_i915_private *dev_priv =
3586 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3587
3588 /* this function is meant to be called only once */
3589 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3590
3591 if (!intel_dp_read_dpcd(intel_dp))
3592 return false;
3593
Imre Deak12a47a422016-10-24 19:33:29 +03003594 intel_dp_read_desc(intel_dp);
3595
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003596 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3597 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3598 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3599
3600 /* Check if the panel supports PSR */
3601 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3602 intel_dp->psr_dpcd,
3603 sizeof(intel_dp->psr_dpcd));
3604 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3605 dev_priv->psr.sink_support = true;
3606 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3607 }
3608
3609 if (INTEL_GEN(dev_priv) >= 9 &&
3610 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3611 uint8_t frame_sync_cap;
3612
3613 dev_priv->psr.sink_support = true;
3614 drm_dp_dpcd_read(&intel_dp->aux,
3615 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3616 &frame_sync_cap, 1);
3617 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3618 /* PSR2 needs frame sync as well */
3619 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3620 DRM_DEBUG_KMS("PSR2 %s on sink",
3621 dev_priv->psr.psr2_support ? "supported" : "not supported");
3622 }
3623
3624 /* Read the eDP Display control capabilities registers */
3625 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
3626 drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003627 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3628 sizeof(intel_dp->edp_dpcd))
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003629 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3630 intel_dp->edp_dpcd);
3631
3632 /* Intermediate frequency support */
3633 if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */
3634 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3635 int i;
3636
3637 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3638 sink_rates, sizeof(sink_rates));
3639
3640 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3641 int val = le16_to_cpu(sink_rates[i]);
3642
3643 if (val == 0)
3644 break;
3645
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -08003646 /* Value read multiplied by 200kHz gives the per-lane
3647 * link rate in kHz. The source rates are, however,
3648 * stored in terms of LS_Clk kHz. The full conversion
3649 * back to symbols is
3650 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
3651 */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003652 intel_dp->sink_rates[i] = (val * 200) / 10;
3653 }
3654 intel_dp->num_sink_rates = i;
3655 }
3656
3657 return true;
3658}
3659
3660
3661static bool
3662intel_dp_get_dpcd(struct intel_dp *intel_dp)
3663{
3664 if (!intel_dp_read_dpcd(intel_dp))
3665 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003666
Lyude9f085eb2016-04-13 10:58:33 -04003667 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT,
3668 &intel_dp->sink_count, 1) < 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303669 return false;
3670
3671 /*
3672 * Sink count can change between short pulse hpd hence
3673 * a member variable in intel_dp will track any changes
3674 * between short pulse interrupts.
3675 */
3676 intel_dp->sink_count = DP_GET_SINK_COUNT(intel_dp->sink_count);
3677
3678 /*
3679 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3680 * a dongle is present but no display. Unless we require to know
3681 * if a dongle is present or not, we don't need to update
3682 * downstream port information. So, an early return here saves
3683 * time from performing other operations which are not required.
3684 */
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05303685 if (!is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303686 return false;
3687
Imre Deakc726ad02016-10-24 19:33:24 +03003688 if (!drm_dp_is_branch(intel_dp->dpcd))
Adam Jacksonedb39242012-09-18 10:58:49 -04003689 return true; /* native DP sink */
3690
3691 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3692 return true; /* no per-port downstream info */
3693
Lyude9f085eb2016-04-13 10:58:33 -04003694 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3695 intel_dp->downstream_ports,
3696 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003697 return false; /* downstream port status fetch failed */
3698
3699 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003700}
3701
Dave Airlie0e32b392014-05-02 14:02:48 +10003702static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003703intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003704{
3705 u8 buf[1];
3706
Nathan Schulte7cc96132016-03-15 10:14:05 -05003707 if (!i915.enable_dp_mst)
3708 return false;
3709
Dave Airlie0e32b392014-05-02 14:02:48 +10003710 if (!intel_dp->can_mst)
3711 return false;
3712
3713 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3714 return false;
3715
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003716 if (drm_dp_dpcd_read(&intel_dp->aux, DP_MSTM_CAP, buf, 1) != 1)
3717 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003718
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003719 return buf[0] & DP_MST_CAP;
3720}
3721
3722static void
3723intel_dp_configure_mst(struct intel_dp *intel_dp)
3724{
3725 if (!i915.enable_dp_mst)
3726 return;
3727
3728 if (!intel_dp->can_mst)
3729 return;
3730
3731 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3732
3733 if (intel_dp->is_mst)
3734 DRM_DEBUG_KMS("Sink is MST capable\n");
3735 else
3736 DRM_DEBUG_KMS("Sink is not MST capable\n");
3737
3738 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3739 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003740}
3741
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003742static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003743{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003744 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003745 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003746 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003747 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003748 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003749 int count = 0;
3750 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003751
3752 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003753 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003754 ret = -EIO;
3755 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003756 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003757
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003758 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003759 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003760 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003761 ret = -EIO;
3762 goto out;
3763 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003764
Rodrigo Vivic6297842015-11-05 10:50:20 -08003765 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003766 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivic6297842015-11-05 10:50:20 -08003767
3768 if (drm_dp_dpcd_readb(&intel_dp->aux,
3769 DP_TEST_SINK_MISC, &buf) < 0) {
3770 ret = -EIO;
3771 goto out;
3772 }
3773 count = buf & DP_TEST_COUNT_MASK;
3774 } while (--attempts && count);
3775
3776 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003777 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003778 ret = -ETIMEDOUT;
3779 }
3780
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003781 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003782 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003783 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003784}
3785
3786static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3787{
3788 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003789 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003790 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3791 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003792 int ret;
3793
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003794 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3795 return -EIO;
3796
3797 if (!(buf & DP_TEST_CRC_SUPPORTED))
3798 return -ENOTTY;
3799
3800 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3801 return -EIO;
3802
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003803 if (buf & DP_TEST_SINK_START) {
3804 ret = intel_dp_sink_crc_stop(intel_dp);
3805 if (ret)
3806 return ret;
3807 }
3808
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003809 hsw_disable_ips(intel_crtc);
3810
3811 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3812 buf | DP_TEST_SINK_START) < 0) {
3813 hsw_enable_ips(intel_crtc);
3814 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003815 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003816
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003817 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003818 return 0;
3819}
3820
3821int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3822{
3823 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003824 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003825 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3826 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003827 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003828 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003829
3830 ret = intel_dp_sink_crc_start(intel_dp);
3831 if (ret)
3832 return ret;
3833
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003834 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003835 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003836
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003837 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003838 DP_TEST_SINK_MISC, &buf) < 0) {
3839 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003840 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003841 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003842 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07003843
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003844 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003845
3846 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003847 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
3848 ret = -ETIMEDOUT;
3849 goto stop;
3850 }
3851
3852 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
3853 ret = -EIO;
3854 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003855 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003856
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003857stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003858 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003859 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003860}
3861
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003862static bool
3863intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3864{
Lyude9f085eb2016-04-13 10:58:33 -04003865 return drm_dp_dpcd_read(&intel_dp->aux,
Jani Nikula9d1a1032014-03-14 16:51:15 +02003866 DP_DEVICE_SERVICE_IRQ_VECTOR,
3867 sink_irq_vector, 1) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003868}
3869
Dave Airlie0e32b392014-05-02 14:02:48 +10003870static bool
3871intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3872{
3873 int ret;
3874
Lyude9f085eb2016-04-13 10:58:33 -04003875 ret = drm_dp_dpcd_read(&intel_dp->aux,
Dave Airlie0e32b392014-05-02 14:02:48 +10003876 DP_SINK_COUNT_ESI,
3877 sink_irq_vector, 14);
3878 if (ret != 14)
3879 return false;
3880
3881 return true;
3882}
3883
Todd Previtec5d5ab72015-04-15 08:38:38 -07003884static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003885{
Todd Previtec5d5ab72015-04-15 08:38:38 -07003886 uint8_t test_result = DP_TEST_ACK;
3887 return test_result;
3888}
3889
3890static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
3891{
3892 uint8_t test_result = DP_TEST_NAK;
3893 return test_result;
3894}
3895
3896static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
3897{
3898 uint8_t test_result = DP_TEST_NAK;
Todd Previte559be302015-05-04 07:48:20 -07003899 struct intel_connector *intel_connector = intel_dp->attached_connector;
3900 struct drm_connector *connector = &intel_connector->base;
3901
3902 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02003903 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07003904 intel_dp->aux.i2c_defer_count > 6) {
3905 /* Check EDID read for NACKs, DEFERs and corruption
3906 * (DP CTS 1.2 Core r1.1)
3907 * 4.2.2.4 : Failed EDID read, I2C_NAK
3908 * 4.2.2.5 : Failed EDID read, I2C_DEFER
3909 * 4.2.2.6 : EDID corruption detected
3910 * Use failsafe mode for all cases
3911 */
3912 if (intel_dp->aux.i2c_nack_count > 0 ||
3913 intel_dp->aux.i2c_defer_count > 0)
3914 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
3915 intel_dp->aux.i2c_nack_count,
3916 intel_dp->aux.i2c_defer_count);
Manasi Navarec1617ab2016-12-09 16:22:50 -08003917 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
Todd Previte559be302015-05-04 07:48:20 -07003918 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05303919 struct edid *block = intel_connector->detect_edid;
3920
3921 /* We have to write the checksum
3922 * of the last block read
3923 */
3924 block += intel_connector->detect_edid->extensions;
3925
Todd Previte559be302015-05-04 07:48:20 -07003926 if (!drm_dp_dpcd_write(&intel_dp->aux,
3927 DP_TEST_EDID_CHECKSUM,
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05303928 &block->checksum,
Dan Carpenter5a1cc652015-05-12 21:07:37 +03003929 1))
Todd Previte559be302015-05-04 07:48:20 -07003930 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
3931
3932 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
Manasi Navarec1617ab2016-12-09 16:22:50 -08003933 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_STANDARD;
Todd Previte559be302015-05-04 07:48:20 -07003934 }
3935
3936 /* Set test active flag here so userspace doesn't interrupt things */
Manasi Navarec1617ab2016-12-09 16:22:50 -08003937 intel_dp->compliance.test_active = 1;
Todd Previte559be302015-05-04 07:48:20 -07003938
Todd Previtec5d5ab72015-04-15 08:38:38 -07003939 return test_result;
3940}
3941
3942static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
3943{
3944 uint8_t test_result = DP_TEST_NAK;
3945 return test_result;
3946}
3947
3948static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
3949{
3950 uint8_t response = DP_TEST_NAK;
3951 uint8_t rxdata = 0;
3952 int status = 0;
3953
Todd Previtec5d5ab72015-04-15 08:38:38 -07003954 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_REQUEST, &rxdata, 1);
3955 if (status <= 0) {
3956 DRM_DEBUG_KMS("Could not read test request from sink\n");
3957 goto update_status;
3958 }
3959
3960 switch (rxdata) {
3961 case DP_TEST_LINK_TRAINING:
3962 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
Manasi Navarec1617ab2016-12-09 16:22:50 -08003963 intel_dp->compliance.test_type = DP_TEST_LINK_TRAINING;
Todd Previtec5d5ab72015-04-15 08:38:38 -07003964 response = intel_dp_autotest_link_training(intel_dp);
3965 break;
3966 case DP_TEST_LINK_VIDEO_PATTERN:
3967 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
Manasi Navarec1617ab2016-12-09 16:22:50 -08003968 intel_dp->compliance.test_type = DP_TEST_LINK_VIDEO_PATTERN;
Todd Previtec5d5ab72015-04-15 08:38:38 -07003969 response = intel_dp_autotest_video_pattern(intel_dp);
3970 break;
3971 case DP_TEST_LINK_EDID_READ:
3972 DRM_DEBUG_KMS("EDID test requested\n");
Manasi Navarec1617ab2016-12-09 16:22:50 -08003973 intel_dp->compliance.test_type = DP_TEST_LINK_EDID_READ;
Todd Previtec5d5ab72015-04-15 08:38:38 -07003974 response = intel_dp_autotest_edid(intel_dp);
3975 break;
3976 case DP_TEST_LINK_PHY_TEST_PATTERN:
3977 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
Manasi Navarec1617ab2016-12-09 16:22:50 -08003978 intel_dp->compliance.test_type = DP_TEST_LINK_PHY_TEST_PATTERN;
Todd Previtec5d5ab72015-04-15 08:38:38 -07003979 response = intel_dp_autotest_phy_pattern(intel_dp);
3980 break;
3981 default:
3982 DRM_DEBUG_KMS("Invalid test request '%02x'\n", rxdata);
3983 break;
3984 }
3985
3986update_status:
3987 status = drm_dp_dpcd_write(&intel_dp->aux,
3988 DP_TEST_RESPONSE,
3989 &response, 1);
3990 if (status <= 0)
3991 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003992}
3993
Dave Airlie0e32b392014-05-02 14:02:48 +10003994static int
3995intel_dp_check_mst_status(struct intel_dp *intel_dp)
3996{
3997 bool bret;
3998
3999 if (intel_dp->is_mst) {
4000 u8 esi[16] = { 0 };
4001 int ret = 0;
4002 int retry;
4003 bool handled;
4004 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4005go_again:
4006 if (bret == true) {
4007
4008 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03004009 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03004010 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10004011 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4012 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004013 intel_dp_stop_link_train(intel_dp);
4014 }
4015
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004016 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004017 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4018
4019 if (handled) {
4020 for (retry = 0; retry < 3; retry++) {
4021 int wret;
4022 wret = drm_dp_dpcd_write(&intel_dp->aux,
4023 DP_SINK_COUNT_ESI+1,
4024 &esi[1], 3);
4025 if (wret == 3) {
4026 break;
4027 }
4028 }
4029
4030 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4031 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004032 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004033 goto go_again;
4034 }
4035 } else
4036 ret = 0;
4037
4038 return ret;
4039 } else {
4040 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4041 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4042 intel_dp->is_mst = false;
4043 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4044 /* send a hotplug event */
4045 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4046 }
4047 }
4048 return -EINVAL;
4049}
4050
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304051static void
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004052intel_dp_retrain_link(struct intel_dp *intel_dp)
4053{
4054 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4055 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4056 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
4057
4058 /* Suppress underruns caused by re-training */
4059 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4060 if (crtc->config->has_pch_encoder)
4061 intel_set_pch_fifo_underrun_reporting(dev_priv,
4062 intel_crtc_pch_transcoder(crtc), false);
4063
4064 intel_dp_start_link_train(intel_dp);
4065 intel_dp_stop_link_train(intel_dp);
4066
4067 /* Keep underrun reporting disabled until things are stable */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02004068 intel_wait_for_vblank(dev_priv, crtc->pipe);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004069
4070 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4071 if (crtc->config->has_pch_encoder)
4072 intel_set_pch_fifo_underrun_reporting(dev_priv,
4073 intel_crtc_pch_transcoder(crtc), true);
4074}
4075
4076static void
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304077intel_dp_check_link_status(struct intel_dp *intel_dp)
4078{
4079 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4080 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4081 u8 link_status[DP_LINK_STATUS_SIZE];
4082
4083 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
4084
4085 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4086 DRM_ERROR("Failed to get link status\n");
4087 return;
4088 }
4089
4090 if (!intel_encoder->base.crtc)
4091 return;
4092
4093 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4094 return;
4095
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004096 /* FIXME: we need to synchronize this sort of stuff with hardware
Daniel Vetter2dd85ae2016-12-13 20:54:14 +01004097 * readout. Currently fast link training doesn't work on boot-up. */
4098 if (!intel_dp->lane_count)
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004099 return;
4100
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304101 /* if link training is requested we should perform it always */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004102 if ((intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) ||
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304103 (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count))) {
4104 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4105 intel_encoder->base.name);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004106
4107 intel_dp_retrain_link(intel_dp);
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304108 }
4109}
4110
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004111/*
4112 * According to DP spec
4113 * 5.1.2:
4114 * 1. Read DPCD
4115 * 2. Configure link according to Receiver Capabilities
4116 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4117 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304118 *
4119 * intel_dp_short_pulse - handles short pulse interrupts
4120 * when full detection is not required.
4121 * Returns %true if short pulse is handled and full detection
4122 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004123 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304124static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304125intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004126{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004127 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004128 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304129 u8 old_sink_count = intel_dp->sink_count;
4130 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004131
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304132 /*
4133 * Clearing compliance test variables to allow capturing
4134 * of values for next automated test request.
4135 */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004136 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304137
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304138 /*
4139 * Now read the DPCD to see if it's actually running
4140 * If the current value of sink count doesn't match with
4141 * the value that was stored earlier or dpcd read failed
4142 * we need to do full detection
4143 */
4144 ret = intel_dp_get_dpcd(intel_dp);
4145
4146 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4147 /* No need to proceed if we are going to do full detect */
4148 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004149 }
4150
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004151 /* Try to read the source of the interrupt */
4152 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004153 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4154 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004155 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004156 drm_dp_dpcd_writeb(&intel_dp->aux,
4157 DP_DEVICE_SERVICE_IRQ_VECTOR,
4158 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004159
4160 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Todd Previte09b1eb12015-04-20 15:27:34 -07004161 DRM_DEBUG_DRIVER("Test request in short pulse not handled\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004162 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4163 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4164 }
4165
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304166 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4167 intel_dp_check_link_status(intel_dp);
4168 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304169
4170 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004171}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004172
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004173/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004174static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004175intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004176{
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004177 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004178 uint8_t type;
4179
4180 if (!intel_dp_get_dpcd(intel_dp))
4181 return connector_status_disconnected;
4182
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304183 if (is_edp(intel_dp))
4184 return connector_status_connected;
4185
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004186 /* if there's no downstream port, we're done */
Imre Deakc726ad02016-10-24 19:33:24 +03004187 if (!drm_dp_is_branch(dpcd))
Keith Packard26d61aa2011-07-25 20:01:09 -07004188 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004189
4190 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004191 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4192 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004193
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304194 return intel_dp->sink_count ?
4195 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004196 }
4197
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004198 if (intel_dp_can_mst(intel_dp))
4199 return connector_status_connected;
4200
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004201 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004202 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004203 return connector_status_connected;
4204
4205 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004206 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4207 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4208 if (type == DP_DS_PORT_TYPE_VGA ||
4209 type == DP_DS_PORT_TYPE_NON_EDID)
4210 return connector_status_unknown;
4211 } else {
4212 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4213 DP_DWN_STRM_PORT_TYPE_MASK;
4214 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4215 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4216 return connector_status_unknown;
4217 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004218
4219 /* Anything else is out of spec, warn and ignore */
4220 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004221 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004222}
4223
4224static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004225edp_detect(struct intel_dp *intel_dp)
4226{
4227 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Mika Kahola1650be72016-12-13 10:02:47 +02004228 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsond410b562014-09-02 20:03:59 +01004229 enum drm_connector_status status;
4230
Mika Kahola1650be72016-12-13 10:02:47 +02004231 status = intel_panel_detect(dev_priv);
Chris Wilsond410b562014-09-02 20:03:59 +01004232 if (status == connector_status_unknown)
4233 status = connector_status_connected;
4234
4235 return status;
4236}
4237
Jani Nikulab93433c2015-08-20 10:47:36 +03004238static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4239 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004240{
Jani Nikulab93433c2015-08-20 10:47:36 +03004241 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004242
Jani Nikula0df53b72015-08-20 10:47:40 +03004243 switch (port->port) {
4244 case PORT_A:
4245 return true;
4246 case PORT_B:
4247 bit = SDE_PORTB_HOTPLUG;
4248 break;
4249 case PORT_C:
4250 bit = SDE_PORTC_HOTPLUG;
4251 break;
4252 case PORT_D:
4253 bit = SDE_PORTD_HOTPLUG;
4254 break;
4255 default:
4256 MISSING_CASE(port->port);
4257 return false;
4258 }
4259
4260 return I915_READ(SDEISR) & bit;
4261}
4262
4263static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4264 struct intel_digital_port *port)
4265{
4266 u32 bit;
4267
4268 switch (port->port) {
4269 case PORT_A:
4270 return true;
4271 case PORT_B:
4272 bit = SDE_PORTB_HOTPLUG_CPT;
4273 break;
4274 case PORT_C:
4275 bit = SDE_PORTC_HOTPLUG_CPT;
4276 break;
4277 case PORT_D:
4278 bit = SDE_PORTD_HOTPLUG_CPT;
4279 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004280 case PORT_E:
4281 bit = SDE_PORTE_HOTPLUG_SPT;
4282 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004283 default:
4284 MISSING_CASE(port->port);
4285 return false;
Jani Nikulab93433c2015-08-20 10:47:36 +03004286 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004287
Jani Nikulab93433c2015-08-20 10:47:36 +03004288 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004289}
4290
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004291static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004292 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004293{
Jani Nikula9642c812015-08-20 10:47:41 +03004294 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004295
Jani Nikula9642c812015-08-20 10:47:41 +03004296 switch (port->port) {
4297 case PORT_B:
4298 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4299 break;
4300 case PORT_C:
4301 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4302 break;
4303 case PORT_D:
4304 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4305 break;
4306 default:
4307 MISSING_CASE(port->port);
4308 return false;
4309 }
4310
4311 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4312}
4313
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004314static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4315 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004316{
4317 u32 bit;
4318
4319 switch (port->port) {
4320 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004321 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004322 break;
4323 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004324 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004325 break;
4326 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004327 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004328 break;
4329 default:
4330 MISSING_CASE(port->port);
4331 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004332 }
4333
Jani Nikula1d245982015-08-20 10:47:37 +03004334 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004335}
4336
Jani Nikulae464bfd2015-08-20 10:47:42 +03004337static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304338 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004339{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304340 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4341 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004342 u32 bit;
4343
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304344 intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port);
4345 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004346 case PORT_A:
4347 bit = BXT_DE_PORT_HP_DDIA;
4348 break;
4349 case PORT_B:
4350 bit = BXT_DE_PORT_HP_DDIB;
4351 break;
4352 case PORT_C:
4353 bit = BXT_DE_PORT_HP_DDIC;
4354 break;
4355 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304356 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004357 return false;
4358 }
4359
4360 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4361}
4362
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004363/*
4364 * intel_digital_port_connected - is the specified port connected?
4365 * @dev_priv: i915 private structure
4366 * @port: the port to test
4367 *
4368 * Return %true if @port is connected, %false otherwise.
4369 */
David Weinehall23f889b2016-08-17 15:47:48 +03004370static bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004371 struct intel_digital_port *port)
4372{
Jani Nikula0df53b72015-08-20 10:47:40 +03004373 if (HAS_PCH_IBX(dev_priv))
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004374 return ibx_digital_port_connected(dev_priv, port);
Ville Syrjälä22824fa2016-02-11 16:44:28 +02004375 else if (HAS_PCH_SPLIT(dev_priv))
Jani Nikula0df53b72015-08-20 10:47:40 +03004376 return cpt_digital_port_connected(dev_priv, port);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004377 else if (IS_GEN9_LP(dev_priv))
Jani Nikulae464bfd2015-08-20 10:47:42 +03004378 return bxt_digital_port_connected(dev_priv, port);
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004379 else if (IS_GM45(dev_priv))
4380 return gm45_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004381 else
4382 return g4x_digital_port_connected(dev_priv, port);
4383}
4384
Keith Packard8c241fe2011-09-28 16:38:44 -07004385static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004386intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004387{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004388 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004389
Jani Nikula9cd300e2012-10-19 14:51:52 +03004390 /* use cached edid if we have one */
4391 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004392 /* invalid edid */
4393 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004394 return NULL;
4395
Jani Nikula55e9ede2013-10-01 10:38:54 +03004396 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004397 } else
4398 return drm_get_edid(&intel_connector->base,
4399 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004400}
4401
Chris Wilsonbeb60602014-09-02 20:04:00 +01004402static void
4403intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004404{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004405 struct intel_connector *intel_connector = intel_dp->attached_connector;
4406 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004407
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304408 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004409 edid = intel_dp_get_edid(intel_dp);
4410 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004411
Chris Wilsonbeb60602014-09-02 20:04:00 +01004412 if (intel_dp->force_audio != HDMI_AUDIO_AUTO)
4413 intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON;
4414 else
4415 intel_dp->has_audio = drm_detect_monitor_audio(edid);
4416}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004417
Chris Wilsonbeb60602014-09-02 20:04:00 +01004418static void
4419intel_dp_unset_edid(struct intel_dp *intel_dp)
4420{
4421 struct intel_connector *intel_connector = intel_dp->attached_connector;
4422
4423 kfree(intel_connector->detect_edid);
4424 intel_connector->detect_edid = NULL;
4425
4426 intel_dp->has_audio = false;
4427}
4428
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004429static enum drm_connector_status
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304430intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004431{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304432 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004433 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004434 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4435 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004436 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004437 enum drm_connector_status status;
Imre Deak671dedd2014-03-05 16:20:53 +02004438 enum intel_display_power_domain power_domain;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004439 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004440
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004441 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4442 intel_display_power_get(to_i915(dev), power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004443
Chris Wilsond410b562014-09-02 20:03:59 +01004444 /* Can't disconnect eDP, but you can close the lid... */
4445 if (is_edp(intel_dp))
4446 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004447 else if (intel_digital_port_connected(to_i915(dev),
4448 dp_to_dig_port(intel_dp)))
4449 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004450 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004451 status = connector_status_disconnected;
4452
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004453 if (status == connector_status_disconnected) {
Manasi Navarec1617ab2016-12-09 16:22:50 -08004454 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304455
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004456 if (intel_dp->is_mst) {
4457 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4458 intel_dp->is_mst,
4459 intel_dp->mst_mgr.mst_state);
4460 intel_dp->is_mst = false;
4461 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4462 intel_dp->is_mst);
4463 }
4464
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004465 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304466 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004467
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304468 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004469 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304470
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004471 DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
4472 yesno(intel_dp_source_supports_hbr2(intel_dp)),
4473 yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
4474
Manasi Navaref4829842016-12-05 16:27:36 -08004475 /* Set the max lane count for sink */
4476 intel_dp->max_sink_lane_count = drm_dp_max_lane_count(intel_dp->dpcd);
4477
4478 /* Set the max link BW for sink */
4479 intel_dp->max_sink_link_bw = intel_dp_max_link_bw(intel_dp);
4480
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004481 intel_dp_print_rates(intel_dp);
4482
Imre Deak7b3fc172016-10-25 16:12:39 +03004483 intel_dp_read_desc(intel_dp);
Mika Kahola0e390a32016-09-09 14:10:53 +03004484
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004485 intel_dp_configure_mst(intel_dp);
4486
4487 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304488 /*
4489 * If we are in MST mode then this connector
4490 * won't appear connected or have anything
4491 * with EDID on it
4492 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004493 status = connector_status_disconnected;
4494 goto out;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304495 } else if (connector->status == connector_status_connected) {
4496 /*
4497 * If display was connected already and is still connected
4498 * check links status, there has been known issues of
4499 * link loss triggerring long pulse!!!!
4500 */
4501 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4502 intel_dp_check_link_status(intel_dp);
4503 drm_modeset_unlock(&dev->mode_config.connection_mutex);
4504 goto out;
Dave Airlie0e32b392014-05-02 14:02:48 +10004505 }
4506
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304507 /*
4508 * Clearing NACK and defer counts to get their exact values
4509 * while reading EDID which are required by Compliance tests
4510 * 4.2.2.4 and 4.2.2.5
4511 */
4512 intel_dp->aux.i2c_nack_count = 0;
4513 intel_dp->aux.i2c_defer_count = 0;
4514
Chris Wilsonbeb60602014-09-02 20:04:00 +01004515 intel_dp_set_edid(intel_dp);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004516 if (is_edp(intel_dp) || intel_connector->detect_edid)
4517 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304518 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004519
Todd Previte09b1eb12015-04-20 15:27:34 -07004520 /* Try to read the source of the interrupt */
4521 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004522 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4523 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004524 /* Clear interrupt source */
4525 drm_dp_dpcd_writeb(&intel_dp->aux,
4526 DP_DEVICE_SERVICE_IRQ_VECTOR,
4527 sink_irq_vector);
4528
4529 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4530 intel_dp_handle_test_request(intel_dp);
4531 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4532 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4533 }
4534
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004535out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004536 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304537 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304538
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004539 intel_display_power_put(to_i915(dev), power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004540 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304541}
4542
4543static enum drm_connector_status
4544intel_dp_detect(struct drm_connector *connector, bool force)
4545{
4546 struct intel_dp *intel_dp = intel_attached_dp(connector);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004547 enum drm_connector_status status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304548
4549 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4550 connector->base.id, connector->name);
4551
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304552 /* If full detect is not performed yet, do a full detect */
4553 if (!intel_dp->detect_done)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004554 status = intel_dp_long_pulse(intel_dp->attached_connector);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304555
4556 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304557
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004558 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004559}
4560
Chris Wilsonbeb60602014-09-02 20:04:00 +01004561static void
4562intel_dp_force(struct drm_connector *connector)
4563{
4564 struct intel_dp *intel_dp = intel_attached_dp(connector);
4565 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004566 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004567 enum intel_display_power_domain power_domain;
4568
4569 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4570 connector->base.id, connector->name);
4571 intel_dp_unset_edid(intel_dp);
4572
4573 if (connector->status != connector_status_connected)
4574 return;
4575
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004576 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4577 intel_display_power_get(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004578
4579 intel_dp_set_edid(intel_dp);
4580
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004581 intel_display_power_put(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004582
4583 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004584 intel_encoder->type = INTEL_OUTPUT_DP;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004585}
4586
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004587static int intel_dp_get_modes(struct drm_connector *connector)
4588{
Jani Nikuladd06f902012-10-19 14:51:50 +03004589 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004590 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004591
Chris Wilsonbeb60602014-09-02 20:04:00 +01004592 edid = intel_connector->detect_edid;
4593 if (edid) {
4594 int ret = intel_connector_update_modes(connector, edid);
4595 if (ret)
4596 return ret;
4597 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004598
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004599 /* if eDP has no EDID, fall back to fixed mode */
Chris Wilsonbeb60602014-09-02 20:04:00 +01004600 if (is_edp(intel_attached_dp(connector)) &&
4601 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004602 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004603
4604 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004605 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004606 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004607 drm_mode_probed_add(connector, mode);
4608 return 1;
4609 }
4610 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004611
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004612 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004613}
4614
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004615static bool
4616intel_dp_detect_audio(struct drm_connector *connector)
4617{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004618 bool has_audio = false;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004619 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004620
Chris Wilsonbeb60602014-09-02 20:04:00 +01004621 edid = to_intel_connector(connector)->detect_edid;
4622 if (edid)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004623 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02004624
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004625 return has_audio;
4626}
4627
Chris Wilsonf6849602010-09-19 09:29:33 +01004628static int
4629intel_dp_set_property(struct drm_connector *connector,
4630 struct drm_property *property,
4631 uint64_t val)
4632{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004633 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Yuly Novikov53b41832012-10-26 12:04:00 +03004634 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004635 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
4636 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01004637 int ret;
4638
Rob Clark662595d2012-10-11 20:36:04 -05004639 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01004640 if (ret)
4641 return ret;
4642
Chris Wilson3f43c482011-05-12 22:17:24 +01004643 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004644 int i = val;
4645 bool has_audio;
4646
4647 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004648 return 0;
4649
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004650 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01004651
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004652 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004653 has_audio = intel_dp_detect_audio(connector);
4654 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004655 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004656
4657 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004658 return 0;
4659
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004660 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01004661 goto done;
4662 }
4663
Chris Wilsone953fd72011-02-21 22:23:52 +00004664 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02004665 bool old_auto = intel_dp->color_range_auto;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004666 bool old_range = intel_dp->limited_color_range;
Daniel Vetterae4edb82013-04-22 17:07:23 +02004667
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004668 switch (val) {
4669 case INTEL_BROADCAST_RGB_AUTO:
4670 intel_dp->color_range_auto = true;
4671 break;
4672 case INTEL_BROADCAST_RGB_FULL:
4673 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004674 intel_dp->limited_color_range = false;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004675 break;
4676 case INTEL_BROADCAST_RGB_LIMITED:
4677 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004678 intel_dp->limited_color_range = true;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004679 break;
4680 default:
4681 return -EINVAL;
4682 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02004683
4684 if (old_auto == intel_dp->color_range_auto &&
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004685 old_range == intel_dp->limited_color_range)
Daniel Vetterae4edb82013-04-22 17:07:23 +02004686 return 0;
4687
Chris Wilsone953fd72011-02-21 22:23:52 +00004688 goto done;
4689 }
4690
Yuly Novikov53b41832012-10-26 12:04:00 +03004691 if (is_edp(intel_dp) &&
4692 property == connector->dev->mode_config.scaling_mode_property) {
4693 if (val == DRM_MODE_SCALE_NONE) {
4694 DRM_DEBUG_KMS("no scaling not supported\n");
4695 return -EINVAL;
4696 }
Ville Syrjälä234126c2016-04-12 22:14:38 +03004697 if (HAS_GMCH_DISPLAY(dev_priv) &&
4698 val == DRM_MODE_SCALE_CENTER) {
4699 DRM_DEBUG_KMS("centering not supported\n");
4700 return -EINVAL;
4701 }
Yuly Novikov53b41832012-10-26 12:04:00 +03004702
4703 if (intel_connector->panel.fitting_mode == val) {
4704 /* the eDP scaling property is not changed */
4705 return 0;
4706 }
4707 intel_connector->panel.fitting_mode = val;
4708
4709 goto done;
4710 }
4711
Chris Wilsonf6849602010-09-19 09:29:33 +01004712 return -EINVAL;
4713
4714done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00004715 if (intel_encoder->base.crtc)
4716 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01004717
4718 return 0;
4719}
4720
Chris Wilson7a418e32016-06-24 14:00:14 +01004721static int
4722intel_dp_connector_register(struct drm_connector *connector)
4723{
4724 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004725 int ret;
4726
4727 ret = intel_connector_register(connector);
4728 if (ret)
4729 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004730
4731 i915_debugfs_connector_add(connector);
4732
4733 DRM_DEBUG_KMS("registering %s bus for %s\n",
4734 intel_dp->aux.name, connector->kdev->kobj.name);
4735
4736 intel_dp->aux.dev = connector->kdev;
4737 return drm_dp_aux_register(&intel_dp->aux);
4738}
4739
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004740static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004741intel_dp_connector_unregister(struct drm_connector *connector)
4742{
4743 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4744 intel_connector_unregister(connector);
4745}
4746
4747static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004748intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004749{
Jani Nikula1d508702012-10-19 14:51:49 +03004750 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004751
Chris Wilson10e972d2014-09-04 21:43:45 +01004752 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004753
Jani Nikula9cd300e2012-10-19 14:51:52 +03004754 if (!IS_ERR_OR_NULL(intel_connector->edid))
4755 kfree(intel_connector->edid);
4756
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004757 /* Can't call is_edp() since the encoder may have been destroyed
4758 * already. */
4759 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004760 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004761
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004762 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004763 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004764}
4765
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004766void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004767{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004768 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4769 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004770
Dave Airlie0e32b392014-05-02 14:02:48 +10004771 intel_dp_mst_encoder_cleanup(intel_dig_port);
Keith Packardbd943152011-09-18 23:09:52 -07004772 if (is_edp(intel_dp)) {
4773 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004774 /*
4775 * vdd might still be enabled do to the delayed vdd off.
4776 * Make sure vdd is actually turned off here.
4777 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004778 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004779 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004780 pps_unlock(intel_dp);
4781
Clint Taylor01527b32014-07-07 13:01:46 -07004782 if (intel_dp->edp_notifier.notifier_call) {
4783 unregister_reboot_notifier(&intel_dp->edp_notifier);
4784 intel_dp->edp_notifier.notifier_call = NULL;
4785 }
Keith Packardbd943152011-09-18 23:09:52 -07004786 }
Chris Wilson99681882016-06-20 09:29:17 +01004787
4788 intel_dp_aux_fini(intel_dp);
4789
Imre Deakc8bd0e42014-12-12 17:57:38 +02004790 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004791 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004792}
4793
Imre Deakbf93ba62016-04-18 10:04:21 +03004794void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004795{
4796 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4797
4798 if (!is_edp(intel_dp))
4799 return;
4800
Ville Syrjälä951468f2014-09-04 14:55:31 +03004801 /*
4802 * vdd might still be enabled do to the delayed vdd off.
4803 * Make sure vdd is actually turned off here.
4804 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004805 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004806 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004807 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004808 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004809}
4810
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004811static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4812{
4813 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4814 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004815 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004816 enum intel_display_power_domain power_domain;
4817
4818 lockdep_assert_held(&dev_priv->pps_mutex);
4819
4820 if (!edp_have_panel_vdd(intel_dp))
4821 return;
4822
4823 /*
4824 * The VDD bit needs a power domain reference, so if the bit is
4825 * already enabled when we boot or resume, grab this reference and
4826 * schedule a vdd off, so we don't hold on to the reference
4827 * indefinitely.
4828 */
4829 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004830 power_domain = intel_display_port_aux_power_domain(&intel_dig_port->base);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004831 intel_display_power_get(dev_priv, power_domain);
4832
4833 edp_panel_vdd_schedule_off(intel_dp);
4834}
4835
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02004836static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
4837{
4838 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
4839
4840 if ((intel_dp->DP & DP_PORT_EN) == 0)
4841 return INVALID_PIPE;
4842
4843 if (IS_CHERRYVIEW(dev_priv))
4844 return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
4845 else
4846 return PORT_TO_PIPE(intel_dp->DP);
4847}
4848
Imre Deakbf93ba62016-04-18 10:04:21 +03004849void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03004850{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03004851 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Imre Deakdd75f6d2016-11-21 21:15:05 +02004852 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
4853 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Ville Syrjälä64989ca42016-05-13 20:53:56 +03004854
4855 if (!HAS_DDI(dev_priv))
4856 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004857
Imre Deakdd75f6d2016-11-21 21:15:05 +02004858 if (lspcon->active)
Shashank Sharma910530c2016-10-14 19:56:52 +05304859 lspcon_resume(lspcon);
4860
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004861 pps_lock(intel_dp);
4862
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02004863 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4864 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
4865
4866 if (is_edp(intel_dp)) {
4867 /* Reinit the power sequencer, in case BIOS did something with it. */
4868 intel_dp_pps_init(encoder->dev, intel_dp);
4869 intel_edp_panel_vdd_sanitize(intel_dp);
4870 }
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004871
4872 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03004873}
4874
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004875static const struct drm_connector_funcs intel_dp_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02004876 .dpms = drm_atomic_helper_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004877 .detect = intel_dp_detect,
Chris Wilsonbeb60602014-09-02 20:04:00 +01004878 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004879 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01004880 .set_property = intel_dp_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -08004881 .atomic_get_property = intel_connector_atomic_get_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01004882 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01004883 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004884 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08004885 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02004886 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004887};
4888
4889static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
4890 .get_modes = intel_dp_get_modes,
4891 .mode_valid = intel_dp_mode_valid,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004892};
4893
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004894static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03004895 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02004896 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004897};
4898
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004899enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10004900intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
4901{
4902 struct intel_dp *intel_dp = &intel_dig_port->dp;
Imre Deak1c767b32014-08-18 14:42:42 +03004903 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Dave Airlie0e32b392014-05-02 14:02:48 +10004904 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004905 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak1c767b32014-08-18 14:42:42 +03004906 enum intel_display_power_domain power_domain;
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004907 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03004908
Takashi Iwai25400582015-11-19 12:09:56 +01004909 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
4910 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004911 intel_dig_port->base.type = INTEL_OUTPUT_DP;
Dave Airlie13cf5502014-06-18 11:29:35 +10004912
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03004913 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
4914 /*
4915 * vdd off can generate a long pulse on eDP which
4916 * would require vdd on to handle it, and thus we
4917 * would end up in an endless cycle of
4918 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
4919 */
4920 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
4921 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d522015-02-10 14:11:46 +02004922 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03004923 }
4924
Ville Syrjälä26fbb772014-08-11 18:37:37 +03004925 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
4926 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10004927 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10004928
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004929 if (long_hpd) {
4930 intel_dp->detect_done = false;
4931 return IRQ_NONE;
4932 }
4933
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004934 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak1c767b32014-08-18 14:42:42 +03004935 intel_display_power_get(dev_priv, power_domain);
4936
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004937 if (intel_dp->is_mst) {
4938 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
4939 /*
4940 * If we were in MST mode, and device is not
4941 * there, get out of MST mode
4942 */
4943 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4944 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
4945 intel_dp->is_mst = false;
4946 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4947 intel_dp->is_mst);
4948 intel_dp->detect_done = false;
4949 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10004950 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004951 }
Dave Airlie0e32b392014-05-02 14:02:48 +10004952
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004953 if (!intel_dp->is_mst) {
4954 if (!intel_dp_short_pulse(intel_dp)) {
4955 intel_dp->detect_done = false;
4956 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304957 }
Dave Airlie0e32b392014-05-02 14:02:48 +10004958 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004959
4960 ret = IRQ_HANDLED;
4961
Imre Deak1c767b32014-08-18 14:42:42 +03004962put_power:
4963 intel_display_power_put(dev_priv, power_domain);
4964
4965 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10004966}
4967
Rodrigo Vivi477ec322015-08-06 15:51:39 +08004968/* check the VBT to see whether the eDP is on another port */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00004969bool intel_dp_is_edp(struct drm_i915_private *dev_priv, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08004970{
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03004971 /*
4972 * eDP not supported on g4x. so bail out early just
4973 * for a bit extra safety in case the VBT is bonkers.
4974 */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00004975 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03004976 return false;
4977
Ville Syrjälä3b32a352013-11-01 18:22:41 +02004978 if (port == PORT_A)
4979 return true;
4980
Jani Nikula951d9ef2016-03-16 12:43:31 +02004981 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08004982}
4983
Dave Airlie0e32b392014-05-02 14:02:48 +10004984void
Chris Wilsonf6849602010-09-19 09:29:33 +01004985intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
4986{
Yuly Novikov53b41832012-10-26 12:04:00 +03004987 struct intel_connector *intel_connector = to_intel_connector(connector);
4988
Chris Wilson3f43c482011-05-12 22:17:24 +01004989 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00004990 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004991 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03004992
4993 if (is_edp(intel_dp)) {
4994 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05004995 drm_object_attach_property(
4996 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03004997 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03004998 DRM_MODE_SCALE_ASPECT);
4999 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03005000 }
Chris Wilsonf6849602010-09-19 09:29:33 +01005001}
5002
Imre Deakdada1a92014-01-29 13:25:41 +02005003static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
5004{
Abhay Kumard28d4732016-01-22 17:39:04 -08005005 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02005006 intel_dp->last_power_on = jiffies;
5007 intel_dp->last_backlight_off = jiffies;
5008}
5009
Daniel Vetter67a54562012-10-20 20:57:45 +02005010static void
Imre Deak54648612016-06-16 16:37:22 +03005011intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
5012 struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02005013{
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305014 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03005015 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07005016
Imre Deak8e8232d2016-06-16 16:37:21 +03005017 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02005018
5019 /* Workaround: Need to write PP_CONTROL with the unlock key as
5020 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305021 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02005022
Imre Deak8e8232d2016-06-16 16:37:21 +03005023 pp_on = I915_READ(regs.pp_on);
5024 pp_off = I915_READ(regs.pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005025 if (!IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005026 I915_WRITE(regs.pp_ctrl, pp_ctl);
5027 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305028 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005029
5030 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03005031 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
5032 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005033
Imre Deak54648612016-06-16 16:37:22 +03005034 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
5035 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005036
Imre Deak54648612016-06-16 16:37:22 +03005037 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
5038 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005039
Imre Deak54648612016-06-16 16:37:22 +03005040 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
5041 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005042
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005043 if (IS_GEN9_LP(dev_priv)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305044 u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
5045 BXT_POWER_CYCLE_DELAY_SHIFT;
5046 if (tmp > 0)
Imre Deak54648612016-06-16 16:37:22 +03005047 seq->t11_t12 = (tmp - 1) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305048 else
Imre Deak54648612016-06-16 16:37:22 +03005049 seq->t11_t12 = 0;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305050 } else {
Imre Deak54648612016-06-16 16:37:22 +03005051 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02005052 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305053 }
Imre Deak54648612016-06-16 16:37:22 +03005054}
5055
5056static void
Imre Deakde9c1b62016-06-16 20:01:46 +03005057intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
5058{
5059 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5060 state_name,
5061 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
5062}
5063
5064static void
5065intel_pps_verify_state(struct drm_i915_private *dev_priv,
5066 struct intel_dp *intel_dp)
5067{
5068 struct edp_power_seq hw;
5069 struct edp_power_seq *sw = &intel_dp->pps_delays;
5070
5071 intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
5072
5073 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
5074 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
5075 DRM_ERROR("PPS state mismatch\n");
5076 intel_pps_dump_state("sw", sw);
5077 intel_pps_dump_state("hw", &hw);
5078 }
5079}
5080
5081static void
Imre Deak54648612016-06-16 16:37:22 +03005082intel_dp_init_panel_power_sequencer(struct drm_device *dev,
5083 struct intel_dp *intel_dp)
5084{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005085 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak54648612016-06-16 16:37:22 +03005086 struct edp_power_seq cur, vbt, spec,
5087 *final = &intel_dp->pps_delays;
5088
5089 lockdep_assert_held(&dev_priv->pps_mutex);
5090
5091 /* already initialized? */
5092 if (final->t11_t12 != 0)
5093 return;
5094
5095 intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005096
Imre Deakde9c1b62016-06-16 20:01:46 +03005097 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005098
Jani Nikula6aa23e62016-03-24 17:50:20 +02005099 vbt = dev_priv->vbt.edp.pps;
Daniel Vetter67a54562012-10-20 20:57:45 +02005100
5101 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5102 * our hw here, which are all in 100usec. */
5103 spec.t1_t3 = 210 * 10;
5104 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5105 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5106 spec.t10 = 500 * 10;
5107 /* This one is special and actually in units of 100ms, but zero
5108 * based in the hw (so we need to add 100 ms). But the sw vbt
5109 * table multiplies it with 1000 to make it in units of 100usec,
5110 * too. */
5111 spec.t11_t12 = (510 + 100) * 10;
5112
Imre Deakde9c1b62016-06-16 20:01:46 +03005113 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005114
5115 /* Use the max of the register settings and vbt. If both are
5116 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005117#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005118 spec.field : \
5119 max(cur.field, vbt.field))
5120 assign_final(t1_t3);
5121 assign_final(t8);
5122 assign_final(t9);
5123 assign_final(t10);
5124 assign_final(t11_t12);
5125#undef assign_final
5126
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005127#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005128 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5129 intel_dp->backlight_on_delay = get_delay(t8);
5130 intel_dp->backlight_off_delay = get_delay(t9);
5131 intel_dp->panel_power_down_delay = get_delay(t10);
5132 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5133#undef get_delay
5134
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005135 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5136 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5137 intel_dp->panel_power_cycle_delay);
5138
5139 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5140 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005141
5142 /*
5143 * We override the HW backlight delays to 1 because we do manual waits
5144 * on them. For T8, even BSpec recommends doing it. For T9, if we
5145 * don't do this, we'll end up waiting for the backlight off delay
5146 * twice: once when we do the manual sleep, and once when we disable
5147 * the panel and wait for the PP_STATUS bit to become zero.
5148 */
5149 final->t8 = 1;
5150 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005151}
5152
5153static void
5154intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005155 struct intel_dp *intel_dp)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005156{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005157 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07005158 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005159 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005160 struct pps_registers regs;
Ville Syrjäläad933b52014-08-18 22:15:56 +03005161 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005162 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005163
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005164 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005165
Imre Deak8e8232d2016-06-16 16:37:21 +03005166 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005167
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005168 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005169 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5170 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005171 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005172 /* Compute the divisor for the pp clock, simply match the Bspec
5173 * formula. */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005174 if (IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005175 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305176 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
5177 pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
5178 << BXT_POWER_CYCLE_DELAY_SHIFT);
5179 } else {
5180 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5181 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5182 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5183 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005184
5185 /* Haswell doesn't have any port selection bits for the panel
5186 * power sequencer any more. */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005187 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005188 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005189 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005190 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005191 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005192 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005193 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005194 }
5195
Jesse Barnes453c5422013-03-28 09:55:41 -07005196 pp_on |= port_sel;
5197
Imre Deak8e8232d2016-06-16 16:37:21 +03005198 I915_WRITE(regs.pp_on, pp_on);
5199 I915_WRITE(regs.pp_off, pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005200 if (IS_GEN9_LP(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005201 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305202 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005203 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005204
Daniel Vetter67a54562012-10-20 20:57:45 +02005205 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 +03005206 I915_READ(regs.pp_on),
5207 I915_READ(regs.pp_off),
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005208 IS_GEN9_LP(dev_priv) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005209 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5210 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005211}
5212
Imre Deak335f7522016-08-10 14:07:32 +03005213static void intel_dp_pps_init(struct drm_device *dev,
5214 struct intel_dp *intel_dp)
5215{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005216 struct drm_i915_private *dev_priv = to_i915(dev);
5217
5218 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Imre Deak335f7522016-08-10 14:07:32 +03005219 vlv_initial_power_sequencer_setup(intel_dp);
5220 } else {
5221 intel_dp_init_panel_power_sequencer(dev, intel_dp);
5222 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
5223 }
5224}
5225
Vandana Kannanb33a2812015-02-13 15:33:03 +05305226/**
5227 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005228 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005229 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305230 * @refresh_rate: RR to be programmed
5231 *
5232 * This function gets called when refresh rate (RR) has to be changed from
5233 * one frequency to another. Switches can be between high and low RR
5234 * supported by the panel or to any other RR based on media playback (in
5235 * this case, RR value needs to be passed from user space).
5236 *
5237 * The caller of this function needs to take a lock on dev_priv->drrs.
5238 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005239static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
5240 struct intel_crtc_state *crtc_state,
5241 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305242{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305243 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305244 struct intel_digital_port *dig_port = NULL;
5245 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005246 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305247 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305248
5249 if (refresh_rate <= 0) {
5250 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5251 return;
5252 }
5253
Vandana Kannan96178ee2015-01-10 02:25:56 +05305254 if (intel_dp == NULL) {
5255 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305256 return;
5257 }
5258
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005259 /*
Rodrigo Vivie4d59f62014-11-20 02:22:08 -08005260 * FIXME: This needs proper synchronization with psr state for some
5261 * platforms that cannot have PSR and DRRS enabled at the same time.
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005262 */
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305263
Vandana Kannan96178ee2015-01-10 02:25:56 +05305264 dig_port = dp_to_dig_port(intel_dp);
5265 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02005266 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305267
5268 if (!intel_crtc) {
5269 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5270 return;
5271 }
5272
Vandana Kannan96178ee2015-01-10 02:25:56 +05305273 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305274 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5275 return;
5276 }
5277
Vandana Kannan96178ee2015-01-10 02:25:56 +05305278 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5279 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305280 index = DRRS_LOW_RR;
5281
Vandana Kannan96178ee2015-01-10 02:25:56 +05305282 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305283 DRM_DEBUG_KMS(
5284 "DRRS requested for previously set RR...ignoring\n");
5285 return;
5286 }
5287
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005288 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305289 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5290 return;
5291 }
5292
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005293 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305294 switch (index) {
5295 case DRRS_HIGH_RR:
5296 intel_dp_set_m_n(intel_crtc, M1_N1);
5297 break;
5298 case DRRS_LOW_RR:
5299 intel_dp_set_m_n(intel_crtc, M2_N2);
5300 break;
5301 case DRRS_MAX_RR:
5302 default:
5303 DRM_ERROR("Unsupported refreshrate type\n");
5304 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005305 } else if (INTEL_GEN(dev_priv) > 6) {
5306 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005307 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305308
Ville Syrjälä649636e2015-09-22 19:50:01 +03005309 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305310 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005311 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305312 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5313 else
5314 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305315 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005316 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305317 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5318 else
5319 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305320 }
5321 I915_WRITE(reg, val);
5322 }
5323
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305324 dev_priv->drrs.refresh_rate_type = index;
5325
5326 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5327}
5328
Vandana Kannanb33a2812015-02-13 15:33:03 +05305329/**
5330 * intel_edp_drrs_enable - init drrs struct if supported
5331 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005332 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305333 *
5334 * Initializes frontbuffer_bits and drrs.dp
5335 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005336void intel_edp_drrs_enable(struct intel_dp *intel_dp,
5337 struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305338{
5339 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005340 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305341
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005342 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305343 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5344 return;
5345 }
5346
5347 mutex_lock(&dev_priv->drrs.mutex);
5348 if (WARN_ON(dev_priv->drrs.dp)) {
5349 DRM_ERROR("DRRS already enabled\n");
5350 goto unlock;
5351 }
5352
5353 dev_priv->drrs.busy_frontbuffer_bits = 0;
5354
5355 dev_priv->drrs.dp = intel_dp;
5356
5357unlock:
5358 mutex_unlock(&dev_priv->drrs.mutex);
5359}
5360
Vandana Kannanb33a2812015-02-13 15:33:03 +05305361/**
5362 * intel_edp_drrs_disable - Disable DRRS
5363 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005364 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305365 *
5366 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005367void intel_edp_drrs_disable(struct intel_dp *intel_dp,
5368 struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305369{
5370 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005371 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305372
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005373 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305374 return;
5375
5376 mutex_lock(&dev_priv->drrs.mutex);
5377 if (!dev_priv->drrs.dp) {
5378 mutex_unlock(&dev_priv->drrs.mutex);
5379 return;
5380 }
5381
5382 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005383 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5384 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305385
5386 dev_priv->drrs.dp = NULL;
5387 mutex_unlock(&dev_priv->drrs.mutex);
5388
5389 cancel_delayed_work_sync(&dev_priv->drrs.work);
5390}
5391
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305392static void intel_edp_drrs_downclock_work(struct work_struct *work)
5393{
5394 struct drm_i915_private *dev_priv =
5395 container_of(work, typeof(*dev_priv), drrs.work.work);
5396 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305397
Vandana Kannan96178ee2015-01-10 02:25:56 +05305398 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305399
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305400 intel_dp = dev_priv->drrs.dp;
5401
5402 if (!intel_dp)
5403 goto unlock;
5404
5405 /*
5406 * The delayed work can race with an invalidate hence we need to
5407 * recheck.
5408 */
5409
5410 if (dev_priv->drrs.busy_frontbuffer_bits)
5411 goto unlock;
5412
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005413 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5414 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5415
5416 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5417 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5418 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305419
5420unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305421 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305422}
5423
Vandana Kannanb33a2812015-02-13 15:33:03 +05305424/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305425 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005426 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305427 * @frontbuffer_bits: frontbuffer plane tracking bits
5428 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305429 * This function gets called everytime rendering on the given planes start.
5430 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305431 *
5432 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5433 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005434void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5435 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305436{
Vandana Kannana93fad02015-01-10 02:25:59 +05305437 struct drm_crtc *crtc;
5438 enum pipe pipe;
5439
Daniel Vetter9da7d692015-04-09 16:44:15 +02005440 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305441 return;
5442
Daniel Vetter88f933a2015-04-09 16:44:16 +02005443 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305444
Vandana Kannana93fad02015-01-10 02:25:59 +05305445 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005446 if (!dev_priv->drrs.dp) {
5447 mutex_unlock(&dev_priv->drrs.mutex);
5448 return;
5449 }
5450
Vandana Kannana93fad02015-01-10 02:25:59 +05305451 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5452 pipe = to_intel_crtc(crtc)->pipe;
5453
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005454 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5455 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5456
Ramalingam C0ddfd202015-06-15 20:50:05 +05305457 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005458 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005459 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5460 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305461
Vandana Kannana93fad02015-01-10 02:25:59 +05305462 mutex_unlock(&dev_priv->drrs.mutex);
5463}
5464
Vandana Kannanb33a2812015-02-13 15:33:03 +05305465/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305466 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005467 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305468 * @frontbuffer_bits: frontbuffer plane tracking bits
5469 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305470 * This function gets called every time rendering on the given planes has
5471 * completed or flip on a crtc is completed. So DRRS should be upclocked
5472 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5473 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305474 *
5475 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5476 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005477void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5478 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305479{
Vandana Kannana93fad02015-01-10 02:25:59 +05305480 struct drm_crtc *crtc;
5481 enum pipe pipe;
5482
Daniel Vetter9da7d692015-04-09 16:44:15 +02005483 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305484 return;
5485
Daniel Vetter88f933a2015-04-09 16:44:16 +02005486 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305487
Vandana Kannana93fad02015-01-10 02:25:59 +05305488 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005489 if (!dev_priv->drrs.dp) {
5490 mutex_unlock(&dev_priv->drrs.mutex);
5491 return;
5492 }
5493
Vandana Kannana93fad02015-01-10 02:25:59 +05305494 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5495 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005496
5497 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305498 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5499
Ramalingam C0ddfd202015-06-15 20:50:05 +05305500 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005501 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005502 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5503 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305504
5505 /*
5506 * flush also means no more activity hence schedule downclock, if all
5507 * other fbs are quiescent too
5508 */
5509 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305510 schedule_delayed_work(&dev_priv->drrs.work,
5511 msecs_to_jiffies(1000));
5512 mutex_unlock(&dev_priv->drrs.mutex);
5513}
5514
Vandana Kannanb33a2812015-02-13 15:33:03 +05305515/**
5516 * DOC: Display Refresh Rate Switching (DRRS)
5517 *
5518 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5519 * which enables swtching between low and high refresh rates,
5520 * dynamically, based on the usage scenario. This feature is applicable
5521 * for internal panels.
5522 *
5523 * Indication that the panel supports DRRS is given by the panel EDID, which
5524 * would list multiple refresh rates for one resolution.
5525 *
5526 * DRRS is of 2 types - static and seamless.
5527 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5528 * (may appear as a blink on screen) and is used in dock-undock scenario.
5529 * Seamless DRRS involves changing RR without any visual effect to the user
5530 * and can be used during normal system usage. This is done by programming
5531 * certain registers.
5532 *
5533 * Support for static/seamless DRRS may be indicated in the VBT based on
5534 * inputs from the panel spec.
5535 *
5536 * DRRS saves power by switching to low RR based on usage scenarios.
5537 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005538 * The implementation is based on frontbuffer tracking implementation. When
5539 * there is a disturbance on the screen triggered by user activity or a periodic
5540 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5541 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5542 * made.
5543 *
5544 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5545 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305546 *
5547 * DRRS can be further extended to support other internal panels and also
5548 * the scenario of video playback wherein RR is set based on the rate
5549 * requested by userspace.
5550 */
5551
5552/**
5553 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5554 * @intel_connector: eDP connector
5555 * @fixed_mode: preferred mode of panel
5556 *
5557 * This function is called only once at driver load to initialize basic
5558 * DRRS stuff.
5559 *
5560 * Returns:
5561 * Downclock mode if panel supports it, else return NULL.
5562 * DRRS support is determined by the presence of downclock mode (apart
5563 * from VBT setting).
5564 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305565static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305566intel_dp_drrs_init(struct intel_connector *intel_connector,
5567 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305568{
5569 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305570 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005571 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305572 struct drm_display_mode *downclock_mode = NULL;
5573
Daniel Vetter9da7d692015-04-09 16:44:15 +02005574 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5575 mutex_init(&dev_priv->drrs.mutex);
5576
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005577 if (INTEL_GEN(dev_priv) <= 6) {
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305578 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5579 return NULL;
5580 }
5581
5582 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005583 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305584 return NULL;
5585 }
5586
5587 downclock_mode = intel_find_panel_downclock
Mika Kaholaa318b4c2016-12-13 10:02:48 +02005588 (dev_priv, fixed_mode, connector);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305589
5590 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305591 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305592 return NULL;
5593 }
5594
Vandana Kannan96178ee2015-01-10 02:25:56 +05305595 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305596
Vandana Kannan96178ee2015-01-10 02:25:56 +05305597 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005598 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305599 return downclock_mode;
5600}
5601
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005602static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005603 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005604{
5605 struct drm_connector *connector = &intel_connector->base;
5606 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005607 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5608 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005609 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005610 struct drm_display_mode *fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305611 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005612 bool has_dpcd;
5613 struct drm_display_mode *scan;
5614 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005615 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005616
5617 if (!is_edp(intel_dp))
5618 return true;
5619
Imre Deak97a824e12016-06-21 11:51:47 +03005620 /*
5621 * On IBX/CPT we may get here with LVDS already registered. Since the
5622 * driver uses the only internal power sequencer available for both
5623 * eDP and LVDS bail out early in this case to prevent interfering
5624 * with an already powered-on LVDS power sequencer.
5625 */
5626 if (intel_get_lvds_encoder(dev)) {
5627 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5628 DRM_INFO("LVDS was detected, not registering eDP\n");
5629
5630 return false;
5631 }
5632
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005633 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005634
5635 intel_dp_init_panel_power_timestamps(intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +03005636 intel_dp_pps_init(dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005637 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005638
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005639 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005640
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005641 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005642 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005643
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005644 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005645 /* if this fails, presume the device is a ghost */
5646 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005647 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005648 }
5649
Daniel Vetter060c8772014-03-21 23:22:35 +01005650 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005651 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005652 if (edid) {
5653 if (drm_add_edid_modes(connector, edid)) {
5654 drm_mode_connector_update_edid_property(connector,
5655 edid);
5656 drm_edid_to_eld(connector, edid);
5657 } else {
5658 kfree(edid);
5659 edid = ERR_PTR(-EINVAL);
5660 }
5661 } else {
5662 edid = ERR_PTR(-ENOENT);
5663 }
5664 intel_connector->edid = edid;
5665
5666 /* prefer fixed mode from EDID if available */
5667 list_for_each_entry(scan, &connector->probed_modes, head) {
5668 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5669 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305670 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305671 intel_connector, fixed_mode);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005672 break;
5673 }
5674 }
5675
5676 /* fallback to VBT if available for eDP */
5677 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5678 fixed_mode = drm_mode_duplicate(dev,
5679 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005680 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005681 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005682 connector->display_info.width_mm = fixed_mode->width_mm;
5683 connector->display_info.height_mm = fixed_mode->height_mm;
5684 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005685 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005686 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005687
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005688 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005689 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5690 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005691
5692 /*
5693 * Figure out the current pipe for the initial backlight setup.
5694 * If the current pipe isn't valid, try the PPS pipe, and if that
5695 * fails just assume pipe A.
5696 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005697 pipe = vlv_active_pipe(intel_dp);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005698
5699 if (pipe != PIPE_A && pipe != PIPE_B)
5700 pipe = intel_dp->pps_pipe;
5701
5702 if (pipe != PIPE_A && pipe != PIPE_B)
5703 pipe = PIPE_A;
5704
5705 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5706 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005707 }
5708
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305709 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005710 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005711 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005712
5713 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005714
5715out_vdd_off:
5716 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5717 /*
5718 * vdd might still be enabled do to the delayed vdd off.
5719 * Make sure vdd is actually turned off here.
5720 */
5721 pps_lock(intel_dp);
5722 edp_panel_vdd_off_sync(intel_dp);
5723 pps_unlock(intel_dp);
5724
5725 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005726}
5727
Paulo Zanoni16c25532013-06-12 17:27:25 -03005728bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005729intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5730 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005731{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005732 struct drm_connector *connector = &intel_connector->base;
5733 struct intel_dp *intel_dp = &intel_dig_port->dp;
5734 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5735 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005736 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02005737 enum port port = intel_dig_port->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01005738 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005739
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005740 if (WARN(intel_dig_port->max_lanes < 1,
5741 "Not enough lanes (%d) for DP on port %c\n",
5742 intel_dig_port->max_lanes, port_name(port)))
5743 return false;
5744
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005745 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005746 intel_dp->active_pipe = INVALID_PIPE;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005747
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005748 /* intel_dp vfuncs */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005749 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub6b5e382014-01-20 16:00:59 +00005750 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005751 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005752 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005753 else if (HAS_PCH_SPLIT(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005754 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
5755 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005756 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005757
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005758 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00005759 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
5760 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005761 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00005762
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005763 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03005764 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
5765
Daniel Vetter07679352012-09-06 22:15:42 +02005766 /* Preserve the current hw state. */
5767 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03005768 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00005769
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005770 if (intel_dp_is_edp(dev_priv, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05305771 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005772 else
5773 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04005774
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005775 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5776 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5777
Imre Deakf7d24902013-05-08 13:14:05 +03005778 /*
5779 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
5780 * for DP the encoder type can be set by the caller to
5781 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
5782 */
5783 if (type == DRM_MODE_CONNECTOR_eDP)
5784 intel_encoder->type = INTEL_OUTPUT_EDP;
5785
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005786 /* eDP only on port B and/or C on vlv/chv */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005787 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08005788 is_edp(intel_dp) && port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005789 return false;
5790
Imre Deake7281ea2013-05-08 13:14:08 +03005791 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
5792 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
5793 port_name(port));
5794
Adam Jacksonb3295302010-07-16 14:46:28 -04005795 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005796 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
5797
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005798 connector->interlace_allowed = true;
5799 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08005800
Mika Kaholab6339582016-09-09 14:10:52 +03005801 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01005802
Daniel Vetter66a92782012-07-12 20:08:18 +02005803 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01005804 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08005805
Chris Wilsondf0e9242010-09-09 16:20:55 +01005806 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005807
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005808 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02005809 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
5810 else
5811 intel_connector->get_hw_state = intel_connector_get_hw_state;
5812
Jani Nikula0b998362014-03-14 16:51:17 +02005813 /* Set up the hotplug pin. */
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005814 switch (port) {
5815 case PORT_A:
Egbert Eich1d843f92013-02-25 12:06:49 -05005816 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005817 break;
5818 case PORT_B:
Egbert Eich1d843f92013-02-25 12:06:49 -05005819 intel_encoder->hpd_pin = HPD_PORT_B;
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01005820 if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1))
Sonika Jindalcf1d5882015-08-10 10:35:36 +05305821 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005822 break;
5823 case PORT_C:
Egbert Eich1d843f92013-02-25 12:06:49 -05005824 intel_encoder->hpd_pin = HPD_PORT_C;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005825 break;
5826 case PORT_D:
Egbert Eich1d843f92013-02-25 12:06:49 -05005827 intel_encoder->hpd_pin = HPD_PORT_D;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005828 break;
Xiong Zhang26951ca2015-08-17 15:55:50 +08005829 case PORT_E:
5830 intel_encoder->hpd_pin = HPD_PORT_E;
5831 break;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005832 default:
Damien Lespiauad1c0b12013-03-07 15:30:28 +00005833 BUG();
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08005834 }
5835
Dave Airlie0e32b392014-05-02 14:02:48 +10005836 /* init MST on ports that can support it */
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00005837 if (HAS_DP_MST(dev_priv) && !is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03005838 (port == PORT_B || port == PORT_C || port == PORT_D))
5839 intel_dp_mst_encoder_init(intel_dig_port,
5840 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10005841
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005842 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005843 intel_dp_aux_fini(intel_dp);
5844 intel_dp_mst_encoder_cleanup(intel_dig_port);
5845 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03005846 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08005847
Chris Wilsonf6849602010-09-19 09:29:33 +01005848 intel_dp_add_properties(intel_dp, connector);
5849
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005850 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
5851 * 0xd. Failure to do so will result in spurious interrupts being
5852 * generated on the port when a cable is not attached.
5853 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01005854 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005855 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
5856 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
5857 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03005858
5859 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005860
5861fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005862 drm_connector_cleanup(connector);
5863
5864 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005865}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005866
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02005867bool intel_dp_init(struct drm_i915_private *dev_priv,
Chris Wilson457c52d2016-06-01 08:27:50 +01005868 i915_reg_t output_reg,
5869 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005870{
5871 struct intel_digital_port *intel_dig_port;
5872 struct intel_encoder *intel_encoder;
5873 struct drm_encoder *encoder;
5874 struct intel_connector *intel_connector;
5875
Daniel Vetterb14c5672013-09-19 12:18:32 +02005876 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005877 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01005878 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005879
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03005880 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305881 if (!intel_connector)
5882 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005883
5884 intel_encoder = &intel_dig_port->base;
5885 encoder = &intel_encoder->base;
5886
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02005887 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
5888 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
5889 "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305890 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005891
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01005892 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005893 intel_encoder->disable = intel_disable_dp;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005894 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07005895 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03005896 intel_encoder->suspend = intel_dp_encoder_suspend;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005897 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03005898 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03005899 intel_encoder->pre_enable = chv_pre_enable_dp;
5900 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03005901 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03005902 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01005903 } else if (IS_VALLEYVIEW(dev_priv)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03005904 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005905 intel_encoder->pre_enable = vlv_pre_enable_dp;
5906 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03005907 intel_encoder->post_disable = vlv_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005908 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03005909 intel_encoder->pre_enable = g4x_pre_enable_dp;
5910 intel_encoder->enable = g4x_enable_dp;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005911 if (INTEL_GEN(dev_priv) >= 5)
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03005912 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005913 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005914
Paulo Zanoni174edf12012-10-26 19:05:50 -02005915 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005916 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005917 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005918
Ville Syrjäläcca05022016-06-22 21:57:06 +03005919 intel_encoder->type = INTEL_OUTPUT_DP;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005920 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03005921 if (port == PORT_D)
5922 intel_encoder->crtc_mask = 1 << 2;
5923 else
5924 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
5925 } else {
5926 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
5927 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02005928 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07005929 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005930
Dave Airlie13cf5502014-06-18 11:29:35 +10005931 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03005932 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10005933
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305934 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
5935 goto err_init_connector;
5936
Chris Wilson457c52d2016-06-01 08:27:50 +01005937 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305938
5939err_init_connector:
5940 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305941err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305942 kfree(intel_connector);
5943err_connector_alloc:
5944 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01005945 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005946}
Dave Airlie0e32b392014-05-02 14:02:48 +10005947
5948void intel_dp_mst_suspend(struct drm_device *dev)
5949{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005950 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10005951 int i;
5952
5953 /* disable MST */
5954 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03005955 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005956
5957 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10005958 continue;
5959
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005960 if (intel_dig_port->dp.is_mst)
5961 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10005962 }
5963}
5964
5965void intel_dp_mst_resume(struct drm_device *dev)
5966{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005967 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10005968 int i;
5969
5970 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03005971 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005972 int ret;
5973
5974 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10005975 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10005976
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005977 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
5978 if (ret)
5979 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10005980 }
5981}