blob: e80d620846c8310fc88bbb0ac07a66e5a820ff87 [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ä5d5ab2d2016-12-20 18:51:17 +0200386 struct intel_dp *intel_dp,
387 bool force_disable_vdd);
Imre Deak335f7522016-08-10 14:07:32 +0300388static void
389intel_dp_pps_init(struct drm_device *dev, struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300390
Ville Syrjälä773538e82014-09-04 14:54:56 +0300391static void pps_lock(struct intel_dp *intel_dp)
392{
393 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
394 struct intel_encoder *encoder = &intel_dig_port->base;
395 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100396 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300397 enum intel_display_power_domain power_domain;
398
399 /*
400 * See vlv_power_sequencer_reset() why we need
401 * a power domain reference here.
402 */
Ville Syrjälä25f78f52015-11-16 15:01:04 +0100403 power_domain = intel_display_port_aux_power_domain(encoder);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300404 intel_display_power_get(dev_priv, power_domain);
405
406 mutex_lock(&dev_priv->pps_mutex);
407}
408
409static void pps_unlock(struct intel_dp *intel_dp)
410{
411 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
412 struct intel_encoder *encoder = &intel_dig_port->base;
413 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100414 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300415 enum intel_display_power_domain power_domain;
416
417 mutex_unlock(&dev_priv->pps_mutex);
418
Ville Syrjälä25f78f52015-11-16 15:01:04 +0100419 power_domain = intel_display_port_aux_power_domain(encoder);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300420 intel_display_power_put(dev_priv, power_domain);
421}
422
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300423static void
424vlv_power_sequencer_kick(struct intel_dp *intel_dp)
425{
426 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200427 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300428 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300429 bool pll_enabled, release_cl_override = false;
430 enum dpio_phy phy = DPIO_PHY(pipe);
431 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300432 uint32_t DP;
433
434 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
435 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
436 pipe_name(pipe), port_name(intel_dig_port->port)))
437 return;
438
439 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
440 pipe_name(pipe), port_name(intel_dig_port->port));
441
442 /* Preserve the BIOS-computed detected bit. This is
443 * supposed to be read-only.
444 */
445 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
446 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
447 DP |= DP_PORT_WIDTH(1);
448 DP |= DP_LINK_TRAIN_PAT_1;
449
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100450 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300451 DP |= DP_PIPE_SELECT_CHV(pipe);
452 else if (pipe == PIPE_B)
453 DP |= DP_PIPEB_SELECT;
454
Ville Syrjäläd288f652014-10-28 13:20:22 +0200455 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
456
457 /*
458 * The DPLL for the pipe must be enabled for this to work.
459 * So enable temporarily it if it's not already enabled.
460 */
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300461 if (!pll_enabled) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100462 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300463 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
464
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200465 if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ?
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000466 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
467 DRM_ERROR("Failed to force on pll for pipe %c!\n",
468 pipe_name(pipe));
469 return;
470 }
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300471 }
Ville Syrjäläd288f652014-10-28 13:20:22 +0200472
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300473 /*
474 * Similar magic as in intel_dp_enable_port().
475 * We _must_ do this port enable + disable trick
476 * to make this power seqeuencer lock onto the port.
477 * Otherwise even VDD force bit won't work.
478 */
479 I915_WRITE(intel_dp->output_reg, DP);
480 POSTING_READ(intel_dp->output_reg);
481
482 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
483 POSTING_READ(intel_dp->output_reg);
484
485 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
486 POSTING_READ(intel_dp->output_reg);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200487
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300488 if (!pll_enabled) {
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200489 vlv_force_pll_off(dev_priv, pipe);
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300490
491 if (release_cl_override)
492 chv_phy_powergate_ch(dev_priv, phy, ch, false);
493 }
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300494}
495
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200496static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv)
497{
498 struct intel_encoder *encoder;
499 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
500
501 /*
502 * We don't have power sequencer currently.
503 * Pick one that's not used by other ports.
504 */
505 for_each_intel_encoder(&dev_priv->drm, encoder) {
506 struct intel_dp *intel_dp;
507
508 if (encoder->type != INTEL_OUTPUT_DP &&
509 encoder->type != INTEL_OUTPUT_EDP)
510 continue;
511
512 intel_dp = enc_to_intel_dp(&encoder->base);
513
514 if (encoder->type == INTEL_OUTPUT_EDP) {
515 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
516 intel_dp->active_pipe != intel_dp->pps_pipe);
517
518 if (intel_dp->pps_pipe != INVALID_PIPE)
519 pipes &= ~(1 << intel_dp->pps_pipe);
520 } else {
521 WARN_ON(intel_dp->pps_pipe != INVALID_PIPE);
522
523 if (intel_dp->active_pipe != INVALID_PIPE)
524 pipes &= ~(1 << intel_dp->active_pipe);
525 }
526 }
527
528 if (pipes == 0)
529 return INVALID_PIPE;
530
531 return ffs(pipes) - 1;
532}
533
Jani Nikulabf13e812013-09-06 07:40:05 +0300534static enum pipe
535vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
536{
537 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300538 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100539 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300540 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300541
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300542 lockdep_assert_held(&dev_priv->pps_mutex);
543
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300544 /* We should never land here with regular DP ports */
545 WARN_ON(!is_edp(intel_dp));
546
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200547 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
548 intel_dp->active_pipe != intel_dp->pps_pipe);
549
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300550 if (intel_dp->pps_pipe != INVALID_PIPE)
551 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300552
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200553 pipe = vlv_find_free_pps(dev_priv);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300554
555 /*
556 * Didn't find one. This should not happen since there
557 * are two power sequencers and up to two eDP ports.
558 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200559 if (WARN_ON(pipe == INVALID_PIPE))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300560 pipe = PIPE_A;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300561
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300562 vlv_steal_power_sequencer(dev, pipe);
563 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300564
565 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
566 pipe_name(intel_dp->pps_pipe),
567 port_name(intel_dig_port->port));
568
569 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300570 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200571 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300572
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300573 /*
574 * Even vdd force doesn't work until we've made
575 * the power sequencer lock in on the port.
576 */
577 vlv_power_sequencer_kick(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300578
579 return intel_dp->pps_pipe;
580}
581
Imre Deak78597992016-06-16 16:37:20 +0300582static int
583bxt_power_sequencer_idx(struct intel_dp *intel_dp)
584{
585 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
586 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100587 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak78597992016-06-16 16:37:20 +0300588
589 lockdep_assert_held(&dev_priv->pps_mutex);
590
591 /* We should never land here with regular DP ports */
592 WARN_ON(!is_edp(intel_dp));
593
594 /*
595 * TODO: BXT has 2 PPS instances. The correct port->PPS instance
596 * mapping needs to be retrieved from VBT, for now just hard-code to
597 * use instance #0 always.
598 */
599 if (!intel_dp->pps_reset)
600 return 0;
601
602 intel_dp->pps_reset = false;
603
604 /*
605 * Only the HW needs to be reprogrammed, the SW state is fixed and
606 * has been setup during connector init.
607 */
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200608 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak78597992016-06-16 16:37:20 +0300609
610 return 0;
611}
612
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300613typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
614 enum pipe pipe);
615
616static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
617 enum pipe pipe)
618{
Imre Deak44cb7342016-08-10 14:07:29 +0300619 return I915_READ(PP_STATUS(pipe)) & PP_ON;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300620}
621
622static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
623 enum pipe pipe)
624{
Imre Deak44cb7342016-08-10 14:07:29 +0300625 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300626}
627
628static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
629 enum pipe pipe)
630{
631 return true;
632}
633
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300634static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300635vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
636 enum port port,
637 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300638{
Jani Nikulabf13e812013-09-06 07:40:05 +0300639 enum pipe pipe;
640
Jani Nikulabf13e812013-09-06 07:40:05 +0300641 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
Imre Deak44cb7342016-08-10 14:07:29 +0300642 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
Jani Nikulabf13e812013-09-06 07:40:05 +0300643 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300644
645 if (port_sel != PANEL_PORT_SELECT_VLV(port))
646 continue;
647
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300648 if (!pipe_check(dev_priv, pipe))
649 continue;
650
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300651 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300652 }
653
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300654 return INVALID_PIPE;
655}
656
657static void
658vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
659{
660 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
661 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100662 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300663 enum port port = intel_dig_port->port;
664
665 lockdep_assert_held(&dev_priv->pps_mutex);
666
667 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300668 /* first pick one where the panel is on */
669 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
670 vlv_pipe_has_pp_on);
671 /* didn't find one? pick one where vdd is on */
672 if (intel_dp->pps_pipe == INVALID_PIPE)
673 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
674 vlv_pipe_has_vdd_on);
675 /* didn't find one? pick one with just the correct port */
676 if (intel_dp->pps_pipe == INVALID_PIPE)
677 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
678 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300679
680 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
681 if (intel_dp->pps_pipe == INVALID_PIPE) {
682 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
683 port_name(port));
684 return;
685 }
686
687 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
688 port_name(port), pipe_name(intel_dp->pps_pipe));
689
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300690 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200691 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Jani Nikulabf13e812013-09-06 07:40:05 +0300692}
693
Imre Deak78597992016-06-16 16:37:20 +0300694void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300695{
Chris Wilson91c8a322016-07-05 10:40:23 +0100696 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300697 struct intel_encoder *encoder;
698
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100699 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200700 !IS_GEN9_LP(dev_priv)))
Ville Syrjälä773538e82014-09-04 14:54:56 +0300701 return;
702
703 /*
704 * We can't grab pps_mutex here due to deadlock with power_domain
705 * mutex when power_domain functions are called while holding pps_mutex.
706 * That also means that in order to use pps_pipe the code needs to
707 * hold both a power domain reference and pps_mutex, and the power domain
708 * reference get/put must be done while _not_ holding pps_mutex.
709 * pps_{lock,unlock}() do these steps in the correct order, so one
710 * should use them always.
711 */
712
Jani Nikula19c80542015-12-16 12:48:16 +0200713 for_each_intel_encoder(dev, encoder) {
Ville Syrjälä773538e82014-09-04 14:54:56 +0300714 struct intel_dp *intel_dp;
715
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200716 if (encoder->type != INTEL_OUTPUT_DP &&
717 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300718 continue;
719
720 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200721
722 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
723
724 if (encoder->type != INTEL_OUTPUT_EDP)
725 continue;
726
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200727 if (IS_GEN9_LP(dev_priv))
Imre Deak78597992016-06-16 16:37:20 +0300728 intel_dp->pps_reset = true;
729 else
730 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300731 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300732}
733
Imre Deak8e8232d2016-06-16 16:37:21 +0300734struct pps_registers {
735 i915_reg_t pp_ctrl;
736 i915_reg_t pp_stat;
737 i915_reg_t pp_on;
738 i915_reg_t pp_off;
739 i915_reg_t pp_div;
740};
741
742static void intel_pps_get_registers(struct drm_i915_private *dev_priv,
743 struct intel_dp *intel_dp,
744 struct pps_registers *regs)
745{
Imre Deak44cb7342016-08-10 14:07:29 +0300746 int pps_idx = 0;
747
Imre Deak8e8232d2016-06-16 16:37:21 +0300748 memset(regs, 0, sizeof(*regs));
749
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200750 if (IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300751 pps_idx = bxt_power_sequencer_idx(intel_dp);
752 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
753 pps_idx = vlv_power_sequencer_pipe(intel_dp);
Imre Deak8e8232d2016-06-16 16:37:21 +0300754
Imre Deak44cb7342016-08-10 14:07:29 +0300755 regs->pp_ctrl = PP_CONTROL(pps_idx);
756 regs->pp_stat = PP_STATUS(pps_idx);
757 regs->pp_on = PP_ON_DELAYS(pps_idx);
758 regs->pp_off = PP_OFF_DELAYS(pps_idx);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200759 if (!IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300760 regs->pp_div = PP_DIVISOR(pps_idx);
Imre Deak8e8232d2016-06-16 16:37:21 +0300761}
762
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200763static i915_reg_t
764_pp_ctrl_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300765{
Imre Deak8e8232d2016-06-16 16:37:21 +0300766 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300767
Imre Deak8e8232d2016-06-16 16:37:21 +0300768 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
769 &regs);
770
771 return regs.pp_ctrl;
Jani Nikulabf13e812013-09-06 07:40:05 +0300772}
773
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200774static i915_reg_t
775_pp_stat_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300776{
Imre Deak8e8232d2016-06-16 16:37:21 +0300777 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300778
Imre Deak8e8232d2016-06-16 16:37:21 +0300779 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
780 &regs);
781
782 return regs.pp_stat;
Jani Nikulabf13e812013-09-06 07:40:05 +0300783}
784
Clint Taylor01527b32014-07-07 13:01:46 -0700785/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
786 This function only applicable when panel PM state is not to be tracked */
787static int edp_notify_handler(struct notifier_block *this, unsigned long code,
788 void *unused)
789{
790 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
791 edp_notifier);
792 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100793 struct drm_i915_private *dev_priv = to_i915(dev);
Clint Taylor01527b32014-07-07 13:01:46 -0700794
795 if (!is_edp(intel_dp) || code != SYS_RESTART)
796 return 0;
797
Ville Syrjälä773538e82014-09-04 14:54:56 +0300798 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300799
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100800 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300801 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200802 i915_reg_t pp_ctrl_reg, pp_div_reg;
Ville Syrjälä649636e2015-09-22 19:50:01 +0300803 u32 pp_div;
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300804
Imre Deak44cb7342016-08-10 14:07:29 +0300805 pp_ctrl_reg = PP_CONTROL(pipe);
806 pp_div_reg = PP_DIVISOR(pipe);
Clint Taylor01527b32014-07-07 13:01:46 -0700807 pp_div = I915_READ(pp_div_reg);
808 pp_div &= PP_REFERENCE_DIVIDER_MASK;
809
810 /* 0x1F write to PP_DIV_REG sets max cycle delay */
811 I915_WRITE(pp_div_reg, pp_div | 0x1F);
812 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
813 msleep(intel_dp->panel_power_cycle_delay);
814 }
815
Ville Syrjälä773538e82014-09-04 14:54:56 +0300816 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300817
Clint Taylor01527b32014-07-07 13:01:46 -0700818 return 0;
819}
820
Daniel Vetter4be73782014-01-17 14:39:48 +0100821static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700822{
Paulo Zanoni30add222012-10-26 19:05:45 -0200823 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100824 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700825
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300826 lockdep_assert_held(&dev_priv->pps_mutex);
827
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100828 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300829 intel_dp->pps_pipe == INVALID_PIPE)
830 return false;
831
Jani Nikulabf13e812013-09-06 07:40:05 +0300832 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700833}
834
Daniel Vetter4be73782014-01-17 14:39:48 +0100835static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700836{
Paulo Zanoni30add222012-10-26 19:05:45 -0200837 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100838 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700839
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300840 lockdep_assert_held(&dev_priv->pps_mutex);
841
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100842 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300843 intel_dp->pps_pipe == INVALID_PIPE)
844 return false;
845
Ville Syrjälä773538e82014-09-04 14:54:56 +0300846 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700847}
848
Keith Packard9b984da2011-09-19 13:54:47 -0700849static void
850intel_dp_check_edp(struct intel_dp *intel_dp)
851{
Paulo Zanoni30add222012-10-26 19:05:45 -0200852 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100853 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700854
Keith Packard9b984da2011-09-19 13:54:47 -0700855 if (!is_edp(intel_dp))
856 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700857
Daniel Vetter4be73782014-01-17 14:39:48 +0100858 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700859 WARN(1, "eDP powered off while attempting aux channel communication.\n");
860 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300861 I915_READ(_pp_stat_reg(intel_dp)),
862 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700863 }
864}
865
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100866static uint32_t
867intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
868{
869 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
870 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100871 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200872 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100873 uint32_t status;
874 bool done;
875
Daniel Vetteref04f002012-12-01 21:03:59 +0100876#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100877 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300878 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300879 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100880 else
Imre Deak713a6b662016-06-28 13:37:33 +0300881 done = wait_for(C, 10) == 0;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100882 if (!done)
883 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
884 has_aux_irq);
885#undef C
886
887 return status;
888}
889
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200890static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000891{
892 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200893 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000894
Ville Syrjäläa457f542016-03-02 17:22:17 +0200895 if (index)
896 return 0;
897
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000898 /*
899 * The clock divider is based off the hrawclk, and would like to run at
Ville Syrjäläa457f542016-03-02 17:22:17 +0200900 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000901 */
Ville Syrjäläa457f542016-03-02 17:22:17 +0200902 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000903}
904
905static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
906{
907 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200908 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000909
910 if (index)
911 return 0;
912
Ville Syrjäläa457f542016-03-02 17:22:17 +0200913 /*
914 * The clock divider is based off the cdclk or PCH rawclk, and would
915 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
916 * divide by 2000 and use that
917 */
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200918 if (intel_dig_port->port == PORT_A)
Ville Syrjäläfce18c42015-11-30 16:23:46 +0200919 return DIV_ROUND_CLOSEST(dev_priv->cdclk_freq, 2000);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200920 else
921 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000922}
923
924static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300925{
926 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200927 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300928
Ville Syrjäläa457f542016-03-02 17:22:17 +0200929 if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300930 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100931 switch (index) {
932 case 0: return 63;
933 case 1: return 72;
934 default: return 0;
935 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300936 }
Ville Syrjäläa457f542016-03-02 17:22:17 +0200937
938 return ilk_get_aux_clock_divider(intel_dp, index);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300939}
940
Damien Lespiaub6b5e382014-01-20 16:00:59 +0000941static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
942{
943 /*
944 * SKL doesn't need us to program the AUX clock divider (Hardware will
945 * derive the clock from CDCLK automatically). We still implement the
946 * get_aux_clock_divider vfunc to plug-in into the existing code.
947 */
948 return index ? 0 : 1;
949}
950
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200951static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
952 bool has_aux_irq,
953 int send_bytes,
954 uint32_t aux_clock_divider)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000955{
956 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100957 struct drm_i915_private *dev_priv =
958 to_i915(intel_dig_port->base.base.dev);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000959 uint32_t precharge, timeout;
960
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100961 if (IS_GEN6(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000962 precharge = 3;
963 else
964 precharge = 5;
965
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100966 if (IS_BROADWELL(dev_priv) && intel_dig_port->port == PORT_A)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000967 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
968 else
969 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
970
971 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +0000972 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000973 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000974 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000975 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +0000976 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000977 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
978 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000979 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000980}
981
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000982static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
983 bool has_aux_irq,
984 int send_bytes,
985 uint32_t unused)
986{
987 return DP_AUX_CH_CTL_SEND_BUSY |
988 DP_AUX_CH_CTL_DONE |
989 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
990 DP_AUX_CH_CTL_TIME_OUT_ERROR |
991 DP_AUX_CH_CTL_TIME_OUT_1600us |
992 DP_AUX_CH_CTL_RECEIVE_ERROR |
993 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Daniel Vetterd4dcbdc2016-05-18 18:47:15 +0200994 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000995 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
996}
997
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700998static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100999intel_dp_aux_ch(struct intel_dp *intel_dp,
Daniel Vetterbd9f74a2014-10-02 09:45:35 +02001000 const uint8_t *send, int send_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001001 uint8_t *recv, int recv_size)
1002{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001003 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001004 struct drm_i915_private *dev_priv =
1005 to_i915(intel_dig_port->base.base.dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001006 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Chris Wilsonbc866252013-07-21 16:00:03 +01001007 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001008 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001009 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001010 int try, clock = 0;
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001011 bool has_aux_irq = HAS_AUX_IRQ(dev_priv);
Jani Nikula884f19e2014-03-14 16:51:14 +02001012 bool vdd;
1013
Ville Syrjälä773538e82014-09-04 14:54:56 +03001014 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001015
Ville Syrjälä72c35002014-08-18 22:16:00 +03001016 /*
1017 * We will be called with VDD already enabled for dpcd/edid/oui reads.
1018 * In such cases we want to leave VDD enabled and it's up to upper layers
1019 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
1020 * ourselves.
1021 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001022 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001023
1024 /* dp aux is extremely sensitive to irq latency, hence request the
1025 * lowest possible wakeup latency and so prevent the cpu from going into
1026 * deep sleep states.
1027 */
1028 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001029
Keith Packard9b984da2011-09-19 13:54:47 -07001030 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001031
Jesse Barnes11bee432011-08-01 15:02:20 -07001032 /* Try to wait for any previous AUX channel activity */
1033 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +01001034 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -07001035 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
1036 break;
1037 msleep(1);
1038 }
1039
1040 if (try == 3) {
Mika Kuoppala02196c72015-08-06 16:48:58 +03001041 static u32 last_status = -1;
1042 const u32 status = I915_READ(ch_ctl);
1043
1044 if (status != last_status) {
1045 WARN(1, "dp_aux_ch not started status 0x%08x\n",
1046 status);
1047 last_status = status;
1048 }
1049
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001050 ret = -EBUSY;
1051 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001052 }
1053
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001054 /* Only 5 data registers! */
1055 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
1056 ret = -E2BIG;
1057 goto out;
1058 }
1059
Damien Lespiauec5b01d2014-01-21 13:35:39 +00001060 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +00001061 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
1062 has_aux_irq,
1063 send_bytes,
1064 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001065
Chris Wilsonbc866252013-07-21 16:00:03 +01001066 /* Must try at least 3 times according to DP spec */
1067 for (try = 0; try < 5; try++) {
1068 /* Load the send data into the aux channel data registers */
1069 for (i = 0; i < send_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001070 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001071 intel_dp_pack_aux(send + i,
1072 send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -04001073
Chris Wilsonbc866252013-07-21 16:00:03 +01001074 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001075 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001076
Chris Wilsonbc866252013-07-21 16:00:03 +01001077 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -04001078
Chris Wilsonbc866252013-07-21 16:00:03 +01001079 /* Clear done status and any errors */
1080 I915_WRITE(ch_ctl,
1081 status |
1082 DP_AUX_CH_CTL_DONE |
1083 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1084 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -04001085
Todd Previte74ebf292015-04-15 08:38:41 -07001086 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
Chris Wilsonbc866252013-07-21 16:00:03 +01001087 continue;
Todd Previte74ebf292015-04-15 08:38:41 -07001088
1089 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
1090 * 400us delay required for errors and timeouts
1091 * Timeout errors from the HW already meet this
1092 * requirement so skip to next iteration
1093 */
1094 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1095 usleep_range(400, 500);
1096 continue;
1097 }
Chris Wilsonbc866252013-07-21 16:00:03 +01001098 if (status & DP_AUX_CH_CTL_DONE)
Jim Bridee058c942015-05-27 10:21:48 -07001099 goto done;
Chris Wilsonbc866252013-07-21 16:00:03 +01001100 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001101 }
1102
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001103 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001104 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001105 ret = -EBUSY;
1106 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001107 }
1108
Jim Bridee058c942015-05-27 10:21:48 -07001109done:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001110 /* Check for timeout or receive error.
1111 * Timeouts occur when the sink is not connected
1112 */
Keith Packarda5b3da52009-06-11 22:30:32 -07001113 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001114 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001115 ret = -EIO;
1116 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -07001117 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001118
1119 /* Timeouts occur when the device isn't connected, so they're
1120 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -07001121 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Zhao Yakui28c97732009-10-09 11:39:41 +08001122 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001123 ret = -ETIMEDOUT;
1124 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001125 }
1126
1127 /* Unload any bytes sent back from the other side */
1128 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
1129 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Rodrigo Vivi14e01882015-12-10 11:12:27 -08001130
1131 /*
1132 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1133 * We have no idea of what happened so we return -EBUSY so
1134 * drm layer takes care for the necessary retries.
1135 */
1136 if (recv_bytes == 0 || recv_bytes > 20) {
1137 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1138 recv_bytes);
1139 /*
1140 * FIXME: This patch was created on top of a series that
1141 * organize the retries at drm level. There EBUSY should
1142 * also take care for 1ms wait before retrying.
1143 * That aux retries re-org is still needed and after that is
1144 * merged we remove this sleep from here.
1145 */
1146 usleep_range(1000, 1500);
1147 ret = -EBUSY;
1148 goto out;
1149 }
1150
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001151 if (recv_bytes > recv_size)
1152 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -04001153
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001154 for (i = 0; i < recv_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001155 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001156 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001157
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001158 ret = recv_bytes;
1159out:
1160 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1161
Jani Nikula884f19e2014-03-14 16:51:14 +02001162 if (vdd)
1163 edp_panel_vdd_off(intel_dp, false);
1164
Ville Syrjälä773538e82014-09-04 14:54:56 +03001165 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001166
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001167 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001168}
1169
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001170#define BARE_ADDRESS_SIZE 3
1171#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +02001172static ssize_t
1173intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001174{
Jani Nikula9d1a1032014-03-14 16:51:15 +02001175 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1176 uint8_t txbuf[20], rxbuf[20];
1177 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001178 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001179
Ville Syrjäläd2d9cbb2015-03-19 11:44:06 +02001180 txbuf[0] = (msg->request << 4) |
1181 ((msg->address >> 16) & 0xf);
1182 txbuf[1] = (msg->address >> 8) & 0xff;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001183 txbuf[2] = msg->address & 0xff;
1184 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001185
Jani Nikula9d1a1032014-03-14 16:51:15 +02001186 switch (msg->request & ~DP_AUX_I2C_MOT) {
1187 case DP_AUX_NATIVE_WRITE:
1188 case DP_AUX_I2C_WRITE:
Ville Syrjäläc1e741222015-08-27 17:23:27 +03001189 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001190 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001191 rxsize = 2; /* 0 or 1 data bytes */
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001192
Jani Nikula9d1a1032014-03-14 16:51:15 +02001193 if (WARN_ON(txsize > 20))
1194 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001195
Ville Syrjälädd788092016-07-28 17:55:04 +03001196 WARN_ON(!msg->buffer != !msg->size);
1197
Imre Deakd81a67c2016-01-29 14:52:26 +02001198 if (msg->buffer)
1199 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001200
Jani Nikula9d1a1032014-03-14 16:51:15 +02001201 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1202 if (ret > 0) {
1203 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001204
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001205 if (ret > 1) {
1206 /* Number of bytes written in a short write. */
1207 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1208 } else {
1209 /* Return payload size. */
1210 ret = msg->size;
1211 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001212 }
Jani Nikula9d1a1032014-03-14 16:51:15 +02001213 break;
1214
1215 case DP_AUX_NATIVE_READ:
1216 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001217 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001218 rxsize = msg->size + 1;
1219
1220 if (WARN_ON(rxsize > 20))
1221 return -E2BIG;
1222
1223 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1224 if (ret > 0) {
1225 msg->reply = rxbuf[0] >> 4;
1226 /*
1227 * Assume happy day, and copy the data. The caller is
1228 * expected to check msg->reply before touching it.
1229 *
1230 * Return payload size.
1231 */
1232 ret--;
1233 memcpy(msg->buffer, rxbuf + 1, ret);
1234 }
1235 break;
1236
1237 default:
1238 ret = -EINVAL;
1239 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001240 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001241
Jani Nikula9d1a1032014-03-14 16:51:15 +02001242 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001243}
1244
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001245static enum port intel_aux_port(struct drm_i915_private *dev_priv,
1246 enum port port)
1247{
1248 const struct ddi_vbt_port_info *info =
1249 &dev_priv->vbt.ddi_port_info[port];
1250 enum port aux_port;
1251
1252 if (!info->alternate_aux_channel) {
1253 DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
1254 port_name(port), port_name(port));
1255 return port;
1256 }
1257
1258 switch (info->alternate_aux_channel) {
1259 case DP_AUX_A:
1260 aux_port = PORT_A;
1261 break;
1262 case DP_AUX_B:
1263 aux_port = PORT_B;
1264 break;
1265 case DP_AUX_C:
1266 aux_port = PORT_C;
1267 break;
1268 case DP_AUX_D:
1269 aux_port = PORT_D;
1270 break;
1271 default:
1272 MISSING_CASE(info->alternate_aux_channel);
1273 aux_port = PORT_A;
1274 break;
1275 }
1276
1277 DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
1278 port_name(aux_port), port_name(port));
1279
1280 return aux_port;
1281}
1282
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001283static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001284 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001285{
1286 switch (port) {
1287 case PORT_B:
1288 case PORT_C:
1289 case PORT_D:
1290 return DP_AUX_CH_CTL(port);
1291 default:
1292 MISSING_CASE(port);
1293 return DP_AUX_CH_CTL(PORT_B);
1294 }
1295}
1296
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001297static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001298 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001299{
1300 switch (port) {
1301 case PORT_B:
1302 case PORT_C:
1303 case PORT_D:
1304 return DP_AUX_CH_DATA(port, index);
1305 default:
1306 MISSING_CASE(port);
1307 return DP_AUX_CH_DATA(PORT_B, index);
1308 }
1309}
1310
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001311static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001312 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001313{
1314 switch (port) {
1315 case PORT_A:
1316 return DP_AUX_CH_CTL(port);
1317 case PORT_B:
1318 case PORT_C:
1319 case PORT_D:
1320 return PCH_DP_AUX_CH_CTL(port);
1321 default:
1322 MISSING_CASE(port);
1323 return DP_AUX_CH_CTL(PORT_A);
1324 }
1325}
1326
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001327static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001328 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001329{
1330 switch (port) {
1331 case PORT_A:
1332 return DP_AUX_CH_DATA(port, index);
1333 case PORT_B:
1334 case PORT_C:
1335 case PORT_D:
1336 return PCH_DP_AUX_CH_DATA(port, index);
1337 default:
1338 MISSING_CASE(port);
1339 return DP_AUX_CH_DATA(PORT_A, index);
1340 }
1341}
1342
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001343static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001344 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001345{
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001346 switch (port) {
1347 case PORT_A:
1348 case PORT_B:
1349 case PORT_C:
1350 case PORT_D:
1351 return DP_AUX_CH_CTL(port);
1352 default:
1353 MISSING_CASE(port);
1354 return DP_AUX_CH_CTL(PORT_A);
1355 }
1356}
1357
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001358static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001359 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001360{
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001361 switch (port) {
1362 case PORT_A:
1363 case PORT_B:
1364 case PORT_C:
1365 case PORT_D:
1366 return DP_AUX_CH_DATA(port, index);
1367 default:
1368 MISSING_CASE(port);
1369 return DP_AUX_CH_DATA(PORT_A, index);
1370 }
1371}
1372
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001373static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001374 enum port port)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001375{
1376 if (INTEL_INFO(dev_priv)->gen >= 9)
1377 return skl_aux_ctl_reg(dev_priv, port);
1378 else if (HAS_PCH_SPLIT(dev_priv))
1379 return ilk_aux_ctl_reg(dev_priv, port);
1380 else
1381 return g4x_aux_ctl_reg(dev_priv, port);
1382}
1383
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001384static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001385 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001386{
1387 if (INTEL_INFO(dev_priv)->gen >= 9)
1388 return skl_aux_data_reg(dev_priv, port, index);
1389 else if (HAS_PCH_SPLIT(dev_priv))
1390 return ilk_aux_data_reg(dev_priv, port, index);
1391 else
1392 return g4x_aux_data_reg(dev_priv, port, index);
1393}
1394
1395static void intel_aux_reg_init(struct intel_dp *intel_dp)
1396{
1397 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001398 enum port port = intel_aux_port(dev_priv,
1399 dp_to_dig_port(intel_dp)->port);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001400 int i;
1401
1402 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1403 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1404 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1405}
1406
Jani Nikula9d1a1032014-03-14 16:51:15 +02001407static void
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001408intel_dp_aux_fini(struct intel_dp *intel_dp)
1409{
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001410 kfree(intel_dp->aux.name);
1411}
1412
Chris Wilson7a418e32016-06-24 14:00:14 +01001413static void
Mika Kaholab6339582016-09-09 14:10:52 +03001414intel_dp_aux_init(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001415{
Jani Nikula33ad6622014-03-14 16:51:16 +02001416 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1417 enum port port = intel_dig_port->port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001418
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001419 intel_aux_reg_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01001420 drm_dp_aux_init(&intel_dp->aux);
David Flynn8316f332010-12-08 16:10:21 +00001421
Chris Wilson7a418e32016-06-24 14:00:14 +01001422 /* Failure to allocate our preferred name is not critical */
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001423 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
Jani Nikula9d1a1032014-03-14 16:51:15 +02001424 intel_dp->aux.transfer = intel_dp_aux_transfer;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001425}
1426
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001427bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301428{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001429 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Navare, Manasi D577c5432016-09-27 16:36:53 -07001430 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001431
Navare, Manasi D577c5432016-09-27 16:36:53 -07001432 if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
1433 IS_BROADWELL(dev_priv) || (INTEL_GEN(dev_priv) >= 9))
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301434 return true;
1435 else
1436 return false;
1437}
1438
Daniel Vetter0e503382014-07-04 11:26:04 -03001439static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001440intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001441 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001442{
1443 struct drm_device *dev = encoder->base.dev;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001444 struct drm_i915_private *dev_priv = to_i915(dev);
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001445 const struct dp_link_dpll *divisor = NULL;
1446 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001447
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001448 if (IS_G4X(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001449 divisor = gen4_dpll;
1450 count = ARRAY_SIZE(gen4_dpll);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001451 } else if (HAS_PCH_SPLIT(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001452 divisor = pch_dpll;
1453 count = ARRAY_SIZE(pch_dpll);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001454 } else if (IS_CHERRYVIEW(dev_priv)) {
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001455 divisor = chv_dpll;
1456 count = ARRAY_SIZE(chv_dpll);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001457 } else if (IS_VALLEYVIEW(dev_priv)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001458 divisor = vlv_dpll;
1459 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001460 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001461
1462 if (divisor && count) {
1463 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001464 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001465 pipe_config->dpll = divisor[i].dpll;
1466 pipe_config->clock_set = true;
1467 break;
1468 }
1469 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001470 }
1471}
1472
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001473static void snprintf_int_array(char *str, size_t len,
1474 const int *array, int nelem)
1475{
1476 int i;
1477
1478 str[0] = '\0';
1479
1480 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001481 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001482 if (r >= len)
1483 return;
1484 str += r;
1485 len -= r;
1486 }
1487}
1488
1489static void intel_dp_print_rates(struct intel_dp *intel_dp)
1490{
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001491 const int *source_rates, *sink_rates;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001492 int source_len, sink_len, common_len;
1493 int common_rates[DP_MAX_SUPPORTED_RATES];
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001494 char str[128]; /* FIXME: too big for stack? */
1495
1496 if ((drm_debug & DRM_UT_KMS) == 0)
1497 return;
1498
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001499 source_len = intel_dp_source_rates(intel_dp, &source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001500 snprintf_int_array(str, sizeof(str), source_rates, source_len);
1501 DRM_DEBUG_KMS("source rates: %s\n", str);
1502
1503 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
1504 snprintf_int_array(str, sizeof(str), sink_rates, sink_len);
1505 DRM_DEBUG_KMS("sink rates: %s\n", str);
1506
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001507 common_len = intel_dp_common_rates(intel_dp, common_rates);
1508 snprintf_int_array(str, sizeof(str), common_rates, common_len);
1509 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001510}
1511
Imre Deak489375c2016-10-24 19:33:31 +03001512bool
Imre Deak7b3fc172016-10-25 16:12:39 +03001513__intel_dp_read_desc(struct intel_dp *intel_dp, struct intel_dp_desc *desc)
Mika Kahola0e390a32016-09-09 14:10:53 +03001514{
Imre Deak7b3fc172016-10-25 16:12:39 +03001515 u32 base = drm_dp_is_branch(intel_dp->dpcd) ? DP_BRANCH_OUI :
1516 DP_SINK_OUI;
Mika Kahola0e390a32016-09-09 14:10:53 +03001517
Imre Deak7b3fc172016-10-25 16:12:39 +03001518 return drm_dp_dpcd_read(&intel_dp->aux, base, desc, sizeof(*desc)) ==
1519 sizeof(*desc);
Mika Kahola0e390a32016-09-09 14:10:53 +03001520}
1521
Imre Deak12a47a422016-10-24 19:33:29 +03001522bool intel_dp_read_desc(struct intel_dp *intel_dp)
Mika Kahola1a2724f2016-09-09 14:10:54 +03001523{
Imre Deak7b3fc172016-10-25 16:12:39 +03001524 struct intel_dp_desc *desc = &intel_dp->desc;
1525 bool oui_sup = intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] &
1526 DP_OUI_SUPPORT;
1527 int dev_id_len;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001528
Imre Deak7b3fc172016-10-25 16:12:39 +03001529 if (!__intel_dp_read_desc(intel_dp, desc))
1530 return false;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001531
Imre Deak7b3fc172016-10-25 16:12:39 +03001532 dev_id_len = strnlen(desc->device_id, sizeof(desc->device_id));
1533 DRM_DEBUG_KMS("DP %s: OUI %*phD%s dev-ID %*pE HW-rev %d.%d SW-rev %d.%d\n",
1534 drm_dp_is_branch(intel_dp->dpcd) ? "branch" : "sink",
1535 (int)sizeof(desc->oui), desc->oui, oui_sup ? "" : "(NS)",
1536 dev_id_len, desc->device_id,
1537 desc->hw_rev >> 4, desc->hw_rev & 0xf,
1538 desc->sw_major_rev, desc->sw_minor_rev);
Mika Kahola1a2724f2016-09-09 14:10:54 +03001539
Imre Deak7b3fc172016-10-25 16:12:39 +03001540 return true;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001541}
1542
Ville Syrjäläf4896f12015-03-12 17:10:27 +02001543static int rate_to_index(int find, const int *rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301544{
1545 int i = 0;
1546
1547 for (i = 0; i < DP_MAX_SUPPORTED_RATES; ++i)
1548 if (find == rates[i])
1549 break;
1550
1551 return i;
1552}
1553
Ville Syrjälä50fec212015-03-12 17:10:34 +02001554int
1555intel_dp_max_link_rate(struct intel_dp *intel_dp)
1556{
1557 int rates[DP_MAX_SUPPORTED_RATES] = {};
1558 int len;
1559
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001560 len = intel_dp_common_rates(intel_dp, rates);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001561 if (WARN_ON(len <= 0))
1562 return 162000;
1563
Ville Syrjälä1354f732016-07-28 17:50:45 +03001564 return rates[len - 1];
Ville Syrjälä50fec212015-03-12 17:10:34 +02001565}
1566
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001567int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1568{
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001569 return rate_to_index(rate, intel_dp->sink_rates);
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001570}
1571
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001572void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1573 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001574{
1575 if (intel_dp->num_sink_rates) {
1576 *link_bw = 0;
1577 *rate_select =
1578 intel_dp_rate_select(intel_dp, port_clock);
1579 } else {
1580 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1581 *rate_select = 0;
1582 }
1583}
1584
Jani Nikulaf580bea2016-09-15 16:28:52 +03001585static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1586 struct intel_crtc_state *pipe_config)
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001587{
1588 int bpp, bpc;
1589
1590 bpp = pipe_config->pipe_bpp;
1591 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1592
1593 if (bpc > 0)
1594 bpp = min(bpp, 3*bpc);
1595
1596 return bpp;
1597}
1598
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001599bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001600intel_dp_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001601 struct intel_crtc_state *pipe_config,
1602 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001603{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001604 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001605 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001606 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001607 enum port port = dp_to_dig_port(intel_dp)->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001608 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001609 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001610 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001611 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001612 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001613 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001614 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301615 int max_clock;
Daniel Vetter083f9562012-04-20 20:23:49 +02001616 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001617 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001618 int common_rates[DP_MAX_SUPPORTED_RATES] = {};
1619 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001620 uint8_t link_bw, rate_select;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301621
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001622 common_len = intel_dp_common_rates(intel_dp, common_rates);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301623
1624 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001625 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301626
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001627 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001628
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001629 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001630 pipe_config->has_pch_encoder = true;
1631
Vandana Kannanf769cd22014-08-05 07:51:22 -07001632 pipe_config->has_drrs = false;
Jani Nikula9fcb1702015-05-05 16:32:12 +03001633 pipe_config->has_audio = intel_dp->has_audio && port != PORT_A;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001634
Jani Nikuladd06f902012-10-19 14:51:50 +03001635 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1636 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
1637 adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001638
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001639 if (INTEL_GEN(dev_priv) >= 9) {
Chandra Kondurua1b22782015-04-07 15:28:45 -07001640 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001641 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001642 if (ret)
1643 return ret;
1644 }
1645
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001646 if (HAS_GMCH_DISPLAY(dev_priv))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001647 intel_gmch_panel_fitting(intel_crtc, pipe_config,
1648 intel_connector->panel.fitting_mode);
1649 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001650 intel_pch_panel_fitting(intel_crtc, pipe_config,
1651 intel_connector->panel.fitting_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001652 }
1653
Daniel Vettercb1793c2012-06-04 18:39:21 +02001654 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001655 return false;
1656
Daniel Vetter083f9562012-04-20 20:23:49 +02001657 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301658 "max bw %d pixel clock %iKHz\n",
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001659 max_lane_count, common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001660 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001661
Daniel Vetter36008362013-03-27 00:44:59 +01001662 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1663 * bpc in between. */
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001664 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
Jani Nikula56071a22014-05-06 14:56:52 +03001665 if (is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301666
1667 /* Get bpp from vbt only for panels that dont have bpp in edid */
1668 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001669 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001670 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001671 dev_priv->vbt.edp.bpp);
1672 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001673 }
1674
Jani Nikula344c5bb2014-09-09 11:25:13 +03001675 /*
1676 * Use the maximum clock and number of lanes the eDP panel
1677 * advertizes being capable of. The panels are generally
1678 * designed to support only a single clock and lane
1679 * configuration, and typically these values correspond to the
1680 * native resolution of the panel.
1681 */
1682 min_lane_count = max_lane_count;
1683 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001684 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001685
Daniel Vetter36008362013-03-27 00:44:59 +01001686 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001687 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1688 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001689
Dave Airliec6930992014-07-14 11:04:39 +10001690 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301691 for (lane_count = min_lane_count;
1692 lane_count <= max_lane_count;
1693 lane_count <<= 1) {
1694
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001695 link_clock = common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001696 link_avail = intel_dp_max_data_rate(link_clock,
1697 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001698
Daniel Vetter36008362013-03-27 00:44:59 +01001699 if (mode_rate <= link_avail) {
1700 goto found;
1701 }
1702 }
1703 }
1704 }
1705
1706 return false;
1707
1708found:
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001709 if (intel_dp->color_range_auto) {
1710 /*
1711 * See:
1712 * CEA-861-E - 5.1 Default Encoding Parameters
1713 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1714 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001715 pipe_config->limited_color_range =
1716 bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1;
1717 } else {
1718 pipe_config->limited_color_range =
1719 intel_dp->limited_color_range;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001720 }
1721
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001722 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301723
Daniel Vetter657445f2013-05-04 10:09:18 +02001724 pipe_config->pipe_bpp = bpp;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001725 pipe_config->port_clock = common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001726
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001727 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1728 &link_bw, &rate_select);
1729
1730 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1731 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001732 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001733 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1734 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001735
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001736 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001737 adjusted_mode->crtc_clock,
1738 pipe_config->port_clock,
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001739 &pipe_config->dp_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001740
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301741 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301742 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001743 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301744 intel_link_compute_m_n(bpp, lane_count,
1745 intel_connector->panel.downclock_mode->clock,
1746 pipe_config->port_clock,
1747 &pipe_config->dp_m2_n2);
1748 }
1749
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001750 /*
1751 * DPLL0 VCO may need to be adjusted to get the correct
1752 * clock for eDP. This will affect cdclk as well.
1753 */
1754 if (is_edp(intel_dp) &&
1755 (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))) {
1756 int vco;
1757
1758 switch (pipe_config->port_clock / 2) {
1759 case 108000:
1760 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001761 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001762 break;
1763 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001764 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001765 break;
1766 }
1767
1768 to_intel_atomic_state(pipe_config->base.state)->cdclk_pll_vco = vco;
1769 }
1770
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001771 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001772 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001773
Daniel Vetter36008362013-03-27 00:44:59 +01001774 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001775}
1776
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001777void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001778 int link_rate, uint8_t lane_count,
1779 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001780{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001781 intel_dp->link_rate = link_rate;
1782 intel_dp->lane_count = lane_count;
1783 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001784}
1785
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001786static void intel_dp_prepare(struct intel_encoder *encoder,
1787 struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001788{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001789 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001790 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001791 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001792 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001793 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001794 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001795
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001796 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1797 pipe_config->lane_count,
1798 intel_crtc_has_type(pipe_config,
1799 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001800
Keith Packard417e8222011-11-01 19:54:11 -07001801 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001802 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001803 *
1804 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001805 * SNB CPU
1806 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001807 * CPT PCH
1808 *
1809 * IBX PCH and CPU are the same for almost everything,
1810 * except that the CPU DP PLL is configured in this
1811 * register
1812 *
1813 * CPT PCH is quite different, having many bits moved
1814 * to the TRANS_DP_CTL register instead. That
1815 * configuration happens (oddly) in ironlake_pch_enable
1816 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001817
Keith Packard417e8222011-11-01 19:54:11 -07001818 /* Preserve the BIOS-computed detected bit. This is
1819 * supposed to be read-only.
1820 */
1821 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001822
Keith Packard417e8222011-11-01 19:54:11 -07001823 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001824 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001825 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001826
Keith Packard417e8222011-11-01 19:54:11 -07001827 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001828
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001829 if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001830 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1831 intel_dp->DP |= DP_SYNC_HS_HIGH;
1832 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1833 intel_dp->DP |= DP_SYNC_VS_HIGH;
1834 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1835
Jani Nikula6aba5b62013-10-04 15:08:10 +03001836 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001837 intel_dp->DP |= DP_ENHANCED_FRAMING;
1838
Daniel Vetter7c62a162013-06-01 17:16:20 +02001839 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001840 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001841 u32 trans_dp;
1842
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001843 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001844
1845 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1846 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1847 trans_dp |= TRANS_DP_ENH_FRAMING;
1848 else
1849 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1850 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001851 } else {
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02001852 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001853 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001854
1855 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1856 intel_dp->DP |= DP_SYNC_HS_HIGH;
1857 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1858 intel_dp->DP |= DP_SYNC_VS_HIGH;
1859 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1860
Jani Nikula6aba5b62013-10-04 15:08:10 +03001861 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001862 intel_dp->DP |= DP_ENHANCED_FRAMING;
1863
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001864 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001865 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001866 else if (crtc->pipe == PIPE_B)
1867 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001868 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001869}
1870
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001871#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1872#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001873
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001874#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1875#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001876
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001877#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1878#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001879
Imre Deakde9c1b62016-06-16 20:01:46 +03001880static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
1881 struct intel_dp *intel_dp);
1882
Daniel Vetter4be73782014-01-17 14:39:48 +01001883static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001884 u32 mask,
1885 u32 value)
1886{
Paulo Zanoni30add222012-10-26 19:05:45 -02001887 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001888 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001889 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001890
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001891 lockdep_assert_held(&dev_priv->pps_mutex);
1892
Imre Deakde9c1b62016-06-16 20:01:46 +03001893 intel_pps_verify_state(dev_priv, intel_dp);
1894
Jani Nikulabf13e812013-09-06 07:40:05 +03001895 pp_stat_reg = _pp_stat_reg(intel_dp);
1896 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001897
1898 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001899 mask, value,
1900 I915_READ(pp_stat_reg),
1901 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001902
Chris Wilson9036ff02016-06-30 15:33:09 +01001903 if (intel_wait_for_register(dev_priv,
1904 pp_stat_reg, mask, value,
1905 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001906 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001907 I915_READ(pp_stat_reg),
1908 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001909
1910 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001911}
1912
Daniel Vetter4be73782014-01-17 14:39:48 +01001913static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001914{
1915 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001916 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001917}
1918
Daniel Vetter4be73782014-01-17 14:39:48 +01001919static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001920{
Keith Packardbd943152011-09-18 23:09:52 -07001921 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001922 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001923}
Keith Packardbd943152011-09-18 23:09:52 -07001924
Daniel Vetter4be73782014-01-17 14:39:48 +01001925static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001926{
Abhay Kumard28d4732016-01-22 17:39:04 -08001927 ktime_t panel_power_on_time;
1928 s64 panel_power_off_duration;
1929
Keith Packard99ea7122011-11-01 19:57:50 -07001930 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001931
Abhay Kumard28d4732016-01-22 17:39:04 -08001932 /* take the difference of currrent time and panel power off time
1933 * and then make panel wait for t11_t12 if needed. */
1934 panel_power_on_time = ktime_get_boottime();
1935 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1936
Paulo Zanonidce56b32013-12-19 14:29:40 -02001937 /* When we disable the VDD override bit last we have to do the manual
1938 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08001939 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
1940 wait_remaining_ms_from_jiffies(jiffies,
1941 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001942
Daniel Vetter4be73782014-01-17 14:39:48 +01001943 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001944}
Keith Packardbd943152011-09-18 23:09:52 -07001945
Daniel Vetter4be73782014-01-17 14:39:48 +01001946static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001947{
1948 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1949 intel_dp->backlight_on_delay);
1950}
1951
Daniel Vetter4be73782014-01-17 14:39:48 +01001952static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001953{
1954 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
1955 intel_dp->backlight_off_delay);
1956}
Keith Packard99ea7122011-11-01 19:57:50 -07001957
Keith Packard832dd3c2011-11-01 19:34:06 -07001958/* Read the current pp_control value, unlocking the register if it
1959 * is locked
1960 */
1961
Jesse Barnes453c5422013-03-28 09:55:41 -07001962static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07001963{
Jesse Barnes453c5422013-03-28 09:55:41 -07001964 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001965 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07001966 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07001967
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001968 lockdep_assert_held(&dev_priv->pps_mutex);
1969
Jani Nikulabf13e812013-09-06 07:40:05 +03001970 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03001971 if (WARN_ON(!HAS_DDI(dev_priv) &&
1972 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05301973 control &= ~PANEL_UNLOCK_MASK;
1974 control |= PANEL_UNLOCK_REGS;
1975 }
Keith Packard832dd3c2011-11-01 19:34:06 -07001976 return control;
Keith Packardbd943152011-09-18 23:09:52 -07001977}
1978
Ville Syrjälä951468f2014-09-04 14:55:31 +03001979/*
1980 * Must be paired with edp_panel_vdd_off().
1981 * Must hold pps_mutex around the whole on/off sequence.
1982 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
1983 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001984static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001985{
Paulo Zanoni30add222012-10-26 19:05:45 -02001986 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001987 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1988 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001989 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001990 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08001991 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001992 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001993 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08001994
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001995 lockdep_assert_held(&dev_priv->pps_mutex);
1996
Keith Packard97af61f572011-09-28 16:23:51 -07001997 if (!is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001998 return false;
Keith Packardbd943152011-09-18 23:09:52 -07001999
Egbert Eich2c623c12014-11-25 12:54:57 +01002000 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002001 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07002002
Daniel Vetter4be73782014-01-17 14:39:48 +01002003 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002004 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002005
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002006 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002007 intel_display_power_get(dev_priv, power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002008
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002009 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
2010 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07002011
Daniel Vetter4be73782014-01-17 14:39:48 +01002012 if (!edp_have_panel_power(intel_dp))
2013 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07002014
Jesse Barnes453c5422013-03-28 09:55:41 -07002015 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002016 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07002017
Jani Nikulabf13e812013-09-06 07:40:05 +03002018 pp_stat_reg = _pp_stat_reg(intel_dp);
2019 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002020
2021 I915_WRITE(pp_ctrl_reg, pp);
2022 POSTING_READ(pp_ctrl_reg);
2023 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2024 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07002025 /*
2026 * If the panel wasn't on, delay before accessing aux channel
2027 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002028 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002029 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
2030 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07002031 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07002032 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002033
2034 return need_to_disable;
2035}
2036
Ville Syrjälä951468f2014-09-04 14:55:31 +03002037/*
2038 * Must be paired with intel_edp_panel_vdd_off() or
2039 * intel_edp_panel_off().
2040 * Nested calls to these functions are not allowed since
2041 * we drop the lock. Caller must use some higher level
2042 * locking to prevent nested calls from other threads.
2043 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01002044void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002045{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002046 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002047
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002048 if (!is_edp(intel_dp))
2049 return;
2050
Ville Syrjälä773538e82014-09-04 14:54:56 +03002051 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002052 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002053 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002054
Rob Clarke2c719b2014-12-15 13:56:32 -05002055 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002056 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08002057}
2058
Daniel Vetter4be73782014-01-17 14:39:48 +01002059static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002060{
Paulo Zanoni30add222012-10-26 19:05:45 -02002061 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002062 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002063 struct intel_digital_port *intel_dig_port =
2064 dp_to_dig_port(intel_dp);
2065 struct intel_encoder *intel_encoder = &intel_dig_port->base;
2066 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08002067 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002068 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002069
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002070 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002071
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002072 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002073
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002074 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002075 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002076
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002077 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2078 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002079
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002080 pp = ironlake_get_pp_control(intel_dp);
2081 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002082
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002083 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2084 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002085
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002086 I915_WRITE(pp_ctrl_reg, pp);
2087 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002088
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002089 /* Make sure sequencer is idle before allowing subsequent activity */
2090 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2091 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002092
Imre Deak5a162e22016-08-10 14:07:30 +03002093 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002094 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002095
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002096 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002097 intel_display_power_put(dev_priv, power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002098}
2099
Daniel Vetter4be73782014-01-17 14:39:48 +01002100static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002101{
2102 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2103 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002104
Ville Syrjälä773538e82014-09-04 14:54:56 +03002105 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002106 if (!intel_dp->want_panel_vdd)
2107 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002108 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002109}
2110
Imre Deakaba86892014-07-30 15:57:31 +03002111static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2112{
2113 unsigned long delay;
2114
2115 /*
2116 * Queue the timer to fire a long time from now (relative to the power
2117 * down delay) to keep the panel power up across a sequence of
2118 * operations.
2119 */
2120 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2121 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2122}
2123
Ville Syrjälä951468f2014-09-04 14:55:31 +03002124/*
2125 * Must be paired with edp_panel_vdd_on().
2126 * Must hold pps_mutex around the whole on/off sequence.
2127 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2128 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002129static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002130{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002131 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002132
2133 lockdep_assert_held(&dev_priv->pps_mutex);
2134
Keith Packard97af61f572011-09-28 16:23:51 -07002135 if (!is_edp(intel_dp))
2136 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002137
Rob Clarke2c719b2014-12-15 13:56:32 -05002138 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002139 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002140
Keith Packardbd943152011-09-18 23:09:52 -07002141 intel_dp->want_panel_vdd = false;
2142
Imre Deakaba86892014-07-30 15:57:31 +03002143 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002144 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002145 else
2146 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002147}
2148
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002149static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002150{
Paulo Zanoni30add222012-10-26 19:05:45 -02002151 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002152 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002153 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002154 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002155
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002156 lockdep_assert_held(&dev_priv->pps_mutex);
2157
Keith Packard97af61f572011-09-28 16:23:51 -07002158 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002159 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002160
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002161 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2162 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002163
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002164 if (WARN(edp_have_panel_power(intel_dp),
2165 "eDP port %c panel power already on\n",
2166 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002167 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002168
Daniel Vetter4be73782014-01-17 14:39:48 +01002169 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002170
Jani Nikulabf13e812013-09-06 07:40:05 +03002171 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002172 pp = ironlake_get_pp_control(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002173 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002174 /* ILK workaround: disable reset around power sequence */
2175 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002176 I915_WRITE(pp_ctrl_reg, pp);
2177 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002178 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002179
Imre Deak5a162e22016-08-10 14:07:30 +03002180 pp |= PANEL_POWER_ON;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002181 if (!IS_GEN5(dev_priv))
Keith Packard99ea7122011-11-01 19:57:50 -07002182 pp |= PANEL_POWER_RESET;
2183
Jesse Barnes453c5422013-03-28 09:55:41 -07002184 I915_WRITE(pp_ctrl_reg, pp);
2185 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002186
Daniel Vetter4be73782014-01-17 14:39:48 +01002187 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002188 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002189
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002190 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002191 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002192 I915_WRITE(pp_ctrl_reg, pp);
2193 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002194 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002195}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002196
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002197void intel_edp_panel_on(struct intel_dp *intel_dp)
2198{
2199 if (!is_edp(intel_dp))
2200 return;
2201
2202 pps_lock(intel_dp);
2203 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002204 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002205}
2206
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002207
2208static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002209{
Imre Deak4e6e1a52014-03-27 17:45:11 +02002210 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2211 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanoni30add222012-10-26 19:05:45 -02002212 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002213 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002214 enum intel_display_power_domain power_domain;
Keith Packard99ea7122011-11-01 19:57:50 -07002215 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002216 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002217
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002218 lockdep_assert_held(&dev_priv->pps_mutex);
2219
Keith Packard97af61f572011-09-28 16:23:51 -07002220 if (!is_edp(intel_dp))
2221 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002222
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002223 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2224 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002225
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002226 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2227 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002228
Jesse Barnes453c5422013-03-28 09:55:41 -07002229 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002230 /* We need to switch off panel power _and_ force vdd, for otherwise some
2231 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002232 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002233 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002234
Jani Nikulabf13e812013-09-06 07:40:05 +03002235 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002236
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002237 intel_dp->want_panel_vdd = false;
2238
Jesse Barnes453c5422013-03-28 09:55:41 -07002239 I915_WRITE(pp_ctrl_reg, pp);
2240 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002241
Abhay Kumard28d4732016-01-22 17:39:04 -08002242 intel_dp->panel_power_off_time = ktime_get_boottime();
Daniel Vetter4be73782014-01-17 14:39:48 +01002243 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002244
2245 /* We got a reference when we enabled the VDD. */
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002246 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002247 intel_display_power_put(dev_priv, power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002248}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002249
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002250void intel_edp_panel_off(struct intel_dp *intel_dp)
2251{
2252 if (!is_edp(intel_dp))
2253 return;
2254
2255 pps_lock(intel_dp);
2256 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002257 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002258}
2259
Jani Nikula1250d102014-08-12 17:11:39 +03002260/* Enable backlight in the panel power control. */
2261static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002262{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002263 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2264 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002265 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002266 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002267 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002268
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002269 /*
2270 * If we enable the backlight right away following a panel power
2271 * on, we may see slight flicker as the panel syncs with the eDP
2272 * link. So delay a bit to make sure the image is solid before
2273 * allowing it to appear.
2274 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002275 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002276
Ville Syrjälä773538e82014-09-04 14:54:56 +03002277 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002278
Jesse Barnes453c5422013-03-28 09:55:41 -07002279 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002280 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002281
Jani Nikulabf13e812013-09-06 07:40:05 +03002282 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002283
2284 I915_WRITE(pp_ctrl_reg, pp);
2285 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002286
Ville Syrjälä773538e82014-09-04 14:54:56 +03002287 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002288}
2289
Jani Nikula1250d102014-08-12 17:11:39 +03002290/* Enable backlight PWM and backlight PP control. */
2291void intel_edp_backlight_on(struct intel_dp *intel_dp)
2292{
2293 if (!is_edp(intel_dp))
2294 return;
2295
2296 DRM_DEBUG_KMS("\n");
2297
2298 intel_panel_enable_backlight(intel_dp->attached_connector);
2299 _intel_edp_backlight_on(intel_dp);
2300}
2301
2302/* Disable backlight in the panel power control. */
2303static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002304{
Paulo Zanoni30add222012-10-26 19:05:45 -02002305 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002306 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002307 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002308 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002309
Keith Packardf01eca22011-09-28 16:48:10 -07002310 if (!is_edp(intel_dp))
2311 return;
2312
Ville Syrjälä773538e82014-09-04 14:54:56 +03002313 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002314
Jesse Barnes453c5422013-03-28 09:55:41 -07002315 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002316 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002317
Jani Nikulabf13e812013-09-06 07:40:05 +03002318 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002319
2320 I915_WRITE(pp_ctrl_reg, pp);
2321 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002322
Ville Syrjälä773538e82014-09-04 14:54:56 +03002323 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002324
Paulo Zanonidce56b32013-12-19 14:29:40 -02002325 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002326 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002327}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002328
Jani Nikula1250d102014-08-12 17:11:39 +03002329/* Disable backlight PP control and backlight PWM. */
2330void intel_edp_backlight_off(struct intel_dp *intel_dp)
2331{
2332 if (!is_edp(intel_dp))
2333 return;
2334
2335 DRM_DEBUG_KMS("\n");
2336
2337 _intel_edp_backlight_off(intel_dp);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002338 intel_panel_disable_backlight(intel_dp->attached_connector);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002339}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002340
Jani Nikula73580fb72014-08-12 17:11:41 +03002341/*
2342 * Hook for controlling the panel power control backlight through the bl_power
2343 * sysfs attribute. Take care to handle multiple calls.
2344 */
2345static void intel_edp_backlight_power(struct intel_connector *connector,
2346 bool enable)
2347{
2348 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002349 bool is_enabled;
2350
Ville Syrjälä773538e82014-09-04 14:54:56 +03002351 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002352 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002353 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002354
2355 if (is_enabled == enable)
2356 return;
2357
Jani Nikula23ba9372014-08-27 14:08:43 +03002358 DRM_DEBUG_KMS("panel power control backlight %s\n",
2359 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002360
2361 if (enable)
2362 _intel_edp_backlight_on(intel_dp);
2363 else
2364 _intel_edp_backlight_off(intel_dp);
2365}
2366
Ville Syrjälä64e10772015-10-29 21:26:01 +02002367static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2368{
2369 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2370 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2371 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2372
2373 I915_STATE_WARN(cur_state != state,
2374 "DP port %c state assertion failure (expected %s, current %s)\n",
2375 port_name(dig_port->port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002376 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002377}
2378#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2379
2380static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2381{
2382 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2383
2384 I915_STATE_WARN(cur_state != state,
2385 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002386 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002387}
2388#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2389#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2390
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002391static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2392 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002393{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002394 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002395 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002396
Ville Syrjälä64e10772015-10-29 21:26:01 +02002397 assert_pipe_disabled(dev_priv, crtc->pipe);
2398 assert_dp_port_disabled(intel_dp);
2399 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002400
Ville Syrjäläabfce942015-10-29 21:26:03 +02002401 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002402 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002403
2404 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2405
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002406 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002407 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2408 else
2409 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2410
2411 I915_WRITE(DP_A, intel_dp->DP);
2412 POSTING_READ(DP_A);
2413 udelay(500);
2414
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002415 /*
2416 * [DevILK] Work around required when enabling DP PLL
2417 * while a pipe is enabled going to FDI:
2418 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2419 * 2. Program DP PLL enable
2420 */
2421 if (IS_GEN5(dev_priv))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02002422 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002423
Daniel Vetter07679352012-09-06 22:15:42 +02002424 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002425
Daniel Vetter07679352012-09-06 22:15:42 +02002426 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002427 POSTING_READ(DP_A);
2428 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002429}
2430
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002431static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002432{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002433 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002434 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2435 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002436
Ville Syrjälä64e10772015-10-29 21:26:01 +02002437 assert_pipe_disabled(dev_priv, crtc->pipe);
2438 assert_dp_port_disabled(intel_dp);
2439 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002440
Ville Syrjäläabfce942015-10-29 21:26:03 +02002441 DRM_DEBUG_KMS("disabling eDP PLL\n");
2442
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002443 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002444
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002445 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002446 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002447 udelay(200);
2448}
2449
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002450/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002451void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002452{
2453 int ret, i;
2454
2455 /* Should have a valid DPCD by this point */
2456 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2457 return;
2458
2459 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002460 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2461 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002462 } else {
Imre Deak357c0ae2016-11-21 21:15:06 +02002463 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
2464
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002465 /*
2466 * When turning on, we need to retry for 1ms to give the sink
2467 * time to wake up.
2468 */
2469 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002470 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2471 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002472 if (ret == 1)
2473 break;
2474 msleep(1);
2475 }
Imre Deak357c0ae2016-11-21 21:15:06 +02002476
2477 if (ret == 1 && lspcon->active)
2478 lspcon_wait_pcon_mode(lspcon);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002479 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002480
2481 if (ret != 1)
2482 DRM_DEBUG_KMS("failed to %s sink power state\n",
2483 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002484}
2485
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002486static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2487 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002488{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002489 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002490 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002491 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002492 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002493 enum intel_display_power_domain power_domain;
2494 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002495 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002496
2497 power_domain = intel_display_port_power_domain(encoder);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002498 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002499 return false;
2500
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002501 ret = false;
2502
Imre Deak6d129be2014-03-05 16:20:54 +02002503 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002504
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002505 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002506 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002507
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002508 if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002509 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002510 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002511 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002512
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002513 for_each_pipe(dev_priv, p) {
2514 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2515 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2516 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002517 ret = true;
2518
2519 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002520 }
2521 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002522
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002523 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002524 i915_mmio_reg_offset(intel_dp->output_reg));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002525 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002526 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2527 } else {
2528 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002529 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002530
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002531 ret = true;
2532
2533out:
2534 intel_display_power_put(dev_priv, power_domain);
2535
2536 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002537}
2538
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002539static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002540 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002541{
2542 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002543 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002544 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002545 struct drm_i915_private *dev_priv = to_i915(dev);
Xiong Zhang63000ef2013-06-28 12:59:06 +08002546 enum port port = dp_to_dig_port(intel_dp)->port;
2547 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002548
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002549 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002550
2551 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002552
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002553 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002554 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2555
2556 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002557 flags |= DRM_MODE_FLAG_PHSYNC;
2558 else
2559 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002560
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002561 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002562 flags |= DRM_MODE_FLAG_PVSYNC;
2563 else
2564 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002565 } else {
2566 if (tmp & DP_SYNC_HS_HIGH)
2567 flags |= DRM_MODE_FLAG_PHSYNC;
2568 else
2569 flags |= DRM_MODE_FLAG_NHSYNC;
2570
2571 if (tmp & DP_SYNC_VS_HIGH)
2572 flags |= DRM_MODE_FLAG_PVSYNC;
2573 else
2574 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002575 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002576
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002577 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002578
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02002579 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002580 pipe_config->limited_color_range = true;
2581
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002582 pipe_config->lane_count =
2583 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2584
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002585 intel_dp_get_m_n(crtc, pipe_config);
2586
Ville Syrjälä18442d02013-09-13 16:00:08 +03002587 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002588 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002589 pipe_config->port_clock = 162000;
2590 else
2591 pipe_config->port_clock = 270000;
2592 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002593
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002594 pipe_config->base.adjusted_mode.crtc_clock =
2595 intel_dotclock_calculate(pipe_config->port_clock,
2596 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002597
Jani Nikula6aa23e62016-03-24 17:50:20 +02002598 if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
2599 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002600 /*
2601 * This is a big fat ugly hack.
2602 *
2603 * Some machines in UEFI boot mode provide us a VBT that has 18
2604 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2605 * unknown we fail to light up. Yet the same BIOS boots up with
2606 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2607 * max, not what it tells us to use.
2608 *
2609 * Note: This will still be broken if the eDP panel is not lit
2610 * up by the BIOS, and thus we can't get the mode at module
2611 * load.
2612 */
2613 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002614 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2615 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002616 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002617}
2618
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002619static void intel_disable_dp(struct intel_encoder *encoder,
2620 struct intel_crtc_state *old_crtc_state,
2621 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002622{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002623 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002624 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002625
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002626 if (old_crtc_state->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002627 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002628
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002629 if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv))
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002630 intel_psr_disable(intel_dp);
2631
Daniel Vetter6cb49832012-05-20 17:14:50 +02002632 /* Make sure the panel is off before trying to change the mode. But also
2633 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002634 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01002635 intel_edp_backlight_off(intel_dp);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002636 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002637 intel_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02002638
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002639 /* disable the port before the pipe on g4x */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002640 if (INTEL_GEN(dev_priv) < 5)
Daniel Vetter37398502012-09-06 22:15:44 +02002641 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07002642}
2643
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002644static void ilk_post_disable_dp(struct intel_encoder *encoder,
2645 struct intel_crtc_state *old_crtc_state,
2646 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002647{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002648 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002649 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002650
Ville Syrjälä49277c32014-03-31 18:21:26 +03002651 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002652
2653 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002654 if (port == PORT_A)
2655 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002656}
2657
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002658static void vlv_post_disable_dp(struct intel_encoder *encoder,
2659 struct intel_crtc_state *old_crtc_state,
2660 struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002661{
2662 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2663
2664 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002665}
2666
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002667static void chv_post_disable_dp(struct intel_encoder *encoder,
2668 struct intel_crtc_state *old_crtc_state,
2669 struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002670{
2671 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002672 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002673 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002674
2675 intel_dp_link_down(intel_dp);
2676
Ville Syrjäläa5805162015-05-26 20:42:30 +03002677 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002678
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002679 /* Assert data lane reset */
2680 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002681
Ville Syrjäläa5805162015-05-26 20:42:30 +03002682 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002683}
2684
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002685static void
2686_intel_dp_set_link_train(struct intel_dp *intel_dp,
2687 uint32_t *DP,
2688 uint8_t dp_train_pat)
2689{
2690 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2691 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002692 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002693 enum port port = intel_dig_port->port;
2694
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002695 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2696 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2697 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2698
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002699 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002700 uint32_t temp = I915_READ(DP_TP_CTL(port));
2701
2702 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2703 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2704 else
2705 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2706
2707 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2708 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2709 case DP_TRAINING_PATTERN_DISABLE:
2710 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2711
2712 break;
2713 case DP_TRAINING_PATTERN_1:
2714 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2715 break;
2716 case DP_TRAINING_PATTERN_2:
2717 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2718 break;
2719 case DP_TRAINING_PATTERN_3:
2720 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2721 break;
2722 }
2723 I915_WRITE(DP_TP_CTL(port), temp);
2724
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002725 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002726 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002727 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2728
2729 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2730 case DP_TRAINING_PATTERN_DISABLE:
2731 *DP |= DP_LINK_TRAIN_OFF_CPT;
2732 break;
2733 case DP_TRAINING_PATTERN_1:
2734 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2735 break;
2736 case DP_TRAINING_PATTERN_2:
2737 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2738 break;
2739 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002740 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002741 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2742 break;
2743 }
2744
2745 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002746 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002747 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2748 else
2749 *DP &= ~DP_LINK_TRAIN_MASK;
2750
2751 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2752 case DP_TRAINING_PATTERN_DISABLE:
2753 *DP |= DP_LINK_TRAIN_OFF;
2754 break;
2755 case DP_TRAINING_PATTERN_1:
2756 *DP |= DP_LINK_TRAIN_PAT_1;
2757 break;
2758 case DP_TRAINING_PATTERN_2:
2759 *DP |= DP_LINK_TRAIN_PAT_2;
2760 break;
2761 case DP_TRAINING_PATTERN_3:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002762 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002763 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2764 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002765 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002766 *DP |= DP_LINK_TRAIN_PAT_2;
2767 }
2768 break;
2769 }
2770 }
2771}
2772
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002773static void intel_dp_enable_port(struct intel_dp *intel_dp,
2774 struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002775{
2776 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002777 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002778
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002779 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002780
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002781 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002782
2783 /*
2784 * Magic for VLV/CHV. We _must_ first set up the register
2785 * without actually enabling the port, and then do another
2786 * write to enable the port. Otherwise link training will
2787 * fail when the power sequencer is freshly used for this port.
2788 */
2789 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002790 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002791 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002792
2793 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2794 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002795}
2796
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002797static void intel_enable_dp(struct intel_encoder *encoder,
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002798 struct intel_crtc_state *pipe_config,
2799 struct drm_connector_state *conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002800{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002801 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2802 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002803 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulac1dec792014-10-27 16:26:56 +02002804 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002805 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002806 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002807
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002808 if (WARN_ON(dp_reg & DP_PORT_EN))
2809 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002810
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002811 pps_lock(intel_dp);
2812
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002813 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002814 vlv_init_panel_power_sequencer(intel_dp);
2815
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002816 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002817
2818 edp_panel_vdd_on(intel_dp);
2819 edp_panel_on(intel_dp);
2820 edp_panel_vdd_off(intel_dp, true);
2821
2822 pps_unlock(intel_dp);
2823
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002824 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002825 unsigned int lane_mask = 0x0;
2826
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002827 if (IS_CHERRYVIEW(dev_priv))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002828 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002829
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002830 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2831 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002832 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002833
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002834 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2835 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002836 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002837
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002838 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002839 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002840 pipe_name(pipe));
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002841 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Jani Nikulac1dec792014-10-27 16:26:56 +02002842 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002843}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002844
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002845static void g4x_enable_dp(struct intel_encoder *encoder,
2846 struct intel_crtc_state *pipe_config,
2847 struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03002848{
Jani Nikula828f5c62013-09-05 16:44:45 +03002849 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2850
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002851 intel_enable_dp(encoder, pipe_config, conn_state);
Daniel Vetter4be73782014-01-17 14:39:48 +01002852 intel_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002853}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002854
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002855static void vlv_enable_dp(struct intel_encoder *encoder,
2856 struct intel_crtc_state *pipe_config,
2857 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002858{
Jani Nikula828f5c62013-09-05 16:44:45 +03002859 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2860
Daniel Vetter4be73782014-01-17 14:39:48 +01002861 intel_edp_backlight_on(intel_dp);
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002862 intel_psr_enable(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002863}
2864
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002865static void g4x_pre_enable_dp(struct intel_encoder *encoder,
2866 struct intel_crtc_state *pipe_config,
2867 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002868{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002869 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002870 enum port port = dp_to_dig_port(intel_dp)->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002871
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002872 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002873
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002874 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002875 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002876 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002877}
2878
Ville Syrjälä83b84592014-10-16 21:29:51 +03002879static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2880{
2881 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002882 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002883 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03002884 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002885
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002886 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
2887
Ville Syrjälä83b84592014-10-16 21:29:51 +03002888 edp_panel_vdd_off_sync(intel_dp);
2889
2890 /*
2891 * VLV seems to get confused when multiple power seqeuencers
2892 * have the same port selected (even if only one has power/vdd
2893 * enabled). The failure manifests as vlv_wait_port_ready() failing
2894 * CHV on the other hand doesn't seem to mind having the same port
2895 * selected in multiple power seqeuencers, but let's clear the
2896 * port select always when logically disconnecting a power sequencer
2897 * from a port.
2898 */
2899 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2900 pipe_name(pipe), port_name(intel_dig_port->port));
2901 I915_WRITE(pp_on_reg, 0);
2902 POSTING_READ(pp_on_reg);
2903
2904 intel_dp->pps_pipe = INVALID_PIPE;
2905}
2906
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002907static void vlv_steal_power_sequencer(struct drm_device *dev,
2908 enum pipe pipe)
2909{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002910 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002911 struct intel_encoder *encoder;
2912
2913 lockdep_assert_held(&dev_priv->pps_mutex);
2914
Ville Syrjäläac3c12e2014-10-16 21:29:56 +03002915 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2916 return;
2917
Jani Nikula19c80542015-12-16 12:48:16 +02002918 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002919 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002920 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002921
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002922 if (encoder->type != INTEL_OUTPUT_DP &&
2923 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002924 continue;
2925
2926 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002927 port = dp_to_dig_port(intel_dp)->port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002928
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002929 WARN(intel_dp->active_pipe == pipe,
2930 "stealing pipe %c power sequencer from active (e)DP port %c\n",
2931 pipe_name(pipe), port_name(port));
2932
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002933 if (intel_dp->pps_pipe != pipe)
2934 continue;
2935
2936 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03002937 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002938
2939 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002940 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002941 }
2942}
2943
2944static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
2945{
2946 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2947 struct intel_encoder *encoder = &intel_dig_port->base;
2948 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002949 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002950 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002951
2952 lockdep_assert_held(&dev_priv->pps_mutex);
2953
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002954 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002955
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002956 if (intel_dp->pps_pipe != INVALID_PIPE &&
2957 intel_dp->pps_pipe != crtc->pipe) {
2958 /*
2959 * If another power sequencer was being used on this
2960 * port previously make sure to turn off vdd there while
2961 * we still have control of it.
2962 */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002963 vlv_detach_power_sequencer(intel_dp);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002964 }
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002965
2966 /*
2967 * We may be stealing the power
2968 * sequencer from another port.
2969 */
2970 vlv_steal_power_sequencer(dev, crtc->pipe);
2971
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002972 intel_dp->active_pipe = crtc->pipe;
2973
2974 if (!is_edp(intel_dp))
2975 return;
2976
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002977 /* now it's all ours */
2978 intel_dp->pps_pipe = crtc->pipe;
2979
2980 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
2981 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
2982
2983 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03002984 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02002985 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002986}
2987
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002988static void vlv_pre_enable_dp(struct intel_encoder *encoder,
2989 struct intel_crtc_state *pipe_config,
2990 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002991{
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03002992 vlv_phy_pre_encoder_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002993
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002994 intel_enable_dp(encoder, pipe_config, conn_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002995}
2996
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002997static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
2998 struct intel_crtc_state *pipe_config,
2999 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07003000{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003001 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02003002
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03003003 vlv_phy_pre_pll_enable(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003004}
3005
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003006static void chv_pre_enable_dp(struct intel_encoder *encoder,
3007 struct intel_crtc_state *pipe_config,
3008 struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003009{
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003010 chv_phy_pre_encoder_enable(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003011
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003012 intel_enable_dp(encoder, pipe_config, conn_state);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03003013
3014 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003015 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003016}
3017
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003018static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
3019 struct intel_crtc_state *pipe_config,
3020 struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03003021{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003022 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03003023
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03003024 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03003025}
3026
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003027static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
3028 struct intel_crtc_state *pipe_config,
3029 struct drm_connector_state *conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003030{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03003031 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003032}
3033
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003034/*
3035 * Fetch AUX CH registers 0x202 - 0x207 which contain
3036 * link status information
3037 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003038bool
Keith Packard93f62da2011-11-01 19:45:03 -07003039intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003040{
Lyude9f085eb2016-04-13 10:58:33 -04003041 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
3042 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003043}
3044
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303045static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp)
3046{
3047 uint8_t psr_caps = 0;
3048
3049 drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps);
3050 return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED;
3051}
3052
3053static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp)
3054{
3055 uint8_t dprx = 0;
3056
3057 drm_dp_dpcd_readb(&intel_dp->aux,
3058 DP_DPRX_FEATURE_ENUMERATION_LIST,
3059 &dprx);
3060 return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED;
3061}
3062
Chris Wilsona76f73d2017-01-14 10:51:13 +00003063static bool intel_dp_get_alpm_status(struct intel_dp *intel_dp)
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303064{
3065 uint8_t alpm_caps = 0;
3066
3067 drm_dp_dpcd_readb(&intel_dp->aux, DP_RECEIVER_ALPM_CAP, &alpm_caps);
3068 return alpm_caps & DP_ALPM_CAP;
3069}
3070
Paulo Zanoni11002442014-06-13 18:45:41 -03003071/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003072uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003073intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003074{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003075 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003076 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003077
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003078 if (IS_GEN9_LP(dev_priv))
Vandana Kannan93147262014-11-18 15:45:29 +05303079 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003080 else if (INTEL_GEN(dev_priv) >= 9) {
Jani Nikula06411f02016-03-24 17:50:21 +02003081 if (dev_priv->vbt.edp.low_vswing && port == PORT_A)
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303082 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003083 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003084 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Sonika Jindalbd600182014-08-08 16:23:41 +05303085 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003086 else if (IS_GEN7(dev_priv) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303087 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003088 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303089 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08003090 else
Sonika Jindalbd600182014-08-08 16:23:41 +05303091 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08003092}
3093
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003094uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003095intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3096{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003097 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003098 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003099
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003100 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003101 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3102 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3103 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3104 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3105 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3106 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3107 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303108 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3109 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003110 default:
3111 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3112 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003113 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003114 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303115 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3116 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3117 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3118 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3119 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3120 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3121 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003122 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303123 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003124 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003125 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003126 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303127 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3128 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3129 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3130 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3131 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3132 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3133 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003134 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303135 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003136 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003137 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003138 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303139 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3140 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3141 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3142 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3143 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003144 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303145 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003146 }
3147 } else {
3148 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303149 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3150 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3151 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3152 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3153 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3154 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3155 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003156 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303157 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003158 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003159 }
3160}
3161
Daniel Vetter5829975c2015-04-16 11:36:52 +02003162static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003163{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003164 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003165 unsigned long demph_reg_value, preemph_reg_value,
3166 uniqtranscale_reg_value;
3167 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003168
3169 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303170 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003171 preemph_reg_value = 0x0004000;
3172 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303173 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003174 demph_reg_value = 0x2B405555;
3175 uniqtranscale_reg_value = 0x552AB83A;
3176 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303177 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003178 demph_reg_value = 0x2B404040;
3179 uniqtranscale_reg_value = 0x5548B83A;
3180 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303181 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003182 demph_reg_value = 0x2B245555;
3183 uniqtranscale_reg_value = 0x5560B83A;
3184 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303185 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003186 demph_reg_value = 0x2B405555;
3187 uniqtranscale_reg_value = 0x5598DA3A;
3188 break;
3189 default:
3190 return 0;
3191 }
3192 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303193 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003194 preemph_reg_value = 0x0002000;
3195 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303196 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003197 demph_reg_value = 0x2B404040;
3198 uniqtranscale_reg_value = 0x5552B83A;
3199 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303200 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003201 demph_reg_value = 0x2B404848;
3202 uniqtranscale_reg_value = 0x5580B83A;
3203 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303204 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003205 demph_reg_value = 0x2B404040;
3206 uniqtranscale_reg_value = 0x55ADDA3A;
3207 break;
3208 default:
3209 return 0;
3210 }
3211 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303212 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003213 preemph_reg_value = 0x0000000;
3214 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303215 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003216 demph_reg_value = 0x2B305555;
3217 uniqtranscale_reg_value = 0x5570B83A;
3218 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303219 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003220 demph_reg_value = 0x2B2B4040;
3221 uniqtranscale_reg_value = 0x55ADDA3A;
3222 break;
3223 default:
3224 return 0;
3225 }
3226 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303227 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003228 preemph_reg_value = 0x0006000;
3229 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303230 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003231 demph_reg_value = 0x1B405555;
3232 uniqtranscale_reg_value = 0x55ADDA3A;
3233 break;
3234 default:
3235 return 0;
3236 }
3237 break;
3238 default:
3239 return 0;
3240 }
3241
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003242 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3243 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003244
3245 return 0;
3246}
3247
Daniel Vetter5829975c2015-04-16 11:36:52 +02003248static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003249{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003250 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3251 u32 deemph_reg_value, margin_reg_value;
3252 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003253 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003254
3255 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303256 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003257 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303258 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003259 deemph_reg_value = 128;
3260 margin_reg_value = 52;
3261 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303262 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003263 deemph_reg_value = 128;
3264 margin_reg_value = 77;
3265 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303266 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003267 deemph_reg_value = 128;
3268 margin_reg_value = 102;
3269 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303270 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003271 deemph_reg_value = 128;
3272 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003273 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003274 break;
3275 default:
3276 return 0;
3277 }
3278 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303279 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003280 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303281 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003282 deemph_reg_value = 85;
3283 margin_reg_value = 78;
3284 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303285 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003286 deemph_reg_value = 85;
3287 margin_reg_value = 116;
3288 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303289 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003290 deemph_reg_value = 85;
3291 margin_reg_value = 154;
3292 break;
3293 default:
3294 return 0;
3295 }
3296 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303297 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003298 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303299 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003300 deemph_reg_value = 64;
3301 margin_reg_value = 104;
3302 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303303 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003304 deemph_reg_value = 64;
3305 margin_reg_value = 154;
3306 break;
3307 default:
3308 return 0;
3309 }
3310 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303311 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003312 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303313 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003314 deemph_reg_value = 43;
3315 margin_reg_value = 154;
3316 break;
3317 default:
3318 return 0;
3319 }
3320 break;
3321 default:
3322 return 0;
3323 }
3324
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003325 chv_set_phy_signal_level(encoder, deemph_reg_value,
3326 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003327
3328 return 0;
3329}
3330
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003331static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003332gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003333{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003334 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003335
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003336 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303337 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003338 default:
3339 signal_levels |= DP_VOLTAGE_0_4;
3340 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303341 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003342 signal_levels |= DP_VOLTAGE_0_6;
3343 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303344 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003345 signal_levels |= DP_VOLTAGE_0_8;
3346 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303347 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003348 signal_levels |= DP_VOLTAGE_1_2;
3349 break;
3350 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003351 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303352 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003353 default:
3354 signal_levels |= DP_PRE_EMPHASIS_0;
3355 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303356 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003357 signal_levels |= DP_PRE_EMPHASIS_3_5;
3358 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303359 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003360 signal_levels |= DP_PRE_EMPHASIS_6;
3361 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303362 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003363 signal_levels |= DP_PRE_EMPHASIS_9_5;
3364 break;
3365 }
3366 return signal_levels;
3367}
3368
Zhenyu Wange3421a12010-04-08 09:43:27 +08003369/* Gen6's DP voltage swing and pre-emphasis control */
3370static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003371gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003372{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003373 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3374 DP_TRAIN_PRE_EMPHASIS_MASK);
3375 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303376 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3377 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003378 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303379 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003380 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303381 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3382 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003383 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303384 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3385 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003386 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303387 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3388 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003389 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003390 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003391 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3392 "0x%x\n", signal_levels);
3393 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003394 }
3395}
3396
Keith Packard1a2eb462011-11-16 16:26:07 -08003397/* Gen7's DP voltage swing and pre-emphasis control */
3398static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003399gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003400{
3401 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3402 DP_TRAIN_PRE_EMPHASIS_MASK);
3403 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303404 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003405 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303406 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003407 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303408 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003409 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3410
Sonika Jindalbd600182014-08-08 16:23:41 +05303411 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003412 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303413 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003414 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3415
Sonika Jindalbd600182014-08-08 16:23:41 +05303416 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003417 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303418 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003419 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3420
3421 default:
3422 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3423 "0x%x\n", signal_levels);
3424 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3425 }
3426}
3427
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003428void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003429intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003430{
3431 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003432 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003433 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003434 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003435 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003436 uint8_t train_set = intel_dp->train_set[0];
3437
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003438 if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003439 signal_levels = ddi_signal_levels(intel_dp);
3440
Michel Thierry254e0932017-01-09 16:51:35 +02003441 if (IS_GEN9_LP(dev_priv))
David Weinehallf8896f52015-06-25 11:11:03 +03003442 signal_levels = 0;
3443 else
3444 mask = DDI_BUF_EMP_MASK;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003445 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003446 signal_levels = chv_signal_levels(intel_dp);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003447 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003448 signal_levels = vlv_signal_levels(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003449 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003450 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003451 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003452 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003453 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003454 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3455 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003456 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003457 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3458 }
3459
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303460 if (mask)
3461 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3462
3463 DRM_DEBUG_KMS("Using vswing level %d\n",
3464 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3465 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3466 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3467 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003468
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003469 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003470
3471 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3472 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003473}
3474
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003475void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003476intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3477 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003478{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003479 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003480 struct drm_i915_private *dev_priv =
3481 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003482
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003483 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003484
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003485 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003486 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003487}
3488
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003489void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003490{
3491 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3492 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003493 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak3ab9c632013-05-03 12:57:41 +03003494 enum port port = intel_dig_port->port;
3495 uint32_t val;
3496
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003497 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003498 return;
3499
3500 val = I915_READ(DP_TP_CTL(port));
3501 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3502 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3503 I915_WRITE(DP_TP_CTL(port), val);
3504
3505 /*
3506 * On PORT_A we can have only eDP in SST mode. There the only reason
3507 * we need to set idle transmission mode is to work around a HW issue
3508 * where we enable the pipe while not in idle link-training mode.
3509 * In this case there is requirement to wait for a minimum number of
3510 * idle patterns to be sent.
3511 */
3512 if (port == PORT_A)
3513 return;
3514
Chris Wilsona7670172016-06-30 15:33:10 +01003515 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3516 DP_TP_STATUS_IDLE_DONE,
3517 DP_TP_STATUS_IDLE_DONE,
3518 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003519 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3520}
3521
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003522static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003523intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003524{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003525 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003526 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003527 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003528 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003529 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003530 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003531
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003532 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003533 return;
3534
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003535 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003536 return;
3537
Zhao Yakui28c97732009-10-09 11:39:41 +08003538 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003539
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003540 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003541 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003542 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003543 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003544 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003545 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003546 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3547 else
3548 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003549 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003550 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003551 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003552 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003553
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003554 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3555 I915_WRITE(intel_dp->output_reg, DP);
3556 POSTING_READ(intel_dp->output_reg);
3557
3558 /*
3559 * HW workaround for IBX, we need to move the port
3560 * to transcoder A after disabling it to allow the
3561 * matching HDMI port to be enabled on transcoder A.
3562 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003563 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003564 /*
3565 * We get CPU/PCH FIFO underruns on the other pipe when
3566 * doing the workaround. Sweep them under the rug.
3567 */
3568 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3569 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3570
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003571 /* always enable with pattern 1 (as per spec) */
3572 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3573 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3574 I915_WRITE(intel_dp->output_reg, DP);
3575 POSTING_READ(intel_dp->output_reg);
3576
3577 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003578 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003579 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003580
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003581 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003582 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3583 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003584 }
3585
Keith Packardf01eca22011-09-28 16:48:10 -07003586 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003587
3588 intel_dp->DP = DP;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003589
3590 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3591 pps_lock(intel_dp);
3592 intel_dp->active_pipe = INVALID_PIPE;
3593 pps_unlock(intel_dp);
3594 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003595}
3596
Imre Deak24e807e2016-10-24 19:33:28 +03003597bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003598intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003599{
Lyude9f085eb2016-04-13 10:58:33 -04003600 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3601 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003602 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003603
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003604 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003605
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003606 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3607}
3608
3609static bool
3610intel_edp_init_dpcd(struct intel_dp *intel_dp)
3611{
3612 struct drm_i915_private *dev_priv =
3613 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3614
3615 /* this function is meant to be called only once */
3616 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3617
3618 if (!intel_dp_read_dpcd(intel_dp))
3619 return false;
3620
Imre Deak12a47a422016-10-24 19:33:29 +03003621 intel_dp_read_desc(intel_dp);
3622
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003623 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3624 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3625 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3626
3627 /* Check if the panel supports PSR */
3628 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3629 intel_dp->psr_dpcd,
3630 sizeof(intel_dp->psr_dpcd));
3631 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3632 dev_priv->psr.sink_support = true;
3633 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3634 }
3635
3636 if (INTEL_GEN(dev_priv) >= 9 &&
3637 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3638 uint8_t frame_sync_cap;
3639
3640 dev_priv->psr.sink_support = true;
3641 drm_dp_dpcd_read(&intel_dp->aux,
3642 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3643 &frame_sync_cap, 1);
3644 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3645 /* PSR2 needs frame sync as well */
3646 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3647 DRM_DEBUG_KMS("PSR2 %s on sink",
3648 dev_priv->psr.psr2_support ? "supported" : "not supported");
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303649
3650 if (dev_priv->psr.psr2_support) {
3651 dev_priv->psr.y_cord_support =
3652 intel_dp_get_y_cord_status(intel_dp);
3653 dev_priv->psr.colorimetry_support =
3654 intel_dp_get_colorimetry_status(intel_dp);
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303655 dev_priv->psr.alpm =
3656 intel_dp_get_alpm_status(intel_dp);
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303657 }
3658
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003659 }
3660
3661 /* Read the eDP Display control capabilities registers */
3662 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
3663 drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003664 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3665 sizeof(intel_dp->edp_dpcd))
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003666 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3667 intel_dp->edp_dpcd);
3668
3669 /* Intermediate frequency support */
3670 if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */
3671 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3672 int i;
3673
3674 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3675 sink_rates, sizeof(sink_rates));
3676
3677 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3678 int val = le16_to_cpu(sink_rates[i]);
3679
3680 if (val == 0)
3681 break;
3682
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -08003683 /* Value read multiplied by 200kHz gives the per-lane
3684 * link rate in kHz. The source rates are, however,
3685 * stored in terms of LS_Clk kHz. The full conversion
3686 * back to symbols is
3687 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
3688 */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003689 intel_dp->sink_rates[i] = (val * 200) / 10;
3690 }
3691 intel_dp->num_sink_rates = i;
3692 }
3693
3694 return true;
3695}
3696
3697
3698static bool
3699intel_dp_get_dpcd(struct intel_dp *intel_dp)
3700{
3701 if (!intel_dp_read_dpcd(intel_dp))
3702 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003703
Lyude9f085eb2016-04-13 10:58:33 -04003704 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT,
3705 &intel_dp->sink_count, 1) < 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303706 return false;
3707
3708 /*
3709 * Sink count can change between short pulse hpd hence
3710 * a member variable in intel_dp will track any changes
3711 * between short pulse interrupts.
3712 */
3713 intel_dp->sink_count = DP_GET_SINK_COUNT(intel_dp->sink_count);
3714
3715 /*
3716 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3717 * a dongle is present but no display. Unless we require to know
3718 * if a dongle is present or not, we don't need to update
3719 * downstream port information. So, an early return here saves
3720 * time from performing other operations which are not required.
3721 */
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05303722 if (!is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303723 return false;
3724
Imre Deakc726ad02016-10-24 19:33:24 +03003725 if (!drm_dp_is_branch(intel_dp->dpcd))
Adam Jacksonedb39242012-09-18 10:58:49 -04003726 return true; /* native DP sink */
3727
3728 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3729 return true; /* no per-port downstream info */
3730
Lyude9f085eb2016-04-13 10:58:33 -04003731 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3732 intel_dp->downstream_ports,
3733 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003734 return false; /* downstream port status fetch failed */
3735
3736 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003737}
3738
Dave Airlie0e32b392014-05-02 14:02:48 +10003739static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003740intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003741{
3742 u8 buf[1];
3743
Nathan Schulte7cc96132016-03-15 10:14:05 -05003744 if (!i915.enable_dp_mst)
3745 return false;
3746
Dave Airlie0e32b392014-05-02 14:02:48 +10003747 if (!intel_dp->can_mst)
3748 return false;
3749
3750 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3751 return false;
3752
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003753 if (drm_dp_dpcd_read(&intel_dp->aux, DP_MSTM_CAP, buf, 1) != 1)
3754 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003755
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003756 return buf[0] & DP_MST_CAP;
3757}
3758
3759static void
3760intel_dp_configure_mst(struct intel_dp *intel_dp)
3761{
3762 if (!i915.enable_dp_mst)
3763 return;
3764
3765 if (!intel_dp->can_mst)
3766 return;
3767
3768 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3769
3770 if (intel_dp->is_mst)
3771 DRM_DEBUG_KMS("Sink is MST capable\n");
3772 else
3773 DRM_DEBUG_KMS("Sink is not MST capable\n");
3774
3775 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3776 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003777}
3778
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003779static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003780{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003781 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003782 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003783 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003784 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003785 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003786 int count = 0;
3787 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003788
3789 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003790 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003791 ret = -EIO;
3792 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003793 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003794
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003795 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003796 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003797 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003798 ret = -EIO;
3799 goto out;
3800 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003801
Rodrigo Vivic6297842015-11-05 10:50:20 -08003802 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003803 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivic6297842015-11-05 10:50:20 -08003804
3805 if (drm_dp_dpcd_readb(&intel_dp->aux,
3806 DP_TEST_SINK_MISC, &buf) < 0) {
3807 ret = -EIO;
3808 goto out;
3809 }
3810 count = buf & DP_TEST_COUNT_MASK;
3811 } while (--attempts && count);
3812
3813 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003814 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003815 ret = -ETIMEDOUT;
3816 }
3817
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003818 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003819 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003820 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003821}
3822
3823static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3824{
3825 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003826 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003827 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3828 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003829 int ret;
3830
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003831 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3832 return -EIO;
3833
3834 if (!(buf & DP_TEST_CRC_SUPPORTED))
3835 return -ENOTTY;
3836
3837 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3838 return -EIO;
3839
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003840 if (buf & DP_TEST_SINK_START) {
3841 ret = intel_dp_sink_crc_stop(intel_dp);
3842 if (ret)
3843 return ret;
3844 }
3845
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003846 hsw_disable_ips(intel_crtc);
3847
3848 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3849 buf | DP_TEST_SINK_START) < 0) {
3850 hsw_enable_ips(intel_crtc);
3851 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003852 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003853
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003854 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003855 return 0;
3856}
3857
3858int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3859{
3860 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003861 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003862 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3863 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003864 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003865 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003866
3867 ret = intel_dp_sink_crc_start(intel_dp);
3868 if (ret)
3869 return ret;
3870
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003871 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003872 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003873
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003874 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003875 DP_TEST_SINK_MISC, &buf) < 0) {
3876 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003877 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003878 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003879 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07003880
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003881 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003882
3883 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003884 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
3885 ret = -ETIMEDOUT;
3886 goto stop;
3887 }
3888
3889 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
3890 ret = -EIO;
3891 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003892 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003893
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003894stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003895 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003896 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003897}
3898
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003899static bool
3900intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3901{
Lyude9f085eb2016-04-13 10:58:33 -04003902 return drm_dp_dpcd_read(&intel_dp->aux,
Jani Nikula9d1a1032014-03-14 16:51:15 +02003903 DP_DEVICE_SERVICE_IRQ_VECTOR,
3904 sink_irq_vector, 1) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003905}
3906
Dave Airlie0e32b392014-05-02 14:02:48 +10003907static bool
3908intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3909{
3910 int ret;
3911
Lyude9f085eb2016-04-13 10:58:33 -04003912 ret = drm_dp_dpcd_read(&intel_dp->aux,
Dave Airlie0e32b392014-05-02 14:02:48 +10003913 DP_SINK_COUNT_ESI,
3914 sink_irq_vector, 14);
3915 if (ret != 14)
3916 return false;
3917
3918 return true;
3919}
3920
Todd Previtec5d5ab72015-04-15 08:38:38 -07003921static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003922{
Todd Previtec5d5ab72015-04-15 08:38:38 -07003923 uint8_t test_result = DP_TEST_ACK;
3924 return test_result;
3925}
3926
3927static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
3928{
3929 uint8_t test_result = DP_TEST_NAK;
3930 return test_result;
3931}
3932
3933static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
3934{
3935 uint8_t test_result = DP_TEST_NAK;
Todd Previte559be302015-05-04 07:48:20 -07003936 struct intel_connector *intel_connector = intel_dp->attached_connector;
3937 struct drm_connector *connector = &intel_connector->base;
3938
3939 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02003940 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07003941 intel_dp->aux.i2c_defer_count > 6) {
3942 /* Check EDID read for NACKs, DEFERs and corruption
3943 * (DP CTS 1.2 Core r1.1)
3944 * 4.2.2.4 : Failed EDID read, I2C_NAK
3945 * 4.2.2.5 : Failed EDID read, I2C_DEFER
3946 * 4.2.2.6 : EDID corruption detected
3947 * Use failsafe mode for all cases
3948 */
3949 if (intel_dp->aux.i2c_nack_count > 0 ||
3950 intel_dp->aux.i2c_defer_count > 0)
3951 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
3952 intel_dp->aux.i2c_nack_count,
3953 intel_dp->aux.i2c_defer_count);
Manasi Navarec1617ab2016-12-09 16:22:50 -08003954 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
Todd Previte559be302015-05-04 07:48:20 -07003955 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05303956 struct edid *block = intel_connector->detect_edid;
3957
3958 /* We have to write the checksum
3959 * of the last block read
3960 */
3961 block += intel_connector->detect_edid->extensions;
3962
Todd Previte559be302015-05-04 07:48:20 -07003963 if (!drm_dp_dpcd_write(&intel_dp->aux,
3964 DP_TEST_EDID_CHECKSUM,
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05303965 &block->checksum,
Dan Carpenter5a1cc652015-05-12 21:07:37 +03003966 1))
Todd Previte559be302015-05-04 07:48:20 -07003967 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
3968
3969 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
Manasi Navarec1617ab2016-12-09 16:22:50 -08003970 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_STANDARD;
Todd Previte559be302015-05-04 07:48:20 -07003971 }
3972
3973 /* Set test active flag here so userspace doesn't interrupt things */
Manasi Navarec1617ab2016-12-09 16:22:50 -08003974 intel_dp->compliance.test_active = 1;
Todd Previte559be302015-05-04 07:48:20 -07003975
Todd Previtec5d5ab72015-04-15 08:38:38 -07003976 return test_result;
3977}
3978
3979static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
3980{
3981 uint8_t test_result = DP_TEST_NAK;
3982 return test_result;
3983}
3984
3985static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
3986{
3987 uint8_t response = DP_TEST_NAK;
3988 uint8_t rxdata = 0;
3989 int status = 0;
3990
Todd Previtec5d5ab72015-04-15 08:38:38 -07003991 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_REQUEST, &rxdata, 1);
3992 if (status <= 0) {
3993 DRM_DEBUG_KMS("Could not read test request from sink\n");
3994 goto update_status;
3995 }
3996
3997 switch (rxdata) {
3998 case DP_TEST_LINK_TRAINING:
3999 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
Manasi Navarec1617ab2016-12-09 16:22:50 -08004000 intel_dp->compliance.test_type = DP_TEST_LINK_TRAINING;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004001 response = intel_dp_autotest_link_training(intel_dp);
4002 break;
4003 case DP_TEST_LINK_VIDEO_PATTERN:
4004 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
Manasi Navarec1617ab2016-12-09 16:22:50 -08004005 intel_dp->compliance.test_type = DP_TEST_LINK_VIDEO_PATTERN;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004006 response = intel_dp_autotest_video_pattern(intel_dp);
4007 break;
4008 case DP_TEST_LINK_EDID_READ:
4009 DRM_DEBUG_KMS("EDID test requested\n");
Manasi Navarec1617ab2016-12-09 16:22:50 -08004010 intel_dp->compliance.test_type = DP_TEST_LINK_EDID_READ;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004011 response = intel_dp_autotest_edid(intel_dp);
4012 break;
4013 case DP_TEST_LINK_PHY_TEST_PATTERN:
4014 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
Manasi Navarec1617ab2016-12-09 16:22:50 -08004015 intel_dp->compliance.test_type = DP_TEST_LINK_PHY_TEST_PATTERN;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004016 response = intel_dp_autotest_phy_pattern(intel_dp);
4017 break;
4018 default:
4019 DRM_DEBUG_KMS("Invalid test request '%02x'\n", rxdata);
4020 break;
4021 }
4022
4023update_status:
4024 status = drm_dp_dpcd_write(&intel_dp->aux,
4025 DP_TEST_RESPONSE,
4026 &response, 1);
4027 if (status <= 0)
4028 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004029}
4030
Dave Airlie0e32b392014-05-02 14:02:48 +10004031static int
4032intel_dp_check_mst_status(struct intel_dp *intel_dp)
4033{
4034 bool bret;
4035
4036 if (intel_dp->is_mst) {
4037 u8 esi[16] = { 0 };
4038 int ret = 0;
4039 int retry;
4040 bool handled;
4041 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4042go_again:
4043 if (bret == true) {
4044
4045 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03004046 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03004047 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10004048 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4049 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004050 intel_dp_stop_link_train(intel_dp);
4051 }
4052
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004053 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004054 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4055
4056 if (handled) {
4057 for (retry = 0; retry < 3; retry++) {
4058 int wret;
4059 wret = drm_dp_dpcd_write(&intel_dp->aux,
4060 DP_SINK_COUNT_ESI+1,
4061 &esi[1], 3);
4062 if (wret == 3) {
4063 break;
4064 }
4065 }
4066
4067 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4068 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004069 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004070 goto go_again;
4071 }
4072 } else
4073 ret = 0;
4074
4075 return ret;
4076 } else {
4077 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4078 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4079 intel_dp->is_mst = false;
4080 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4081 /* send a hotplug event */
4082 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4083 }
4084 }
4085 return -EINVAL;
4086}
4087
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304088static void
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004089intel_dp_retrain_link(struct intel_dp *intel_dp)
4090{
4091 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4092 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4093 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
4094
4095 /* Suppress underruns caused by re-training */
4096 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4097 if (crtc->config->has_pch_encoder)
4098 intel_set_pch_fifo_underrun_reporting(dev_priv,
4099 intel_crtc_pch_transcoder(crtc), false);
4100
4101 intel_dp_start_link_train(intel_dp);
4102 intel_dp_stop_link_train(intel_dp);
4103
4104 /* Keep underrun reporting disabled until things are stable */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02004105 intel_wait_for_vblank(dev_priv, crtc->pipe);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004106
4107 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4108 if (crtc->config->has_pch_encoder)
4109 intel_set_pch_fifo_underrun_reporting(dev_priv,
4110 intel_crtc_pch_transcoder(crtc), true);
4111}
4112
4113static void
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304114intel_dp_check_link_status(struct intel_dp *intel_dp)
4115{
4116 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4117 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4118 u8 link_status[DP_LINK_STATUS_SIZE];
4119
4120 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
4121
4122 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4123 DRM_ERROR("Failed to get link status\n");
4124 return;
4125 }
4126
4127 if (!intel_encoder->base.crtc)
4128 return;
4129
4130 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4131 return;
4132
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004133 /* FIXME: we need to synchronize this sort of stuff with hardware
Daniel Vetter2dd85ae2016-12-13 20:54:14 +01004134 * readout. Currently fast link training doesn't work on boot-up. */
4135 if (!intel_dp->lane_count)
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004136 return;
4137
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304138 /* if link training is requested we should perform it always */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004139 if ((intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) ||
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304140 (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count))) {
4141 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4142 intel_encoder->base.name);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004143
4144 intel_dp_retrain_link(intel_dp);
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304145 }
4146}
4147
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004148/*
4149 * According to DP spec
4150 * 5.1.2:
4151 * 1. Read DPCD
4152 * 2. Configure link according to Receiver Capabilities
4153 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4154 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304155 *
4156 * intel_dp_short_pulse - handles short pulse interrupts
4157 * when full detection is not required.
4158 * Returns %true if short pulse is handled and full detection
4159 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004160 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304161static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304162intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004163{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004164 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004165 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304166 u8 old_sink_count = intel_dp->sink_count;
4167 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004168
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304169 /*
4170 * Clearing compliance test variables to allow capturing
4171 * of values for next automated test request.
4172 */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004173 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304174
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304175 /*
4176 * Now read the DPCD to see if it's actually running
4177 * If the current value of sink count doesn't match with
4178 * the value that was stored earlier or dpcd read failed
4179 * we need to do full detection
4180 */
4181 ret = intel_dp_get_dpcd(intel_dp);
4182
4183 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4184 /* No need to proceed if we are going to do full detect */
4185 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004186 }
4187
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004188 /* Try to read the source of the interrupt */
4189 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004190 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4191 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004192 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004193 drm_dp_dpcd_writeb(&intel_dp->aux,
4194 DP_DEVICE_SERVICE_IRQ_VECTOR,
4195 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004196
4197 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Todd Previte09b1eb12015-04-20 15:27:34 -07004198 DRM_DEBUG_DRIVER("Test request in short pulse not handled\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004199 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4200 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4201 }
4202
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304203 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4204 intel_dp_check_link_status(intel_dp);
4205 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304206
4207 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004208}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004209
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004210/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004211static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004212intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004213{
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004214 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004215 uint8_t type;
4216
4217 if (!intel_dp_get_dpcd(intel_dp))
4218 return connector_status_disconnected;
4219
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304220 if (is_edp(intel_dp))
4221 return connector_status_connected;
4222
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004223 /* if there's no downstream port, we're done */
Imre Deakc726ad02016-10-24 19:33:24 +03004224 if (!drm_dp_is_branch(dpcd))
Keith Packard26d61aa2011-07-25 20:01:09 -07004225 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004226
4227 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004228 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4229 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004230
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304231 return intel_dp->sink_count ?
4232 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004233 }
4234
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004235 if (intel_dp_can_mst(intel_dp))
4236 return connector_status_connected;
4237
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004238 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004239 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004240 return connector_status_connected;
4241
4242 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004243 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4244 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4245 if (type == DP_DS_PORT_TYPE_VGA ||
4246 type == DP_DS_PORT_TYPE_NON_EDID)
4247 return connector_status_unknown;
4248 } else {
4249 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4250 DP_DWN_STRM_PORT_TYPE_MASK;
4251 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4252 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4253 return connector_status_unknown;
4254 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004255
4256 /* Anything else is out of spec, warn and ignore */
4257 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004258 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004259}
4260
4261static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004262edp_detect(struct intel_dp *intel_dp)
4263{
4264 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Mika Kahola1650be72016-12-13 10:02:47 +02004265 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsond410b562014-09-02 20:03:59 +01004266 enum drm_connector_status status;
4267
Mika Kahola1650be72016-12-13 10:02:47 +02004268 status = intel_panel_detect(dev_priv);
Chris Wilsond410b562014-09-02 20:03:59 +01004269 if (status == connector_status_unknown)
4270 status = connector_status_connected;
4271
4272 return status;
4273}
4274
Jani Nikulab93433c2015-08-20 10:47:36 +03004275static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4276 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004277{
Jani Nikulab93433c2015-08-20 10:47:36 +03004278 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004279
Jani Nikula0df53b72015-08-20 10:47:40 +03004280 switch (port->port) {
4281 case PORT_A:
4282 return true;
4283 case PORT_B:
4284 bit = SDE_PORTB_HOTPLUG;
4285 break;
4286 case PORT_C:
4287 bit = SDE_PORTC_HOTPLUG;
4288 break;
4289 case PORT_D:
4290 bit = SDE_PORTD_HOTPLUG;
4291 break;
4292 default:
4293 MISSING_CASE(port->port);
4294 return false;
4295 }
4296
4297 return I915_READ(SDEISR) & bit;
4298}
4299
4300static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4301 struct intel_digital_port *port)
4302{
4303 u32 bit;
4304
4305 switch (port->port) {
4306 case PORT_A:
4307 return true;
4308 case PORT_B:
4309 bit = SDE_PORTB_HOTPLUG_CPT;
4310 break;
4311 case PORT_C:
4312 bit = SDE_PORTC_HOTPLUG_CPT;
4313 break;
4314 case PORT_D:
4315 bit = SDE_PORTD_HOTPLUG_CPT;
4316 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004317 case PORT_E:
4318 bit = SDE_PORTE_HOTPLUG_SPT;
4319 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004320 default:
4321 MISSING_CASE(port->port);
4322 return false;
Jani Nikulab93433c2015-08-20 10:47:36 +03004323 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004324
Jani Nikulab93433c2015-08-20 10:47:36 +03004325 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004326}
4327
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004328static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004329 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004330{
Jani Nikula9642c812015-08-20 10:47:41 +03004331 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004332
Jani Nikula9642c812015-08-20 10:47:41 +03004333 switch (port->port) {
4334 case PORT_B:
4335 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4336 break;
4337 case PORT_C:
4338 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4339 break;
4340 case PORT_D:
4341 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4342 break;
4343 default:
4344 MISSING_CASE(port->port);
4345 return false;
4346 }
4347
4348 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4349}
4350
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004351static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4352 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004353{
4354 u32 bit;
4355
4356 switch (port->port) {
4357 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004358 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004359 break;
4360 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004361 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004362 break;
4363 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004364 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004365 break;
4366 default:
4367 MISSING_CASE(port->port);
4368 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004369 }
4370
Jani Nikula1d245982015-08-20 10:47:37 +03004371 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004372}
4373
Jani Nikulae464bfd2015-08-20 10:47:42 +03004374static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304375 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004376{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304377 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4378 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004379 u32 bit;
4380
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304381 intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port);
4382 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004383 case PORT_A:
4384 bit = BXT_DE_PORT_HP_DDIA;
4385 break;
4386 case PORT_B:
4387 bit = BXT_DE_PORT_HP_DDIB;
4388 break;
4389 case PORT_C:
4390 bit = BXT_DE_PORT_HP_DDIC;
4391 break;
4392 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304393 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004394 return false;
4395 }
4396
4397 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4398}
4399
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004400/*
4401 * intel_digital_port_connected - is the specified port connected?
4402 * @dev_priv: i915 private structure
4403 * @port: the port to test
4404 *
4405 * Return %true if @port is connected, %false otherwise.
4406 */
David Weinehall23f889b2016-08-17 15:47:48 +03004407static bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004408 struct intel_digital_port *port)
4409{
Jani Nikula0df53b72015-08-20 10:47:40 +03004410 if (HAS_PCH_IBX(dev_priv))
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004411 return ibx_digital_port_connected(dev_priv, port);
Ville Syrjälä22824fa2016-02-11 16:44:28 +02004412 else if (HAS_PCH_SPLIT(dev_priv))
Jani Nikula0df53b72015-08-20 10:47:40 +03004413 return cpt_digital_port_connected(dev_priv, port);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004414 else if (IS_GEN9_LP(dev_priv))
Jani Nikulae464bfd2015-08-20 10:47:42 +03004415 return bxt_digital_port_connected(dev_priv, port);
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004416 else if (IS_GM45(dev_priv))
4417 return gm45_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004418 else
4419 return g4x_digital_port_connected(dev_priv, port);
4420}
4421
Keith Packard8c241fe2011-09-28 16:38:44 -07004422static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004423intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004424{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004425 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004426
Jani Nikula9cd300e2012-10-19 14:51:52 +03004427 /* use cached edid if we have one */
4428 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004429 /* invalid edid */
4430 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004431 return NULL;
4432
Jani Nikula55e9ede2013-10-01 10:38:54 +03004433 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004434 } else
4435 return drm_get_edid(&intel_connector->base,
4436 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004437}
4438
Chris Wilsonbeb60602014-09-02 20:04:00 +01004439static void
4440intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004441{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004442 struct intel_connector *intel_connector = intel_dp->attached_connector;
4443 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004444
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304445 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004446 edid = intel_dp_get_edid(intel_dp);
4447 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004448
Chris Wilsonbeb60602014-09-02 20:04:00 +01004449 if (intel_dp->force_audio != HDMI_AUDIO_AUTO)
4450 intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON;
4451 else
4452 intel_dp->has_audio = drm_detect_monitor_audio(edid);
4453}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004454
Chris Wilsonbeb60602014-09-02 20:04:00 +01004455static void
4456intel_dp_unset_edid(struct intel_dp *intel_dp)
4457{
4458 struct intel_connector *intel_connector = intel_dp->attached_connector;
4459
4460 kfree(intel_connector->detect_edid);
4461 intel_connector->detect_edid = NULL;
4462
4463 intel_dp->has_audio = false;
4464}
4465
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004466static enum drm_connector_status
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304467intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004468{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304469 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004470 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004471 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4472 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004473 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004474 enum drm_connector_status status;
Imre Deak671dedd2014-03-05 16:20:53 +02004475 enum intel_display_power_domain power_domain;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004476 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004477
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004478 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4479 intel_display_power_get(to_i915(dev), power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004480
Chris Wilsond410b562014-09-02 20:03:59 +01004481 /* Can't disconnect eDP, but you can close the lid... */
4482 if (is_edp(intel_dp))
4483 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004484 else if (intel_digital_port_connected(to_i915(dev),
4485 dp_to_dig_port(intel_dp)))
4486 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004487 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004488 status = connector_status_disconnected;
4489
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004490 if (status == connector_status_disconnected) {
Manasi Navarec1617ab2016-12-09 16:22:50 -08004491 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304492
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004493 if (intel_dp->is_mst) {
4494 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4495 intel_dp->is_mst,
4496 intel_dp->mst_mgr.mst_state);
4497 intel_dp->is_mst = false;
4498 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4499 intel_dp->is_mst);
4500 }
4501
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004502 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304503 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004504
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304505 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004506 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304507
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004508 DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
4509 yesno(intel_dp_source_supports_hbr2(intel_dp)),
4510 yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
4511
Manasi Navaref4829842016-12-05 16:27:36 -08004512 /* Set the max lane count for sink */
4513 intel_dp->max_sink_lane_count = drm_dp_max_lane_count(intel_dp->dpcd);
4514
4515 /* Set the max link BW for sink */
4516 intel_dp->max_sink_link_bw = intel_dp_max_link_bw(intel_dp);
4517
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004518 intel_dp_print_rates(intel_dp);
4519
Imre Deak7b3fc172016-10-25 16:12:39 +03004520 intel_dp_read_desc(intel_dp);
Mika Kahola0e390a32016-09-09 14:10:53 +03004521
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004522 intel_dp_configure_mst(intel_dp);
4523
4524 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304525 /*
4526 * If we are in MST mode then this connector
4527 * won't appear connected or have anything
4528 * with EDID on it
4529 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004530 status = connector_status_disconnected;
4531 goto out;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304532 } else if (connector->status == connector_status_connected) {
4533 /*
4534 * If display was connected already and is still connected
4535 * check links status, there has been known issues of
4536 * link loss triggerring long pulse!!!!
4537 */
4538 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4539 intel_dp_check_link_status(intel_dp);
4540 drm_modeset_unlock(&dev->mode_config.connection_mutex);
4541 goto out;
Dave Airlie0e32b392014-05-02 14:02:48 +10004542 }
4543
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304544 /*
4545 * Clearing NACK and defer counts to get their exact values
4546 * while reading EDID which are required by Compliance tests
4547 * 4.2.2.4 and 4.2.2.5
4548 */
4549 intel_dp->aux.i2c_nack_count = 0;
4550 intel_dp->aux.i2c_defer_count = 0;
4551
Chris Wilsonbeb60602014-09-02 20:04:00 +01004552 intel_dp_set_edid(intel_dp);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004553 if (is_edp(intel_dp) || intel_connector->detect_edid)
4554 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304555 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004556
Todd Previte09b1eb12015-04-20 15:27:34 -07004557 /* Try to read the source of the interrupt */
4558 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004559 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4560 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004561 /* Clear interrupt source */
4562 drm_dp_dpcd_writeb(&intel_dp->aux,
4563 DP_DEVICE_SERVICE_IRQ_VECTOR,
4564 sink_irq_vector);
4565
4566 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4567 intel_dp_handle_test_request(intel_dp);
4568 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4569 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4570 }
4571
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004572out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004573 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304574 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304575
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004576 intel_display_power_put(to_i915(dev), power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004577 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304578}
4579
4580static enum drm_connector_status
4581intel_dp_detect(struct drm_connector *connector, bool force)
4582{
4583 struct intel_dp *intel_dp = intel_attached_dp(connector);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004584 enum drm_connector_status status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304585
4586 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4587 connector->base.id, connector->name);
4588
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304589 /* If full detect is not performed yet, do a full detect */
4590 if (!intel_dp->detect_done)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004591 status = intel_dp_long_pulse(intel_dp->attached_connector);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304592
4593 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304594
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004595 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004596}
4597
Chris Wilsonbeb60602014-09-02 20:04:00 +01004598static void
4599intel_dp_force(struct drm_connector *connector)
4600{
4601 struct intel_dp *intel_dp = intel_attached_dp(connector);
4602 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004603 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004604 enum intel_display_power_domain power_domain;
4605
4606 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4607 connector->base.id, connector->name);
4608 intel_dp_unset_edid(intel_dp);
4609
4610 if (connector->status != connector_status_connected)
4611 return;
4612
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004613 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4614 intel_display_power_get(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004615
4616 intel_dp_set_edid(intel_dp);
4617
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004618 intel_display_power_put(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004619
4620 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004621 intel_encoder->type = INTEL_OUTPUT_DP;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004622}
4623
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004624static int intel_dp_get_modes(struct drm_connector *connector)
4625{
Jani Nikuladd06f902012-10-19 14:51:50 +03004626 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004627 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004628
Chris Wilsonbeb60602014-09-02 20:04:00 +01004629 edid = intel_connector->detect_edid;
4630 if (edid) {
4631 int ret = intel_connector_update_modes(connector, edid);
4632 if (ret)
4633 return ret;
4634 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004635
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004636 /* if eDP has no EDID, fall back to fixed mode */
Chris Wilsonbeb60602014-09-02 20:04:00 +01004637 if (is_edp(intel_attached_dp(connector)) &&
4638 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004639 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004640
4641 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004642 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004643 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004644 drm_mode_probed_add(connector, mode);
4645 return 1;
4646 }
4647 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004648
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004649 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004650}
4651
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004652static bool
4653intel_dp_detect_audio(struct drm_connector *connector)
4654{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004655 bool has_audio = false;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004656 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004657
Chris Wilsonbeb60602014-09-02 20:04:00 +01004658 edid = to_intel_connector(connector)->detect_edid;
4659 if (edid)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004660 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02004661
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004662 return has_audio;
4663}
4664
Chris Wilsonf6849602010-09-19 09:29:33 +01004665static int
4666intel_dp_set_property(struct drm_connector *connector,
4667 struct drm_property *property,
4668 uint64_t val)
4669{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004670 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Yuly Novikov53b41832012-10-26 12:04:00 +03004671 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004672 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
4673 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01004674 int ret;
4675
Rob Clark662595d2012-10-11 20:36:04 -05004676 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01004677 if (ret)
4678 return ret;
4679
Chris Wilson3f43c482011-05-12 22:17:24 +01004680 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004681 int i = val;
4682 bool has_audio;
4683
4684 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004685 return 0;
4686
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004687 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01004688
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004689 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004690 has_audio = intel_dp_detect_audio(connector);
4691 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004692 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004693
4694 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004695 return 0;
4696
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004697 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01004698 goto done;
4699 }
4700
Chris Wilsone953fd72011-02-21 22:23:52 +00004701 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02004702 bool old_auto = intel_dp->color_range_auto;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004703 bool old_range = intel_dp->limited_color_range;
Daniel Vetterae4edb82013-04-22 17:07:23 +02004704
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004705 switch (val) {
4706 case INTEL_BROADCAST_RGB_AUTO:
4707 intel_dp->color_range_auto = true;
4708 break;
4709 case INTEL_BROADCAST_RGB_FULL:
4710 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004711 intel_dp->limited_color_range = false;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004712 break;
4713 case INTEL_BROADCAST_RGB_LIMITED:
4714 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004715 intel_dp->limited_color_range = true;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004716 break;
4717 default:
4718 return -EINVAL;
4719 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02004720
4721 if (old_auto == intel_dp->color_range_auto &&
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004722 old_range == intel_dp->limited_color_range)
Daniel Vetterae4edb82013-04-22 17:07:23 +02004723 return 0;
4724
Chris Wilsone953fd72011-02-21 22:23:52 +00004725 goto done;
4726 }
4727
Yuly Novikov53b41832012-10-26 12:04:00 +03004728 if (is_edp(intel_dp) &&
4729 property == connector->dev->mode_config.scaling_mode_property) {
4730 if (val == DRM_MODE_SCALE_NONE) {
4731 DRM_DEBUG_KMS("no scaling not supported\n");
4732 return -EINVAL;
4733 }
Ville Syrjälä234126c2016-04-12 22:14:38 +03004734 if (HAS_GMCH_DISPLAY(dev_priv) &&
4735 val == DRM_MODE_SCALE_CENTER) {
4736 DRM_DEBUG_KMS("centering not supported\n");
4737 return -EINVAL;
4738 }
Yuly Novikov53b41832012-10-26 12:04:00 +03004739
4740 if (intel_connector->panel.fitting_mode == val) {
4741 /* the eDP scaling property is not changed */
4742 return 0;
4743 }
4744 intel_connector->panel.fitting_mode = val;
4745
4746 goto done;
4747 }
4748
Chris Wilsonf6849602010-09-19 09:29:33 +01004749 return -EINVAL;
4750
4751done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00004752 if (intel_encoder->base.crtc)
4753 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01004754
4755 return 0;
4756}
4757
Chris Wilson7a418e32016-06-24 14:00:14 +01004758static int
4759intel_dp_connector_register(struct drm_connector *connector)
4760{
4761 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004762 int ret;
4763
4764 ret = intel_connector_register(connector);
4765 if (ret)
4766 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004767
4768 i915_debugfs_connector_add(connector);
4769
4770 DRM_DEBUG_KMS("registering %s bus for %s\n",
4771 intel_dp->aux.name, connector->kdev->kobj.name);
4772
4773 intel_dp->aux.dev = connector->kdev;
4774 return drm_dp_aux_register(&intel_dp->aux);
4775}
4776
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004777static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004778intel_dp_connector_unregister(struct drm_connector *connector)
4779{
4780 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4781 intel_connector_unregister(connector);
4782}
4783
4784static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004785intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004786{
Jani Nikula1d508702012-10-19 14:51:49 +03004787 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004788
Chris Wilson10e972d2014-09-04 21:43:45 +01004789 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004790
Jani Nikula9cd300e2012-10-19 14:51:52 +03004791 if (!IS_ERR_OR_NULL(intel_connector->edid))
4792 kfree(intel_connector->edid);
4793
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004794 /* Can't call is_edp() since the encoder may have been destroyed
4795 * already. */
4796 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004797 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004798
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004799 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004800 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004801}
4802
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004803void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004804{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004805 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4806 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004807
Dave Airlie0e32b392014-05-02 14:02:48 +10004808 intel_dp_mst_encoder_cleanup(intel_dig_port);
Keith Packardbd943152011-09-18 23:09:52 -07004809 if (is_edp(intel_dp)) {
4810 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004811 /*
4812 * vdd might still be enabled do to the delayed vdd off.
4813 * Make sure vdd is actually turned off here.
4814 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004815 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004816 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004817 pps_unlock(intel_dp);
4818
Clint Taylor01527b32014-07-07 13:01:46 -07004819 if (intel_dp->edp_notifier.notifier_call) {
4820 unregister_reboot_notifier(&intel_dp->edp_notifier);
4821 intel_dp->edp_notifier.notifier_call = NULL;
4822 }
Keith Packardbd943152011-09-18 23:09:52 -07004823 }
Chris Wilson99681882016-06-20 09:29:17 +01004824
4825 intel_dp_aux_fini(intel_dp);
4826
Imre Deakc8bd0e42014-12-12 17:57:38 +02004827 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004828 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004829}
4830
Imre Deakbf93ba62016-04-18 10:04:21 +03004831void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004832{
4833 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4834
4835 if (!is_edp(intel_dp))
4836 return;
4837
Ville Syrjälä951468f2014-09-04 14:55:31 +03004838 /*
4839 * vdd might still be enabled do to the delayed vdd off.
4840 * Make sure vdd is actually turned off here.
4841 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004842 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004843 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004844 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004845 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004846}
4847
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004848static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4849{
4850 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4851 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004852 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004853 enum intel_display_power_domain power_domain;
4854
4855 lockdep_assert_held(&dev_priv->pps_mutex);
4856
4857 if (!edp_have_panel_vdd(intel_dp))
4858 return;
4859
4860 /*
4861 * The VDD bit needs a power domain reference, so if the bit is
4862 * already enabled when we boot or resume, grab this reference and
4863 * schedule a vdd off, so we don't hold on to the reference
4864 * indefinitely.
4865 */
4866 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004867 power_domain = intel_display_port_aux_power_domain(&intel_dig_port->base);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004868 intel_display_power_get(dev_priv, power_domain);
4869
4870 edp_panel_vdd_schedule_off(intel_dp);
4871}
4872
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02004873static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
4874{
4875 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
4876
4877 if ((intel_dp->DP & DP_PORT_EN) == 0)
4878 return INVALID_PIPE;
4879
4880 if (IS_CHERRYVIEW(dev_priv))
4881 return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
4882 else
4883 return PORT_TO_PIPE(intel_dp->DP);
4884}
4885
Imre Deakbf93ba62016-04-18 10:04:21 +03004886void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03004887{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03004888 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Imre Deakdd75f6d2016-11-21 21:15:05 +02004889 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
4890 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Ville Syrjälä64989ca42016-05-13 20:53:56 +03004891
4892 if (!HAS_DDI(dev_priv))
4893 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004894
Imre Deakdd75f6d2016-11-21 21:15:05 +02004895 if (lspcon->active)
Shashank Sharma910530c2016-10-14 19:56:52 +05304896 lspcon_resume(lspcon);
4897
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004898 pps_lock(intel_dp);
4899
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02004900 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4901 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
4902
4903 if (is_edp(intel_dp)) {
4904 /* Reinit the power sequencer, in case BIOS did something with it. */
4905 intel_dp_pps_init(encoder->dev, intel_dp);
4906 intel_edp_panel_vdd_sanitize(intel_dp);
4907 }
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004908
4909 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03004910}
4911
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004912static const struct drm_connector_funcs intel_dp_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02004913 .dpms = drm_atomic_helper_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004914 .detect = intel_dp_detect,
Chris Wilsonbeb60602014-09-02 20:04:00 +01004915 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004916 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01004917 .set_property = intel_dp_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -08004918 .atomic_get_property = intel_connector_atomic_get_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01004919 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01004920 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004921 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08004922 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02004923 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004924};
4925
4926static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
4927 .get_modes = intel_dp_get_modes,
4928 .mode_valid = intel_dp_mode_valid,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004929};
4930
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004931static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03004932 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02004933 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004934};
4935
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004936enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10004937intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
4938{
4939 struct intel_dp *intel_dp = &intel_dig_port->dp;
Imre Deak1c767b32014-08-18 14:42:42 +03004940 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Dave Airlie0e32b392014-05-02 14:02:48 +10004941 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004942 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak1c767b32014-08-18 14:42:42 +03004943 enum intel_display_power_domain power_domain;
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004944 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03004945
Takashi Iwai25400582015-11-19 12:09:56 +01004946 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
4947 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004948 intel_dig_port->base.type = INTEL_OUTPUT_DP;
Dave Airlie13cf5502014-06-18 11:29:35 +10004949
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03004950 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
4951 /*
4952 * vdd off can generate a long pulse on eDP which
4953 * would require vdd on to handle it, and thus we
4954 * would end up in an endless cycle of
4955 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
4956 */
4957 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
4958 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d522015-02-10 14:11:46 +02004959 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03004960 }
4961
Ville Syrjälä26fbb772014-08-11 18:37:37 +03004962 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
4963 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10004964 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10004965
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004966 if (long_hpd) {
4967 intel_dp->detect_done = false;
4968 return IRQ_NONE;
4969 }
4970
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004971 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak1c767b32014-08-18 14:42:42 +03004972 intel_display_power_get(dev_priv, power_domain);
4973
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004974 if (intel_dp->is_mst) {
4975 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
4976 /*
4977 * If we were in MST mode, and device is not
4978 * there, get out of MST mode
4979 */
4980 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4981 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
4982 intel_dp->is_mst = false;
4983 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4984 intel_dp->is_mst);
4985 intel_dp->detect_done = false;
4986 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10004987 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004988 }
Dave Airlie0e32b392014-05-02 14:02:48 +10004989
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004990 if (!intel_dp->is_mst) {
4991 if (!intel_dp_short_pulse(intel_dp)) {
4992 intel_dp->detect_done = false;
4993 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304994 }
Dave Airlie0e32b392014-05-02 14:02:48 +10004995 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004996
4997 ret = IRQ_HANDLED;
4998
Imre Deak1c767b32014-08-18 14:42:42 +03004999put_power:
5000 intel_display_power_put(dev_priv, power_domain);
5001
5002 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10005003}
5004
Rodrigo Vivi477ec322015-08-06 15:51:39 +08005005/* check the VBT to see whether the eDP is on another port */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005006bool intel_dp_is_edp(struct drm_i915_private *dev_priv, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08005007{
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005008 /*
5009 * eDP not supported on g4x. so bail out early just
5010 * for a bit extra safety in case the VBT is bonkers.
5011 */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005012 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005013 return false;
5014
Imre Deaka98d9c12016-12-21 12:17:24 +02005015 if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005016 return true;
5017
Jani Nikula951d9ef2016-03-16 12:43:31 +02005018 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08005019}
5020
Dave Airlie0e32b392014-05-02 14:02:48 +10005021void
Chris Wilsonf6849602010-09-19 09:29:33 +01005022intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
5023{
Yuly Novikov53b41832012-10-26 12:04:00 +03005024 struct intel_connector *intel_connector = to_intel_connector(connector);
5025
Chris Wilson3f43c482011-05-12 22:17:24 +01005026 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00005027 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02005028 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03005029
5030 if (is_edp(intel_dp)) {
5031 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05005032 drm_object_attach_property(
5033 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03005034 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03005035 DRM_MODE_SCALE_ASPECT);
5036 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03005037 }
Chris Wilsonf6849602010-09-19 09:29:33 +01005038}
5039
Imre Deakdada1a92014-01-29 13:25:41 +02005040static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
5041{
Abhay Kumard28d4732016-01-22 17:39:04 -08005042 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02005043 intel_dp->last_power_on = jiffies;
5044 intel_dp->last_backlight_off = jiffies;
5045}
5046
Daniel Vetter67a54562012-10-20 20:57:45 +02005047static void
Imre Deak54648612016-06-16 16:37:22 +03005048intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
5049 struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02005050{
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305051 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03005052 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07005053
Imre Deak8e8232d2016-06-16 16:37:21 +03005054 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02005055
5056 /* Workaround: Need to write PP_CONTROL with the unlock key as
5057 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305058 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02005059
Imre Deak8e8232d2016-06-16 16:37:21 +03005060 pp_on = I915_READ(regs.pp_on);
5061 pp_off = I915_READ(regs.pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005062 if (!IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005063 I915_WRITE(regs.pp_ctrl, pp_ctl);
5064 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305065 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005066
5067 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03005068 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
5069 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005070
Imre Deak54648612016-06-16 16:37:22 +03005071 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
5072 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005073
Imre Deak54648612016-06-16 16:37:22 +03005074 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
5075 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005076
Imre Deak54648612016-06-16 16:37:22 +03005077 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
5078 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005079
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005080 if (IS_GEN9_LP(dev_priv)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305081 u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
5082 BXT_POWER_CYCLE_DELAY_SHIFT;
5083 if (tmp > 0)
Imre Deak54648612016-06-16 16:37:22 +03005084 seq->t11_t12 = (tmp - 1) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305085 else
Imre Deak54648612016-06-16 16:37:22 +03005086 seq->t11_t12 = 0;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305087 } else {
Imre Deak54648612016-06-16 16:37:22 +03005088 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02005089 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305090 }
Imre Deak54648612016-06-16 16:37:22 +03005091}
5092
5093static void
Imre Deakde9c1b62016-06-16 20:01:46 +03005094intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
5095{
5096 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5097 state_name,
5098 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
5099}
5100
5101static void
5102intel_pps_verify_state(struct drm_i915_private *dev_priv,
5103 struct intel_dp *intel_dp)
5104{
5105 struct edp_power_seq hw;
5106 struct edp_power_seq *sw = &intel_dp->pps_delays;
5107
5108 intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
5109
5110 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
5111 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
5112 DRM_ERROR("PPS state mismatch\n");
5113 intel_pps_dump_state("sw", sw);
5114 intel_pps_dump_state("hw", &hw);
5115 }
5116}
5117
5118static void
Imre Deak54648612016-06-16 16:37:22 +03005119intel_dp_init_panel_power_sequencer(struct drm_device *dev,
5120 struct intel_dp *intel_dp)
5121{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005122 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak54648612016-06-16 16:37:22 +03005123 struct edp_power_seq cur, vbt, spec,
5124 *final = &intel_dp->pps_delays;
5125
5126 lockdep_assert_held(&dev_priv->pps_mutex);
5127
5128 /* already initialized? */
5129 if (final->t11_t12 != 0)
5130 return;
5131
5132 intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005133
Imre Deakde9c1b62016-06-16 20:01:46 +03005134 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005135
Jani Nikula6aa23e62016-03-24 17:50:20 +02005136 vbt = dev_priv->vbt.edp.pps;
Daniel Vetter67a54562012-10-20 20:57:45 +02005137
5138 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5139 * our hw here, which are all in 100usec. */
5140 spec.t1_t3 = 210 * 10;
5141 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5142 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5143 spec.t10 = 500 * 10;
5144 /* This one is special and actually in units of 100ms, but zero
5145 * based in the hw (so we need to add 100 ms). But the sw vbt
5146 * table multiplies it with 1000 to make it in units of 100usec,
5147 * too. */
5148 spec.t11_t12 = (510 + 100) * 10;
5149
Imre Deakde9c1b62016-06-16 20:01:46 +03005150 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005151
5152 /* Use the max of the register settings and vbt. If both are
5153 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005154#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005155 spec.field : \
5156 max(cur.field, vbt.field))
5157 assign_final(t1_t3);
5158 assign_final(t8);
5159 assign_final(t9);
5160 assign_final(t10);
5161 assign_final(t11_t12);
5162#undef assign_final
5163
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005164#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005165 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5166 intel_dp->backlight_on_delay = get_delay(t8);
5167 intel_dp->backlight_off_delay = get_delay(t9);
5168 intel_dp->panel_power_down_delay = get_delay(t10);
5169 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5170#undef get_delay
5171
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005172 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5173 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5174 intel_dp->panel_power_cycle_delay);
5175
5176 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5177 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005178
5179 /*
5180 * We override the HW backlight delays to 1 because we do manual waits
5181 * on them. For T8, even BSpec recommends doing it. For T9, if we
5182 * don't do this, we'll end up waiting for the backlight off delay
5183 * twice: once when we do the manual sleep, and once when we disable
5184 * the panel and wait for the PP_STATUS bit to become zero.
5185 */
5186 final->t8 = 1;
5187 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005188}
5189
5190static void
5191intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005192 struct intel_dp *intel_dp,
5193 bool force_disable_vdd)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005194{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005195 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07005196 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005197 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005198 struct pps_registers regs;
Ville Syrjäläad933b52014-08-18 22:15:56 +03005199 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005200 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005201
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005202 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005203
Imre Deak8e8232d2016-06-16 16:37:21 +03005204 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005205
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005206 /*
5207 * On some VLV machines the BIOS can leave the VDD
5208 * enabled even on power seqeuencers which aren't
5209 * hooked up to any port. This would mess up the
5210 * power domain tracking the first time we pick
5211 * one of these power sequencers for use since
5212 * edp_panel_vdd_on() would notice that the VDD was
5213 * already on and therefore wouldn't grab the power
5214 * domain reference. Disable VDD first to avoid this.
5215 * This also avoids spuriously turning the VDD on as
5216 * soon as the new power seqeuencer gets initialized.
5217 */
5218 if (force_disable_vdd) {
5219 u32 pp = ironlake_get_pp_control(intel_dp);
5220
5221 WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
5222
5223 if (pp & EDP_FORCE_VDD)
5224 DRM_DEBUG_KMS("VDD already on, disabling first\n");
5225
5226 pp &= ~EDP_FORCE_VDD;
5227
5228 I915_WRITE(regs.pp_ctrl, pp);
5229 }
5230
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005231 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005232 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5233 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005234 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005235 /* Compute the divisor for the pp clock, simply match the Bspec
5236 * formula. */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005237 if (IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005238 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305239 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
5240 pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
5241 << BXT_POWER_CYCLE_DELAY_SHIFT);
5242 } else {
5243 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5244 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5245 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5246 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005247
5248 /* Haswell doesn't have any port selection bits for the panel
5249 * power sequencer any more. */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005250 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005251 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005252 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005253 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005254 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005255 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005256 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005257 }
5258
Jesse Barnes453c5422013-03-28 09:55:41 -07005259 pp_on |= port_sel;
5260
Imre Deak8e8232d2016-06-16 16:37:21 +03005261 I915_WRITE(regs.pp_on, pp_on);
5262 I915_WRITE(regs.pp_off, pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005263 if (IS_GEN9_LP(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005264 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305265 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005266 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005267
Daniel Vetter67a54562012-10-20 20:57:45 +02005268 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 +03005269 I915_READ(regs.pp_on),
5270 I915_READ(regs.pp_off),
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005271 IS_GEN9_LP(dev_priv) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005272 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5273 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005274}
5275
Imre Deak335f7522016-08-10 14:07:32 +03005276static void intel_dp_pps_init(struct drm_device *dev,
5277 struct intel_dp *intel_dp)
5278{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005279 struct drm_i915_private *dev_priv = to_i915(dev);
5280
5281 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Imre Deak335f7522016-08-10 14:07:32 +03005282 vlv_initial_power_sequencer_setup(intel_dp);
5283 } else {
5284 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005285 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak335f7522016-08-10 14:07:32 +03005286 }
5287}
5288
Vandana Kannanb33a2812015-02-13 15:33:03 +05305289/**
5290 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005291 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005292 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305293 * @refresh_rate: RR to be programmed
5294 *
5295 * This function gets called when refresh rate (RR) has to be changed from
5296 * one frequency to another. Switches can be between high and low RR
5297 * supported by the panel or to any other RR based on media playback (in
5298 * this case, RR value needs to be passed from user space).
5299 *
5300 * The caller of this function needs to take a lock on dev_priv->drrs.
5301 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005302static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
5303 struct intel_crtc_state *crtc_state,
5304 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305305{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305306 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305307 struct intel_digital_port *dig_port = NULL;
5308 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005309 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305310 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305311
5312 if (refresh_rate <= 0) {
5313 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5314 return;
5315 }
5316
Vandana Kannan96178ee2015-01-10 02:25:56 +05305317 if (intel_dp == NULL) {
5318 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305319 return;
5320 }
5321
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005322 /*
Rodrigo Vivie4d59f62014-11-20 02:22:08 -08005323 * FIXME: This needs proper synchronization with psr state for some
5324 * platforms that cannot have PSR and DRRS enabled at the same time.
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005325 */
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305326
Vandana Kannan96178ee2015-01-10 02:25:56 +05305327 dig_port = dp_to_dig_port(intel_dp);
5328 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02005329 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305330
5331 if (!intel_crtc) {
5332 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5333 return;
5334 }
5335
Vandana Kannan96178ee2015-01-10 02:25:56 +05305336 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305337 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5338 return;
5339 }
5340
Vandana Kannan96178ee2015-01-10 02:25:56 +05305341 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5342 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305343 index = DRRS_LOW_RR;
5344
Vandana Kannan96178ee2015-01-10 02:25:56 +05305345 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305346 DRM_DEBUG_KMS(
5347 "DRRS requested for previously set RR...ignoring\n");
5348 return;
5349 }
5350
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005351 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305352 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5353 return;
5354 }
5355
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005356 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305357 switch (index) {
5358 case DRRS_HIGH_RR:
5359 intel_dp_set_m_n(intel_crtc, M1_N1);
5360 break;
5361 case DRRS_LOW_RR:
5362 intel_dp_set_m_n(intel_crtc, M2_N2);
5363 break;
5364 case DRRS_MAX_RR:
5365 default:
5366 DRM_ERROR("Unsupported refreshrate type\n");
5367 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005368 } else if (INTEL_GEN(dev_priv) > 6) {
5369 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005370 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305371
Ville Syrjälä649636e2015-09-22 19:50:01 +03005372 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305373 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005374 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305375 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5376 else
5377 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305378 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005379 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305380 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5381 else
5382 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305383 }
5384 I915_WRITE(reg, val);
5385 }
5386
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305387 dev_priv->drrs.refresh_rate_type = index;
5388
5389 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5390}
5391
Vandana Kannanb33a2812015-02-13 15:33:03 +05305392/**
5393 * intel_edp_drrs_enable - init drrs struct if supported
5394 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005395 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305396 *
5397 * Initializes frontbuffer_bits and drrs.dp
5398 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005399void intel_edp_drrs_enable(struct intel_dp *intel_dp,
5400 struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305401{
5402 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005403 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305404
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005405 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305406 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5407 return;
5408 }
5409
5410 mutex_lock(&dev_priv->drrs.mutex);
5411 if (WARN_ON(dev_priv->drrs.dp)) {
5412 DRM_ERROR("DRRS already enabled\n");
5413 goto unlock;
5414 }
5415
5416 dev_priv->drrs.busy_frontbuffer_bits = 0;
5417
5418 dev_priv->drrs.dp = intel_dp;
5419
5420unlock:
5421 mutex_unlock(&dev_priv->drrs.mutex);
5422}
5423
Vandana Kannanb33a2812015-02-13 15:33:03 +05305424/**
5425 * intel_edp_drrs_disable - Disable DRRS
5426 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005427 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305428 *
5429 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005430void intel_edp_drrs_disable(struct intel_dp *intel_dp,
5431 struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305432{
5433 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005434 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305435
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005436 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305437 return;
5438
5439 mutex_lock(&dev_priv->drrs.mutex);
5440 if (!dev_priv->drrs.dp) {
5441 mutex_unlock(&dev_priv->drrs.mutex);
5442 return;
5443 }
5444
5445 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005446 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5447 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305448
5449 dev_priv->drrs.dp = NULL;
5450 mutex_unlock(&dev_priv->drrs.mutex);
5451
5452 cancel_delayed_work_sync(&dev_priv->drrs.work);
5453}
5454
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305455static void intel_edp_drrs_downclock_work(struct work_struct *work)
5456{
5457 struct drm_i915_private *dev_priv =
5458 container_of(work, typeof(*dev_priv), drrs.work.work);
5459 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305460
Vandana Kannan96178ee2015-01-10 02:25:56 +05305461 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305462
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305463 intel_dp = dev_priv->drrs.dp;
5464
5465 if (!intel_dp)
5466 goto unlock;
5467
5468 /*
5469 * The delayed work can race with an invalidate hence we need to
5470 * recheck.
5471 */
5472
5473 if (dev_priv->drrs.busy_frontbuffer_bits)
5474 goto unlock;
5475
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005476 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5477 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5478
5479 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5480 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5481 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305482
5483unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305484 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305485}
5486
Vandana Kannanb33a2812015-02-13 15:33:03 +05305487/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305488 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005489 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305490 * @frontbuffer_bits: frontbuffer plane tracking bits
5491 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305492 * This function gets called everytime rendering on the given planes start.
5493 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305494 *
5495 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5496 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005497void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5498 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305499{
Vandana Kannana93fad02015-01-10 02:25:59 +05305500 struct drm_crtc *crtc;
5501 enum pipe pipe;
5502
Daniel Vetter9da7d692015-04-09 16:44:15 +02005503 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305504 return;
5505
Daniel Vetter88f933a2015-04-09 16:44:16 +02005506 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305507
Vandana Kannana93fad02015-01-10 02:25:59 +05305508 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005509 if (!dev_priv->drrs.dp) {
5510 mutex_unlock(&dev_priv->drrs.mutex);
5511 return;
5512 }
5513
Vandana Kannana93fad02015-01-10 02:25:59 +05305514 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5515 pipe = to_intel_crtc(crtc)->pipe;
5516
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005517 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5518 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5519
Ramalingam C0ddfd202015-06-15 20:50:05 +05305520 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005521 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005522 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5523 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305524
Vandana Kannana93fad02015-01-10 02:25:59 +05305525 mutex_unlock(&dev_priv->drrs.mutex);
5526}
5527
Vandana Kannanb33a2812015-02-13 15:33:03 +05305528/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305529 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005530 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305531 * @frontbuffer_bits: frontbuffer plane tracking bits
5532 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305533 * This function gets called every time rendering on the given planes has
5534 * completed or flip on a crtc is completed. So DRRS should be upclocked
5535 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5536 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305537 *
5538 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5539 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005540void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5541 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305542{
Vandana Kannana93fad02015-01-10 02:25:59 +05305543 struct drm_crtc *crtc;
5544 enum pipe pipe;
5545
Daniel Vetter9da7d692015-04-09 16:44:15 +02005546 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305547 return;
5548
Daniel Vetter88f933a2015-04-09 16:44:16 +02005549 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305550
Vandana Kannana93fad02015-01-10 02:25:59 +05305551 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005552 if (!dev_priv->drrs.dp) {
5553 mutex_unlock(&dev_priv->drrs.mutex);
5554 return;
5555 }
5556
Vandana Kannana93fad02015-01-10 02:25:59 +05305557 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5558 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005559
5560 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305561 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5562
Ramalingam C0ddfd202015-06-15 20:50:05 +05305563 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005564 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005565 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5566 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305567
5568 /*
5569 * flush also means no more activity hence schedule downclock, if all
5570 * other fbs are quiescent too
5571 */
5572 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305573 schedule_delayed_work(&dev_priv->drrs.work,
5574 msecs_to_jiffies(1000));
5575 mutex_unlock(&dev_priv->drrs.mutex);
5576}
5577
Vandana Kannanb33a2812015-02-13 15:33:03 +05305578/**
5579 * DOC: Display Refresh Rate Switching (DRRS)
5580 *
5581 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5582 * which enables swtching between low and high refresh rates,
5583 * dynamically, based on the usage scenario. This feature is applicable
5584 * for internal panels.
5585 *
5586 * Indication that the panel supports DRRS is given by the panel EDID, which
5587 * would list multiple refresh rates for one resolution.
5588 *
5589 * DRRS is of 2 types - static and seamless.
5590 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5591 * (may appear as a blink on screen) and is used in dock-undock scenario.
5592 * Seamless DRRS involves changing RR without any visual effect to the user
5593 * and can be used during normal system usage. This is done by programming
5594 * certain registers.
5595 *
5596 * Support for static/seamless DRRS may be indicated in the VBT based on
5597 * inputs from the panel spec.
5598 *
5599 * DRRS saves power by switching to low RR based on usage scenarios.
5600 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005601 * The implementation is based on frontbuffer tracking implementation. When
5602 * there is a disturbance on the screen triggered by user activity or a periodic
5603 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5604 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5605 * made.
5606 *
5607 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5608 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305609 *
5610 * DRRS can be further extended to support other internal panels and also
5611 * the scenario of video playback wherein RR is set based on the rate
5612 * requested by userspace.
5613 */
5614
5615/**
5616 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5617 * @intel_connector: eDP connector
5618 * @fixed_mode: preferred mode of panel
5619 *
5620 * This function is called only once at driver load to initialize basic
5621 * DRRS stuff.
5622 *
5623 * Returns:
5624 * Downclock mode if panel supports it, else return NULL.
5625 * DRRS support is determined by the presence of downclock mode (apart
5626 * from VBT setting).
5627 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305628static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305629intel_dp_drrs_init(struct intel_connector *intel_connector,
5630 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305631{
5632 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305633 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005634 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305635 struct drm_display_mode *downclock_mode = NULL;
5636
Daniel Vetter9da7d692015-04-09 16:44:15 +02005637 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5638 mutex_init(&dev_priv->drrs.mutex);
5639
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005640 if (INTEL_GEN(dev_priv) <= 6) {
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305641 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5642 return NULL;
5643 }
5644
5645 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005646 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305647 return NULL;
5648 }
5649
5650 downclock_mode = intel_find_panel_downclock
Mika Kaholaa318b4c2016-12-13 10:02:48 +02005651 (dev_priv, fixed_mode, connector);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305652
5653 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305654 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305655 return NULL;
5656 }
5657
Vandana Kannan96178ee2015-01-10 02:25:56 +05305658 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305659
Vandana Kannan96178ee2015-01-10 02:25:56 +05305660 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005661 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305662 return downclock_mode;
5663}
5664
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005665static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005666 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005667{
5668 struct drm_connector *connector = &intel_connector->base;
5669 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005670 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5671 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005672 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005673 struct drm_display_mode *fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305674 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005675 bool has_dpcd;
5676 struct drm_display_mode *scan;
5677 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005678 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005679
5680 if (!is_edp(intel_dp))
5681 return true;
5682
Imre Deak97a824e12016-06-21 11:51:47 +03005683 /*
5684 * On IBX/CPT we may get here with LVDS already registered. Since the
5685 * driver uses the only internal power sequencer available for both
5686 * eDP and LVDS bail out early in this case to prevent interfering
5687 * with an already powered-on LVDS power sequencer.
5688 */
5689 if (intel_get_lvds_encoder(dev)) {
5690 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5691 DRM_INFO("LVDS was detected, not registering eDP\n");
5692
5693 return false;
5694 }
5695
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005696 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005697
5698 intel_dp_init_panel_power_timestamps(intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +03005699 intel_dp_pps_init(dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005700 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005701
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005702 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005703
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005704 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005705 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005706
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005707 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005708 /* if this fails, presume the device is a ghost */
5709 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005710 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005711 }
5712
Daniel Vetter060c8772014-03-21 23:22:35 +01005713 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005714 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005715 if (edid) {
5716 if (drm_add_edid_modes(connector, edid)) {
5717 drm_mode_connector_update_edid_property(connector,
5718 edid);
5719 drm_edid_to_eld(connector, edid);
5720 } else {
5721 kfree(edid);
5722 edid = ERR_PTR(-EINVAL);
5723 }
5724 } else {
5725 edid = ERR_PTR(-ENOENT);
5726 }
5727 intel_connector->edid = edid;
5728
5729 /* prefer fixed mode from EDID if available */
5730 list_for_each_entry(scan, &connector->probed_modes, head) {
5731 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5732 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305733 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305734 intel_connector, fixed_mode);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005735 break;
5736 }
5737 }
5738
5739 /* fallback to VBT if available for eDP */
5740 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5741 fixed_mode = drm_mode_duplicate(dev,
5742 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005743 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005744 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005745 connector->display_info.width_mm = fixed_mode->width_mm;
5746 connector->display_info.height_mm = fixed_mode->height_mm;
5747 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005748 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005749 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005750
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005751 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005752 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5753 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005754
5755 /*
5756 * Figure out the current pipe for the initial backlight setup.
5757 * If the current pipe isn't valid, try the PPS pipe, and if that
5758 * fails just assume pipe A.
5759 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005760 pipe = vlv_active_pipe(intel_dp);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005761
5762 if (pipe != PIPE_A && pipe != PIPE_B)
5763 pipe = intel_dp->pps_pipe;
5764
5765 if (pipe != PIPE_A && pipe != PIPE_B)
5766 pipe = PIPE_A;
5767
5768 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5769 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005770 }
5771
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305772 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005773 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005774 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005775
5776 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005777
5778out_vdd_off:
5779 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5780 /*
5781 * vdd might still be enabled do to the delayed vdd off.
5782 * Make sure vdd is actually turned off here.
5783 */
5784 pps_lock(intel_dp);
5785 edp_panel_vdd_off_sync(intel_dp);
5786 pps_unlock(intel_dp);
5787
5788 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005789}
5790
Paulo Zanoni16c25532013-06-12 17:27:25 -03005791bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005792intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5793 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005794{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005795 struct drm_connector *connector = &intel_connector->base;
5796 struct intel_dp *intel_dp = &intel_dig_port->dp;
5797 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5798 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005799 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02005800 enum port port = intel_dig_port->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01005801 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005802
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005803 if (WARN(intel_dig_port->max_lanes < 1,
5804 "Not enough lanes (%d) for DP on port %c\n",
5805 intel_dig_port->max_lanes, port_name(port)))
5806 return false;
5807
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005808 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005809 intel_dp->active_pipe = INVALID_PIPE;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005810
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005811 /* intel_dp vfuncs */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005812 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub6b5e382014-01-20 16:00:59 +00005813 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005814 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005815 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005816 else if (HAS_PCH_SPLIT(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005817 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
5818 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005819 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005820
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005821 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00005822 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
5823 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005824 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00005825
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005826 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03005827 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
5828
Daniel Vetter07679352012-09-06 22:15:42 +02005829 /* Preserve the current hw state. */
5830 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03005831 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00005832
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005833 if (intel_dp_is_edp(dev_priv, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05305834 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005835 else
5836 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04005837
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005838 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5839 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5840
Imre Deakf7d24902013-05-08 13:14:05 +03005841 /*
5842 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
5843 * for DP the encoder type can be set by the caller to
5844 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
5845 */
5846 if (type == DRM_MODE_CONNECTOR_eDP)
5847 intel_encoder->type = INTEL_OUTPUT_EDP;
5848
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005849 /* eDP only on port B and/or C on vlv/chv */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005850 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08005851 is_edp(intel_dp) && port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005852 return false;
5853
Imre Deake7281ea2013-05-08 13:14:08 +03005854 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
5855 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
5856 port_name(port));
5857
Adam Jacksonb3295302010-07-16 14:46:28 -04005858 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005859 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
5860
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005861 connector->interlace_allowed = true;
5862 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08005863
Mika Kaholab6339582016-09-09 14:10:52 +03005864 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01005865
Daniel Vetter66a92782012-07-12 20:08:18 +02005866 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01005867 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08005868
Chris Wilsondf0e9242010-09-09 16:20:55 +01005869 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005870
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005871 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02005872 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
5873 else
5874 intel_connector->get_hw_state = intel_connector_get_hw_state;
5875
Jani Nikula0b998362014-03-14 16:51:17 +02005876 /* Set up the hotplug pin. */
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005877 switch (port) {
5878 case PORT_A:
Egbert Eich1d843f92013-02-25 12:06:49 -05005879 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005880 break;
5881 case PORT_B:
Egbert Eich1d843f92013-02-25 12:06:49 -05005882 intel_encoder->hpd_pin = HPD_PORT_B;
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01005883 if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1))
Sonika Jindalcf1d5882015-08-10 10:35:36 +05305884 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005885 break;
5886 case PORT_C:
Egbert Eich1d843f92013-02-25 12:06:49 -05005887 intel_encoder->hpd_pin = HPD_PORT_C;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005888 break;
5889 case PORT_D:
Egbert Eich1d843f92013-02-25 12:06:49 -05005890 intel_encoder->hpd_pin = HPD_PORT_D;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005891 break;
Xiong Zhang26951ca2015-08-17 15:55:50 +08005892 case PORT_E:
5893 intel_encoder->hpd_pin = HPD_PORT_E;
5894 break;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005895 default:
Damien Lespiauad1c0b12013-03-07 15:30:28 +00005896 BUG();
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08005897 }
5898
Dave Airlie0e32b392014-05-02 14:02:48 +10005899 /* init MST on ports that can support it */
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00005900 if (HAS_DP_MST(dev_priv) && !is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03005901 (port == PORT_B || port == PORT_C || port == PORT_D))
5902 intel_dp_mst_encoder_init(intel_dig_port,
5903 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10005904
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005905 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005906 intel_dp_aux_fini(intel_dp);
5907 intel_dp_mst_encoder_cleanup(intel_dig_port);
5908 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03005909 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08005910
Chris Wilsonf6849602010-09-19 09:29:33 +01005911 intel_dp_add_properties(intel_dp, connector);
5912
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005913 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
5914 * 0xd. Failure to do so will result in spurious interrupts being
5915 * generated on the port when a cable is not attached.
5916 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01005917 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005918 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
5919 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
5920 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03005921
5922 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005923
5924fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005925 drm_connector_cleanup(connector);
5926
5927 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005928}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005929
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02005930bool intel_dp_init(struct drm_i915_private *dev_priv,
Chris Wilson457c52d2016-06-01 08:27:50 +01005931 i915_reg_t output_reg,
5932 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005933{
5934 struct intel_digital_port *intel_dig_port;
5935 struct intel_encoder *intel_encoder;
5936 struct drm_encoder *encoder;
5937 struct intel_connector *intel_connector;
5938
Daniel Vetterb14c5672013-09-19 12:18:32 +02005939 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005940 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01005941 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005942
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03005943 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305944 if (!intel_connector)
5945 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005946
5947 intel_encoder = &intel_dig_port->base;
5948 encoder = &intel_encoder->base;
5949
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02005950 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
5951 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
5952 "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305953 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005954
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01005955 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005956 intel_encoder->disable = intel_disable_dp;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005957 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07005958 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03005959 intel_encoder->suspend = intel_dp_encoder_suspend;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005960 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03005961 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03005962 intel_encoder->pre_enable = chv_pre_enable_dp;
5963 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03005964 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03005965 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01005966 } else if (IS_VALLEYVIEW(dev_priv)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03005967 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005968 intel_encoder->pre_enable = vlv_pre_enable_dp;
5969 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03005970 intel_encoder->post_disable = vlv_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005971 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03005972 intel_encoder->pre_enable = g4x_pre_enable_dp;
5973 intel_encoder->enable = g4x_enable_dp;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005974 if (INTEL_GEN(dev_priv) >= 5)
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03005975 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005976 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005977
Paulo Zanoni174edf12012-10-26 19:05:50 -02005978 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005979 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005980 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005981
Ville Syrjäläcca05022016-06-22 21:57:06 +03005982 intel_encoder->type = INTEL_OUTPUT_DP;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005983 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03005984 if (port == PORT_D)
5985 intel_encoder->crtc_mask = 1 << 2;
5986 else
5987 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
5988 } else {
5989 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
5990 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02005991 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07005992 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005993
Dave Airlie13cf5502014-06-18 11:29:35 +10005994 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03005995 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10005996
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305997 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
5998 goto err_init_connector;
5999
Chris Wilson457c52d2016-06-01 08:27:50 +01006000 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306001
6002err_init_connector:
6003 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306004err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306005 kfree(intel_connector);
6006err_connector_alloc:
6007 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01006008 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006009}
Dave Airlie0e32b392014-05-02 14:02:48 +10006010
6011void intel_dp_mst_suspend(struct drm_device *dev)
6012{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006013 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006014 int i;
6015
6016 /* disable MST */
6017 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006018 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006019
6020 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006021 continue;
6022
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006023 if (intel_dig_port->dp.is_mst)
6024 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10006025 }
6026}
6027
6028void intel_dp_mst_resume(struct drm_device *dev)
6029{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006030 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006031 int i;
6032
6033 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006034 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006035 int ret;
6036
6037 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006038 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10006039
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006040 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
6041 if (ret)
6042 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10006043 }
6044}