blob: e0f9b9e49acca3b7d7d44588b3663e12c2af383a [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);
Rodrigo Vivib976dc52017-01-23 10:32:37 -0800229 } else if (IS_GEN9_BC(dev_priv)) {
Navare, Manasi D40dba342016-10-26 16:25:55 -0700230 *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 */
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001754 if (is_edp(intel_dp) && IS_GEN9_BC(dev_priv)) {
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001755 int vco;
1756
1757 switch (pipe_config->port_clock / 2) {
1758 case 108000:
1759 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001760 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001761 break;
1762 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001763 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001764 break;
1765 }
1766
1767 to_intel_atomic_state(pipe_config->base.state)->cdclk_pll_vco = vco;
1768 }
1769
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001770 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001771 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001772
Daniel Vetter36008362013-03-27 00:44:59 +01001773 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001774}
1775
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001776void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001777 int link_rate, uint8_t lane_count,
1778 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001779{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001780 intel_dp->link_rate = link_rate;
1781 intel_dp->lane_count = lane_count;
1782 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001783}
1784
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001785static void intel_dp_prepare(struct intel_encoder *encoder,
1786 struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001787{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001788 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001789 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001790 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001791 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001792 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001793 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001794
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001795 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1796 pipe_config->lane_count,
1797 intel_crtc_has_type(pipe_config,
1798 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001799
Keith Packard417e8222011-11-01 19:54:11 -07001800 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001801 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001802 *
1803 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001804 * SNB CPU
1805 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001806 * CPT PCH
1807 *
1808 * IBX PCH and CPU are the same for almost everything,
1809 * except that the CPU DP PLL is configured in this
1810 * register
1811 *
1812 * CPT PCH is quite different, having many bits moved
1813 * to the TRANS_DP_CTL register instead. That
1814 * configuration happens (oddly) in ironlake_pch_enable
1815 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001816
Keith Packard417e8222011-11-01 19:54:11 -07001817 /* Preserve the BIOS-computed detected bit. This is
1818 * supposed to be read-only.
1819 */
1820 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001821
Keith Packard417e8222011-11-01 19:54:11 -07001822 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001823 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001824 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001825
Keith Packard417e8222011-11-01 19:54:11 -07001826 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001827
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001828 if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001829 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1830 intel_dp->DP |= DP_SYNC_HS_HIGH;
1831 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1832 intel_dp->DP |= DP_SYNC_VS_HIGH;
1833 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1834
Jani Nikula6aba5b62013-10-04 15:08:10 +03001835 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001836 intel_dp->DP |= DP_ENHANCED_FRAMING;
1837
Daniel Vetter7c62a162013-06-01 17:16:20 +02001838 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001839 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001840 u32 trans_dp;
1841
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001842 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001843
1844 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1845 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1846 trans_dp |= TRANS_DP_ENH_FRAMING;
1847 else
1848 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1849 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001850 } else {
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02001851 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001852 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001853
1854 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1855 intel_dp->DP |= DP_SYNC_HS_HIGH;
1856 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1857 intel_dp->DP |= DP_SYNC_VS_HIGH;
1858 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1859
Jani Nikula6aba5b62013-10-04 15:08:10 +03001860 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001861 intel_dp->DP |= DP_ENHANCED_FRAMING;
1862
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001863 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001864 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001865 else if (crtc->pipe == PIPE_B)
1866 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001867 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001868}
1869
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001870#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1871#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001872
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001873#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1874#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001875
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001876#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1877#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001878
Imre Deakde9c1b62016-06-16 20:01:46 +03001879static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
1880 struct intel_dp *intel_dp);
1881
Daniel Vetter4be73782014-01-17 14:39:48 +01001882static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001883 u32 mask,
1884 u32 value)
1885{
Paulo Zanoni30add222012-10-26 19:05:45 -02001886 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001887 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001888 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001889
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001890 lockdep_assert_held(&dev_priv->pps_mutex);
1891
Imre Deakde9c1b62016-06-16 20:01:46 +03001892 intel_pps_verify_state(dev_priv, intel_dp);
1893
Jani Nikulabf13e812013-09-06 07:40:05 +03001894 pp_stat_reg = _pp_stat_reg(intel_dp);
1895 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001896
1897 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001898 mask, value,
1899 I915_READ(pp_stat_reg),
1900 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001901
Chris Wilson9036ff02016-06-30 15:33:09 +01001902 if (intel_wait_for_register(dev_priv,
1903 pp_stat_reg, mask, value,
1904 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001905 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001906 I915_READ(pp_stat_reg),
1907 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001908
1909 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001910}
1911
Daniel Vetter4be73782014-01-17 14:39:48 +01001912static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001913{
1914 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001915 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001916}
1917
Daniel Vetter4be73782014-01-17 14:39:48 +01001918static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001919{
Keith Packardbd943152011-09-18 23:09:52 -07001920 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001921 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001922}
Keith Packardbd943152011-09-18 23:09:52 -07001923
Daniel Vetter4be73782014-01-17 14:39:48 +01001924static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001925{
Abhay Kumard28d4732016-01-22 17:39:04 -08001926 ktime_t panel_power_on_time;
1927 s64 panel_power_off_duration;
1928
Keith Packard99ea7122011-11-01 19:57:50 -07001929 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001930
Abhay Kumard28d4732016-01-22 17:39:04 -08001931 /* take the difference of currrent time and panel power off time
1932 * and then make panel wait for t11_t12 if needed. */
1933 panel_power_on_time = ktime_get_boottime();
1934 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1935
Paulo Zanonidce56b32013-12-19 14:29:40 -02001936 /* When we disable the VDD override bit last we have to do the manual
1937 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08001938 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
1939 wait_remaining_ms_from_jiffies(jiffies,
1940 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001941
Daniel Vetter4be73782014-01-17 14:39:48 +01001942 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001943}
Keith Packardbd943152011-09-18 23:09:52 -07001944
Daniel Vetter4be73782014-01-17 14:39:48 +01001945static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001946{
1947 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1948 intel_dp->backlight_on_delay);
1949}
1950
Daniel Vetter4be73782014-01-17 14:39:48 +01001951static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001952{
1953 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
1954 intel_dp->backlight_off_delay);
1955}
Keith Packard99ea7122011-11-01 19:57:50 -07001956
Keith Packard832dd3c2011-11-01 19:34:06 -07001957/* Read the current pp_control value, unlocking the register if it
1958 * is locked
1959 */
1960
Jesse Barnes453c5422013-03-28 09:55:41 -07001961static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07001962{
Jesse Barnes453c5422013-03-28 09:55:41 -07001963 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001964 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07001965 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07001966
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001967 lockdep_assert_held(&dev_priv->pps_mutex);
1968
Jani Nikulabf13e812013-09-06 07:40:05 +03001969 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03001970 if (WARN_ON(!HAS_DDI(dev_priv) &&
1971 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05301972 control &= ~PANEL_UNLOCK_MASK;
1973 control |= PANEL_UNLOCK_REGS;
1974 }
Keith Packard832dd3c2011-11-01 19:34:06 -07001975 return control;
Keith Packardbd943152011-09-18 23:09:52 -07001976}
1977
Ville Syrjälä951468f2014-09-04 14:55:31 +03001978/*
1979 * Must be paired with edp_panel_vdd_off().
1980 * Must hold pps_mutex around the whole on/off sequence.
1981 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
1982 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001983static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001984{
Paulo Zanoni30add222012-10-26 19:05:45 -02001985 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001986 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1987 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001988 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001989 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08001990 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001991 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001992 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08001993
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001994 lockdep_assert_held(&dev_priv->pps_mutex);
1995
Keith Packard97af61f572011-09-28 16:23:51 -07001996 if (!is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001997 return false;
Keith Packardbd943152011-09-18 23:09:52 -07001998
Egbert Eich2c623c12014-11-25 12:54:57 +01001999 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002000 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07002001
Daniel Vetter4be73782014-01-17 14:39:48 +01002002 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002003 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002004
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002005 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002006 intel_display_power_get(dev_priv, power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002007
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002008 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
2009 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07002010
Daniel Vetter4be73782014-01-17 14:39:48 +01002011 if (!edp_have_panel_power(intel_dp))
2012 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07002013
Jesse Barnes453c5422013-03-28 09:55:41 -07002014 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002015 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07002016
Jani Nikulabf13e812013-09-06 07:40:05 +03002017 pp_stat_reg = _pp_stat_reg(intel_dp);
2018 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002019
2020 I915_WRITE(pp_ctrl_reg, pp);
2021 POSTING_READ(pp_ctrl_reg);
2022 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2023 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07002024 /*
2025 * If the panel wasn't on, delay before accessing aux channel
2026 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002027 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002028 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
2029 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07002030 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07002031 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002032
2033 return need_to_disable;
2034}
2035
Ville Syrjälä951468f2014-09-04 14:55:31 +03002036/*
2037 * Must be paired with intel_edp_panel_vdd_off() or
2038 * intel_edp_panel_off().
2039 * Nested calls to these functions are not allowed since
2040 * we drop the lock. Caller must use some higher level
2041 * locking to prevent nested calls from other threads.
2042 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01002043void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002044{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002045 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002046
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002047 if (!is_edp(intel_dp))
2048 return;
2049
Ville Syrjälä773538e82014-09-04 14:54:56 +03002050 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002051 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002052 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002053
Rob Clarke2c719b2014-12-15 13:56:32 -05002054 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002055 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08002056}
2057
Daniel Vetter4be73782014-01-17 14:39:48 +01002058static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002059{
Paulo Zanoni30add222012-10-26 19:05:45 -02002060 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002061 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002062 struct intel_digital_port *intel_dig_port =
2063 dp_to_dig_port(intel_dp);
2064 struct intel_encoder *intel_encoder = &intel_dig_port->base;
2065 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08002066 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002067 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002068
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002069 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002070
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002071 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002072
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002073 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002074 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002075
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002076 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2077 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002078
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002079 pp = ironlake_get_pp_control(intel_dp);
2080 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002081
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002082 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2083 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002084
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002085 I915_WRITE(pp_ctrl_reg, pp);
2086 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002087
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002088 /* Make sure sequencer is idle before allowing subsequent activity */
2089 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2090 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002091
Imre Deak5a162e22016-08-10 14:07:30 +03002092 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002093 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002094
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002095 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002096 intel_display_power_put(dev_priv, power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002097}
2098
Daniel Vetter4be73782014-01-17 14:39:48 +01002099static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002100{
2101 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2102 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002103
Ville Syrjälä773538e82014-09-04 14:54:56 +03002104 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002105 if (!intel_dp->want_panel_vdd)
2106 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002107 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002108}
2109
Imre Deakaba86892014-07-30 15:57:31 +03002110static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2111{
2112 unsigned long delay;
2113
2114 /*
2115 * Queue the timer to fire a long time from now (relative to the power
2116 * down delay) to keep the panel power up across a sequence of
2117 * operations.
2118 */
2119 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2120 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2121}
2122
Ville Syrjälä951468f2014-09-04 14:55:31 +03002123/*
2124 * Must be paired with edp_panel_vdd_on().
2125 * Must hold pps_mutex around the whole on/off sequence.
2126 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2127 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002128static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002129{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002130 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002131
2132 lockdep_assert_held(&dev_priv->pps_mutex);
2133
Keith Packard97af61f572011-09-28 16:23:51 -07002134 if (!is_edp(intel_dp))
2135 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002136
Rob Clarke2c719b2014-12-15 13:56:32 -05002137 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002138 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002139
Keith Packardbd943152011-09-18 23:09:52 -07002140 intel_dp->want_panel_vdd = false;
2141
Imre Deakaba86892014-07-30 15:57:31 +03002142 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002143 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002144 else
2145 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002146}
2147
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002148static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002149{
Paulo Zanoni30add222012-10-26 19:05:45 -02002150 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002151 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002152 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002153 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002154
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002155 lockdep_assert_held(&dev_priv->pps_mutex);
2156
Keith Packard97af61f572011-09-28 16:23:51 -07002157 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002158 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002159
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002160 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2161 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002162
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002163 if (WARN(edp_have_panel_power(intel_dp),
2164 "eDP port %c panel power already on\n",
2165 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002166 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002167
Daniel Vetter4be73782014-01-17 14:39:48 +01002168 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002169
Jani Nikulabf13e812013-09-06 07:40:05 +03002170 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002171 pp = ironlake_get_pp_control(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002172 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002173 /* ILK workaround: disable reset around power sequence */
2174 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002175 I915_WRITE(pp_ctrl_reg, pp);
2176 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002177 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002178
Imre Deak5a162e22016-08-10 14:07:30 +03002179 pp |= PANEL_POWER_ON;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002180 if (!IS_GEN5(dev_priv))
Keith Packard99ea7122011-11-01 19:57:50 -07002181 pp |= PANEL_POWER_RESET;
2182
Jesse Barnes453c5422013-03-28 09:55:41 -07002183 I915_WRITE(pp_ctrl_reg, pp);
2184 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002185
Daniel Vetter4be73782014-01-17 14:39:48 +01002186 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002187 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002188
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002189 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002190 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002191 I915_WRITE(pp_ctrl_reg, pp);
2192 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002193 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002194}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002195
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002196void intel_edp_panel_on(struct intel_dp *intel_dp)
2197{
2198 if (!is_edp(intel_dp))
2199 return;
2200
2201 pps_lock(intel_dp);
2202 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002203 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002204}
2205
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002206
2207static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002208{
Imre Deak4e6e1a52014-03-27 17:45:11 +02002209 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2210 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanoni30add222012-10-26 19:05:45 -02002211 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002212 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002213 enum intel_display_power_domain power_domain;
Keith Packard99ea7122011-11-01 19:57:50 -07002214 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002215 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002216
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002217 lockdep_assert_held(&dev_priv->pps_mutex);
2218
Keith Packard97af61f572011-09-28 16:23:51 -07002219 if (!is_edp(intel_dp))
2220 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002221
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002222 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2223 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002224
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002225 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2226 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002227
Jesse Barnes453c5422013-03-28 09:55:41 -07002228 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002229 /* We need to switch off panel power _and_ force vdd, for otherwise some
2230 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002231 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002232 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002233
Jani Nikulabf13e812013-09-06 07:40:05 +03002234 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002235
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002236 intel_dp->want_panel_vdd = false;
2237
Jesse Barnes453c5422013-03-28 09:55:41 -07002238 I915_WRITE(pp_ctrl_reg, pp);
2239 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002240
Abhay Kumard28d4732016-01-22 17:39:04 -08002241 intel_dp->panel_power_off_time = ktime_get_boottime();
Daniel Vetter4be73782014-01-17 14:39:48 +01002242 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002243
2244 /* We got a reference when we enabled the VDD. */
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002245 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002246 intel_display_power_put(dev_priv, power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002247}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002248
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002249void intel_edp_panel_off(struct intel_dp *intel_dp)
2250{
2251 if (!is_edp(intel_dp))
2252 return;
2253
2254 pps_lock(intel_dp);
2255 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002256 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002257}
2258
Jani Nikula1250d102014-08-12 17:11:39 +03002259/* Enable backlight in the panel power control. */
2260static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002261{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002262 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2263 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002264 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002265 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002266 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002267
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002268 /*
2269 * If we enable the backlight right away following a panel power
2270 * on, we may see slight flicker as the panel syncs with the eDP
2271 * link. So delay a bit to make sure the image is solid before
2272 * allowing it to appear.
2273 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002274 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002275
Ville Syrjälä773538e82014-09-04 14:54:56 +03002276 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002277
Jesse Barnes453c5422013-03-28 09:55:41 -07002278 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002279 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002280
Jani Nikulabf13e812013-09-06 07:40:05 +03002281 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002282
2283 I915_WRITE(pp_ctrl_reg, pp);
2284 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002285
Ville Syrjälä773538e82014-09-04 14:54:56 +03002286 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002287}
2288
Jani Nikula1250d102014-08-12 17:11:39 +03002289/* Enable backlight PWM and backlight PP control. */
2290void intel_edp_backlight_on(struct intel_dp *intel_dp)
2291{
2292 if (!is_edp(intel_dp))
2293 return;
2294
2295 DRM_DEBUG_KMS("\n");
2296
2297 intel_panel_enable_backlight(intel_dp->attached_connector);
2298 _intel_edp_backlight_on(intel_dp);
2299}
2300
2301/* Disable backlight in the panel power control. */
2302static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002303{
Paulo Zanoni30add222012-10-26 19:05:45 -02002304 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002305 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002306 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002307 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002308
Keith Packardf01eca22011-09-28 16:48:10 -07002309 if (!is_edp(intel_dp))
2310 return;
2311
Ville Syrjälä773538e82014-09-04 14:54:56 +03002312 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002313
Jesse Barnes453c5422013-03-28 09:55:41 -07002314 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002315 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002316
Jani Nikulabf13e812013-09-06 07:40:05 +03002317 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002318
2319 I915_WRITE(pp_ctrl_reg, pp);
2320 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002321
Ville Syrjälä773538e82014-09-04 14:54:56 +03002322 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002323
Paulo Zanonidce56b32013-12-19 14:29:40 -02002324 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002325 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002326}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002327
Jani Nikula1250d102014-08-12 17:11:39 +03002328/* Disable backlight PP control and backlight PWM. */
2329void intel_edp_backlight_off(struct intel_dp *intel_dp)
2330{
2331 if (!is_edp(intel_dp))
2332 return;
2333
2334 DRM_DEBUG_KMS("\n");
2335
2336 _intel_edp_backlight_off(intel_dp);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002337 intel_panel_disable_backlight(intel_dp->attached_connector);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002338}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002339
Jani Nikula73580fb72014-08-12 17:11:41 +03002340/*
2341 * Hook for controlling the panel power control backlight through the bl_power
2342 * sysfs attribute. Take care to handle multiple calls.
2343 */
2344static void intel_edp_backlight_power(struct intel_connector *connector,
2345 bool enable)
2346{
2347 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002348 bool is_enabled;
2349
Ville Syrjälä773538e82014-09-04 14:54:56 +03002350 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002351 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002352 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002353
2354 if (is_enabled == enable)
2355 return;
2356
Jani Nikula23ba9372014-08-27 14:08:43 +03002357 DRM_DEBUG_KMS("panel power control backlight %s\n",
2358 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002359
2360 if (enable)
2361 _intel_edp_backlight_on(intel_dp);
2362 else
2363 _intel_edp_backlight_off(intel_dp);
2364}
2365
Ville Syrjälä64e10772015-10-29 21:26:01 +02002366static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2367{
2368 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2369 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2370 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2371
2372 I915_STATE_WARN(cur_state != state,
2373 "DP port %c state assertion failure (expected %s, current %s)\n",
2374 port_name(dig_port->port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002375 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002376}
2377#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2378
2379static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2380{
2381 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2382
2383 I915_STATE_WARN(cur_state != state,
2384 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002385 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002386}
2387#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2388#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2389
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002390static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2391 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002392{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002393 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002394 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002395
Ville Syrjälä64e10772015-10-29 21:26:01 +02002396 assert_pipe_disabled(dev_priv, crtc->pipe);
2397 assert_dp_port_disabled(intel_dp);
2398 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002399
Ville Syrjäläabfce942015-10-29 21:26:03 +02002400 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002401 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002402
2403 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2404
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002405 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002406 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2407 else
2408 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2409
2410 I915_WRITE(DP_A, intel_dp->DP);
2411 POSTING_READ(DP_A);
2412 udelay(500);
2413
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002414 /*
2415 * [DevILK] Work around required when enabling DP PLL
2416 * while a pipe is enabled going to FDI:
2417 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2418 * 2. Program DP PLL enable
2419 */
2420 if (IS_GEN5(dev_priv))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02002421 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002422
Daniel Vetter07679352012-09-06 22:15:42 +02002423 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002424
Daniel Vetter07679352012-09-06 22:15:42 +02002425 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002426 POSTING_READ(DP_A);
2427 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002428}
2429
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002430static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002431{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002432 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002433 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2434 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002435
Ville Syrjälä64e10772015-10-29 21:26:01 +02002436 assert_pipe_disabled(dev_priv, crtc->pipe);
2437 assert_dp_port_disabled(intel_dp);
2438 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002439
Ville Syrjäläabfce942015-10-29 21:26:03 +02002440 DRM_DEBUG_KMS("disabling eDP PLL\n");
2441
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002442 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002443
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002444 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002445 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002446 udelay(200);
2447}
2448
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002449/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002450void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002451{
2452 int ret, i;
2453
2454 /* Should have a valid DPCD by this point */
2455 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2456 return;
2457
2458 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002459 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2460 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002461 } else {
Imre Deak357c0ae2016-11-21 21:15:06 +02002462 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
2463
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002464 /*
2465 * When turning on, we need to retry for 1ms to give the sink
2466 * time to wake up.
2467 */
2468 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002469 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2470 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002471 if (ret == 1)
2472 break;
2473 msleep(1);
2474 }
Imre Deak357c0ae2016-11-21 21:15:06 +02002475
2476 if (ret == 1 && lspcon->active)
2477 lspcon_wait_pcon_mode(lspcon);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002478 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002479
2480 if (ret != 1)
2481 DRM_DEBUG_KMS("failed to %s sink power state\n",
2482 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002483}
2484
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002485static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2486 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002487{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002488 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002489 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002490 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002491 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002492 enum intel_display_power_domain power_domain;
2493 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002494 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002495
2496 power_domain = intel_display_port_power_domain(encoder);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002497 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002498 return false;
2499
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002500 ret = false;
2501
Imre Deak6d129be2014-03-05 16:20:54 +02002502 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002503
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002504 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002505 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002506
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002507 if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002508 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002509 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002510 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002511
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002512 for_each_pipe(dev_priv, p) {
2513 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2514 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2515 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002516 ret = true;
2517
2518 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002519 }
2520 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002521
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002522 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002523 i915_mmio_reg_offset(intel_dp->output_reg));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002524 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002525 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2526 } else {
2527 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002528 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002529
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002530 ret = true;
2531
2532out:
2533 intel_display_power_put(dev_priv, power_domain);
2534
2535 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002536}
2537
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002538static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002539 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002540{
2541 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002542 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002543 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002544 struct drm_i915_private *dev_priv = to_i915(dev);
Xiong Zhang63000ef2013-06-28 12:59:06 +08002545 enum port port = dp_to_dig_port(intel_dp)->port;
2546 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002547
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002548 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002549
2550 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002551
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002552 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002553 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2554
2555 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002556 flags |= DRM_MODE_FLAG_PHSYNC;
2557 else
2558 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002559
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002560 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002561 flags |= DRM_MODE_FLAG_PVSYNC;
2562 else
2563 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002564 } else {
2565 if (tmp & DP_SYNC_HS_HIGH)
2566 flags |= DRM_MODE_FLAG_PHSYNC;
2567 else
2568 flags |= DRM_MODE_FLAG_NHSYNC;
2569
2570 if (tmp & DP_SYNC_VS_HIGH)
2571 flags |= DRM_MODE_FLAG_PVSYNC;
2572 else
2573 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002574 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002575
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002576 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002577
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02002578 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002579 pipe_config->limited_color_range = true;
2580
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002581 pipe_config->lane_count =
2582 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2583
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002584 intel_dp_get_m_n(crtc, pipe_config);
2585
Ville Syrjälä18442d02013-09-13 16:00:08 +03002586 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002587 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002588 pipe_config->port_clock = 162000;
2589 else
2590 pipe_config->port_clock = 270000;
2591 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002592
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002593 pipe_config->base.adjusted_mode.crtc_clock =
2594 intel_dotclock_calculate(pipe_config->port_clock,
2595 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002596
Jani Nikula6aa23e62016-03-24 17:50:20 +02002597 if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
2598 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002599 /*
2600 * This is a big fat ugly hack.
2601 *
2602 * Some machines in UEFI boot mode provide us a VBT that has 18
2603 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2604 * unknown we fail to light up. Yet the same BIOS boots up with
2605 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2606 * max, not what it tells us to use.
2607 *
2608 * Note: This will still be broken if the eDP panel is not lit
2609 * up by the BIOS, and thus we can't get the mode at module
2610 * load.
2611 */
2612 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002613 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2614 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002615 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002616}
2617
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002618static void intel_disable_dp(struct intel_encoder *encoder,
2619 struct intel_crtc_state *old_crtc_state,
2620 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002621{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002622 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002623 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002624
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002625 if (old_crtc_state->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002626 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002627
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002628 if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv))
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002629 intel_psr_disable(intel_dp);
2630
Daniel Vetter6cb49832012-05-20 17:14:50 +02002631 /* Make sure the panel is off before trying to change the mode. But also
2632 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002633 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01002634 intel_edp_backlight_off(intel_dp);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002635 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002636 intel_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02002637
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002638 /* disable the port before the pipe on g4x */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002639 if (INTEL_GEN(dev_priv) < 5)
Daniel Vetter37398502012-09-06 22:15:44 +02002640 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07002641}
2642
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002643static void ilk_post_disable_dp(struct intel_encoder *encoder,
2644 struct intel_crtc_state *old_crtc_state,
2645 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002646{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002647 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002648 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002649
Ville Syrjälä49277c32014-03-31 18:21:26 +03002650 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002651
2652 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002653 if (port == PORT_A)
2654 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002655}
2656
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002657static void vlv_post_disable_dp(struct intel_encoder *encoder,
2658 struct intel_crtc_state *old_crtc_state,
2659 struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002660{
2661 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2662
2663 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002664}
2665
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002666static void chv_post_disable_dp(struct intel_encoder *encoder,
2667 struct intel_crtc_state *old_crtc_state,
2668 struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002669{
2670 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002671 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002672 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002673
2674 intel_dp_link_down(intel_dp);
2675
Ville Syrjäläa5805162015-05-26 20:42:30 +03002676 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002677
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002678 /* Assert data lane reset */
2679 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002680
Ville Syrjäläa5805162015-05-26 20:42:30 +03002681 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002682}
2683
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002684static void
2685_intel_dp_set_link_train(struct intel_dp *intel_dp,
2686 uint32_t *DP,
2687 uint8_t dp_train_pat)
2688{
2689 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2690 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002691 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002692 enum port port = intel_dig_port->port;
2693
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002694 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2695 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2696 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2697
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002698 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002699 uint32_t temp = I915_READ(DP_TP_CTL(port));
2700
2701 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2702 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2703 else
2704 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2705
2706 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2707 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2708 case DP_TRAINING_PATTERN_DISABLE:
2709 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2710
2711 break;
2712 case DP_TRAINING_PATTERN_1:
2713 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2714 break;
2715 case DP_TRAINING_PATTERN_2:
2716 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2717 break;
2718 case DP_TRAINING_PATTERN_3:
2719 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2720 break;
2721 }
2722 I915_WRITE(DP_TP_CTL(port), temp);
2723
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002724 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002725 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002726 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2727
2728 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2729 case DP_TRAINING_PATTERN_DISABLE:
2730 *DP |= DP_LINK_TRAIN_OFF_CPT;
2731 break;
2732 case DP_TRAINING_PATTERN_1:
2733 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2734 break;
2735 case DP_TRAINING_PATTERN_2:
2736 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2737 break;
2738 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002739 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002740 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2741 break;
2742 }
2743
2744 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002745 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002746 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2747 else
2748 *DP &= ~DP_LINK_TRAIN_MASK;
2749
2750 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2751 case DP_TRAINING_PATTERN_DISABLE:
2752 *DP |= DP_LINK_TRAIN_OFF;
2753 break;
2754 case DP_TRAINING_PATTERN_1:
2755 *DP |= DP_LINK_TRAIN_PAT_1;
2756 break;
2757 case DP_TRAINING_PATTERN_2:
2758 *DP |= DP_LINK_TRAIN_PAT_2;
2759 break;
2760 case DP_TRAINING_PATTERN_3:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002761 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002762 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2763 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002764 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002765 *DP |= DP_LINK_TRAIN_PAT_2;
2766 }
2767 break;
2768 }
2769 }
2770}
2771
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002772static void intel_dp_enable_port(struct intel_dp *intel_dp,
2773 struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002774{
2775 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002776 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002777
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002778 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002779
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002780 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002781
2782 /*
2783 * Magic for VLV/CHV. We _must_ first set up the register
2784 * without actually enabling the port, and then do another
2785 * write to enable the port. Otherwise link training will
2786 * fail when the power sequencer is freshly used for this port.
2787 */
2788 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002789 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002790 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002791
2792 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2793 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002794}
2795
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002796static void intel_enable_dp(struct intel_encoder *encoder,
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002797 struct intel_crtc_state *pipe_config,
2798 struct drm_connector_state *conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002799{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002800 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2801 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002802 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulac1dec792014-10-27 16:26:56 +02002803 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002804 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002805 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002806
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002807 if (WARN_ON(dp_reg & DP_PORT_EN))
2808 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002809
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002810 pps_lock(intel_dp);
2811
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002812 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002813 vlv_init_panel_power_sequencer(intel_dp);
2814
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002815 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002816
2817 edp_panel_vdd_on(intel_dp);
2818 edp_panel_on(intel_dp);
2819 edp_panel_vdd_off(intel_dp, true);
2820
2821 pps_unlock(intel_dp);
2822
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002823 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002824 unsigned int lane_mask = 0x0;
2825
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002826 if (IS_CHERRYVIEW(dev_priv))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002827 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002828
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002829 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2830 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002831 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002832
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002833 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2834 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002835 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002836
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002837 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002838 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002839 pipe_name(pipe));
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002840 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Jani Nikulac1dec792014-10-27 16:26:56 +02002841 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002842}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002843
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002844static void g4x_enable_dp(struct intel_encoder *encoder,
2845 struct intel_crtc_state *pipe_config,
2846 struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03002847{
Jani Nikula828f5c62013-09-05 16:44:45 +03002848 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2849
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002850 intel_enable_dp(encoder, pipe_config, conn_state);
Daniel Vetter4be73782014-01-17 14:39:48 +01002851 intel_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002852}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002853
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002854static void vlv_enable_dp(struct intel_encoder *encoder,
2855 struct intel_crtc_state *pipe_config,
2856 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002857{
Jani Nikula828f5c62013-09-05 16:44:45 +03002858 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2859
Daniel Vetter4be73782014-01-17 14:39:48 +01002860 intel_edp_backlight_on(intel_dp);
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002861 intel_psr_enable(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002862}
2863
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002864static void g4x_pre_enable_dp(struct intel_encoder *encoder,
2865 struct intel_crtc_state *pipe_config,
2866 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002867{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002868 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002869 enum port port = dp_to_dig_port(intel_dp)->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002870
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002871 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002872
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002873 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002874 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002875 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002876}
2877
Ville Syrjälä83b84592014-10-16 21:29:51 +03002878static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2879{
2880 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002881 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002882 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03002883 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002884
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002885 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
2886
Ville Syrjälä83b84592014-10-16 21:29:51 +03002887 edp_panel_vdd_off_sync(intel_dp);
2888
2889 /*
2890 * VLV seems to get confused when multiple power seqeuencers
2891 * have the same port selected (even if only one has power/vdd
2892 * enabled). The failure manifests as vlv_wait_port_ready() failing
2893 * CHV on the other hand doesn't seem to mind having the same port
2894 * selected in multiple power seqeuencers, but let's clear the
2895 * port select always when logically disconnecting a power sequencer
2896 * from a port.
2897 */
2898 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2899 pipe_name(pipe), port_name(intel_dig_port->port));
2900 I915_WRITE(pp_on_reg, 0);
2901 POSTING_READ(pp_on_reg);
2902
2903 intel_dp->pps_pipe = INVALID_PIPE;
2904}
2905
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002906static void vlv_steal_power_sequencer(struct drm_device *dev,
2907 enum pipe pipe)
2908{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002909 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002910 struct intel_encoder *encoder;
2911
2912 lockdep_assert_held(&dev_priv->pps_mutex);
2913
Ville Syrjäläac3c12e2014-10-16 21:29:56 +03002914 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2915 return;
2916
Jani Nikula19c80542015-12-16 12:48:16 +02002917 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002918 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002919 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002920
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002921 if (encoder->type != INTEL_OUTPUT_DP &&
2922 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002923 continue;
2924
2925 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002926 port = dp_to_dig_port(intel_dp)->port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002927
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002928 WARN(intel_dp->active_pipe == pipe,
2929 "stealing pipe %c power sequencer from active (e)DP port %c\n",
2930 pipe_name(pipe), port_name(port));
2931
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002932 if (intel_dp->pps_pipe != pipe)
2933 continue;
2934
2935 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03002936 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002937
2938 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002939 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002940 }
2941}
2942
2943static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
2944{
2945 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2946 struct intel_encoder *encoder = &intel_dig_port->base;
2947 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002948 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002949 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002950
2951 lockdep_assert_held(&dev_priv->pps_mutex);
2952
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002953 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002954
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002955 if (intel_dp->pps_pipe != INVALID_PIPE &&
2956 intel_dp->pps_pipe != crtc->pipe) {
2957 /*
2958 * If another power sequencer was being used on this
2959 * port previously make sure to turn off vdd there while
2960 * we still have control of it.
2961 */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002962 vlv_detach_power_sequencer(intel_dp);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002963 }
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002964
2965 /*
2966 * We may be stealing the power
2967 * sequencer from another port.
2968 */
2969 vlv_steal_power_sequencer(dev, crtc->pipe);
2970
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002971 intel_dp->active_pipe = crtc->pipe;
2972
2973 if (!is_edp(intel_dp))
2974 return;
2975
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002976 /* now it's all ours */
2977 intel_dp->pps_pipe = crtc->pipe;
2978
2979 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
2980 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
2981
2982 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03002983 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02002984 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002985}
2986
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002987static void vlv_pre_enable_dp(struct intel_encoder *encoder,
2988 struct intel_crtc_state *pipe_config,
2989 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002990{
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03002991 vlv_phy_pre_encoder_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002992
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002993 intel_enable_dp(encoder, pipe_config, conn_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002994}
2995
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002996static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
2997 struct intel_crtc_state *pipe_config,
2998 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07002999{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003000 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02003001
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03003002 vlv_phy_pre_pll_enable(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003003}
3004
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003005static void chv_pre_enable_dp(struct intel_encoder *encoder,
3006 struct intel_crtc_state *pipe_config,
3007 struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003008{
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003009 chv_phy_pre_encoder_enable(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003010
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003011 intel_enable_dp(encoder, pipe_config, conn_state);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03003012
3013 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003014 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003015}
3016
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003017static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
3018 struct intel_crtc_state *pipe_config,
3019 struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03003020{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003021 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03003022
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03003023 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03003024}
3025
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003026static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
3027 struct intel_crtc_state *pipe_config,
3028 struct drm_connector_state *conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003029{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03003030 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003031}
3032
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003033/*
3034 * Fetch AUX CH registers 0x202 - 0x207 which contain
3035 * link status information
3036 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003037bool
Keith Packard93f62da2011-11-01 19:45:03 -07003038intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003039{
Lyude9f085eb2016-04-13 10:58:33 -04003040 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
3041 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003042}
3043
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303044static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp)
3045{
3046 uint8_t psr_caps = 0;
3047
3048 drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps);
3049 return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED;
3050}
3051
3052static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp)
3053{
3054 uint8_t dprx = 0;
3055
3056 drm_dp_dpcd_readb(&intel_dp->aux,
3057 DP_DPRX_FEATURE_ENUMERATION_LIST,
3058 &dprx);
3059 return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED;
3060}
3061
Chris Wilsona76f73d2017-01-14 10:51:13 +00003062static bool intel_dp_get_alpm_status(struct intel_dp *intel_dp)
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303063{
3064 uint8_t alpm_caps = 0;
3065
3066 drm_dp_dpcd_readb(&intel_dp->aux, DP_RECEIVER_ALPM_CAP, &alpm_caps);
3067 return alpm_caps & DP_ALPM_CAP;
3068}
3069
Paulo Zanoni11002442014-06-13 18:45:41 -03003070/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003071uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003072intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003073{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003074 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003075 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003076
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003077 if (IS_GEN9_LP(dev_priv))
Vandana Kannan93147262014-11-18 15:45:29 +05303078 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003079 else if (INTEL_GEN(dev_priv) >= 9) {
Jani Nikula06411f02016-03-24 17:50:21 +02003080 if (dev_priv->vbt.edp.low_vswing && port == PORT_A)
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303081 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003082 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003083 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Sonika Jindalbd600182014-08-08 16:23:41 +05303084 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003085 else if (IS_GEN7(dev_priv) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303086 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003087 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303088 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08003089 else
Sonika Jindalbd600182014-08-08 16:23:41 +05303090 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08003091}
3092
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003093uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003094intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3095{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003096 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003097 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003098
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003099 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003100 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3101 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3102 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3103 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3104 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3105 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3106 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303107 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3108 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003109 default:
3110 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3111 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003112 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003113 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303114 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3115 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3116 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3117 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3118 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3119 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3120 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003121 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303122 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003123 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003124 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003125 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303126 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3127 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3128 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3129 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3130 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3131 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3132 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003133 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303134 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003135 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003136 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003137 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303138 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3139 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3140 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3141 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3142 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003143 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303144 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003145 }
3146 } else {
3147 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303148 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3149 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3150 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3151 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3152 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3153 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3154 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003155 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303156 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003157 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003158 }
3159}
3160
Daniel Vetter5829975c2015-04-16 11:36:52 +02003161static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003162{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003163 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003164 unsigned long demph_reg_value, preemph_reg_value,
3165 uniqtranscale_reg_value;
3166 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003167
3168 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303169 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003170 preemph_reg_value = 0x0004000;
3171 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303172 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003173 demph_reg_value = 0x2B405555;
3174 uniqtranscale_reg_value = 0x552AB83A;
3175 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303176 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003177 demph_reg_value = 0x2B404040;
3178 uniqtranscale_reg_value = 0x5548B83A;
3179 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303180 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003181 demph_reg_value = 0x2B245555;
3182 uniqtranscale_reg_value = 0x5560B83A;
3183 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303184 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003185 demph_reg_value = 0x2B405555;
3186 uniqtranscale_reg_value = 0x5598DA3A;
3187 break;
3188 default:
3189 return 0;
3190 }
3191 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303192 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003193 preemph_reg_value = 0x0002000;
3194 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303195 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003196 demph_reg_value = 0x2B404040;
3197 uniqtranscale_reg_value = 0x5552B83A;
3198 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303199 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003200 demph_reg_value = 0x2B404848;
3201 uniqtranscale_reg_value = 0x5580B83A;
3202 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303203 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003204 demph_reg_value = 0x2B404040;
3205 uniqtranscale_reg_value = 0x55ADDA3A;
3206 break;
3207 default:
3208 return 0;
3209 }
3210 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303211 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003212 preemph_reg_value = 0x0000000;
3213 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303214 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003215 demph_reg_value = 0x2B305555;
3216 uniqtranscale_reg_value = 0x5570B83A;
3217 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303218 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003219 demph_reg_value = 0x2B2B4040;
3220 uniqtranscale_reg_value = 0x55ADDA3A;
3221 break;
3222 default:
3223 return 0;
3224 }
3225 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303226 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003227 preemph_reg_value = 0x0006000;
3228 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303229 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003230 demph_reg_value = 0x1B405555;
3231 uniqtranscale_reg_value = 0x55ADDA3A;
3232 break;
3233 default:
3234 return 0;
3235 }
3236 break;
3237 default:
3238 return 0;
3239 }
3240
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003241 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3242 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003243
3244 return 0;
3245}
3246
Daniel Vetter5829975c2015-04-16 11:36:52 +02003247static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003248{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003249 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3250 u32 deemph_reg_value, margin_reg_value;
3251 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003252 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003253
3254 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303255 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003256 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303257 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003258 deemph_reg_value = 128;
3259 margin_reg_value = 52;
3260 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303261 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003262 deemph_reg_value = 128;
3263 margin_reg_value = 77;
3264 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303265 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003266 deemph_reg_value = 128;
3267 margin_reg_value = 102;
3268 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303269 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003270 deemph_reg_value = 128;
3271 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003272 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003273 break;
3274 default:
3275 return 0;
3276 }
3277 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303278 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003279 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303280 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003281 deemph_reg_value = 85;
3282 margin_reg_value = 78;
3283 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303284 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003285 deemph_reg_value = 85;
3286 margin_reg_value = 116;
3287 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303288 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003289 deemph_reg_value = 85;
3290 margin_reg_value = 154;
3291 break;
3292 default:
3293 return 0;
3294 }
3295 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303296 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003297 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303298 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003299 deemph_reg_value = 64;
3300 margin_reg_value = 104;
3301 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303302 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003303 deemph_reg_value = 64;
3304 margin_reg_value = 154;
3305 break;
3306 default:
3307 return 0;
3308 }
3309 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303310 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003311 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303312 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003313 deemph_reg_value = 43;
3314 margin_reg_value = 154;
3315 break;
3316 default:
3317 return 0;
3318 }
3319 break;
3320 default:
3321 return 0;
3322 }
3323
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003324 chv_set_phy_signal_level(encoder, deemph_reg_value,
3325 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003326
3327 return 0;
3328}
3329
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003330static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003331gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003332{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003333 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003334
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003335 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303336 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003337 default:
3338 signal_levels |= DP_VOLTAGE_0_4;
3339 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303340 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003341 signal_levels |= DP_VOLTAGE_0_6;
3342 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303343 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003344 signal_levels |= DP_VOLTAGE_0_8;
3345 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303346 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003347 signal_levels |= DP_VOLTAGE_1_2;
3348 break;
3349 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003350 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303351 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003352 default:
3353 signal_levels |= DP_PRE_EMPHASIS_0;
3354 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303355 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003356 signal_levels |= DP_PRE_EMPHASIS_3_5;
3357 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303358 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003359 signal_levels |= DP_PRE_EMPHASIS_6;
3360 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303361 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003362 signal_levels |= DP_PRE_EMPHASIS_9_5;
3363 break;
3364 }
3365 return signal_levels;
3366}
3367
Zhenyu Wange3421a12010-04-08 09:43:27 +08003368/* Gen6's DP voltage swing and pre-emphasis control */
3369static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003370gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003371{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003372 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3373 DP_TRAIN_PRE_EMPHASIS_MASK);
3374 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303375 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3376 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003377 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303378 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003379 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303380 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3381 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003382 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303383 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3384 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003385 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303386 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3387 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003388 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003389 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003390 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3391 "0x%x\n", signal_levels);
3392 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003393 }
3394}
3395
Keith Packard1a2eb462011-11-16 16:26:07 -08003396/* Gen7's DP voltage swing and pre-emphasis control */
3397static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003398gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003399{
3400 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3401 DP_TRAIN_PRE_EMPHASIS_MASK);
3402 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303403 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003404 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303405 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003406 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303407 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003408 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3409
Sonika Jindalbd600182014-08-08 16:23:41 +05303410 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003411 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303412 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003413 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3414
Sonika Jindalbd600182014-08-08 16:23:41 +05303415 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003416 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303417 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003418 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3419
3420 default:
3421 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3422 "0x%x\n", signal_levels);
3423 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3424 }
3425}
3426
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003427void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003428intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003429{
3430 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003431 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003432 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003433 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003434 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003435 uint8_t train_set = intel_dp->train_set[0];
3436
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003437 if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003438 signal_levels = ddi_signal_levels(intel_dp);
3439
Michel Thierry254e0932017-01-09 16:51:35 +02003440 if (IS_GEN9_LP(dev_priv))
David Weinehallf8896f52015-06-25 11:11:03 +03003441 signal_levels = 0;
3442 else
3443 mask = DDI_BUF_EMP_MASK;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003444 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003445 signal_levels = chv_signal_levels(intel_dp);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003446 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003447 signal_levels = vlv_signal_levels(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003448 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003449 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003450 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003451 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003452 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003453 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3454 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003455 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003456 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3457 }
3458
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303459 if (mask)
3460 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3461
3462 DRM_DEBUG_KMS("Using vswing level %d\n",
3463 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3464 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3465 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3466 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003467
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003468 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003469
3470 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3471 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003472}
3473
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003474void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003475intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3476 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003477{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003478 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003479 struct drm_i915_private *dev_priv =
3480 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003481
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003482 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003483
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003484 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003485 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003486}
3487
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003488void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003489{
3490 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3491 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003492 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak3ab9c632013-05-03 12:57:41 +03003493 enum port port = intel_dig_port->port;
3494 uint32_t val;
3495
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003496 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003497 return;
3498
3499 val = I915_READ(DP_TP_CTL(port));
3500 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3501 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3502 I915_WRITE(DP_TP_CTL(port), val);
3503
3504 /*
3505 * On PORT_A we can have only eDP in SST mode. There the only reason
3506 * we need to set idle transmission mode is to work around a HW issue
3507 * where we enable the pipe while not in idle link-training mode.
3508 * In this case there is requirement to wait for a minimum number of
3509 * idle patterns to be sent.
3510 */
3511 if (port == PORT_A)
3512 return;
3513
Chris Wilsona7670172016-06-30 15:33:10 +01003514 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3515 DP_TP_STATUS_IDLE_DONE,
3516 DP_TP_STATUS_IDLE_DONE,
3517 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003518 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3519}
3520
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003521static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003522intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003523{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003524 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003525 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003526 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003527 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003528 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003529 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003530
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003531 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003532 return;
3533
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003534 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003535 return;
3536
Zhao Yakui28c97732009-10-09 11:39:41 +08003537 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003538
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003539 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003540 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003541 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003542 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003543 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003544 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003545 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3546 else
3547 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003548 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003549 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003550 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003551 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003552
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003553 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3554 I915_WRITE(intel_dp->output_reg, DP);
3555 POSTING_READ(intel_dp->output_reg);
3556
3557 /*
3558 * HW workaround for IBX, we need to move the port
3559 * to transcoder A after disabling it to allow the
3560 * matching HDMI port to be enabled on transcoder A.
3561 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003562 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003563 /*
3564 * We get CPU/PCH FIFO underruns on the other pipe when
3565 * doing the workaround. Sweep them under the rug.
3566 */
3567 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3568 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3569
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003570 /* always enable with pattern 1 (as per spec) */
3571 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3572 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3573 I915_WRITE(intel_dp->output_reg, DP);
3574 POSTING_READ(intel_dp->output_reg);
3575
3576 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003577 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003578 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003579
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003580 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003581 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3582 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003583 }
3584
Keith Packardf01eca22011-09-28 16:48:10 -07003585 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003586
3587 intel_dp->DP = DP;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003588
3589 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3590 pps_lock(intel_dp);
3591 intel_dp->active_pipe = INVALID_PIPE;
3592 pps_unlock(intel_dp);
3593 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003594}
3595
Imre Deak24e807e2016-10-24 19:33:28 +03003596bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003597intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003598{
Lyude9f085eb2016-04-13 10:58:33 -04003599 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3600 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003601 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003602
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003603 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003604
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003605 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3606}
3607
3608static bool
3609intel_edp_init_dpcd(struct intel_dp *intel_dp)
3610{
3611 struct drm_i915_private *dev_priv =
3612 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3613
3614 /* this function is meant to be called only once */
3615 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3616
3617 if (!intel_dp_read_dpcd(intel_dp))
3618 return false;
3619
Imre Deak12a47a422016-10-24 19:33:29 +03003620 intel_dp_read_desc(intel_dp);
3621
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003622 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3623 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3624 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3625
3626 /* Check if the panel supports PSR */
3627 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3628 intel_dp->psr_dpcd,
3629 sizeof(intel_dp->psr_dpcd));
3630 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3631 dev_priv->psr.sink_support = true;
3632 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3633 }
3634
3635 if (INTEL_GEN(dev_priv) >= 9 &&
3636 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3637 uint8_t frame_sync_cap;
3638
3639 dev_priv->psr.sink_support = true;
3640 drm_dp_dpcd_read(&intel_dp->aux,
3641 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3642 &frame_sync_cap, 1);
3643 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3644 /* PSR2 needs frame sync as well */
3645 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3646 DRM_DEBUG_KMS("PSR2 %s on sink",
3647 dev_priv->psr.psr2_support ? "supported" : "not supported");
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303648
3649 if (dev_priv->psr.psr2_support) {
3650 dev_priv->psr.y_cord_support =
3651 intel_dp_get_y_cord_status(intel_dp);
3652 dev_priv->psr.colorimetry_support =
3653 intel_dp_get_colorimetry_status(intel_dp);
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303654 dev_priv->psr.alpm =
3655 intel_dp_get_alpm_status(intel_dp);
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303656 }
3657
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003658 }
3659
3660 /* Read the eDP Display control capabilities registers */
3661 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
3662 drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003663 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3664 sizeof(intel_dp->edp_dpcd))
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003665 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3666 intel_dp->edp_dpcd);
3667
3668 /* Intermediate frequency support */
3669 if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */
3670 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3671 int i;
3672
3673 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3674 sink_rates, sizeof(sink_rates));
3675
3676 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3677 int val = le16_to_cpu(sink_rates[i]);
3678
3679 if (val == 0)
3680 break;
3681
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -08003682 /* Value read multiplied by 200kHz gives the per-lane
3683 * link rate in kHz. The source rates are, however,
3684 * stored in terms of LS_Clk kHz. The full conversion
3685 * back to symbols is
3686 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
3687 */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003688 intel_dp->sink_rates[i] = (val * 200) / 10;
3689 }
3690 intel_dp->num_sink_rates = i;
3691 }
3692
3693 return true;
3694}
3695
3696
3697static bool
3698intel_dp_get_dpcd(struct intel_dp *intel_dp)
3699{
3700 if (!intel_dp_read_dpcd(intel_dp))
3701 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003702
Lyude9f085eb2016-04-13 10:58:33 -04003703 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT,
3704 &intel_dp->sink_count, 1) < 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303705 return false;
3706
3707 /*
3708 * Sink count can change between short pulse hpd hence
3709 * a member variable in intel_dp will track any changes
3710 * between short pulse interrupts.
3711 */
3712 intel_dp->sink_count = DP_GET_SINK_COUNT(intel_dp->sink_count);
3713
3714 /*
3715 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3716 * a dongle is present but no display. Unless we require to know
3717 * if a dongle is present or not, we don't need to update
3718 * downstream port information. So, an early return here saves
3719 * time from performing other operations which are not required.
3720 */
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05303721 if (!is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303722 return false;
3723
Imre Deakc726ad02016-10-24 19:33:24 +03003724 if (!drm_dp_is_branch(intel_dp->dpcd))
Adam Jacksonedb39242012-09-18 10:58:49 -04003725 return true; /* native DP sink */
3726
3727 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3728 return true; /* no per-port downstream info */
3729
Lyude9f085eb2016-04-13 10:58:33 -04003730 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3731 intel_dp->downstream_ports,
3732 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003733 return false; /* downstream port status fetch failed */
3734
3735 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003736}
3737
Dave Airlie0e32b392014-05-02 14:02:48 +10003738static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003739intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003740{
3741 u8 buf[1];
3742
Nathan Schulte7cc96132016-03-15 10:14:05 -05003743 if (!i915.enable_dp_mst)
3744 return false;
3745
Dave Airlie0e32b392014-05-02 14:02:48 +10003746 if (!intel_dp->can_mst)
3747 return false;
3748
3749 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3750 return false;
3751
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003752 if (drm_dp_dpcd_read(&intel_dp->aux, DP_MSTM_CAP, buf, 1) != 1)
3753 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003754
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003755 return buf[0] & DP_MST_CAP;
3756}
3757
3758static void
3759intel_dp_configure_mst(struct intel_dp *intel_dp)
3760{
3761 if (!i915.enable_dp_mst)
3762 return;
3763
3764 if (!intel_dp->can_mst)
3765 return;
3766
3767 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3768
3769 if (intel_dp->is_mst)
3770 DRM_DEBUG_KMS("Sink is MST capable\n");
3771 else
3772 DRM_DEBUG_KMS("Sink is not MST capable\n");
3773
3774 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3775 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003776}
3777
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003778static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003779{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003780 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003781 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003782 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003783 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003784 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003785 int count = 0;
3786 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003787
3788 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003789 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003790 ret = -EIO;
3791 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003792 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003793
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003794 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003795 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003796 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003797 ret = -EIO;
3798 goto out;
3799 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003800
Rodrigo Vivic6297842015-11-05 10:50:20 -08003801 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003802 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivic6297842015-11-05 10:50:20 -08003803
3804 if (drm_dp_dpcd_readb(&intel_dp->aux,
3805 DP_TEST_SINK_MISC, &buf) < 0) {
3806 ret = -EIO;
3807 goto out;
3808 }
3809 count = buf & DP_TEST_COUNT_MASK;
3810 } while (--attempts && count);
3811
3812 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003813 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003814 ret = -ETIMEDOUT;
3815 }
3816
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003817 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003818 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003819 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003820}
3821
3822static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3823{
3824 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003825 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003826 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3827 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003828 int ret;
3829
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003830 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3831 return -EIO;
3832
3833 if (!(buf & DP_TEST_CRC_SUPPORTED))
3834 return -ENOTTY;
3835
3836 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3837 return -EIO;
3838
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003839 if (buf & DP_TEST_SINK_START) {
3840 ret = intel_dp_sink_crc_stop(intel_dp);
3841 if (ret)
3842 return ret;
3843 }
3844
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003845 hsw_disable_ips(intel_crtc);
3846
3847 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3848 buf | DP_TEST_SINK_START) < 0) {
3849 hsw_enable_ips(intel_crtc);
3850 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003851 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003852
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003853 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003854 return 0;
3855}
3856
3857int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3858{
3859 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003860 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003861 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3862 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003863 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003864 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003865
3866 ret = intel_dp_sink_crc_start(intel_dp);
3867 if (ret)
3868 return ret;
3869
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003870 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003871 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003872
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003873 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003874 DP_TEST_SINK_MISC, &buf) < 0) {
3875 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003876 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003877 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003878 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07003879
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003880 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003881
3882 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003883 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
3884 ret = -ETIMEDOUT;
3885 goto stop;
3886 }
3887
3888 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
3889 ret = -EIO;
3890 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003891 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003892
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003893stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003894 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003895 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003896}
3897
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003898static bool
3899intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3900{
Lyude9f085eb2016-04-13 10:58:33 -04003901 return drm_dp_dpcd_read(&intel_dp->aux,
Jani Nikula9d1a1032014-03-14 16:51:15 +02003902 DP_DEVICE_SERVICE_IRQ_VECTOR,
3903 sink_irq_vector, 1) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003904}
3905
Dave Airlie0e32b392014-05-02 14:02:48 +10003906static bool
3907intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3908{
3909 int ret;
3910
Lyude9f085eb2016-04-13 10:58:33 -04003911 ret = drm_dp_dpcd_read(&intel_dp->aux,
Dave Airlie0e32b392014-05-02 14:02:48 +10003912 DP_SINK_COUNT_ESI,
3913 sink_irq_vector, 14);
3914 if (ret != 14)
3915 return false;
3916
3917 return true;
3918}
3919
Todd Previtec5d5ab72015-04-15 08:38:38 -07003920static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003921{
Todd Previtec5d5ab72015-04-15 08:38:38 -07003922 uint8_t test_result = DP_TEST_ACK;
3923 return test_result;
3924}
3925
3926static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
3927{
3928 uint8_t test_result = DP_TEST_NAK;
3929 return test_result;
3930}
3931
3932static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
3933{
3934 uint8_t test_result = DP_TEST_NAK;
Todd Previte559be302015-05-04 07:48:20 -07003935 struct intel_connector *intel_connector = intel_dp->attached_connector;
3936 struct drm_connector *connector = &intel_connector->base;
3937
3938 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02003939 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07003940 intel_dp->aux.i2c_defer_count > 6) {
3941 /* Check EDID read for NACKs, DEFERs and corruption
3942 * (DP CTS 1.2 Core r1.1)
3943 * 4.2.2.4 : Failed EDID read, I2C_NAK
3944 * 4.2.2.5 : Failed EDID read, I2C_DEFER
3945 * 4.2.2.6 : EDID corruption detected
3946 * Use failsafe mode for all cases
3947 */
3948 if (intel_dp->aux.i2c_nack_count > 0 ||
3949 intel_dp->aux.i2c_defer_count > 0)
3950 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
3951 intel_dp->aux.i2c_nack_count,
3952 intel_dp->aux.i2c_defer_count);
Manasi Navarec1617ab2016-12-09 16:22:50 -08003953 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
Todd Previte559be302015-05-04 07:48:20 -07003954 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05303955 struct edid *block = intel_connector->detect_edid;
3956
3957 /* We have to write the checksum
3958 * of the last block read
3959 */
3960 block += intel_connector->detect_edid->extensions;
3961
Todd Previte559be302015-05-04 07:48:20 -07003962 if (!drm_dp_dpcd_write(&intel_dp->aux,
3963 DP_TEST_EDID_CHECKSUM,
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05303964 &block->checksum,
Dan Carpenter5a1cc652015-05-12 21:07:37 +03003965 1))
Todd Previte559be302015-05-04 07:48:20 -07003966 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
3967
3968 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
Manasi Navarec1617ab2016-12-09 16:22:50 -08003969 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_STANDARD;
Todd Previte559be302015-05-04 07:48:20 -07003970 }
3971
3972 /* Set test active flag here so userspace doesn't interrupt things */
Manasi Navarec1617ab2016-12-09 16:22:50 -08003973 intel_dp->compliance.test_active = 1;
Todd Previte559be302015-05-04 07:48:20 -07003974
Todd Previtec5d5ab72015-04-15 08:38:38 -07003975 return test_result;
3976}
3977
3978static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
3979{
3980 uint8_t test_result = DP_TEST_NAK;
3981 return test_result;
3982}
3983
3984static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
3985{
3986 uint8_t response = DP_TEST_NAK;
Jani Nikula5ec63bb2017-01-20 19:04:06 +02003987 uint8_t request = 0;
3988 int status;
Todd Previtec5d5ab72015-04-15 08:38:38 -07003989
Jani Nikula5ec63bb2017-01-20 19:04:06 +02003990 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07003991 if (status <= 0) {
3992 DRM_DEBUG_KMS("Could not read test request from sink\n");
3993 goto update_status;
3994 }
3995
Jani Nikula5ec63bb2017-01-20 19:04:06 +02003996 switch (request) {
Todd Previtec5d5ab72015-04-15 08:38:38 -07003997 case DP_TEST_LINK_TRAINING:
3998 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07003999 response = intel_dp_autotest_link_training(intel_dp);
4000 break;
4001 case DP_TEST_LINK_VIDEO_PATTERN:
4002 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004003 response = intel_dp_autotest_video_pattern(intel_dp);
4004 break;
4005 case DP_TEST_LINK_EDID_READ:
4006 DRM_DEBUG_KMS("EDID test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004007 response = intel_dp_autotest_edid(intel_dp);
4008 break;
4009 case DP_TEST_LINK_PHY_TEST_PATTERN:
4010 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004011 response = intel_dp_autotest_phy_pattern(intel_dp);
4012 break;
4013 default:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004014 DRM_DEBUG_KMS("Invalid test request '%02x'\n", request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004015 break;
4016 }
4017
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004018 if (response & DP_TEST_ACK)
4019 intel_dp->compliance.test_type = request;
4020
Todd Previtec5d5ab72015-04-15 08:38:38 -07004021update_status:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004022 status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004023 if (status <= 0)
4024 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004025}
4026
Dave Airlie0e32b392014-05-02 14:02:48 +10004027static int
4028intel_dp_check_mst_status(struct intel_dp *intel_dp)
4029{
4030 bool bret;
4031
4032 if (intel_dp->is_mst) {
4033 u8 esi[16] = { 0 };
4034 int ret = 0;
4035 int retry;
4036 bool handled;
4037 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4038go_again:
4039 if (bret == true) {
4040
4041 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03004042 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03004043 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10004044 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4045 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004046 intel_dp_stop_link_train(intel_dp);
4047 }
4048
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004049 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004050 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4051
4052 if (handled) {
4053 for (retry = 0; retry < 3; retry++) {
4054 int wret;
4055 wret = drm_dp_dpcd_write(&intel_dp->aux,
4056 DP_SINK_COUNT_ESI+1,
4057 &esi[1], 3);
4058 if (wret == 3) {
4059 break;
4060 }
4061 }
4062
4063 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4064 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004065 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004066 goto go_again;
4067 }
4068 } else
4069 ret = 0;
4070
4071 return ret;
4072 } else {
4073 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4074 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4075 intel_dp->is_mst = false;
4076 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4077 /* send a hotplug event */
4078 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4079 }
4080 }
4081 return -EINVAL;
4082}
4083
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304084static void
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004085intel_dp_retrain_link(struct intel_dp *intel_dp)
4086{
4087 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4088 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4089 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
4090
4091 /* Suppress underruns caused by re-training */
4092 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4093 if (crtc->config->has_pch_encoder)
4094 intel_set_pch_fifo_underrun_reporting(dev_priv,
4095 intel_crtc_pch_transcoder(crtc), false);
4096
4097 intel_dp_start_link_train(intel_dp);
4098 intel_dp_stop_link_train(intel_dp);
4099
4100 /* Keep underrun reporting disabled until things are stable */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02004101 intel_wait_for_vblank(dev_priv, crtc->pipe);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004102
4103 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4104 if (crtc->config->has_pch_encoder)
4105 intel_set_pch_fifo_underrun_reporting(dev_priv,
4106 intel_crtc_pch_transcoder(crtc), true);
4107}
4108
4109static void
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304110intel_dp_check_link_status(struct intel_dp *intel_dp)
4111{
4112 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4113 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4114 u8 link_status[DP_LINK_STATUS_SIZE];
4115
4116 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
4117
4118 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4119 DRM_ERROR("Failed to get link status\n");
4120 return;
4121 }
4122
4123 if (!intel_encoder->base.crtc)
4124 return;
4125
4126 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4127 return;
4128
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004129 /* FIXME: we need to synchronize this sort of stuff with hardware
Daniel Vetter2dd85ae2016-12-13 20:54:14 +01004130 * readout. Currently fast link training doesn't work on boot-up. */
4131 if (!intel_dp->lane_count)
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004132 return;
4133
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304134 /* if link training is requested we should perform it always */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004135 if ((intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) ||
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304136 (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count))) {
4137 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4138 intel_encoder->base.name);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004139
4140 intel_dp_retrain_link(intel_dp);
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304141 }
4142}
4143
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004144/*
4145 * According to DP spec
4146 * 5.1.2:
4147 * 1. Read DPCD
4148 * 2. Configure link according to Receiver Capabilities
4149 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4150 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304151 *
4152 * intel_dp_short_pulse - handles short pulse interrupts
4153 * when full detection is not required.
4154 * Returns %true if short pulse is handled and full detection
4155 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004156 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304157static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304158intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004159{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004160 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004161 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304162 u8 old_sink_count = intel_dp->sink_count;
4163 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004164
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304165 /*
4166 * Clearing compliance test variables to allow capturing
4167 * of values for next automated test request.
4168 */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004169 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304170
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304171 /*
4172 * Now read the DPCD to see if it's actually running
4173 * If the current value of sink count doesn't match with
4174 * the value that was stored earlier or dpcd read failed
4175 * we need to do full detection
4176 */
4177 ret = intel_dp_get_dpcd(intel_dp);
4178
4179 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4180 /* No need to proceed if we are going to do full detect */
4181 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004182 }
4183
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004184 /* Try to read the source of the interrupt */
4185 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004186 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4187 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004188 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004189 drm_dp_dpcd_writeb(&intel_dp->aux,
4190 DP_DEVICE_SERVICE_IRQ_VECTOR,
4191 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004192
4193 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Todd Previte09b1eb12015-04-20 15:27:34 -07004194 DRM_DEBUG_DRIVER("Test request in short pulse not handled\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004195 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4196 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4197 }
4198
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304199 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4200 intel_dp_check_link_status(intel_dp);
4201 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304202
4203 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004204}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004205
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004206/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004207static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004208intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004209{
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004210 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004211 uint8_t type;
4212
4213 if (!intel_dp_get_dpcd(intel_dp))
4214 return connector_status_disconnected;
4215
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304216 if (is_edp(intel_dp))
4217 return connector_status_connected;
4218
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004219 /* if there's no downstream port, we're done */
Imre Deakc726ad02016-10-24 19:33:24 +03004220 if (!drm_dp_is_branch(dpcd))
Keith Packard26d61aa2011-07-25 20:01:09 -07004221 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004222
4223 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004224 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4225 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004226
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304227 return intel_dp->sink_count ?
4228 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004229 }
4230
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004231 if (intel_dp_can_mst(intel_dp))
4232 return connector_status_connected;
4233
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004234 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004235 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004236 return connector_status_connected;
4237
4238 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004239 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4240 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4241 if (type == DP_DS_PORT_TYPE_VGA ||
4242 type == DP_DS_PORT_TYPE_NON_EDID)
4243 return connector_status_unknown;
4244 } else {
4245 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4246 DP_DWN_STRM_PORT_TYPE_MASK;
4247 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4248 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4249 return connector_status_unknown;
4250 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004251
4252 /* Anything else is out of spec, warn and ignore */
4253 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004254 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004255}
4256
4257static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004258edp_detect(struct intel_dp *intel_dp)
4259{
4260 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Mika Kahola1650be72016-12-13 10:02:47 +02004261 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsond410b562014-09-02 20:03:59 +01004262 enum drm_connector_status status;
4263
Mika Kahola1650be72016-12-13 10:02:47 +02004264 status = intel_panel_detect(dev_priv);
Chris Wilsond410b562014-09-02 20:03:59 +01004265 if (status == connector_status_unknown)
4266 status = connector_status_connected;
4267
4268 return status;
4269}
4270
Jani Nikulab93433c2015-08-20 10:47:36 +03004271static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4272 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004273{
Jani Nikulab93433c2015-08-20 10:47:36 +03004274 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004275
Jani Nikula0df53b72015-08-20 10:47:40 +03004276 switch (port->port) {
4277 case PORT_A:
4278 return true;
4279 case PORT_B:
4280 bit = SDE_PORTB_HOTPLUG;
4281 break;
4282 case PORT_C:
4283 bit = SDE_PORTC_HOTPLUG;
4284 break;
4285 case PORT_D:
4286 bit = SDE_PORTD_HOTPLUG;
4287 break;
4288 default:
4289 MISSING_CASE(port->port);
4290 return false;
4291 }
4292
4293 return I915_READ(SDEISR) & bit;
4294}
4295
4296static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4297 struct intel_digital_port *port)
4298{
4299 u32 bit;
4300
4301 switch (port->port) {
4302 case PORT_A:
4303 return true;
4304 case PORT_B:
4305 bit = SDE_PORTB_HOTPLUG_CPT;
4306 break;
4307 case PORT_C:
4308 bit = SDE_PORTC_HOTPLUG_CPT;
4309 break;
4310 case PORT_D:
4311 bit = SDE_PORTD_HOTPLUG_CPT;
4312 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004313 case PORT_E:
4314 bit = SDE_PORTE_HOTPLUG_SPT;
4315 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004316 default:
4317 MISSING_CASE(port->port);
4318 return false;
Jani Nikulab93433c2015-08-20 10:47:36 +03004319 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004320
Jani Nikulab93433c2015-08-20 10:47:36 +03004321 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004322}
4323
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004324static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004325 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004326{
Jani Nikula9642c812015-08-20 10:47:41 +03004327 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004328
Jani Nikula9642c812015-08-20 10:47:41 +03004329 switch (port->port) {
4330 case PORT_B:
4331 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4332 break;
4333 case PORT_C:
4334 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4335 break;
4336 case PORT_D:
4337 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4338 break;
4339 default:
4340 MISSING_CASE(port->port);
4341 return false;
4342 }
4343
4344 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4345}
4346
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004347static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4348 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004349{
4350 u32 bit;
4351
4352 switch (port->port) {
4353 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004354 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004355 break;
4356 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004357 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004358 break;
4359 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004360 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004361 break;
4362 default:
4363 MISSING_CASE(port->port);
4364 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004365 }
4366
Jani Nikula1d245982015-08-20 10:47:37 +03004367 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004368}
4369
Jani Nikulae464bfd2015-08-20 10:47:42 +03004370static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304371 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004372{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304373 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4374 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004375 u32 bit;
4376
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304377 intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port);
4378 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004379 case PORT_A:
4380 bit = BXT_DE_PORT_HP_DDIA;
4381 break;
4382 case PORT_B:
4383 bit = BXT_DE_PORT_HP_DDIB;
4384 break;
4385 case PORT_C:
4386 bit = BXT_DE_PORT_HP_DDIC;
4387 break;
4388 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304389 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004390 return false;
4391 }
4392
4393 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4394}
4395
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004396/*
4397 * intel_digital_port_connected - is the specified port connected?
4398 * @dev_priv: i915 private structure
4399 * @port: the port to test
4400 *
4401 * Return %true if @port is connected, %false otherwise.
4402 */
David Weinehall23f889b2016-08-17 15:47:48 +03004403static bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004404 struct intel_digital_port *port)
4405{
Jani Nikula0df53b72015-08-20 10:47:40 +03004406 if (HAS_PCH_IBX(dev_priv))
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004407 return ibx_digital_port_connected(dev_priv, port);
Ville Syrjälä22824fa2016-02-11 16:44:28 +02004408 else if (HAS_PCH_SPLIT(dev_priv))
Jani Nikula0df53b72015-08-20 10:47:40 +03004409 return cpt_digital_port_connected(dev_priv, port);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004410 else if (IS_GEN9_LP(dev_priv))
Jani Nikulae464bfd2015-08-20 10:47:42 +03004411 return bxt_digital_port_connected(dev_priv, port);
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004412 else if (IS_GM45(dev_priv))
4413 return gm45_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004414 else
4415 return g4x_digital_port_connected(dev_priv, port);
4416}
4417
Keith Packard8c241fe2011-09-28 16:38:44 -07004418static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004419intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004420{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004421 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004422
Jani Nikula9cd300e2012-10-19 14:51:52 +03004423 /* use cached edid if we have one */
4424 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004425 /* invalid edid */
4426 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004427 return NULL;
4428
Jani Nikula55e9ede2013-10-01 10:38:54 +03004429 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004430 } else
4431 return drm_get_edid(&intel_connector->base,
4432 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004433}
4434
Chris Wilsonbeb60602014-09-02 20:04:00 +01004435static void
4436intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004437{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004438 struct intel_connector *intel_connector = intel_dp->attached_connector;
4439 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004440
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304441 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004442 edid = intel_dp_get_edid(intel_dp);
4443 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004444
Chris Wilsonbeb60602014-09-02 20:04:00 +01004445 if (intel_dp->force_audio != HDMI_AUDIO_AUTO)
4446 intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON;
4447 else
4448 intel_dp->has_audio = drm_detect_monitor_audio(edid);
4449}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004450
Chris Wilsonbeb60602014-09-02 20:04:00 +01004451static void
4452intel_dp_unset_edid(struct intel_dp *intel_dp)
4453{
4454 struct intel_connector *intel_connector = intel_dp->attached_connector;
4455
4456 kfree(intel_connector->detect_edid);
4457 intel_connector->detect_edid = NULL;
4458
4459 intel_dp->has_audio = false;
4460}
4461
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004462static enum drm_connector_status
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304463intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004464{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304465 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004466 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004467 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4468 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004469 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004470 enum drm_connector_status status;
Imre Deak671dedd2014-03-05 16:20:53 +02004471 enum intel_display_power_domain power_domain;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004472 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004473
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004474 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4475 intel_display_power_get(to_i915(dev), power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004476
Chris Wilsond410b562014-09-02 20:03:59 +01004477 /* Can't disconnect eDP, but you can close the lid... */
4478 if (is_edp(intel_dp))
4479 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004480 else if (intel_digital_port_connected(to_i915(dev),
4481 dp_to_dig_port(intel_dp)))
4482 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004483 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004484 status = connector_status_disconnected;
4485
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004486 if (status == connector_status_disconnected) {
Manasi Navarec1617ab2016-12-09 16:22:50 -08004487 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304488
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004489 if (intel_dp->is_mst) {
4490 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4491 intel_dp->is_mst,
4492 intel_dp->mst_mgr.mst_state);
4493 intel_dp->is_mst = false;
4494 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4495 intel_dp->is_mst);
4496 }
4497
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004498 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304499 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004500
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304501 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004502 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304503
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004504 DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
4505 yesno(intel_dp_source_supports_hbr2(intel_dp)),
4506 yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
4507
Manasi Navaref4829842016-12-05 16:27:36 -08004508 /* Set the max lane count for sink */
4509 intel_dp->max_sink_lane_count = drm_dp_max_lane_count(intel_dp->dpcd);
4510
4511 /* Set the max link BW for sink */
4512 intel_dp->max_sink_link_bw = intel_dp_max_link_bw(intel_dp);
4513
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004514 intel_dp_print_rates(intel_dp);
4515
Imre Deak7b3fc172016-10-25 16:12:39 +03004516 intel_dp_read_desc(intel_dp);
Mika Kahola0e390a32016-09-09 14:10:53 +03004517
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004518 intel_dp_configure_mst(intel_dp);
4519
4520 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304521 /*
4522 * If we are in MST mode then this connector
4523 * won't appear connected or have anything
4524 * with EDID on it
4525 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004526 status = connector_status_disconnected;
4527 goto out;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304528 } else if (connector->status == connector_status_connected) {
4529 /*
4530 * If display was connected already and is still connected
4531 * check links status, there has been known issues of
4532 * link loss triggerring long pulse!!!!
4533 */
4534 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4535 intel_dp_check_link_status(intel_dp);
4536 drm_modeset_unlock(&dev->mode_config.connection_mutex);
4537 goto out;
Dave Airlie0e32b392014-05-02 14:02:48 +10004538 }
4539
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304540 /*
4541 * Clearing NACK and defer counts to get their exact values
4542 * while reading EDID which are required by Compliance tests
4543 * 4.2.2.4 and 4.2.2.5
4544 */
4545 intel_dp->aux.i2c_nack_count = 0;
4546 intel_dp->aux.i2c_defer_count = 0;
4547
Chris Wilsonbeb60602014-09-02 20:04:00 +01004548 intel_dp_set_edid(intel_dp);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004549 if (is_edp(intel_dp) || intel_connector->detect_edid)
4550 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304551 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004552
Todd Previte09b1eb12015-04-20 15:27:34 -07004553 /* Try to read the source of the interrupt */
4554 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004555 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4556 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004557 /* Clear interrupt source */
4558 drm_dp_dpcd_writeb(&intel_dp->aux,
4559 DP_DEVICE_SERVICE_IRQ_VECTOR,
4560 sink_irq_vector);
4561
4562 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4563 intel_dp_handle_test_request(intel_dp);
4564 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4565 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4566 }
4567
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004568out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004569 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304570 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304571
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004572 intel_display_power_put(to_i915(dev), power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004573 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304574}
4575
4576static enum drm_connector_status
4577intel_dp_detect(struct drm_connector *connector, bool force)
4578{
4579 struct intel_dp *intel_dp = intel_attached_dp(connector);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004580 enum drm_connector_status status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304581
4582 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4583 connector->base.id, connector->name);
4584
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304585 /* If full detect is not performed yet, do a full detect */
4586 if (!intel_dp->detect_done)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004587 status = intel_dp_long_pulse(intel_dp->attached_connector);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304588
4589 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304590
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004591 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004592}
4593
Chris Wilsonbeb60602014-09-02 20:04:00 +01004594static void
4595intel_dp_force(struct drm_connector *connector)
4596{
4597 struct intel_dp *intel_dp = intel_attached_dp(connector);
4598 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004599 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004600 enum intel_display_power_domain power_domain;
4601
4602 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4603 connector->base.id, connector->name);
4604 intel_dp_unset_edid(intel_dp);
4605
4606 if (connector->status != connector_status_connected)
4607 return;
4608
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004609 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4610 intel_display_power_get(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004611
4612 intel_dp_set_edid(intel_dp);
4613
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004614 intel_display_power_put(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004615
4616 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004617 intel_encoder->type = INTEL_OUTPUT_DP;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004618}
4619
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004620static int intel_dp_get_modes(struct drm_connector *connector)
4621{
Jani Nikuladd06f902012-10-19 14:51:50 +03004622 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004623 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004624
Chris Wilsonbeb60602014-09-02 20:04:00 +01004625 edid = intel_connector->detect_edid;
4626 if (edid) {
4627 int ret = intel_connector_update_modes(connector, edid);
4628 if (ret)
4629 return ret;
4630 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004631
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004632 /* if eDP has no EDID, fall back to fixed mode */
Chris Wilsonbeb60602014-09-02 20:04:00 +01004633 if (is_edp(intel_attached_dp(connector)) &&
4634 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004635 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004636
4637 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004638 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004639 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004640 drm_mode_probed_add(connector, mode);
4641 return 1;
4642 }
4643 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004644
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004645 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004646}
4647
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004648static bool
4649intel_dp_detect_audio(struct drm_connector *connector)
4650{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004651 bool has_audio = false;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004652 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004653
Chris Wilsonbeb60602014-09-02 20:04:00 +01004654 edid = to_intel_connector(connector)->detect_edid;
4655 if (edid)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004656 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02004657
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004658 return has_audio;
4659}
4660
Chris Wilsonf6849602010-09-19 09:29:33 +01004661static int
4662intel_dp_set_property(struct drm_connector *connector,
4663 struct drm_property *property,
4664 uint64_t val)
4665{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004666 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Yuly Novikov53b41832012-10-26 12:04:00 +03004667 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004668 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
4669 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01004670 int ret;
4671
Rob Clark662595d2012-10-11 20:36:04 -05004672 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01004673 if (ret)
4674 return ret;
4675
Chris Wilson3f43c482011-05-12 22:17:24 +01004676 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004677 int i = val;
4678 bool has_audio;
4679
4680 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004681 return 0;
4682
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004683 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01004684
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004685 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004686 has_audio = intel_dp_detect_audio(connector);
4687 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004688 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004689
4690 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004691 return 0;
4692
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004693 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01004694 goto done;
4695 }
4696
Chris Wilsone953fd72011-02-21 22:23:52 +00004697 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02004698 bool old_auto = intel_dp->color_range_auto;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004699 bool old_range = intel_dp->limited_color_range;
Daniel Vetterae4edb82013-04-22 17:07:23 +02004700
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004701 switch (val) {
4702 case INTEL_BROADCAST_RGB_AUTO:
4703 intel_dp->color_range_auto = true;
4704 break;
4705 case INTEL_BROADCAST_RGB_FULL:
4706 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004707 intel_dp->limited_color_range = false;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004708 break;
4709 case INTEL_BROADCAST_RGB_LIMITED:
4710 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004711 intel_dp->limited_color_range = true;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004712 break;
4713 default:
4714 return -EINVAL;
4715 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02004716
4717 if (old_auto == intel_dp->color_range_auto &&
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004718 old_range == intel_dp->limited_color_range)
Daniel Vetterae4edb82013-04-22 17:07:23 +02004719 return 0;
4720
Chris Wilsone953fd72011-02-21 22:23:52 +00004721 goto done;
4722 }
4723
Yuly Novikov53b41832012-10-26 12:04:00 +03004724 if (is_edp(intel_dp) &&
4725 property == connector->dev->mode_config.scaling_mode_property) {
4726 if (val == DRM_MODE_SCALE_NONE) {
4727 DRM_DEBUG_KMS("no scaling not supported\n");
4728 return -EINVAL;
4729 }
Ville Syrjälä234126c2016-04-12 22:14:38 +03004730 if (HAS_GMCH_DISPLAY(dev_priv) &&
4731 val == DRM_MODE_SCALE_CENTER) {
4732 DRM_DEBUG_KMS("centering not supported\n");
4733 return -EINVAL;
4734 }
Yuly Novikov53b41832012-10-26 12:04:00 +03004735
4736 if (intel_connector->panel.fitting_mode == val) {
4737 /* the eDP scaling property is not changed */
4738 return 0;
4739 }
4740 intel_connector->panel.fitting_mode = val;
4741
4742 goto done;
4743 }
4744
Chris Wilsonf6849602010-09-19 09:29:33 +01004745 return -EINVAL;
4746
4747done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00004748 if (intel_encoder->base.crtc)
4749 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01004750
4751 return 0;
4752}
4753
Chris Wilson7a418e32016-06-24 14:00:14 +01004754static int
4755intel_dp_connector_register(struct drm_connector *connector)
4756{
4757 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004758 int ret;
4759
4760 ret = intel_connector_register(connector);
4761 if (ret)
4762 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004763
4764 i915_debugfs_connector_add(connector);
4765
4766 DRM_DEBUG_KMS("registering %s bus for %s\n",
4767 intel_dp->aux.name, connector->kdev->kobj.name);
4768
4769 intel_dp->aux.dev = connector->kdev;
4770 return drm_dp_aux_register(&intel_dp->aux);
4771}
4772
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004773static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004774intel_dp_connector_unregister(struct drm_connector *connector)
4775{
4776 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4777 intel_connector_unregister(connector);
4778}
4779
4780static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004781intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004782{
Jani Nikula1d508702012-10-19 14:51:49 +03004783 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004784
Chris Wilson10e972d2014-09-04 21:43:45 +01004785 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004786
Jani Nikula9cd300e2012-10-19 14:51:52 +03004787 if (!IS_ERR_OR_NULL(intel_connector->edid))
4788 kfree(intel_connector->edid);
4789
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004790 /* Can't call is_edp() since the encoder may have been destroyed
4791 * already. */
4792 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004793 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004794
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004795 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004796 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004797}
4798
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004799void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004800{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004801 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4802 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004803
Dave Airlie0e32b392014-05-02 14:02:48 +10004804 intel_dp_mst_encoder_cleanup(intel_dig_port);
Keith Packardbd943152011-09-18 23:09:52 -07004805 if (is_edp(intel_dp)) {
4806 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004807 /*
4808 * vdd might still be enabled do to the delayed vdd off.
4809 * Make sure vdd is actually turned off here.
4810 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004811 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004812 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004813 pps_unlock(intel_dp);
4814
Clint Taylor01527b32014-07-07 13:01:46 -07004815 if (intel_dp->edp_notifier.notifier_call) {
4816 unregister_reboot_notifier(&intel_dp->edp_notifier);
4817 intel_dp->edp_notifier.notifier_call = NULL;
4818 }
Keith Packardbd943152011-09-18 23:09:52 -07004819 }
Chris Wilson99681882016-06-20 09:29:17 +01004820
4821 intel_dp_aux_fini(intel_dp);
4822
Imre Deakc8bd0e42014-12-12 17:57:38 +02004823 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004824 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004825}
4826
Imre Deakbf93ba62016-04-18 10:04:21 +03004827void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004828{
4829 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4830
4831 if (!is_edp(intel_dp))
4832 return;
4833
Ville Syrjälä951468f2014-09-04 14:55:31 +03004834 /*
4835 * vdd might still be enabled do to the delayed vdd off.
4836 * Make sure vdd is actually turned off here.
4837 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004838 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004839 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004840 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004841 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004842}
4843
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004844static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4845{
4846 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4847 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004848 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004849 enum intel_display_power_domain power_domain;
4850
4851 lockdep_assert_held(&dev_priv->pps_mutex);
4852
4853 if (!edp_have_panel_vdd(intel_dp))
4854 return;
4855
4856 /*
4857 * The VDD bit needs a power domain reference, so if the bit is
4858 * already enabled when we boot or resume, grab this reference and
4859 * schedule a vdd off, so we don't hold on to the reference
4860 * indefinitely.
4861 */
4862 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004863 power_domain = intel_display_port_aux_power_domain(&intel_dig_port->base);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004864 intel_display_power_get(dev_priv, power_domain);
4865
4866 edp_panel_vdd_schedule_off(intel_dp);
4867}
4868
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02004869static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
4870{
4871 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
4872
4873 if ((intel_dp->DP & DP_PORT_EN) == 0)
4874 return INVALID_PIPE;
4875
4876 if (IS_CHERRYVIEW(dev_priv))
4877 return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
4878 else
4879 return PORT_TO_PIPE(intel_dp->DP);
4880}
4881
Imre Deakbf93ba62016-04-18 10:04:21 +03004882void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03004883{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03004884 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Imre Deakdd75f6d2016-11-21 21:15:05 +02004885 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
4886 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Ville Syrjälä64989ca42016-05-13 20:53:56 +03004887
4888 if (!HAS_DDI(dev_priv))
4889 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004890
Imre Deakdd75f6d2016-11-21 21:15:05 +02004891 if (lspcon->active)
Shashank Sharma910530c2016-10-14 19:56:52 +05304892 lspcon_resume(lspcon);
4893
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004894 pps_lock(intel_dp);
4895
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02004896 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4897 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
4898
4899 if (is_edp(intel_dp)) {
4900 /* Reinit the power sequencer, in case BIOS did something with it. */
4901 intel_dp_pps_init(encoder->dev, intel_dp);
4902 intel_edp_panel_vdd_sanitize(intel_dp);
4903 }
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004904
4905 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03004906}
4907
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004908static const struct drm_connector_funcs intel_dp_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02004909 .dpms = drm_atomic_helper_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004910 .detect = intel_dp_detect,
Chris Wilsonbeb60602014-09-02 20:04:00 +01004911 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004912 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01004913 .set_property = intel_dp_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -08004914 .atomic_get_property = intel_connector_atomic_get_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01004915 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01004916 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004917 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08004918 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02004919 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004920};
4921
4922static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
4923 .get_modes = intel_dp_get_modes,
4924 .mode_valid = intel_dp_mode_valid,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004925};
4926
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004927static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03004928 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02004929 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004930};
4931
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004932enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10004933intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
4934{
4935 struct intel_dp *intel_dp = &intel_dig_port->dp;
Imre Deak1c767b32014-08-18 14:42:42 +03004936 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Dave Airlie0e32b392014-05-02 14:02:48 +10004937 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004938 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak1c767b32014-08-18 14:42:42 +03004939 enum intel_display_power_domain power_domain;
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004940 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03004941
Takashi Iwai25400582015-11-19 12:09:56 +01004942 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
4943 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004944 intel_dig_port->base.type = INTEL_OUTPUT_DP;
Dave Airlie13cf5502014-06-18 11:29:35 +10004945
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03004946 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
4947 /*
4948 * vdd off can generate a long pulse on eDP which
4949 * would require vdd on to handle it, and thus we
4950 * would end up in an endless cycle of
4951 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
4952 */
4953 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
4954 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d522015-02-10 14:11:46 +02004955 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03004956 }
4957
Ville Syrjälä26fbb772014-08-11 18:37:37 +03004958 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
4959 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10004960 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10004961
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004962 if (long_hpd) {
4963 intel_dp->detect_done = false;
4964 return IRQ_NONE;
4965 }
4966
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004967 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak1c767b32014-08-18 14:42:42 +03004968 intel_display_power_get(dev_priv, power_domain);
4969
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004970 if (intel_dp->is_mst) {
4971 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
4972 /*
4973 * If we were in MST mode, and device is not
4974 * there, get out of MST mode
4975 */
4976 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4977 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
4978 intel_dp->is_mst = false;
4979 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4980 intel_dp->is_mst);
4981 intel_dp->detect_done = false;
4982 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10004983 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004984 }
Dave Airlie0e32b392014-05-02 14:02:48 +10004985
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004986 if (!intel_dp->is_mst) {
4987 if (!intel_dp_short_pulse(intel_dp)) {
4988 intel_dp->detect_done = false;
4989 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304990 }
Dave Airlie0e32b392014-05-02 14:02:48 +10004991 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004992
4993 ret = IRQ_HANDLED;
4994
Imre Deak1c767b32014-08-18 14:42:42 +03004995put_power:
4996 intel_display_power_put(dev_priv, power_domain);
4997
4998 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10004999}
5000
Rodrigo Vivi477ec322015-08-06 15:51:39 +08005001/* check the VBT to see whether the eDP is on another port */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005002bool intel_dp_is_edp(struct drm_i915_private *dev_priv, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08005003{
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005004 /*
5005 * eDP not supported on g4x. so bail out early just
5006 * for a bit extra safety in case the VBT is bonkers.
5007 */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005008 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005009 return false;
5010
Imre Deaka98d9c12016-12-21 12:17:24 +02005011 if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005012 return true;
5013
Jani Nikula951d9ef2016-03-16 12:43:31 +02005014 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08005015}
5016
Dave Airlie0e32b392014-05-02 14:02:48 +10005017void
Chris Wilsonf6849602010-09-19 09:29:33 +01005018intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
5019{
Yuly Novikov53b41832012-10-26 12:04:00 +03005020 struct intel_connector *intel_connector = to_intel_connector(connector);
5021
Chris Wilson3f43c482011-05-12 22:17:24 +01005022 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00005023 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02005024 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03005025
5026 if (is_edp(intel_dp)) {
5027 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05005028 drm_object_attach_property(
5029 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03005030 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03005031 DRM_MODE_SCALE_ASPECT);
5032 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03005033 }
Chris Wilsonf6849602010-09-19 09:29:33 +01005034}
5035
Imre Deakdada1a92014-01-29 13:25:41 +02005036static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
5037{
Abhay Kumard28d4732016-01-22 17:39:04 -08005038 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02005039 intel_dp->last_power_on = jiffies;
5040 intel_dp->last_backlight_off = jiffies;
5041}
5042
Daniel Vetter67a54562012-10-20 20:57:45 +02005043static void
Imre Deak54648612016-06-16 16:37:22 +03005044intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
5045 struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02005046{
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305047 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03005048 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07005049
Imre Deak8e8232d2016-06-16 16:37:21 +03005050 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02005051
5052 /* Workaround: Need to write PP_CONTROL with the unlock key as
5053 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305054 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02005055
Imre Deak8e8232d2016-06-16 16:37:21 +03005056 pp_on = I915_READ(regs.pp_on);
5057 pp_off = I915_READ(regs.pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005058 if (!IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005059 I915_WRITE(regs.pp_ctrl, pp_ctl);
5060 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305061 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005062
5063 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03005064 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
5065 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005066
Imre Deak54648612016-06-16 16:37:22 +03005067 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
5068 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005069
Imre Deak54648612016-06-16 16:37:22 +03005070 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
5071 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005072
Imre Deak54648612016-06-16 16:37:22 +03005073 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
5074 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005075
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005076 if (IS_GEN9_LP(dev_priv)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305077 u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
5078 BXT_POWER_CYCLE_DELAY_SHIFT;
5079 if (tmp > 0)
Imre Deak54648612016-06-16 16:37:22 +03005080 seq->t11_t12 = (tmp - 1) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305081 else
Imre Deak54648612016-06-16 16:37:22 +03005082 seq->t11_t12 = 0;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305083 } else {
Imre Deak54648612016-06-16 16:37:22 +03005084 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02005085 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305086 }
Imre Deak54648612016-06-16 16:37:22 +03005087}
5088
5089static void
Imre Deakde9c1b62016-06-16 20:01:46 +03005090intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
5091{
5092 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5093 state_name,
5094 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
5095}
5096
5097static void
5098intel_pps_verify_state(struct drm_i915_private *dev_priv,
5099 struct intel_dp *intel_dp)
5100{
5101 struct edp_power_seq hw;
5102 struct edp_power_seq *sw = &intel_dp->pps_delays;
5103
5104 intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
5105
5106 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
5107 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
5108 DRM_ERROR("PPS state mismatch\n");
5109 intel_pps_dump_state("sw", sw);
5110 intel_pps_dump_state("hw", &hw);
5111 }
5112}
5113
5114static void
Imre Deak54648612016-06-16 16:37:22 +03005115intel_dp_init_panel_power_sequencer(struct drm_device *dev,
5116 struct intel_dp *intel_dp)
5117{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005118 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak54648612016-06-16 16:37:22 +03005119 struct edp_power_seq cur, vbt, spec,
5120 *final = &intel_dp->pps_delays;
5121
5122 lockdep_assert_held(&dev_priv->pps_mutex);
5123
5124 /* already initialized? */
5125 if (final->t11_t12 != 0)
5126 return;
5127
5128 intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005129
Imre Deakde9c1b62016-06-16 20:01:46 +03005130 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005131
Jani Nikula6aa23e62016-03-24 17:50:20 +02005132 vbt = dev_priv->vbt.edp.pps;
Daniel Vetter67a54562012-10-20 20:57:45 +02005133
5134 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5135 * our hw here, which are all in 100usec. */
5136 spec.t1_t3 = 210 * 10;
5137 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5138 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5139 spec.t10 = 500 * 10;
5140 /* This one is special and actually in units of 100ms, but zero
5141 * based in the hw (so we need to add 100 ms). But the sw vbt
5142 * table multiplies it with 1000 to make it in units of 100usec,
5143 * too. */
5144 spec.t11_t12 = (510 + 100) * 10;
5145
Imre Deakde9c1b62016-06-16 20:01:46 +03005146 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005147
5148 /* Use the max of the register settings and vbt. If both are
5149 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005150#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005151 spec.field : \
5152 max(cur.field, vbt.field))
5153 assign_final(t1_t3);
5154 assign_final(t8);
5155 assign_final(t9);
5156 assign_final(t10);
5157 assign_final(t11_t12);
5158#undef assign_final
5159
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005160#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005161 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5162 intel_dp->backlight_on_delay = get_delay(t8);
5163 intel_dp->backlight_off_delay = get_delay(t9);
5164 intel_dp->panel_power_down_delay = get_delay(t10);
5165 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5166#undef get_delay
5167
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005168 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5169 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5170 intel_dp->panel_power_cycle_delay);
5171
5172 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5173 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005174
5175 /*
5176 * We override the HW backlight delays to 1 because we do manual waits
5177 * on them. For T8, even BSpec recommends doing it. For T9, if we
5178 * don't do this, we'll end up waiting for the backlight off delay
5179 * twice: once when we do the manual sleep, and once when we disable
5180 * the panel and wait for the PP_STATUS bit to become zero.
5181 */
5182 final->t8 = 1;
5183 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005184}
5185
5186static void
5187intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005188 struct intel_dp *intel_dp,
5189 bool force_disable_vdd)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005190{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005191 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07005192 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005193 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005194 struct pps_registers regs;
Ville Syrjäläad933b52014-08-18 22:15:56 +03005195 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005196 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005197
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005198 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005199
Imre Deak8e8232d2016-06-16 16:37:21 +03005200 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005201
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005202 /*
5203 * On some VLV machines the BIOS can leave the VDD
5204 * enabled even on power seqeuencers which aren't
5205 * hooked up to any port. This would mess up the
5206 * power domain tracking the first time we pick
5207 * one of these power sequencers for use since
5208 * edp_panel_vdd_on() would notice that the VDD was
5209 * already on and therefore wouldn't grab the power
5210 * domain reference. Disable VDD first to avoid this.
5211 * This also avoids spuriously turning the VDD on as
5212 * soon as the new power seqeuencer gets initialized.
5213 */
5214 if (force_disable_vdd) {
5215 u32 pp = ironlake_get_pp_control(intel_dp);
5216
5217 WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
5218
5219 if (pp & EDP_FORCE_VDD)
5220 DRM_DEBUG_KMS("VDD already on, disabling first\n");
5221
5222 pp &= ~EDP_FORCE_VDD;
5223
5224 I915_WRITE(regs.pp_ctrl, pp);
5225 }
5226
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005227 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005228 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5229 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005230 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005231 /* Compute the divisor for the pp clock, simply match the Bspec
5232 * formula. */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005233 if (IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005234 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305235 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
5236 pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
5237 << BXT_POWER_CYCLE_DELAY_SHIFT);
5238 } else {
5239 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5240 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5241 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5242 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005243
5244 /* Haswell doesn't have any port selection bits for the panel
5245 * power sequencer any more. */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005246 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005247 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005248 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005249 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005250 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005251 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005252 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005253 }
5254
Jesse Barnes453c5422013-03-28 09:55:41 -07005255 pp_on |= port_sel;
5256
Imre Deak8e8232d2016-06-16 16:37:21 +03005257 I915_WRITE(regs.pp_on, pp_on);
5258 I915_WRITE(regs.pp_off, pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005259 if (IS_GEN9_LP(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005260 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305261 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005262 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005263
Daniel Vetter67a54562012-10-20 20:57:45 +02005264 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 +03005265 I915_READ(regs.pp_on),
5266 I915_READ(regs.pp_off),
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005267 IS_GEN9_LP(dev_priv) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005268 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5269 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005270}
5271
Imre Deak335f7522016-08-10 14:07:32 +03005272static void intel_dp_pps_init(struct drm_device *dev,
5273 struct intel_dp *intel_dp)
5274{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005275 struct drm_i915_private *dev_priv = to_i915(dev);
5276
5277 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Imre Deak335f7522016-08-10 14:07:32 +03005278 vlv_initial_power_sequencer_setup(intel_dp);
5279 } else {
5280 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005281 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak335f7522016-08-10 14:07:32 +03005282 }
5283}
5284
Vandana Kannanb33a2812015-02-13 15:33:03 +05305285/**
5286 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005287 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005288 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305289 * @refresh_rate: RR to be programmed
5290 *
5291 * This function gets called when refresh rate (RR) has to be changed from
5292 * one frequency to another. Switches can be between high and low RR
5293 * supported by the panel or to any other RR based on media playback (in
5294 * this case, RR value needs to be passed from user space).
5295 *
5296 * The caller of this function needs to take a lock on dev_priv->drrs.
5297 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005298static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
5299 struct intel_crtc_state *crtc_state,
5300 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305301{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305302 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305303 struct intel_digital_port *dig_port = NULL;
5304 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005305 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305306 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305307
5308 if (refresh_rate <= 0) {
5309 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5310 return;
5311 }
5312
Vandana Kannan96178ee2015-01-10 02:25:56 +05305313 if (intel_dp == NULL) {
5314 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305315 return;
5316 }
5317
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005318 /*
Rodrigo Vivie4d59f62014-11-20 02:22:08 -08005319 * FIXME: This needs proper synchronization with psr state for some
5320 * platforms that cannot have PSR and DRRS enabled at the same time.
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005321 */
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305322
Vandana Kannan96178ee2015-01-10 02:25:56 +05305323 dig_port = dp_to_dig_port(intel_dp);
5324 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02005325 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305326
5327 if (!intel_crtc) {
5328 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5329 return;
5330 }
5331
Vandana Kannan96178ee2015-01-10 02:25:56 +05305332 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305333 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5334 return;
5335 }
5336
Vandana Kannan96178ee2015-01-10 02:25:56 +05305337 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5338 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305339 index = DRRS_LOW_RR;
5340
Vandana Kannan96178ee2015-01-10 02:25:56 +05305341 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305342 DRM_DEBUG_KMS(
5343 "DRRS requested for previously set RR...ignoring\n");
5344 return;
5345 }
5346
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005347 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305348 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5349 return;
5350 }
5351
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005352 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305353 switch (index) {
5354 case DRRS_HIGH_RR:
5355 intel_dp_set_m_n(intel_crtc, M1_N1);
5356 break;
5357 case DRRS_LOW_RR:
5358 intel_dp_set_m_n(intel_crtc, M2_N2);
5359 break;
5360 case DRRS_MAX_RR:
5361 default:
5362 DRM_ERROR("Unsupported refreshrate type\n");
5363 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005364 } else if (INTEL_GEN(dev_priv) > 6) {
5365 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005366 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305367
Ville Syrjälä649636e2015-09-22 19:50:01 +03005368 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305369 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005370 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305371 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5372 else
5373 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305374 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005375 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305376 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5377 else
5378 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305379 }
5380 I915_WRITE(reg, val);
5381 }
5382
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305383 dev_priv->drrs.refresh_rate_type = index;
5384
5385 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5386}
5387
Vandana Kannanb33a2812015-02-13 15:33:03 +05305388/**
5389 * intel_edp_drrs_enable - init drrs struct if supported
5390 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005391 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305392 *
5393 * Initializes frontbuffer_bits and drrs.dp
5394 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005395void intel_edp_drrs_enable(struct intel_dp *intel_dp,
5396 struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305397{
5398 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005399 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305400
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005401 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305402 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5403 return;
5404 }
5405
5406 mutex_lock(&dev_priv->drrs.mutex);
5407 if (WARN_ON(dev_priv->drrs.dp)) {
5408 DRM_ERROR("DRRS already enabled\n");
5409 goto unlock;
5410 }
5411
5412 dev_priv->drrs.busy_frontbuffer_bits = 0;
5413
5414 dev_priv->drrs.dp = intel_dp;
5415
5416unlock:
5417 mutex_unlock(&dev_priv->drrs.mutex);
5418}
5419
Vandana Kannanb33a2812015-02-13 15:33:03 +05305420/**
5421 * intel_edp_drrs_disable - Disable DRRS
5422 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005423 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305424 *
5425 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005426void intel_edp_drrs_disable(struct intel_dp *intel_dp,
5427 struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305428{
5429 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005430 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305431
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005432 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305433 return;
5434
5435 mutex_lock(&dev_priv->drrs.mutex);
5436 if (!dev_priv->drrs.dp) {
5437 mutex_unlock(&dev_priv->drrs.mutex);
5438 return;
5439 }
5440
5441 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005442 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5443 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305444
5445 dev_priv->drrs.dp = NULL;
5446 mutex_unlock(&dev_priv->drrs.mutex);
5447
5448 cancel_delayed_work_sync(&dev_priv->drrs.work);
5449}
5450
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305451static void intel_edp_drrs_downclock_work(struct work_struct *work)
5452{
5453 struct drm_i915_private *dev_priv =
5454 container_of(work, typeof(*dev_priv), drrs.work.work);
5455 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305456
Vandana Kannan96178ee2015-01-10 02:25:56 +05305457 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305458
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305459 intel_dp = dev_priv->drrs.dp;
5460
5461 if (!intel_dp)
5462 goto unlock;
5463
5464 /*
5465 * The delayed work can race with an invalidate hence we need to
5466 * recheck.
5467 */
5468
5469 if (dev_priv->drrs.busy_frontbuffer_bits)
5470 goto unlock;
5471
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005472 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5473 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5474
5475 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5476 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5477 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305478
5479unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305480 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305481}
5482
Vandana Kannanb33a2812015-02-13 15:33:03 +05305483/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305484 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005485 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305486 * @frontbuffer_bits: frontbuffer plane tracking bits
5487 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305488 * This function gets called everytime rendering on the given planes start.
5489 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305490 *
5491 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5492 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005493void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5494 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305495{
Vandana Kannana93fad02015-01-10 02:25:59 +05305496 struct drm_crtc *crtc;
5497 enum pipe pipe;
5498
Daniel Vetter9da7d692015-04-09 16:44:15 +02005499 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305500 return;
5501
Daniel Vetter88f933a2015-04-09 16:44:16 +02005502 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305503
Vandana Kannana93fad02015-01-10 02:25:59 +05305504 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005505 if (!dev_priv->drrs.dp) {
5506 mutex_unlock(&dev_priv->drrs.mutex);
5507 return;
5508 }
5509
Vandana Kannana93fad02015-01-10 02:25:59 +05305510 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5511 pipe = to_intel_crtc(crtc)->pipe;
5512
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005513 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5514 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5515
Ramalingam C0ddfd202015-06-15 20:50:05 +05305516 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005517 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005518 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5519 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305520
Vandana Kannana93fad02015-01-10 02:25:59 +05305521 mutex_unlock(&dev_priv->drrs.mutex);
5522}
5523
Vandana Kannanb33a2812015-02-13 15:33:03 +05305524/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305525 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005526 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305527 * @frontbuffer_bits: frontbuffer plane tracking bits
5528 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305529 * This function gets called every time rendering on the given planes has
5530 * completed or flip on a crtc is completed. So DRRS should be upclocked
5531 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5532 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305533 *
5534 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5535 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005536void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5537 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305538{
Vandana Kannana93fad02015-01-10 02:25:59 +05305539 struct drm_crtc *crtc;
5540 enum pipe pipe;
5541
Daniel Vetter9da7d692015-04-09 16:44:15 +02005542 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305543 return;
5544
Daniel Vetter88f933a2015-04-09 16:44:16 +02005545 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305546
Vandana Kannana93fad02015-01-10 02:25:59 +05305547 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005548 if (!dev_priv->drrs.dp) {
5549 mutex_unlock(&dev_priv->drrs.mutex);
5550 return;
5551 }
5552
Vandana Kannana93fad02015-01-10 02:25:59 +05305553 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5554 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005555
5556 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305557 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5558
Ramalingam C0ddfd202015-06-15 20:50:05 +05305559 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005560 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005561 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5562 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305563
5564 /*
5565 * flush also means no more activity hence schedule downclock, if all
5566 * other fbs are quiescent too
5567 */
5568 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305569 schedule_delayed_work(&dev_priv->drrs.work,
5570 msecs_to_jiffies(1000));
5571 mutex_unlock(&dev_priv->drrs.mutex);
5572}
5573
Vandana Kannanb33a2812015-02-13 15:33:03 +05305574/**
5575 * DOC: Display Refresh Rate Switching (DRRS)
5576 *
5577 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5578 * which enables swtching between low and high refresh rates,
5579 * dynamically, based on the usage scenario. This feature is applicable
5580 * for internal panels.
5581 *
5582 * Indication that the panel supports DRRS is given by the panel EDID, which
5583 * would list multiple refresh rates for one resolution.
5584 *
5585 * DRRS is of 2 types - static and seamless.
5586 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5587 * (may appear as a blink on screen) and is used in dock-undock scenario.
5588 * Seamless DRRS involves changing RR without any visual effect to the user
5589 * and can be used during normal system usage. This is done by programming
5590 * certain registers.
5591 *
5592 * Support for static/seamless DRRS may be indicated in the VBT based on
5593 * inputs from the panel spec.
5594 *
5595 * DRRS saves power by switching to low RR based on usage scenarios.
5596 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005597 * The implementation is based on frontbuffer tracking implementation. When
5598 * there is a disturbance on the screen triggered by user activity or a periodic
5599 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5600 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5601 * made.
5602 *
5603 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5604 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305605 *
5606 * DRRS can be further extended to support other internal panels and also
5607 * the scenario of video playback wherein RR is set based on the rate
5608 * requested by userspace.
5609 */
5610
5611/**
5612 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5613 * @intel_connector: eDP connector
5614 * @fixed_mode: preferred mode of panel
5615 *
5616 * This function is called only once at driver load to initialize basic
5617 * DRRS stuff.
5618 *
5619 * Returns:
5620 * Downclock mode if panel supports it, else return NULL.
5621 * DRRS support is determined by the presence of downclock mode (apart
5622 * from VBT setting).
5623 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305624static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305625intel_dp_drrs_init(struct intel_connector *intel_connector,
5626 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305627{
5628 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305629 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005630 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305631 struct drm_display_mode *downclock_mode = NULL;
5632
Daniel Vetter9da7d692015-04-09 16:44:15 +02005633 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5634 mutex_init(&dev_priv->drrs.mutex);
5635
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005636 if (INTEL_GEN(dev_priv) <= 6) {
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305637 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5638 return NULL;
5639 }
5640
5641 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005642 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305643 return NULL;
5644 }
5645
5646 downclock_mode = intel_find_panel_downclock
Mika Kaholaa318b4c2016-12-13 10:02:48 +02005647 (dev_priv, fixed_mode, connector);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305648
5649 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305650 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305651 return NULL;
5652 }
5653
Vandana Kannan96178ee2015-01-10 02:25:56 +05305654 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305655
Vandana Kannan96178ee2015-01-10 02:25:56 +05305656 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005657 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305658 return downclock_mode;
5659}
5660
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005661static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005662 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005663{
5664 struct drm_connector *connector = &intel_connector->base;
5665 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005666 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5667 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005668 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005669 struct drm_display_mode *fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305670 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005671 bool has_dpcd;
5672 struct drm_display_mode *scan;
5673 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005674 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005675
5676 if (!is_edp(intel_dp))
5677 return true;
5678
Imre Deak97a824e12016-06-21 11:51:47 +03005679 /*
5680 * On IBX/CPT we may get here with LVDS already registered. Since the
5681 * driver uses the only internal power sequencer available for both
5682 * eDP and LVDS bail out early in this case to prevent interfering
5683 * with an already powered-on LVDS power sequencer.
5684 */
5685 if (intel_get_lvds_encoder(dev)) {
5686 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5687 DRM_INFO("LVDS was detected, not registering eDP\n");
5688
5689 return false;
5690 }
5691
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005692 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005693
5694 intel_dp_init_panel_power_timestamps(intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +03005695 intel_dp_pps_init(dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005696 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005697
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005698 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005699
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005700 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005701 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005702
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005703 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005704 /* if this fails, presume the device is a ghost */
5705 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005706 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005707 }
5708
Daniel Vetter060c8772014-03-21 23:22:35 +01005709 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005710 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005711 if (edid) {
5712 if (drm_add_edid_modes(connector, edid)) {
5713 drm_mode_connector_update_edid_property(connector,
5714 edid);
5715 drm_edid_to_eld(connector, edid);
5716 } else {
5717 kfree(edid);
5718 edid = ERR_PTR(-EINVAL);
5719 }
5720 } else {
5721 edid = ERR_PTR(-ENOENT);
5722 }
5723 intel_connector->edid = edid;
5724
5725 /* prefer fixed mode from EDID if available */
5726 list_for_each_entry(scan, &connector->probed_modes, head) {
5727 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5728 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305729 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305730 intel_connector, fixed_mode);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005731 break;
5732 }
5733 }
5734
5735 /* fallback to VBT if available for eDP */
5736 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5737 fixed_mode = drm_mode_duplicate(dev,
5738 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005739 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005740 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005741 connector->display_info.width_mm = fixed_mode->width_mm;
5742 connector->display_info.height_mm = fixed_mode->height_mm;
5743 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005744 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005745 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005746
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005747 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005748 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5749 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005750
5751 /*
5752 * Figure out the current pipe for the initial backlight setup.
5753 * If the current pipe isn't valid, try the PPS pipe, and if that
5754 * fails just assume pipe A.
5755 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005756 pipe = vlv_active_pipe(intel_dp);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005757
5758 if (pipe != PIPE_A && pipe != PIPE_B)
5759 pipe = intel_dp->pps_pipe;
5760
5761 if (pipe != PIPE_A && pipe != PIPE_B)
5762 pipe = PIPE_A;
5763
5764 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5765 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005766 }
5767
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305768 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005769 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005770 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005771
5772 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005773
5774out_vdd_off:
5775 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5776 /*
5777 * vdd might still be enabled do to the delayed vdd off.
5778 * Make sure vdd is actually turned off here.
5779 */
5780 pps_lock(intel_dp);
5781 edp_panel_vdd_off_sync(intel_dp);
5782 pps_unlock(intel_dp);
5783
5784 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005785}
5786
Paulo Zanoni16c25532013-06-12 17:27:25 -03005787bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005788intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5789 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005790{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005791 struct drm_connector *connector = &intel_connector->base;
5792 struct intel_dp *intel_dp = &intel_dig_port->dp;
5793 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5794 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005795 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02005796 enum port port = intel_dig_port->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01005797 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005798
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005799 if (WARN(intel_dig_port->max_lanes < 1,
5800 "Not enough lanes (%d) for DP on port %c\n",
5801 intel_dig_port->max_lanes, port_name(port)))
5802 return false;
5803
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005804 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005805 intel_dp->active_pipe = INVALID_PIPE;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005806
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005807 /* intel_dp vfuncs */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005808 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub6b5e382014-01-20 16:00:59 +00005809 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005810 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005811 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005812 else if (HAS_PCH_SPLIT(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005813 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
5814 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005815 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005816
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005817 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00005818 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
5819 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005820 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00005821
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005822 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03005823 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
5824
Daniel Vetter07679352012-09-06 22:15:42 +02005825 /* Preserve the current hw state. */
5826 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03005827 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00005828
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005829 if (intel_dp_is_edp(dev_priv, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05305830 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005831 else
5832 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04005833
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005834 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5835 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5836
Imre Deakf7d24902013-05-08 13:14:05 +03005837 /*
5838 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
5839 * for DP the encoder type can be set by the caller to
5840 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
5841 */
5842 if (type == DRM_MODE_CONNECTOR_eDP)
5843 intel_encoder->type = INTEL_OUTPUT_EDP;
5844
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005845 /* eDP only on port B and/or C on vlv/chv */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005846 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08005847 is_edp(intel_dp) && port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005848 return false;
5849
Imre Deake7281ea2013-05-08 13:14:08 +03005850 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
5851 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
5852 port_name(port));
5853
Adam Jacksonb3295302010-07-16 14:46:28 -04005854 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005855 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
5856
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005857 connector->interlace_allowed = true;
5858 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08005859
Mika Kaholab6339582016-09-09 14:10:52 +03005860 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01005861
Daniel Vetter66a92782012-07-12 20:08:18 +02005862 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01005863 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08005864
Chris Wilsondf0e9242010-09-09 16:20:55 +01005865 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005866
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005867 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02005868 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
5869 else
5870 intel_connector->get_hw_state = intel_connector_get_hw_state;
5871
Jani Nikula0b998362014-03-14 16:51:17 +02005872 /* Set up the hotplug pin. */
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005873 switch (port) {
5874 case PORT_A:
Egbert Eich1d843f92013-02-25 12:06:49 -05005875 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005876 break;
5877 case PORT_B:
Egbert Eich1d843f92013-02-25 12:06:49 -05005878 intel_encoder->hpd_pin = HPD_PORT_B;
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01005879 if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1))
Sonika Jindalcf1d5882015-08-10 10:35:36 +05305880 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005881 break;
5882 case PORT_C:
Egbert Eich1d843f92013-02-25 12:06:49 -05005883 intel_encoder->hpd_pin = HPD_PORT_C;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005884 break;
5885 case PORT_D:
Egbert Eich1d843f92013-02-25 12:06:49 -05005886 intel_encoder->hpd_pin = HPD_PORT_D;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005887 break;
Xiong Zhang26951ca2015-08-17 15:55:50 +08005888 case PORT_E:
5889 intel_encoder->hpd_pin = HPD_PORT_E;
5890 break;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005891 default:
Damien Lespiauad1c0b12013-03-07 15:30:28 +00005892 BUG();
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08005893 }
5894
Dave Airlie0e32b392014-05-02 14:02:48 +10005895 /* init MST on ports that can support it */
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00005896 if (HAS_DP_MST(dev_priv) && !is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03005897 (port == PORT_B || port == PORT_C || port == PORT_D))
5898 intel_dp_mst_encoder_init(intel_dig_port,
5899 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10005900
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005901 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005902 intel_dp_aux_fini(intel_dp);
5903 intel_dp_mst_encoder_cleanup(intel_dig_port);
5904 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03005905 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08005906
Chris Wilsonf6849602010-09-19 09:29:33 +01005907 intel_dp_add_properties(intel_dp, connector);
5908
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005909 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
5910 * 0xd. Failure to do so will result in spurious interrupts being
5911 * generated on the port when a cable is not attached.
5912 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01005913 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005914 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
5915 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
5916 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03005917
5918 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005919
5920fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005921 drm_connector_cleanup(connector);
5922
5923 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005924}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005925
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02005926bool intel_dp_init(struct drm_i915_private *dev_priv,
Chris Wilson457c52d2016-06-01 08:27:50 +01005927 i915_reg_t output_reg,
5928 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005929{
5930 struct intel_digital_port *intel_dig_port;
5931 struct intel_encoder *intel_encoder;
5932 struct drm_encoder *encoder;
5933 struct intel_connector *intel_connector;
5934
Daniel Vetterb14c5672013-09-19 12:18:32 +02005935 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005936 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01005937 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005938
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03005939 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305940 if (!intel_connector)
5941 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005942
5943 intel_encoder = &intel_dig_port->base;
5944 encoder = &intel_encoder->base;
5945
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02005946 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
5947 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
5948 "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305949 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005950
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01005951 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005952 intel_encoder->disable = intel_disable_dp;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005953 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07005954 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03005955 intel_encoder->suspend = intel_dp_encoder_suspend;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005956 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03005957 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03005958 intel_encoder->pre_enable = chv_pre_enable_dp;
5959 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03005960 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03005961 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01005962 } else if (IS_VALLEYVIEW(dev_priv)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03005963 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005964 intel_encoder->pre_enable = vlv_pre_enable_dp;
5965 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03005966 intel_encoder->post_disable = vlv_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005967 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03005968 intel_encoder->pre_enable = g4x_pre_enable_dp;
5969 intel_encoder->enable = g4x_enable_dp;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005970 if (INTEL_GEN(dev_priv) >= 5)
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03005971 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005972 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005973
Paulo Zanoni174edf12012-10-26 19:05:50 -02005974 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005975 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005976 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005977
Ville Syrjäläcca05022016-06-22 21:57:06 +03005978 intel_encoder->type = INTEL_OUTPUT_DP;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005979 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03005980 if (port == PORT_D)
5981 intel_encoder->crtc_mask = 1 << 2;
5982 else
5983 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
5984 } else {
5985 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
5986 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02005987 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07005988 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005989
Dave Airlie13cf5502014-06-18 11:29:35 +10005990 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03005991 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10005992
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305993 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
5994 goto err_init_connector;
5995
Chris Wilson457c52d2016-06-01 08:27:50 +01005996 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305997
5998err_init_connector:
5999 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306000err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306001 kfree(intel_connector);
6002err_connector_alloc:
6003 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01006004 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006005}
Dave Airlie0e32b392014-05-02 14:02:48 +10006006
6007void intel_dp_mst_suspend(struct drm_device *dev)
6008{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006009 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006010 int i;
6011
6012 /* disable MST */
6013 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006014 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006015
6016 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006017 continue;
6018
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006019 if (intel_dig_port->dp.is_mst)
6020 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10006021 }
6022}
6023
6024void intel_dp_mst_resume(struct drm_device *dev)
6025{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006026 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006027 int i;
6028
6029 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006030 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006031 int ret;
6032
6033 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006034 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10006035
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006036 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
6037 if (ret)
6038 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10006039 }
6040}