blob: e72c92a08c81a4b07e6c64a8445d76c88849bdde [file] [log] [blame]
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Keith Packard <keithp@keithp.com>
25 *
26 */
27
28#include <linux/i2c.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040030#include <linux/export.h>
Manasi Navare611032b2017-01-24 08:21:49 -080031#include <linux/types.h>
Clint Taylor01527b32014-07-07 13:01:46 -070032#include <linux/notifier.h>
33#include <linux/reboot.h>
Manasi Navare611032b2017-01-24 08:21:49 -080034#include <asm/byteorder.h>
David Howells760285e2012-10-02 18:01:07 +010035#include <drm/drmP.h>
Matt Roperc6f95f22015-01-22 16:50:32 -080036#include <drm/drm_atomic_helper.h>
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/drm_crtc.h>
38#include <drm/drm_crtc_helper.h>
39#include <drm/drm_edid.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070040#include "intel_drv.h"
David Howells760285e2012-10-02 18:01:07 +010041#include <drm/i915_drm.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070042#include "i915_drv.h"
Keith Packarda4fc5ed2009-04-07 16:16:42 -070043
Keith Packarda4fc5ed2009-04-07 16:16:42 -070044#define DP_LINK_CHECK_TIMEOUT (10 * 1000)
45
Todd Previte559be302015-05-04 07:48:20 -070046/* Compliance test status bits */
47#define INTEL_DP_RESOLUTION_SHIFT_MASK 0
48#define INTEL_DP_RESOLUTION_PREFERRED (1 << INTEL_DP_RESOLUTION_SHIFT_MASK)
49#define INTEL_DP_RESOLUTION_STANDARD (2 << INTEL_DP_RESOLUTION_SHIFT_MASK)
50#define INTEL_DP_RESOLUTION_FAILSAFE (3 << INTEL_DP_RESOLUTION_SHIFT_MASK)
51
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080052struct dp_link_dpll {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030053 int clock;
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080054 struct dpll dpll;
55};
56
57static const struct dp_link_dpll gen4_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030058 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080059 { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030060 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080061 { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
62};
63
64static const struct dp_link_dpll pch_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030065 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080066 { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030067 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080068 { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
69};
70
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080071static const struct dp_link_dpll vlv_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030072 { 162000,
Chon Ming Lee58f6e632013-09-25 15:47:51 +080073 { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030074 { 270000,
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080075 { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } }
76};
77
Chon Ming Leeef9348c2014-04-09 13:28:18 +030078/*
79 * CHV supports eDP 1.4 that have more link rates.
80 * Below only provides the fixed rate but exclude variable rate.
81 */
82static const struct dp_link_dpll chv_dpll[] = {
83 /*
84 * CHV requires to program fractional division for m2.
85 * m2 is stored in fixed point format using formula below
86 * (m2_int << 22) | m2_fraction
87 */
Ville Syrjälä840b32b2015-08-11 20:21:46 +030088 { 162000, /* m2_int = 32, m2_fraction = 1677722 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030089 { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030090 { 270000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030091 { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030092 { 540000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030093 { .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }
94};
Sonika Jindal637a9c62015-05-07 09:52:08 +053095
Sonika Jindal64987fc2015-05-26 17:50:13 +053096static const int bxt_rates[] = { 162000, 216000, 243000, 270000,
97 324000, 432000, 540000 };
Sonika Jindal637a9c62015-05-07 09:52:08 +053098static const int skl_rates[] = { 162000, 216000, 270000,
Ville Syrjäläf4896f12015-03-12 17:10:27 +020099 324000, 432000, 540000 };
100static const int default_rates[] = { 162000, 270000, 540000 };
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300101
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700102/**
103 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
104 * @intel_dp: DP struct
105 *
106 * If a CPU or PCH DP output is attached to an eDP panel, this function
107 * will return true, and false otherwise.
108 */
109static bool is_edp(struct intel_dp *intel_dp)
110{
Paulo Zanonida63a9f2012-10-26 19:05:46 -0200111 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
112
113 return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700114}
115
Imre Deak68b4d822013-05-08 13:14:06 +0300116static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp)
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700117{
Imre Deak68b4d822013-05-08 13:14:06 +0300118 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
119
120 return intel_dig_port->base.base.dev;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700121}
122
Chris Wilsondf0e9242010-09-09 16:20:55 +0100123static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
124{
Paulo Zanonifa90ece2012-10-26 19:05:44 -0200125 return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
Chris Wilsondf0e9242010-09-09 16:20:55 +0100126}
127
Chris Wilsonea5b2132010-08-04 13:50:23 +0100128static void intel_dp_link_down(struct intel_dp *intel_dp);
Ville Syrjälä1e0560e2014-08-19 13:24:25 +0300129static bool edp_panel_vdd_on(struct intel_dp *intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +0100130static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
Ville Syrjälä093e3f12014-10-16 21:27:33 +0300131static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300132static void vlv_steal_power_sequencer(struct drm_device *dev,
133 enum pipe pipe);
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +0530134static void intel_dp_unset_edid(struct intel_dp *intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700135
Ville Syrjäläed4e9c12015-03-12 17:10:36 +0200136static int
137intel_dp_max_link_bw(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700138{
Jesse Barnes7183dc22011-07-07 11:10:58 -0700139 int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700140
141 switch (max_link_bw) {
142 case DP_LINK_BW_1_62:
143 case DP_LINK_BW_2_7:
Ville Syrjälä1db10e22015-03-12 17:10:32 +0200144 case DP_LINK_BW_5_4:
Imre Deakd4eead52013-07-09 17:05:26 +0300145 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700146 default:
Imre Deakd4eead52013-07-09 17:05:26 +0300147 WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
148 max_link_bw);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700149 max_link_bw = DP_LINK_BW_1_62;
150 break;
151 }
152 return max_link_bw;
153}
154
Paulo Zanonieeb63242014-05-06 14:56:50 +0300155static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
156{
157 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300158 u8 source_max, sink_max;
159
Ville Syrjäläccb1a832015-12-08 19:59:38 +0200160 source_max = intel_dig_port->max_lanes;
Manasi Navaref4829842016-12-05 16:27:36 -0800161 sink_max = intel_dp->max_sink_lane_count;
Paulo Zanonieeb63242014-05-06 14:56:50 +0300162
163 return min(source_max, sink_max);
164}
165
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800166int
Keith Packardc8982612012-01-25 08:16:25 -0800167intel_dp_link_required(int pixel_clock, int bpp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700168{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800169 /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
170 return DIV_ROUND_UP(pixel_clock * bpp, 8);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700171}
172
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800173int
Dave Airliefe27d532010-06-30 11:46:17 +1000174intel_dp_max_data_rate(int max_link_clock, int max_lanes)
175{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800176 /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
177 * link rate that is generally expressed in Gbps. Since, 8 bits of data
178 * is transmitted every LS_Clk per lane, there is no need to account for
179 * the channel encoding that is done in the PHY layer here.
180 */
181
182 return max_link_clock * max_lanes;
Dave Airliefe27d532010-06-30 11:46:17 +1000183}
184
Mika Kahola70ec0642016-09-09 14:10:55 +0300185static int
186intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp)
187{
188 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
189 struct intel_encoder *encoder = &intel_dig_port->base;
190 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
191 int max_dotclk = dev_priv->max_dotclk_freq;
192 int ds_max_dotclk;
193
194 int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
195
196 if (type != DP_DS_PORT_TYPE_VGA)
197 return max_dotclk;
198
199 ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd,
200 intel_dp->downstream_ports);
201
202 if (ds_max_dotclk != 0)
203 max_dotclk = min(max_dotclk, ds_max_dotclk);
204
205 return max_dotclk;
206}
207
Navare, Manasi D40dba342016-10-26 16:25:55 -0700208static int
209intel_dp_sink_rates(struct intel_dp *intel_dp, const int **sink_rates)
210{
211 if (intel_dp->num_sink_rates) {
212 *sink_rates = intel_dp->sink_rates;
213 return intel_dp->num_sink_rates;
214 }
215
216 *sink_rates = default_rates;
217
Manasi Navaref4829842016-12-05 16:27:36 -0800218 return (intel_dp->max_sink_link_bw >> 3) + 1;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700219}
220
221static int
222intel_dp_source_rates(struct intel_dp *intel_dp, const int **source_rates)
223{
224 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
225 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
226 int size;
227
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200228 if (IS_GEN9_LP(dev_priv)) {
Navare, Manasi D40dba342016-10-26 16:25:55 -0700229 *source_rates = bxt_rates;
230 size = ARRAY_SIZE(bxt_rates);
Rodrigo Vivib976dc52017-01-23 10:32:37 -0800231 } else if (IS_GEN9_BC(dev_priv)) {
Navare, Manasi D40dba342016-10-26 16:25:55 -0700232 *source_rates = skl_rates;
233 size = ARRAY_SIZE(skl_rates);
234 } else {
235 *source_rates = default_rates;
236 size = ARRAY_SIZE(default_rates);
237 }
238
239 /* This depends on the fact that 5.4 is last value in the array */
240 if (!intel_dp_source_supports_hbr2(intel_dp))
241 size--;
242
243 return size;
244}
245
246static int intersect_rates(const int *source_rates, int source_len,
247 const int *sink_rates, int sink_len,
248 int *common_rates)
249{
250 int i = 0, j = 0, k = 0;
251
252 while (i < source_len && j < sink_len) {
253 if (source_rates[i] == sink_rates[j]) {
254 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
255 return k;
256 common_rates[k] = source_rates[i];
257 ++k;
258 ++i;
259 ++j;
260 } else if (source_rates[i] < sink_rates[j]) {
261 ++i;
262 } else {
263 ++j;
264 }
265 }
266 return k;
267}
268
269static int intel_dp_common_rates(struct intel_dp *intel_dp,
270 int *common_rates)
271{
272 const int *source_rates, *sink_rates;
273 int source_len, sink_len;
274
275 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
276 source_len = intel_dp_source_rates(intel_dp, &source_rates);
277
278 return intersect_rates(source_rates, source_len,
279 sink_rates, sink_len,
280 common_rates);
281}
282
Manasi Navarefdb14d32016-12-08 19:05:12 -0800283static int intel_dp_link_rate_index(struct intel_dp *intel_dp,
284 int *common_rates, int link_rate)
285{
286 int common_len;
287 int index;
288
289 common_len = intel_dp_common_rates(intel_dp, common_rates);
290 for (index = 0; index < common_len; index++) {
291 if (link_rate == common_rates[common_len - index - 1])
292 return common_len - index - 1;
293 }
294
295 return -1;
296}
297
298int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
299 int link_rate, uint8_t lane_count)
300{
301 int common_rates[DP_MAX_SUPPORTED_RATES];
302 int link_rate_index;
303
304 link_rate_index = intel_dp_link_rate_index(intel_dp,
305 common_rates,
306 link_rate);
307 if (link_rate_index > 0) {
308 intel_dp->max_sink_link_bw = drm_dp_link_rate_to_bw_code(common_rates[link_rate_index - 1]);
309 intel_dp->max_sink_lane_count = lane_count;
310 } else if (lane_count > 1) {
311 intel_dp->max_sink_link_bw = intel_dp_max_link_bw(intel_dp);
312 intel_dp->max_sink_lane_count = lane_count >> 1;
313 } else {
314 DRM_ERROR("Link Training Unsuccessful\n");
315 return -1;
316 }
317
318 return 0;
319}
320
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000321static enum drm_mode_status
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700322intel_dp_mode_valid(struct drm_connector *connector,
323 struct drm_display_mode *mode)
324{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100325 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300326 struct intel_connector *intel_connector = to_intel_connector(connector);
327 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Daniel Vetter36008362013-03-27 00:44:59 +0100328 int target_clock = mode->clock;
329 int max_rate, mode_rate, max_lanes, max_link_clock;
Mika Kahola70ec0642016-09-09 14:10:55 +0300330 int max_dotclk;
331
332 max_dotclk = intel_dp_downstream_max_dotclock(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700333
Jani Nikuladd06f902012-10-19 14:51:50 +0300334 if (is_edp(intel_dp) && fixed_mode) {
335 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100336 return MODE_PANEL;
337
Jani Nikuladd06f902012-10-19 14:51:50 +0300338 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100339 return MODE_PANEL;
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200340
341 target_clock = fixed_mode->clock;
Zhao Yakui7de56f42010-07-19 09:43:14 +0100342 }
343
Ville Syrjälä50fec212015-03-12 17:10:34 +0200344 max_link_clock = intel_dp_max_link_rate(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300345 max_lanes = intel_dp_max_lane_count(intel_dp);
Daniel Vetter36008362013-03-27 00:44:59 +0100346
347 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
348 mode_rate = intel_dp_link_required(target_clock, 18);
349
Mika Kahola799487f2016-02-02 15:16:38 +0200350 if (mode_rate > max_rate || target_clock > max_dotclk)
Daniel Vetterc4867932012-04-10 10:42:36 +0200351 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700352
353 if (mode->clock < 10000)
354 return MODE_CLOCK_LOW;
355
Daniel Vetter0af78a22012-05-23 11:30:55 +0200356 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
357 return MODE_H_ILLEGAL;
358
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700359 return MODE_OK;
360}
361
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800362uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700363{
364 int i;
365 uint32_t v = 0;
366
367 if (src_bytes > 4)
368 src_bytes = 4;
369 for (i = 0; i < src_bytes; i++)
370 v |= ((uint32_t) src[i]) << ((3-i) * 8);
371 return v;
372}
373
Damien Lespiauc2af70e2015-02-10 19:32:23 +0000374static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700375{
376 int i;
377 if (dst_bytes > 4)
378 dst_bytes = 4;
379 for (i = 0; i < dst_bytes; i++)
380 dst[i] = src >> ((3-i) * 8);
381}
382
Jani Nikulabf13e812013-09-06 07:40:05 +0300383static void
384intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300385 struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300386static void
387intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200388 struct intel_dp *intel_dp,
389 bool force_disable_vdd);
Imre Deak335f7522016-08-10 14:07:32 +0300390static void
391intel_dp_pps_init(struct drm_device *dev, struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300392
Ville Syrjälä773538e82014-09-04 14:54:56 +0300393static void pps_lock(struct intel_dp *intel_dp)
394{
395 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
396 struct intel_encoder *encoder = &intel_dig_port->base;
397 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100398 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300399 enum intel_display_power_domain power_domain;
400
401 /*
402 * See vlv_power_sequencer_reset() why we need
403 * a power domain reference here.
404 */
Ville Syrjälä25f78f52015-11-16 15:01:04 +0100405 power_domain = intel_display_port_aux_power_domain(encoder);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300406 intel_display_power_get(dev_priv, power_domain);
407
408 mutex_lock(&dev_priv->pps_mutex);
409}
410
411static void pps_unlock(struct intel_dp *intel_dp)
412{
413 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
414 struct intel_encoder *encoder = &intel_dig_port->base;
415 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100416 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300417 enum intel_display_power_domain power_domain;
418
419 mutex_unlock(&dev_priv->pps_mutex);
420
Ville Syrjälä25f78f52015-11-16 15:01:04 +0100421 power_domain = intel_display_port_aux_power_domain(encoder);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300422 intel_display_power_put(dev_priv, power_domain);
423}
424
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300425static void
426vlv_power_sequencer_kick(struct intel_dp *intel_dp)
427{
428 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200429 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300430 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300431 bool pll_enabled, release_cl_override = false;
432 enum dpio_phy phy = DPIO_PHY(pipe);
433 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300434 uint32_t DP;
435
436 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
437 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
438 pipe_name(pipe), port_name(intel_dig_port->port)))
439 return;
440
441 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
442 pipe_name(pipe), port_name(intel_dig_port->port));
443
444 /* Preserve the BIOS-computed detected bit. This is
445 * supposed to be read-only.
446 */
447 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
448 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
449 DP |= DP_PORT_WIDTH(1);
450 DP |= DP_LINK_TRAIN_PAT_1;
451
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100452 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300453 DP |= DP_PIPE_SELECT_CHV(pipe);
454 else if (pipe == PIPE_B)
455 DP |= DP_PIPEB_SELECT;
456
Ville Syrjäläd288f652014-10-28 13:20:22 +0200457 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
458
459 /*
460 * The DPLL for the pipe must be enabled for this to work.
461 * So enable temporarily it if it's not already enabled.
462 */
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300463 if (!pll_enabled) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100464 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300465 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
466
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200467 if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ?
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000468 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
469 DRM_ERROR("Failed to force on pll for pipe %c!\n",
470 pipe_name(pipe));
471 return;
472 }
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300473 }
Ville Syrjäläd288f652014-10-28 13:20:22 +0200474
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300475 /*
476 * Similar magic as in intel_dp_enable_port().
477 * We _must_ do this port enable + disable trick
478 * to make this power seqeuencer lock onto the port.
479 * Otherwise even VDD force bit won't work.
480 */
481 I915_WRITE(intel_dp->output_reg, DP);
482 POSTING_READ(intel_dp->output_reg);
483
484 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
485 POSTING_READ(intel_dp->output_reg);
486
487 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
488 POSTING_READ(intel_dp->output_reg);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200489
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300490 if (!pll_enabled) {
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200491 vlv_force_pll_off(dev_priv, pipe);
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300492
493 if (release_cl_override)
494 chv_phy_powergate_ch(dev_priv, phy, ch, false);
495 }
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300496}
497
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200498static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv)
499{
500 struct intel_encoder *encoder;
501 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
502
503 /*
504 * We don't have power sequencer currently.
505 * Pick one that's not used by other ports.
506 */
507 for_each_intel_encoder(&dev_priv->drm, encoder) {
508 struct intel_dp *intel_dp;
509
510 if (encoder->type != INTEL_OUTPUT_DP &&
511 encoder->type != INTEL_OUTPUT_EDP)
512 continue;
513
514 intel_dp = enc_to_intel_dp(&encoder->base);
515
516 if (encoder->type == INTEL_OUTPUT_EDP) {
517 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
518 intel_dp->active_pipe != intel_dp->pps_pipe);
519
520 if (intel_dp->pps_pipe != INVALID_PIPE)
521 pipes &= ~(1 << intel_dp->pps_pipe);
522 } else {
523 WARN_ON(intel_dp->pps_pipe != INVALID_PIPE);
524
525 if (intel_dp->active_pipe != INVALID_PIPE)
526 pipes &= ~(1 << intel_dp->active_pipe);
527 }
528 }
529
530 if (pipes == 0)
531 return INVALID_PIPE;
532
533 return ffs(pipes) - 1;
534}
535
Jani Nikulabf13e812013-09-06 07:40:05 +0300536static enum pipe
537vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
538{
539 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300540 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100541 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300542 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300543
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300544 lockdep_assert_held(&dev_priv->pps_mutex);
545
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300546 /* We should never land here with regular DP ports */
547 WARN_ON(!is_edp(intel_dp));
548
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200549 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
550 intel_dp->active_pipe != intel_dp->pps_pipe);
551
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300552 if (intel_dp->pps_pipe != INVALID_PIPE)
553 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300554
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200555 pipe = vlv_find_free_pps(dev_priv);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300556
557 /*
558 * Didn't find one. This should not happen since there
559 * are two power sequencers and up to two eDP ports.
560 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200561 if (WARN_ON(pipe == INVALID_PIPE))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300562 pipe = PIPE_A;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300563
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300564 vlv_steal_power_sequencer(dev, pipe);
565 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300566
567 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
568 pipe_name(intel_dp->pps_pipe),
569 port_name(intel_dig_port->port));
570
571 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300572 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200573 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300574
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300575 /*
576 * Even vdd force doesn't work until we've made
577 * the power sequencer lock in on the port.
578 */
579 vlv_power_sequencer_kick(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300580
581 return intel_dp->pps_pipe;
582}
583
Imre Deak78597992016-06-16 16:37:20 +0300584static int
585bxt_power_sequencer_idx(struct intel_dp *intel_dp)
586{
587 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
588 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100589 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak78597992016-06-16 16:37:20 +0300590
591 lockdep_assert_held(&dev_priv->pps_mutex);
592
593 /* We should never land here with regular DP ports */
594 WARN_ON(!is_edp(intel_dp));
595
596 /*
597 * TODO: BXT has 2 PPS instances. The correct port->PPS instance
598 * mapping needs to be retrieved from VBT, for now just hard-code to
599 * use instance #0 always.
600 */
601 if (!intel_dp->pps_reset)
602 return 0;
603
604 intel_dp->pps_reset = false;
605
606 /*
607 * Only the HW needs to be reprogrammed, the SW state is fixed and
608 * has been setup during connector init.
609 */
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200610 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak78597992016-06-16 16:37:20 +0300611
612 return 0;
613}
614
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300615typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
616 enum pipe pipe);
617
618static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
619 enum pipe pipe)
620{
Imre Deak44cb7342016-08-10 14:07:29 +0300621 return I915_READ(PP_STATUS(pipe)) & PP_ON;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300622}
623
624static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
625 enum pipe pipe)
626{
Imre Deak44cb7342016-08-10 14:07:29 +0300627 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300628}
629
630static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
631 enum pipe pipe)
632{
633 return true;
634}
635
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300636static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300637vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
638 enum port port,
639 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300640{
Jani Nikulabf13e812013-09-06 07:40:05 +0300641 enum pipe pipe;
642
Jani Nikulabf13e812013-09-06 07:40:05 +0300643 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
Imre Deak44cb7342016-08-10 14:07:29 +0300644 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
Jani Nikulabf13e812013-09-06 07:40:05 +0300645 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300646
647 if (port_sel != PANEL_PORT_SELECT_VLV(port))
648 continue;
649
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300650 if (!pipe_check(dev_priv, pipe))
651 continue;
652
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300653 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300654 }
655
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300656 return INVALID_PIPE;
657}
658
659static void
660vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
661{
662 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
663 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100664 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300665 enum port port = intel_dig_port->port;
666
667 lockdep_assert_held(&dev_priv->pps_mutex);
668
669 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300670 /* first pick one where the panel is on */
671 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
672 vlv_pipe_has_pp_on);
673 /* didn't find one? pick one where vdd is on */
674 if (intel_dp->pps_pipe == INVALID_PIPE)
675 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
676 vlv_pipe_has_vdd_on);
677 /* didn't find one? pick one with just the correct port */
678 if (intel_dp->pps_pipe == INVALID_PIPE)
679 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
680 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300681
682 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
683 if (intel_dp->pps_pipe == INVALID_PIPE) {
684 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
685 port_name(port));
686 return;
687 }
688
689 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
690 port_name(port), pipe_name(intel_dp->pps_pipe));
691
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300692 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200693 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Jani Nikulabf13e812013-09-06 07:40:05 +0300694}
695
Imre Deak78597992016-06-16 16:37:20 +0300696void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300697{
Chris Wilson91c8a322016-07-05 10:40:23 +0100698 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300699 struct intel_encoder *encoder;
700
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100701 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200702 !IS_GEN9_LP(dev_priv)))
Ville Syrjälä773538e82014-09-04 14:54:56 +0300703 return;
704
705 /*
706 * We can't grab pps_mutex here due to deadlock with power_domain
707 * mutex when power_domain functions are called while holding pps_mutex.
708 * That also means that in order to use pps_pipe the code needs to
709 * hold both a power domain reference and pps_mutex, and the power domain
710 * reference get/put must be done while _not_ holding pps_mutex.
711 * pps_{lock,unlock}() do these steps in the correct order, so one
712 * should use them always.
713 */
714
Jani Nikula19c80542015-12-16 12:48:16 +0200715 for_each_intel_encoder(dev, encoder) {
Ville Syrjälä773538e82014-09-04 14:54:56 +0300716 struct intel_dp *intel_dp;
717
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200718 if (encoder->type != INTEL_OUTPUT_DP &&
719 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300720 continue;
721
722 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200723
724 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
725
726 if (encoder->type != INTEL_OUTPUT_EDP)
727 continue;
728
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200729 if (IS_GEN9_LP(dev_priv))
Imre Deak78597992016-06-16 16:37:20 +0300730 intel_dp->pps_reset = true;
731 else
732 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300733 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300734}
735
Imre Deak8e8232d2016-06-16 16:37:21 +0300736struct pps_registers {
737 i915_reg_t pp_ctrl;
738 i915_reg_t pp_stat;
739 i915_reg_t pp_on;
740 i915_reg_t pp_off;
741 i915_reg_t pp_div;
742};
743
744static void intel_pps_get_registers(struct drm_i915_private *dev_priv,
745 struct intel_dp *intel_dp,
746 struct pps_registers *regs)
747{
Imre Deak44cb7342016-08-10 14:07:29 +0300748 int pps_idx = 0;
749
Imre Deak8e8232d2016-06-16 16:37:21 +0300750 memset(regs, 0, sizeof(*regs));
751
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200752 if (IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300753 pps_idx = bxt_power_sequencer_idx(intel_dp);
754 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
755 pps_idx = vlv_power_sequencer_pipe(intel_dp);
Imre Deak8e8232d2016-06-16 16:37:21 +0300756
Imre Deak44cb7342016-08-10 14:07:29 +0300757 regs->pp_ctrl = PP_CONTROL(pps_idx);
758 regs->pp_stat = PP_STATUS(pps_idx);
759 regs->pp_on = PP_ON_DELAYS(pps_idx);
760 regs->pp_off = PP_OFF_DELAYS(pps_idx);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200761 if (!IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300762 regs->pp_div = PP_DIVISOR(pps_idx);
Imre Deak8e8232d2016-06-16 16:37:21 +0300763}
764
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200765static i915_reg_t
766_pp_ctrl_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300767{
Imre Deak8e8232d2016-06-16 16:37:21 +0300768 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300769
Imre Deak8e8232d2016-06-16 16:37:21 +0300770 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
771 &regs);
772
773 return regs.pp_ctrl;
Jani Nikulabf13e812013-09-06 07:40:05 +0300774}
775
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200776static i915_reg_t
777_pp_stat_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300778{
Imre Deak8e8232d2016-06-16 16:37:21 +0300779 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300780
Imre Deak8e8232d2016-06-16 16:37:21 +0300781 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
782 &regs);
783
784 return regs.pp_stat;
Jani Nikulabf13e812013-09-06 07:40:05 +0300785}
786
Clint Taylor01527b32014-07-07 13:01:46 -0700787/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
788 This function only applicable when panel PM state is not to be tracked */
789static int edp_notify_handler(struct notifier_block *this, unsigned long code,
790 void *unused)
791{
792 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
793 edp_notifier);
794 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100795 struct drm_i915_private *dev_priv = to_i915(dev);
Clint Taylor01527b32014-07-07 13:01:46 -0700796
797 if (!is_edp(intel_dp) || code != SYS_RESTART)
798 return 0;
799
Ville Syrjälä773538e82014-09-04 14:54:56 +0300800 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300801
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100802 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300803 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200804 i915_reg_t pp_ctrl_reg, pp_div_reg;
Ville Syrjälä649636e2015-09-22 19:50:01 +0300805 u32 pp_div;
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300806
Imre Deak44cb7342016-08-10 14:07:29 +0300807 pp_ctrl_reg = PP_CONTROL(pipe);
808 pp_div_reg = PP_DIVISOR(pipe);
Clint Taylor01527b32014-07-07 13:01:46 -0700809 pp_div = I915_READ(pp_div_reg);
810 pp_div &= PP_REFERENCE_DIVIDER_MASK;
811
812 /* 0x1F write to PP_DIV_REG sets max cycle delay */
813 I915_WRITE(pp_div_reg, pp_div | 0x1F);
814 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
815 msleep(intel_dp->panel_power_cycle_delay);
816 }
817
Ville Syrjälä773538e82014-09-04 14:54:56 +0300818 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300819
Clint Taylor01527b32014-07-07 13:01:46 -0700820 return 0;
821}
822
Daniel Vetter4be73782014-01-17 14:39:48 +0100823static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700824{
Paulo Zanoni30add222012-10-26 19:05:45 -0200825 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100826 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700827
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300828 lockdep_assert_held(&dev_priv->pps_mutex);
829
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100830 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300831 intel_dp->pps_pipe == INVALID_PIPE)
832 return false;
833
Jani Nikulabf13e812013-09-06 07:40:05 +0300834 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700835}
836
Daniel Vetter4be73782014-01-17 14:39:48 +0100837static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700838{
Paulo Zanoni30add222012-10-26 19:05:45 -0200839 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100840 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700841
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300842 lockdep_assert_held(&dev_priv->pps_mutex);
843
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100844 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300845 intel_dp->pps_pipe == INVALID_PIPE)
846 return false;
847
Ville Syrjälä773538e82014-09-04 14:54:56 +0300848 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700849}
850
Keith Packard9b984da2011-09-19 13:54:47 -0700851static void
852intel_dp_check_edp(struct intel_dp *intel_dp)
853{
Paulo Zanoni30add222012-10-26 19:05:45 -0200854 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100855 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700856
Keith Packard9b984da2011-09-19 13:54:47 -0700857 if (!is_edp(intel_dp))
858 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700859
Daniel Vetter4be73782014-01-17 14:39:48 +0100860 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700861 WARN(1, "eDP powered off while attempting aux channel communication.\n");
862 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300863 I915_READ(_pp_stat_reg(intel_dp)),
864 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700865 }
866}
867
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100868static uint32_t
869intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
870{
871 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
872 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100873 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200874 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100875 uint32_t status;
876 bool done;
877
Daniel Vetteref04f002012-12-01 21:03:59 +0100878#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100879 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300880 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300881 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100882 else
Imre Deak713a6b662016-06-28 13:37:33 +0300883 done = wait_for(C, 10) == 0;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100884 if (!done)
885 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
886 has_aux_irq);
887#undef C
888
889 return status;
890}
891
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200892static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000893{
894 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200895 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000896
Ville Syrjäläa457f542016-03-02 17:22:17 +0200897 if (index)
898 return 0;
899
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000900 /*
901 * The clock divider is based off the hrawclk, and would like to run at
Ville Syrjäläa457f542016-03-02 17:22:17 +0200902 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000903 */
Ville Syrjäläa457f542016-03-02 17:22:17 +0200904 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000905}
906
907static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
908{
909 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200910 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000911
912 if (index)
913 return 0;
914
Ville Syrjäläa457f542016-03-02 17:22:17 +0200915 /*
916 * The clock divider is based off the cdclk or PCH rawclk, and would
917 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
918 * divide by 2000 and use that
919 */
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200920 if (intel_dig_port->port == PORT_A)
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200921 return DIV_ROUND_CLOSEST(dev_priv->cdclk.hw.cdclk, 2000);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200922 else
923 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000924}
925
926static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300927{
928 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200929 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300930
Ville Syrjäläa457f542016-03-02 17:22:17 +0200931 if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300932 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100933 switch (index) {
934 case 0: return 63;
935 case 1: return 72;
936 default: return 0;
937 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300938 }
Ville Syrjäläa457f542016-03-02 17:22:17 +0200939
940 return ilk_get_aux_clock_divider(intel_dp, index);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300941}
942
Damien Lespiaub6b5e382014-01-20 16:00:59 +0000943static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
944{
945 /*
946 * SKL doesn't need us to program the AUX clock divider (Hardware will
947 * derive the clock from CDCLK automatically). We still implement the
948 * get_aux_clock_divider vfunc to plug-in into the existing code.
949 */
950 return index ? 0 : 1;
951}
952
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200953static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
954 bool has_aux_irq,
955 int send_bytes,
956 uint32_t aux_clock_divider)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000957{
958 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100959 struct drm_i915_private *dev_priv =
960 to_i915(intel_dig_port->base.base.dev);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000961 uint32_t precharge, timeout;
962
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100963 if (IS_GEN6(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000964 precharge = 3;
965 else
966 precharge = 5;
967
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100968 if (IS_BROADWELL(dev_priv) && intel_dig_port->port == PORT_A)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000969 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
970 else
971 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
972
973 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +0000974 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000975 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000976 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000977 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +0000978 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000979 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
980 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000981 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000982}
983
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000984static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
985 bool has_aux_irq,
986 int send_bytes,
987 uint32_t unused)
988{
989 return DP_AUX_CH_CTL_SEND_BUSY |
990 DP_AUX_CH_CTL_DONE |
991 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
992 DP_AUX_CH_CTL_TIME_OUT_ERROR |
993 DP_AUX_CH_CTL_TIME_OUT_1600us |
994 DP_AUX_CH_CTL_RECEIVE_ERROR |
995 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Daniel Vetterd4dcbdc2016-05-18 18:47:15 +0200996 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000997 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
998}
999
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001000static int
Chris Wilsonea5b2132010-08-04 13:50:23 +01001001intel_dp_aux_ch(struct intel_dp *intel_dp,
Daniel Vetterbd9f74a2014-10-02 09:45:35 +02001002 const uint8_t *send, int send_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001003 uint8_t *recv, int recv_size)
1004{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001005 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001006 struct drm_i915_private *dev_priv =
1007 to_i915(intel_dig_port->base.base.dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001008 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Chris Wilsonbc866252013-07-21 16:00:03 +01001009 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001010 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001011 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001012 int try, clock = 0;
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001013 bool has_aux_irq = HAS_AUX_IRQ(dev_priv);
Jani Nikula884f19e2014-03-14 16:51:14 +02001014 bool vdd;
1015
Ville Syrjälä773538e82014-09-04 14:54:56 +03001016 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001017
Ville Syrjälä72c35002014-08-18 22:16:00 +03001018 /*
1019 * We will be called with VDD already enabled for dpcd/edid/oui reads.
1020 * In such cases we want to leave VDD enabled and it's up to upper layers
1021 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
1022 * ourselves.
1023 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001024 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001025
1026 /* dp aux is extremely sensitive to irq latency, hence request the
1027 * lowest possible wakeup latency and so prevent the cpu from going into
1028 * deep sleep states.
1029 */
1030 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001031
Keith Packard9b984da2011-09-19 13:54:47 -07001032 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001033
Jesse Barnes11bee432011-08-01 15:02:20 -07001034 /* Try to wait for any previous AUX channel activity */
1035 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +01001036 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -07001037 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
1038 break;
1039 msleep(1);
1040 }
1041
1042 if (try == 3) {
Mika Kuoppala02196c72015-08-06 16:48:58 +03001043 static u32 last_status = -1;
1044 const u32 status = I915_READ(ch_ctl);
1045
1046 if (status != last_status) {
1047 WARN(1, "dp_aux_ch not started status 0x%08x\n",
1048 status);
1049 last_status = status;
1050 }
1051
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001052 ret = -EBUSY;
1053 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001054 }
1055
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001056 /* Only 5 data registers! */
1057 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
1058 ret = -E2BIG;
1059 goto out;
1060 }
1061
Damien Lespiauec5b01d2014-01-21 13:35:39 +00001062 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +00001063 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
1064 has_aux_irq,
1065 send_bytes,
1066 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001067
Chris Wilsonbc866252013-07-21 16:00:03 +01001068 /* Must try at least 3 times according to DP spec */
1069 for (try = 0; try < 5; try++) {
1070 /* Load the send data into the aux channel data registers */
1071 for (i = 0; i < send_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001072 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001073 intel_dp_pack_aux(send + i,
1074 send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -04001075
Chris Wilsonbc866252013-07-21 16:00:03 +01001076 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001077 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001078
Chris Wilsonbc866252013-07-21 16:00:03 +01001079 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -04001080
Chris Wilsonbc866252013-07-21 16:00:03 +01001081 /* Clear done status and any errors */
1082 I915_WRITE(ch_ctl,
1083 status |
1084 DP_AUX_CH_CTL_DONE |
1085 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1086 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -04001087
Todd Previte74ebf292015-04-15 08:38:41 -07001088 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
Chris Wilsonbc866252013-07-21 16:00:03 +01001089 continue;
Todd Previte74ebf292015-04-15 08:38:41 -07001090
1091 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
1092 * 400us delay required for errors and timeouts
1093 * Timeout errors from the HW already meet this
1094 * requirement so skip to next iteration
1095 */
1096 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1097 usleep_range(400, 500);
1098 continue;
1099 }
Chris Wilsonbc866252013-07-21 16:00:03 +01001100 if (status & DP_AUX_CH_CTL_DONE)
Jim Bridee058c942015-05-27 10:21:48 -07001101 goto done;
Chris Wilsonbc866252013-07-21 16:00:03 +01001102 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001103 }
1104
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001105 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001106 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001107 ret = -EBUSY;
1108 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001109 }
1110
Jim Bridee058c942015-05-27 10:21:48 -07001111done:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001112 /* Check for timeout or receive error.
1113 * Timeouts occur when the sink is not connected
1114 */
Keith Packarda5b3da52009-06-11 22:30:32 -07001115 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001116 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001117 ret = -EIO;
1118 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -07001119 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001120
1121 /* Timeouts occur when the device isn't connected, so they're
1122 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -07001123 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Chris Wilsona5570fe2017-02-23 11:51:02 +00001124 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001125 ret = -ETIMEDOUT;
1126 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001127 }
1128
1129 /* Unload any bytes sent back from the other side */
1130 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
1131 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Rodrigo Vivi14e01882015-12-10 11:12:27 -08001132
1133 /*
1134 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1135 * We have no idea of what happened so we return -EBUSY so
1136 * drm layer takes care for the necessary retries.
1137 */
1138 if (recv_bytes == 0 || recv_bytes > 20) {
1139 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1140 recv_bytes);
1141 /*
1142 * FIXME: This patch was created on top of a series that
1143 * organize the retries at drm level. There EBUSY should
1144 * also take care for 1ms wait before retrying.
1145 * That aux retries re-org is still needed and after that is
1146 * merged we remove this sleep from here.
1147 */
1148 usleep_range(1000, 1500);
1149 ret = -EBUSY;
1150 goto out;
1151 }
1152
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001153 if (recv_bytes > recv_size)
1154 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -04001155
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001156 for (i = 0; i < recv_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001157 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001158 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001159
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001160 ret = recv_bytes;
1161out:
1162 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1163
Jani Nikula884f19e2014-03-14 16:51:14 +02001164 if (vdd)
1165 edp_panel_vdd_off(intel_dp, false);
1166
Ville Syrjälä773538e82014-09-04 14:54:56 +03001167 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001168
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001169 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001170}
1171
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001172#define BARE_ADDRESS_SIZE 3
1173#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +02001174static ssize_t
1175intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001176{
Jani Nikula9d1a1032014-03-14 16:51:15 +02001177 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1178 uint8_t txbuf[20], rxbuf[20];
1179 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001180 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001181
Ville Syrjäläd2d9cbb2015-03-19 11:44:06 +02001182 txbuf[0] = (msg->request << 4) |
1183 ((msg->address >> 16) & 0xf);
1184 txbuf[1] = (msg->address >> 8) & 0xff;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001185 txbuf[2] = msg->address & 0xff;
1186 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001187
Jani Nikula9d1a1032014-03-14 16:51:15 +02001188 switch (msg->request & ~DP_AUX_I2C_MOT) {
1189 case DP_AUX_NATIVE_WRITE:
1190 case DP_AUX_I2C_WRITE:
Ville Syrjäläc1e741222015-08-27 17:23:27 +03001191 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001192 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001193 rxsize = 2; /* 0 or 1 data bytes */
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001194
Jani Nikula9d1a1032014-03-14 16:51:15 +02001195 if (WARN_ON(txsize > 20))
1196 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001197
Ville Syrjälädd788092016-07-28 17:55:04 +03001198 WARN_ON(!msg->buffer != !msg->size);
1199
Imre Deakd81a67c2016-01-29 14:52:26 +02001200 if (msg->buffer)
1201 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001202
Jani Nikula9d1a1032014-03-14 16:51:15 +02001203 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1204 if (ret > 0) {
1205 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001206
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001207 if (ret > 1) {
1208 /* Number of bytes written in a short write. */
1209 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1210 } else {
1211 /* Return payload size. */
1212 ret = msg->size;
1213 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001214 }
Jani Nikula9d1a1032014-03-14 16:51:15 +02001215 break;
1216
1217 case DP_AUX_NATIVE_READ:
1218 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001219 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001220 rxsize = msg->size + 1;
1221
1222 if (WARN_ON(rxsize > 20))
1223 return -E2BIG;
1224
1225 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1226 if (ret > 0) {
1227 msg->reply = rxbuf[0] >> 4;
1228 /*
1229 * Assume happy day, and copy the data. The caller is
1230 * expected to check msg->reply before touching it.
1231 *
1232 * Return payload size.
1233 */
1234 ret--;
1235 memcpy(msg->buffer, rxbuf + 1, ret);
1236 }
1237 break;
1238
1239 default:
1240 ret = -EINVAL;
1241 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001242 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001243
Jani Nikula9d1a1032014-03-14 16:51:15 +02001244 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001245}
1246
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001247static enum port intel_aux_port(struct drm_i915_private *dev_priv,
1248 enum port port)
1249{
1250 const struct ddi_vbt_port_info *info =
1251 &dev_priv->vbt.ddi_port_info[port];
1252 enum port aux_port;
1253
1254 if (!info->alternate_aux_channel) {
1255 DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
1256 port_name(port), port_name(port));
1257 return port;
1258 }
1259
1260 switch (info->alternate_aux_channel) {
1261 case DP_AUX_A:
1262 aux_port = PORT_A;
1263 break;
1264 case DP_AUX_B:
1265 aux_port = PORT_B;
1266 break;
1267 case DP_AUX_C:
1268 aux_port = PORT_C;
1269 break;
1270 case DP_AUX_D:
1271 aux_port = PORT_D;
1272 break;
1273 default:
1274 MISSING_CASE(info->alternate_aux_channel);
1275 aux_port = PORT_A;
1276 break;
1277 }
1278
1279 DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
1280 port_name(aux_port), port_name(port));
1281
1282 return aux_port;
1283}
1284
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001285static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001286 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001287{
1288 switch (port) {
1289 case PORT_B:
1290 case PORT_C:
1291 case PORT_D:
1292 return DP_AUX_CH_CTL(port);
1293 default:
1294 MISSING_CASE(port);
1295 return DP_AUX_CH_CTL(PORT_B);
1296 }
1297}
1298
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001299static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001300 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001301{
1302 switch (port) {
1303 case PORT_B:
1304 case PORT_C:
1305 case PORT_D:
1306 return DP_AUX_CH_DATA(port, index);
1307 default:
1308 MISSING_CASE(port);
1309 return DP_AUX_CH_DATA(PORT_B, index);
1310 }
1311}
1312
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001313static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001314 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001315{
1316 switch (port) {
1317 case PORT_A:
1318 return DP_AUX_CH_CTL(port);
1319 case PORT_B:
1320 case PORT_C:
1321 case PORT_D:
1322 return PCH_DP_AUX_CH_CTL(port);
1323 default:
1324 MISSING_CASE(port);
1325 return DP_AUX_CH_CTL(PORT_A);
1326 }
1327}
1328
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001329static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001330 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001331{
1332 switch (port) {
1333 case PORT_A:
1334 return DP_AUX_CH_DATA(port, index);
1335 case PORT_B:
1336 case PORT_C:
1337 case PORT_D:
1338 return PCH_DP_AUX_CH_DATA(port, index);
1339 default:
1340 MISSING_CASE(port);
1341 return DP_AUX_CH_DATA(PORT_A, index);
1342 }
1343}
1344
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001345static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001346 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001347{
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001348 switch (port) {
1349 case PORT_A:
1350 case PORT_B:
1351 case PORT_C:
1352 case PORT_D:
1353 return DP_AUX_CH_CTL(port);
1354 default:
1355 MISSING_CASE(port);
1356 return DP_AUX_CH_CTL(PORT_A);
1357 }
1358}
1359
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001360static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001361 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001362{
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001363 switch (port) {
1364 case PORT_A:
1365 case PORT_B:
1366 case PORT_C:
1367 case PORT_D:
1368 return DP_AUX_CH_DATA(port, index);
1369 default:
1370 MISSING_CASE(port);
1371 return DP_AUX_CH_DATA(PORT_A, index);
1372 }
1373}
1374
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001375static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001376 enum port port)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001377{
1378 if (INTEL_INFO(dev_priv)->gen >= 9)
1379 return skl_aux_ctl_reg(dev_priv, port);
1380 else if (HAS_PCH_SPLIT(dev_priv))
1381 return ilk_aux_ctl_reg(dev_priv, port);
1382 else
1383 return g4x_aux_ctl_reg(dev_priv, port);
1384}
1385
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001386static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001387 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001388{
1389 if (INTEL_INFO(dev_priv)->gen >= 9)
1390 return skl_aux_data_reg(dev_priv, port, index);
1391 else if (HAS_PCH_SPLIT(dev_priv))
1392 return ilk_aux_data_reg(dev_priv, port, index);
1393 else
1394 return g4x_aux_data_reg(dev_priv, port, index);
1395}
1396
1397static void intel_aux_reg_init(struct intel_dp *intel_dp)
1398{
1399 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001400 enum port port = intel_aux_port(dev_priv,
1401 dp_to_dig_port(intel_dp)->port);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001402 int i;
1403
1404 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1405 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1406 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1407}
1408
Jani Nikula9d1a1032014-03-14 16:51:15 +02001409static void
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001410intel_dp_aux_fini(struct intel_dp *intel_dp)
1411{
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001412 kfree(intel_dp->aux.name);
1413}
1414
Chris Wilson7a418e32016-06-24 14:00:14 +01001415static void
Mika Kaholab6339582016-09-09 14:10:52 +03001416intel_dp_aux_init(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001417{
Jani Nikula33ad6622014-03-14 16:51:16 +02001418 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1419 enum port port = intel_dig_port->port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001420
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001421 intel_aux_reg_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01001422 drm_dp_aux_init(&intel_dp->aux);
David Flynn8316f332010-12-08 16:10:21 +00001423
Chris Wilson7a418e32016-06-24 14:00:14 +01001424 /* Failure to allocate our preferred name is not critical */
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001425 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
Jani Nikula9d1a1032014-03-14 16:51:15 +02001426 intel_dp->aux.transfer = intel_dp_aux_transfer;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001427}
1428
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001429bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301430{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001431 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Navare, Manasi D577c5432016-09-27 16:36:53 -07001432 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001433
Navare, Manasi D577c5432016-09-27 16:36:53 -07001434 if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
1435 IS_BROADWELL(dev_priv) || (INTEL_GEN(dev_priv) >= 9))
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301436 return true;
1437 else
1438 return false;
1439}
1440
Daniel Vetter0e503382014-07-04 11:26:04 -03001441static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001442intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001443 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001444{
1445 struct drm_device *dev = encoder->base.dev;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001446 struct drm_i915_private *dev_priv = to_i915(dev);
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001447 const struct dp_link_dpll *divisor = NULL;
1448 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001449
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001450 if (IS_G4X(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001451 divisor = gen4_dpll;
1452 count = ARRAY_SIZE(gen4_dpll);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001453 } else if (HAS_PCH_SPLIT(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001454 divisor = pch_dpll;
1455 count = ARRAY_SIZE(pch_dpll);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001456 } else if (IS_CHERRYVIEW(dev_priv)) {
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001457 divisor = chv_dpll;
1458 count = ARRAY_SIZE(chv_dpll);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001459 } else if (IS_VALLEYVIEW(dev_priv)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001460 divisor = vlv_dpll;
1461 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001462 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001463
1464 if (divisor && count) {
1465 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001466 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001467 pipe_config->dpll = divisor[i].dpll;
1468 pipe_config->clock_set = true;
1469 break;
1470 }
1471 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001472 }
1473}
1474
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001475static void snprintf_int_array(char *str, size_t len,
1476 const int *array, int nelem)
1477{
1478 int i;
1479
1480 str[0] = '\0';
1481
1482 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001483 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001484 if (r >= len)
1485 return;
1486 str += r;
1487 len -= r;
1488 }
1489}
1490
1491static void intel_dp_print_rates(struct intel_dp *intel_dp)
1492{
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001493 const int *source_rates, *sink_rates;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001494 int source_len, sink_len, common_len;
1495 int common_rates[DP_MAX_SUPPORTED_RATES];
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001496 char str[128]; /* FIXME: too big for stack? */
1497
1498 if ((drm_debug & DRM_UT_KMS) == 0)
1499 return;
1500
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001501 source_len = intel_dp_source_rates(intel_dp, &source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001502 snprintf_int_array(str, sizeof(str), source_rates, source_len);
1503 DRM_DEBUG_KMS("source rates: %s\n", str);
1504
1505 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
1506 snprintf_int_array(str, sizeof(str), sink_rates, sink_len);
1507 DRM_DEBUG_KMS("sink rates: %s\n", str);
1508
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001509 common_len = intel_dp_common_rates(intel_dp, common_rates);
1510 snprintf_int_array(str, sizeof(str), common_rates, common_len);
1511 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001512}
1513
Imre Deak489375c2016-10-24 19:33:31 +03001514bool
Imre Deak7b3fc172016-10-25 16:12:39 +03001515__intel_dp_read_desc(struct intel_dp *intel_dp, struct intel_dp_desc *desc)
Mika Kahola0e390a32016-09-09 14:10:53 +03001516{
Imre Deak7b3fc172016-10-25 16:12:39 +03001517 u32 base = drm_dp_is_branch(intel_dp->dpcd) ? DP_BRANCH_OUI :
1518 DP_SINK_OUI;
Mika Kahola0e390a32016-09-09 14:10:53 +03001519
Imre Deak7b3fc172016-10-25 16:12:39 +03001520 return drm_dp_dpcd_read(&intel_dp->aux, base, desc, sizeof(*desc)) ==
1521 sizeof(*desc);
Mika Kahola0e390a32016-09-09 14:10:53 +03001522}
1523
Imre Deak12a47a422016-10-24 19:33:29 +03001524bool intel_dp_read_desc(struct intel_dp *intel_dp)
Mika Kahola1a2724f2016-09-09 14:10:54 +03001525{
Imre Deak7b3fc172016-10-25 16:12:39 +03001526 struct intel_dp_desc *desc = &intel_dp->desc;
1527 bool oui_sup = intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] &
1528 DP_OUI_SUPPORT;
1529 int dev_id_len;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001530
Imre Deak7b3fc172016-10-25 16:12:39 +03001531 if (!__intel_dp_read_desc(intel_dp, desc))
1532 return false;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001533
Imre Deak7b3fc172016-10-25 16:12:39 +03001534 dev_id_len = strnlen(desc->device_id, sizeof(desc->device_id));
1535 DRM_DEBUG_KMS("DP %s: OUI %*phD%s dev-ID %*pE HW-rev %d.%d SW-rev %d.%d\n",
1536 drm_dp_is_branch(intel_dp->dpcd) ? "branch" : "sink",
1537 (int)sizeof(desc->oui), desc->oui, oui_sup ? "" : "(NS)",
1538 dev_id_len, desc->device_id,
1539 desc->hw_rev >> 4, desc->hw_rev & 0xf,
1540 desc->sw_major_rev, desc->sw_minor_rev);
Mika Kahola1a2724f2016-09-09 14:10:54 +03001541
Imre Deak7b3fc172016-10-25 16:12:39 +03001542 return true;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001543}
1544
Ville Syrjäläf4896f12015-03-12 17:10:27 +02001545static int rate_to_index(int find, const int *rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301546{
1547 int i = 0;
1548
1549 for (i = 0; i < DP_MAX_SUPPORTED_RATES; ++i)
1550 if (find == rates[i])
1551 break;
1552
1553 return i;
1554}
1555
Ville Syrjälä50fec212015-03-12 17:10:34 +02001556int
1557intel_dp_max_link_rate(struct intel_dp *intel_dp)
1558{
1559 int rates[DP_MAX_SUPPORTED_RATES] = {};
1560 int len;
1561
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001562 len = intel_dp_common_rates(intel_dp, rates);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001563 if (WARN_ON(len <= 0))
1564 return 162000;
1565
Ville Syrjälä1354f732016-07-28 17:50:45 +03001566 return rates[len - 1];
Ville Syrjälä50fec212015-03-12 17:10:34 +02001567}
1568
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001569int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1570{
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001571 return rate_to_index(rate, intel_dp->sink_rates);
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001572}
1573
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001574void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1575 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001576{
1577 if (intel_dp->num_sink_rates) {
1578 *link_bw = 0;
1579 *rate_select =
1580 intel_dp_rate_select(intel_dp, port_clock);
1581 } else {
1582 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1583 *rate_select = 0;
1584 }
1585}
1586
Jani Nikulaf580bea2016-09-15 16:28:52 +03001587static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1588 struct intel_crtc_state *pipe_config)
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001589{
1590 int bpp, bpc;
1591
1592 bpp = pipe_config->pipe_bpp;
1593 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1594
1595 if (bpc > 0)
1596 bpp = min(bpp, 3*bpc);
1597
Manasi Navare611032b2017-01-24 08:21:49 -08001598 /* For DP Compliance we override the computed bpp for the pipe */
1599 if (intel_dp->compliance.test_data.bpc != 0) {
1600 pipe_config->pipe_bpp = 3*intel_dp->compliance.test_data.bpc;
1601 pipe_config->dither_force_disable = pipe_config->pipe_bpp == 6*3;
1602 DRM_DEBUG_KMS("Setting pipe_bpp to %d\n",
1603 pipe_config->pipe_bpp);
1604 }
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001605 return bpp;
1606}
1607
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001608bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001609intel_dp_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001610 struct intel_crtc_state *pipe_config,
1611 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001612{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001613 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001614 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001615 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001616 enum port port = dp_to_dig_port(intel_dp)->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001617 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001618 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001619 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001620 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001621 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001622 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001623 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301624 int max_clock;
Manasi Navareda15f7c2017-01-24 08:16:34 -08001625 int link_rate_index;
Daniel Vetter083f9562012-04-20 20:23:49 +02001626 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001627 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001628 int common_rates[DP_MAX_SUPPORTED_RATES] = {};
1629 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001630 uint8_t link_bw, rate_select;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301631
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001632 common_len = intel_dp_common_rates(intel_dp, common_rates);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301633
1634 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001635 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301636
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001637 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001638
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001639 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001640 pipe_config->has_pch_encoder = true;
1641
Vandana Kannanf769cd22014-08-05 07:51:22 -07001642 pipe_config->has_drrs = false;
Jani Nikula9fcb1702015-05-05 16:32:12 +03001643 pipe_config->has_audio = intel_dp->has_audio && port != PORT_A;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001644
Jani Nikuladd06f902012-10-19 14:51:50 +03001645 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1646 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
1647 adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001648
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001649 if (INTEL_GEN(dev_priv) >= 9) {
Chandra Kondurua1b22782015-04-07 15:28:45 -07001650 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001651 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001652 if (ret)
1653 return ret;
1654 }
1655
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001656 if (HAS_GMCH_DISPLAY(dev_priv))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001657 intel_gmch_panel_fitting(intel_crtc, pipe_config,
1658 intel_connector->panel.fitting_mode);
1659 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001660 intel_pch_panel_fitting(intel_crtc, pipe_config,
1661 intel_connector->panel.fitting_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001662 }
1663
Daniel Vettercb1793c2012-06-04 18:39:21 +02001664 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001665 return false;
1666
Manasi Navareda15f7c2017-01-24 08:16:34 -08001667 /* Use values requested by Compliance Test Request */
1668 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
1669 link_rate_index = intel_dp_link_rate_index(intel_dp,
1670 common_rates,
1671 intel_dp->compliance.test_link_rate);
1672 if (link_rate_index >= 0)
1673 min_clock = max_clock = link_rate_index;
1674 min_lane_count = max_lane_count = intel_dp->compliance.test_lane_count;
1675 }
Daniel Vetter083f9562012-04-20 20:23:49 +02001676 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301677 "max bw %d pixel clock %iKHz\n",
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001678 max_lane_count, common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001679 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001680
Daniel Vetter36008362013-03-27 00:44:59 +01001681 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1682 * bpc in between. */
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001683 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
Jani Nikula56071a22014-05-06 14:56:52 +03001684 if (is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301685
1686 /* Get bpp from vbt only for panels that dont have bpp in edid */
1687 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001688 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001689 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001690 dev_priv->vbt.edp.bpp);
1691 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001692 }
1693
Jani Nikula344c5bb2014-09-09 11:25:13 +03001694 /*
1695 * Use the maximum clock and number of lanes the eDP panel
1696 * advertizes being capable of. The panels are generally
1697 * designed to support only a single clock and lane
1698 * configuration, and typically these values correspond to the
1699 * native resolution of the panel.
1700 */
1701 min_lane_count = max_lane_count;
1702 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001703 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001704
Daniel Vetter36008362013-03-27 00:44:59 +01001705 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001706 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1707 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001708
Dave Airliec6930992014-07-14 11:04:39 +10001709 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301710 for (lane_count = min_lane_count;
1711 lane_count <= max_lane_count;
1712 lane_count <<= 1) {
1713
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001714 link_clock = common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001715 link_avail = intel_dp_max_data_rate(link_clock,
1716 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001717
Daniel Vetter36008362013-03-27 00:44:59 +01001718 if (mode_rate <= link_avail) {
1719 goto found;
1720 }
1721 }
1722 }
1723 }
1724
1725 return false;
1726
1727found:
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001728 if (intel_dp->color_range_auto) {
1729 /*
1730 * See:
1731 * CEA-861-E - 5.1 Default Encoding Parameters
1732 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1733 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001734 pipe_config->limited_color_range =
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02001735 bpp != 18 &&
1736 drm_default_rgb_quant_range(adjusted_mode) ==
1737 HDMI_QUANTIZATION_RANGE_LIMITED;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001738 } else {
1739 pipe_config->limited_color_range =
1740 intel_dp->limited_color_range;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001741 }
1742
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001743 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301744
Daniel Vetter657445f2013-05-04 10:09:18 +02001745 pipe_config->pipe_bpp = bpp;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001746 pipe_config->port_clock = common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001747
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001748 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1749 &link_bw, &rate_select);
1750
1751 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1752 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001753 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001754 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1755 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001756
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001757 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001758 adjusted_mode->crtc_clock,
1759 pipe_config->port_clock,
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001760 &pipe_config->dp_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001761
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301762 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301763 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001764 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301765 intel_link_compute_m_n(bpp, lane_count,
1766 intel_connector->panel.downclock_mode->clock,
1767 pipe_config->port_clock,
1768 &pipe_config->dp_m2_n2);
1769 }
1770
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001771 /*
1772 * DPLL0 VCO may need to be adjusted to get the correct
1773 * clock for eDP. This will affect cdclk as well.
1774 */
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001775 if (is_edp(intel_dp) && IS_GEN9_BC(dev_priv)) {
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001776 int vco;
1777
1778 switch (pipe_config->port_clock / 2) {
1779 case 108000:
1780 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001781 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001782 break;
1783 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001784 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001785 break;
1786 }
1787
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +02001788 to_intel_atomic_state(pipe_config->base.state)->cdclk.logical.vco = vco;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001789 }
1790
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001791 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001792 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001793
Daniel Vetter36008362013-03-27 00:44:59 +01001794 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001795}
1796
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001797void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001798 int link_rate, uint8_t lane_count,
1799 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001800{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001801 intel_dp->link_rate = link_rate;
1802 intel_dp->lane_count = lane_count;
1803 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001804}
1805
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001806static void intel_dp_prepare(struct intel_encoder *encoder,
1807 struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001808{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001809 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001810 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001811 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001812 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001813 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001814 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001815
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001816 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1817 pipe_config->lane_count,
1818 intel_crtc_has_type(pipe_config,
1819 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001820
Keith Packard417e8222011-11-01 19:54:11 -07001821 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001822 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001823 *
1824 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001825 * SNB CPU
1826 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001827 * CPT PCH
1828 *
1829 * IBX PCH and CPU are the same for almost everything,
1830 * except that the CPU DP PLL is configured in this
1831 * register
1832 *
1833 * CPT PCH is quite different, having many bits moved
1834 * to the TRANS_DP_CTL register instead. That
1835 * configuration happens (oddly) in ironlake_pch_enable
1836 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001837
Keith Packard417e8222011-11-01 19:54:11 -07001838 /* Preserve the BIOS-computed detected bit. This is
1839 * supposed to be read-only.
1840 */
1841 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001842
Keith Packard417e8222011-11-01 19:54:11 -07001843 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001844 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001845 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001846
Keith Packard417e8222011-11-01 19:54:11 -07001847 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001848
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001849 if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001850 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1851 intel_dp->DP |= DP_SYNC_HS_HIGH;
1852 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1853 intel_dp->DP |= DP_SYNC_VS_HIGH;
1854 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1855
Jani Nikula6aba5b62013-10-04 15:08:10 +03001856 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001857 intel_dp->DP |= DP_ENHANCED_FRAMING;
1858
Daniel Vetter7c62a162013-06-01 17:16:20 +02001859 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001860 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001861 u32 trans_dp;
1862
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001863 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001864
1865 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1866 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1867 trans_dp |= TRANS_DP_ENH_FRAMING;
1868 else
1869 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1870 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001871 } else {
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02001872 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001873 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001874
1875 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1876 intel_dp->DP |= DP_SYNC_HS_HIGH;
1877 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1878 intel_dp->DP |= DP_SYNC_VS_HIGH;
1879 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1880
Jani Nikula6aba5b62013-10-04 15:08:10 +03001881 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001882 intel_dp->DP |= DP_ENHANCED_FRAMING;
1883
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001884 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001885 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001886 else if (crtc->pipe == PIPE_B)
1887 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001888 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001889}
1890
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001891#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1892#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001893
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001894#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1895#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001896
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001897#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1898#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001899
Imre Deakde9c1b62016-06-16 20:01:46 +03001900static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
1901 struct intel_dp *intel_dp);
1902
Daniel Vetter4be73782014-01-17 14:39:48 +01001903static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001904 u32 mask,
1905 u32 value)
1906{
Paulo Zanoni30add222012-10-26 19:05:45 -02001907 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001908 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001909 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001910
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001911 lockdep_assert_held(&dev_priv->pps_mutex);
1912
Imre Deakde9c1b62016-06-16 20:01:46 +03001913 intel_pps_verify_state(dev_priv, intel_dp);
1914
Jani Nikulabf13e812013-09-06 07:40:05 +03001915 pp_stat_reg = _pp_stat_reg(intel_dp);
1916 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001917
1918 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001919 mask, value,
1920 I915_READ(pp_stat_reg),
1921 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001922
Chris Wilson9036ff02016-06-30 15:33:09 +01001923 if (intel_wait_for_register(dev_priv,
1924 pp_stat_reg, mask, value,
1925 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001926 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001927 I915_READ(pp_stat_reg),
1928 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001929
1930 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001931}
1932
Daniel Vetter4be73782014-01-17 14:39:48 +01001933static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001934{
1935 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001936 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001937}
1938
Daniel Vetter4be73782014-01-17 14:39:48 +01001939static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001940{
Keith Packardbd943152011-09-18 23:09:52 -07001941 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001942 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001943}
Keith Packardbd943152011-09-18 23:09:52 -07001944
Daniel Vetter4be73782014-01-17 14:39:48 +01001945static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001946{
Abhay Kumard28d4732016-01-22 17:39:04 -08001947 ktime_t panel_power_on_time;
1948 s64 panel_power_off_duration;
1949
Keith Packard99ea7122011-11-01 19:57:50 -07001950 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001951
Abhay Kumard28d4732016-01-22 17:39:04 -08001952 /* take the difference of currrent time and panel power off time
1953 * and then make panel wait for t11_t12 if needed. */
1954 panel_power_on_time = ktime_get_boottime();
1955 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1956
Paulo Zanonidce56b32013-12-19 14:29:40 -02001957 /* When we disable the VDD override bit last we have to do the manual
1958 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08001959 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
1960 wait_remaining_ms_from_jiffies(jiffies,
1961 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001962
Daniel Vetter4be73782014-01-17 14:39:48 +01001963 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001964}
Keith Packardbd943152011-09-18 23:09:52 -07001965
Daniel Vetter4be73782014-01-17 14:39:48 +01001966static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001967{
1968 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1969 intel_dp->backlight_on_delay);
1970}
1971
Daniel Vetter4be73782014-01-17 14:39:48 +01001972static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001973{
1974 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
1975 intel_dp->backlight_off_delay);
1976}
Keith Packard99ea7122011-11-01 19:57:50 -07001977
Keith Packard832dd3c2011-11-01 19:34:06 -07001978/* Read the current pp_control value, unlocking the register if it
1979 * is locked
1980 */
1981
Jesse Barnes453c5422013-03-28 09:55:41 -07001982static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07001983{
Jesse Barnes453c5422013-03-28 09:55:41 -07001984 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001985 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07001986 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07001987
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001988 lockdep_assert_held(&dev_priv->pps_mutex);
1989
Jani Nikulabf13e812013-09-06 07:40:05 +03001990 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03001991 if (WARN_ON(!HAS_DDI(dev_priv) &&
1992 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05301993 control &= ~PANEL_UNLOCK_MASK;
1994 control |= PANEL_UNLOCK_REGS;
1995 }
Keith Packard832dd3c2011-11-01 19:34:06 -07001996 return control;
Keith Packardbd943152011-09-18 23:09:52 -07001997}
1998
Ville Syrjälä951468f2014-09-04 14:55:31 +03001999/*
2000 * Must be paired with edp_panel_vdd_off().
2001 * Must hold pps_mutex around the whole on/off sequence.
2002 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2003 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03002004static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002005{
Paulo Zanoni30add222012-10-26 19:05:45 -02002006 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002007 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2008 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002009 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002010 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08002011 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002012 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002013 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08002014
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002015 lockdep_assert_held(&dev_priv->pps_mutex);
2016
Keith Packard97af61f572011-09-28 16:23:51 -07002017 if (!is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002018 return false;
Keith Packardbd943152011-09-18 23:09:52 -07002019
Egbert Eich2c623c12014-11-25 12:54:57 +01002020 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002021 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07002022
Daniel Vetter4be73782014-01-17 14:39:48 +01002023 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002024 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002025
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002026 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002027 intel_display_power_get(dev_priv, power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002028
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002029 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
2030 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07002031
Daniel Vetter4be73782014-01-17 14:39:48 +01002032 if (!edp_have_panel_power(intel_dp))
2033 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07002034
Jesse Barnes453c5422013-03-28 09:55:41 -07002035 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002036 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07002037
Jani Nikulabf13e812013-09-06 07:40:05 +03002038 pp_stat_reg = _pp_stat_reg(intel_dp);
2039 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002040
2041 I915_WRITE(pp_ctrl_reg, pp);
2042 POSTING_READ(pp_ctrl_reg);
2043 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2044 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07002045 /*
2046 * If the panel wasn't on, delay before accessing aux channel
2047 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002048 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002049 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
2050 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07002051 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07002052 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002053
2054 return need_to_disable;
2055}
2056
Ville Syrjälä951468f2014-09-04 14:55:31 +03002057/*
2058 * Must be paired with intel_edp_panel_vdd_off() or
2059 * intel_edp_panel_off().
2060 * Nested calls to these functions are not allowed since
2061 * we drop the lock. Caller must use some higher level
2062 * locking to prevent nested calls from other threads.
2063 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01002064void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002065{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002066 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002067
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002068 if (!is_edp(intel_dp))
2069 return;
2070
Ville Syrjälä773538e82014-09-04 14:54:56 +03002071 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002072 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002073 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002074
Rob Clarke2c719b2014-12-15 13:56:32 -05002075 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002076 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08002077}
2078
Daniel Vetter4be73782014-01-17 14:39:48 +01002079static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002080{
Paulo Zanoni30add222012-10-26 19:05:45 -02002081 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002082 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002083 struct intel_digital_port *intel_dig_port =
2084 dp_to_dig_port(intel_dp);
2085 struct intel_encoder *intel_encoder = &intel_dig_port->base;
2086 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08002087 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002088 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002089
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002090 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002091
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002092 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002093
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002094 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002095 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002096
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002097 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2098 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002099
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002100 pp = ironlake_get_pp_control(intel_dp);
2101 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002102
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002103 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2104 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002105
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002106 I915_WRITE(pp_ctrl_reg, pp);
2107 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002108
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002109 /* Make sure sequencer is idle before allowing subsequent activity */
2110 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2111 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002112
Imre Deak5a162e22016-08-10 14:07:30 +03002113 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002114 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002115
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002116 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002117 intel_display_power_put(dev_priv, power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002118}
2119
Daniel Vetter4be73782014-01-17 14:39:48 +01002120static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002121{
2122 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2123 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002124
Ville Syrjälä773538e82014-09-04 14:54:56 +03002125 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002126 if (!intel_dp->want_panel_vdd)
2127 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002128 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002129}
2130
Imre Deakaba86892014-07-30 15:57:31 +03002131static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2132{
2133 unsigned long delay;
2134
2135 /*
2136 * Queue the timer to fire a long time from now (relative to the power
2137 * down delay) to keep the panel power up across a sequence of
2138 * operations.
2139 */
2140 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2141 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2142}
2143
Ville Syrjälä951468f2014-09-04 14:55:31 +03002144/*
2145 * Must be paired with edp_panel_vdd_on().
2146 * Must hold pps_mutex around the whole on/off sequence.
2147 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2148 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002149static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002150{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002151 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002152
2153 lockdep_assert_held(&dev_priv->pps_mutex);
2154
Keith Packard97af61f572011-09-28 16:23:51 -07002155 if (!is_edp(intel_dp))
2156 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002157
Rob Clarke2c719b2014-12-15 13:56:32 -05002158 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002159 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002160
Keith Packardbd943152011-09-18 23:09:52 -07002161 intel_dp->want_panel_vdd = false;
2162
Imre Deakaba86892014-07-30 15:57:31 +03002163 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002164 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002165 else
2166 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002167}
2168
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002169static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002170{
Paulo Zanoni30add222012-10-26 19:05:45 -02002171 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002172 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002173 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002174 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002175
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002176 lockdep_assert_held(&dev_priv->pps_mutex);
2177
Keith Packard97af61f572011-09-28 16:23:51 -07002178 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002179 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002180
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002181 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2182 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002183
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002184 if (WARN(edp_have_panel_power(intel_dp),
2185 "eDP port %c panel power already on\n",
2186 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002187 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002188
Daniel Vetter4be73782014-01-17 14:39:48 +01002189 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002190
Jani Nikulabf13e812013-09-06 07:40:05 +03002191 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002192 pp = ironlake_get_pp_control(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002193 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002194 /* ILK workaround: disable reset around power sequence */
2195 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002196 I915_WRITE(pp_ctrl_reg, pp);
2197 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002198 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002199
Imre Deak5a162e22016-08-10 14:07:30 +03002200 pp |= PANEL_POWER_ON;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002201 if (!IS_GEN5(dev_priv))
Keith Packard99ea7122011-11-01 19:57:50 -07002202 pp |= PANEL_POWER_RESET;
2203
Jesse Barnes453c5422013-03-28 09:55:41 -07002204 I915_WRITE(pp_ctrl_reg, pp);
2205 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002206
Daniel Vetter4be73782014-01-17 14:39:48 +01002207 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002208 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002209
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002210 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002211 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002212 I915_WRITE(pp_ctrl_reg, pp);
2213 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002214 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002215}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002216
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002217void intel_edp_panel_on(struct intel_dp *intel_dp)
2218{
2219 if (!is_edp(intel_dp))
2220 return;
2221
2222 pps_lock(intel_dp);
2223 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002224 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002225}
2226
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002227
2228static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002229{
Imre Deak4e6e1a52014-03-27 17:45:11 +02002230 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2231 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanoni30add222012-10-26 19:05:45 -02002232 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002233 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002234 enum intel_display_power_domain power_domain;
Keith Packard99ea7122011-11-01 19:57:50 -07002235 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002236 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002237
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002238 lockdep_assert_held(&dev_priv->pps_mutex);
2239
Keith Packard97af61f572011-09-28 16:23:51 -07002240 if (!is_edp(intel_dp))
2241 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002242
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002243 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2244 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002245
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002246 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2247 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002248
Jesse Barnes453c5422013-03-28 09:55:41 -07002249 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002250 /* We need to switch off panel power _and_ force vdd, for otherwise some
2251 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002252 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002253 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002254
Jani Nikulabf13e812013-09-06 07:40:05 +03002255 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002256
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002257 intel_dp->want_panel_vdd = false;
2258
Jesse Barnes453c5422013-03-28 09:55:41 -07002259 I915_WRITE(pp_ctrl_reg, pp);
2260 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002261
Abhay Kumard28d4732016-01-22 17:39:04 -08002262 intel_dp->panel_power_off_time = ktime_get_boottime();
Daniel Vetter4be73782014-01-17 14:39:48 +01002263 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002264
2265 /* We got a reference when we enabled the VDD. */
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002266 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002267 intel_display_power_put(dev_priv, power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002268}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002269
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002270void intel_edp_panel_off(struct intel_dp *intel_dp)
2271{
2272 if (!is_edp(intel_dp))
2273 return;
2274
2275 pps_lock(intel_dp);
2276 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002277 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002278}
2279
Jani Nikula1250d102014-08-12 17:11:39 +03002280/* Enable backlight in the panel power control. */
2281static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002282{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002283 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2284 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002285 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002286 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002287 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002288
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002289 /*
2290 * If we enable the backlight right away following a panel power
2291 * on, we may see slight flicker as the panel syncs with the eDP
2292 * link. So delay a bit to make sure the image is solid before
2293 * allowing it to appear.
2294 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002295 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002296
Ville Syrjälä773538e82014-09-04 14:54:56 +03002297 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002298
Jesse Barnes453c5422013-03-28 09:55:41 -07002299 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002300 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002301
Jani Nikulabf13e812013-09-06 07:40:05 +03002302 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002303
2304 I915_WRITE(pp_ctrl_reg, pp);
2305 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002306
Ville Syrjälä773538e82014-09-04 14:54:56 +03002307 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002308}
2309
Jani Nikula1250d102014-08-12 17:11:39 +03002310/* Enable backlight PWM and backlight PP control. */
2311void intel_edp_backlight_on(struct intel_dp *intel_dp)
2312{
2313 if (!is_edp(intel_dp))
2314 return;
2315
2316 DRM_DEBUG_KMS("\n");
2317
2318 intel_panel_enable_backlight(intel_dp->attached_connector);
2319 _intel_edp_backlight_on(intel_dp);
2320}
2321
2322/* Disable backlight in the panel power control. */
2323static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002324{
Paulo Zanoni30add222012-10-26 19:05:45 -02002325 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002326 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002327 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002328 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002329
Keith Packardf01eca22011-09-28 16:48:10 -07002330 if (!is_edp(intel_dp))
2331 return;
2332
Ville Syrjälä773538e82014-09-04 14:54:56 +03002333 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002334
Jesse Barnes453c5422013-03-28 09:55:41 -07002335 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002336 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002337
Jani Nikulabf13e812013-09-06 07:40:05 +03002338 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002339
2340 I915_WRITE(pp_ctrl_reg, pp);
2341 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002342
Ville Syrjälä773538e82014-09-04 14:54:56 +03002343 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002344
Paulo Zanonidce56b32013-12-19 14:29:40 -02002345 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002346 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002347}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002348
Jani Nikula1250d102014-08-12 17:11:39 +03002349/* Disable backlight PP control and backlight PWM. */
2350void intel_edp_backlight_off(struct intel_dp *intel_dp)
2351{
2352 if (!is_edp(intel_dp))
2353 return;
2354
2355 DRM_DEBUG_KMS("\n");
2356
2357 _intel_edp_backlight_off(intel_dp);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002358 intel_panel_disable_backlight(intel_dp->attached_connector);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002359}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002360
Jani Nikula73580fb72014-08-12 17:11:41 +03002361/*
2362 * Hook for controlling the panel power control backlight through the bl_power
2363 * sysfs attribute. Take care to handle multiple calls.
2364 */
2365static void intel_edp_backlight_power(struct intel_connector *connector,
2366 bool enable)
2367{
2368 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002369 bool is_enabled;
2370
Ville Syrjälä773538e82014-09-04 14:54:56 +03002371 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002372 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002373 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002374
2375 if (is_enabled == enable)
2376 return;
2377
Jani Nikula23ba9372014-08-27 14:08:43 +03002378 DRM_DEBUG_KMS("panel power control backlight %s\n",
2379 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002380
2381 if (enable)
2382 _intel_edp_backlight_on(intel_dp);
2383 else
2384 _intel_edp_backlight_off(intel_dp);
2385}
2386
Ville Syrjälä64e10772015-10-29 21:26:01 +02002387static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2388{
2389 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2390 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2391 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2392
2393 I915_STATE_WARN(cur_state != state,
2394 "DP port %c state assertion failure (expected %s, current %s)\n",
2395 port_name(dig_port->port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002396 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002397}
2398#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2399
2400static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2401{
2402 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2403
2404 I915_STATE_WARN(cur_state != state,
2405 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002406 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002407}
2408#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2409#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2410
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002411static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2412 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002413{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002414 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002415 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002416
Ville Syrjälä64e10772015-10-29 21:26:01 +02002417 assert_pipe_disabled(dev_priv, crtc->pipe);
2418 assert_dp_port_disabled(intel_dp);
2419 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002420
Ville Syrjäläabfce942015-10-29 21:26:03 +02002421 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002422 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002423
2424 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2425
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002426 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002427 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2428 else
2429 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2430
2431 I915_WRITE(DP_A, intel_dp->DP);
2432 POSTING_READ(DP_A);
2433 udelay(500);
2434
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002435 /*
2436 * [DevILK] Work around required when enabling DP PLL
2437 * while a pipe is enabled going to FDI:
2438 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2439 * 2. Program DP PLL enable
2440 */
2441 if (IS_GEN5(dev_priv))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02002442 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002443
Daniel Vetter07679352012-09-06 22:15:42 +02002444 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002445
Daniel Vetter07679352012-09-06 22:15:42 +02002446 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002447 POSTING_READ(DP_A);
2448 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002449}
2450
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002451static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002452{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002453 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002454 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2455 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002456
Ville Syrjälä64e10772015-10-29 21:26:01 +02002457 assert_pipe_disabled(dev_priv, crtc->pipe);
2458 assert_dp_port_disabled(intel_dp);
2459 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002460
Ville Syrjäläabfce942015-10-29 21:26:03 +02002461 DRM_DEBUG_KMS("disabling eDP PLL\n");
2462
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002463 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002464
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002465 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002466 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002467 udelay(200);
2468}
2469
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002470/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002471void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002472{
2473 int ret, i;
2474
2475 /* Should have a valid DPCD by this point */
2476 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2477 return;
2478
2479 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002480 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2481 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002482 } else {
Imre Deak357c0ae2016-11-21 21:15:06 +02002483 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
2484
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002485 /*
2486 * When turning on, we need to retry for 1ms to give the sink
2487 * time to wake up.
2488 */
2489 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002490 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2491 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002492 if (ret == 1)
2493 break;
2494 msleep(1);
2495 }
Imre Deak357c0ae2016-11-21 21:15:06 +02002496
2497 if (ret == 1 && lspcon->active)
2498 lspcon_wait_pcon_mode(lspcon);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002499 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002500
2501 if (ret != 1)
2502 DRM_DEBUG_KMS("failed to %s sink power state\n",
2503 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002504}
2505
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002506static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2507 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002508{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002509 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002510 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002511 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002512 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002513 enum intel_display_power_domain power_domain;
2514 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002515 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002516
2517 power_domain = intel_display_port_power_domain(encoder);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002518 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002519 return false;
2520
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002521 ret = false;
2522
Imre Deak6d129be2014-03-05 16:20:54 +02002523 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002524
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002525 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002526 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002527
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002528 if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002529 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002530 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002531 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002532
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002533 for_each_pipe(dev_priv, p) {
2534 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2535 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2536 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002537 ret = true;
2538
2539 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002540 }
2541 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002542
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002543 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002544 i915_mmio_reg_offset(intel_dp->output_reg));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002545 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002546 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2547 } else {
2548 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002549 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002550
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002551 ret = true;
2552
2553out:
2554 intel_display_power_put(dev_priv, power_domain);
2555
2556 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002557}
2558
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002559static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002560 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002561{
2562 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002563 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002564 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002565 struct drm_i915_private *dev_priv = to_i915(dev);
Xiong Zhang63000ef2013-06-28 12:59:06 +08002566 enum port port = dp_to_dig_port(intel_dp)->port;
2567 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002568
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002569 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002570
2571 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002572
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002573 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002574 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2575
2576 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002577 flags |= DRM_MODE_FLAG_PHSYNC;
2578 else
2579 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002580
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002581 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002582 flags |= DRM_MODE_FLAG_PVSYNC;
2583 else
2584 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002585 } else {
2586 if (tmp & DP_SYNC_HS_HIGH)
2587 flags |= DRM_MODE_FLAG_PHSYNC;
2588 else
2589 flags |= DRM_MODE_FLAG_NHSYNC;
2590
2591 if (tmp & DP_SYNC_VS_HIGH)
2592 flags |= DRM_MODE_FLAG_PVSYNC;
2593 else
2594 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002595 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002596
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002597 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002598
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02002599 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002600 pipe_config->limited_color_range = true;
2601
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002602 pipe_config->lane_count =
2603 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2604
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002605 intel_dp_get_m_n(crtc, pipe_config);
2606
Ville Syrjälä18442d02013-09-13 16:00:08 +03002607 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002608 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002609 pipe_config->port_clock = 162000;
2610 else
2611 pipe_config->port_clock = 270000;
2612 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002613
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002614 pipe_config->base.adjusted_mode.crtc_clock =
2615 intel_dotclock_calculate(pipe_config->port_clock,
2616 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002617
Jani Nikula6aa23e62016-03-24 17:50:20 +02002618 if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
2619 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002620 /*
2621 * This is a big fat ugly hack.
2622 *
2623 * Some machines in UEFI boot mode provide us a VBT that has 18
2624 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2625 * unknown we fail to light up. Yet the same BIOS boots up with
2626 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2627 * max, not what it tells us to use.
2628 *
2629 * Note: This will still be broken if the eDP panel is not lit
2630 * up by the BIOS, and thus we can't get the mode at module
2631 * load.
2632 */
2633 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002634 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2635 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002636 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002637}
2638
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002639static void intel_disable_dp(struct intel_encoder *encoder,
2640 struct intel_crtc_state *old_crtc_state,
2641 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002642{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002643 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002644 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002645
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002646 if (old_crtc_state->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002647 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002648
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002649 if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv))
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002650 intel_psr_disable(intel_dp);
2651
Daniel Vetter6cb49832012-05-20 17:14:50 +02002652 /* Make sure the panel is off before trying to change the mode. But also
2653 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002654 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01002655 intel_edp_backlight_off(intel_dp);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002656 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002657 intel_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02002658
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002659 /* disable the port before the pipe on g4x */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002660 if (INTEL_GEN(dev_priv) < 5)
Daniel Vetter37398502012-09-06 22:15:44 +02002661 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07002662}
2663
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002664static void ilk_post_disable_dp(struct intel_encoder *encoder,
2665 struct intel_crtc_state *old_crtc_state,
2666 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002667{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002668 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002669 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002670
Ville Syrjälä49277c32014-03-31 18:21:26 +03002671 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002672
2673 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002674 if (port == PORT_A)
2675 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002676}
2677
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002678static void vlv_post_disable_dp(struct intel_encoder *encoder,
2679 struct intel_crtc_state *old_crtc_state,
2680 struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002681{
2682 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2683
2684 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002685}
2686
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002687static void chv_post_disable_dp(struct intel_encoder *encoder,
2688 struct intel_crtc_state *old_crtc_state,
2689 struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002690{
2691 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002692 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002693 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002694
2695 intel_dp_link_down(intel_dp);
2696
Ville Syrjäläa5805162015-05-26 20:42:30 +03002697 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002698
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002699 /* Assert data lane reset */
2700 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002701
Ville Syrjäläa5805162015-05-26 20:42:30 +03002702 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002703}
2704
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002705static void
2706_intel_dp_set_link_train(struct intel_dp *intel_dp,
2707 uint32_t *DP,
2708 uint8_t dp_train_pat)
2709{
2710 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2711 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002712 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002713 enum port port = intel_dig_port->port;
2714
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002715 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2716 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2717 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2718
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002719 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002720 uint32_t temp = I915_READ(DP_TP_CTL(port));
2721
2722 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2723 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2724 else
2725 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2726
2727 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2728 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2729 case DP_TRAINING_PATTERN_DISABLE:
2730 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2731
2732 break;
2733 case DP_TRAINING_PATTERN_1:
2734 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2735 break;
2736 case DP_TRAINING_PATTERN_2:
2737 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2738 break;
2739 case DP_TRAINING_PATTERN_3:
2740 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2741 break;
2742 }
2743 I915_WRITE(DP_TP_CTL(port), temp);
2744
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002745 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002746 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002747 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2748
2749 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2750 case DP_TRAINING_PATTERN_DISABLE:
2751 *DP |= DP_LINK_TRAIN_OFF_CPT;
2752 break;
2753 case DP_TRAINING_PATTERN_1:
2754 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2755 break;
2756 case DP_TRAINING_PATTERN_2:
2757 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2758 break;
2759 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002760 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002761 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2762 break;
2763 }
2764
2765 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002766 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002767 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2768 else
2769 *DP &= ~DP_LINK_TRAIN_MASK;
2770
2771 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2772 case DP_TRAINING_PATTERN_DISABLE:
2773 *DP |= DP_LINK_TRAIN_OFF;
2774 break;
2775 case DP_TRAINING_PATTERN_1:
2776 *DP |= DP_LINK_TRAIN_PAT_1;
2777 break;
2778 case DP_TRAINING_PATTERN_2:
2779 *DP |= DP_LINK_TRAIN_PAT_2;
2780 break;
2781 case DP_TRAINING_PATTERN_3:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002782 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002783 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2784 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002785 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002786 *DP |= DP_LINK_TRAIN_PAT_2;
2787 }
2788 break;
2789 }
2790 }
2791}
2792
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002793static void intel_dp_enable_port(struct intel_dp *intel_dp,
2794 struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002795{
2796 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002797 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002798
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002799 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002800
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002801 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002802
2803 /*
2804 * Magic for VLV/CHV. We _must_ first set up the register
2805 * without actually enabling the port, and then do another
2806 * write to enable the port. Otherwise link training will
2807 * fail when the power sequencer is freshly used for this port.
2808 */
2809 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002810 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002811 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002812
2813 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2814 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002815}
2816
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002817static void intel_enable_dp(struct intel_encoder *encoder,
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002818 struct intel_crtc_state *pipe_config,
2819 struct drm_connector_state *conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002820{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002821 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2822 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002823 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulac1dec792014-10-27 16:26:56 +02002824 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002825 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002826 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002827
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002828 if (WARN_ON(dp_reg & DP_PORT_EN))
2829 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002830
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002831 pps_lock(intel_dp);
2832
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002833 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002834 vlv_init_panel_power_sequencer(intel_dp);
2835
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002836 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002837
2838 edp_panel_vdd_on(intel_dp);
2839 edp_panel_on(intel_dp);
2840 edp_panel_vdd_off(intel_dp, true);
2841
2842 pps_unlock(intel_dp);
2843
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002844 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002845 unsigned int lane_mask = 0x0;
2846
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002847 if (IS_CHERRYVIEW(dev_priv))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002848 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002849
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002850 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2851 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002852 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002853
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002854 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2855 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002856 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002857
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002858 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002859 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002860 pipe_name(pipe));
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002861 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Jani Nikulac1dec792014-10-27 16:26:56 +02002862 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002863}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002864
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002865static void g4x_enable_dp(struct intel_encoder *encoder,
2866 struct intel_crtc_state *pipe_config,
2867 struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03002868{
Jani Nikula828f5c62013-09-05 16:44:45 +03002869 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2870
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002871 intel_enable_dp(encoder, pipe_config, conn_state);
Daniel Vetter4be73782014-01-17 14:39:48 +01002872 intel_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002873}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002874
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002875static void vlv_enable_dp(struct intel_encoder *encoder,
2876 struct intel_crtc_state *pipe_config,
2877 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002878{
Jani Nikula828f5c62013-09-05 16:44:45 +03002879 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2880
Daniel Vetter4be73782014-01-17 14:39:48 +01002881 intel_edp_backlight_on(intel_dp);
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002882 intel_psr_enable(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002883}
2884
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002885static void g4x_pre_enable_dp(struct intel_encoder *encoder,
2886 struct intel_crtc_state *pipe_config,
2887 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002888{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002889 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002890 enum port port = dp_to_dig_port(intel_dp)->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002891
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002892 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002893
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002894 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002895 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002896 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002897}
2898
Ville Syrjälä83b84592014-10-16 21:29:51 +03002899static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2900{
2901 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002902 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002903 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03002904 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002905
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002906 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
2907
Ville Syrjäläd1586942017-02-08 19:52:54 +02002908 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2909 return;
2910
Ville Syrjälä83b84592014-10-16 21:29:51 +03002911 edp_panel_vdd_off_sync(intel_dp);
2912
2913 /*
2914 * VLV seems to get confused when multiple power seqeuencers
2915 * have the same port selected (even if only one has power/vdd
2916 * enabled). The failure manifests as vlv_wait_port_ready() failing
2917 * CHV on the other hand doesn't seem to mind having the same port
2918 * selected in multiple power seqeuencers, but let's clear the
2919 * port select always when logically disconnecting a power sequencer
2920 * from a port.
2921 */
2922 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2923 pipe_name(pipe), port_name(intel_dig_port->port));
2924 I915_WRITE(pp_on_reg, 0);
2925 POSTING_READ(pp_on_reg);
2926
2927 intel_dp->pps_pipe = INVALID_PIPE;
2928}
2929
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002930static void vlv_steal_power_sequencer(struct drm_device *dev,
2931 enum pipe pipe)
2932{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002933 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002934 struct intel_encoder *encoder;
2935
2936 lockdep_assert_held(&dev_priv->pps_mutex);
2937
Jani Nikula19c80542015-12-16 12:48:16 +02002938 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002939 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002940 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002941
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002942 if (encoder->type != INTEL_OUTPUT_DP &&
2943 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002944 continue;
2945
2946 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002947 port = dp_to_dig_port(intel_dp)->port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002948
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002949 WARN(intel_dp->active_pipe == pipe,
2950 "stealing pipe %c power sequencer from active (e)DP port %c\n",
2951 pipe_name(pipe), port_name(port));
2952
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002953 if (intel_dp->pps_pipe != pipe)
2954 continue;
2955
2956 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03002957 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002958
2959 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002960 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002961 }
2962}
2963
2964static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
2965{
2966 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2967 struct intel_encoder *encoder = &intel_dig_port->base;
2968 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002969 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002970 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002971
2972 lockdep_assert_held(&dev_priv->pps_mutex);
2973
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002974 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002975
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002976 if (intel_dp->pps_pipe != INVALID_PIPE &&
2977 intel_dp->pps_pipe != crtc->pipe) {
2978 /*
2979 * If another power sequencer was being used on this
2980 * port previously make sure to turn off vdd there while
2981 * we still have control of it.
2982 */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002983 vlv_detach_power_sequencer(intel_dp);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002984 }
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002985
2986 /*
2987 * We may be stealing the power
2988 * sequencer from another port.
2989 */
2990 vlv_steal_power_sequencer(dev, crtc->pipe);
2991
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002992 intel_dp->active_pipe = crtc->pipe;
2993
2994 if (!is_edp(intel_dp))
2995 return;
2996
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002997 /* now it's all ours */
2998 intel_dp->pps_pipe = crtc->pipe;
2999
3000 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
3001 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
3002
3003 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03003004 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02003005 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003006}
3007
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003008static void vlv_pre_enable_dp(struct intel_encoder *encoder,
3009 struct intel_crtc_state *pipe_config,
3010 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03003011{
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03003012 vlv_phy_pre_encoder_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003013
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003014 intel_enable_dp(encoder, pipe_config, conn_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003015}
3016
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003017static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
3018 struct intel_crtc_state *pipe_config,
3019 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07003020{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003021 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02003022
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03003023 vlv_phy_pre_pll_enable(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003024}
3025
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003026static void chv_pre_enable_dp(struct intel_encoder *encoder,
3027 struct intel_crtc_state *pipe_config,
3028 struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003029{
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003030 chv_phy_pre_encoder_enable(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003031
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003032 intel_enable_dp(encoder, pipe_config, conn_state);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03003033
3034 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003035 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003036}
3037
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003038static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
3039 struct intel_crtc_state *pipe_config,
3040 struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03003041{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003042 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03003043
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03003044 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03003045}
3046
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003047static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
3048 struct intel_crtc_state *pipe_config,
3049 struct drm_connector_state *conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003050{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03003051 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003052}
3053
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003054/*
3055 * Fetch AUX CH registers 0x202 - 0x207 which contain
3056 * link status information
3057 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003058bool
Keith Packard93f62da2011-11-01 19:45:03 -07003059intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003060{
Lyude9f085eb2016-04-13 10:58:33 -04003061 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
3062 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003063}
3064
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303065static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp)
3066{
3067 uint8_t psr_caps = 0;
3068
3069 drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps);
3070 return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED;
3071}
3072
3073static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp)
3074{
3075 uint8_t dprx = 0;
3076
3077 drm_dp_dpcd_readb(&intel_dp->aux,
3078 DP_DPRX_FEATURE_ENUMERATION_LIST,
3079 &dprx);
3080 return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED;
3081}
3082
Chris Wilsona76f73d2017-01-14 10:51:13 +00003083static bool intel_dp_get_alpm_status(struct intel_dp *intel_dp)
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303084{
3085 uint8_t alpm_caps = 0;
3086
3087 drm_dp_dpcd_readb(&intel_dp->aux, DP_RECEIVER_ALPM_CAP, &alpm_caps);
3088 return alpm_caps & DP_ALPM_CAP;
3089}
3090
Paulo Zanoni11002442014-06-13 18:45:41 -03003091/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003092uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003093intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003094{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003095 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003096 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003097
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003098 if (IS_GEN9_LP(dev_priv))
Vandana Kannan93147262014-11-18 15:45:29 +05303099 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003100 else if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjäläffe51112017-02-23 19:49:01 +02003101 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3102 return intel_ddi_dp_voltage_max(encoder);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003103 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Sonika Jindalbd600182014-08-08 16:23:41 +05303104 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003105 else if (IS_GEN7(dev_priv) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303106 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003107 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303108 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08003109 else
Sonika Jindalbd600182014-08-08 16:23:41 +05303110 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08003111}
3112
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003113uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003114intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3115{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003116 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003117 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003118
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003119 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003120 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3121 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3122 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3123 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3124 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3125 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3126 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303127 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3128 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003129 default:
3130 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3131 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003132 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003133 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303134 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3135 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3136 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3137 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3138 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3139 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3140 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003141 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303142 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003143 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003144 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003145 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303146 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3147 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3148 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3149 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3150 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3151 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3152 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003153 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303154 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003155 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003156 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003157 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303158 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3159 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3160 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3161 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3162 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003163 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303164 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003165 }
3166 } else {
3167 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303168 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3169 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3170 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3171 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3172 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3173 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3174 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003175 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303176 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003177 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003178 }
3179}
3180
Daniel Vetter5829975c2015-04-16 11:36:52 +02003181static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003182{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003183 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003184 unsigned long demph_reg_value, preemph_reg_value,
3185 uniqtranscale_reg_value;
3186 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003187
3188 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303189 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003190 preemph_reg_value = 0x0004000;
3191 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303192 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003193 demph_reg_value = 0x2B405555;
3194 uniqtranscale_reg_value = 0x552AB83A;
3195 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303196 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003197 demph_reg_value = 0x2B404040;
3198 uniqtranscale_reg_value = 0x5548B83A;
3199 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303200 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003201 demph_reg_value = 0x2B245555;
3202 uniqtranscale_reg_value = 0x5560B83A;
3203 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303204 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003205 demph_reg_value = 0x2B405555;
3206 uniqtranscale_reg_value = 0x5598DA3A;
3207 break;
3208 default:
3209 return 0;
3210 }
3211 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303212 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003213 preemph_reg_value = 0x0002000;
3214 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303215 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003216 demph_reg_value = 0x2B404040;
3217 uniqtranscale_reg_value = 0x5552B83A;
3218 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303219 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003220 demph_reg_value = 0x2B404848;
3221 uniqtranscale_reg_value = 0x5580B83A;
3222 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303223 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003224 demph_reg_value = 0x2B404040;
3225 uniqtranscale_reg_value = 0x55ADDA3A;
3226 break;
3227 default:
3228 return 0;
3229 }
3230 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303231 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003232 preemph_reg_value = 0x0000000;
3233 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303234 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003235 demph_reg_value = 0x2B305555;
3236 uniqtranscale_reg_value = 0x5570B83A;
3237 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303238 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003239 demph_reg_value = 0x2B2B4040;
3240 uniqtranscale_reg_value = 0x55ADDA3A;
3241 break;
3242 default:
3243 return 0;
3244 }
3245 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303246 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003247 preemph_reg_value = 0x0006000;
3248 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303249 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003250 demph_reg_value = 0x1B405555;
3251 uniqtranscale_reg_value = 0x55ADDA3A;
3252 break;
3253 default:
3254 return 0;
3255 }
3256 break;
3257 default:
3258 return 0;
3259 }
3260
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003261 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3262 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003263
3264 return 0;
3265}
3266
Daniel Vetter5829975c2015-04-16 11:36:52 +02003267static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003268{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003269 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3270 u32 deemph_reg_value, margin_reg_value;
3271 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003272 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003273
3274 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303275 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003276 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303277 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003278 deemph_reg_value = 128;
3279 margin_reg_value = 52;
3280 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303281 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003282 deemph_reg_value = 128;
3283 margin_reg_value = 77;
3284 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303285 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003286 deemph_reg_value = 128;
3287 margin_reg_value = 102;
3288 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303289 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003290 deemph_reg_value = 128;
3291 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003292 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003293 break;
3294 default:
3295 return 0;
3296 }
3297 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303298 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003299 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303300 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003301 deemph_reg_value = 85;
3302 margin_reg_value = 78;
3303 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303304 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003305 deemph_reg_value = 85;
3306 margin_reg_value = 116;
3307 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303308 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003309 deemph_reg_value = 85;
3310 margin_reg_value = 154;
3311 break;
3312 default:
3313 return 0;
3314 }
3315 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303316 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003317 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303318 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003319 deemph_reg_value = 64;
3320 margin_reg_value = 104;
3321 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303322 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003323 deemph_reg_value = 64;
3324 margin_reg_value = 154;
3325 break;
3326 default:
3327 return 0;
3328 }
3329 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303330 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003331 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303332 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003333 deemph_reg_value = 43;
3334 margin_reg_value = 154;
3335 break;
3336 default:
3337 return 0;
3338 }
3339 break;
3340 default:
3341 return 0;
3342 }
3343
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003344 chv_set_phy_signal_level(encoder, deemph_reg_value,
3345 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003346
3347 return 0;
3348}
3349
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003350static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003351gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003352{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003353 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003354
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003355 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303356 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003357 default:
3358 signal_levels |= DP_VOLTAGE_0_4;
3359 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303360 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003361 signal_levels |= DP_VOLTAGE_0_6;
3362 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303363 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003364 signal_levels |= DP_VOLTAGE_0_8;
3365 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303366 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003367 signal_levels |= DP_VOLTAGE_1_2;
3368 break;
3369 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003370 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303371 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003372 default:
3373 signal_levels |= DP_PRE_EMPHASIS_0;
3374 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303375 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003376 signal_levels |= DP_PRE_EMPHASIS_3_5;
3377 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303378 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003379 signal_levels |= DP_PRE_EMPHASIS_6;
3380 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303381 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003382 signal_levels |= DP_PRE_EMPHASIS_9_5;
3383 break;
3384 }
3385 return signal_levels;
3386}
3387
Zhenyu Wange3421a12010-04-08 09:43:27 +08003388/* Gen6's DP voltage swing and pre-emphasis control */
3389static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003390gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003391{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003392 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3393 DP_TRAIN_PRE_EMPHASIS_MASK);
3394 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303395 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3396 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003397 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303398 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003399 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303400 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3401 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003402 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303403 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3404 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003405 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303406 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3407 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003408 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003409 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003410 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3411 "0x%x\n", signal_levels);
3412 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003413 }
3414}
3415
Keith Packard1a2eb462011-11-16 16:26:07 -08003416/* Gen7's DP voltage swing and pre-emphasis control */
3417static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003418gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003419{
3420 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3421 DP_TRAIN_PRE_EMPHASIS_MASK);
3422 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303423 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003424 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303425 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003426 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303427 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003428 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3429
Sonika Jindalbd600182014-08-08 16:23:41 +05303430 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003431 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303432 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003433 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3434
Sonika Jindalbd600182014-08-08 16:23:41 +05303435 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003436 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303437 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003438 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3439
3440 default:
3441 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3442 "0x%x\n", signal_levels);
3443 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3444 }
3445}
3446
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003447void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003448intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003449{
3450 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003451 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003452 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003453 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003454 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003455 uint8_t train_set = intel_dp->train_set[0];
3456
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003457 if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003458 signal_levels = ddi_signal_levels(intel_dp);
3459
Michel Thierry254e0932017-01-09 16:51:35 +02003460 if (IS_GEN9_LP(dev_priv))
David Weinehallf8896f52015-06-25 11:11:03 +03003461 signal_levels = 0;
3462 else
3463 mask = DDI_BUF_EMP_MASK;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003464 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003465 signal_levels = chv_signal_levels(intel_dp);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003466 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003467 signal_levels = vlv_signal_levels(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003468 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003469 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003470 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003471 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003472 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003473 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3474 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003475 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003476 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3477 }
3478
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303479 if (mask)
3480 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3481
3482 DRM_DEBUG_KMS("Using vswing level %d\n",
3483 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3484 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3485 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3486 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003487
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003488 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003489
3490 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3491 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003492}
3493
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003494void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003495intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3496 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003497{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003498 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003499 struct drm_i915_private *dev_priv =
3500 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003501
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003502 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003503
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003504 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003505 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003506}
3507
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003508void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003509{
3510 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3511 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003512 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak3ab9c632013-05-03 12:57:41 +03003513 enum port port = intel_dig_port->port;
3514 uint32_t val;
3515
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003516 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003517 return;
3518
3519 val = I915_READ(DP_TP_CTL(port));
3520 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3521 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3522 I915_WRITE(DP_TP_CTL(port), val);
3523
3524 /*
3525 * On PORT_A we can have only eDP in SST mode. There the only reason
3526 * we need to set idle transmission mode is to work around a HW issue
3527 * where we enable the pipe while not in idle link-training mode.
3528 * In this case there is requirement to wait for a minimum number of
3529 * idle patterns to be sent.
3530 */
3531 if (port == PORT_A)
3532 return;
3533
Chris Wilsona7670172016-06-30 15:33:10 +01003534 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3535 DP_TP_STATUS_IDLE_DONE,
3536 DP_TP_STATUS_IDLE_DONE,
3537 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003538 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3539}
3540
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003541static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003542intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003543{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003544 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003545 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003546 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003547 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003548 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003549 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003550
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003551 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003552 return;
3553
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003554 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003555 return;
3556
Zhao Yakui28c97732009-10-09 11:39:41 +08003557 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003558
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003559 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003560 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003561 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003562 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003563 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003564 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003565 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3566 else
3567 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003568 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003569 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003570 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003571 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003572
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003573 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3574 I915_WRITE(intel_dp->output_reg, DP);
3575 POSTING_READ(intel_dp->output_reg);
3576
3577 /*
3578 * HW workaround for IBX, we need to move the port
3579 * to transcoder A after disabling it to allow the
3580 * matching HDMI port to be enabled on transcoder A.
3581 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003582 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003583 /*
3584 * We get CPU/PCH FIFO underruns on the other pipe when
3585 * doing the workaround. Sweep them under the rug.
3586 */
3587 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3588 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3589
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003590 /* always enable with pattern 1 (as per spec) */
3591 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3592 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3593 I915_WRITE(intel_dp->output_reg, DP);
3594 POSTING_READ(intel_dp->output_reg);
3595
3596 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003597 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003598 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003599
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003600 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003601 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3602 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003603 }
3604
Keith Packardf01eca22011-09-28 16:48:10 -07003605 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003606
3607 intel_dp->DP = DP;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003608
3609 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3610 pps_lock(intel_dp);
3611 intel_dp->active_pipe = INVALID_PIPE;
3612 pps_unlock(intel_dp);
3613 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003614}
3615
Imre Deak24e807e2016-10-24 19:33:28 +03003616bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003617intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003618{
Lyude9f085eb2016-04-13 10:58:33 -04003619 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3620 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003621 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003622
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003623 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003624
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003625 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3626}
3627
3628static bool
3629intel_edp_init_dpcd(struct intel_dp *intel_dp)
3630{
3631 struct drm_i915_private *dev_priv =
3632 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3633
3634 /* this function is meant to be called only once */
3635 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3636
3637 if (!intel_dp_read_dpcd(intel_dp))
3638 return false;
3639
Imre Deak12a47a422016-10-24 19:33:29 +03003640 intel_dp_read_desc(intel_dp);
3641
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003642 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3643 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3644 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3645
3646 /* Check if the panel supports PSR */
3647 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3648 intel_dp->psr_dpcd,
3649 sizeof(intel_dp->psr_dpcd));
3650 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3651 dev_priv->psr.sink_support = true;
3652 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3653 }
3654
3655 if (INTEL_GEN(dev_priv) >= 9 &&
3656 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3657 uint8_t frame_sync_cap;
3658
3659 dev_priv->psr.sink_support = true;
3660 drm_dp_dpcd_read(&intel_dp->aux,
3661 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3662 &frame_sync_cap, 1);
3663 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3664 /* PSR2 needs frame sync as well */
3665 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3666 DRM_DEBUG_KMS("PSR2 %s on sink",
3667 dev_priv->psr.psr2_support ? "supported" : "not supported");
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303668
3669 if (dev_priv->psr.psr2_support) {
3670 dev_priv->psr.y_cord_support =
3671 intel_dp_get_y_cord_status(intel_dp);
3672 dev_priv->psr.colorimetry_support =
3673 intel_dp_get_colorimetry_status(intel_dp);
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303674 dev_priv->psr.alpm =
3675 intel_dp_get_alpm_status(intel_dp);
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303676 }
3677
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003678 }
3679
3680 /* Read the eDP Display control capabilities registers */
3681 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
3682 drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003683 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3684 sizeof(intel_dp->edp_dpcd))
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003685 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3686 intel_dp->edp_dpcd);
3687
3688 /* Intermediate frequency support */
3689 if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */
3690 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3691 int i;
3692
3693 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3694 sink_rates, sizeof(sink_rates));
3695
3696 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3697 int val = le16_to_cpu(sink_rates[i]);
3698
3699 if (val == 0)
3700 break;
3701
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -08003702 /* Value read multiplied by 200kHz gives the per-lane
3703 * link rate in kHz. The source rates are, however,
3704 * stored in terms of LS_Clk kHz. The full conversion
3705 * back to symbols is
3706 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
3707 */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003708 intel_dp->sink_rates[i] = (val * 200) / 10;
3709 }
3710 intel_dp->num_sink_rates = i;
3711 }
3712
3713 return true;
3714}
3715
3716
3717static bool
3718intel_dp_get_dpcd(struct intel_dp *intel_dp)
3719{
3720 if (!intel_dp_read_dpcd(intel_dp))
3721 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003722
Lyude9f085eb2016-04-13 10:58:33 -04003723 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT,
3724 &intel_dp->sink_count, 1) < 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303725 return false;
3726
3727 /*
3728 * Sink count can change between short pulse hpd hence
3729 * a member variable in intel_dp will track any changes
3730 * between short pulse interrupts.
3731 */
3732 intel_dp->sink_count = DP_GET_SINK_COUNT(intel_dp->sink_count);
3733
3734 /*
3735 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3736 * a dongle is present but no display. Unless we require to know
3737 * if a dongle is present or not, we don't need to update
3738 * downstream port information. So, an early return here saves
3739 * time from performing other operations which are not required.
3740 */
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05303741 if (!is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303742 return false;
3743
Imre Deakc726ad02016-10-24 19:33:24 +03003744 if (!drm_dp_is_branch(intel_dp->dpcd))
Adam Jacksonedb39242012-09-18 10:58:49 -04003745 return true; /* native DP sink */
3746
3747 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3748 return true; /* no per-port downstream info */
3749
Lyude9f085eb2016-04-13 10:58:33 -04003750 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3751 intel_dp->downstream_ports,
3752 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003753 return false; /* downstream port status fetch failed */
3754
3755 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003756}
3757
Dave Airlie0e32b392014-05-02 14:02:48 +10003758static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003759intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003760{
3761 u8 buf[1];
3762
Nathan Schulte7cc96132016-03-15 10:14:05 -05003763 if (!i915.enable_dp_mst)
3764 return false;
3765
Dave Airlie0e32b392014-05-02 14:02:48 +10003766 if (!intel_dp->can_mst)
3767 return false;
3768
3769 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3770 return false;
3771
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003772 if (drm_dp_dpcd_read(&intel_dp->aux, DP_MSTM_CAP, buf, 1) != 1)
3773 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003774
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003775 return buf[0] & DP_MST_CAP;
3776}
3777
3778static void
3779intel_dp_configure_mst(struct intel_dp *intel_dp)
3780{
3781 if (!i915.enable_dp_mst)
3782 return;
3783
3784 if (!intel_dp->can_mst)
3785 return;
3786
3787 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3788
3789 if (intel_dp->is_mst)
3790 DRM_DEBUG_KMS("Sink is MST capable\n");
3791 else
3792 DRM_DEBUG_KMS("Sink is not MST capable\n");
3793
3794 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3795 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003796}
3797
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003798static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003799{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003800 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003801 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003802 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003803 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003804 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003805 int count = 0;
3806 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003807
3808 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003809 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003810 ret = -EIO;
3811 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003812 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003813
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003814 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003815 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003816 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003817 ret = -EIO;
3818 goto out;
3819 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003820
Rodrigo Vivic6297842015-11-05 10:50:20 -08003821 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003822 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivic6297842015-11-05 10:50:20 -08003823
3824 if (drm_dp_dpcd_readb(&intel_dp->aux,
3825 DP_TEST_SINK_MISC, &buf) < 0) {
3826 ret = -EIO;
3827 goto out;
3828 }
3829 count = buf & DP_TEST_COUNT_MASK;
3830 } while (--attempts && count);
3831
3832 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003833 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003834 ret = -ETIMEDOUT;
3835 }
3836
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003837 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003838 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003839 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003840}
3841
3842static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3843{
3844 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003845 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003846 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3847 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003848 int ret;
3849
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003850 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3851 return -EIO;
3852
3853 if (!(buf & DP_TEST_CRC_SUPPORTED))
3854 return -ENOTTY;
3855
3856 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3857 return -EIO;
3858
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003859 if (buf & DP_TEST_SINK_START) {
3860 ret = intel_dp_sink_crc_stop(intel_dp);
3861 if (ret)
3862 return ret;
3863 }
3864
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003865 hsw_disable_ips(intel_crtc);
3866
3867 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3868 buf | DP_TEST_SINK_START) < 0) {
3869 hsw_enable_ips(intel_crtc);
3870 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003871 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003872
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003873 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003874 return 0;
3875}
3876
3877int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3878{
3879 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003880 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003881 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3882 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003883 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003884 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003885
3886 ret = intel_dp_sink_crc_start(intel_dp);
3887 if (ret)
3888 return ret;
3889
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003890 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003891 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003892
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003893 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003894 DP_TEST_SINK_MISC, &buf) < 0) {
3895 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003896 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003897 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003898 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07003899
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003900 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003901
3902 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003903 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
3904 ret = -ETIMEDOUT;
3905 goto stop;
3906 }
3907
3908 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
3909 ret = -EIO;
3910 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003911 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003912
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003913stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003914 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003915 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003916}
3917
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003918static bool
3919intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3920{
Lyude9f085eb2016-04-13 10:58:33 -04003921 return drm_dp_dpcd_read(&intel_dp->aux,
Jani Nikula9d1a1032014-03-14 16:51:15 +02003922 DP_DEVICE_SERVICE_IRQ_VECTOR,
3923 sink_irq_vector, 1) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003924}
3925
Dave Airlie0e32b392014-05-02 14:02:48 +10003926static bool
3927intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3928{
3929 int ret;
3930
Lyude9f085eb2016-04-13 10:58:33 -04003931 ret = drm_dp_dpcd_read(&intel_dp->aux,
Dave Airlie0e32b392014-05-02 14:02:48 +10003932 DP_SINK_COUNT_ESI,
3933 sink_irq_vector, 14);
3934 if (ret != 14)
3935 return false;
3936
3937 return true;
3938}
3939
Todd Previtec5d5ab72015-04-15 08:38:38 -07003940static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003941{
Manasi Navareda15f7c2017-01-24 08:16:34 -08003942 int status = 0;
3943 int min_lane_count = 1;
3944 int common_rates[DP_MAX_SUPPORTED_RATES] = {};
3945 int link_rate_index, test_link_rate;
3946 uint8_t test_lane_count, test_link_bw;
3947 /* (DP CTS 1.2)
3948 * 4.3.1.11
3949 */
3950 /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */
3951 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT,
3952 &test_lane_count);
3953
3954 if (status <= 0) {
3955 DRM_DEBUG_KMS("Lane count read failed\n");
3956 return DP_TEST_NAK;
3957 }
3958 test_lane_count &= DP_MAX_LANE_COUNT_MASK;
3959 /* Validate the requested lane count */
3960 if (test_lane_count < min_lane_count ||
3961 test_lane_count > intel_dp->max_sink_lane_count)
3962 return DP_TEST_NAK;
3963
3964 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE,
3965 &test_link_bw);
3966 if (status <= 0) {
3967 DRM_DEBUG_KMS("Link Rate read failed\n");
3968 return DP_TEST_NAK;
3969 }
3970 /* Validate the requested link rate */
3971 test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw);
3972 link_rate_index = intel_dp_link_rate_index(intel_dp,
3973 common_rates,
3974 test_link_rate);
3975 if (link_rate_index < 0)
3976 return DP_TEST_NAK;
3977
3978 intel_dp->compliance.test_lane_count = test_lane_count;
3979 intel_dp->compliance.test_link_rate = test_link_rate;
3980
3981 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07003982}
3983
3984static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
3985{
Manasi Navare611032b2017-01-24 08:21:49 -08003986 uint8_t test_pattern;
3987 uint16_t test_misc;
3988 __be16 h_width, v_height;
3989 int status = 0;
3990
3991 /* Read the TEST_PATTERN (DP CTS 3.1.5) */
3992 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_PATTERN,
3993 &test_pattern, 1);
3994 if (status <= 0) {
3995 DRM_DEBUG_KMS("Test pattern read failed\n");
3996 return DP_TEST_NAK;
3997 }
3998 if (test_pattern != DP_COLOR_RAMP)
3999 return DP_TEST_NAK;
4000
4001 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI,
4002 &h_width, 2);
4003 if (status <= 0) {
4004 DRM_DEBUG_KMS("H Width read failed\n");
4005 return DP_TEST_NAK;
4006 }
4007
4008 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI,
4009 &v_height, 2);
4010 if (status <= 0) {
4011 DRM_DEBUG_KMS("V Height read failed\n");
4012 return DP_TEST_NAK;
4013 }
4014
4015 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_MISC0,
4016 &test_misc, 1);
4017 if (status <= 0) {
4018 DRM_DEBUG_KMS("TEST MISC read failed\n");
4019 return DP_TEST_NAK;
4020 }
4021 if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB)
4022 return DP_TEST_NAK;
4023 if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA)
4024 return DP_TEST_NAK;
4025 switch (test_misc & DP_TEST_BIT_DEPTH_MASK) {
4026 case DP_TEST_BIT_DEPTH_6:
4027 intel_dp->compliance.test_data.bpc = 6;
4028 break;
4029 case DP_TEST_BIT_DEPTH_8:
4030 intel_dp->compliance.test_data.bpc = 8;
4031 break;
4032 default:
4033 return DP_TEST_NAK;
4034 }
4035
4036 intel_dp->compliance.test_data.video_pattern = test_pattern;
4037 intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width);
4038 intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height);
4039 /* Set test active flag here so userspace doesn't interrupt things */
4040 intel_dp->compliance.test_active = 1;
4041
4042 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004043}
4044
4045static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
4046{
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004047 uint8_t test_result = DP_TEST_ACK;
Todd Previte559be302015-05-04 07:48:20 -07004048 struct intel_connector *intel_connector = intel_dp->attached_connector;
4049 struct drm_connector *connector = &intel_connector->base;
4050
4051 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02004052 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07004053 intel_dp->aux.i2c_defer_count > 6) {
4054 /* Check EDID read for NACKs, DEFERs and corruption
4055 * (DP CTS 1.2 Core r1.1)
4056 * 4.2.2.4 : Failed EDID read, I2C_NAK
4057 * 4.2.2.5 : Failed EDID read, I2C_DEFER
4058 * 4.2.2.6 : EDID corruption detected
4059 * Use failsafe mode for all cases
4060 */
4061 if (intel_dp->aux.i2c_nack_count > 0 ||
4062 intel_dp->aux.i2c_defer_count > 0)
4063 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
4064 intel_dp->aux.i2c_nack_count,
4065 intel_dp->aux.i2c_defer_count);
Manasi Navarec1617ab2016-12-09 16:22:50 -08004066 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
Todd Previte559be302015-05-04 07:48:20 -07004067 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05304068 struct edid *block = intel_connector->detect_edid;
4069
4070 /* We have to write the checksum
4071 * of the last block read
4072 */
4073 block += intel_connector->detect_edid->extensions;
4074
Todd Previte559be302015-05-04 07:48:20 -07004075 if (!drm_dp_dpcd_write(&intel_dp->aux,
4076 DP_TEST_EDID_CHECKSUM,
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05304077 &block->checksum,
Dan Carpenter5a1cc652015-05-12 21:07:37 +03004078 1))
Todd Previte559be302015-05-04 07:48:20 -07004079 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
4080
4081 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004082 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED;
Todd Previte559be302015-05-04 07:48:20 -07004083 }
4084
4085 /* Set test active flag here so userspace doesn't interrupt things */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004086 intel_dp->compliance.test_active = 1;
Todd Previte559be302015-05-04 07:48:20 -07004087
Todd Previtec5d5ab72015-04-15 08:38:38 -07004088 return test_result;
4089}
4090
4091static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
4092{
4093 uint8_t test_result = DP_TEST_NAK;
4094 return test_result;
4095}
4096
4097static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
4098{
4099 uint8_t response = DP_TEST_NAK;
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004100 uint8_t request = 0;
4101 int status;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004102
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004103 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004104 if (status <= 0) {
4105 DRM_DEBUG_KMS("Could not read test request from sink\n");
4106 goto update_status;
4107 }
4108
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004109 switch (request) {
Todd Previtec5d5ab72015-04-15 08:38:38 -07004110 case DP_TEST_LINK_TRAINING:
4111 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004112 response = intel_dp_autotest_link_training(intel_dp);
4113 break;
4114 case DP_TEST_LINK_VIDEO_PATTERN:
4115 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004116 response = intel_dp_autotest_video_pattern(intel_dp);
4117 break;
4118 case DP_TEST_LINK_EDID_READ:
4119 DRM_DEBUG_KMS("EDID test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004120 response = intel_dp_autotest_edid(intel_dp);
4121 break;
4122 case DP_TEST_LINK_PHY_TEST_PATTERN:
4123 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004124 response = intel_dp_autotest_phy_pattern(intel_dp);
4125 break;
4126 default:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004127 DRM_DEBUG_KMS("Invalid test request '%02x'\n", request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004128 break;
4129 }
4130
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004131 if (response & DP_TEST_ACK)
4132 intel_dp->compliance.test_type = request;
4133
Todd Previtec5d5ab72015-04-15 08:38:38 -07004134update_status:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004135 status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004136 if (status <= 0)
4137 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004138}
4139
Dave Airlie0e32b392014-05-02 14:02:48 +10004140static int
4141intel_dp_check_mst_status(struct intel_dp *intel_dp)
4142{
4143 bool bret;
4144
4145 if (intel_dp->is_mst) {
4146 u8 esi[16] = { 0 };
4147 int ret = 0;
4148 int retry;
4149 bool handled;
4150 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4151go_again:
4152 if (bret == true) {
4153
4154 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03004155 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03004156 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10004157 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4158 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004159 intel_dp_stop_link_train(intel_dp);
4160 }
4161
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004162 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004163 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4164
4165 if (handled) {
4166 for (retry = 0; retry < 3; retry++) {
4167 int wret;
4168 wret = drm_dp_dpcd_write(&intel_dp->aux,
4169 DP_SINK_COUNT_ESI+1,
4170 &esi[1], 3);
4171 if (wret == 3) {
4172 break;
4173 }
4174 }
4175
4176 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4177 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004178 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004179 goto go_again;
4180 }
4181 } else
4182 ret = 0;
4183
4184 return ret;
4185 } else {
4186 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4187 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4188 intel_dp->is_mst = false;
4189 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4190 /* send a hotplug event */
4191 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4192 }
4193 }
4194 return -EINVAL;
4195}
4196
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304197static void
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004198intel_dp_retrain_link(struct intel_dp *intel_dp)
4199{
4200 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4201 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4202 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
4203
4204 /* Suppress underruns caused by re-training */
4205 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4206 if (crtc->config->has_pch_encoder)
4207 intel_set_pch_fifo_underrun_reporting(dev_priv,
4208 intel_crtc_pch_transcoder(crtc), false);
4209
4210 intel_dp_start_link_train(intel_dp);
4211 intel_dp_stop_link_train(intel_dp);
4212
4213 /* Keep underrun reporting disabled until things are stable */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02004214 intel_wait_for_vblank(dev_priv, crtc->pipe);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004215
4216 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4217 if (crtc->config->has_pch_encoder)
4218 intel_set_pch_fifo_underrun_reporting(dev_priv,
4219 intel_crtc_pch_transcoder(crtc), true);
4220}
4221
4222static void
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304223intel_dp_check_link_status(struct intel_dp *intel_dp)
4224{
4225 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4226 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4227 u8 link_status[DP_LINK_STATUS_SIZE];
4228
4229 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
4230
4231 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4232 DRM_ERROR("Failed to get link status\n");
4233 return;
4234 }
4235
4236 if (!intel_encoder->base.crtc)
4237 return;
4238
4239 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4240 return;
4241
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004242 /* FIXME: we need to synchronize this sort of stuff with hardware
Daniel Vetter2dd85ae2016-12-13 20:54:14 +01004243 * readout. Currently fast link training doesn't work on boot-up. */
4244 if (!intel_dp->lane_count)
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004245 return;
4246
Manasi Navareda15f7c2017-01-24 08:16:34 -08004247 /* Retrain if Channel EQ or CR not ok */
4248 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304249 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4250 intel_encoder->base.name);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004251
4252 intel_dp_retrain_link(intel_dp);
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304253 }
4254}
4255
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004256/*
4257 * According to DP spec
4258 * 5.1.2:
4259 * 1. Read DPCD
4260 * 2. Configure link according to Receiver Capabilities
4261 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4262 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304263 *
4264 * intel_dp_short_pulse - handles short pulse interrupts
4265 * when full detection is not required.
4266 * Returns %true if short pulse is handled and full detection
4267 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004268 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304269static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304270intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004271{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004272 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004273 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004274 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304275 u8 old_sink_count = intel_dp->sink_count;
4276 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004277
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304278 /*
4279 * Clearing compliance test variables to allow capturing
4280 * of values for next automated test request.
4281 */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004282 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304283
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304284 /*
4285 * Now read the DPCD to see if it's actually running
4286 * If the current value of sink count doesn't match with
4287 * the value that was stored earlier or dpcd read failed
4288 * we need to do full detection
4289 */
4290 ret = intel_dp_get_dpcd(intel_dp);
4291
4292 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4293 /* No need to proceed if we are going to do full detect */
4294 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004295 }
4296
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004297 /* Try to read the source of the interrupt */
4298 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004299 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4300 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004301 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004302 drm_dp_dpcd_writeb(&intel_dp->aux,
4303 DP_DEVICE_SERVICE_IRQ_VECTOR,
4304 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004305
4306 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Manasi Navareda15f7c2017-01-24 08:16:34 -08004307 intel_dp_handle_test_request(intel_dp);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004308 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4309 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4310 }
4311
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304312 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4313 intel_dp_check_link_status(intel_dp);
4314 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004315 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
4316 DRM_DEBUG_KMS("Link Training Compliance Test requested\n");
4317 /* Send a Hotplug Uevent to userspace to start modeset */
4318 drm_kms_helper_hotplug_event(intel_encoder->base.dev);
4319 }
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304320
4321 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004322}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004323
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004324/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004325static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004326intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004327{
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004328 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004329 uint8_t type;
4330
4331 if (!intel_dp_get_dpcd(intel_dp))
4332 return connector_status_disconnected;
4333
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304334 if (is_edp(intel_dp))
4335 return connector_status_connected;
4336
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004337 /* if there's no downstream port, we're done */
Imre Deakc726ad02016-10-24 19:33:24 +03004338 if (!drm_dp_is_branch(dpcd))
Keith Packard26d61aa2011-07-25 20:01:09 -07004339 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004340
4341 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004342 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4343 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004344
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304345 return intel_dp->sink_count ?
4346 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004347 }
4348
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004349 if (intel_dp_can_mst(intel_dp))
4350 return connector_status_connected;
4351
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004352 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004353 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004354 return connector_status_connected;
4355
4356 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004357 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4358 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4359 if (type == DP_DS_PORT_TYPE_VGA ||
4360 type == DP_DS_PORT_TYPE_NON_EDID)
4361 return connector_status_unknown;
4362 } else {
4363 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4364 DP_DWN_STRM_PORT_TYPE_MASK;
4365 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4366 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4367 return connector_status_unknown;
4368 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004369
4370 /* Anything else is out of spec, warn and ignore */
4371 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004372 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004373}
4374
4375static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004376edp_detect(struct intel_dp *intel_dp)
4377{
4378 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Mika Kahola1650be72016-12-13 10:02:47 +02004379 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsond410b562014-09-02 20:03:59 +01004380 enum drm_connector_status status;
4381
Mika Kahola1650be72016-12-13 10:02:47 +02004382 status = intel_panel_detect(dev_priv);
Chris Wilsond410b562014-09-02 20:03:59 +01004383 if (status == connector_status_unknown)
4384 status = connector_status_connected;
4385
4386 return status;
4387}
4388
Jani Nikulab93433c2015-08-20 10:47:36 +03004389static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4390 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004391{
Jani Nikulab93433c2015-08-20 10:47:36 +03004392 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004393
Jani Nikula0df53b72015-08-20 10:47:40 +03004394 switch (port->port) {
4395 case PORT_A:
4396 return true;
4397 case PORT_B:
4398 bit = SDE_PORTB_HOTPLUG;
4399 break;
4400 case PORT_C:
4401 bit = SDE_PORTC_HOTPLUG;
4402 break;
4403 case PORT_D:
4404 bit = SDE_PORTD_HOTPLUG;
4405 break;
4406 default:
4407 MISSING_CASE(port->port);
4408 return false;
4409 }
4410
4411 return I915_READ(SDEISR) & bit;
4412}
4413
4414static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4415 struct intel_digital_port *port)
4416{
4417 u32 bit;
4418
4419 switch (port->port) {
4420 case PORT_A:
4421 return true;
4422 case PORT_B:
4423 bit = SDE_PORTB_HOTPLUG_CPT;
4424 break;
4425 case PORT_C:
4426 bit = SDE_PORTC_HOTPLUG_CPT;
4427 break;
4428 case PORT_D:
4429 bit = SDE_PORTD_HOTPLUG_CPT;
4430 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004431 case PORT_E:
4432 bit = SDE_PORTE_HOTPLUG_SPT;
4433 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004434 default:
4435 MISSING_CASE(port->port);
4436 return false;
Jani Nikulab93433c2015-08-20 10:47:36 +03004437 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004438
Jani Nikulab93433c2015-08-20 10:47:36 +03004439 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004440}
4441
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004442static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004443 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004444{
Jani Nikula9642c812015-08-20 10:47:41 +03004445 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004446
Jani Nikula9642c812015-08-20 10:47:41 +03004447 switch (port->port) {
4448 case PORT_B:
4449 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4450 break;
4451 case PORT_C:
4452 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4453 break;
4454 case PORT_D:
4455 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4456 break;
4457 default:
4458 MISSING_CASE(port->port);
4459 return false;
4460 }
4461
4462 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4463}
4464
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004465static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4466 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004467{
4468 u32 bit;
4469
4470 switch (port->port) {
4471 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004472 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004473 break;
4474 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004475 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004476 break;
4477 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004478 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004479 break;
4480 default:
4481 MISSING_CASE(port->port);
4482 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004483 }
4484
Jani Nikula1d245982015-08-20 10:47:37 +03004485 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004486}
4487
Jani Nikulae464bfd2015-08-20 10:47:42 +03004488static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304489 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004490{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304491 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4492 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004493 u32 bit;
4494
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304495 intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port);
4496 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004497 case PORT_A:
4498 bit = BXT_DE_PORT_HP_DDIA;
4499 break;
4500 case PORT_B:
4501 bit = BXT_DE_PORT_HP_DDIB;
4502 break;
4503 case PORT_C:
4504 bit = BXT_DE_PORT_HP_DDIC;
4505 break;
4506 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304507 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004508 return false;
4509 }
4510
4511 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4512}
4513
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004514/*
4515 * intel_digital_port_connected - is the specified port connected?
4516 * @dev_priv: i915 private structure
4517 * @port: the port to test
4518 *
4519 * Return %true if @port is connected, %false otherwise.
4520 */
Imre Deak390b4e02017-01-27 11:39:19 +02004521bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
4522 struct intel_digital_port *port)
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004523{
Jani Nikula0df53b72015-08-20 10:47:40 +03004524 if (HAS_PCH_IBX(dev_priv))
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004525 return ibx_digital_port_connected(dev_priv, port);
Ville Syrjälä22824fa2016-02-11 16:44:28 +02004526 else if (HAS_PCH_SPLIT(dev_priv))
Jani Nikula0df53b72015-08-20 10:47:40 +03004527 return cpt_digital_port_connected(dev_priv, port);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004528 else if (IS_GEN9_LP(dev_priv))
Jani Nikulae464bfd2015-08-20 10:47:42 +03004529 return bxt_digital_port_connected(dev_priv, port);
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004530 else if (IS_GM45(dev_priv))
4531 return gm45_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004532 else
4533 return g4x_digital_port_connected(dev_priv, port);
4534}
4535
Keith Packard8c241fe2011-09-28 16:38:44 -07004536static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004537intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004538{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004539 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004540
Jani Nikula9cd300e2012-10-19 14:51:52 +03004541 /* use cached edid if we have one */
4542 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004543 /* invalid edid */
4544 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004545 return NULL;
4546
Jani Nikula55e9ede2013-10-01 10:38:54 +03004547 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004548 } else
4549 return drm_get_edid(&intel_connector->base,
4550 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004551}
4552
Chris Wilsonbeb60602014-09-02 20:04:00 +01004553static void
4554intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004555{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004556 struct intel_connector *intel_connector = intel_dp->attached_connector;
4557 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004558
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304559 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004560 edid = intel_dp_get_edid(intel_dp);
4561 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004562
Chris Wilsonbeb60602014-09-02 20:04:00 +01004563 if (intel_dp->force_audio != HDMI_AUDIO_AUTO)
4564 intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON;
4565 else
4566 intel_dp->has_audio = drm_detect_monitor_audio(edid);
4567}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004568
Chris Wilsonbeb60602014-09-02 20:04:00 +01004569static void
4570intel_dp_unset_edid(struct intel_dp *intel_dp)
4571{
4572 struct intel_connector *intel_connector = intel_dp->attached_connector;
4573
4574 kfree(intel_connector->detect_edid);
4575 intel_connector->detect_edid = NULL;
4576
4577 intel_dp->has_audio = false;
4578}
4579
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004580static enum drm_connector_status
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304581intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004582{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304583 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004584 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004585 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4586 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004587 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004588 enum drm_connector_status status;
Imre Deak671dedd2014-03-05 16:20:53 +02004589 enum intel_display_power_domain power_domain;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004590 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004591
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004592 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4593 intel_display_power_get(to_i915(dev), power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004594
Chris Wilsond410b562014-09-02 20:03:59 +01004595 /* Can't disconnect eDP, but you can close the lid... */
4596 if (is_edp(intel_dp))
4597 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004598 else if (intel_digital_port_connected(to_i915(dev),
4599 dp_to_dig_port(intel_dp)))
4600 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004601 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004602 status = connector_status_disconnected;
4603
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004604 if (status == connector_status_disconnected) {
Manasi Navarec1617ab2016-12-09 16:22:50 -08004605 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304606
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004607 if (intel_dp->is_mst) {
4608 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4609 intel_dp->is_mst,
4610 intel_dp->mst_mgr.mst_state);
4611 intel_dp->is_mst = false;
4612 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4613 intel_dp->is_mst);
4614 }
4615
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004616 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304617 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004618
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304619 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004620 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304621
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004622 DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
4623 yesno(intel_dp_source_supports_hbr2(intel_dp)),
4624 yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
4625
Manasi Navared7e8ef02017-02-07 16:54:11 -08004626 if (intel_dp->reset_link_params) {
4627 /* Set the max lane count for sink */
4628 intel_dp->max_sink_lane_count = drm_dp_max_lane_count(intel_dp->dpcd);
Manasi Navaref4829842016-12-05 16:27:36 -08004629
Manasi Navared7e8ef02017-02-07 16:54:11 -08004630 /* Set the max link BW for sink */
4631 intel_dp->max_sink_link_bw = intel_dp_max_link_bw(intel_dp);
4632
4633 intel_dp->reset_link_params = false;
4634 }
Manasi Navaref4829842016-12-05 16:27:36 -08004635
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004636 intel_dp_print_rates(intel_dp);
4637
Imre Deak7b3fc172016-10-25 16:12:39 +03004638 intel_dp_read_desc(intel_dp);
Mika Kahola0e390a32016-09-09 14:10:53 +03004639
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004640 intel_dp_configure_mst(intel_dp);
4641
4642 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304643 /*
4644 * If we are in MST mode then this connector
4645 * won't appear connected or have anything
4646 * with EDID on it
4647 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004648 status = connector_status_disconnected;
4649 goto out;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304650 } else if (connector->status == connector_status_connected) {
4651 /*
4652 * If display was connected already and is still connected
4653 * check links status, there has been known issues of
4654 * link loss triggerring long pulse!!!!
4655 */
4656 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4657 intel_dp_check_link_status(intel_dp);
4658 drm_modeset_unlock(&dev->mode_config.connection_mutex);
4659 goto out;
Dave Airlie0e32b392014-05-02 14:02:48 +10004660 }
4661
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304662 /*
4663 * Clearing NACK and defer counts to get their exact values
4664 * while reading EDID which are required by Compliance tests
4665 * 4.2.2.4 and 4.2.2.5
4666 */
4667 intel_dp->aux.i2c_nack_count = 0;
4668 intel_dp->aux.i2c_defer_count = 0;
4669
Chris Wilsonbeb60602014-09-02 20:04:00 +01004670 intel_dp_set_edid(intel_dp);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004671 if (is_edp(intel_dp) || intel_connector->detect_edid)
4672 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304673 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004674
Todd Previte09b1eb12015-04-20 15:27:34 -07004675 /* Try to read the source of the interrupt */
4676 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004677 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4678 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004679 /* Clear interrupt source */
4680 drm_dp_dpcd_writeb(&intel_dp->aux,
4681 DP_DEVICE_SERVICE_IRQ_VECTOR,
4682 sink_irq_vector);
4683
4684 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4685 intel_dp_handle_test_request(intel_dp);
4686 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4687 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4688 }
4689
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004690out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004691 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304692 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304693
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004694 intel_display_power_put(to_i915(dev), power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004695 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304696}
4697
4698static enum drm_connector_status
4699intel_dp_detect(struct drm_connector *connector, bool force)
4700{
4701 struct intel_dp *intel_dp = intel_attached_dp(connector);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004702 enum drm_connector_status status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304703
4704 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4705 connector->base.id, connector->name);
4706
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304707 /* If full detect is not performed yet, do a full detect */
4708 if (!intel_dp->detect_done)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004709 status = intel_dp_long_pulse(intel_dp->attached_connector);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304710
4711 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304712
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004713 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004714}
4715
Chris Wilsonbeb60602014-09-02 20:04:00 +01004716static void
4717intel_dp_force(struct drm_connector *connector)
4718{
4719 struct intel_dp *intel_dp = intel_attached_dp(connector);
4720 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004721 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004722 enum intel_display_power_domain power_domain;
4723
4724 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4725 connector->base.id, connector->name);
4726 intel_dp_unset_edid(intel_dp);
4727
4728 if (connector->status != connector_status_connected)
4729 return;
4730
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004731 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4732 intel_display_power_get(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004733
4734 intel_dp_set_edid(intel_dp);
4735
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004736 intel_display_power_put(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004737
4738 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004739 intel_encoder->type = INTEL_OUTPUT_DP;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004740}
4741
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004742static int intel_dp_get_modes(struct drm_connector *connector)
4743{
Jani Nikuladd06f902012-10-19 14:51:50 +03004744 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004745 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004746
Chris Wilsonbeb60602014-09-02 20:04:00 +01004747 edid = intel_connector->detect_edid;
4748 if (edid) {
4749 int ret = intel_connector_update_modes(connector, edid);
4750 if (ret)
4751 return ret;
4752 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004753
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004754 /* if eDP has no EDID, fall back to fixed mode */
Chris Wilsonbeb60602014-09-02 20:04:00 +01004755 if (is_edp(intel_attached_dp(connector)) &&
4756 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004757 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004758
4759 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004760 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004761 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004762 drm_mode_probed_add(connector, mode);
4763 return 1;
4764 }
4765 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004766
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004767 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004768}
4769
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004770static bool
4771intel_dp_detect_audio(struct drm_connector *connector)
4772{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004773 bool has_audio = false;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004774 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004775
Chris Wilsonbeb60602014-09-02 20:04:00 +01004776 edid = to_intel_connector(connector)->detect_edid;
4777 if (edid)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004778 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02004779
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004780 return has_audio;
4781}
4782
Chris Wilsonf6849602010-09-19 09:29:33 +01004783static int
4784intel_dp_set_property(struct drm_connector *connector,
4785 struct drm_property *property,
4786 uint64_t val)
4787{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004788 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Yuly Novikov53b41832012-10-26 12:04:00 +03004789 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004790 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
4791 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01004792 int ret;
4793
Rob Clark662595d2012-10-11 20:36:04 -05004794 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01004795 if (ret)
4796 return ret;
4797
Chris Wilson3f43c482011-05-12 22:17:24 +01004798 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004799 int i = val;
4800 bool has_audio;
4801
4802 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004803 return 0;
4804
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004805 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01004806
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004807 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004808 has_audio = intel_dp_detect_audio(connector);
4809 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004810 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004811
4812 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004813 return 0;
4814
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004815 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01004816 goto done;
4817 }
4818
Chris Wilsone953fd72011-02-21 22:23:52 +00004819 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02004820 bool old_auto = intel_dp->color_range_auto;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004821 bool old_range = intel_dp->limited_color_range;
Daniel Vetterae4edb82013-04-22 17:07:23 +02004822
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004823 switch (val) {
4824 case INTEL_BROADCAST_RGB_AUTO:
4825 intel_dp->color_range_auto = true;
4826 break;
4827 case INTEL_BROADCAST_RGB_FULL:
4828 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004829 intel_dp->limited_color_range = false;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004830 break;
4831 case INTEL_BROADCAST_RGB_LIMITED:
4832 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004833 intel_dp->limited_color_range = true;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004834 break;
4835 default:
4836 return -EINVAL;
4837 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02004838
4839 if (old_auto == intel_dp->color_range_auto &&
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004840 old_range == intel_dp->limited_color_range)
Daniel Vetterae4edb82013-04-22 17:07:23 +02004841 return 0;
4842
Chris Wilsone953fd72011-02-21 22:23:52 +00004843 goto done;
4844 }
4845
Yuly Novikov53b41832012-10-26 12:04:00 +03004846 if (is_edp(intel_dp) &&
4847 property == connector->dev->mode_config.scaling_mode_property) {
4848 if (val == DRM_MODE_SCALE_NONE) {
4849 DRM_DEBUG_KMS("no scaling not supported\n");
4850 return -EINVAL;
4851 }
Ville Syrjälä234126c2016-04-12 22:14:38 +03004852 if (HAS_GMCH_DISPLAY(dev_priv) &&
4853 val == DRM_MODE_SCALE_CENTER) {
4854 DRM_DEBUG_KMS("centering not supported\n");
4855 return -EINVAL;
4856 }
Yuly Novikov53b41832012-10-26 12:04:00 +03004857
4858 if (intel_connector->panel.fitting_mode == val) {
4859 /* the eDP scaling property is not changed */
4860 return 0;
4861 }
4862 intel_connector->panel.fitting_mode = val;
4863
4864 goto done;
4865 }
4866
Chris Wilsonf6849602010-09-19 09:29:33 +01004867 return -EINVAL;
4868
4869done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00004870 if (intel_encoder->base.crtc)
4871 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01004872
4873 return 0;
4874}
4875
Chris Wilson7a418e32016-06-24 14:00:14 +01004876static int
4877intel_dp_connector_register(struct drm_connector *connector)
4878{
4879 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004880 int ret;
4881
4882 ret = intel_connector_register(connector);
4883 if (ret)
4884 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004885
4886 i915_debugfs_connector_add(connector);
4887
4888 DRM_DEBUG_KMS("registering %s bus for %s\n",
4889 intel_dp->aux.name, connector->kdev->kobj.name);
4890
4891 intel_dp->aux.dev = connector->kdev;
4892 return drm_dp_aux_register(&intel_dp->aux);
4893}
4894
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004895static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004896intel_dp_connector_unregister(struct drm_connector *connector)
4897{
4898 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4899 intel_connector_unregister(connector);
4900}
4901
4902static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004903intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004904{
Jani Nikula1d508702012-10-19 14:51:49 +03004905 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004906
Chris Wilson10e972d2014-09-04 21:43:45 +01004907 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004908
Jani Nikula9cd300e2012-10-19 14:51:52 +03004909 if (!IS_ERR_OR_NULL(intel_connector->edid))
4910 kfree(intel_connector->edid);
4911
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004912 /* Can't call is_edp() since the encoder may have been destroyed
4913 * already. */
4914 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004915 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004916
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004917 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004918 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004919}
4920
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004921void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004922{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004923 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4924 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004925
Dave Airlie0e32b392014-05-02 14:02:48 +10004926 intel_dp_mst_encoder_cleanup(intel_dig_port);
Keith Packardbd943152011-09-18 23:09:52 -07004927 if (is_edp(intel_dp)) {
4928 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004929 /*
4930 * vdd might still be enabled do to the delayed vdd off.
4931 * Make sure vdd is actually turned off here.
4932 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004933 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004934 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004935 pps_unlock(intel_dp);
4936
Clint Taylor01527b32014-07-07 13:01:46 -07004937 if (intel_dp->edp_notifier.notifier_call) {
4938 unregister_reboot_notifier(&intel_dp->edp_notifier);
4939 intel_dp->edp_notifier.notifier_call = NULL;
4940 }
Keith Packardbd943152011-09-18 23:09:52 -07004941 }
Chris Wilson99681882016-06-20 09:29:17 +01004942
4943 intel_dp_aux_fini(intel_dp);
4944
Imre Deakc8bd0e42014-12-12 17:57:38 +02004945 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004946 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004947}
4948
Imre Deakbf93ba62016-04-18 10:04:21 +03004949void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004950{
4951 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4952
4953 if (!is_edp(intel_dp))
4954 return;
4955
Ville Syrjälä951468f2014-09-04 14:55:31 +03004956 /*
4957 * vdd might still be enabled do to the delayed vdd off.
4958 * Make sure vdd is actually turned off here.
4959 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004960 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004961 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004962 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004963 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004964}
4965
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004966static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4967{
4968 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4969 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004970 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004971 enum intel_display_power_domain power_domain;
4972
4973 lockdep_assert_held(&dev_priv->pps_mutex);
4974
4975 if (!edp_have_panel_vdd(intel_dp))
4976 return;
4977
4978 /*
4979 * The VDD bit needs a power domain reference, so if the bit is
4980 * already enabled when we boot or resume, grab this reference and
4981 * schedule a vdd off, so we don't hold on to the reference
4982 * indefinitely.
4983 */
4984 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004985 power_domain = intel_display_port_aux_power_domain(&intel_dig_port->base);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004986 intel_display_power_get(dev_priv, power_domain);
4987
4988 edp_panel_vdd_schedule_off(intel_dp);
4989}
4990
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02004991static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
4992{
4993 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
4994
4995 if ((intel_dp->DP & DP_PORT_EN) == 0)
4996 return INVALID_PIPE;
4997
4998 if (IS_CHERRYVIEW(dev_priv))
4999 return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
5000 else
5001 return PORT_TO_PIPE(intel_dp->DP);
5002}
5003
Imre Deakbf93ba62016-04-18 10:04:21 +03005004void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03005005{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005006 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Imre Deakdd75f6d2016-11-21 21:15:05 +02005007 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
5008 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005009
5010 if (!HAS_DDI(dev_priv))
5011 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005012
Imre Deakdd75f6d2016-11-21 21:15:05 +02005013 if (lspcon->active)
Shashank Sharma910530c2016-10-14 19:56:52 +05305014 lspcon_resume(lspcon);
5015
Manasi Navared7e8ef02017-02-07 16:54:11 -08005016 intel_dp->reset_link_params = true;
5017
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005018 pps_lock(intel_dp);
5019
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005020 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5021 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5022
5023 if (is_edp(intel_dp)) {
5024 /* Reinit the power sequencer, in case BIOS did something with it. */
5025 intel_dp_pps_init(encoder->dev, intel_dp);
5026 intel_edp_panel_vdd_sanitize(intel_dp);
5027 }
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005028
5029 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03005030}
5031
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005032static const struct drm_connector_funcs intel_dp_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02005033 .dpms = drm_atomic_helper_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005034 .detect = intel_dp_detect,
Chris Wilsonbeb60602014-09-02 20:04:00 +01005035 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005036 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01005037 .set_property = intel_dp_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -08005038 .atomic_get_property = intel_connector_atomic_get_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01005039 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01005040 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03005041 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08005042 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02005043 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005044};
5045
5046static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
5047 .get_modes = intel_dp_get_modes,
5048 .mode_valid = intel_dp_mode_valid,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005049};
5050
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005051static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03005052 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02005053 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005054};
5055
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005056enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10005057intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
5058{
5059 struct intel_dp *intel_dp = &intel_dig_port->dp;
Imre Deak1c767b32014-08-18 14:42:42 +03005060 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Dave Airlie0e32b392014-05-02 14:02:48 +10005061 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005062 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak1c767b32014-08-18 14:42:42 +03005063 enum intel_display_power_domain power_domain;
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005064 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03005065
Takashi Iwai25400582015-11-19 12:09:56 +01005066 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
5067 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Ville Syrjäläcca05022016-06-22 21:57:06 +03005068 intel_dig_port->base.type = INTEL_OUTPUT_DP;
Dave Airlie13cf5502014-06-18 11:29:35 +10005069
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005070 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
5071 /*
5072 * vdd off can generate a long pulse on eDP which
5073 * would require vdd on to handle it, and thus we
5074 * would end up in an endless cycle of
5075 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
5076 */
5077 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
5078 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d52f82015-02-10 14:11:46 +02005079 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005080 }
5081
Ville Syrjälä26fbb772014-08-11 18:37:37 +03005082 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
5083 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10005084 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10005085
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005086 if (long_hpd) {
Manasi Navared7e8ef02017-02-07 16:54:11 -08005087 intel_dp->reset_link_params = true;
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005088 intel_dp->detect_done = false;
5089 return IRQ_NONE;
5090 }
5091
Ville Syrjälä25f78f52015-11-16 15:01:04 +01005092 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak1c767b32014-08-18 14:42:42 +03005093 intel_display_power_get(dev_priv, power_domain);
5094
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005095 if (intel_dp->is_mst) {
5096 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
5097 /*
5098 * If we were in MST mode, and device is not
5099 * there, get out of MST mode
5100 */
5101 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
5102 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
5103 intel_dp->is_mst = false;
5104 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
5105 intel_dp->is_mst);
5106 intel_dp->detect_done = false;
5107 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10005108 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005109 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005110
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005111 if (!intel_dp->is_mst) {
5112 if (!intel_dp_short_pulse(intel_dp)) {
5113 intel_dp->detect_done = false;
5114 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05305115 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005116 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005117
5118 ret = IRQ_HANDLED;
5119
Imre Deak1c767b32014-08-18 14:42:42 +03005120put_power:
5121 intel_display_power_put(dev_priv, power_domain);
5122
5123 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10005124}
5125
Rodrigo Vivi477ec322015-08-06 15:51:39 +08005126/* check the VBT to see whether the eDP is on another port */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005127bool intel_dp_is_edp(struct drm_i915_private *dev_priv, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08005128{
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005129 /*
5130 * eDP not supported on g4x. so bail out early just
5131 * for a bit extra safety in case the VBT is bonkers.
5132 */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005133 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005134 return false;
5135
Imre Deaka98d9c12016-12-21 12:17:24 +02005136 if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005137 return true;
5138
Jani Nikula951d9ef2016-03-16 12:43:31 +02005139 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08005140}
5141
Dave Airlie0e32b392014-05-02 14:02:48 +10005142void
Chris Wilsonf6849602010-09-19 09:29:33 +01005143intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
5144{
Yuly Novikov53b41832012-10-26 12:04:00 +03005145 struct intel_connector *intel_connector = to_intel_connector(connector);
5146
Chris Wilson3f43c482011-05-12 22:17:24 +01005147 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00005148 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02005149 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03005150
5151 if (is_edp(intel_dp)) {
5152 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05005153 drm_object_attach_property(
5154 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03005155 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03005156 DRM_MODE_SCALE_ASPECT);
5157 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03005158 }
Chris Wilsonf6849602010-09-19 09:29:33 +01005159}
5160
Imre Deakdada1a92014-01-29 13:25:41 +02005161static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
5162{
Abhay Kumard28d4732016-01-22 17:39:04 -08005163 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02005164 intel_dp->last_power_on = jiffies;
5165 intel_dp->last_backlight_off = jiffies;
5166}
5167
Daniel Vetter67a54562012-10-20 20:57:45 +02005168static void
Imre Deak54648612016-06-16 16:37:22 +03005169intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
5170 struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02005171{
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305172 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03005173 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07005174
Imre Deak8e8232d2016-06-16 16:37:21 +03005175 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02005176
5177 /* Workaround: Need to write PP_CONTROL with the unlock key as
5178 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305179 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02005180
Imre Deak8e8232d2016-06-16 16:37:21 +03005181 pp_on = I915_READ(regs.pp_on);
5182 pp_off = I915_READ(regs.pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005183 if (!IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005184 I915_WRITE(regs.pp_ctrl, pp_ctl);
5185 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305186 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005187
5188 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03005189 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
5190 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005191
Imre Deak54648612016-06-16 16:37:22 +03005192 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
5193 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005194
Imre Deak54648612016-06-16 16:37:22 +03005195 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
5196 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005197
Imre Deak54648612016-06-16 16:37:22 +03005198 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
5199 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005200
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005201 if (IS_GEN9_LP(dev_priv)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305202 u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
5203 BXT_POWER_CYCLE_DELAY_SHIFT;
5204 if (tmp > 0)
Imre Deak54648612016-06-16 16:37:22 +03005205 seq->t11_t12 = (tmp - 1) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305206 else
Imre Deak54648612016-06-16 16:37:22 +03005207 seq->t11_t12 = 0;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305208 } else {
Imre Deak54648612016-06-16 16:37:22 +03005209 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02005210 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305211 }
Imre Deak54648612016-06-16 16:37:22 +03005212}
5213
5214static void
Imre Deakde9c1b62016-06-16 20:01:46 +03005215intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
5216{
5217 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5218 state_name,
5219 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
5220}
5221
5222static void
5223intel_pps_verify_state(struct drm_i915_private *dev_priv,
5224 struct intel_dp *intel_dp)
5225{
5226 struct edp_power_seq hw;
5227 struct edp_power_seq *sw = &intel_dp->pps_delays;
5228
5229 intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
5230
5231 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
5232 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
5233 DRM_ERROR("PPS state mismatch\n");
5234 intel_pps_dump_state("sw", sw);
5235 intel_pps_dump_state("hw", &hw);
5236 }
5237}
5238
5239static void
Imre Deak54648612016-06-16 16:37:22 +03005240intel_dp_init_panel_power_sequencer(struct drm_device *dev,
5241 struct intel_dp *intel_dp)
5242{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005243 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak54648612016-06-16 16:37:22 +03005244 struct edp_power_seq cur, vbt, spec,
5245 *final = &intel_dp->pps_delays;
5246
5247 lockdep_assert_held(&dev_priv->pps_mutex);
5248
5249 /* already initialized? */
5250 if (final->t11_t12 != 0)
5251 return;
5252
5253 intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005254
Imre Deakde9c1b62016-06-16 20:01:46 +03005255 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005256
Jani Nikula6aa23e62016-03-24 17:50:20 +02005257 vbt = dev_priv->vbt.edp.pps;
Daniel Vetter67a54562012-10-20 20:57:45 +02005258
5259 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5260 * our hw here, which are all in 100usec. */
5261 spec.t1_t3 = 210 * 10;
5262 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5263 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5264 spec.t10 = 500 * 10;
5265 /* This one is special and actually in units of 100ms, but zero
5266 * based in the hw (so we need to add 100 ms). But the sw vbt
5267 * table multiplies it with 1000 to make it in units of 100usec,
5268 * too. */
5269 spec.t11_t12 = (510 + 100) * 10;
5270
Imre Deakde9c1b62016-06-16 20:01:46 +03005271 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005272
5273 /* Use the max of the register settings and vbt. If both are
5274 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005275#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005276 spec.field : \
5277 max(cur.field, vbt.field))
5278 assign_final(t1_t3);
5279 assign_final(t8);
5280 assign_final(t9);
5281 assign_final(t10);
5282 assign_final(t11_t12);
5283#undef assign_final
5284
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005285#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005286 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5287 intel_dp->backlight_on_delay = get_delay(t8);
5288 intel_dp->backlight_off_delay = get_delay(t9);
5289 intel_dp->panel_power_down_delay = get_delay(t10);
5290 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5291#undef get_delay
5292
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005293 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5294 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5295 intel_dp->panel_power_cycle_delay);
5296
5297 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5298 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005299
5300 /*
5301 * We override the HW backlight delays to 1 because we do manual waits
5302 * on them. For T8, even BSpec recommends doing it. For T9, if we
5303 * don't do this, we'll end up waiting for the backlight off delay
5304 * twice: once when we do the manual sleep, and once when we disable
5305 * the panel and wait for the PP_STATUS bit to become zero.
5306 */
5307 final->t8 = 1;
5308 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005309}
5310
5311static void
5312intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005313 struct intel_dp *intel_dp,
5314 bool force_disable_vdd)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005315{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005316 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07005317 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005318 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005319 struct pps_registers regs;
Ville Syrjäläad933b52014-08-18 22:15:56 +03005320 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005321 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005322
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005323 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005324
Imre Deak8e8232d2016-06-16 16:37:21 +03005325 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005326
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005327 /*
5328 * On some VLV machines the BIOS can leave the VDD
5329 * enabled even on power seqeuencers which aren't
5330 * hooked up to any port. This would mess up the
5331 * power domain tracking the first time we pick
5332 * one of these power sequencers for use since
5333 * edp_panel_vdd_on() would notice that the VDD was
5334 * already on and therefore wouldn't grab the power
5335 * domain reference. Disable VDD first to avoid this.
5336 * This also avoids spuriously turning the VDD on as
5337 * soon as the new power seqeuencer gets initialized.
5338 */
5339 if (force_disable_vdd) {
5340 u32 pp = ironlake_get_pp_control(intel_dp);
5341
5342 WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
5343
5344 if (pp & EDP_FORCE_VDD)
5345 DRM_DEBUG_KMS("VDD already on, disabling first\n");
5346
5347 pp &= ~EDP_FORCE_VDD;
5348
5349 I915_WRITE(regs.pp_ctrl, pp);
5350 }
5351
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005352 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005353 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5354 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005355 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005356 /* Compute the divisor for the pp clock, simply match the Bspec
5357 * formula. */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005358 if (IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005359 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305360 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
5361 pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
5362 << BXT_POWER_CYCLE_DELAY_SHIFT);
5363 } else {
5364 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5365 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5366 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5367 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005368
5369 /* Haswell doesn't have any port selection bits for the panel
5370 * power sequencer any more. */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005371 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005372 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005373 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005374 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005375 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005376 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005377 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005378 }
5379
Jesse Barnes453c5422013-03-28 09:55:41 -07005380 pp_on |= port_sel;
5381
Imre Deak8e8232d2016-06-16 16:37:21 +03005382 I915_WRITE(regs.pp_on, pp_on);
5383 I915_WRITE(regs.pp_off, pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005384 if (IS_GEN9_LP(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005385 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305386 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005387 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005388
Daniel Vetter67a54562012-10-20 20:57:45 +02005389 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 +03005390 I915_READ(regs.pp_on),
5391 I915_READ(regs.pp_off),
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005392 IS_GEN9_LP(dev_priv) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005393 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5394 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005395}
5396
Imre Deak335f7522016-08-10 14:07:32 +03005397static void intel_dp_pps_init(struct drm_device *dev,
5398 struct intel_dp *intel_dp)
5399{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005400 struct drm_i915_private *dev_priv = to_i915(dev);
5401
5402 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Imre Deak335f7522016-08-10 14:07:32 +03005403 vlv_initial_power_sequencer_setup(intel_dp);
5404 } else {
5405 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005406 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak335f7522016-08-10 14:07:32 +03005407 }
5408}
5409
Vandana Kannanb33a2812015-02-13 15:33:03 +05305410/**
5411 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005412 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005413 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305414 * @refresh_rate: RR to be programmed
5415 *
5416 * This function gets called when refresh rate (RR) has to be changed from
5417 * one frequency to another. Switches can be between high and low RR
5418 * supported by the panel or to any other RR based on media playback (in
5419 * this case, RR value needs to be passed from user space).
5420 *
5421 * The caller of this function needs to take a lock on dev_priv->drrs.
5422 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005423static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
5424 struct intel_crtc_state *crtc_state,
5425 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305426{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305427 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305428 struct intel_digital_port *dig_port = NULL;
5429 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005430 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305431 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305432
5433 if (refresh_rate <= 0) {
5434 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5435 return;
5436 }
5437
Vandana Kannan96178ee2015-01-10 02:25:56 +05305438 if (intel_dp == NULL) {
5439 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305440 return;
5441 }
5442
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005443 /*
Rodrigo Vivie4d59f62014-11-20 02:22:08 -08005444 * FIXME: This needs proper synchronization with psr state for some
5445 * platforms that cannot have PSR and DRRS enabled at the same time.
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005446 */
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305447
Vandana Kannan96178ee2015-01-10 02:25:56 +05305448 dig_port = dp_to_dig_port(intel_dp);
5449 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02005450 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305451
5452 if (!intel_crtc) {
5453 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5454 return;
5455 }
5456
Vandana Kannan96178ee2015-01-10 02:25:56 +05305457 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305458 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5459 return;
5460 }
5461
Vandana Kannan96178ee2015-01-10 02:25:56 +05305462 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5463 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305464 index = DRRS_LOW_RR;
5465
Vandana Kannan96178ee2015-01-10 02:25:56 +05305466 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305467 DRM_DEBUG_KMS(
5468 "DRRS requested for previously set RR...ignoring\n");
5469 return;
5470 }
5471
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005472 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305473 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5474 return;
5475 }
5476
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005477 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305478 switch (index) {
5479 case DRRS_HIGH_RR:
5480 intel_dp_set_m_n(intel_crtc, M1_N1);
5481 break;
5482 case DRRS_LOW_RR:
5483 intel_dp_set_m_n(intel_crtc, M2_N2);
5484 break;
5485 case DRRS_MAX_RR:
5486 default:
5487 DRM_ERROR("Unsupported refreshrate type\n");
5488 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005489 } else if (INTEL_GEN(dev_priv) > 6) {
5490 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005491 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305492
Ville Syrjälä649636e2015-09-22 19:50:01 +03005493 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305494 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005495 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305496 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5497 else
5498 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305499 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005500 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305501 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5502 else
5503 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305504 }
5505 I915_WRITE(reg, val);
5506 }
5507
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305508 dev_priv->drrs.refresh_rate_type = index;
5509
5510 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5511}
5512
Vandana Kannanb33a2812015-02-13 15:33:03 +05305513/**
5514 * intel_edp_drrs_enable - init drrs struct if supported
5515 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005516 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305517 *
5518 * Initializes frontbuffer_bits and drrs.dp
5519 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005520void intel_edp_drrs_enable(struct intel_dp *intel_dp,
5521 struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305522{
5523 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005524 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305525
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005526 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305527 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5528 return;
5529 }
5530
5531 mutex_lock(&dev_priv->drrs.mutex);
5532 if (WARN_ON(dev_priv->drrs.dp)) {
5533 DRM_ERROR("DRRS already enabled\n");
5534 goto unlock;
5535 }
5536
5537 dev_priv->drrs.busy_frontbuffer_bits = 0;
5538
5539 dev_priv->drrs.dp = intel_dp;
5540
5541unlock:
5542 mutex_unlock(&dev_priv->drrs.mutex);
5543}
5544
Vandana Kannanb33a2812015-02-13 15:33:03 +05305545/**
5546 * intel_edp_drrs_disable - Disable DRRS
5547 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005548 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305549 *
5550 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005551void intel_edp_drrs_disable(struct intel_dp *intel_dp,
5552 struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305553{
5554 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005555 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305556
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005557 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305558 return;
5559
5560 mutex_lock(&dev_priv->drrs.mutex);
5561 if (!dev_priv->drrs.dp) {
5562 mutex_unlock(&dev_priv->drrs.mutex);
5563 return;
5564 }
5565
5566 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005567 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5568 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305569
5570 dev_priv->drrs.dp = NULL;
5571 mutex_unlock(&dev_priv->drrs.mutex);
5572
5573 cancel_delayed_work_sync(&dev_priv->drrs.work);
5574}
5575
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305576static void intel_edp_drrs_downclock_work(struct work_struct *work)
5577{
5578 struct drm_i915_private *dev_priv =
5579 container_of(work, typeof(*dev_priv), drrs.work.work);
5580 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305581
Vandana Kannan96178ee2015-01-10 02:25:56 +05305582 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305583
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305584 intel_dp = dev_priv->drrs.dp;
5585
5586 if (!intel_dp)
5587 goto unlock;
5588
5589 /*
5590 * The delayed work can race with an invalidate hence we need to
5591 * recheck.
5592 */
5593
5594 if (dev_priv->drrs.busy_frontbuffer_bits)
5595 goto unlock;
5596
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005597 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5598 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5599
5600 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5601 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5602 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305603
5604unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305605 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305606}
5607
Vandana Kannanb33a2812015-02-13 15:33:03 +05305608/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305609 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005610 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305611 * @frontbuffer_bits: frontbuffer plane tracking bits
5612 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305613 * This function gets called everytime rendering on the given planes start.
5614 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305615 *
5616 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5617 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005618void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5619 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305620{
Vandana Kannana93fad02015-01-10 02:25:59 +05305621 struct drm_crtc *crtc;
5622 enum pipe pipe;
5623
Daniel Vetter9da7d692015-04-09 16:44:15 +02005624 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305625 return;
5626
Daniel Vetter88f933a2015-04-09 16:44:16 +02005627 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305628
Vandana Kannana93fad02015-01-10 02:25:59 +05305629 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005630 if (!dev_priv->drrs.dp) {
5631 mutex_unlock(&dev_priv->drrs.mutex);
5632 return;
5633 }
5634
Vandana Kannana93fad02015-01-10 02:25:59 +05305635 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5636 pipe = to_intel_crtc(crtc)->pipe;
5637
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005638 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5639 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5640
Ramalingam C0ddfd202015-06-15 20:50:05 +05305641 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005642 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005643 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5644 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305645
Vandana Kannana93fad02015-01-10 02:25:59 +05305646 mutex_unlock(&dev_priv->drrs.mutex);
5647}
5648
Vandana Kannanb33a2812015-02-13 15:33:03 +05305649/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305650 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005651 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305652 * @frontbuffer_bits: frontbuffer plane tracking bits
5653 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305654 * This function gets called every time rendering on the given planes has
5655 * completed or flip on a crtc is completed. So DRRS should be upclocked
5656 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5657 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305658 *
5659 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5660 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005661void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5662 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305663{
Vandana Kannana93fad02015-01-10 02:25:59 +05305664 struct drm_crtc *crtc;
5665 enum pipe pipe;
5666
Daniel Vetter9da7d692015-04-09 16:44:15 +02005667 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305668 return;
5669
Daniel Vetter88f933a2015-04-09 16:44:16 +02005670 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305671
Vandana Kannana93fad02015-01-10 02:25:59 +05305672 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005673 if (!dev_priv->drrs.dp) {
5674 mutex_unlock(&dev_priv->drrs.mutex);
5675 return;
5676 }
5677
Vandana Kannana93fad02015-01-10 02:25:59 +05305678 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5679 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005680
5681 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305682 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5683
Ramalingam C0ddfd202015-06-15 20:50:05 +05305684 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005685 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005686 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5687 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305688
5689 /*
5690 * flush also means no more activity hence schedule downclock, if all
5691 * other fbs are quiescent too
5692 */
5693 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305694 schedule_delayed_work(&dev_priv->drrs.work,
5695 msecs_to_jiffies(1000));
5696 mutex_unlock(&dev_priv->drrs.mutex);
5697}
5698
Vandana Kannanb33a2812015-02-13 15:33:03 +05305699/**
5700 * DOC: Display Refresh Rate Switching (DRRS)
5701 *
5702 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5703 * which enables swtching between low and high refresh rates,
5704 * dynamically, based on the usage scenario. This feature is applicable
5705 * for internal panels.
5706 *
5707 * Indication that the panel supports DRRS is given by the panel EDID, which
5708 * would list multiple refresh rates for one resolution.
5709 *
5710 * DRRS is of 2 types - static and seamless.
5711 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5712 * (may appear as a blink on screen) and is used in dock-undock scenario.
5713 * Seamless DRRS involves changing RR without any visual effect to the user
5714 * and can be used during normal system usage. This is done by programming
5715 * certain registers.
5716 *
5717 * Support for static/seamless DRRS may be indicated in the VBT based on
5718 * inputs from the panel spec.
5719 *
5720 * DRRS saves power by switching to low RR based on usage scenarios.
5721 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005722 * The implementation is based on frontbuffer tracking implementation. When
5723 * there is a disturbance on the screen triggered by user activity or a periodic
5724 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5725 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5726 * made.
5727 *
5728 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5729 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305730 *
5731 * DRRS can be further extended to support other internal panels and also
5732 * the scenario of video playback wherein RR is set based on the rate
5733 * requested by userspace.
5734 */
5735
5736/**
5737 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5738 * @intel_connector: eDP connector
5739 * @fixed_mode: preferred mode of panel
5740 *
5741 * This function is called only once at driver load to initialize basic
5742 * DRRS stuff.
5743 *
5744 * Returns:
5745 * Downclock mode if panel supports it, else return NULL.
5746 * DRRS support is determined by the presence of downclock mode (apart
5747 * from VBT setting).
5748 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305749static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305750intel_dp_drrs_init(struct intel_connector *intel_connector,
5751 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305752{
5753 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305754 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005755 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305756 struct drm_display_mode *downclock_mode = NULL;
5757
Daniel Vetter9da7d692015-04-09 16:44:15 +02005758 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5759 mutex_init(&dev_priv->drrs.mutex);
5760
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005761 if (INTEL_GEN(dev_priv) <= 6) {
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305762 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5763 return NULL;
5764 }
5765
5766 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005767 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305768 return NULL;
5769 }
5770
5771 downclock_mode = intel_find_panel_downclock
Mika Kaholaa318b4c2016-12-13 10:02:48 +02005772 (dev_priv, fixed_mode, connector);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305773
5774 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305775 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305776 return NULL;
5777 }
5778
Vandana Kannan96178ee2015-01-10 02:25:56 +05305779 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305780
Vandana Kannan96178ee2015-01-10 02:25:56 +05305781 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005782 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305783 return downclock_mode;
5784}
5785
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005786static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005787 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005788{
5789 struct drm_connector *connector = &intel_connector->base;
5790 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005791 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5792 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005793 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005794 struct drm_display_mode *fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305795 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005796 bool has_dpcd;
5797 struct drm_display_mode *scan;
5798 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005799 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005800
5801 if (!is_edp(intel_dp))
5802 return true;
5803
Imre Deak97a824e12016-06-21 11:51:47 +03005804 /*
5805 * On IBX/CPT we may get here with LVDS already registered. Since the
5806 * driver uses the only internal power sequencer available for both
5807 * eDP and LVDS bail out early in this case to prevent interfering
5808 * with an already powered-on LVDS power sequencer.
5809 */
5810 if (intel_get_lvds_encoder(dev)) {
5811 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5812 DRM_INFO("LVDS was detected, not registering eDP\n");
5813
5814 return false;
5815 }
5816
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005817 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005818
5819 intel_dp_init_panel_power_timestamps(intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +03005820 intel_dp_pps_init(dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005821 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005822
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005823 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005824
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005825 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005826 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005827
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005828 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005829 /* if this fails, presume the device is a ghost */
5830 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005831 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005832 }
5833
Daniel Vetter060c8772014-03-21 23:22:35 +01005834 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005835 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005836 if (edid) {
5837 if (drm_add_edid_modes(connector, edid)) {
5838 drm_mode_connector_update_edid_property(connector,
5839 edid);
5840 drm_edid_to_eld(connector, edid);
5841 } else {
5842 kfree(edid);
5843 edid = ERR_PTR(-EINVAL);
5844 }
5845 } else {
5846 edid = ERR_PTR(-ENOENT);
5847 }
5848 intel_connector->edid = edid;
5849
5850 /* prefer fixed mode from EDID if available */
5851 list_for_each_entry(scan, &connector->probed_modes, head) {
5852 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5853 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305854 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305855 intel_connector, fixed_mode);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005856 break;
5857 }
5858 }
5859
5860 /* fallback to VBT if available for eDP */
5861 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5862 fixed_mode = drm_mode_duplicate(dev,
5863 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005864 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005865 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005866 connector->display_info.width_mm = fixed_mode->width_mm;
5867 connector->display_info.height_mm = fixed_mode->height_mm;
5868 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005869 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005870 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005871
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005872 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005873 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5874 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005875
5876 /*
5877 * Figure out the current pipe for the initial backlight setup.
5878 * If the current pipe isn't valid, try the PPS pipe, and if that
5879 * fails just assume pipe A.
5880 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005881 pipe = vlv_active_pipe(intel_dp);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005882
5883 if (pipe != PIPE_A && pipe != PIPE_B)
5884 pipe = intel_dp->pps_pipe;
5885
5886 if (pipe != PIPE_A && pipe != PIPE_B)
5887 pipe = PIPE_A;
5888
5889 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5890 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005891 }
5892
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305893 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005894 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005895 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005896
5897 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005898
5899out_vdd_off:
5900 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5901 /*
5902 * vdd might still be enabled do to the delayed vdd off.
5903 * Make sure vdd is actually turned off here.
5904 */
5905 pps_lock(intel_dp);
5906 edp_panel_vdd_off_sync(intel_dp);
5907 pps_unlock(intel_dp);
5908
5909 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005910}
5911
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005912static void
5913intel_dp_init_connector_port_info(struct intel_digital_port *intel_dig_port)
5914{
5915 struct intel_encoder *encoder = &intel_dig_port->base;
5916
5917 /* Set up the hotplug pin. */
5918 switch (intel_dig_port->port) {
5919 case PORT_A:
5920 encoder->hpd_pin = HPD_PORT_A;
5921 break;
5922 case PORT_B:
5923 encoder->hpd_pin = HPD_PORT_B;
5924 break;
5925 case PORT_C:
5926 encoder->hpd_pin = HPD_PORT_C;
5927 break;
5928 case PORT_D:
5929 encoder->hpd_pin = HPD_PORT_D;
5930 break;
5931 case PORT_E:
5932 encoder->hpd_pin = HPD_PORT_E;
5933 break;
5934 default:
5935 MISSING_CASE(intel_dig_port->port);
5936 }
5937}
5938
Paulo Zanoni16c25532013-06-12 17:27:25 -03005939bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005940intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5941 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005942{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005943 struct drm_connector *connector = &intel_connector->base;
5944 struct intel_dp *intel_dp = &intel_dig_port->dp;
5945 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5946 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005947 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02005948 enum port port = intel_dig_port->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01005949 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005950
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005951 if (WARN(intel_dig_port->max_lanes < 1,
5952 "Not enough lanes (%d) for DP on port %c\n",
5953 intel_dig_port->max_lanes, port_name(port)))
5954 return false;
5955
Manasi Navared7e8ef02017-02-07 16:54:11 -08005956 intel_dp->reset_link_params = true;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005957 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005958 intel_dp->active_pipe = INVALID_PIPE;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005959
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005960 /* intel_dp vfuncs */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005961 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub6b5e382014-01-20 16:00:59 +00005962 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005963 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005964 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005965 else if (HAS_PCH_SPLIT(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005966 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
5967 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005968 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005969
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005970 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00005971 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
5972 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005973 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00005974
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005975 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03005976 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
5977
Daniel Vetter07679352012-09-06 22:15:42 +02005978 /* Preserve the current hw state. */
5979 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03005980 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00005981
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005982 if (intel_dp_is_edp(dev_priv, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05305983 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005984 else
5985 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04005986
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005987 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5988 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5989
Imre Deakf7d24902013-05-08 13:14:05 +03005990 /*
5991 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
5992 * for DP the encoder type can be set by the caller to
5993 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
5994 */
5995 if (type == DRM_MODE_CONNECTOR_eDP)
5996 intel_encoder->type = INTEL_OUTPUT_EDP;
5997
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005998 /* eDP only on port B and/or C on vlv/chv */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005999 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08006000 is_edp(intel_dp) && port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03006001 return false;
6002
Imre Deake7281ea2013-05-08 13:14:08 +03006003 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
6004 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
6005 port_name(port));
6006
Adam Jacksonb3295302010-07-16 14:46:28 -04006007 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006008 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
6009
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006010 connector->interlace_allowed = true;
6011 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08006012
Mika Kaholab6339582016-09-09 14:10:52 +03006013 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01006014
Daniel Vetter66a92782012-07-12 20:08:18 +02006015 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01006016 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08006017
Chris Wilsondf0e9242010-09-09 16:20:55 +01006018 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006019
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006020 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02006021 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
6022 else
6023 intel_connector->get_hw_state = intel_connector_get_hw_state;
6024
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02006025 intel_dp_init_connector_port_info(intel_dig_port);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08006026
Dave Airlie0e32b392014-05-02 14:02:48 +10006027 /* init MST on ports that can support it */
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00006028 if (HAS_DP_MST(dev_priv) && !is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03006029 (port == PORT_B || port == PORT_C || port == PORT_D))
6030 intel_dp_mst_encoder_init(intel_dig_port,
6031 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10006032
Ville Syrjälä36b5f422014-10-16 21:27:30 +03006033 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006034 intel_dp_aux_fini(intel_dp);
6035 intel_dp_mst_encoder_cleanup(intel_dig_port);
6036 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03006037 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08006038
Chris Wilsonf6849602010-09-19 09:29:33 +01006039 intel_dp_add_properties(intel_dp, connector);
6040
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006041 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
6042 * 0xd. Failure to do so will result in spurious interrupts being
6043 * generated on the port when a cable is not attached.
6044 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01006045 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006046 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
6047 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
6048 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03006049
6050 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006051
6052fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006053 drm_connector_cleanup(connector);
6054
6055 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006056}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006057
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006058bool intel_dp_init(struct drm_i915_private *dev_priv,
Chris Wilson457c52d2016-06-01 08:27:50 +01006059 i915_reg_t output_reg,
6060 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006061{
6062 struct intel_digital_port *intel_dig_port;
6063 struct intel_encoder *intel_encoder;
6064 struct drm_encoder *encoder;
6065 struct intel_connector *intel_connector;
6066
Daniel Vetterb14c5672013-09-19 12:18:32 +02006067 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006068 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01006069 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006070
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03006071 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306072 if (!intel_connector)
6073 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006074
6075 intel_encoder = &intel_dig_port->base;
6076 encoder = &intel_encoder->base;
6077
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006078 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
6079 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
6080 "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306081 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006082
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01006083 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006084 intel_encoder->disable = intel_disable_dp;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006085 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07006086 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03006087 intel_encoder->suspend = intel_dp_encoder_suspend;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006088 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03006089 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03006090 intel_encoder->pre_enable = chv_pre_enable_dp;
6091 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03006092 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03006093 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01006094 } else if (IS_VALLEYVIEW(dev_priv)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006095 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006096 intel_encoder->pre_enable = vlv_pre_enable_dp;
6097 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03006098 intel_encoder->post_disable = vlv_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006099 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006100 intel_encoder->pre_enable = g4x_pre_enable_dp;
6101 intel_encoder->enable = g4x_enable_dp;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006102 if (INTEL_GEN(dev_priv) >= 5)
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03006103 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006104 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006105
Paulo Zanoni174edf12012-10-26 19:05:50 -02006106 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006107 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02006108 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006109
Ville Syrjäläcca05022016-06-22 21:57:06 +03006110 intel_encoder->type = INTEL_OUTPUT_DP;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006111 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03006112 if (port == PORT_D)
6113 intel_encoder->crtc_mask = 1 << 2;
6114 else
6115 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
6116 } else {
6117 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
6118 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02006119 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07006120 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006121
Dave Airlie13cf5502014-06-18 11:29:35 +10006122 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03006123 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10006124
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306125 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
6126 goto err_init_connector;
6127
Chris Wilson457c52d2016-06-01 08:27:50 +01006128 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306129
6130err_init_connector:
6131 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306132err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306133 kfree(intel_connector);
6134err_connector_alloc:
6135 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01006136 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006137}
Dave Airlie0e32b392014-05-02 14:02:48 +10006138
6139void intel_dp_mst_suspend(struct drm_device *dev)
6140{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006141 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006142 int i;
6143
6144 /* disable MST */
6145 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006146 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006147
6148 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006149 continue;
6150
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006151 if (intel_dig_port->dp.is_mst)
6152 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10006153 }
6154}
6155
6156void intel_dp_mst_resume(struct drm_device *dev)
6157{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006158 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006159 int i;
6160
6161 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006162 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006163 int ret;
6164
6165 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006166 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10006167
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006168 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
6169 if (ret)
6170 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10006171 }
6172}