blob: 343e1d9fa7618595322f04dea0dcc321069016b4 [file] [log] [blame]
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Keith Packard <keithp@keithp.com>
25 *
26 */
27
28#include <linux/i2c.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040030#include <linux/export.h>
Clint Taylor01527b32014-07-07 13:01:46 -070031#include <linux/notifier.h>
32#include <linux/reboot.h>
David Howells760285e2012-10-02 18:01:07 +010033#include <drm/drmP.h>
Matt Roperc6f95f22015-01-22 16:50:32 -080034#include <drm/drm_atomic_helper.h>
David Howells760285e2012-10-02 18:01:07 +010035#include <drm/drm_crtc.h>
36#include <drm/drm_crtc_helper.h>
37#include <drm/drm_edid.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070038#include "intel_drv.h"
David Howells760285e2012-10-02 18:01:07 +010039#include <drm/i915_drm.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070040#include "i915_drv.h"
Keith Packarda4fc5ed2009-04-07 16:16:42 -070041
Keith Packarda4fc5ed2009-04-07 16:16:42 -070042#define DP_LINK_CHECK_TIMEOUT (10 * 1000)
43
Todd Previte559be302015-05-04 07:48:20 -070044/* Compliance test status bits */
45#define INTEL_DP_RESOLUTION_SHIFT_MASK 0
46#define INTEL_DP_RESOLUTION_PREFERRED (1 << INTEL_DP_RESOLUTION_SHIFT_MASK)
47#define INTEL_DP_RESOLUTION_STANDARD (2 << INTEL_DP_RESOLUTION_SHIFT_MASK)
48#define INTEL_DP_RESOLUTION_FAILSAFE (3 << INTEL_DP_RESOLUTION_SHIFT_MASK)
49
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080050struct dp_link_dpll {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030051 int clock;
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080052 struct dpll dpll;
53};
54
55static const struct dp_link_dpll gen4_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030056 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080057 { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030058 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080059 { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
60};
61
62static const struct dp_link_dpll pch_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030063 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080064 { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030065 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080066 { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
67};
68
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080069static const struct dp_link_dpll vlv_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030070 { 162000,
Chon Ming Lee58f6e632013-09-25 15:47:51 +080071 { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030072 { 270000,
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080073 { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } }
74};
75
Chon Ming Leeef9348c2014-04-09 13:28:18 +030076/*
77 * CHV supports eDP 1.4 that have more link rates.
78 * Below only provides the fixed rate but exclude variable rate.
79 */
80static const struct dp_link_dpll chv_dpll[] = {
81 /*
82 * CHV requires to program fractional division for m2.
83 * m2 is stored in fixed point format using formula below
84 * (m2_int << 22) | m2_fraction
85 */
Ville Syrjälä840b32b2015-08-11 20:21:46 +030086 { 162000, /* m2_int = 32, m2_fraction = 1677722 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030087 { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030088 { 270000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030089 { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030090 { 540000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030091 { .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }
92};
Sonika Jindal637a9c62015-05-07 09:52:08 +053093
Sonika Jindal64987fc2015-05-26 17:50:13 +053094static const int bxt_rates[] = { 162000, 216000, 243000, 270000,
95 324000, 432000, 540000 };
Sonika Jindal637a9c62015-05-07 09:52:08 +053096static const int skl_rates[] = { 162000, 216000, 270000,
Ville Syrjäläf4896f12015-03-12 17:10:27 +020097 324000, 432000, 540000 };
98static const int default_rates[] = { 162000, 270000, 540000 };
Chon Ming Leeef9348c2014-04-09 13:28:18 +030099
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700100/**
101 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
102 * @intel_dp: DP struct
103 *
104 * If a CPU or PCH DP output is attached to an eDP panel, this function
105 * will return true, and false otherwise.
106 */
107static bool is_edp(struct intel_dp *intel_dp)
108{
Paulo Zanonida63a9f2012-10-26 19:05:46 -0200109 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
110
111 return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700112}
113
Imre Deak68b4d822013-05-08 13:14:06 +0300114static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp)
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700115{
Imre Deak68b4d822013-05-08 13:14:06 +0300116 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
117
118 return intel_dig_port->base.base.dev;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700119}
120
Chris Wilsondf0e9242010-09-09 16:20:55 +0100121static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
122{
Paulo Zanonifa90ece2012-10-26 19:05:44 -0200123 return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
Chris Wilsondf0e9242010-09-09 16:20:55 +0100124}
125
Chris Wilsonea5b2132010-08-04 13:50:23 +0100126static void intel_dp_link_down(struct intel_dp *intel_dp);
Ville Syrjälä1e0560e2014-08-19 13:24:25 +0300127static bool edp_panel_vdd_on(struct intel_dp *intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +0100128static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
Ville Syrjälä093e3f12014-10-16 21:27:33 +0300129static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300130static void vlv_steal_power_sequencer(struct drm_device *dev,
131 enum pipe pipe);
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +0530132static void intel_dp_unset_edid(struct intel_dp *intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700133
Ville Syrjäläed4e9c12015-03-12 17:10:36 +0200134static int
135intel_dp_max_link_bw(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700136{
Jesse Barnes7183dc22011-07-07 11:10:58 -0700137 int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700138
139 switch (max_link_bw) {
140 case DP_LINK_BW_1_62:
141 case DP_LINK_BW_2_7:
Ville Syrjälä1db10e22015-03-12 17:10:32 +0200142 case DP_LINK_BW_5_4:
Imre Deakd4eead52013-07-09 17:05:26 +0300143 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700144 default:
Imre Deakd4eead52013-07-09 17:05:26 +0300145 WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
146 max_link_bw);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700147 max_link_bw = DP_LINK_BW_1_62;
148 break;
149 }
150 return max_link_bw;
151}
152
Paulo Zanonieeb63242014-05-06 14:56:50 +0300153static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
154{
155 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300156 u8 source_max, sink_max;
157
Ville Syrjäläccb1a832015-12-08 19:59:38 +0200158 source_max = intel_dig_port->max_lanes;
Manasi Navaref4829842016-12-05 16:27:36 -0800159 sink_max = intel_dp->max_sink_lane_count;
Paulo Zanonieeb63242014-05-06 14:56:50 +0300160
161 return min(source_max, sink_max);
162}
163
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800164int
Keith Packardc8982612012-01-25 08:16:25 -0800165intel_dp_link_required(int pixel_clock, int bpp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700166{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800167 /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
168 return DIV_ROUND_UP(pixel_clock * bpp, 8);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700169}
170
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800171int
Dave Airliefe27d532010-06-30 11:46:17 +1000172intel_dp_max_data_rate(int max_link_clock, int max_lanes)
173{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800174 /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
175 * link rate that is generally expressed in Gbps. Since, 8 bits of data
176 * is transmitted every LS_Clk per lane, there is no need to account for
177 * the channel encoding that is done in the PHY layer here.
178 */
179
180 return max_link_clock * max_lanes;
Dave Airliefe27d532010-06-30 11:46:17 +1000181}
182
Mika Kahola70ec0642016-09-09 14:10:55 +0300183static int
184intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp)
185{
186 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
187 struct intel_encoder *encoder = &intel_dig_port->base;
188 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
189 int max_dotclk = dev_priv->max_dotclk_freq;
190 int ds_max_dotclk;
191
192 int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
193
194 if (type != DP_DS_PORT_TYPE_VGA)
195 return max_dotclk;
196
197 ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd,
198 intel_dp->downstream_ports);
199
200 if (ds_max_dotclk != 0)
201 max_dotclk = min(max_dotclk, ds_max_dotclk);
202
203 return max_dotclk;
204}
205
Navare, Manasi D40dba342016-10-26 16:25:55 -0700206static int
207intel_dp_sink_rates(struct intel_dp *intel_dp, const int **sink_rates)
208{
209 if (intel_dp->num_sink_rates) {
210 *sink_rates = intel_dp->sink_rates;
211 return intel_dp->num_sink_rates;
212 }
213
214 *sink_rates = default_rates;
215
Manasi Navaref4829842016-12-05 16:27:36 -0800216 return (intel_dp->max_sink_link_bw >> 3) + 1;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700217}
218
219static int
220intel_dp_source_rates(struct intel_dp *intel_dp, const int **source_rates)
221{
222 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
223 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
224 int size;
225
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200226 if (IS_GEN9_LP(dev_priv)) {
Navare, Manasi D40dba342016-10-26 16:25:55 -0700227 *source_rates = bxt_rates;
228 size = ARRAY_SIZE(bxt_rates);
229 } else if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
230 *source_rates = skl_rates;
231 size = ARRAY_SIZE(skl_rates);
232 } else {
233 *source_rates = default_rates;
234 size = ARRAY_SIZE(default_rates);
235 }
236
237 /* This depends on the fact that 5.4 is last value in the array */
238 if (!intel_dp_source_supports_hbr2(intel_dp))
239 size--;
240
241 return size;
242}
243
244static int intersect_rates(const int *source_rates, int source_len,
245 const int *sink_rates, int sink_len,
246 int *common_rates)
247{
248 int i = 0, j = 0, k = 0;
249
250 while (i < source_len && j < sink_len) {
251 if (source_rates[i] == sink_rates[j]) {
252 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
253 return k;
254 common_rates[k] = source_rates[i];
255 ++k;
256 ++i;
257 ++j;
258 } else if (source_rates[i] < sink_rates[j]) {
259 ++i;
260 } else {
261 ++j;
262 }
263 }
264 return k;
265}
266
267static int intel_dp_common_rates(struct intel_dp *intel_dp,
268 int *common_rates)
269{
270 const int *source_rates, *sink_rates;
271 int source_len, sink_len;
272
273 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
274 source_len = intel_dp_source_rates(intel_dp, &source_rates);
275
276 return intersect_rates(source_rates, source_len,
277 sink_rates, sink_len,
278 common_rates);
279}
280
Manasi Navarefdb14d32016-12-08 19:05:12 -0800281static int intel_dp_link_rate_index(struct intel_dp *intel_dp,
282 int *common_rates, int link_rate)
283{
284 int common_len;
285 int index;
286
287 common_len = intel_dp_common_rates(intel_dp, common_rates);
288 for (index = 0; index < common_len; index++) {
289 if (link_rate == common_rates[common_len - index - 1])
290 return common_len - index - 1;
291 }
292
293 return -1;
294}
295
296int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
297 int link_rate, uint8_t lane_count)
298{
299 int common_rates[DP_MAX_SUPPORTED_RATES];
300 int link_rate_index;
301
302 link_rate_index = intel_dp_link_rate_index(intel_dp,
303 common_rates,
304 link_rate);
305 if (link_rate_index > 0) {
306 intel_dp->max_sink_link_bw = drm_dp_link_rate_to_bw_code(common_rates[link_rate_index - 1]);
307 intel_dp->max_sink_lane_count = lane_count;
308 } else if (lane_count > 1) {
309 intel_dp->max_sink_link_bw = intel_dp_max_link_bw(intel_dp);
310 intel_dp->max_sink_lane_count = lane_count >> 1;
311 } else {
312 DRM_ERROR("Link Training Unsuccessful\n");
313 return -1;
314 }
315
316 return 0;
317}
318
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000319static enum drm_mode_status
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700320intel_dp_mode_valid(struct drm_connector *connector,
321 struct drm_display_mode *mode)
322{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100323 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300324 struct intel_connector *intel_connector = to_intel_connector(connector);
325 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Daniel Vetter36008362013-03-27 00:44:59 +0100326 int target_clock = mode->clock;
327 int max_rate, mode_rate, max_lanes, max_link_clock;
Mika Kahola70ec0642016-09-09 14:10:55 +0300328 int max_dotclk;
329
330 max_dotclk = intel_dp_downstream_max_dotclock(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700331
Jani Nikuladd06f902012-10-19 14:51:50 +0300332 if (is_edp(intel_dp) && fixed_mode) {
333 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100334 return MODE_PANEL;
335
Jani Nikuladd06f902012-10-19 14:51:50 +0300336 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100337 return MODE_PANEL;
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200338
339 target_clock = fixed_mode->clock;
Zhao Yakui7de56f42010-07-19 09:43:14 +0100340 }
341
Ville Syrjälä50fec212015-03-12 17:10:34 +0200342 max_link_clock = intel_dp_max_link_rate(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300343 max_lanes = intel_dp_max_lane_count(intel_dp);
Daniel Vetter36008362013-03-27 00:44:59 +0100344
345 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
346 mode_rate = intel_dp_link_required(target_clock, 18);
347
Mika Kahola799487f2016-02-02 15:16:38 +0200348 if (mode_rate > max_rate || target_clock > max_dotclk)
Daniel Vetterc4867932012-04-10 10:42:36 +0200349 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700350
351 if (mode->clock < 10000)
352 return MODE_CLOCK_LOW;
353
Daniel Vetter0af78a22012-05-23 11:30:55 +0200354 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
355 return MODE_H_ILLEGAL;
356
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700357 return MODE_OK;
358}
359
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800360uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700361{
362 int i;
363 uint32_t v = 0;
364
365 if (src_bytes > 4)
366 src_bytes = 4;
367 for (i = 0; i < src_bytes; i++)
368 v |= ((uint32_t) src[i]) << ((3-i) * 8);
369 return v;
370}
371
Damien Lespiauc2af70e2015-02-10 19:32:23 +0000372static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700373{
374 int i;
375 if (dst_bytes > 4)
376 dst_bytes = 4;
377 for (i = 0; i < dst_bytes; i++)
378 dst[i] = src >> ((3-i) * 8);
379}
380
Jani Nikulabf13e812013-09-06 07:40:05 +0300381static void
382intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300383 struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300384static void
385intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200386 struct intel_dp *intel_dp,
387 bool force_disable_vdd);
Imre Deak335f7522016-08-10 14:07:32 +0300388static void
389intel_dp_pps_init(struct drm_device *dev, struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300390
Ville Syrjälä773538e82014-09-04 14:54:56 +0300391static void pps_lock(struct intel_dp *intel_dp)
392{
393 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
394 struct intel_encoder *encoder = &intel_dig_port->base;
395 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100396 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300397 enum intel_display_power_domain power_domain;
398
399 /*
400 * See vlv_power_sequencer_reset() why we need
401 * a power domain reference here.
402 */
Ville Syrjälä25f78f52015-11-16 15:01:04 +0100403 power_domain = intel_display_port_aux_power_domain(encoder);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300404 intel_display_power_get(dev_priv, power_domain);
405
406 mutex_lock(&dev_priv->pps_mutex);
407}
408
409static void pps_unlock(struct intel_dp *intel_dp)
410{
411 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
412 struct intel_encoder *encoder = &intel_dig_port->base;
413 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100414 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300415 enum intel_display_power_domain power_domain;
416
417 mutex_unlock(&dev_priv->pps_mutex);
418
Ville Syrjälä25f78f52015-11-16 15:01:04 +0100419 power_domain = intel_display_port_aux_power_domain(encoder);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300420 intel_display_power_put(dev_priv, power_domain);
421}
422
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300423static void
424vlv_power_sequencer_kick(struct intel_dp *intel_dp)
425{
426 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200427 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300428 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300429 bool pll_enabled, release_cl_override = false;
430 enum dpio_phy phy = DPIO_PHY(pipe);
431 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300432 uint32_t DP;
433
434 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
435 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
436 pipe_name(pipe), port_name(intel_dig_port->port)))
437 return;
438
439 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
440 pipe_name(pipe), port_name(intel_dig_port->port));
441
442 /* Preserve the BIOS-computed detected bit. This is
443 * supposed to be read-only.
444 */
445 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
446 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
447 DP |= DP_PORT_WIDTH(1);
448 DP |= DP_LINK_TRAIN_PAT_1;
449
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100450 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300451 DP |= DP_PIPE_SELECT_CHV(pipe);
452 else if (pipe == PIPE_B)
453 DP |= DP_PIPEB_SELECT;
454
Ville Syrjäläd288f652014-10-28 13:20:22 +0200455 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
456
457 /*
458 * The DPLL for the pipe must be enabled for this to work.
459 * So enable temporarily it if it's not already enabled.
460 */
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300461 if (!pll_enabled) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100462 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300463 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
464
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200465 if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ?
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000466 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
467 DRM_ERROR("Failed to force on pll for pipe %c!\n",
468 pipe_name(pipe));
469 return;
470 }
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300471 }
Ville Syrjäläd288f652014-10-28 13:20:22 +0200472
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300473 /*
474 * Similar magic as in intel_dp_enable_port().
475 * We _must_ do this port enable + disable trick
476 * to make this power seqeuencer lock onto the port.
477 * Otherwise even VDD force bit won't work.
478 */
479 I915_WRITE(intel_dp->output_reg, DP);
480 POSTING_READ(intel_dp->output_reg);
481
482 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
483 POSTING_READ(intel_dp->output_reg);
484
485 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
486 POSTING_READ(intel_dp->output_reg);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200487
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300488 if (!pll_enabled) {
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200489 vlv_force_pll_off(dev_priv, pipe);
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300490
491 if (release_cl_override)
492 chv_phy_powergate_ch(dev_priv, phy, ch, false);
493 }
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300494}
495
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200496static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv)
497{
498 struct intel_encoder *encoder;
499 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
500
501 /*
502 * We don't have power sequencer currently.
503 * Pick one that's not used by other ports.
504 */
505 for_each_intel_encoder(&dev_priv->drm, encoder) {
506 struct intel_dp *intel_dp;
507
508 if (encoder->type != INTEL_OUTPUT_DP &&
509 encoder->type != INTEL_OUTPUT_EDP)
510 continue;
511
512 intel_dp = enc_to_intel_dp(&encoder->base);
513
514 if (encoder->type == INTEL_OUTPUT_EDP) {
515 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
516 intel_dp->active_pipe != intel_dp->pps_pipe);
517
518 if (intel_dp->pps_pipe != INVALID_PIPE)
519 pipes &= ~(1 << intel_dp->pps_pipe);
520 } else {
521 WARN_ON(intel_dp->pps_pipe != INVALID_PIPE);
522
523 if (intel_dp->active_pipe != INVALID_PIPE)
524 pipes &= ~(1 << intel_dp->active_pipe);
525 }
526 }
527
528 if (pipes == 0)
529 return INVALID_PIPE;
530
531 return ffs(pipes) - 1;
532}
533
Jani Nikulabf13e812013-09-06 07:40:05 +0300534static enum pipe
535vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
536{
537 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300538 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100539 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300540 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300541
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300542 lockdep_assert_held(&dev_priv->pps_mutex);
543
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300544 /* We should never land here with regular DP ports */
545 WARN_ON(!is_edp(intel_dp));
546
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200547 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
548 intel_dp->active_pipe != intel_dp->pps_pipe);
549
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300550 if (intel_dp->pps_pipe != INVALID_PIPE)
551 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300552
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200553 pipe = vlv_find_free_pps(dev_priv);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300554
555 /*
556 * Didn't find one. This should not happen since there
557 * are two power sequencers and up to two eDP ports.
558 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200559 if (WARN_ON(pipe == INVALID_PIPE))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300560 pipe = PIPE_A;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300561
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300562 vlv_steal_power_sequencer(dev, pipe);
563 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300564
565 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
566 pipe_name(intel_dp->pps_pipe),
567 port_name(intel_dig_port->port));
568
569 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300570 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200571 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300572
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300573 /*
574 * Even vdd force doesn't work until we've made
575 * the power sequencer lock in on the port.
576 */
577 vlv_power_sequencer_kick(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300578
579 return intel_dp->pps_pipe;
580}
581
Imre Deak78597992016-06-16 16:37:20 +0300582static int
583bxt_power_sequencer_idx(struct intel_dp *intel_dp)
584{
585 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
586 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100587 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak78597992016-06-16 16:37:20 +0300588
589 lockdep_assert_held(&dev_priv->pps_mutex);
590
591 /* We should never land here with regular DP ports */
592 WARN_ON(!is_edp(intel_dp));
593
594 /*
595 * TODO: BXT has 2 PPS instances. The correct port->PPS instance
596 * mapping needs to be retrieved from VBT, for now just hard-code to
597 * use instance #0 always.
598 */
599 if (!intel_dp->pps_reset)
600 return 0;
601
602 intel_dp->pps_reset = false;
603
604 /*
605 * Only the HW needs to be reprogrammed, the SW state is fixed and
606 * has been setup during connector init.
607 */
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200608 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak78597992016-06-16 16:37:20 +0300609
610 return 0;
611}
612
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300613typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
614 enum pipe pipe);
615
616static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
617 enum pipe pipe)
618{
Imre Deak44cb7342016-08-10 14:07:29 +0300619 return I915_READ(PP_STATUS(pipe)) & PP_ON;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300620}
621
622static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
623 enum pipe pipe)
624{
Imre Deak44cb7342016-08-10 14:07:29 +0300625 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300626}
627
628static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
629 enum pipe pipe)
630{
631 return true;
632}
633
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300634static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300635vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
636 enum port port,
637 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300638{
Jani Nikulabf13e812013-09-06 07:40:05 +0300639 enum pipe pipe;
640
Jani Nikulabf13e812013-09-06 07:40:05 +0300641 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
Imre Deak44cb7342016-08-10 14:07:29 +0300642 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
Jani Nikulabf13e812013-09-06 07:40:05 +0300643 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300644
645 if (port_sel != PANEL_PORT_SELECT_VLV(port))
646 continue;
647
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300648 if (!pipe_check(dev_priv, pipe))
649 continue;
650
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300651 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300652 }
653
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300654 return INVALID_PIPE;
655}
656
657static void
658vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
659{
660 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
661 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100662 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300663 enum port port = intel_dig_port->port;
664
665 lockdep_assert_held(&dev_priv->pps_mutex);
666
667 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300668 /* first pick one where the panel is on */
669 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
670 vlv_pipe_has_pp_on);
671 /* didn't find one? pick one where vdd is on */
672 if (intel_dp->pps_pipe == INVALID_PIPE)
673 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
674 vlv_pipe_has_vdd_on);
675 /* didn't find one? pick one with just the correct port */
676 if (intel_dp->pps_pipe == INVALID_PIPE)
677 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
678 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300679
680 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
681 if (intel_dp->pps_pipe == INVALID_PIPE) {
682 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
683 port_name(port));
684 return;
685 }
686
687 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
688 port_name(port), pipe_name(intel_dp->pps_pipe));
689
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300690 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200691 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Jani Nikulabf13e812013-09-06 07:40:05 +0300692}
693
Imre Deak78597992016-06-16 16:37:20 +0300694void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300695{
Chris Wilson91c8a322016-07-05 10:40:23 +0100696 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300697 struct intel_encoder *encoder;
698
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100699 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200700 !IS_GEN9_LP(dev_priv)))
Ville Syrjälä773538e82014-09-04 14:54:56 +0300701 return;
702
703 /*
704 * We can't grab pps_mutex here due to deadlock with power_domain
705 * mutex when power_domain functions are called while holding pps_mutex.
706 * That also means that in order to use pps_pipe the code needs to
707 * hold both a power domain reference and pps_mutex, and the power domain
708 * reference get/put must be done while _not_ holding pps_mutex.
709 * pps_{lock,unlock}() do these steps in the correct order, so one
710 * should use them always.
711 */
712
Jani Nikula19c80542015-12-16 12:48:16 +0200713 for_each_intel_encoder(dev, encoder) {
Ville Syrjälä773538e82014-09-04 14:54:56 +0300714 struct intel_dp *intel_dp;
715
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200716 if (encoder->type != INTEL_OUTPUT_DP &&
717 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300718 continue;
719
720 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200721
722 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
723
724 if (encoder->type != INTEL_OUTPUT_EDP)
725 continue;
726
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200727 if (IS_GEN9_LP(dev_priv))
Imre Deak78597992016-06-16 16:37:20 +0300728 intel_dp->pps_reset = true;
729 else
730 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300731 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300732}
733
Imre Deak8e8232d2016-06-16 16:37:21 +0300734struct pps_registers {
735 i915_reg_t pp_ctrl;
736 i915_reg_t pp_stat;
737 i915_reg_t pp_on;
738 i915_reg_t pp_off;
739 i915_reg_t pp_div;
740};
741
742static void intel_pps_get_registers(struct drm_i915_private *dev_priv,
743 struct intel_dp *intel_dp,
744 struct pps_registers *regs)
745{
Imre Deak44cb7342016-08-10 14:07:29 +0300746 int pps_idx = 0;
747
Imre Deak8e8232d2016-06-16 16:37:21 +0300748 memset(regs, 0, sizeof(*regs));
749
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200750 if (IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300751 pps_idx = bxt_power_sequencer_idx(intel_dp);
752 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
753 pps_idx = vlv_power_sequencer_pipe(intel_dp);
Imre Deak8e8232d2016-06-16 16:37:21 +0300754
Imre Deak44cb7342016-08-10 14:07:29 +0300755 regs->pp_ctrl = PP_CONTROL(pps_idx);
756 regs->pp_stat = PP_STATUS(pps_idx);
757 regs->pp_on = PP_ON_DELAYS(pps_idx);
758 regs->pp_off = PP_OFF_DELAYS(pps_idx);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200759 if (!IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300760 regs->pp_div = PP_DIVISOR(pps_idx);
Imre Deak8e8232d2016-06-16 16:37:21 +0300761}
762
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200763static i915_reg_t
764_pp_ctrl_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300765{
Imre Deak8e8232d2016-06-16 16:37:21 +0300766 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300767
Imre Deak8e8232d2016-06-16 16:37:21 +0300768 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
769 &regs);
770
771 return regs.pp_ctrl;
Jani Nikulabf13e812013-09-06 07:40:05 +0300772}
773
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200774static i915_reg_t
775_pp_stat_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300776{
Imre Deak8e8232d2016-06-16 16:37:21 +0300777 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300778
Imre Deak8e8232d2016-06-16 16:37:21 +0300779 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
780 &regs);
781
782 return regs.pp_stat;
Jani Nikulabf13e812013-09-06 07:40:05 +0300783}
784
Clint Taylor01527b32014-07-07 13:01:46 -0700785/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
786 This function only applicable when panel PM state is not to be tracked */
787static int edp_notify_handler(struct notifier_block *this, unsigned long code,
788 void *unused)
789{
790 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
791 edp_notifier);
792 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100793 struct drm_i915_private *dev_priv = to_i915(dev);
Clint Taylor01527b32014-07-07 13:01:46 -0700794
795 if (!is_edp(intel_dp) || code != SYS_RESTART)
796 return 0;
797
Ville Syrjälä773538e82014-09-04 14:54:56 +0300798 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300799
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100800 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300801 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200802 i915_reg_t pp_ctrl_reg, pp_div_reg;
Ville Syrjälä649636e2015-09-22 19:50:01 +0300803 u32 pp_div;
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300804
Imre Deak44cb7342016-08-10 14:07:29 +0300805 pp_ctrl_reg = PP_CONTROL(pipe);
806 pp_div_reg = PP_DIVISOR(pipe);
Clint Taylor01527b32014-07-07 13:01:46 -0700807 pp_div = I915_READ(pp_div_reg);
808 pp_div &= PP_REFERENCE_DIVIDER_MASK;
809
810 /* 0x1F write to PP_DIV_REG sets max cycle delay */
811 I915_WRITE(pp_div_reg, pp_div | 0x1F);
812 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
813 msleep(intel_dp->panel_power_cycle_delay);
814 }
815
Ville Syrjälä773538e82014-09-04 14:54:56 +0300816 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300817
Clint Taylor01527b32014-07-07 13:01:46 -0700818 return 0;
819}
820
Daniel Vetter4be73782014-01-17 14:39:48 +0100821static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700822{
Paulo Zanoni30add222012-10-26 19:05:45 -0200823 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100824 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700825
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300826 lockdep_assert_held(&dev_priv->pps_mutex);
827
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100828 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300829 intel_dp->pps_pipe == INVALID_PIPE)
830 return false;
831
Jani Nikulabf13e812013-09-06 07:40:05 +0300832 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700833}
834
Daniel Vetter4be73782014-01-17 14:39:48 +0100835static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700836{
Paulo Zanoni30add222012-10-26 19:05:45 -0200837 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100838 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700839
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300840 lockdep_assert_held(&dev_priv->pps_mutex);
841
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100842 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300843 intel_dp->pps_pipe == INVALID_PIPE)
844 return false;
845
Ville Syrjälä773538e82014-09-04 14:54:56 +0300846 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700847}
848
Keith Packard9b984da2011-09-19 13:54:47 -0700849static void
850intel_dp_check_edp(struct intel_dp *intel_dp)
851{
Paulo Zanoni30add222012-10-26 19:05:45 -0200852 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100853 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700854
Keith Packard9b984da2011-09-19 13:54:47 -0700855 if (!is_edp(intel_dp))
856 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700857
Daniel Vetter4be73782014-01-17 14:39:48 +0100858 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700859 WARN(1, "eDP powered off while attempting aux channel communication.\n");
860 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300861 I915_READ(_pp_stat_reg(intel_dp)),
862 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700863 }
864}
865
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100866static uint32_t
867intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
868{
869 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
870 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100871 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200872 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100873 uint32_t status;
874 bool done;
875
Daniel Vetteref04f002012-12-01 21:03:59 +0100876#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100877 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300878 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300879 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100880 else
Imre Deak713a6b662016-06-28 13:37:33 +0300881 done = wait_for(C, 10) == 0;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100882 if (!done)
883 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
884 has_aux_irq);
885#undef C
886
887 return status;
888}
889
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200890static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000891{
892 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200893 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000894
Ville Syrjäläa457f542016-03-02 17:22:17 +0200895 if (index)
896 return 0;
897
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000898 /*
899 * The clock divider is based off the hrawclk, and would like to run at
Ville Syrjäläa457f542016-03-02 17:22:17 +0200900 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000901 */
Ville Syrjäläa457f542016-03-02 17:22:17 +0200902 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000903}
904
905static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
906{
907 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200908 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000909
910 if (index)
911 return 0;
912
Ville Syrjäläa457f542016-03-02 17:22:17 +0200913 /*
914 * The clock divider is based off the cdclk or PCH rawclk, and would
915 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
916 * divide by 2000 and use that
917 */
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200918 if (intel_dig_port->port == PORT_A)
Ville Syrjäläfce18c42015-11-30 16:23:46 +0200919 return DIV_ROUND_CLOSEST(dev_priv->cdclk_freq, 2000);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200920 else
921 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000922}
923
924static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300925{
926 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200927 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300928
Ville Syrjäläa457f542016-03-02 17:22:17 +0200929 if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300930 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100931 switch (index) {
932 case 0: return 63;
933 case 1: return 72;
934 default: return 0;
935 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300936 }
Ville Syrjäläa457f542016-03-02 17:22:17 +0200937
938 return ilk_get_aux_clock_divider(intel_dp, index);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300939}
940
Damien Lespiaub6b5e382014-01-20 16:00:59 +0000941static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
942{
943 /*
944 * SKL doesn't need us to program the AUX clock divider (Hardware will
945 * derive the clock from CDCLK automatically). We still implement the
946 * get_aux_clock_divider vfunc to plug-in into the existing code.
947 */
948 return index ? 0 : 1;
949}
950
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200951static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
952 bool has_aux_irq,
953 int send_bytes,
954 uint32_t aux_clock_divider)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000955{
956 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100957 struct drm_i915_private *dev_priv =
958 to_i915(intel_dig_port->base.base.dev);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000959 uint32_t precharge, timeout;
960
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100961 if (IS_GEN6(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000962 precharge = 3;
963 else
964 precharge = 5;
965
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100966 if (IS_BROADWELL(dev_priv) && intel_dig_port->port == PORT_A)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000967 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
968 else
969 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
970
971 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +0000972 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000973 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000974 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000975 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +0000976 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000977 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
978 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000979 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000980}
981
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000982static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
983 bool has_aux_irq,
984 int send_bytes,
985 uint32_t unused)
986{
987 return DP_AUX_CH_CTL_SEND_BUSY |
988 DP_AUX_CH_CTL_DONE |
989 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
990 DP_AUX_CH_CTL_TIME_OUT_ERROR |
991 DP_AUX_CH_CTL_TIME_OUT_1600us |
992 DP_AUX_CH_CTL_RECEIVE_ERROR |
993 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Daniel Vetterd4dcbdc2016-05-18 18:47:15 +0200994 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000995 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
996}
997
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700998static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100999intel_dp_aux_ch(struct intel_dp *intel_dp,
Daniel Vetterbd9f74a2014-10-02 09:45:35 +02001000 const uint8_t *send, int send_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001001 uint8_t *recv, int recv_size)
1002{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001003 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001004 struct drm_i915_private *dev_priv =
1005 to_i915(intel_dig_port->base.base.dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001006 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Chris Wilsonbc866252013-07-21 16:00:03 +01001007 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001008 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001009 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001010 int try, clock = 0;
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001011 bool has_aux_irq = HAS_AUX_IRQ(dev_priv);
Jani Nikula884f19e2014-03-14 16:51:14 +02001012 bool vdd;
1013
Ville Syrjälä773538e82014-09-04 14:54:56 +03001014 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001015
Ville Syrjälä72c35002014-08-18 22:16:00 +03001016 /*
1017 * We will be called with VDD already enabled for dpcd/edid/oui reads.
1018 * In such cases we want to leave VDD enabled and it's up to upper layers
1019 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
1020 * ourselves.
1021 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001022 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001023
1024 /* dp aux is extremely sensitive to irq latency, hence request the
1025 * lowest possible wakeup latency and so prevent the cpu from going into
1026 * deep sleep states.
1027 */
1028 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001029
Keith Packard9b984da2011-09-19 13:54:47 -07001030 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001031
Jesse Barnes11bee432011-08-01 15:02:20 -07001032 /* Try to wait for any previous AUX channel activity */
1033 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +01001034 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -07001035 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
1036 break;
1037 msleep(1);
1038 }
1039
1040 if (try == 3) {
Mika Kuoppala02196c72015-08-06 16:48:58 +03001041 static u32 last_status = -1;
1042 const u32 status = I915_READ(ch_ctl);
1043
1044 if (status != last_status) {
1045 WARN(1, "dp_aux_ch not started status 0x%08x\n",
1046 status);
1047 last_status = status;
1048 }
1049
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001050 ret = -EBUSY;
1051 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001052 }
1053
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001054 /* Only 5 data registers! */
1055 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
1056 ret = -E2BIG;
1057 goto out;
1058 }
1059
Damien Lespiauec5b01d2014-01-21 13:35:39 +00001060 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +00001061 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
1062 has_aux_irq,
1063 send_bytes,
1064 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001065
Chris Wilsonbc866252013-07-21 16:00:03 +01001066 /* Must try at least 3 times according to DP spec */
1067 for (try = 0; try < 5; try++) {
1068 /* Load the send data into the aux channel data registers */
1069 for (i = 0; i < send_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001070 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001071 intel_dp_pack_aux(send + i,
1072 send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -04001073
Chris Wilsonbc866252013-07-21 16:00:03 +01001074 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001075 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001076
Chris Wilsonbc866252013-07-21 16:00:03 +01001077 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -04001078
Chris Wilsonbc866252013-07-21 16:00:03 +01001079 /* Clear done status and any errors */
1080 I915_WRITE(ch_ctl,
1081 status |
1082 DP_AUX_CH_CTL_DONE |
1083 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1084 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -04001085
Todd Previte74ebf292015-04-15 08:38:41 -07001086 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
Chris Wilsonbc866252013-07-21 16:00:03 +01001087 continue;
Todd Previte74ebf292015-04-15 08:38:41 -07001088
1089 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
1090 * 400us delay required for errors and timeouts
1091 * Timeout errors from the HW already meet this
1092 * requirement so skip to next iteration
1093 */
1094 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1095 usleep_range(400, 500);
1096 continue;
1097 }
Chris Wilsonbc866252013-07-21 16:00:03 +01001098 if (status & DP_AUX_CH_CTL_DONE)
Jim Bridee058c942015-05-27 10:21:48 -07001099 goto done;
Chris Wilsonbc866252013-07-21 16:00:03 +01001100 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001101 }
1102
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001103 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001104 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001105 ret = -EBUSY;
1106 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001107 }
1108
Jim Bridee058c942015-05-27 10:21:48 -07001109done:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001110 /* Check for timeout or receive error.
1111 * Timeouts occur when the sink is not connected
1112 */
Keith Packarda5b3da52009-06-11 22:30:32 -07001113 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001114 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001115 ret = -EIO;
1116 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -07001117 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001118
1119 /* Timeouts occur when the device isn't connected, so they're
1120 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -07001121 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Zhao Yakui28c97732009-10-09 11:39:41 +08001122 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001123 ret = -ETIMEDOUT;
1124 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001125 }
1126
1127 /* Unload any bytes sent back from the other side */
1128 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
1129 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Rodrigo Vivi14e01882015-12-10 11:12:27 -08001130
1131 /*
1132 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1133 * We have no idea of what happened so we return -EBUSY so
1134 * drm layer takes care for the necessary retries.
1135 */
1136 if (recv_bytes == 0 || recv_bytes > 20) {
1137 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1138 recv_bytes);
1139 /*
1140 * FIXME: This patch was created on top of a series that
1141 * organize the retries at drm level. There EBUSY should
1142 * also take care for 1ms wait before retrying.
1143 * That aux retries re-org is still needed and after that is
1144 * merged we remove this sleep from here.
1145 */
1146 usleep_range(1000, 1500);
1147 ret = -EBUSY;
1148 goto out;
1149 }
1150
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001151 if (recv_bytes > recv_size)
1152 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -04001153
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001154 for (i = 0; i < recv_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001155 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001156 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001157
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001158 ret = recv_bytes;
1159out:
1160 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1161
Jani Nikula884f19e2014-03-14 16:51:14 +02001162 if (vdd)
1163 edp_panel_vdd_off(intel_dp, false);
1164
Ville Syrjälä773538e82014-09-04 14:54:56 +03001165 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001166
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001167 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001168}
1169
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001170#define BARE_ADDRESS_SIZE 3
1171#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +02001172static ssize_t
1173intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001174{
Jani Nikula9d1a1032014-03-14 16:51:15 +02001175 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1176 uint8_t txbuf[20], rxbuf[20];
1177 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001178 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001179
Ville Syrjäläd2d9cbb2015-03-19 11:44:06 +02001180 txbuf[0] = (msg->request << 4) |
1181 ((msg->address >> 16) & 0xf);
1182 txbuf[1] = (msg->address >> 8) & 0xff;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001183 txbuf[2] = msg->address & 0xff;
1184 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001185
Jani Nikula9d1a1032014-03-14 16:51:15 +02001186 switch (msg->request & ~DP_AUX_I2C_MOT) {
1187 case DP_AUX_NATIVE_WRITE:
1188 case DP_AUX_I2C_WRITE:
Ville Syrjäläc1e741222015-08-27 17:23:27 +03001189 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001190 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001191 rxsize = 2; /* 0 or 1 data bytes */
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001192
Jani Nikula9d1a1032014-03-14 16:51:15 +02001193 if (WARN_ON(txsize > 20))
1194 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001195
Ville Syrjälädd788092016-07-28 17:55:04 +03001196 WARN_ON(!msg->buffer != !msg->size);
1197
Imre Deakd81a67c2016-01-29 14:52:26 +02001198 if (msg->buffer)
1199 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001200
Jani Nikula9d1a1032014-03-14 16:51:15 +02001201 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1202 if (ret > 0) {
1203 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001204
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001205 if (ret > 1) {
1206 /* Number of bytes written in a short write. */
1207 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1208 } else {
1209 /* Return payload size. */
1210 ret = msg->size;
1211 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001212 }
Jani Nikula9d1a1032014-03-14 16:51:15 +02001213 break;
1214
1215 case DP_AUX_NATIVE_READ:
1216 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001217 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001218 rxsize = msg->size + 1;
1219
1220 if (WARN_ON(rxsize > 20))
1221 return -E2BIG;
1222
1223 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1224 if (ret > 0) {
1225 msg->reply = rxbuf[0] >> 4;
1226 /*
1227 * Assume happy day, and copy the data. The caller is
1228 * expected to check msg->reply before touching it.
1229 *
1230 * Return payload size.
1231 */
1232 ret--;
1233 memcpy(msg->buffer, rxbuf + 1, ret);
1234 }
1235 break;
1236
1237 default:
1238 ret = -EINVAL;
1239 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001240 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001241
Jani Nikula9d1a1032014-03-14 16:51:15 +02001242 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001243}
1244
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001245static enum port intel_aux_port(struct drm_i915_private *dev_priv,
1246 enum port port)
1247{
1248 const struct ddi_vbt_port_info *info =
1249 &dev_priv->vbt.ddi_port_info[port];
1250 enum port aux_port;
1251
1252 if (!info->alternate_aux_channel) {
1253 DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
1254 port_name(port), port_name(port));
1255 return port;
1256 }
1257
1258 switch (info->alternate_aux_channel) {
1259 case DP_AUX_A:
1260 aux_port = PORT_A;
1261 break;
1262 case DP_AUX_B:
1263 aux_port = PORT_B;
1264 break;
1265 case DP_AUX_C:
1266 aux_port = PORT_C;
1267 break;
1268 case DP_AUX_D:
1269 aux_port = PORT_D;
1270 break;
1271 default:
1272 MISSING_CASE(info->alternate_aux_channel);
1273 aux_port = PORT_A;
1274 break;
1275 }
1276
1277 DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
1278 port_name(aux_port), port_name(port));
1279
1280 return aux_port;
1281}
1282
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001283static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001284 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001285{
1286 switch (port) {
1287 case PORT_B:
1288 case PORT_C:
1289 case PORT_D:
1290 return DP_AUX_CH_CTL(port);
1291 default:
1292 MISSING_CASE(port);
1293 return DP_AUX_CH_CTL(PORT_B);
1294 }
1295}
1296
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001297static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001298 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001299{
1300 switch (port) {
1301 case PORT_B:
1302 case PORT_C:
1303 case PORT_D:
1304 return DP_AUX_CH_DATA(port, index);
1305 default:
1306 MISSING_CASE(port);
1307 return DP_AUX_CH_DATA(PORT_B, index);
1308 }
1309}
1310
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001311static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001312 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001313{
1314 switch (port) {
1315 case PORT_A:
1316 return DP_AUX_CH_CTL(port);
1317 case PORT_B:
1318 case PORT_C:
1319 case PORT_D:
1320 return PCH_DP_AUX_CH_CTL(port);
1321 default:
1322 MISSING_CASE(port);
1323 return DP_AUX_CH_CTL(PORT_A);
1324 }
1325}
1326
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001327static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001328 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001329{
1330 switch (port) {
1331 case PORT_A:
1332 return DP_AUX_CH_DATA(port, index);
1333 case PORT_B:
1334 case PORT_C:
1335 case PORT_D:
1336 return PCH_DP_AUX_CH_DATA(port, index);
1337 default:
1338 MISSING_CASE(port);
1339 return DP_AUX_CH_DATA(PORT_A, index);
1340 }
1341}
1342
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001343static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001344 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001345{
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001346 switch (port) {
1347 case PORT_A:
1348 case PORT_B:
1349 case PORT_C:
1350 case PORT_D:
1351 return DP_AUX_CH_CTL(port);
1352 default:
1353 MISSING_CASE(port);
1354 return DP_AUX_CH_CTL(PORT_A);
1355 }
1356}
1357
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001358static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001359 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001360{
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001361 switch (port) {
1362 case PORT_A:
1363 case PORT_B:
1364 case PORT_C:
1365 case PORT_D:
1366 return DP_AUX_CH_DATA(port, index);
1367 default:
1368 MISSING_CASE(port);
1369 return DP_AUX_CH_DATA(PORT_A, index);
1370 }
1371}
1372
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001373static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001374 enum port port)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001375{
1376 if (INTEL_INFO(dev_priv)->gen >= 9)
1377 return skl_aux_ctl_reg(dev_priv, port);
1378 else if (HAS_PCH_SPLIT(dev_priv))
1379 return ilk_aux_ctl_reg(dev_priv, port);
1380 else
1381 return g4x_aux_ctl_reg(dev_priv, port);
1382}
1383
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001384static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001385 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001386{
1387 if (INTEL_INFO(dev_priv)->gen >= 9)
1388 return skl_aux_data_reg(dev_priv, port, index);
1389 else if (HAS_PCH_SPLIT(dev_priv))
1390 return ilk_aux_data_reg(dev_priv, port, index);
1391 else
1392 return g4x_aux_data_reg(dev_priv, port, index);
1393}
1394
1395static void intel_aux_reg_init(struct intel_dp *intel_dp)
1396{
1397 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001398 enum port port = intel_aux_port(dev_priv,
1399 dp_to_dig_port(intel_dp)->port);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001400 int i;
1401
1402 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1403 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1404 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1405}
1406
Jani Nikula9d1a1032014-03-14 16:51:15 +02001407static void
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001408intel_dp_aux_fini(struct intel_dp *intel_dp)
1409{
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001410 kfree(intel_dp->aux.name);
1411}
1412
Chris Wilson7a418e32016-06-24 14:00:14 +01001413static void
Mika Kaholab6339582016-09-09 14:10:52 +03001414intel_dp_aux_init(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001415{
Jani Nikula33ad6622014-03-14 16:51:16 +02001416 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1417 enum port port = intel_dig_port->port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001418
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001419 intel_aux_reg_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01001420 drm_dp_aux_init(&intel_dp->aux);
David Flynn8316f332010-12-08 16:10:21 +00001421
Chris Wilson7a418e32016-06-24 14:00:14 +01001422 /* Failure to allocate our preferred name is not critical */
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001423 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
Jani Nikula9d1a1032014-03-14 16:51:15 +02001424 intel_dp->aux.transfer = intel_dp_aux_transfer;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001425}
1426
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001427bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301428{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001429 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Navare, Manasi D577c5432016-09-27 16:36:53 -07001430 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001431
Navare, Manasi D577c5432016-09-27 16:36:53 -07001432 if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
1433 IS_BROADWELL(dev_priv) || (INTEL_GEN(dev_priv) >= 9))
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301434 return true;
1435 else
1436 return false;
1437}
1438
Daniel Vetter0e503382014-07-04 11:26:04 -03001439static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001440intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001441 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001442{
1443 struct drm_device *dev = encoder->base.dev;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001444 struct drm_i915_private *dev_priv = to_i915(dev);
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001445 const struct dp_link_dpll *divisor = NULL;
1446 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001447
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001448 if (IS_G4X(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001449 divisor = gen4_dpll;
1450 count = ARRAY_SIZE(gen4_dpll);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001451 } else if (HAS_PCH_SPLIT(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001452 divisor = pch_dpll;
1453 count = ARRAY_SIZE(pch_dpll);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001454 } else if (IS_CHERRYVIEW(dev_priv)) {
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001455 divisor = chv_dpll;
1456 count = ARRAY_SIZE(chv_dpll);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001457 } else if (IS_VALLEYVIEW(dev_priv)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001458 divisor = vlv_dpll;
1459 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001460 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001461
1462 if (divisor && count) {
1463 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001464 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001465 pipe_config->dpll = divisor[i].dpll;
1466 pipe_config->clock_set = true;
1467 break;
1468 }
1469 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001470 }
1471}
1472
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001473static void snprintf_int_array(char *str, size_t len,
1474 const int *array, int nelem)
1475{
1476 int i;
1477
1478 str[0] = '\0';
1479
1480 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001481 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001482 if (r >= len)
1483 return;
1484 str += r;
1485 len -= r;
1486 }
1487}
1488
1489static void intel_dp_print_rates(struct intel_dp *intel_dp)
1490{
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001491 const int *source_rates, *sink_rates;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001492 int source_len, sink_len, common_len;
1493 int common_rates[DP_MAX_SUPPORTED_RATES];
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001494 char str[128]; /* FIXME: too big for stack? */
1495
1496 if ((drm_debug & DRM_UT_KMS) == 0)
1497 return;
1498
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001499 source_len = intel_dp_source_rates(intel_dp, &source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001500 snprintf_int_array(str, sizeof(str), source_rates, source_len);
1501 DRM_DEBUG_KMS("source rates: %s\n", str);
1502
1503 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
1504 snprintf_int_array(str, sizeof(str), sink_rates, sink_len);
1505 DRM_DEBUG_KMS("sink rates: %s\n", str);
1506
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001507 common_len = intel_dp_common_rates(intel_dp, common_rates);
1508 snprintf_int_array(str, sizeof(str), common_rates, common_len);
1509 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001510}
1511
Imre Deak489375c2016-10-24 19:33:31 +03001512bool
Imre Deak7b3fc172016-10-25 16:12:39 +03001513__intel_dp_read_desc(struct intel_dp *intel_dp, struct intel_dp_desc *desc)
Mika Kahola0e390a32016-09-09 14:10:53 +03001514{
Imre Deak7b3fc172016-10-25 16:12:39 +03001515 u32 base = drm_dp_is_branch(intel_dp->dpcd) ? DP_BRANCH_OUI :
1516 DP_SINK_OUI;
Mika Kahola0e390a32016-09-09 14:10:53 +03001517
Imre Deak7b3fc172016-10-25 16:12:39 +03001518 return drm_dp_dpcd_read(&intel_dp->aux, base, desc, sizeof(*desc)) ==
1519 sizeof(*desc);
Mika Kahola0e390a32016-09-09 14:10:53 +03001520}
1521
Imre Deak12a47a422016-10-24 19:33:29 +03001522bool intel_dp_read_desc(struct intel_dp *intel_dp)
Mika Kahola1a2724f2016-09-09 14:10:54 +03001523{
Imre Deak7b3fc172016-10-25 16:12:39 +03001524 struct intel_dp_desc *desc = &intel_dp->desc;
1525 bool oui_sup = intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] &
1526 DP_OUI_SUPPORT;
1527 int dev_id_len;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001528
Imre Deak7b3fc172016-10-25 16:12:39 +03001529 if (!__intel_dp_read_desc(intel_dp, desc))
1530 return false;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001531
Imre Deak7b3fc172016-10-25 16:12:39 +03001532 dev_id_len = strnlen(desc->device_id, sizeof(desc->device_id));
1533 DRM_DEBUG_KMS("DP %s: OUI %*phD%s dev-ID %*pE HW-rev %d.%d SW-rev %d.%d\n",
1534 drm_dp_is_branch(intel_dp->dpcd) ? "branch" : "sink",
1535 (int)sizeof(desc->oui), desc->oui, oui_sup ? "" : "(NS)",
1536 dev_id_len, desc->device_id,
1537 desc->hw_rev >> 4, desc->hw_rev & 0xf,
1538 desc->sw_major_rev, desc->sw_minor_rev);
Mika Kahola1a2724f2016-09-09 14:10:54 +03001539
Imre Deak7b3fc172016-10-25 16:12:39 +03001540 return true;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001541}
1542
Ville Syrjäläf4896f12015-03-12 17:10:27 +02001543static int rate_to_index(int find, const int *rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301544{
1545 int i = 0;
1546
1547 for (i = 0; i < DP_MAX_SUPPORTED_RATES; ++i)
1548 if (find == rates[i])
1549 break;
1550
1551 return i;
1552}
1553
Ville Syrjälä50fec212015-03-12 17:10:34 +02001554int
1555intel_dp_max_link_rate(struct intel_dp *intel_dp)
1556{
1557 int rates[DP_MAX_SUPPORTED_RATES] = {};
1558 int len;
1559
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001560 len = intel_dp_common_rates(intel_dp, rates);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001561 if (WARN_ON(len <= 0))
1562 return 162000;
1563
Ville Syrjälä1354f732016-07-28 17:50:45 +03001564 return rates[len - 1];
Ville Syrjälä50fec212015-03-12 17:10:34 +02001565}
1566
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001567int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1568{
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001569 return rate_to_index(rate, intel_dp->sink_rates);
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001570}
1571
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001572void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1573 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001574{
1575 if (intel_dp->num_sink_rates) {
1576 *link_bw = 0;
1577 *rate_select =
1578 intel_dp_rate_select(intel_dp, port_clock);
1579 } else {
1580 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1581 *rate_select = 0;
1582 }
1583}
1584
Jani Nikulaf580bea2016-09-15 16:28:52 +03001585static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1586 struct intel_crtc_state *pipe_config)
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001587{
1588 int bpp, bpc;
1589
1590 bpp = pipe_config->pipe_bpp;
1591 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1592
1593 if (bpc > 0)
1594 bpp = min(bpp, 3*bpc);
1595
1596 return bpp;
1597}
1598
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001599bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001600intel_dp_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001601 struct intel_crtc_state *pipe_config,
1602 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001603{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001604 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001605 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001606 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001607 enum port port = dp_to_dig_port(intel_dp)->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001608 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001609 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001610 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001611 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001612 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001613 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001614 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301615 int max_clock;
Daniel Vetter083f9562012-04-20 20:23:49 +02001616 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001617 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001618 int common_rates[DP_MAX_SUPPORTED_RATES] = {};
1619 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001620 uint8_t link_bw, rate_select;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301621
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001622 common_len = intel_dp_common_rates(intel_dp, common_rates);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301623
1624 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001625 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301626
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001627 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001628
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001629 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001630 pipe_config->has_pch_encoder = true;
1631
Vandana Kannanf769cd22014-08-05 07:51:22 -07001632 pipe_config->has_drrs = false;
Jani Nikula9fcb1702015-05-05 16:32:12 +03001633 pipe_config->has_audio = intel_dp->has_audio && port != PORT_A;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001634
Jani Nikuladd06f902012-10-19 14:51:50 +03001635 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1636 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
1637 adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001638
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001639 if (INTEL_GEN(dev_priv) >= 9) {
Chandra Kondurua1b22782015-04-07 15:28:45 -07001640 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001641 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001642 if (ret)
1643 return ret;
1644 }
1645
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001646 if (HAS_GMCH_DISPLAY(dev_priv))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001647 intel_gmch_panel_fitting(intel_crtc, pipe_config,
1648 intel_connector->panel.fitting_mode);
1649 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001650 intel_pch_panel_fitting(intel_crtc, pipe_config,
1651 intel_connector->panel.fitting_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001652 }
1653
Daniel Vettercb1793c2012-06-04 18:39:21 +02001654 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001655 return false;
1656
Daniel Vetter083f9562012-04-20 20:23:49 +02001657 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301658 "max bw %d pixel clock %iKHz\n",
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001659 max_lane_count, common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001660 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001661
Daniel Vetter36008362013-03-27 00:44:59 +01001662 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1663 * bpc in between. */
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001664 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
Jani Nikula56071a22014-05-06 14:56:52 +03001665 if (is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301666
1667 /* Get bpp from vbt only for panels that dont have bpp in edid */
1668 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001669 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001670 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001671 dev_priv->vbt.edp.bpp);
1672 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001673 }
1674
Jani Nikula344c5bb2014-09-09 11:25:13 +03001675 /*
1676 * Use the maximum clock and number of lanes the eDP panel
1677 * advertizes being capable of. The panels are generally
1678 * designed to support only a single clock and lane
1679 * configuration, and typically these values correspond to the
1680 * native resolution of the panel.
1681 */
1682 min_lane_count = max_lane_count;
1683 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001684 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001685
Daniel Vetter36008362013-03-27 00:44:59 +01001686 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001687 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1688 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001689
Dave Airliec6930992014-07-14 11:04:39 +10001690 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301691 for (lane_count = min_lane_count;
1692 lane_count <= max_lane_count;
1693 lane_count <<= 1) {
1694
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001695 link_clock = common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001696 link_avail = intel_dp_max_data_rate(link_clock,
1697 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001698
Daniel Vetter36008362013-03-27 00:44:59 +01001699 if (mode_rate <= link_avail) {
1700 goto found;
1701 }
1702 }
1703 }
1704 }
1705
1706 return false;
1707
1708found:
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001709 if (intel_dp->color_range_auto) {
1710 /*
1711 * See:
1712 * CEA-861-E - 5.1 Default Encoding Parameters
1713 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1714 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001715 pipe_config->limited_color_range =
1716 bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1;
1717 } else {
1718 pipe_config->limited_color_range =
1719 intel_dp->limited_color_range;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001720 }
1721
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001722 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301723
Daniel Vetter657445f2013-05-04 10:09:18 +02001724 pipe_config->pipe_bpp = bpp;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001725 pipe_config->port_clock = common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001726
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001727 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1728 &link_bw, &rate_select);
1729
1730 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1731 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001732 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001733 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1734 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001735
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001736 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001737 adjusted_mode->crtc_clock,
1738 pipe_config->port_clock,
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001739 &pipe_config->dp_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001740
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301741 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301742 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001743 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301744 intel_link_compute_m_n(bpp, lane_count,
1745 intel_connector->panel.downclock_mode->clock,
1746 pipe_config->port_clock,
1747 &pipe_config->dp_m2_n2);
1748 }
1749
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001750 /*
1751 * DPLL0 VCO may need to be adjusted to get the correct
1752 * clock for eDP. This will affect cdclk as well.
1753 */
1754 if (is_edp(intel_dp) &&
1755 (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))) {
1756 int vco;
1757
1758 switch (pipe_config->port_clock / 2) {
1759 case 108000:
1760 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001761 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001762 break;
1763 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001764 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001765 break;
1766 }
1767
1768 to_intel_atomic_state(pipe_config->base.state)->cdclk_pll_vco = vco;
1769 }
1770
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001771 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001772 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001773
Daniel Vetter36008362013-03-27 00:44:59 +01001774 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001775}
1776
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001777void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001778 int link_rate, uint8_t lane_count,
1779 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001780{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001781 intel_dp->link_rate = link_rate;
1782 intel_dp->lane_count = lane_count;
1783 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001784}
1785
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001786static void intel_dp_prepare(struct intel_encoder *encoder,
1787 struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001788{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001789 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001790 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001791 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001792 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001793 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001794 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001795
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001796 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1797 pipe_config->lane_count,
1798 intel_crtc_has_type(pipe_config,
1799 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001800
Keith Packard417e8222011-11-01 19:54:11 -07001801 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001802 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001803 *
1804 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001805 * SNB CPU
1806 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001807 * CPT PCH
1808 *
1809 * IBX PCH and CPU are the same for almost everything,
1810 * except that the CPU DP PLL is configured in this
1811 * register
1812 *
1813 * CPT PCH is quite different, having many bits moved
1814 * to the TRANS_DP_CTL register instead. That
1815 * configuration happens (oddly) in ironlake_pch_enable
1816 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001817
Keith Packard417e8222011-11-01 19:54:11 -07001818 /* Preserve the BIOS-computed detected bit. This is
1819 * supposed to be read-only.
1820 */
1821 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001822
Keith Packard417e8222011-11-01 19:54:11 -07001823 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001824 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001825 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001826
Keith Packard417e8222011-11-01 19:54:11 -07001827 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001828
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001829 if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001830 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1831 intel_dp->DP |= DP_SYNC_HS_HIGH;
1832 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1833 intel_dp->DP |= DP_SYNC_VS_HIGH;
1834 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1835
Jani Nikula6aba5b62013-10-04 15:08:10 +03001836 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001837 intel_dp->DP |= DP_ENHANCED_FRAMING;
1838
Daniel Vetter7c62a162013-06-01 17:16:20 +02001839 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001840 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001841 u32 trans_dp;
1842
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001843 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001844
1845 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1846 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1847 trans_dp |= TRANS_DP_ENH_FRAMING;
1848 else
1849 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1850 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001851 } else {
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02001852 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001853 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001854
1855 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1856 intel_dp->DP |= DP_SYNC_HS_HIGH;
1857 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1858 intel_dp->DP |= DP_SYNC_VS_HIGH;
1859 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1860
Jani Nikula6aba5b62013-10-04 15:08:10 +03001861 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001862 intel_dp->DP |= DP_ENHANCED_FRAMING;
1863
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001864 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001865 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001866 else if (crtc->pipe == PIPE_B)
1867 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001868 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001869}
1870
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001871#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1872#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001873
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001874#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1875#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001876
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001877#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1878#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001879
Imre Deakde9c1b62016-06-16 20:01:46 +03001880static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
1881 struct intel_dp *intel_dp);
1882
Daniel Vetter4be73782014-01-17 14:39:48 +01001883static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001884 u32 mask,
1885 u32 value)
1886{
Paulo Zanoni30add222012-10-26 19:05:45 -02001887 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001888 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001889 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001890
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001891 lockdep_assert_held(&dev_priv->pps_mutex);
1892
Imre Deakde9c1b62016-06-16 20:01:46 +03001893 intel_pps_verify_state(dev_priv, intel_dp);
1894
Jani Nikulabf13e812013-09-06 07:40:05 +03001895 pp_stat_reg = _pp_stat_reg(intel_dp);
1896 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001897
1898 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001899 mask, value,
1900 I915_READ(pp_stat_reg),
1901 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001902
Chris Wilson9036ff02016-06-30 15:33:09 +01001903 if (intel_wait_for_register(dev_priv,
1904 pp_stat_reg, mask, value,
1905 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001906 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001907 I915_READ(pp_stat_reg),
1908 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001909
1910 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001911}
1912
Daniel Vetter4be73782014-01-17 14:39:48 +01001913static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001914{
1915 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001916 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001917}
1918
Daniel Vetter4be73782014-01-17 14:39:48 +01001919static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001920{
Keith Packardbd943152011-09-18 23:09:52 -07001921 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001922 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001923}
Keith Packardbd943152011-09-18 23:09:52 -07001924
Daniel Vetter4be73782014-01-17 14:39:48 +01001925static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001926{
Abhay Kumard28d4732016-01-22 17:39:04 -08001927 ktime_t panel_power_on_time;
1928 s64 panel_power_off_duration;
1929
Keith Packard99ea7122011-11-01 19:57:50 -07001930 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001931
Abhay Kumard28d4732016-01-22 17:39:04 -08001932 /* take the difference of currrent time and panel power off time
1933 * and then make panel wait for t11_t12 if needed. */
1934 panel_power_on_time = ktime_get_boottime();
1935 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1936
Paulo Zanonidce56b32013-12-19 14:29:40 -02001937 /* When we disable the VDD override bit last we have to do the manual
1938 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08001939 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
1940 wait_remaining_ms_from_jiffies(jiffies,
1941 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001942
Daniel Vetter4be73782014-01-17 14:39:48 +01001943 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001944}
Keith Packardbd943152011-09-18 23:09:52 -07001945
Daniel Vetter4be73782014-01-17 14:39:48 +01001946static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001947{
1948 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1949 intel_dp->backlight_on_delay);
1950}
1951
Daniel Vetter4be73782014-01-17 14:39:48 +01001952static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001953{
1954 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
1955 intel_dp->backlight_off_delay);
1956}
Keith Packard99ea7122011-11-01 19:57:50 -07001957
Keith Packard832dd3c2011-11-01 19:34:06 -07001958/* Read the current pp_control value, unlocking the register if it
1959 * is locked
1960 */
1961
Jesse Barnes453c5422013-03-28 09:55:41 -07001962static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07001963{
Jesse Barnes453c5422013-03-28 09:55:41 -07001964 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001965 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07001966 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07001967
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001968 lockdep_assert_held(&dev_priv->pps_mutex);
1969
Jani Nikulabf13e812013-09-06 07:40:05 +03001970 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03001971 if (WARN_ON(!HAS_DDI(dev_priv) &&
1972 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05301973 control &= ~PANEL_UNLOCK_MASK;
1974 control |= PANEL_UNLOCK_REGS;
1975 }
Keith Packard832dd3c2011-11-01 19:34:06 -07001976 return control;
Keith Packardbd943152011-09-18 23:09:52 -07001977}
1978
Ville Syrjälä951468f2014-09-04 14:55:31 +03001979/*
1980 * Must be paired with edp_panel_vdd_off().
1981 * Must hold pps_mutex around the whole on/off sequence.
1982 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
1983 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001984static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001985{
Paulo Zanoni30add222012-10-26 19:05:45 -02001986 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001987 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1988 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001989 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001990 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08001991 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001992 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001993 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08001994
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001995 lockdep_assert_held(&dev_priv->pps_mutex);
1996
Keith Packard97af61f572011-09-28 16:23:51 -07001997 if (!is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001998 return false;
Keith Packardbd943152011-09-18 23:09:52 -07001999
Egbert Eich2c623c12014-11-25 12:54:57 +01002000 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002001 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07002002
Daniel Vetter4be73782014-01-17 14:39:48 +01002003 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002004 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002005
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002006 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002007 intel_display_power_get(dev_priv, power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002008
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002009 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
2010 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07002011
Daniel Vetter4be73782014-01-17 14:39:48 +01002012 if (!edp_have_panel_power(intel_dp))
2013 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07002014
Jesse Barnes453c5422013-03-28 09:55:41 -07002015 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002016 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07002017
Jani Nikulabf13e812013-09-06 07:40:05 +03002018 pp_stat_reg = _pp_stat_reg(intel_dp);
2019 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002020
2021 I915_WRITE(pp_ctrl_reg, pp);
2022 POSTING_READ(pp_ctrl_reg);
2023 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2024 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07002025 /*
2026 * If the panel wasn't on, delay before accessing aux channel
2027 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002028 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002029 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
2030 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07002031 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07002032 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002033
2034 return need_to_disable;
2035}
2036
Ville Syrjälä951468f2014-09-04 14:55:31 +03002037/*
2038 * Must be paired with intel_edp_panel_vdd_off() or
2039 * intel_edp_panel_off().
2040 * Nested calls to these functions are not allowed since
2041 * we drop the lock. Caller must use some higher level
2042 * locking to prevent nested calls from other threads.
2043 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01002044void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002045{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002046 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002047
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002048 if (!is_edp(intel_dp))
2049 return;
2050
Ville Syrjälä773538e82014-09-04 14:54:56 +03002051 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002052 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002053 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002054
Rob Clarke2c719b2014-12-15 13:56:32 -05002055 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002056 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08002057}
2058
Daniel Vetter4be73782014-01-17 14:39:48 +01002059static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002060{
Paulo Zanoni30add222012-10-26 19:05:45 -02002061 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002062 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002063 struct intel_digital_port *intel_dig_port =
2064 dp_to_dig_port(intel_dp);
2065 struct intel_encoder *intel_encoder = &intel_dig_port->base;
2066 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08002067 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002068 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002069
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002070 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002071
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002072 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002073
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002074 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002075 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002076
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002077 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2078 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002079
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002080 pp = ironlake_get_pp_control(intel_dp);
2081 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002082
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002083 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2084 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002085
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002086 I915_WRITE(pp_ctrl_reg, pp);
2087 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002088
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002089 /* Make sure sequencer is idle before allowing subsequent activity */
2090 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2091 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002092
Imre Deak5a162e22016-08-10 14:07:30 +03002093 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002094 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002095
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002096 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002097 intel_display_power_put(dev_priv, power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002098}
2099
Daniel Vetter4be73782014-01-17 14:39:48 +01002100static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002101{
2102 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2103 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002104
Ville Syrjälä773538e82014-09-04 14:54:56 +03002105 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002106 if (!intel_dp->want_panel_vdd)
2107 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002108 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002109}
2110
Imre Deakaba86892014-07-30 15:57:31 +03002111static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2112{
2113 unsigned long delay;
2114
2115 /*
2116 * Queue the timer to fire a long time from now (relative to the power
2117 * down delay) to keep the panel power up across a sequence of
2118 * operations.
2119 */
2120 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2121 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2122}
2123
Ville Syrjälä951468f2014-09-04 14:55:31 +03002124/*
2125 * Must be paired with edp_panel_vdd_on().
2126 * Must hold pps_mutex around the whole on/off sequence.
2127 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2128 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002129static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002130{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002131 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002132
2133 lockdep_assert_held(&dev_priv->pps_mutex);
2134
Keith Packard97af61f572011-09-28 16:23:51 -07002135 if (!is_edp(intel_dp))
2136 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002137
Rob Clarke2c719b2014-12-15 13:56:32 -05002138 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002139 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002140
Keith Packardbd943152011-09-18 23:09:52 -07002141 intel_dp->want_panel_vdd = false;
2142
Imre Deakaba86892014-07-30 15:57:31 +03002143 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002144 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002145 else
2146 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002147}
2148
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002149static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002150{
Paulo Zanoni30add222012-10-26 19:05:45 -02002151 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002152 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002153 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002154 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002155
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002156 lockdep_assert_held(&dev_priv->pps_mutex);
2157
Keith Packard97af61f572011-09-28 16:23:51 -07002158 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002159 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002160
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002161 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2162 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002163
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002164 if (WARN(edp_have_panel_power(intel_dp),
2165 "eDP port %c panel power already on\n",
2166 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002167 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002168
Daniel Vetter4be73782014-01-17 14:39:48 +01002169 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002170
Jani Nikulabf13e812013-09-06 07:40:05 +03002171 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002172 pp = ironlake_get_pp_control(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002173 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002174 /* ILK workaround: disable reset around power sequence */
2175 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002176 I915_WRITE(pp_ctrl_reg, pp);
2177 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002178 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002179
Imre Deak5a162e22016-08-10 14:07:30 +03002180 pp |= PANEL_POWER_ON;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002181 if (!IS_GEN5(dev_priv))
Keith Packard99ea7122011-11-01 19:57:50 -07002182 pp |= PANEL_POWER_RESET;
2183
Jesse Barnes453c5422013-03-28 09:55:41 -07002184 I915_WRITE(pp_ctrl_reg, pp);
2185 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002186
Daniel Vetter4be73782014-01-17 14:39:48 +01002187 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002188 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002189
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002190 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002191 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002192 I915_WRITE(pp_ctrl_reg, pp);
2193 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002194 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002195}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002196
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002197void intel_edp_panel_on(struct intel_dp *intel_dp)
2198{
2199 if (!is_edp(intel_dp))
2200 return;
2201
2202 pps_lock(intel_dp);
2203 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002204 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002205}
2206
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002207
2208static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002209{
Imre Deak4e6e1a52014-03-27 17:45:11 +02002210 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2211 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanoni30add222012-10-26 19:05:45 -02002212 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002213 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002214 enum intel_display_power_domain power_domain;
Keith Packard99ea7122011-11-01 19:57:50 -07002215 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002216 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002217
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002218 lockdep_assert_held(&dev_priv->pps_mutex);
2219
Keith Packard97af61f572011-09-28 16:23:51 -07002220 if (!is_edp(intel_dp))
2221 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002222
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002223 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2224 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002225
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002226 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2227 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002228
Jesse Barnes453c5422013-03-28 09:55:41 -07002229 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002230 /* We need to switch off panel power _and_ force vdd, for otherwise some
2231 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002232 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002233 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002234
Jani Nikulabf13e812013-09-06 07:40:05 +03002235 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002236
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002237 intel_dp->want_panel_vdd = false;
2238
Jesse Barnes453c5422013-03-28 09:55:41 -07002239 I915_WRITE(pp_ctrl_reg, pp);
2240 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002241
Abhay Kumard28d4732016-01-22 17:39:04 -08002242 intel_dp->panel_power_off_time = ktime_get_boottime();
Daniel Vetter4be73782014-01-17 14:39:48 +01002243 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002244
2245 /* We got a reference when we enabled the VDD. */
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002246 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002247 intel_display_power_put(dev_priv, power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002248}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002249
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002250void intel_edp_panel_off(struct intel_dp *intel_dp)
2251{
2252 if (!is_edp(intel_dp))
2253 return;
2254
2255 pps_lock(intel_dp);
2256 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002257 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002258}
2259
Jani Nikula1250d102014-08-12 17:11:39 +03002260/* Enable backlight in the panel power control. */
2261static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002262{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002263 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2264 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002265 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002266 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002267 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002268
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002269 /*
2270 * If we enable the backlight right away following a panel power
2271 * on, we may see slight flicker as the panel syncs with the eDP
2272 * link. So delay a bit to make sure the image is solid before
2273 * allowing it to appear.
2274 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002275 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002276
Ville Syrjälä773538e82014-09-04 14:54:56 +03002277 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002278
Jesse Barnes453c5422013-03-28 09:55:41 -07002279 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002280 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002281
Jani Nikulabf13e812013-09-06 07:40:05 +03002282 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002283
2284 I915_WRITE(pp_ctrl_reg, pp);
2285 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002286
Ville Syrjälä773538e82014-09-04 14:54:56 +03002287 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002288}
2289
Jani Nikula1250d102014-08-12 17:11:39 +03002290/* Enable backlight PWM and backlight PP control. */
2291void intel_edp_backlight_on(struct intel_dp *intel_dp)
2292{
2293 if (!is_edp(intel_dp))
2294 return;
2295
2296 DRM_DEBUG_KMS("\n");
2297
2298 intel_panel_enable_backlight(intel_dp->attached_connector);
2299 _intel_edp_backlight_on(intel_dp);
2300}
2301
2302/* Disable backlight in the panel power control. */
2303static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002304{
Paulo Zanoni30add222012-10-26 19:05:45 -02002305 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002306 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002307 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002308 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002309
Keith Packardf01eca22011-09-28 16:48:10 -07002310 if (!is_edp(intel_dp))
2311 return;
2312
Ville Syrjälä773538e82014-09-04 14:54:56 +03002313 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002314
Jesse Barnes453c5422013-03-28 09:55:41 -07002315 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002316 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002317
Jani Nikulabf13e812013-09-06 07:40:05 +03002318 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002319
2320 I915_WRITE(pp_ctrl_reg, pp);
2321 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002322
Ville Syrjälä773538e82014-09-04 14:54:56 +03002323 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002324
Paulo Zanonidce56b32013-12-19 14:29:40 -02002325 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002326 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002327}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002328
Jani Nikula1250d102014-08-12 17:11:39 +03002329/* Disable backlight PP control and backlight PWM. */
2330void intel_edp_backlight_off(struct intel_dp *intel_dp)
2331{
2332 if (!is_edp(intel_dp))
2333 return;
2334
2335 DRM_DEBUG_KMS("\n");
2336
2337 _intel_edp_backlight_off(intel_dp);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002338 intel_panel_disable_backlight(intel_dp->attached_connector);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002339}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002340
Jani Nikula73580fb72014-08-12 17:11:41 +03002341/*
2342 * Hook for controlling the panel power control backlight through the bl_power
2343 * sysfs attribute. Take care to handle multiple calls.
2344 */
2345static void intel_edp_backlight_power(struct intel_connector *connector,
2346 bool enable)
2347{
2348 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002349 bool is_enabled;
2350
Ville Syrjälä773538e82014-09-04 14:54:56 +03002351 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002352 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002353 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002354
2355 if (is_enabled == enable)
2356 return;
2357
Jani Nikula23ba9372014-08-27 14:08:43 +03002358 DRM_DEBUG_KMS("panel power control backlight %s\n",
2359 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002360
2361 if (enable)
2362 _intel_edp_backlight_on(intel_dp);
2363 else
2364 _intel_edp_backlight_off(intel_dp);
2365}
2366
Ville Syrjälä64e10772015-10-29 21:26:01 +02002367static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2368{
2369 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2370 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2371 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2372
2373 I915_STATE_WARN(cur_state != state,
2374 "DP port %c state assertion failure (expected %s, current %s)\n",
2375 port_name(dig_port->port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002376 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002377}
2378#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2379
2380static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2381{
2382 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2383
2384 I915_STATE_WARN(cur_state != state,
2385 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002386 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002387}
2388#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2389#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2390
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002391static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2392 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002393{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002394 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002395 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002396
Ville Syrjälä64e10772015-10-29 21:26:01 +02002397 assert_pipe_disabled(dev_priv, crtc->pipe);
2398 assert_dp_port_disabled(intel_dp);
2399 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002400
Ville Syrjäläabfce942015-10-29 21:26:03 +02002401 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002402 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002403
2404 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2405
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002406 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002407 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2408 else
2409 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2410
2411 I915_WRITE(DP_A, intel_dp->DP);
2412 POSTING_READ(DP_A);
2413 udelay(500);
2414
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002415 /*
2416 * [DevILK] Work around required when enabling DP PLL
2417 * while a pipe is enabled going to FDI:
2418 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2419 * 2. Program DP PLL enable
2420 */
2421 if (IS_GEN5(dev_priv))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02002422 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002423
Daniel Vetter07679352012-09-06 22:15:42 +02002424 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002425
Daniel Vetter07679352012-09-06 22:15:42 +02002426 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002427 POSTING_READ(DP_A);
2428 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002429}
2430
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002431static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002432{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002433 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002434 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2435 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002436
Ville Syrjälä64e10772015-10-29 21:26:01 +02002437 assert_pipe_disabled(dev_priv, crtc->pipe);
2438 assert_dp_port_disabled(intel_dp);
2439 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002440
Ville Syrjäläabfce942015-10-29 21:26:03 +02002441 DRM_DEBUG_KMS("disabling eDP PLL\n");
2442
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002443 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002444
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002445 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002446 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002447 udelay(200);
2448}
2449
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002450/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002451void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002452{
2453 int ret, i;
2454
2455 /* Should have a valid DPCD by this point */
2456 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2457 return;
2458
2459 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002460 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2461 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002462 } else {
Imre Deak357c0ae2016-11-21 21:15:06 +02002463 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
2464
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002465 /*
2466 * When turning on, we need to retry for 1ms to give the sink
2467 * time to wake up.
2468 */
2469 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002470 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2471 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002472 if (ret == 1)
2473 break;
2474 msleep(1);
2475 }
Imre Deak357c0ae2016-11-21 21:15:06 +02002476
2477 if (ret == 1 && lspcon->active)
2478 lspcon_wait_pcon_mode(lspcon);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002479 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002480
2481 if (ret != 1)
2482 DRM_DEBUG_KMS("failed to %s sink power state\n",
2483 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002484}
2485
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002486static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2487 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002488{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002489 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002490 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002491 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002492 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002493 enum intel_display_power_domain power_domain;
2494 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002495 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002496
2497 power_domain = intel_display_port_power_domain(encoder);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002498 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002499 return false;
2500
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002501 ret = false;
2502
Imre Deak6d129be2014-03-05 16:20:54 +02002503 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002504
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002505 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002506 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002507
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002508 if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002509 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002510 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002511 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002512
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002513 for_each_pipe(dev_priv, p) {
2514 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2515 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2516 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002517 ret = true;
2518
2519 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002520 }
2521 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002522
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002523 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002524 i915_mmio_reg_offset(intel_dp->output_reg));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002525 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002526 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2527 } else {
2528 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002529 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002530
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002531 ret = true;
2532
2533out:
2534 intel_display_power_put(dev_priv, power_domain);
2535
2536 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002537}
2538
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002539static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002540 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002541{
2542 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002543 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002544 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002545 struct drm_i915_private *dev_priv = to_i915(dev);
Xiong Zhang63000ef2013-06-28 12:59:06 +08002546 enum port port = dp_to_dig_port(intel_dp)->port;
2547 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002548
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002549 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002550
2551 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002552
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002553 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002554 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2555
2556 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002557 flags |= DRM_MODE_FLAG_PHSYNC;
2558 else
2559 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002560
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002561 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002562 flags |= DRM_MODE_FLAG_PVSYNC;
2563 else
2564 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002565 } else {
2566 if (tmp & DP_SYNC_HS_HIGH)
2567 flags |= DRM_MODE_FLAG_PHSYNC;
2568 else
2569 flags |= DRM_MODE_FLAG_NHSYNC;
2570
2571 if (tmp & DP_SYNC_VS_HIGH)
2572 flags |= DRM_MODE_FLAG_PVSYNC;
2573 else
2574 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002575 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002576
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002577 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002578
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02002579 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002580 pipe_config->limited_color_range = true;
2581
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002582 pipe_config->lane_count =
2583 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2584
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002585 intel_dp_get_m_n(crtc, pipe_config);
2586
Ville Syrjälä18442d02013-09-13 16:00:08 +03002587 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002588 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002589 pipe_config->port_clock = 162000;
2590 else
2591 pipe_config->port_clock = 270000;
2592 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002593
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002594 pipe_config->base.adjusted_mode.crtc_clock =
2595 intel_dotclock_calculate(pipe_config->port_clock,
2596 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002597
Jani Nikula6aa23e62016-03-24 17:50:20 +02002598 if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
2599 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002600 /*
2601 * This is a big fat ugly hack.
2602 *
2603 * Some machines in UEFI boot mode provide us a VBT that has 18
2604 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2605 * unknown we fail to light up. Yet the same BIOS boots up with
2606 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2607 * max, not what it tells us to use.
2608 *
2609 * Note: This will still be broken if the eDP panel is not lit
2610 * up by the BIOS, and thus we can't get the mode at module
2611 * load.
2612 */
2613 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002614 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2615 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002616 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002617}
2618
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002619static void intel_disable_dp(struct intel_encoder *encoder,
2620 struct intel_crtc_state *old_crtc_state,
2621 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002622{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002623 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002624 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002625
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002626 if (old_crtc_state->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002627 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002628
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002629 if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv))
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002630 intel_psr_disable(intel_dp);
2631
Daniel Vetter6cb49832012-05-20 17:14:50 +02002632 /* Make sure the panel is off before trying to change the mode. But also
2633 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002634 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01002635 intel_edp_backlight_off(intel_dp);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002636 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002637 intel_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02002638
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002639 /* disable the port before the pipe on g4x */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002640 if (INTEL_GEN(dev_priv) < 5)
Daniel Vetter37398502012-09-06 22:15:44 +02002641 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07002642}
2643
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002644static void ilk_post_disable_dp(struct intel_encoder *encoder,
2645 struct intel_crtc_state *old_crtc_state,
2646 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002647{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002648 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002649 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002650
Ville Syrjälä49277c32014-03-31 18:21:26 +03002651 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002652
2653 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002654 if (port == PORT_A)
2655 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002656}
2657
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002658static void vlv_post_disable_dp(struct intel_encoder *encoder,
2659 struct intel_crtc_state *old_crtc_state,
2660 struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002661{
2662 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2663
2664 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002665}
2666
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002667static void chv_post_disable_dp(struct intel_encoder *encoder,
2668 struct intel_crtc_state *old_crtc_state,
2669 struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002670{
2671 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002672 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002673 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002674
2675 intel_dp_link_down(intel_dp);
2676
Ville Syrjäläa5805162015-05-26 20:42:30 +03002677 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002678
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002679 /* Assert data lane reset */
2680 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002681
Ville Syrjäläa5805162015-05-26 20:42:30 +03002682 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002683}
2684
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002685static void
2686_intel_dp_set_link_train(struct intel_dp *intel_dp,
2687 uint32_t *DP,
2688 uint8_t dp_train_pat)
2689{
2690 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2691 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002692 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002693 enum port port = intel_dig_port->port;
2694
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002695 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2696 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2697 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2698
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002699 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002700 uint32_t temp = I915_READ(DP_TP_CTL(port));
2701
2702 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2703 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2704 else
2705 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2706
2707 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2708 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2709 case DP_TRAINING_PATTERN_DISABLE:
2710 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2711
2712 break;
2713 case DP_TRAINING_PATTERN_1:
2714 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2715 break;
2716 case DP_TRAINING_PATTERN_2:
2717 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2718 break;
2719 case DP_TRAINING_PATTERN_3:
2720 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2721 break;
2722 }
2723 I915_WRITE(DP_TP_CTL(port), temp);
2724
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002725 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002726 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002727 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2728
2729 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2730 case DP_TRAINING_PATTERN_DISABLE:
2731 *DP |= DP_LINK_TRAIN_OFF_CPT;
2732 break;
2733 case DP_TRAINING_PATTERN_1:
2734 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2735 break;
2736 case DP_TRAINING_PATTERN_2:
2737 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2738 break;
2739 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002740 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002741 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2742 break;
2743 }
2744
2745 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002746 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002747 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2748 else
2749 *DP &= ~DP_LINK_TRAIN_MASK;
2750
2751 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2752 case DP_TRAINING_PATTERN_DISABLE:
2753 *DP |= DP_LINK_TRAIN_OFF;
2754 break;
2755 case DP_TRAINING_PATTERN_1:
2756 *DP |= DP_LINK_TRAIN_PAT_1;
2757 break;
2758 case DP_TRAINING_PATTERN_2:
2759 *DP |= DP_LINK_TRAIN_PAT_2;
2760 break;
2761 case DP_TRAINING_PATTERN_3:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002762 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002763 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2764 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002765 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002766 *DP |= DP_LINK_TRAIN_PAT_2;
2767 }
2768 break;
2769 }
2770 }
2771}
2772
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002773static void intel_dp_enable_port(struct intel_dp *intel_dp,
2774 struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002775{
2776 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002777 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002778
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002779 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002780
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002781 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002782
2783 /*
2784 * Magic for VLV/CHV. We _must_ first set up the register
2785 * without actually enabling the port, and then do another
2786 * write to enable the port. Otherwise link training will
2787 * fail when the power sequencer is freshly used for this port.
2788 */
2789 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002790 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002791 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002792
2793 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2794 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002795}
2796
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002797static void intel_enable_dp(struct intel_encoder *encoder,
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002798 struct intel_crtc_state *pipe_config,
2799 struct drm_connector_state *conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002800{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002801 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2802 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002803 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulac1dec792014-10-27 16:26:56 +02002804 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002805 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002806 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002807
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002808 if (WARN_ON(dp_reg & DP_PORT_EN))
2809 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002810
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002811 pps_lock(intel_dp);
2812
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002813 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002814 vlv_init_panel_power_sequencer(intel_dp);
2815
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002816 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002817
2818 edp_panel_vdd_on(intel_dp);
2819 edp_panel_on(intel_dp);
2820 edp_panel_vdd_off(intel_dp, true);
2821
2822 pps_unlock(intel_dp);
2823
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002824 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002825 unsigned int lane_mask = 0x0;
2826
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002827 if (IS_CHERRYVIEW(dev_priv))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002828 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002829
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002830 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2831 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002832 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002833
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002834 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2835 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002836 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002837
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002838 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002839 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002840 pipe_name(pipe));
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002841 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Jani Nikulac1dec792014-10-27 16:26:56 +02002842 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002843}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002844
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002845static void g4x_enable_dp(struct intel_encoder *encoder,
2846 struct intel_crtc_state *pipe_config,
2847 struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03002848{
Jani Nikula828f5c62013-09-05 16:44:45 +03002849 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2850
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002851 intel_enable_dp(encoder, pipe_config, conn_state);
Daniel Vetter4be73782014-01-17 14:39:48 +01002852 intel_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002853}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002854
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002855static void vlv_enable_dp(struct intel_encoder *encoder,
2856 struct intel_crtc_state *pipe_config,
2857 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002858{
Jani Nikula828f5c62013-09-05 16:44:45 +03002859 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2860
Daniel Vetter4be73782014-01-17 14:39:48 +01002861 intel_edp_backlight_on(intel_dp);
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002862 intel_psr_enable(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002863}
2864
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002865static void g4x_pre_enable_dp(struct intel_encoder *encoder,
2866 struct intel_crtc_state *pipe_config,
2867 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002868{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002869 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002870 enum port port = dp_to_dig_port(intel_dp)->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002871
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002872 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002873
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002874 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002875 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002876 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002877}
2878
Ville Syrjälä83b84592014-10-16 21:29:51 +03002879static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2880{
2881 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002882 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002883 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03002884 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002885
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002886 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
2887
Ville Syrjälä83b84592014-10-16 21:29:51 +03002888 edp_panel_vdd_off_sync(intel_dp);
2889
2890 /*
2891 * VLV seems to get confused when multiple power seqeuencers
2892 * have the same port selected (even if only one has power/vdd
2893 * enabled). The failure manifests as vlv_wait_port_ready() failing
2894 * CHV on the other hand doesn't seem to mind having the same port
2895 * selected in multiple power seqeuencers, but let's clear the
2896 * port select always when logically disconnecting a power sequencer
2897 * from a port.
2898 */
2899 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2900 pipe_name(pipe), port_name(intel_dig_port->port));
2901 I915_WRITE(pp_on_reg, 0);
2902 POSTING_READ(pp_on_reg);
2903
2904 intel_dp->pps_pipe = INVALID_PIPE;
2905}
2906
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002907static void vlv_steal_power_sequencer(struct drm_device *dev,
2908 enum pipe pipe)
2909{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002910 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002911 struct intel_encoder *encoder;
2912
2913 lockdep_assert_held(&dev_priv->pps_mutex);
2914
Ville Syrjäläac3c12e2014-10-16 21:29:56 +03002915 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2916 return;
2917
Jani Nikula19c80542015-12-16 12:48:16 +02002918 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002919 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002920 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002921
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002922 if (encoder->type != INTEL_OUTPUT_DP &&
2923 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002924 continue;
2925
2926 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002927 port = dp_to_dig_port(intel_dp)->port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002928
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002929 WARN(intel_dp->active_pipe == pipe,
2930 "stealing pipe %c power sequencer from active (e)DP port %c\n",
2931 pipe_name(pipe), port_name(port));
2932
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002933 if (intel_dp->pps_pipe != pipe)
2934 continue;
2935
2936 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03002937 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002938
2939 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002940 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002941 }
2942}
2943
2944static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
2945{
2946 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2947 struct intel_encoder *encoder = &intel_dig_port->base;
2948 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002949 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002950 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002951
2952 lockdep_assert_held(&dev_priv->pps_mutex);
2953
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002954 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002955
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002956 if (intel_dp->pps_pipe != INVALID_PIPE &&
2957 intel_dp->pps_pipe != crtc->pipe) {
2958 /*
2959 * If another power sequencer was being used on this
2960 * port previously make sure to turn off vdd there while
2961 * we still have control of it.
2962 */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002963 vlv_detach_power_sequencer(intel_dp);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002964 }
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002965
2966 /*
2967 * We may be stealing the power
2968 * sequencer from another port.
2969 */
2970 vlv_steal_power_sequencer(dev, crtc->pipe);
2971
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002972 intel_dp->active_pipe = crtc->pipe;
2973
2974 if (!is_edp(intel_dp))
2975 return;
2976
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002977 /* now it's all ours */
2978 intel_dp->pps_pipe = crtc->pipe;
2979
2980 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
2981 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
2982
2983 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03002984 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02002985 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002986}
2987
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002988static void vlv_pre_enable_dp(struct intel_encoder *encoder,
2989 struct intel_crtc_state *pipe_config,
2990 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002991{
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03002992 vlv_phy_pre_encoder_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002993
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002994 intel_enable_dp(encoder, pipe_config, conn_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002995}
2996
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002997static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
2998 struct intel_crtc_state *pipe_config,
2999 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07003000{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003001 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02003002
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03003003 vlv_phy_pre_pll_enable(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003004}
3005
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003006static void chv_pre_enable_dp(struct intel_encoder *encoder,
3007 struct intel_crtc_state *pipe_config,
3008 struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003009{
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003010 chv_phy_pre_encoder_enable(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003011
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003012 intel_enable_dp(encoder, pipe_config, conn_state);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03003013
3014 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003015 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003016}
3017
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003018static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
3019 struct intel_crtc_state *pipe_config,
3020 struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03003021{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003022 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03003023
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03003024 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03003025}
3026
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003027static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
3028 struct intel_crtc_state *pipe_config,
3029 struct drm_connector_state *conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003030{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03003031 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003032}
3033
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003034/*
3035 * Fetch AUX CH registers 0x202 - 0x207 which contain
3036 * link status information
3037 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003038bool
Keith Packard93f62da2011-11-01 19:45:03 -07003039intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003040{
Lyude9f085eb2016-04-13 10:58:33 -04003041 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
3042 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003043}
3044
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303045static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp)
3046{
3047 uint8_t psr_caps = 0;
3048
3049 drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps);
3050 return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED;
3051}
3052
3053static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp)
3054{
3055 uint8_t dprx = 0;
3056
3057 drm_dp_dpcd_readb(&intel_dp->aux,
3058 DP_DPRX_FEATURE_ENUMERATION_LIST,
3059 &dprx);
3060 return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED;
3061}
3062
Paulo Zanoni11002442014-06-13 18:45:41 -03003063/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003064uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003065intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003066{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003067 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003068 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003069
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003070 if (IS_GEN9_LP(dev_priv))
Vandana Kannan93147262014-11-18 15:45:29 +05303071 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003072 else if (INTEL_GEN(dev_priv) >= 9) {
Jani Nikula06411f02016-03-24 17:50:21 +02003073 if (dev_priv->vbt.edp.low_vswing && port == PORT_A)
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303074 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003075 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003076 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Sonika Jindalbd600182014-08-08 16:23:41 +05303077 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003078 else if (IS_GEN7(dev_priv) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303079 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003080 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303081 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08003082 else
Sonika Jindalbd600182014-08-08 16:23:41 +05303083 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08003084}
3085
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003086uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003087intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3088{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003089 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003090 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003091
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003092 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003093 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3094 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3095 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3096 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3097 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3098 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3099 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303100 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3101 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003102 default:
3103 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3104 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003105 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003106 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303107 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3108 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3109 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3110 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3111 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3112 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3113 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003114 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303115 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003116 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003117 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003118 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303119 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3120 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3121 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3122 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3123 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3124 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3125 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003126 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303127 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003128 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003129 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003130 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303131 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3132 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3133 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3134 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3135 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003136 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303137 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003138 }
3139 } else {
3140 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303141 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3142 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3143 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3144 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3145 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3146 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3147 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003148 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303149 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003150 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003151 }
3152}
3153
Daniel Vetter5829975c2015-04-16 11:36:52 +02003154static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003155{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003156 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003157 unsigned long demph_reg_value, preemph_reg_value,
3158 uniqtranscale_reg_value;
3159 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003160
3161 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303162 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003163 preemph_reg_value = 0x0004000;
3164 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303165 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003166 demph_reg_value = 0x2B405555;
3167 uniqtranscale_reg_value = 0x552AB83A;
3168 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303169 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003170 demph_reg_value = 0x2B404040;
3171 uniqtranscale_reg_value = 0x5548B83A;
3172 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303173 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003174 demph_reg_value = 0x2B245555;
3175 uniqtranscale_reg_value = 0x5560B83A;
3176 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303177 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003178 demph_reg_value = 0x2B405555;
3179 uniqtranscale_reg_value = 0x5598DA3A;
3180 break;
3181 default:
3182 return 0;
3183 }
3184 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303185 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003186 preemph_reg_value = 0x0002000;
3187 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303188 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003189 demph_reg_value = 0x2B404040;
3190 uniqtranscale_reg_value = 0x5552B83A;
3191 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303192 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003193 demph_reg_value = 0x2B404848;
3194 uniqtranscale_reg_value = 0x5580B83A;
3195 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303196 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003197 demph_reg_value = 0x2B404040;
3198 uniqtranscale_reg_value = 0x55ADDA3A;
3199 break;
3200 default:
3201 return 0;
3202 }
3203 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303204 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003205 preemph_reg_value = 0x0000000;
3206 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303207 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003208 demph_reg_value = 0x2B305555;
3209 uniqtranscale_reg_value = 0x5570B83A;
3210 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303211 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003212 demph_reg_value = 0x2B2B4040;
3213 uniqtranscale_reg_value = 0x55ADDA3A;
3214 break;
3215 default:
3216 return 0;
3217 }
3218 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303219 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003220 preemph_reg_value = 0x0006000;
3221 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303222 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003223 demph_reg_value = 0x1B405555;
3224 uniqtranscale_reg_value = 0x55ADDA3A;
3225 break;
3226 default:
3227 return 0;
3228 }
3229 break;
3230 default:
3231 return 0;
3232 }
3233
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003234 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3235 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003236
3237 return 0;
3238}
3239
Daniel Vetter5829975c2015-04-16 11:36:52 +02003240static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003241{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003242 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3243 u32 deemph_reg_value, margin_reg_value;
3244 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003245 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003246
3247 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303248 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003249 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303250 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003251 deemph_reg_value = 128;
3252 margin_reg_value = 52;
3253 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303254 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003255 deemph_reg_value = 128;
3256 margin_reg_value = 77;
3257 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303258 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003259 deemph_reg_value = 128;
3260 margin_reg_value = 102;
3261 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303262 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003263 deemph_reg_value = 128;
3264 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003265 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003266 break;
3267 default:
3268 return 0;
3269 }
3270 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303271 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003272 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303273 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003274 deemph_reg_value = 85;
3275 margin_reg_value = 78;
3276 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303277 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003278 deemph_reg_value = 85;
3279 margin_reg_value = 116;
3280 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303281 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003282 deemph_reg_value = 85;
3283 margin_reg_value = 154;
3284 break;
3285 default:
3286 return 0;
3287 }
3288 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303289 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003290 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303291 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003292 deemph_reg_value = 64;
3293 margin_reg_value = 104;
3294 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303295 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003296 deemph_reg_value = 64;
3297 margin_reg_value = 154;
3298 break;
3299 default:
3300 return 0;
3301 }
3302 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303303 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003304 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303305 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003306 deemph_reg_value = 43;
3307 margin_reg_value = 154;
3308 break;
3309 default:
3310 return 0;
3311 }
3312 break;
3313 default:
3314 return 0;
3315 }
3316
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003317 chv_set_phy_signal_level(encoder, deemph_reg_value,
3318 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003319
3320 return 0;
3321}
3322
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003323static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003324gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003325{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003326 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003327
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003328 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303329 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003330 default:
3331 signal_levels |= DP_VOLTAGE_0_4;
3332 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303333 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003334 signal_levels |= DP_VOLTAGE_0_6;
3335 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303336 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003337 signal_levels |= DP_VOLTAGE_0_8;
3338 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303339 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003340 signal_levels |= DP_VOLTAGE_1_2;
3341 break;
3342 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003343 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303344 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003345 default:
3346 signal_levels |= DP_PRE_EMPHASIS_0;
3347 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303348 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003349 signal_levels |= DP_PRE_EMPHASIS_3_5;
3350 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303351 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003352 signal_levels |= DP_PRE_EMPHASIS_6;
3353 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303354 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003355 signal_levels |= DP_PRE_EMPHASIS_9_5;
3356 break;
3357 }
3358 return signal_levels;
3359}
3360
Zhenyu Wange3421a12010-04-08 09:43:27 +08003361/* Gen6's DP voltage swing and pre-emphasis control */
3362static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003363gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003364{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003365 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3366 DP_TRAIN_PRE_EMPHASIS_MASK);
3367 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303368 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3369 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003370 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303371 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003372 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303373 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3374 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003375 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303376 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3377 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003378 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303379 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3380 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003381 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003382 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003383 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3384 "0x%x\n", signal_levels);
3385 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003386 }
3387}
3388
Keith Packard1a2eb462011-11-16 16:26:07 -08003389/* Gen7's DP voltage swing and pre-emphasis control */
3390static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003391gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003392{
3393 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3394 DP_TRAIN_PRE_EMPHASIS_MASK);
3395 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303396 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003397 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303398 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003399 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303400 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003401 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3402
Sonika Jindalbd600182014-08-08 16:23:41 +05303403 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003404 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303405 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003406 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3407
Sonika Jindalbd600182014-08-08 16:23:41 +05303408 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003409 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303410 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003411 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3412
3413 default:
3414 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3415 "0x%x\n", signal_levels);
3416 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3417 }
3418}
3419
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003420void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003421intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003422{
3423 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003424 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003425 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003426 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003427 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003428 uint8_t train_set = intel_dp->train_set[0];
3429
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003430 if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003431 signal_levels = ddi_signal_levels(intel_dp);
3432
Michel Thierry254e0932017-01-09 16:51:35 +02003433 if (IS_GEN9_LP(dev_priv))
David Weinehallf8896f52015-06-25 11:11:03 +03003434 signal_levels = 0;
3435 else
3436 mask = DDI_BUF_EMP_MASK;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003437 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003438 signal_levels = chv_signal_levels(intel_dp);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003439 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003440 signal_levels = vlv_signal_levels(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003441 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003442 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003443 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003444 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003445 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003446 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3447 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003448 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003449 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3450 }
3451
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303452 if (mask)
3453 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3454
3455 DRM_DEBUG_KMS("Using vswing level %d\n",
3456 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3457 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3458 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3459 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003460
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003461 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003462
3463 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3464 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003465}
3466
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003467void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003468intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3469 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003470{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003471 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003472 struct drm_i915_private *dev_priv =
3473 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003474
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003475 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003476
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003477 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003478 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003479}
3480
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003481void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003482{
3483 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3484 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003485 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak3ab9c632013-05-03 12:57:41 +03003486 enum port port = intel_dig_port->port;
3487 uint32_t val;
3488
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003489 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003490 return;
3491
3492 val = I915_READ(DP_TP_CTL(port));
3493 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3494 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3495 I915_WRITE(DP_TP_CTL(port), val);
3496
3497 /*
3498 * On PORT_A we can have only eDP in SST mode. There the only reason
3499 * we need to set idle transmission mode is to work around a HW issue
3500 * where we enable the pipe while not in idle link-training mode.
3501 * In this case there is requirement to wait for a minimum number of
3502 * idle patterns to be sent.
3503 */
3504 if (port == PORT_A)
3505 return;
3506
Chris Wilsona7670172016-06-30 15:33:10 +01003507 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3508 DP_TP_STATUS_IDLE_DONE,
3509 DP_TP_STATUS_IDLE_DONE,
3510 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003511 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3512}
3513
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003514static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003515intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003516{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003517 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003518 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003519 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003520 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003521 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003522 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003523
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003524 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003525 return;
3526
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003527 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003528 return;
3529
Zhao Yakui28c97732009-10-09 11:39:41 +08003530 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003531
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003532 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003533 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003534 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003535 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003536 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003537 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003538 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3539 else
3540 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003541 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003542 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003543 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003544 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003545
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003546 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3547 I915_WRITE(intel_dp->output_reg, DP);
3548 POSTING_READ(intel_dp->output_reg);
3549
3550 /*
3551 * HW workaround for IBX, we need to move the port
3552 * to transcoder A after disabling it to allow the
3553 * matching HDMI port to be enabled on transcoder A.
3554 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003555 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003556 /*
3557 * We get CPU/PCH FIFO underruns on the other pipe when
3558 * doing the workaround. Sweep them under the rug.
3559 */
3560 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3561 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3562
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003563 /* always enable with pattern 1 (as per spec) */
3564 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3565 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3566 I915_WRITE(intel_dp->output_reg, DP);
3567 POSTING_READ(intel_dp->output_reg);
3568
3569 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003570 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003571 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003572
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003573 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003574 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3575 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003576 }
3577
Keith Packardf01eca22011-09-28 16:48:10 -07003578 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003579
3580 intel_dp->DP = DP;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003581
3582 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3583 pps_lock(intel_dp);
3584 intel_dp->active_pipe = INVALID_PIPE;
3585 pps_unlock(intel_dp);
3586 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003587}
3588
Imre Deak24e807e2016-10-24 19:33:28 +03003589bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003590intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003591{
Lyude9f085eb2016-04-13 10:58:33 -04003592 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3593 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003594 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003595
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003596 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003597
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003598 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3599}
3600
3601static bool
3602intel_edp_init_dpcd(struct intel_dp *intel_dp)
3603{
3604 struct drm_i915_private *dev_priv =
3605 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3606
3607 /* this function is meant to be called only once */
3608 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3609
3610 if (!intel_dp_read_dpcd(intel_dp))
3611 return false;
3612
Imre Deak12a47a422016-10-24 19:33:29 +03003613 intel_dp_read_desc(intel_dp);
3614
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003615 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3616 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3617 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3618
3619 /* Check if the panel supports PSR */
3620 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3621 intel_dp->psr_dpcd,
3622 sizeof(intel_dp->psr_dpcd));
3623 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3624 dev_priv->psr.sink_support = true;
3625 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3626 }
3627
3628 if (INTEL_GEN(dev_priv) >= 9 &&
3629 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3630 uint8_t frame_sync_cap;
3631
3632 dev_priv->psr.sink_support = true;
3633 drm_dp_dpcd_read(&intel_dp->aux,
3634 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3635 &frame_sync_cap, 1);
3636 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3637 /* PSR2 needs frame sync as well */
3638 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3639 DRM_DEBUG_KMS("PSR2 %s on sink",
3640 dev_priv->psr.psr2_support ? "supported" : "not supported");
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303641
3642 if (dev_priv->psr.psr2_support) {
3643 dev_priv->psr.y_cord_support =
3644 intel_dp_get_y_cord_status(intel_dp);
3645 dev_priv->psr.colorimetry_support =
3646 intel_dp_get_colorimetry_status(intel_dp);
3647 }
3648
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003649 }
3650
3651 /* Read the eDP Display control capabilities registers */
3652 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
3653 drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003654 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3655 sizeof(intel_dp->edp_dpcd))
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003656 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3657 intel_dp->edp_dpcd);
3658
3659 /* Intermediate frequency support */
3660 if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */
3661 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3662 int i;
3663
3664 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3665 sink_rates, sizeof(sink_rates));
3666
3667 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3668 int val = le16_to_cpu(sink_rates[i]);
3669
3670 if (val == 0)
3671 break;
3672
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -08003673 /* Value read multiplied by 200kHz gives the per-lane
3674 * link rate in kHz. The source rates are, however,
3675 * stored in terms of LS_Clk kHz. The full conversion
3676 * back to symbols is
3677 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
3678 */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003679 intel_dp->sink_rates[i] = (val * 200) / 10;
3680 }
3681 intel_dp->num_sink_rates = i;
3682 }
3683
3684 return true;
3685}
3686
3687
3688static bool
3689intel_dp_get_dpcd(struct intel_dp *intel_dp)
3690{
3691 if (!intel_dp_read_dpcd(intel_dp))
3692 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003693
Lyude9f085eb2016-04-13 10:58:33 -04003694 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT,
3695 &intel_dp->sink_count, 1) < 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303696 return false;
3697
3698 /*
3699 * Sink count can change between short pulse hpd hence
3700 * a member variable in intel_dp will track any changes
3701 * between short pulse interrupts.
3702 */
3703 intel_dp->sink_count = DP_GET_SINK_COUNT(intel_dp->sink_count);
3704
3705 /*
3706 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3707 * a dongle is present but no display. Unless we require to know
3708 * if a dongle is present or not, we don't need to update
3709 * downstream port information. So, an early return here saves
3710 * time from performing other operations which are not required.
3711 */
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05303712 if (!is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303713 return false;
3714
Imre Deakc726ad02016-10-24 19:33:24 +03003715 if (!drm_dp_is_branch(intel_dp->dpcd))
Adam Jacksonedb39242012-09-18 10:58:49 -04003716 return true; /* native DP sink */
3717
3718 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3719 return true; /* no per-port downstream info */
3720
Lyude9f085eb2016-04-13 10:58:33 -04003721 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3722 intel_dp->downstream_ports,
3723 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003724 return false; /* downstream port status fetch failed */
3725
3726 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003727}
3728
Dave Airlie0e32b392014-05-02 14:02:48 +10003729static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003730intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003731{
3732 u8 buf[1];
3733
Nathan Schulte7cc96132016-03-15 10:14:05 -05003734 if (!i915.enable_dp_mst)
3735 return false;
3736
Dave Airlie0e32b392014-05-02 14:02:48 +10003737 if (!intel_dp->can_mst)
3738 return false;
3739
3740 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3741 return false;
3742
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003743 if (drm_dp_dpcd_read(&intel_dp->aux, DP_MSTM_CAP, buf, 1) != 1)
3744 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003745
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003746 return buf[0] & DP_MST_CAP;
3747}
3748
3749static void
3750intel_dp_configure_mst(struct intel_dp *intel_dp)
3751{
3752 if (!i915.enable_dp_mst)
3753 return;
3754
3755 if (!intel_dp->can_mst)
3756 return;
3757
3758 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3759
3760 if (intel_dp->is_mst)
3761 DRM_DEBUG_KMS("Sink is MST capable\n");
3762 else
3763 DRM_DEBUG_KMS("Sink is not MST capable\n");
3764
3765 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3766 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003767}
3768
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003769static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003770{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003771 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003772 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003773 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003774 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003775 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003776 int count = 0;
3777 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003778
3779 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003780 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003781 ret = -EIO;
3782 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003783 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003784
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003785 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003786 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003787 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003788 ret = -EIO;
3789 goto out;
3790 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003791
Rodrigo Vivic6297842015-11-05 10:50:20 -08003792 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003793 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivic6297842015-11-05 10:50:20 -08003794
3795 if (drm_dp_dpcd_readb(&intel_dp->aux,
3796 DP_TEST_SINK_MISC, &buf) < 0) {
3797 ret = -EIO;
3798 goto out;
3799 }
3800 count = buf & DP_TEST_COUNT_MASK;
3801 } while (--attempts && count);
3802
3803 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003804 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003805 ret = -ETIMEDOUT;
3806 }
3807
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003808 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003809 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003810 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003811}
3812
3813static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3814{
3815 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003816 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003817 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3818 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003819 int ret;
3820
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003821 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3822 return -EIO;
3823
3824 if (!(buf & DP_TEST_CRC_SUPPORTED))
3825 return -ENOTTY;
3826
3827 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3828 return -EIO;
3829
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003830 if (buf & DP_TEST_SINK_START) {
3831 ret = intel_dp_sink_crc_stop(intel_dp);
3832 if (ret)
3833 return ret;
3834 }
3835
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003836 hsw_disable_ips(intel_crtc);
3837
3838 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3839 buf | DP_TEST_SINK_START) < 0) {
3840 hsw_enable_ips(intel_crtc);
3841 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003842 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003843
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003844 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003845 return 0;
3846}
3847
3848int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3849{
3850 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003851 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003852 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3853 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003854 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003855 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003856
3857 ret = intel_dp_sink_crc_start(intel_dp);
3858 if (ret)
3859 return ret;
3860
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003861 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003862 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003863
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003864 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003865 DP_TEST_SINK_MISC, &buf) < 0) {
3866 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003867 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003868 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003869 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07003870
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003871 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003872
3873 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003874 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
3875 ret = -ETIMEDOUT;
3876 goto stop;
3877 }
3878
3879 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
3880 ret = -EIO;
3881 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003882 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003883
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003884stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003885 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003886 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003887}
3888
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003889static bool
3890intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3891{
Lyude9f085eb2016-04-13 10:58:33 -04003892 return drm_dp_dpcd_read(&intel_dp->aux,
Jani Nikula9d1a1032014-03-14 16:51:15 +02003893 DP_DEVICE_SERVICE_IRQ_VECTOR,
3894 sink_irq_vector, 1) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003895}
3896
Dave Airlie0e32b392014-05-02 14:02:48 +10003897static bool
3898intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3899{
3900 int ret;
3901
Lyude9f085eb2016-04-13 10:58:33 -04003902 ret = drm_dp_dpcd_read(&intel_dp->aux,
Dave Airlie0e32b392014-05-02 14:02:48 +10003903 DP_SINK_COUNT_ESI,
3904 sink_irq_vector, 14);
3905 if (ret != 14)
3906 return false;
3907
3908 return true;
3909}
3910
Todd Previtec5d5ab72015-04-15 08:38:38 -07003911static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003912{
Todd Previtec5d5ab72015-04-15 08:38:38 -07003913 uint8_t test_result = DP_TEST_ACK;
3914 return test_result;
3915}
3916
3917static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
3918{
3919 uint8_t test_result = DP_TEST_NAK;
3920 return test_result;
3921}
3922
3923static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
3924{
3925 uint8_t test_result = DP_TEST_NAK;
Todd Previte559be302015-05-04 07:48:20 -07003926 struct intel_connector *intel_connector = intel_dp->attached_connector;
3927 struct drm_connector *connector = &intel_connector->base;
3928
3929 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02003930 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07003931 intel_dp->aux.i2c_defer_count > 6) {
3932 /* Check EDID read for NACKs, DEFERs and corruption
3933 * (DP CTS 1.2 Core r1.1)
3934 * 4.2.2.4 : Failed EDID read, I2C_NAK
3935 * 4.2.2.5 : Failed EDID read, I2C_DEFER
3936 * 4.2.2.6 : EDID corruption detected
3937 * Use failsafe mode for all cases
3938 */
3939 if (intel_dp->aux.i2c_nack_count > 0 ||
3940 intel_dp->aux.i2c_defer_count > 0)
3941 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
3942 intel_dp->aux.i2c_nack_count,
3943 intel_dp->aux.i2c_defer_count);
Manasi Navarec1617ab2016-12-09 16:22:50 -08003944 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
Todd Previte559be302015-05-04 07:48:20 -07003945 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05303946 struct edid *block = intel_connector->detect_edid;
3947
3948 /* We have to write the checksum
3949 * of the last block read
3950 */
3951 block += intel_connector->detect_edid->extensions;
3952
Todd Previte559be302015-05-04 07:48:20 -07003953 if (!drm_dp_dpcd_write(&intel_dp->aux,
3954 DP_TEST_EDID_CHECKSUM,
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05303955 &block->checksum,
Dan Carpenter5a1cc652015-05-12 21:07:37 +03003956 1))
Todd Previte559be302015-05-04 07:48:20 -07003957 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
3958
3959 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
Manasi Navarec1617ab2016-12-09 16:22:50 -08003960 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_STANDARD;
Todd Previte559be302015-05-04 07:48:20 -07003961 }
3962
3963 /* Set test active flag here so userspace doesn't interrupt things */
Manasi Navarec1617ab2016-12-09 16:22:50 -08003964 intel_dp->compliance.test_active = 1;
Todd Previte559be302015-05-04 07:48:20 -07003965
Todd Previtec5d5ab72015-04-15 08:38:38 -07003966 return test_result;
3967}
3968
3969static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
3970{
3971 uint8_t test_result = DP_TEST_NAK;
3972 return test_result;
3973}
3974
3975static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
3976{
3977 uint8_t response = DP_TEST_NAK;
3978 uint8_t rxdata = 0;
3979 int status = 0;
3980
Todd Previtec5d5ab72015-04-15 08:38:38 -07003981 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_REQUEST, &rxdata, 1);
3982 if (status <= 0) {
3983 DRM_DEBUG_KMS("Could not read test request from sink\n");
3984 goto update_status;
3985 }
3986
3987 switch (rxdata) {
3988 case DP_TEST_LINK_TRAINING:
3989 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
Manasi Navarec1617ab2016-12-09 16:22:50 -08003990 intel_dp->compliance.test_type = DP_TEST_LINK_TRAINING;
Todd Previtec5d5ab72015-04-15 08:38:38 -07003991 response = intel_dp_autotest_link_training(intel_dp);
3992 break;
3993 case DP_TEST_LINK_VIDEO_PATTERN:
3994 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
Manasi Navarec1617ab2016-12-09 16:22:50 -08003995 intel_dp->compliance.test_type = DP_TEST_LINK_VIDEO_PATTERN;
Todd Previtec5d5ab72015-04-15 08:38:38 -07003996 response = intel_dp_autotest_video_pattern(intel_dp);
3997 break;
3998 case DP_TEST_LINK_EDID_READ:
3999 DRM_DEBUG_KMS("EDID test requested\n");
Manasi Navarec1617ab2016-12-09 16:22:50 -08004000 intel_dp->compliance.test_type = DP_TEST_LINK_EDID_READ;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004001 response = intel_dp_autotest_edid(intel_dp);
4002 break;
4003 case DP_TEST_LINK_PHY_TEST_PATTERN:
4004 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
Manasi Navarec1617ab2016-12-09 16:22:50 -08004005 intel_dp->compliance.test_type = DP_TEST_LINK_PHY_TEST_PATTERN;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004006 response = intel_dp_autotest_phy_pattern(intel_dp);
4007 break;
4008 default:
4009 DRM_DEBUG_KMS("Invalid test request '%02x'\n", rxdata);
4010 break;
4011 }
4012
4013update_status:
4014 status = drm_dp_dpcd_write(&intel_dp->aux,
4015 DP_TEST_RESPONSE,
4016 &response, 1);
4017 if (status <= 0)
4018 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004019}
4020
Dave Airlie0e32b392014-05-02 14:02:48 +10004021static int
4022intel_dp_check_mst_status(struct intel_dp *intel_dp)
4023{
4024 bool bret;
4025
4026 if (intel_dp->is_mst) {
4027 u8 esi[16] = { 0 };
4028 int ret = 0;
4029 int retry;
4030 bool handled;
4031 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4032go_again:
4033 if (bret == true) {
4034
4035 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03004036 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03004037 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10004038 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4039 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004040 intel_dp_stop_link_train(intel_dp);
4041 }
4042
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004043 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004044 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4045
4046 if (handled) {
4047 for (retry = 0; retry < 3; retry++) {
4048 int wret;
4049 wret = drm_dp_dpcd_write(&intel_dp->aux,
4050 DP_SINK_COUNT_ESI+1,
4051 &esi[1], 3);
4052 if (wret == 3) {
4053 break;
4054 }
4055 }
4056
4057 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4058 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004059 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004060 goto go_again;
4061 }
4062 } else
4063 ret = 0;
4064
4065 return ret;
4066 } else {
4067 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4068 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4069 intel_dp->is_mst = false;
4070 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4071 /* send a hotplug event */
4072 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4073 }
4074 }
4075 return -EINVAL;
4076}
4077
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304078static void
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004079intel_dp_retrain_link(struct intel_dp *intel_dp)
4080{
4081 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4082 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4083 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
4084
4085 /* Suppress underruns caused by re-training */
4086 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4087 if (crtc->config->has_pch_encoder)
4088 intel_set_pch_fifo_underrun_reporting(dev_priv,
4089 intel_crtc_pch_transcoder(crtc), false);
4090
4091 intel_dp_start_link_train(intel_dp);
4092 intel_dp_stop_link_train(intel_dp);
4093
4094 /* Keep underrun reporting disabled until things are stable */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02004095 intel_wait_for_vblank(dev_priv, crtc->pipe);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004096
4097 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4098 if (crtc->config->has_pch_encoder)
4099 intel_set_pch_fifo_underrun_reporting(dev_priv,
4100 intel_crtc_pch_transcoder(crtc), true);
4101}
4102
4103static void
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304104intel_dp_check_link_status(struct intel_dp *intel_dp)
4105{
4106 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4107 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4108 u8 link_status[DP_LINK_STATUS_SIZE];
4109
4110 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
4111
4112 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4113 DRM_ERROR("Failed to get link status\n");
4114 return;
4115 }
4116
4117 if (!intel_encoder->base.crtc)
4118 return;
4119
4120 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4121 return;
4122
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004123 /* FIXME: we need to synchronize this sort of stuff with hardware
Daniel Vetter2dd85ae2016-12-13 20:54:14 +01004124 * readout. Currently fast link training doesn't work on boot-up. */
4125 if (!intel_dp->lane_count)
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004126 return;
4127
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304128 /* if link training is requested we should perform it always */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004129 if ((intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) ||
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304130 (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count))) {
4131 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4132 intel_encoder->base.name);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004133
4134 intel_dp_retrain_link(intel_dp);
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304135 }
4136}
4137
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004138/*
4139 * According to DP spec
4140 * 5.1.2:
4141 * 1. Read DPCD
4142 * 2. Configure link according to Receiver Capabilities
4143 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4144 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304145 *
4146 * intel_dp_short_pulse - handles short pulse interrupts
4147 * when full detection is not required.
4148 * Returns %true if short pulse is handled and full detection
4149 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004150 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304151static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304152intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004153{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004154 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004155 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304156 u8 old_sink_count = intel_dp->sink_count;
4157 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004158
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304159 /*
4160 * Clearing compliance test variables to allow capturing
4161 * of values for next automated test request.
4162 */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004163 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304164
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304165 /*
4166 * Now read the DPCD to see if it's actually running
4167 * If the current value of sink count doesn't match with
4168 * the value that was stored earlier or dpcd read failed
4169 * we need to do full detection
4170 */
4171 ret = intel_dp_get_dpcd(intel_dp);
4172
4173 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4174 /* No need to proceed if we are going to do full detect */
4175 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004176 }
4177
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004178 /* Try to read the source of the interrupt */
4179 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004180 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4181 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004182 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004183 drm_dp_dpcd_writeb(&intel_dp->aux,
4184 DP_DEVICE_SERVICE_IRQ_VECTOR,
4185 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004186
4187 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Todd Previte09b1eb12015-04-20 15:27:34 -07004188 DRM_DEBUG_DRIVER("Test request in short pulse not handled\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004189 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4190 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4191 }
4192
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304193 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4194 intel_dp_check_link_status(intel_dp);
4195 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304196
4197 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004198}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004199
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004200/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004201static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004202intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004203{
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004204 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004205 uint8_t type;
4206
4207 if (!intel_dp_get_dpcd(intel_dp))
4208 return connector_status_disconnected;
4209
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304210 if (is_edp(intel_dp))
4211 return connector_status_connected;
4212
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004213 /* if there's no downstream port, we're done */
Imre Deakc726ad02016-10-24 19:33:24 +03004214 if (!drm_dp_is_branch(dpcd))
Keith Packard26d61aa2011-07-25 20:01:09 -07004215 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004216
4217 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004218 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4219 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004220
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304221 return intel_dp->sink_count ?
4222 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004223 }
4224
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004225 if (intel_dp_can_mst(intel_dp))
4226 return connector_status_connected;
4227
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004228 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004229 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004230 return connector_status_connected;
4231
4232 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004233 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4234 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4235 if (type == DP_DS_PORT_TYPE_VGA ||
4236 type == DP_DS_PORT_TYPE_NON_EDID)
4237 return connector_status_unknown;
4238 } else {
4239 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4240 DP_DWN_STRM_PORT_TYPE_MASK;
4241 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4242 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4243 return connector_status_unknown;
4244 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004245
4246 /* Anything else is out of spec, warn and ignore */
4247 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004248 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004249}
4250
4251static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004252edp_detect(struct intel_dp *intel_dp)
4253{
4254 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Mika Kahola1650be72016-12-13 10:02:47 +02004255 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsond410b562014-09-02 20:03:59 +01004256 enum drm_connector_status status;
4257
Mika Kahola1650be72016-12-13 10:02:47 +02004258 status = intel_panel_detect(dev_priv);
Chris Wilsond410b562014-09-02 20:03:59 +01004259 if (status == connector_status_unknown)
4260 status = connector_status_connected;
4261
4262 return status;
4263}
4264
Jani Nikulab93433c2015-08-20 10:47:36 +03004265static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4266 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004267{
Jani Nikulab93433c2015-08-20 10:47:36 +03004268 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004269
Jani Nikula0df53b72015-08-20 10:47:40 +03004270 switch (port->port) {
4271 case PORT_A:
4272 return true;
4273 case PORT_B:
4274 bit = SDE_PORTB_HOTPLUG;
4275 break;
4276 case PORT_C:
4277 bit = SDE_PORTC_HOTPLUG;
4278 break;
4279 case PORT_D:
4280 bit = SDE_PORTD_HOTPLUG;
4281 break;
4282 default:
4283 MISSING_CASE(port->port);
4284 return false;
4285 }
4286
4287 return I915_READ(SDEISR) & bit;
4288}
4289
4290static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4291 struct intel_digital_port *port)
4292{
4293 u32 bit;
4294
4295 switch (port->port) {
4296 case PORT_A:
4297 return true;
4298 case PORT_B:
4299 bit = SDE_PORTB_HOTPLUG_CPT;
4300 break;
4301 case PORT_C:
4302 bit = SDE_PORTC_HOTPLUG_CPT;
4303 break;
4304 case PORT_D:
4305 bit = SDE_PORTD_HOTPLUG_CPT;
4306 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004307 case PORT_E:
4308 bit = SDE_PORTE_HOTPLUG_SPT;
4309 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004310 default:
4311 MISSING_CASE(port->port);
4312 return false;
Jani Nikulab93433c2015-08-20 10:47:36 +03004313 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004314
Jani Nikulab93433c2015-08-20 10:47:36 +03004315 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004316}
4317
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004318static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004319 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004320{
Jani Nikula9642c812015-08-20 10:47:41 +03004321 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004322
Jani Nikula9642c812015-08-20 10:47:41 +03004323 switch (port->port) {
4324 case PORT_B:
4325 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4326 break;
4327 case PORT_C:
4328 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4329 break;
4330 case PORT_D:
4331 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4332 break;
4333 default:
4334 MISSING_CASE(port->port);
4335 return false;
4336 }
4337
4338 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4339}
4340
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004341static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4342 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004343{
4344 u32 bit;
4345
4346 switch (port->port) {
4347 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004348 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004349 break;
4350 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004351 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004352 break;
4353 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004354 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004355 break;
4356 default:
4357 MISSING_CASE(port->port);
4358 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004359 }
4360
Jani Nikula1d245982015-08-20 10:47:37 +03004361 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004362}
4363
Jani Nikulae464bfd2015-08-20 10:47:42 +03004364static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304365 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004366{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304367 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4368 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004369 u32 bit;
4370
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304371 intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port);
4372 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004373 case PORT_A:
4374 bit = BXT_DE_PORT_HP_DDIA;
4375 break;
4376 case PORT_B:
4377 bit = BXT_DE_PORT_HP_DDIB;
4378 break;
4379 case PORT_C:
4380 bit = BXT_DE_PORT_HP_DDIC;
4381 break;
4382 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304383 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004384 return false;
4385 }
4386
4387 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4388}
4389
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004390/*
4391 * intel_digital_port_connected - is the specified port connected?
4392 * @dev_priv: i915 private structure
4393 * @port: the port to test
4394 *
4395 * Return %true if @port is connected, %false otherwise.
4396 */
David Weinehall23f889b2016-08-17 15:47:48 +03004397static bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004398 struct intel_digital_port *port)
4399{
Jani Nikula0df53b72015-08-20 10:47:40 +03004400 if (HAS_PCH_IBX(dev_priv))
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004401 return ibx_digital_port_connected(dev_priv, port);
Ville Syrjälä22824fa2016-02-11 16:44:28 +02004402 else if (HAS_PCH_SPLIT(dev_priv))
Jani Nikula0df53b72015-08-20 10:47:40 +03004403 return cpt_digital_port_connected(dev_priv, port);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004404 else if (IS_GEN9_LP(dev_priv))
Jani Nikulae464bfd2015-08-20 10:47:42 +03004405 return bxt_digital_port_connected(dev_priv, port);
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004406 else if (IS_GM45(dev_priv))
4407 return gm45_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004408 else
4409 return g4x_digital_port_connected(dev_priv, port);
4410}
4411
Keith Packard8c241fe2011-09-28 16:38:44 -07004412static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004413intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004414{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004415 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004416
Jani Nikula9cd300e2012-10-19 14:51:52 +03004417 /* use cached edid if we have one */
4418 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004419 /* invalid edid */
4420 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004421 return NULL;
4422
Jani Nikula55e9ede2013-10-01 10:38:54 +03004423 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004424 } else
4425 return drm_get_edid(&intel_connector->base,
4426 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004427}
4428
Chris Wilsonbeb60602014-09-02 20:04:00 +01004429static void
4430intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004431{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004432 struct intel_connector *intel_connector = intel_dp->attached_connector;
4433 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004434
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304435 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004436 edid = intel_dp_get_edid(intel_dp);
4437 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004438
Chris Wilsonbeb60602014-09-02 20:04:00 +01004439 if (intel_dp->force_audio != HDMI_AUDIO_AUTO)
4440 intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON;
4441 else
4442 intel_dp->has_audio = drm_detect_monitor_audio(edid);
4443}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004444
Chris Wilsonbeb60602014-09-02 20:04:00 +01004445static void
4446intel_dp_unset_edid(struct intel_dp *intel_dp)
4447{
4448 struct intel_connector *intel_connector = intel_dp->attached_connector;
4449
4450 kfree(intel_connector->detect_edid);
4451 intel_connector->detect_edid = NULL;
4452
4453 intel_dp->has_audio = false;
4454}
4455
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004456static enum drm_connector_status
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304457intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004458{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304459 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004460 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004461 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4462 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004463 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004464 enum drm_connector_status status;
Imre Deak671dedd2014-03-05 16:20:53 +02004465 enum intel_display_power_domain power_domain;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004466 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004467
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004468 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4469 intel_display_power_get(to_i915(dev), power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004470
Chris Wilsond410b562014-09-02 20:03:59 +01004471 /* Can't disconnect eDP, but you can close the lid... */
4472 if (is_edp(intel_dp))
4473 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004474 else if (intel_digital_port_connected(to_i915(dev),
4475 dp_to_dig_port(intel_dp)))
4476 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004477 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004478 status = connector_status_disconnected;
4479
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004480 if (status == connector_status_disconnected) {
Manasi Navarec1617ab2016-12-09 16:22:50 -08004481 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304482
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004483 if (intel_dp->is_mst) {
4484 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4485 intel_dp->is_mst,
4486 intel_dp->mst_mgr.mst_state);
4487 intel_dp->is_mst = false;
4488 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4489 intel_dp->is_mst);
4490 }
4491
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004492 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304493 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004494
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304495 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004496 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304497
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004498 DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
4499 yesno(intel_dp_source_supports_hbr2(intel_dp)),
4500 yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
4501
Manasi Navaref4829842016-12-05 16:27:36 -08004502 /* Set the max lane count for sink */
4503 intel_dp->max_sink_lane_count = drm_dp_max_lane_count(intel_dp->dpcd);
4504
4505 /* Set the max link BW for sink */
4506 intel_dp->max_sink_link_bw = intel_dp_max_link_bw(intel_dp);
4507
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004508 intel_dp_print_rates(intel_dp);
4509
Imre Deak7b3fc172016-10-25 16:12:39 +03004510 intel_dp_read_desc(intel_dp);
Mika Kahola0e390a32016-09-09 14:10:53 +03004511
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004512 intel_dp_configure_mst(intel_dp);
4513
4514 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304515 /*
4516 * If we are in MST mode then this connector
4517 * won't appear connected or have anything
4518 * with EDID on it
4519 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004520 status = connector_status_disconnected;
4521 goto out;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304522 } else if (connector->status == connector_status_connected) {
4523 /*
4524 * If display was connected already and is still connected
4525 * check links status, there has been known issues of
4526 * link loss triggerring long pulse!!!!
4527 */
4528 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4529 intel_dp_check_link_status(intel_dp);
4530 drm_modeset_unlock(&dev->mode_config.connection_mutex);
4531 goto out;
Dave Airlie0e32b392014-05-02 14:02:48 +10004532 }
4533
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304534 /*
4535 * Clearing NACK and defer counts to get their exact values
4536 * while reading EDID which are required by Compliance tests
4537 * 4.2.2.4 and 4.2.2.5
4538 */
4539 intel_dp->aux.i2c_nack_count = 0;
4540 intel_dp->aux.i2c_defer_count = 0;
4541
Chris Wilsonbeb60602014-09-02 20:04:00 +01004542 intel_dp_set_edid(intel_dp);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004543 if (is_edp(intel_dp) || intel_connector->detect_edid)
4544 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304545 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004546
Todd Previte09b1eb12015-04-20 15:27:34 -07004547 /* Try to read the source of the interrupt */
4548 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004549 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4550 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004551 /* Clear interrupt source */
4552 drm_dp_dpcd_writeb(&intel_dp->aux,
4553 DP_DEVICE_SERVICE_IRQ_VECTOR,
4554 sink_irq_vector);
4555
4556 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4557 intel_dp_handle_test_request(intel_dp);
4558 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4559 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4560 }
4561
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004562out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004563 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304564 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304565
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004566 intel_display_power_put(to_i915(dev), power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004567 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304568}
4569
4570static enum drm_connector_status
4571intel_dp_detect(struct drm_connector *connector, bool force)
4572{
4573 struct intel_dp *intel_dp = intel_attached_dp(connector);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004574 enum drm_connector_status status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304575
4576 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4577 connector->base.id, connector->name);
4578
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304579 /* If full detect is not performed yet, do a full detect */
4580 if (!intel_dp->detect_done)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004581 status = intel_dp_long_pulse(intel_dp->attached_connector);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304582
4583 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304584
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004585 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004586}
4587
Chris Wilsonbeb60602014-09-02 20:04:00 +01004588static void
4589intel_dp_force(struct drm_connector *connector)
4590{
4591 struct intel_dp *intel_dp = intel_attached_dp(connector);
4592 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004593 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004594 enum intel_display_power_domain power_domain;
4595
4596 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4597 connector->base.id, connector->name);
4598 intel_dp_unset_edid(intel_dp);
4599
4600 if (connector->status != connector_status_connected)
4601 return;
4602
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004603 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4604 intel_display_power_get(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004605
4606 intel_dp_set_edid(intel_dp);
4607
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004608 intel_display_power_put(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004609
4610 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004611 intel_encoder->type = INTEL_OUTPUT_DP;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004612}
4613
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004614static int intel_dp_get_modes(struct drm_connector *connector)
4615{
Jani Nikuladd06f902012-10-19 14:51:50 +03004616 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004617 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004618
Chris Wilsonbeb60602014-09-02 20:04:00 +01004619 edid = intel_connector->detect_edid;
4620 if (edid) {
4621 int ret = intel_connector_update_modes(connector, edid);
4622 if (ret)
4623 return ret;
4624 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004625
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004626 /* if eDP has no EDID, fall back to fixed mode */
Chris Wilsonbeb60602014-09-02 20:04:00 +01004627 if (is_edp(intel_attached_dp(connector)) &&
4628 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004629 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004630
4631 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004632 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004633 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004634 drm_mode_probed_add(connector, mode);
4635 return 1;
4636 }
4637 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004638
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004639 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004640}
4641
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004642static bool
4643intel_dp_detect_audio(struct drm_connector *connector)
4644{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004645 bool has_audio = false;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004646 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004647
Chris Wilsonbeb60602014-09-02 20:04:00 +01004648 edid = to_intel_connector(connector)->detect_edid;
4649 if (edid)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004650 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02004651
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004652 return has_audio;
4653}
4654
Chris Wilsonf6849602010-09-19 09:29:33 +01004655static int
4656intel_dp_set_property(struct drm_connector *connector,
4657 struct drm_property *property,
4658 uint64_t val)
4659{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004660 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Yuly Novikov53b41832012-10-26 12:04:00 +03004661 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004662 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
4663 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01004664 int ret;
4665
Rob Clark662595d2012-10-11 20:36:04 -05004666 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01004667 if (ret)
4668 return ret;
4669
Chris Wilson3f43c482011-05-12 22:17:24 +01004670 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004671 int i = val;
4672 bool has_audio;
4673
4674 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004675 return 0;
4676
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004677 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01004678
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004679 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004680 has_audio = intel_dp_detect_audio(connector);
4681 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004682 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004683
4684 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004685 return 0;
4686
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004687 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01004688 goto done;
4689 }
4690
Chris Wilsone953fd72011-02-21 22:23:52 +00004691 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02004692 bool old_auto = intel_dp->color_range_auto;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004693 bool old_range = intel_dp->limited_color_range;
Daniel Vetterae4edb82013-04-22 17:07:23 +02004694
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004695 switch (val) {
4696 case INTEL_BROADCAST_RGB_AUTO:
4697 intel_dp->color_range_auto = true;
4698 break;
4699 case INTEL_BROADCAST_RGB_FULL:
4700 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004701 intel_dp->limited_color_range = false;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004702 break;
4703 case INTEL_BROADCAST_RGB_LIMITED:
4704 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004705 intel_dp->limited_color_range = true;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004706 break;
4707 default:
4708 return -EINVAL;
4709 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02004710
4711 if (old_auto == intel_dp->color_range_auto &&
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004712 old_range == intel_dp->limited_color_range)
Daniel Vetterae4edb82013-04-22 17:07:23 +02004713 return 0;
4714
Chris Wilsone953fd72011-02-21 22:23:52 +00004715 goto done;
4716 }
4717
Yuly Novikov53b41832012-10-26 12:04:00 +03004718 if (is_edp(intel_dp) &&
4719 property == connector->dev->mode_config.scaling_mode_property) {
4720 if (val == DRM_MODE_SCALE_NONE) {
4721 DRM_DEBUG_KMS("no scaling not supported\n");
4722 return -EINVAL;
4723 }
Ville Syrjälä234126c2016-04-12 22:14:38 +03004724 if (HAS_GMCH_DISPLAY(dev_priv) &&
4725 val == DRM_MODE_SCALE_CENTER) {
4726 DRM_DEBUG_KMS("centering not supported\n");
4727 return -EINVAL;
4728 }
Yuly Novikov53b41832012-10-26 12:04:00 +03004729
4730 if (intel_connector->panel.fitting_mode == val) {
4731 /* the eDP scaling property is not changed */
4732 return 0;
4733 }
4734 intel_connector->panel.fitting_mode = val;
4735
4736 goto done;
4737 }
4738
Chris Wilsonf6849602010-09-19 09:29:33 +01004739 return -EINVAL;
4740
4741done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00004742 if (intel_encoder->base.crtc)
4743 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01004744
4745 return 0;
4746}
4747
Chris Wilson7a418e32016-06-24 14:00:14 +01004748static int
4749intel_dp_connector_register(struct drm_connector *connector)
4750{
4751 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004752 int ret;
4753
4754 ret = intel_connector_register(connector);
4755 if (ret)
4756 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004757
4758 i915_debugfs_connector_add(connector);
4759
4760 DRM_DEBUG_KMS("registering %s bus for %s\n",
4761 intel_dp->aux.name, connector->kdev->kobj.name);
4762
4763 intel_dp->aux.dev = connector->kdev;
4764 return drm_dp_aux_register(&intel_dp->aux);
4765}
4766
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004767static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004768intel_dp_connector_unregister(struct drm_connector *connector)
4769{
4770 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4771 intel_connector_unregister(connector);
4772}
4773
4774static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004775intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004776{
Jani Nikula1d508702012-10-19 14:51:49 +03004777 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004778
Chris Wilson10e972d2014-09-04 21:43:45 +01004779 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004780
Jani Nikula9cd300e2012-10-19 14:51:52 +03004781 if (!IS_ERR_OR_NULL(intel_connector->edid))
4782 kfree(intel_connector->edid);
4783
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004784 /* Can't call is_edp() since the encoder may have been destroyed
4785 * already. */
4786 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004787 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004788
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004789 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004790 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004791}
4792
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004793void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004794{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004795 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4796 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004797
Dave Airlie0e32b392014-05-02 14:02:48 +10004798 intel_dp_mst_encoder_cleanup(intel_dig_port);
Keith Packardbd943152011-09-18 23:09:52 -07004799 if (is_edp(intel_dp)) {
4800 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004801 /*
4802 * vdd might still be enabled do to the delayed vdd off.
4803 * Make sure vdd is actually turned off here.
4804 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004805 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004806 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004807 pps_unlock(intel_dp);
4808
Clint Taylor01527b32014-07-07 13:01:46 -07004809 if (intel_dp->edp_notifier.notifier_call) {
4810 unregister_reboot_notifier(&intel_dp->edp_notifier);
4811 intel_dp->edp_notifier.notifier_call = NULL;
4812 }
Keith Packardbd943152011-09-18 23:09:52 -07004813 }
Chris Wilson99681882016-06-20 09:29:17 +01004814
4815 intel_dp_aux_fini(intel_dp);
4816
Imre Deakc8bd0e42014-12-12 17:57:38 +02004817 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004818 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004819}
4820
Imre Deakbf93ba62016-04-18 10:04:21 +03004821void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004822{
4823 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4824
4825 if (!is_edp(intel_dp))
4826 return;
4827
Ville Syrjälä951468f2014-09-04 14:55:31 +03004828 /*
4829 * vdd might still be enabled do to the delayed vdd off.
4830 * Make sure vdd is actually turned off here.
4831 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004832 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004833 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004834 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004835 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004836}
4837
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004838static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4839{
4840 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4841 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004842 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004843 enum intel_display_power_domain power_domain;
4844
4845 lockdep_assert_held(&dev_priv->pps_mutex);
4846
4847 if (!edp_have_panel_vdd(intel_dp))
4848 return;
4849
4850 /*
4851 * The VDD bit needs a power domain reference, so if the bit is
4852 * already enabled when we boot or resume, grab this reference and
4853 * schedule a vdd off, so we don't hold on to the reference
4854 * indefinitely.
4855 */
4856 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004857 power_domain = intel_display_port_aux_power_domain(&intel_dig_port->base);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004858 intel_display_power_get(dev_priv, power_domain);
4859
4860 edp_panel_vdd_schedule_off(intel_dp);
4861}
4862
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02004863static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
4864{
4865 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
4866
4867 if ((intel_dp->DP & DP_PORT_EN) == 0)
4868 return INVALID_PIPE;
4869
4870 if (IS_CHERRYVIEW(dev_priv))
4871 return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
4872 else
4873 return PORT_TO_PIPE(intel_dp->DP);
4874}
4875
Imre Deakbf93ba62016-04-18 10:04:21 +03004876void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03004877{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03004878 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Imre Deakdd75f6d2016-11-21 21:15:05 +02004879 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
4880 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Ville Syrjälä64989ca42016-05-13 20:53:56 +03004881
4882 if (!HAS_DDI(dev_priv))
4883 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004884
Imre Deakdd75f6d2016-11-21 21:15:05 +02004885 if (lspcon->active)
Shashank Sharma910530c2016-10-14 19:56:52 +05304886 lspcon_resume(lspcon);
4887
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004888 pps_lock(intel_dp);
4889
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02004890 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4891 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
4892
4893 if (is_edp(intel_dp)) {
4894 /* Reinit the power sequencer, in case BIOS did something with it. */
4895 intel_dp_pps_init(encoder->dev, intel_dp);
4896 intel_edp_panel_vdd_sanitize(intel_dp);
4897 }
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004898
4899 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03004900}
4901
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004902static const struct drm_connector_funcs intel_dp_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02004903 .dpms = drm_atomic_helper_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004904 .detect = intel_dp_detect,
Chris Wilsonbeb60602014-09-02 20:04:00 +01004905 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004906 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01004907 .set_property = intel_dp_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -08004908 .atomic_get_property = intel_connector_atomic_get_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01004909 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01004910 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004911 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08004912 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02004913 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004914};
4915
4916static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
4917 .get_modes = intel_dp_get_modes,
4918 .mode_valid = intel_dp_mode_valid,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004919};
4920
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004921static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03004922 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02004923 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004924};
4925
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004926enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10004927intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
4928{
4929 struct intel_dp *intel_dp = &intel_dig_port->dp;
Imre Deak1c767b32014-08-18 14:42:42 +03004930 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Dave Airlie0e32b392014-05-02 14:02:48 +10004931 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004932 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak1c767b32014-08-18 14:42:42 +03004933 enum intel_display_power_domain power_domain;
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004934 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03004935
Takashi Iwai25400582015-11-19 12:09:56 +01004936 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
4937 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004938 intel_dig_port->base.type = INTEL_OUTPUT_DP;
Dave Airlie13cf5502014-06-18 11:29:35 +10004939
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03004940 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
4941 /*
4942 * vdd off can generate a long pulse on eDP which
4943 * would require vdd on to handle it, and thus we
4944 * would end up in an endless cycle of
4945 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
4946 */
4947 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
4948 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d522015-02-10 14:11:46 +02004949 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03004950 }
4951
Ville Syrjälä26fbb772014-08-11 18:37:37 +03004952 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
4953 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10004954 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10004955
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004956 if (long_hpd) {
4957 intel_dp->detect_done = false;
4958 return IRQ_NONE;
4959 }
4960
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004961 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak1c767b32014-08-18 14:42:42 +03004962 intel_display_power_get(dev_priv, power_domain);
4963
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004964 if (intel_dp->is_mst) {
4965 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
4966 /*
4967 * If we were in MST mode, and device is not
4968 * there, get out of MST mode
4969 */
4970 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4971 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
4972 intel_dp->is_mst = false;
4973 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4974 intel_dp->is_mst);
4975 intel_dp->detect_done = false;
4976 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10004977 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004978 }
Dave Airlie0e32b392014-05-02 14:02:48 +10004979
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004980 if (!intel_dp->is_mst) {
4981 if (!intel_dp_short_pulse(intel_dp)) {
4982 intel_dp->detect_done = false;
4983 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304984 }
Dave Airlie0e32b392014-05-02 14:02:48 +10004985 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004986
4987 ret = IRQ_HANDLED;
4988
Imre Deak1c767b32014-08-18 14:42:42 +03004989put_power:
4990 intel_display_power_put(dev_priv, power_domain);
4991
4992 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10004993}
4994
Rodrigo Vivi477ec322015-08-06 15:51:39 +08004995/* check the VBT to see whether the eDP is on another port */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00004996bool intel_dp_is_edp(struct drm_i915_private *dev_priv, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08004997{
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03004998 /*
4999 * eDP not supported on g4x. so bail out early just
5000 * for a bit extra safety in case the VBT is bonkers.
5001 */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005002 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005003 return false;
5004
Imre Deaka98d9c12016-12-21 12:17:24 +02005005 if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005006 return true;
5007
Jani Nikula951d9ef2016-03-16 12:43:31 +02005008 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08005009}
5010
Dave Airlie0e32b392014-05-02 14:02:48 +10005011void
Chris Wilsonf6849602010-09-19 09:29:33 +01005012intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
5013{
Yuly Novikov53b41832012-10-26 12:04:00 +03005014 struct intel_connector *intel_connector = to_intel_connector(connector);
5015
Chris Wilson3f43c482011-05-12 22:17:24 +01005016 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00005017 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02005018 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03005019
5020 if (is_edp(intel_dp)) {
5021 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05005022 drm_object_attach_property(
5023 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03005024 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03005025 DRM_MODE_SCALE_ASPECT);
5026 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03005027 }
Chris Wilsonf6849602010-09-19 09:29:33 +01005028}
5029
Imre Deakdada1a92014-01-29 13:25:41 +02005030static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
5031{
Abhay Kumard28d4732016-01-22 17:39:04 -08005032 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02005033 intel_dp->last_power_on = jiffies;
5034 intel_dp->last_backlight_off = jiffies;
5035}
5036
Daniel Vetter67a54562012-10-20 20:57:45 +02005037static void
Imre Deak54648612016-06-16 16:37:22 +03005038intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
5039 struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02005040{
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305041 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03005042 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07005043
Imre Deak8e8232d2016-06-16 16:37:21 +03005044 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02005045
5046 /* Workaround: Need to write PP_CONTROL with the unlock key as
5047 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305048 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02005049
Imre Deak8e8232d2016-06-16 16:37:21 +03005050 pp_on = I915_READ(regs.pp_on);
5051 pp_off = I915_READ(regs.pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005052 if (!IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005053 I915_WRITE(regs.pp_ctrl, pp_ctl);
5054 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305055 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005056
5057 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03005058 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
5059 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005060
Imre Deak54648612016-06-16 16:37:22 +03005061 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
5062 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005063
Imre Deak54648612016-06-16 16:37:22 +03005064 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
5065 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005066
Imre Deak54648612016-06-16 16:37:22 +03005067 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
5068 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005069
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005070 if (IS_GEN9_LP(dev_priv)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305071 u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
5072 BXT_POWER_CYCLE_DELAY_SHIFT;
5073 if (tmp > 0)
Imre Deak54648612016-06-16 16:37:22 +03005074 seq->t11_t12 = (tmp - 1) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305075 else
Imre Deak54648612016-06-16 16:37:22 +03005076 seq->t11_t12 = 0;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305077 } else {
Imre Deak54648612016-06-16 16:37:22 +03005078 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02005079 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305080 }
Imre Deak54648612016-06-16 16:37:22 +03005081}
5082
5083static void
Imre Deakde9c1b62016-06-16 20:01:46 +03005084intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
5085{
5086 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5087 state_name,
5088 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
5089}
5090
5091static void
5092intel_pps_verify_state(struct drm_i915_private *dev_priv,
5093 struct intel_dp *intel_dp)
5094{
5095 struct edp_power_seq hw;
5096 struct edp_power_seq *sw = &intel_dp->pps_delays;
5097
5098 intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
5099
5100 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
5101 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
5102 DRM_ERROR("PPS state mismatch\n");
5103 intel_pps_dump_state("sw", sw);
5104 intel_pps_dump_state("hw", &hw);
5105 }
5106}
5107
5108static void
Imre Deak54648612016-06-16 16:37:22 +03005109intel_dp_init_panel_power_sequencer(struct drm_device *dev,
5110 struct intel_dp *intel_dp)
5111{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005112 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak54648612016-06-16 16:37:22 +03005113 struct edp_power_seq cur, vbt, spec,
5114 *final = &intel_dp->pps_delays;
5115
5116 lockdep_assert_held(&dev_priv->pps_mutex);
5117
5118 /* already initialized? */
5119 if (final->t11_t12 != 0)
5120 return;
5121
5122 intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005123
Imre Deakde9c1b62016-06-16 20:01:46 +03005124 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005125
Jani Nikula6aa23e62016-03-24 17:50:20 +02005126 vbt = dev_priv->vbt.edp.pps;
Daniel Vetter67a54562012-10-20 20:57:45 +02005127
5128 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5129 * our hw here, which are all in 100usec. */
5130 spec.t1_t3 = 210 * 10;
5131 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5132 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5133 spec.t10 = 500 * 10;
5134 /* This one is special and actually in units of 100ms, but zero
5135 * based in the hw (so we need to add 100 ms). But the sw vbt
5136 * table multiplies it with 1000 to make it in units of 100usec,
5137 * too. */
5138 spec.t11_t12 = (510 + 100) * 10;
5139
Imre Deakde9c1b62016-06-16 20:01:46 +03005140 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005141
5142 /* Use the max of the register settings and vbt. If both are
5143 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005144#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005145 spec.field : \
5146 max(cur.field, vbt.field))
5147 assign_final(t1_t3);
5148 assign_final(t8);
5149 assign_final(t9);
5150 assign_final(t10);
5151 assign_final(t11_t12);
5152#undef assign_final
5153
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005154#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005155 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5156 intel_dp->backlight_on_delay = get_delay(t8);
5157 intel_dp->backlight_off_delay = get_delay(t9);
5158 intel_dp->panel_power_down_delay = get_delay(t10);
5159 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5160#undef get_delay
5161
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005162 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5163 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5164 intel_dp->panel_power_cycle_delay);
5165
5166 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5167 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005168
5169 /*
5170 * We override the HW backlight delays to 1 because we do manual waits
5171 * on them. For T8, even BSpec recommends doing it. For T9, if we
5172 * don't do this, we'll end up waiting for the backlight off delay
5173 * twice: once when we do the manual sleep, and once when we disable
5174 * the panel and wait for the PP_STATUS bit to become zero.
5175 */
5176 final->t8 = 1;
5177 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005178}
5179
5180static void
5181intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005182 struct intel_dp *intel_dp,
5183 bool force_disable_vdd)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005184{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005185 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07005186 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005187 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005188 struct pps_registers regs;
Ville Syrjäläad933b52014-08-18 22:15:56 +03005189 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005190 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005191
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005192 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005193
Imre Deak8e8232d2016-06-16 16:37:21 +03005194 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005195
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005196 /*
5197 * On some VLV machines the BIOS can leave the VDD
5198 * enabled even on power seqeuencers which aren't
5199 * hooked up to any port. This would mess up the
5200 * power domain tracking the first time we pick
5201 * one of these power sequencers for use since
5202 * edp_panel_vdd_on() would notice that the VDD was
5203 * already on and therefore wouldn't grab the power
5204 * domain reference. Disable VDD first to avoid this.
5205 * This also avoids spuriously turning the VDD on as
5206 * soon as the new power seqeuencer gets initialized.
5207 */
5208 if (force_disable_vdd) {
5209 u32 pp = ironlake_get_pp_control(intel_dp);
5210
5211 WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
5212
5213 if (pp & EDP_FORCE_VDD)
5214 DRM_DEBUG_KMS("VDD already on, disabling first\n");
5215
5216 pp &= ~EDP_FORCE_VDD;
5217
5218 I915_WRITE(regs.pp_ctrl, pp);
5219 }
5220
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005221 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005222 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5223 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005224 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005225 /* Compute the divisor for the pp clock, simply match the Bspec
5226 * formula. */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005227 if (IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005228 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305229 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
5230 pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
5231 << BXT_POWER_CYCLE_DELAY_SHIFT);
5232 } else {
5233 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5234 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5235 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5236 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005237
5238 /* Haswell doesn't have any port selection bits for the panel
5239 * power sequencer any more. */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005240 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005241 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005242 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005243 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005244 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005245 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005246 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005247 }
5248
Jesse Barnes453c5422013-03-28 09:55:41 -07005249 pp_on |= port_sel;
5250
Imre Deak8e8232d2016-06-16 16:37:21 +03005251 I915_WRITE(regs.pp_on, pp_on);
5252 I915_WRITE(regs.pp_off, pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005253 if (IS_GEN9_LP(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005254 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305255 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005256 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005257
Daniel Vetter67a54562012-10-20 20:57:45 +02005258 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 +03005259 I915_READ(regs.pp_on),
5260 I915_READ(regs.pp_off),
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005261 IS_GEN9_LP(dev_priv) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005262 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5263 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005264}
5265
Imre Deak335f7522016-08-10 14:07:32 +03005266static void intel_dp_pps_init(struct drm_device *dev,
5267 struct intel_dp *intel_dp)
5268{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005269 struct drm_i915_private *dev_priv = to_i915(dev);
5270
5271 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Imre Deak335f7522016-08-10 14:07:32 +03005272 vlv_initial_power_sequencer_setup(intel_dp);
5273 } else {
5274 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005275 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak335f7522016-08-10 14:07:32 +03005276 }
5277}
5278
Vandana Kannanb33a2812015-02-13 15:33:03 +05305279/**
5280 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005281 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005282 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305283 * @refresh_rate: RR to be programmed
5284 *
5285 * This function gets called when refresh rate (RR) has to be changed from
5286 * one frequency to another. Switches can be between high and low RR
5287 * supported by the panel or to any other RR based on media playback (in
5288 * this case, RR value needs to be passed from user space).
5289 *
5290 * The caller of this function needs to take a lock on dev_priv->drrs.
5291 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005292static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
5293 struct intel_crtc_state *crtc_state,
5294 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305295{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305296 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305297 struct intel_digital_port *dig_port = NULL;
5298 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005299 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305300 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305301
5302 if (refresh_rate <= 0) {
5303 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5304 return;
5305 }
5306
Vandana Kannan96178ee2015-01-10 02:25:56 +05305307 if (intel_dp == NULL) {
5308 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305309 return;
5310 }
5311
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005312 /*
Rodrigo Vivie4d59f62014-11-20 02:22:08 -08005313 * FIXME: This needs proper synchronization with psr state for some
5314 * platforms that cannot have PSR and DRRS enabled at the same time.
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005315 */
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305316
Vandana Kannan96178ee2015-01-10 02:25:56 +05305317 dig_port = dp_to_dig_port(intel_dp);
5318 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02005319 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305320
5321 if (!intel_crtc) {
5322 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5323 return;
5324 }
5325
Vandana Kannan96178ee2015-01-10 02:25:56 +05305326 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305327 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5328 return;
5329 }
5330
Vandana Kannan96178ee2015-01-10 02:25:56 +05305331 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5332 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305333 index = DRRS_LOW_RR;
5334
Vandana Kannan96178ee2015-01-10 02:25:56 +05305335 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305336 DRM_DEBUG_KMS(
5337 "DRRS requested for previously set RR...ignoring\n");
5338 return;
5339 }
5340
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005341 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305342 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5343 return;
5344 }
5345
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005346 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305347 switch (index) {
5348 case DRRS_HIGH_RR:
5349 intel_dp_set_m_n(intel_crtc, M1_N1);
5350 break;
5351 case DRRS_LOW_RR:
5352 intel_dp_set_m_n(intel_crtc, M2_N2);
5353 break;
5354 case DRRS_MAX_RR:
5355 default:
5356 DRM_ERROR("Unsupported refreshrate type\n");
5357 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005358 } else if (INTEL_GEN(dev_priv) > 6) {
5359 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005360 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305361
Ville Syrjälä649636e2015-09-22 19:50:01 +03005362 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305363 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005364 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305365 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5366 else
5367 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305368 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005369 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305370 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5371 else
5372 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305373 }
5374 I915_WRITE(reg, val);
5375 }
5376
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305377 dev_priv->drrs.refresh_rate_type = index;
5378
5379 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5380}
5381
Vandana Kannanb33a2812015-02-13 15:33:03 +05305382/**
5383 * intel_edp_drrs_enable - init drrs struct if supported
5384 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005385 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305386 *
5387 * Initializes frontbuffer_bits and drrs.dp
5388 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005389void intel_edp_drrs_enable(struct intel_dp *intel_dp,
5390 struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305391{
5392 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005393 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305394
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005395 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305396 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5397 return;
5398 }
5399
5400 mutex_lock(&dev_priv->drrs.mutex);
5401 if (WARN_ON(dev_priv->drrs.dp)) {
5402 DRM_ERROR("DRRS already enabled\n");
5403 goto unlock;
5404 }
5405
5406 dev_priv->drrs.busy_frontbuffer_bits = 0;
5407
5408 dev_priv->drrs.dp = intel_dp;
5409
5410unlock:
5411 mutex_unlock(&dev_priv->drrs.mutex);
5412}
5413
Vandana Kannanb33a2812015-02-13 15:33:03 +05305414/**
5415 * intel_edp_drrs_disable - Disable DRRS
5416 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005417 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305418 *
5419 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005420void intel_edp_drrs_disable(struct intel_dp *intel_dp,
5421 struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305422{
5423 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005424 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305425
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005426 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305427 return;
5428
5429 mutex_lock(&dev_priv->drrs.mutex);
5430 if (!dev_priv->drrs.dp) {
5431 mutex_unlock(&dev_priv->drrs.mutex);
5432 return;
5433 }
5434
5435 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005436 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5437 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305438
5439 dev_priv->drrs.dp = NULL;
5440 mutex_unlock(&dev_priv->drrs.mutex);
5441
5442 cancel_delayed_work_sync(&dev_priv->drrs.work);
5443}
5444
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305445static void intel_edp_drrs_downclock_work(struct work_struct *work)
5446{
5447 struct drm_i915_private *dev_priv =
5448 container_of(work, typeof(*dev_priv), drrs.work.work);
5449 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305450
Vandana Kannan96178ee2015-01-10 02:25:56 +05305451 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305452
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305453 intel_dp = dev_priv->drrs.dp;
5454
5455 if (!intel_dp)
5456 goto unlock;
5457
5458 /*
5459 * The delayed work can race with an invalidate hence we need to
5460 * recheck.
5461 */
5462
5463 if (dev_priv->drrs.busy_frontbuffer_bits)
5464 goto unlock;
5465
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005466 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5467 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5468
5469 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5470 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5471 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305472
5473unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305474 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305475}
5476
Vandana Kannanb33a2812015-02-13 15:33:03 +05305477/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305478 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005479 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305480 * @frontbuffer_bits: frontbuffer plane tracking bits
5481 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305482 * This function gets called everytime rendering on the given planes start.
5483 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305484 *
5485 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5486 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005487void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5488 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305489{
Vandana Kannana93fad02015-01-10 02:25:59 +05305490 struct drm_crtc *crtc;
5491 enum pipe pipe;
5492
Daniel Vetter9da7d692015-04-09 16:44:15 +02005493 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305494 return;
5495
Daniel Vetter88f933a2015-04-09 16:44:16 +02005496 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305497
Vandana Kannana93fad02015-01-10 02:25:59 +05305498 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005499 if (!dev_priv->drrs.dp) {
5500 mutex_unlock(&dev_priv->drrs.mutex);
5501 return;
5502 }
5503
Vandana Kannana93fad02015-01-10 02:25:59 +05305504 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5505 pipe = to_intel_crtc(crtc)->pipe;
5506
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005507 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5508 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5509
Ramalingam C0ddfd202015-06-15 20:50:05 +05305510 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005511 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005512 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5513 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305514
Vandana Kannana93fad02015-01-10 02:25:59 +05305515 mutex_unlock(&dev_priv->drrs.mutex);
5516}
5517
Vandana Kannanb33a2812015-02-13 15:33:03 +05305518/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305519 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005520 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305521 * @frontbuffer_bits: frontbuffer plane tracking bits
5522 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305523 * This function gets called every time rendering on the given planes has
5524 * completed or flip on a crtc is completed. So DRRS should be upclocked
5525 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5526 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305527 *
5528 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5529 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005530void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5531 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305532{
Vandana Kannana93fad02015-01-10 02:25:59 +05305533 struct drm_crtc *crtc;
5534 enum pipe pipe;
5535
Daniel Vetter9da7d692015-04-09 16:44:15 +02005536 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305537 return;
5538
Daniel Vetter88f933a2015-04-09 16:44:16 +02005539 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305540
Vandana Kannana93fad02015-01-10 02:25:59 +05305541 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005542 if (!dev_priv->drrs.dp) {
5543 mutex_unlock(&dev_priv->drrs.mutex);
5544 return;
5545 }
5546
Vandana Kannana93fad02015-01-10 02:25:59 +05305547 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5548 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005549
5550 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305551 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5552
Ramalingam C0ddfd202015-06-15 20:50:05 +05305553 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005554 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005555 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5556 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305557
5558 /*
5559 * flush also means no more activity hence schedule downclock, if all
5560 * other fbs are quiescent too
5561 */
5562 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305563 schedule_delayed_work(&dev_priv->drrs.work,
5564 msecs_to_jiffies(1000));
5565 mutex_unlock(&dev_priv->drrs.mutex);
5566}
5567
Vandana Kannanb33a2812015-02-13 15:33:03 +05305568/**
5569 * DOC: Display Refresh Rate Switching (DRRS)
5570 *
5571 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5572 * which enables swtching between low and high refresh rates,
5573 * dynamically, based on the usage scenario. This feature is applicable
5574 * for internal panels.
5575 *
5576 * Indication that the panel supports DRRS is given by the panel EDID, which
5577 * would list multiple refresh rates for one resolution.
5578 *
5579 * DRRS is of 2 types - static and seamless.
5580 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5581 * (may appear as a blink on screen) and is used in dock-undock scenario.
5582 * Seamless DRRS involves changing RR without any visual effect to the user
5583 * and can be used during normal system usage. This is done by programming
5584 * certain registers.
5585 *
5586 * Support for static/seamless DRRS may be indicated in the VBT based on
5587 * inputs from the panel spec.
5588 *
5589 * DRRS saves power by switching to low RR based on usage scenarios.
5590 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005591 * The implementation is based on frontbuffer tracking implementation. When
5592 * there is a disturbance on the screen triggered by user activity or a periodic
5593 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5594 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5595 * made.
5596 *
5597 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5598 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305599 *
5600 * DRRS can be further extended to support other internal panels and also
5601 * the scenario of video playback wherein RR is set based on the rate
5602 * requested by userspace.
5603 */
5604
5605/**
5606 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5607 * @intel_connector: eDP connector
5608 * @fixed_mode: preferred mode of panel
5609 *
5610 * This function is called only once at driver load to initialize basic
5611 * DRRS stuff.
5612 *
5613 * Returns:
5614 * Downclock mode if panel supports it, else return NULL.
5615 * DRRS support is determined by the presence of downclock mode (apart
5616 * from VBT setting).
5617 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305618static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305619intel_dp_drrs_init(struct intel_connector *intel_connector,
5620 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305621{
5622 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305623 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005624 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305625 struct drm_display_mode *downclock_mode = NULL;
5626
Daniel Vetter9da7d692015-04-09 16:44:15 +02005627 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5628 mutex_init(&dev_priv->drrs.mutex);
5629
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005630 if (INTEL_GEN(dev_priv) <= 6) {
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305631 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5632 return NULL;
5633 }
5634
5635 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005636 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305637 return NULL;
5638 }
5639
5640 downclock_mode = intel_find_panel_downclock
Mika Kaholaa318b4c2016-12-13 10:02:48 +02005641 (dev_priv, fixed_mode, connector);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305642
5643 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305644 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305645 return NULL;
5646 }
5647
Vandana Kannan96178ee2015-01-10 02:25:56 +05305648 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305649
Vandana Kannan96178ee2015-01-10 02:25:56 +05305650 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005651 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305652 return downclock_mode;
5653}
5654
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005655static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005656 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005657{
5658 struct drm_connector *connector = &intel_connector->base;
5659 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005660 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5661 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005662 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005663 struct drm_display_mode *fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305664 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005665 bool has_dpcd;
5666 struct drm_display_mode *scan;
5667 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005668 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005669
5670 if (!is_edp(intel_dp))
5671 return true;
5672
Imre Deak97a824e12016-06-21 11:51:47 +03005673 /*
5674 * On IBX/CPT we may get here with LVDS already registered. Since the
5675 * driver uses the only internal power sequencer available for both
5676 * eDP and LVDS bail out early in this case to prevent interfering
5677 * with an already powered-on LVDS power sequencer.
5678 */
5679 if (intel_get_lvds_encoder(dev)) {
5680 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5681 DRM_INFO("LVDS was detected, not registering eDP\n");
5682
5683 return false;
5684 }
5685
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005686 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005687
5688 intel_dp_init_panel_power_timestamps(intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +03005689 intel_dp_pps_init(dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005690 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005691
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005692 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005693
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005694 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005695 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005696
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005697 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005698 /* if this fails, presume the device is a ghost */
5699 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005700 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005701 }
5702
Daniel Vetter060c8772014-03-21 23:22:35 +01005703 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005704 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005705 if (edid) {
5706 if (drm_add_edid_modes(connector, edid)) {
5707 drm_mode_connector_update_edid_property(connector,
5708 edid);
5709 drm_edid_to_eld(connector, edid);
5710 } else {
5711 kfree(edid);
5712 edid = ERR_PTR(-EINVAL);
5713 }
5714 } else {
5715 edid = ERR_PTR(-ENOENT);
5716 }
5717 intel_connector->edid = edid;
5718
5719 /* prefer fixed mode from EDID if available */
5720 list_for_each_entry(scan, &connector->probed_modes, head) {
5721 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5722 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305723 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305724 intel_connector, fixed_mode);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005725 break;
5726 }
5727 }
5728
5729 /* fallback to VBT if available for eDP */
5730 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5731 fixed_mode = drm_mode_duplicate(dev,
5732 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005733 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005734 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005735 connector->display_info.width_mm = fixed_mode->width_mm;
5736 connector->display_info.height_mm = fixed_mode->height_mm;
5737 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005738 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005739 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005740
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005741 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005742 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5743 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005744
5745 /*
5746 * Figure out the current pipe for the initial backlight setup.
5747 * If the current pipe isn't valid, try the PPS pipe, and if that
5748 * fails just assume pipe A.
5749 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005750 pipe = vlv_active_pipe(intel_dp);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005751
5752 if (pipe != PIPE_A && pipe != PIPE_B)
5753 pipe = intel_dp->pps_pipe;
5754
5755 if (pipe != PIPE_A && pipe != PIPE_B)
5756 pipe = PIPE_A;
5757
5758 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5759 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005760 }
5761
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305762 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005763 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005764 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005765
5766 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005767
5768out_vdd_off:
5769 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5770 /*
5771 * vdd might still be enabled do to the delayed vdd off.
5772 * Make sure vdd is actually turned off here.
5773 */
5774 pps_lock(intel_dp);
5775 edp_panel_vdd_off_sync(intel_dp);
5776 pps_unlock(intel_dp);
5777
5778 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005779}
5780
Paulo Zanoni16c25532013-06-12 17:27:25 -03005781bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005782intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5783 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005784{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005785 struct drm_connector *connector = &intel_connector->base;
5786 struct intel_dp *intel_dp = &intel_dig_port->dp;
5787 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5788 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005789 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02005790 enum port port = intel_dig_port->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01005791 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005792
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005793 if (WARN(intel_dig_port->max_lanes < 1,
5794 "Not enough lanes (%d) for DP on port %c\n",
5795 intel_dig_port->max_lanes, port_name(port)))
5796 return false;
5797
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005798 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005799 intel_dp->active_pipe = INVALID_PIPE;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005800
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005801 /* intel_dp vfuncs */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005802 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub6b5e382014-01-20 16:00:59 +00005803 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005804 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005805 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005806 else if (HAS_PCH_SPLIT(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005807 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
5808 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005809 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005810
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005811 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00005812 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
5813 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005814 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00005815
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005816 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03005817 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
5818
Daniel Vetter07679352012-09-06 22:15:42 +02005819 /* Preserve the current hw state. */
5820 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03005821 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00005822
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005823 if (intel_dp_is_edp(dev_priv, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05305824 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005825 else
5826 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04005827
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005828 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5829 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5830
Imre Deakf7d24902013-05-08 13:14:05 +03005831 /*
5832 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
5833 * for DP the encoder type can be set by the caller to
5834 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
5835 */
5836 if (type == DRM_MODE_CONNECTOR_eDP)
5837 intel_encoder->type = INTEL_OUTPUT_EDP;
5838
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005839 /* eDP only on port B and/or C on vlv/chv */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005840 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08005841 is_edp(intel_dp) && port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005842 return false;
5843
Imre Deake7281ea2013-05-08 13:14:08 +03005844 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
5845 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
5846 port_name(port));
5847
Adam Jacksonb3295302010-07-16 14:46:28 -04005848 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005849 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
5850
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005851 connector->interlace_allowed = true;
5852 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08005853
Mika Kaholab6339582016-09-09 14:10:52 +03005854 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01005855
Daniel Vetter66a92782012-07-12 20:08:18 +02005856 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01005857 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08005858
Chris Wilsondf0e9242010-09-09 16:20:55 +01005859 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005860
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005861 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02005862 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
5863 else
5864 intel_connector->get_hw_state = intel_connector_get_hw_state;
5865
Jani Nikula0b998362014-03-14 16:51:17 +02005866 /* Set up the hotplug pin. */
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005867 switch (port) {
5868 case PORT_A:
Egbert Eich1d843f92013-02-25 12:06:49 -05005869 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005870 break;
5871 case PORT_B:
Egbert Eich1d843f92013-02-25 12:06:49 -05005872 intel_encoder->hpd_pin = HPD_PORT_B;
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01005873 if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1))
Sonika Jindalcf1d5882015-08-10 10:35:36 +05305874 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005875 break;
5876 case PORT_C:
Egbert Eich1d843f92013-02-25 12:06:49 -05005877 intel_encoder->hpd_pin = HPD_PORT_C;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005878 break;
5879 case PORT_D:
Egbert Eich1d843f92013-02-25 12:06:49 -05005880 intel_encoder->hpd_pin = HPD_PORT_D;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005881 break;
Xiong Zhang26951ca2015-08-17 15:55:50 +08005882 case PORT_E:
5883 intel_encoder->hpd_pin = HPD_PORT_E;
5884 break;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005885 default:
Damien Lespiauad1c0b12013-03-07 15:30:28 +00005886 BUG();
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08005887 }
5888
Dave Airlie0e32b392014-05-02 14:02:48 +10005889 /* init MST on ports that can support it */
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00005890 if (HAS_DP_MST(dev_priv) && !is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03005891 (port == PORT_B || port == PORT_C || port == PORT_D))
5892 intel_dp_mst_encoder_init(intel_dig_port,
5893 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10005894
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005895 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005896 intel_dp_aux_fini(intel_dp);
5897 intel_dp_mst_encoder_cleanup(intel_dig_port);
5898 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03005899 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08005900
Chris Wilsonf6849602010-09-19 09:29:33 +01005901 intel_dp_add_properties(intel_dp, connector);
5902
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005903 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
5904 * 0xd. Failure to do so will result in spurious interrupts being
5905 * generated on the port when a cable is not attached.
5906 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01005907 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005908 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
5909 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
5910 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03005911
5912 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005913
5914fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005915 drm_connector_cleanup(connector);
5916
5917 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005918}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005919
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02005920bool intel_dp_init(struct drm_i915_private *dev_priv,
Chris Wilson457c52d2016-06-01 08:27:50 +01005921 i915_reg_t output_reg,
5922 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005923{
5924 struct intel_digital_port *intel_dig_port;
5925 struct intel_encoder *intel_encoder;
5926 struct drm_encoder *encoder;
5927 struct intel_connector *intel_connector;
5928
Daniel Vetterb14c5672013-09-19 12:18:32 +02005929 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005930 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01005931 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005932
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03005933 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305934 if (!intel_connector)
5935 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005936
5937 intel_encoder = &intel_dig_port->base;
5938 encoder = &intel_encoder->base;
5939
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02005940 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
5941 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
5942 "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305943 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005944
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01005945 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005946 intel_encoder->disable = intel_disable_dp;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005947 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07005948 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03005949 intel_encoder->suspend = intel_dp_encoder_suspend;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005950 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03005951 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03005952 intel_encoder->pre_enable = chv_pre_enable_dp;
5953 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03005954 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03005955 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01005956 } else if (IS_VALLEYVIEW(dev_priv)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03005957 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005958 intel_encoder->pre_enable = vlv_pre_enable_dp;
5959 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03005960 intel_encoder->post_disable = vlv_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005961 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03005962 intel_encoder->pre_enable = g4x_pre_enable_dp;
5963 intel_encoder->enable = g4x_enable_dp;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005964 if (INTEL_GEN(dev_priv) >= 5)
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03005965 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005966 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005967
Paulo Zanoni174edf12012-10-26 19:05:50 -02005968 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005969 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005970 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005971
Ville Syrjäläcca05022016-06-22 21:57:06 +03005972 intel_encoder->type = INTEL_OUTPUT_DP;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005973 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03005974 if (port == PORT_D)
5975 intel_encoder->crtc_mask = 1 << 2;
5976 else
5977 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
5978 } else {
5979 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
5980 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02005981 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07005982 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005983
Dave Airlie13cf5502014-06-18 11:29:35 +10005984 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03005985 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10005986
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305987 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
5988 goto err_init_connector;
5989
Chris Wilson457c52d2016-06-01 08:27:50 +01005990 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305991
5992err_init_connector:
5993 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305994err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305995 kfree(intel_connector);
5996err_connector_alloc:
5997 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01005998 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005999}
Dave Airlie0e32b392014-05-02 14:02:48 +10006000
6001void intel_dp_mst_suspend(struct drm_device *dev)
6002{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006003 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006004 int i;
6005
6006 /* disable MST */
6007 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006008 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006009
6010 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006011 continue;
6012
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006013 if (intel_dig_port->dp.is_mst)
6014 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10006015 }
6016}
6017
6018void intel_dp_mst_resume(struct drm_device *dev)
6019{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006020 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006021 int i;
6022
6023 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006024 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006025 int ret;
6026
6027 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006028 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10006029
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006030 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
6031 if (ret)
6032 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10006033 }
6034}