blob: ee77b519835c5fd9d8c582a9c3169b43d06ebab6 [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
400 /*
401 * See vlv_power_sequencer_reset() why we need
402 * a power domain reference here.
403 */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +0200404 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300405
406 mutex_lock(&dev_priv->pps_mutex);
407}
408
409static void pps_unlock(struct intel_dp *intel_dp)
410{
411 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
412 struct intel_encoder *encoder = &intel_dig_port->base;
413 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100414 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300415
416 mutex_unlock(&dev_priv->pps_mutex);
417
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +0200418 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300419}
420
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300421static void
422vlv_power_sequencer_kick(struct intel_dp *intel_dp)
423{
424 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200425 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300426 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300427 bool pll_enabled, release_cl_override = false;
428 enum dpio_phy phy = DPIO_PHY(pipe);
429 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300430 uint32_t DP;
431
432 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
433 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
434 pipe_name(pipe), port_name(intel_dig_port->port)))
435 return;
436
437 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
438 pipe_name(pipe), port_name(intel_dig_port->port));
439
440 /* Preserve the BIOS-computed detected bit. This is
441 * supposed to be read-only.
442 */
443 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
444 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
445 DP |= DP_PORT_WIDTH(1);
446 DP |= DP_LINK_TRAIN_PAT_1;
447
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100448 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300449 DP |= DP_PIPE_SELECT_CHV(pipe);
450 else if (pipe == PIPE_B)
451 DP |= DP_PIPEB_SELECT;
452
Ville Syrjäläd288f652014-10-28 13:20:22 +0200453 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
454
455 /*
456 * The DPLL for the pipe must be enabled for this to work.
457 * So enable temporarily it if it's not already enabled.
458 */
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300459 if (!pll_enabled) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100460 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300461 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
462
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200463 if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ?
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000464 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
465 DRM_ERROR("Failed to force on pll for pipe %c!\n",
466 pipe_name(pipe));
467 return;
468 }
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300469 }
Ville Syrjäläd288f652014-10-28 13:20:22 +0200470
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300471 /*
472 * Similar magic as in intel_dp_enable_port().
473 * We _must_ do this port enable + disable trick
474 * to make this power seqeuencer lock onto the port.
475 * Otherwise even VDD force bit won't work.
476 */
477 I915_WRITE(intel_dp->output_reg, DP);
478 POSTING_READ(intel_dp->output_reg);
479
480 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
481 POSTING_READ(intel_dp->output_reg);
482
483 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
484 POSTING_READ(intel_dp->output_reg);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200485
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300486 if (!pll_enabled) {
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200487 vlv_force_pll_off(dev_priv, pipe);
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300488
489 if (release_cl_override)
490 chv_phy_powergate_ch(dev_priv, phy, ch, false);
491 }
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300492}
493
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200494static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv)
495{
496 struct intel_encoder *encoder;
497 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
498
499 /*
500 * We don't have power sequencer currently.
501 * Pick one that's not used by other ports.
502 */
503 for_each_intel_encoder(&dev_priv->drm, encoder) {
504 struct intel_dp *intel_dp;
505
506 if (encoder->type != INTEL_OUTPUT_DP &&
507 encoder->type != INTEL_OUTPUT_EDP)
508 continue;
509
510 intel_dp = enc_to_intel_dp(&encoder->base);
511
512 if (encoder->type == INTEL_OUTPUT_EDP) {
513 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
514 intel_dp->active_pipe != intel_dp->pps_pipe);
515
516 if (intel_dp->pps_pipe != INVALID_PIPE)
517 pipes &= ~(1 << intel_dp->pps_pipe);
518 } else {
519 WARN_ON(intel_dp->pps_pipe != INVALID_PIPE);
520
521 if (intel_dp->active_pipe != INVALID_PIPE)
522 pipes &= ~(1 << intel_dp->active_pipe);
523 }
524 }
525
526 if (pipes == 0)
527 return INVALID_PIPE;
528
529 return ffs(pipes) - 1;
530}
531
Jani Nikulabf13e812013-09-06 07:40:05 +0300532static enum pipe
533vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
534{
535 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300536 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100537 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300538 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300539
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300540 lockdep_assert_held(&dev_priv->pps_mutex);
541
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300542 /* We should never land here with regular DP ports */
543 WARN_ON(!is_edp(intel_dp));
544
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200545 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
546 intel_dp->active_pipe != intel_dp->pps_pipe);
547
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300548 if (intel_dp->pps_pipe != INVALID_PIPE)
549 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300550
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200551 pipe = vlv_find_free_pps(dev_priv);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300552
553 /*
554 * Didn't find one. This should not happen since there
555 * are two power sequencers and up to two eDP ports.
556 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200557 if (WARN_ON(pipe == INVALID_PIPE))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300558 pipe = PIPE_A;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300559
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300560 vlv_steal_power_sequencer(dev, pipe);
561 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300562
563 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
564 pipe_name(intel_dp->pps_pipe),
565 port_name(intel_dig_port->port));
566
567 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300568 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200569 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300570
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300571 /*
572 * Even vdd force doesn't work until we've made
573 * the power sequencer lock in on the port.
574 */
575 vlv_power_sequencer_kick(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300576
577 return intel_dp->pps_pipe;
578}
579
Imre Deak78597992016-06-16 16:37:20 +0300580static int
581bxt_power_sequencer_idx(struct intel_dp *intel_dp)
582{
583 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
584 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100585 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak78597992016-06-16 16:37:20 +0300586
587 lockdep_assert_held(&dev_priv->pps_mutex);
588
589 /* We should never land here with regular DP ports */
590 WARN_ON(!is_edp(intel_dp));
591
592 /*
593 * TODO: BXT has 2 PPS instances. The correct port->PPS instance
594 * mapping needs to be retrieved from VBT, for now just hard-code to
595 * use instance #0 always.
596 */
597 if (!intel_dp->pps_reset)
598 return 0;
599
600 intel_dp->pps_reset = false;
601
602 /*
603 * Only the HW needs to be reprogrammed, the SW state is fixed and
604 * has been setup during connector init.
605 */
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200606 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak78597992016-06-16 16:37:20 +0300607
608 return 0;
609}
610
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300611typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
612 enum pipe pipe);
613
614static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
615 enum pipe pipe)
616{
Imre Deak44cb7342016-08-10 14:07:29 +0300617 return I915_READ(PP_STATUS(pipe)) & PP_ON;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300618}
619
620static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
621 enum pipe pipe)
622{
Imre Deak44cb7342016-08-10 14:07:29 +0300623 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300624}
625
626static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
627 enum pipe pipe)
628{
629 return true;
630}
631
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300632static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300633vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
634 enum port port,
635 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300636{
Jani Nikulabf13e812013-09-06 07:40:05 +0300637 enum pipe pipe;
638
Jani Nikulabf13e812013-09-06 07:40:05 +0300639 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
Imre Deak44cb7342016-08-10 14:07:29 +0300640 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
Jani Nikulabf13e812013-09-06 07:40:05 +0300641 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300642
643 if (port_sel != PANEL_PORT_SELECT_VLV(port))
644 continue;
645
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300646 if (!pipe_check(dev_priv, pipe))
647 continue;
648
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300649 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300650 }
651
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300652 return INVALID_PIPE;
653}
654
655static void
656vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
657{
658 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
659 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100660 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300661 enum port port = intel_dig_port->port;
662
663 lockdep_assert_held(&dev_priv->pps_mutex);
664
665 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300666 /* first pick one where the panel is on */
667 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
668 vlv_pipe_has_pp_on);
669 /* didn't find one? pick one where vdd is on */
670 if (intel_dp->pps_pipe == INVALID_PIPE)
671 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
672 vlv_pipe_has_vdd_on);
673 /* didn't find one? pick one with just the correct port */
674 if (intel_dp->pps_pipe == INVALID_PIPE)
675 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
676 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300677
678 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
679 if (intel_dp->pps_pipe == INVALID_PIPE) {
680 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
681 port_name(port));
682 return;
683 }
684
685 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
686 port_name(port), pipe_name(intel_dp->pps_pipe));
687
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300688 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200689 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Jani Nikulabf13e812013-09-06 07:40:05 +0300690}
691
Imre Deak78597992016-06-16 16:37:20 +0300692void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300693{
Chris Wilson91c8a322016-07-05 10:40:23 +0100694 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300695 struct intel_encoder *encoder;
696
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100697 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200698 !IS_GEN9_LP(dev_priv)))
Ville Syrjälä773538e82014-09-04 14:54:56 +0300699 return;
700
701 /*
702 * We can't grab pps_mutex here due to deadlock with power_domain
703 * mutex when power_domain functions are called while holding pps_mutex.
704 * That also means that in order to use pps_pipe the code needs to
705 * hold both a power domain reference and pps_mutex, and the power domain
706 * reference get/put must be done while _not_ holding pps_mutex.
707 * pps_{lock,unlock}() do these steps in the correct order, so one
708 * should use them always.
709 */
710
Jani Nikula19c80542015-12-16 12:48:16 +0200711 for_each_intel_encoder(dev, encoder) {
Ville Syrjälä773538e82014-09-04 14:54:56 +0300712 struct intel_dp *intel_dp;
713
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200714 if (encoder->type != INTEL_OUTPUT_DP &&
715 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300716 continue;
717
718 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200719
720 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
721
722 if (encoder->type != INTEL_OUTPUT_EDP)
723 continue;
724
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200725 if (IS_GEN9_LP(dev_priv))
Imre Deak78597992016-06-16 16:37:20 +0300726 intel_dp->pps_reset = true;
727 else
728 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300729 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300730}
731
Imre Deak8e8232d2016-06-16 16:37:21 +0300732struct pps_registers {
733 i915_reg_t pp_ctrl;
734 i915_reg_t pp_stat;
735 i915_reg_t pp_on;
736 i915_reg_t pp_off;
737 i915_reg_t pp_div;
738};
739
740static void intel_pps_get_registers(struct drm_i915_private *dev_priv,
741 struct intel_dp *intel_dp,
742 struct pps_registers *regs)
743{
Imre Deak44cb7342016-08-10 14:07:29 +0300744 int pps_idx = 0;
745
Imre Deak8e8232d2016-06-16 16:37:21 +0300746 memset(regs, 0, sizeof(*regs));
747
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200748 if (IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300749 pps_idx = bxt_power_sequencer_idx(intel_dp);
750 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
751 pps_idx = vlv_power_sequencer_pipe(intel_dp);
Imre Deak8e8232d2016-06-16 16:37:21 +0300752
Imre Deak44cb7342016-08-10 14:07:29 +0300753 regs->pp_ctrl = PP_CONTROL(pps_idx);
754 regs->pp_stat = PP_STATUS(pps_idx);
755 regs->pp_on = PP_ON_DELAYS(pps_idx);
756 regs->pp_off = PP_OFF_DELAYS(pps_idx);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200757 if (!IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300758 regs->pp_div = PP_DIVISOR(pps_idx);
Imre Deak8e8232d2016-06-16 16:37:21 +0300759}
760
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200761static i915_reg_t
762_pp_ctrl_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300763{
Imre Deak8e8232d2016-06-16 16:37:21 +0300764 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300765
Imre Deak8e8232d2016-06-16 16:37:21 +0300766 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
767 &regs);
768
769 return regs.pp_ctrl;
Jani Nikulabf13e812013-09-06 07:40:05 +0300770}
771
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200772static i915_reg_t
773_pp_stat_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300774{
Imre Deak8e8232d2016-06-16 16:37:21 +0300775 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300776
Imre Deak8e8232d2016-06-16 16:37:21 +0300777 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
778 &regs);
779
780 return regs.pp_stat;
Jani Nikulabf13e812013-09-06 07:40:05 +0300781}
782
Clint Taylor01527b32014-07-07 13:01:46 -0700783/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
784 This function only applicable when panel PM state is not to be tracked */
785static int edp_notify_handler(struct notifier_block *this, unsigned long code,
786 void *unused)
787{
788 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
789 edp_notifier);
790 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100791 struct drm_i915_private *dev_priv = to_i915(dev);
Clint Taylor01527b32014-07-07 13:01:46 -0700792
793 if (!is_edp(intel_dp) || code != SYS_RESTART)
794 return 0;
795
Ville Syrjälä773538e82014-09-04 14:54:56 +0300796 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300797
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100798 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300799 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200800 i915_reg_t pp_ctrl_reg, pp_div_reg;
Ville Syrjälä649636e2015-09-22 19:50:01 +0300801 u32 pp_div;
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300802
Imre Deak44cb7342016-08-10 14:07:29 +0300803 pp_ctrl_reg = PP_CONTROL(pipe);
804 pp_div_reg = PP_DIVISOR(pipe);
Clint Taylor01527b32014-07-07 13:01:46 -0700805 pp_div = I915_READ(pp_div_reg);
806 pp_div &= PP_REFERENCE_DIVIDER_MASK;
807
808 /* 0x1F write to PP_DIV_REG sets max cycle delay */
809 I915_WRITE(pp_div_reg, pp_div | 0x1F);
810 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
811 msleep(intel_dp->panel_power_cycle_delay);
812 }
813
Ville Syrjälä773538e82014-09-04 14:54:56 +0300814 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300815
Clint Taylor01527b32014-07-07 13:01:46 -0700816 return 0;
817}
818
Daniel Vetter4be73782014-01-17 14:39:48 +0100819static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700820{
Paulo Zanoni30add222012-10-26 19:05:45 -0200821 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100822 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700823
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300824 lockdep_assert_held(&dev_priv->pps_mutex);
825
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100826 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300827 intel_dp->pps_pipe == INVALID_PIPE)
828 return false;
829
Jani Nikulabf13e812013-09-06 07:40:05 +0300830 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700831}
832
Daniel Vetter4be73782014-01-17 14:39:48 +0100833static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700834{
Paulo Zanoni30add222012-10-26 19:05:45 -0200835 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100836 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700837
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300838 lockdep_assert_held(&dev_priv->pps_mutex);
839
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100840 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300841 intel_dp->pps_pipe == INVALID_PIPE)
842 return false;
843
Ville Syrjälä773538e82014-09-04 14:54:56 +0300844 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700845}
846
Keith Packard9b984da2011-09-19 13:54:47 -0700847static void
848intel_dp_check_edp(struct intel_dp *intel_dp)
849{
Paulo Zanoni30add222012-10-26 19:05:45 -0200850 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100851 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700852
Keith Packard9b984da2011-09-19 13:54:47 -0700853 if (!is_edp(intel_dp))
854 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700855
Daniel Vetter4be73782014-01-17 14:39:48 +0100856 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700857 WARN(1, "eDP powered off while attempting aux channel communication.\n");
858 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300859 I915_READ(_pp_stat_reg(intel_dp)),
860 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700861 }
862}
863
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100864static uint32_t
865intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
866{
867 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
868 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100869 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200870 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100871 uint32_t status;
872 bool done;
873
Daniel Vetteref04f002012-12-01 21:03:59 +0100874#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100875 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300876 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300877 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100878 else
Imre Deak713a6b662016-06-28 13:37:33 +0300879 done = wait_for(C, 10) == 0;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100880 if (!done)
881 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
882 has_aux_irq);
883#undef C
884
885 return status;
886}
887
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200888static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000889{
890 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200891 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000892
Ville Syrjäläa457f542016-03-02 17:22:17 +0200893 if (index)
894 return 0;
895
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000896 /*
897 * The clock divider is based off the hrawclk, and would like to run at
Ville Syrjäläa457f542016-03-02 17:22:17 +0200898 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000899 */
Ville Syrjäläa457f542016-03-02 17:22:17 +0200900 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000901}
902
903static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
904{
905 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200906 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000907
908 if (index)
909 return 0;
910
Ville Syrjäläa457f542016-03-02 17:22:17 +0200911 /*
912 * The clock divider is based off the cdclk or PCH rawclk, and would
913 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
914 * divide by 2000 and use that
915 */
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200916 if (intel_dig_port->port == PORT_A)
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200917 return DIV_ROUND_CLOSEST(dev_priv->cdclk.hw.cdclk, 2000);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200918 else
919 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000920}
921
922static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300923{
924 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200925 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300926
Ville Syrjäläa457f542016-03-02 17:22:17 +0200927 if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300928 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100929 switch (index) {
930 case 0: return 63;
931 case 1: return 72;
932 default: return 0;
933 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300934 }
Ville Syrjäläa457f542016-03-02 17:22:17 +0200935
936 return ilk_get_aux_clock_divider(intel_dp, index);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300937}
938
Damien Lespiaub6b5e382014-01-20 16:00:59 +0000939static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
940{
941 /*
942 * SKL doesn't need us to program the AUX clock divider (Hardware will
943 * derive the clock from CDCLK automatically). We still implement the
944 * get_aux_clock_divider vfunc to plug-in into the existing code.
945 */
946 return index ? 0 : 1;
947}
948
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200949static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
950 bool has_aux_irq,
951 int send_bytes,
952 uint32_t aux_clock_divider)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000953{
954 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100955 struct drm_i915_private *dev_priv =
956 to_i915(intel_dig_port->base.base.dev);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000957 uint32_t precharge, timeout;
958
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100959 if (IS_GEN6(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000960 precharge = 3;
961 else
962 precharge = 5;
963
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100964 if (IS_BROADWELL(dev_priv) && intel_dig_port->port == PORT_A)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000965 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
966 else
967 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
968
969 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +0000970 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000971 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000972 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000973 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +0000974 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000975 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
976 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000977 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000978}
979
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000980static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
981 bool has_aux_irq,
982 int send_bytes,
983 uint32_t unused)
984{
985 return DP_AUX_CH_CTL_SEND_BUSY |
986 DP_AUX_CH_CTL_DONE |
987 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
988 DP_AUX_CH_CTL_TIME_OUT_ERROR |
989 DP_AUX_CH_CTL_TIME_OUT_1600us |
990 DP_AUX_CH_CTL_RECEIVE_ERROR |
991 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Daniel Vetterd4dcbdc2016-05-18 18:47:15 +0200992 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000993 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
994}
995
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700996static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100997intel_dp_aux_ch(struct intel_dp *intel_dp,
Daniel Vetterbd9f74a2014-10-02 09:45:35 +0200998 const uint8_t *send, int send_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700999 uint8_t *recv, int recv_size)
1000{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001001 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001002 struct drm_i915_private *dev_priv =
1003 to_i915(intel_dig_port->base.base.dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001004 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Chris Wilsonbc866252013-07-21 16:00:03 +01001005 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001006 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001007 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001008 int try, clock = 0;
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001009 bool has_aux_irq = HAS_AUX_IRQ(dev_priv);
Jani Nikula884f19e2014-03-14 16:51:14 +02001010 bool vdd;
1011
Ville Syrjälä773538e82014-09-04 14:54:56 +03001012 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001013
Ville Syrjälä72c35002014-08-18 22:16:00 +03001014 /*
1015 * We will be called with VDD already enabled for dpcd/edid/oui reads.
1016 * In such cases we want to leave VDD enabled and it's up to upper layers
1017 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
1018 * ourselves.
1019 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001020 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001021
1022 /* dp aux is extremely sensitive to irq latency, hence request the
1023 * lowest possible wakeup latency and so prevent the cpu from going into
1024 * deep sleep states.
1025 */
1026 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001027
Keith Packard9b984da2011-09-19 13:54:47 -07001028 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001029
Jesse Barnes11bee432011-08-01 15:02:20 -07001030 /* Try to wait for any previous AUX channel activity */
1031 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +01001032 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -07001033 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
1034 break;
1035 msleep(1);
1036 }
1037
1038 if (try == 3) {
Mika Kuoppala02196c72015-08-06 16:48:58 +03001039 static u32 last_status = -1;
1040 const u32 status = I915_READ(ch_ctl);
1041
1042 if (status != last_status) {
1043 WARN(1, "dp_aux_ch not started status 0x%08x\n",
1044 status);
1045 last_status = status;
1046 }
1047
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001048 ret = -EBUSY;
1049 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001050 }
1051
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001052 /* Only 5 data registers! */
1053 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
1054 ret = -E2BIG;
1055 goto out;
1056 }
1057
Damien Lespiauec5b01d2014-01-21 13:35:39 +00001058 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +00001059 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
1060 has_aux_irq,
1061 send_bytes,
1062 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001063
Chris Wilsonbc866252013-07-21 16:00:03 +01001064 /* Must try at least 3 times according to DP spec */
1065 for (try = 0; try < 5; try++) {
1066 /* Load the send data into the aux channel data registers */
1067 for (i = 0; i < send_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001068 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001069 intel_dp_pack_aux(send + i,
1070 send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -04001071
Chris Wilsonbc866252013-07-21 16:00:03 +01001072 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001073 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001074
Chris Wilsonbc866252013-07-21 16:00:03 +01001075 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -04001076
Chris Wilsonbc866252013-07-21 16:00:03 +01001077 /* Clear done status and any errors */
1078 I915_WRITE(ch_ctl,
1079 status |
1080 DP_AUX_CH_CTL_DONE |
1081 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1082 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -04001083
Todd Previte74ebf292015-04-15 08:38:41 -07001084 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
Chris Wilsonbc866252013-07-21 16:00:03 +01001085 continue;
Todd Previte74ebf292015-04-15 08:38:41 -07001086
1087 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
1088 * 400us delay required for errors and timeouts
1089 * Timeout errors from the HW already meet this
1090 * requirement so skip to next iteration
1091 */
1092 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1093 usleep_range(400, 500);
1094 continue;
1095 }
Chris Wilsonbc866252013-07-21 16:00:03 +01001096 if (status & DP_AUX_CH_CTL_DONE)
Jim Bridee058c942015-05-27 10:21:48 -07001097 goto done;
Chris Wilsonbc866252013-07-21 16:00:03 +01001098 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001099 }
1100
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001101 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001102 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001103 ret = -EBUSY;
1104 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001105 }
1106
Jim Bridee058c942015-05-27 10:21:48 -07001107done:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001108 /* Check for timeout or receive error.
1109 * Timeouts occur when the sink is not connected
1110 */
Keith Packarda5b3da52009-06-11 22:30:32 -07001111 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001112 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001113 ret = -EIO;
1114 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -07001115 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001116
1117 /* Timeouts occur when the device isn't connected, so they're
1118 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -07001119 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Chris Wilsona5570fe2017-02-23 11:51:02 +00001120 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001121 ret = -ETIMEDOUT;
1122 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001123 }
1124
1125 /* Unload any bytes sent back from the other side */
1126 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
1127 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Rodrigo Vivi14e01882015-12-10 11:12:27 -08001128
1129 /*
1130 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1131 * We have no idea of what happened so we return -EBUSY so
1132 * drm layer takes care for the necessary retries.
1133 */
1134 if (recv_bytes == 0 || recv_bytes > 20) {
1135 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1136 recv_bytes);
1137 /*
1138 * FIXME: This patch was created on top of a series that
1139 * organize the retries at drm level. There EBUSY should
1140 * also take care for 1ms wait before retrying.
1141 * That aux retries re-org is still needed and after that is
1142 * merged we remove this sleep from here.
1143 */
1144 usleep_range(1000, 1500);
1145 ret = -EBUSY;
1146 goto out;
1147 }
1148
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001149 if (recv_bytes > recv_size)
1150 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -04001151
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001152 for (i = 0; i < recv_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001153 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001154 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001155
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001156 ret = recv_bytes;
1157out:
1158 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1159
Jani Nikula884f19e2014-03-14 16:51:14 +02001160 if (vdd)
1161 edp_panel_vdd_off(intel_dp, false);
1162
Ville Syrjälä773538e82014-09-04 14:54:56 +03001163 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001164
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001165 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001166}
1167
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001168#define BARE_ADDRESS_SIZE 3
1169#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +02001170static ssize_t
1171intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001172{
Jani Nikula9d1a1032014-03-14 16:51:15 +02001173 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1174 uint8_t txbuf[20], rxbuf[20];
1175 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001176 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001177
Ville Syrjäläd2d9cbb2015-03-19 11:44:06 +02001178 txbuf[0] = (msg->request << 4) |
1179 ((msg->address >> 16) & 0xf);
1180 txbuf[1] = (msg->address >> 8) & 0xff;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001181 txbuf[2] = msg->address & 0xff;
1182 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001183
Jani Nikula9d1a1032014-03-14 16:51:15 +02001184 switch (msg->request & ~DP_AUX_I2C_MOT) {
1185 case DP_AUX_NATIVE_WRITE:
1186 case DP_AUX_I2C_WRITE:
Ville Syrjäläc1e741222015-08-27 17:23:27 +03001187 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001188 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001189 rxsize = 2; /* 0 or 1 data bytes */
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001190
Jani Nikula9d1a1032014-03-14 16:51:15 +02001191 if (WARN_ON(txsize > 20))
1192 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001193
Ville Syrjälädd788092016-07-28 17:55:04 +03001194 WARN_ON(!msg->buffer != !msg->size);
1195
Imre Deakd81a67c2016-01-29 14:52:26 +02001196 if (msg->buffer)
1197 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001198
Jani Nikula9d1a1032014-03-14 16:51:15 +02001199 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1200 if (ret > 0) {
1201 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001202
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001203 if (ret > 1) {
1204 /* Number of bytes written in a short write. */
1205 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1206 } else {
1207 /* Return payload size. */
1208 ret = msg->size;
1209 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001210 }
Jani Nikula9d1a1032014-03-14 16:51:15 +02001211 break;
1212
1213 case DP_AUX_NATIVE_READ:
1214 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001215 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001216 rxsize = msg->size + 1;
1217
1218 if (WARN_ON(rxsize > 20))
1219 return -E2BIG;
1220
1221 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1222 if (ret > 0) {
1223 msg->reply = rxbuf[0] >> 4;
1224 /*
1225 * Assume happy day, and copy the data. The caller is
1226 * expected to check msg->reply before touching it.
1227 *
1228 * Return payload size.
1229 */
1230 ret--;
1231 memcpy(msg->buffer, rxbuf + 1, ret);
1232 }
1233 break;
1234
1235 default:
1236 ret = -EINVAL;
1237 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001238 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001239
Jani Nikula9d1a1032014-03-14 16:51:15 +02001240 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001241}
1242
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001243static enum port intel_aux_port(struct drm_i915_private *dev_priv,
1244 enum port port)
1245{
1246 const struct ddi_vbt_port_info *info =
1247 &dev_priv->vbt.ddi_port_info[port];
1248 enum port aux_port;
1249
1250 if (!info->alternate_aux_channel) {
1251 DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
1252 port_name(port), port_name(port));
1253 return port;
1254 }
1255
1256 switch (info->alternate_aux_channel) {
1257 case DP_AUX_A:
1258 aux_port = PORT_A;
1259 break;
1260 case DP_AUX_B:
1261 aux_port = PORT_B;
1262 break;
1263 case DP_AUX_C:
1264 aux_port = PORT_C;
1265 break;
1266 case DP_AUX_D:
1267 aux_port = PORT_D;
1268 break;
1269 default:
1270 MISSING_CASE(info->alternate_aux_channel);
1271 aux_port = PORT_A;
1272 break;
1273 }
1274
1275 DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
1276 port_name(aux_port), port_name(port));
1277
1278 return aux_port;
1279}
1280
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001281static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001282 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001283{
1284 switch (port) {
1285 case PORT_B:
1286 case PORT_C:
1287 case PORT_D:
1288 return DP_AUX_CH_CTL(port);
1289 default:
1290 MISSING_CASE(port);
1291 return DP_AUX_CH_CTL(PORT_B);
1292 }
1293}
1294
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001295static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001296 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001297{
1298 switch (port) {
1299 case PORT_B:
1300 case PORT_C:
1301 case PORT_D:
1302 return DP_AUX_CH_DATA(port, index);
1303 default:
1304 MISSING_CASE(port);
1305 return DP_AUX_CH_DATA(PORT_B, index);
1306 }
1307}
1308
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001309static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001310 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001311{
1312 switch (port) {
1313 case PORT_A:
1314 return DP_AUX_CH_CTL(port);
1315 case PORT_B:
1316 case PORT_C:
1317 case PORT_D:
1318 return PCH_DP_AUX_CH_CTL(port);
1319 default:
1320 MISSING_CASE(port);
1321 return DP_AUX_CH_CTL(PORT_A);
1322 }
1323}
1324
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001325static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001326 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001327{
1328 switch (port) {
1329 case PORT_A:
1330 return DP_AUX_CH_DATA(port, index);
1331 case PORT_B:
1332 case PORT_C:
1333 case PORT_D:
1334 return PCH_DP_AUX_CH_DATA(port, index);
1335 default:
1336 MISSING_CASE(port);
1337 return DP_AUX_CH_DATA(PORT_A, index);
1338 }
1339}
1340
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001341static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001342 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001343{
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001344 switch (port) {
1345 case PORT_A:
1346 case PORT_B:
1347 case PORT_C:
1348 case PORT_D:
1349 return DP_AUX_CH_CTL(port);
1350 default:
1351 MISSING_CASE(port);
1352 return DP_AUX_CH_CTL(PORT_A);
1353 }
1354}
1355
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001356static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001357 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001358{
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001359 switch (port) {
1360 case PORT_A:
1361 case PORT_B:
1362 case PORT_C:
1363 case PORT_D:
1364 return DP_AUX_CH_DATA(port, index);
1365 default:
1366 MISSING_CASE(port);
1367 return DP_AUX_CH_DATA(PORT_A, index);
1368 }
1369}
1370
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001371static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001372 enum port port)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001373{
1374 if (INTEL_INFO(dev_priv)->gen >= 9)
1375 return skl_aux_ctl_reg(dev_priv, port);
1376 else if (HAS_PCH_SPLIT(dev_priv))
1377 return ilk_aux_ctl_reg(dev_priv, port);
1378 else
1379 return g4x_aux_ctl_reg(dev_priv, port);
1380}
1381
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001382static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001383 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001384{
1385 if (INTEL_INFO(dev_priv)->gen >= 9)
1386 return skl_aux_data_reg(dev_priv, port, index);
1387 else if (HAS_PCH_SPLIT(dev_priv))
1388 return ilk_aux_data_reg(dev_priv, port, index);
1389 else
1390 return g4x_aux_data_reg(dev_priv, port, index);
1391}
1392
1393static void intel_aux_reg_init(struct intel_dp *intel_dp)
1394{
1395 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001396 enum port port = intel_aux_port(dev_priv,
1397 dp_to_dig_port(intel_dp)->port);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001398 int i;
1399
1400 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1401 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1402 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1403}
1404
Jani Nikula9d1a1032014-03-14 16:51:15 +02001405static void
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001406intel_dp_aux_fini(struct intel_dp *intel_dp)
1407{
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001408 kfree(intel_dp->aux.name);
1409}
1410
Chris Wilson7a418e32016-06-24 14:00:14 +01001411static void
Mika Kaholab6339582016-09-09 14:10:52 +03001412intel_dp_aux_init(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001413{
Jani Nikula33ad6622014-03-14 16:51:16 +02001414 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1415 enum port port = intel_dig_port->port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001416
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001417 intel_aux_reg_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01001418 drm_dp_aux_init(&intel_dp->aux);
David Flynn8316f332010-12-08 16:10:21 +00001419
Chris Wilson7a418e32016-06-24 14:00:14 +01001420 /* Failure to allocate our preferred name is not critical */
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001421 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
Jani Nikula9d1a1032014-03-14 16:51:15 +02001422 intel_dp->aux.transfer = intel_dp_aux_transfer;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001423}
1424
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001425bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301426{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001427 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Navare, Manasi D577c5432016-09-27 16:36:53 -07001428 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001429
Navare, Manasi D577c5432016-09-27 16:36:53 -07001430 if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
1431 IS_BROADWELL(dev_priv) || (INTEL_GEN(dev_priv) >= 9))
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301432 return true;
1433 else
1434 return false;
1435}
1436
Daniel Vetter0e503382014-07-04 11:26:04 -03001437static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001438intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001439 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001440{
1441 struct drm_device *dev = encoder->base.dev;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001442 struct drm_i915_private *dev_priv = to_i915(dev);
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001443 const struct dp_link_dpll *divisor = NULL;
1444 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001445
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001446 if (IS_G4X(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001447 divisor = gen4_dpll;
1448 count = ARRAY_SIZE(gen4_dpll);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001449 } else if (HAS_PCH_SPLIT(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001450 divisor = pch_dpll;
1451 count = ARRAY_SIZE(pch_dpll);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001452 } else if (IS_CHERRYVIEW(dev_priv)) {
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001453 divisor = chv_dpll;
1454 count = ARRAY_SIZE(chv_dpll);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001455 } else if (IS_VALLEYVIEW(dev_priv)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001456 divisor = vlv_dpll;
1457 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001458 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001459
1460 if (divisor && count) {
1461 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001462 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001463 pipe_config->dpll = divisor[i].dpll;
1464 pipe_config->clock_set = true;
1465 break;
1466 }
1467 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001468 }
1469}
1470
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001471static void snprintf_int_array(char *str, size_t len,
1472 const int *array, int nelem)
1473{
1474 int i;
1475
1476 str[0] = '\0';
1477
1478 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001479 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001480 if (r >= len)
1481 return;
1482 str += r;
1483 len -= r;
1484 }
1485}
1486
1487static void intel_dp_print_rates(struct intel_dp *intel_dp)
1488{
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001489 const int *source_rates, *sink_rates;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001490 int source_len, sink_len, common_len;
1491 int common_rates[DP_MAX_SUPPORTED_RATES];
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001492 char str[128]; /* FIXME: too big for stack? */
1493
1494 if ((drm_debug & DRM_UT_KMS) == 0)
1495 return;
1496
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001497 source_len = intel_dp_source_rates(intel_dp, &source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001498 snprintf_int_array(str, sizeof(str), source_rates, source_len);
1499 DRM_DEBUG_KMS("source rates: %s\n", str);
1500
1501 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
1502 snprintf_int_array(str, sizeof(str), sink_rates, sink_len);
1503 DRM_DEBUG_KMS("sink rates: %s\n", str);
1504
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001505 common_len = intel_dp_common_rates(intel_dp, common_rates);
1506 snprintf_int_array(str, sizeof(str), common_rates, common_len);
1507 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001508}
1509
Imre Deak489375c2016-10-24 19:33:31 +03001510bool
Imre Deak7b3fc172016-10-25 16:12:39 +03001511__intel_dp_read_desc(struct intel_dp *intel_dp, struct intel_dp_desc *desc)
Mika Kahola0e390a32016-09-09 14:10:53 +03001512{
Imre Deak7b3fc172016-10-25 16:12:39 +03001513 u32 base = drm_dp_is_branch(intel_dp->dpcd) ? DP_BRANCH_OUI :
1514 DP_SINK_OUI;
Mika Kahola0e390a32016-09-09 14:10:53 +03001515
Imre Deak7b3fc172016-10-25 16:12:39 +03001516 return drm_dp_dpcd_read(&intel_dp->aux, base, desc, sizeof(*desc)) ==
1517 sizeof(*desc);
Mika Kahola0e390a32016-09-09 14:10:53 +03001518}
1519
Imre Deak12a47a422016-10-24 19:33:29 +03001520bool intel_dp_read_desc(struct intel_dp *intel_dp)
Mika Kahola1a2724f2016-09-09 14:10:54 +03001521{
Imre Deak7b3fc172016-10-25 16:12:39 +03001522 struct intel_dp_desc *desc = &intel_dp->desc;
1523 bool oui_sup = intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] &
1524 DP_OUI_SUPPORT;
1525 int dev_id_len;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001526
Imre Deak7b3fc172016-10-25 16:12:39 +03001527 if (!__intel_dp_read_desc(intel_dp, desc))
1528 return false;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001529
Imre Deak7b3fc172016-10-25 16:12:39 +03001530 dev_id_len = strnlen(desc->device_id, sizeof(desc->device_id));
1531 DRM_DEBUG_KMS("DP %s: OUI %*phD%s dev-ID %*pE HW-rev %d.%d SW-rev %d.%d\n",
1532 drm_dp_is_branch(intel_dp->dpcd) ? "branch" : "sink",
1533 (int)sizeof(desc->oui), desc->oui, oui_sup ? "" : "(NS)",
1534 dev_id_len, desc->device_id,
1535 desc->hw_rev >> 4, desc->hw_rev & 0xf,
1536 desc->sw_major_rev, desc->sw_minor_rev);
Mika Kahola1a2724f2016-09-09 14:10:54 +03001537
Imre Deak7b3fc172016-10-25 16:12:39 +03001538 return true;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001539}
1540
Ville Syrjäläf4896f12015-03-12 17:10:27 +02001541static int rate_to_index(int find, const int *rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301542{
1543 int i = 0;
1544
1545 for (i = 0; i < DP_MAX_SUPPORTED_RATES; ++i)
1546 if (find == rates[i])
1547 break;
1548
1549 return i;
1550}
1551
Ville Syrjälä50fec212015-03-12 17:10:34 +02001552int
1553intel_dp_max_link_rate(struct intel_dp *intel_dp)
1554{
1555 int rates[DP_MAX_SUPPORTED_RATES] = {};
1556 int len;
1557
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001558 len = intel_dp_common_rates(intel_dp, rates);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001559 if (WARN_ON(len <= 0))
1560 return 162000;
1561
Ville Syrjälä1354f732016-07-28 17:50:45 +03001562 return rates[len - 1];
Ville Syrjälä50fec212015-03-12 17:10:34 +02001563}
1564
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001565int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1566{
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001567 return rate_to_index(rate, intel_dp->sink_rates);
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001568}
1569
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001570void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1571 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001572{
1573 if (intel_dp->num_sink_rates) {
1574 *link_bw = 0;
1575 *rate_select =
1576 intel_dp_rate_select(intel_dp, port_clock);
1577 } else {
1578 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1579 *rate_select = 0;
1580 }
1581}
1582
Jani Nikulaf580bea2016-09-15 16:28:52 +03001583static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1584 struct intel_crtc_state *pipe_config)
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001585{
1586 int bpp, bpc;
1587
1588 bpp = pipe_config->pipe_bpp;
1589 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1590
1591 if (bpc > 0)
1592 bpp = min(bpp, 3*bpc);
1593
Manasi Navare611032b2017-01-24 08:21:49 -08001594 /* For DP Compliance we override the computed bpp for the pipe */
1595 if (intel_dp->compliance.test_data.bpc != 0) {
1596 pipe_config->pipe_bpp = 3*intel_dp->compliance.test_data.bpc;
1597 pipe_config->dither_force_disable = pipe_config->pipe_bpp == 6*3;
1598 DRM_DEBUG_KMS("Setting pipe_bpp to %d\n",
1599 pipe_config->pipe_bpp);
1600 }
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001601 return bpp;
1602}
1603
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001604bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001605intel_dp_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001606 struct intel_crtc_state *pipe_config,
1607 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001608{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001609 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001610 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001611 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001612 enum port port = dp_to_dig_port(intel_dp)->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001613 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001614 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001615 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001616 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001617 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001618 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001619 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301620 int max_clock;
Manasi Navareda15f7c2017-01-24 08:16:34 -08001621 int link_rate_index;
Daniel Vetter083f9562012-04-20 20:23:49 +02001622 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001623 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001624 int common_rates[DP_MAX_SUPPORTED_RATES] = {};
1625 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001626 uint8_t link_bw, rate_select;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301627
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001628 common_len = intel_dp_common_rates(intel_dp, common_rates);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301629
1630 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001631 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301632
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001633 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001634
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001635 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001636 pipe_config->has_pch_encoder = true;
1637
Vandana Kannanf769cd22014-08-05 07:51:22 -07001638 pipe_config->has_drrs = false;
Jani Nikula9fcb1702015-05-05 16:32:12 +03001639 pipe_config->has_audio = intel_dp->has_audio && port != PORT_A;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001640
Jani Nikuladd06f902012-10-19 14:51:50 +03001641 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1642 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
1643 adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001644
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001645 if (INTEL_GEN(dev_priv) >= 9) {
Chandra Kondurua1b22782015-04-07 15:28:45 -07001646 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001647 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001648 if (ret)
1649 return ret;
1650 }
1651
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001652 if (HAS_GMCH_DISPLAY(dev_priv))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001653 intel_gmch_panel_fitting(intel_crtc, pipe_config,
1654 intel_connector->panel.fitting_mode);
1655 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001656 intel_pch_panel_fitting(intel_crtc, pipe_config,
1657 intel_connector->panel.fitting_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001658 }
1659
Daniel Vettercb1793c2012-06-04 18:39:21 +02001660 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001661 return false;
1662
Manasi Navareda15f7c2017-01-24 08:16:34 -08001663 /* Use values requested by Compliance Test Request */
1664 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
1665 link_rate_index = intel_dp_link_rate_index(intel_dp,
1666 common_rates,
1667 intel_dp->compliance.test_link_rate);
1668 if (link_rate_index >= 0)
1669 min_clock = max_clock = link_rate_index;
1670 min_lane_count = max_lane_count = intel_dp->compliance.test_lane_count;
1671 }
Daniel Vetter083f9562012-04-20 20:23:49 +02001672 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301673 "max bw %d pixel clock %iKHz\n",
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001674 max_lane_count, common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001675 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001676
Daniel Vetter36008362013-03-27 00:44:59 +01001677 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1678 * bpc in between. */
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001679 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
Jani Nikula56071a22014-05-06 14:56:52 +03001680 if (is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301681
1682 /* Get bpp from vbt only for panels that dont have bpp in edid */
1683 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001684 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001685 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001686 dev_priv->vbt.edp.bpp);
1687 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001688 }
1689
Jani Nikula344c5bb2014-09-09 11:25:13 +03001690 /*
1691 * Use the maximum clock and number of lanes the eDP panel
1692 * advertizes being capable of. The panels are generally
1693 * designed to support only a single clock and lane
1694 * configuration, and typically these values correspond to the
1695 * native resolution of the panel.
1696 */
1697 min_lane_count = max_lane_count;
1698 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001699 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001700
Daniel Vetter36008362013-03-27 00:44:59 +01001701 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001702 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1703 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001704
Dave Airliec6930992014-07-14 11:04:39 +10001705 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301706 for (lane_count = min_lane_count;
1707 lane_count <= max_lane_count;
1708 lane_count <<= 1) {
1709
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001710 link_clock = common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001711 link_avail = intel_dp_max_data_rate(link_clock,
1712 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001713
Daniel Vetter36008362013-03-27 00:44:59 +01001714 if (mode_rate <= link_avail) {
1715 goto found;
1716 }
1717 }
1718 }
1719 }
1720
1721 return false;
1722
1723found:
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001724 if (intel_dp->color_range_auto) {
1725 /*
1726 * See:
1727 * CEA-861-E - 5.1 Default Encoding Parameters
1728 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1729 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001730 pipe_config->limited_color_range =
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02001731 bpp != 18 &&
1732 drm_default_rgb_quant_range(adjusted_mode) ==
1733 HDMI_QUANTIZATION_RANGE_LIMITED;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001734 } else {
1735 pipe_config->limited_color_range =
1736 intel_dp->limited_color_range;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001737 }
1738
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001739 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301740
Daniel Vetter657445f2013-05-04 10:09:18 +02001741 pipe_config->pipe_bpp = bpp;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001742 pipe_config->port_clock = common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001743
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001744 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1745 &link_bw, &rate_select);
1746
1747 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1748 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001749 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001750 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1751 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001752
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001753 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001754 adjusted_mode->crtc_clock,
1755 pipe_config->port_clock,
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001756 &pipe_config->dp_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001757
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301758 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301759 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001760 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301761 intel_link_compute_m_n(bpp, lane_count,
1762 intel_connector->panel.downclock_mode->clock,
1763 pipe_config->port_clock,
1764 &pipe_config->dp_m2_n2);
1765 }
1766
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001767 /*
1768 * DPLL0 VCO may need to be adjusted to get the correct
1769 * clock for eDP. This will affect cdclk as well.
1770 */
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001771 if (is_edp(intel_dp) && IS_GEN9_BC(dev_priv)) {
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001772 int vco;
1773
1774 switch (pipe_config->port_clock / 2) {
1775 case 108000:
1776 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001777 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001778 break;
1779 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001780 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001781 break;
1782 }
1783
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +02001784 to_intel_atomic_state(pipe_config->base.state)->cdclk.logical.vco = vco;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001785 }
1786
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001787 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001788 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001789
Daniel Vetter36008362013-03-27 00:44:59 +01001790 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001791}
1792
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001793void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001794 int link_rate, uint8_t lane_count,
1795 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001796{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001797 intel_dp->link_rate = link_rate;
1798 intel_dp->lane_count = lane_count;
1799 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001800}
1801
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001802static void intel_dp_prepare(struct intel_encoder *encoder,
1803 struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001804{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001805 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001806 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001807 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001808 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001809 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001810 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001811
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001812 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1813 pipe_config->lane_count,
1814 intel_crtc_has_type(pipe_config,
1815 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001816
Keith Packard417e8222011-11-01 19:54:11 -07001817 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001818 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001819 *
1820 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001821 * SNB CPU
1822 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001823 * CPT PCH
1824 *
1825 * IBX PCH and CPU are the same for almost everything,
1826 * except that the CPU DP PLL is configured in this
1827 * register
1828 *
1829 * CPT PCH is quite different, having many bits moved
1830 * to the TRANS_DP_CTL register instead. That
1831 * configuration happens (oddly) in ironlake_pch_enable
1832 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001833
Keith Packard417e8222011-11-01 19:54:11 -07001834 /* Preserve the BIOS-computed detected bit. This is
1835 * supposed to be read-only.
1836 */
1837 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001838
Keith Packard417e8222011-11-01 19:54:11 -07001839 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001840 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001841 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001842
Keith Packard417e8222011-11-01 19:54:11 -07001843 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001844
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001845 if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001846 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1847 intel_dp->DP |= DP_SYNC_HS_HIGH;
1848 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1849 intel_dp->DP |= DP_SYNC_VS_HIGH;
1850 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1851
Jani Nikula6aba5b62013-10-04 15:08:10 +03001852 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001853 intel_dp->DP |= DP_ENHANCED_FRAMING;
1854
Daniel Vetter7c62a162013-06-01 17:16:20 +02001855 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001856 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001857 u32 trans_dp;
1858
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001859 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001860
1861 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1862 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1863 trans_dp |= TRANS_DP_ENH_FRAMING;
1864 else
1865 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1866 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001867 } else {
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02001868 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001869 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001870
1871 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1872 intel_dp->DP |= DP_SYNC_HS_HIGH;
1873 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1874 intel_dp->DP |= DP_SYNC_VS_HIGH;
1875 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1876
Jani Nikula6aba5b62013-10-04 15:08:10 +03001877 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001878 intel_dp->DP |= DP_ENHANCED_FRAMING;
1879
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001880 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001881 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001882 else if (crtc->pipe == PIPE_B)
1883 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001884 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001885}
1886
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001887#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1888#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001889
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001890#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1891#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001892
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001893#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1894#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001895
Imre Deakde9c1b62016-06-16 20:01:46 +03001896static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
1897 struct intel_dp *intel_dp);
1898
Daniel Vetter4be73782014-01-17 14:39:48 +01001899static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001900 u32 mask,
1901 u32 value)
1902{
Paulo Zanoni30add222012-10-26 19:05:45 -02001903 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001904 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001905 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001906
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001907 lockdep_assert_held(&dev_priv->pps_mutex);
1908
Imre Deakde9c1b62016-06-16 20:01:46 +03001909 intel_pps_verify_state(dev_priv, intel_dp);
1910
Jani Nikulabf13e812013-09-06 07:40:05 +03001911 pp_stat_reg = _pp_stat_reg(intel_dp);
1912 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001913
1914 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001915 mask, value,
1916 I915_READ(pp_stat_reg),
1917 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001918
Chris Wilson9036ff02016-06-30 15:33:09 +01001919 if (intel_wait_for_register(dev_priv,
1920 pp_stat_reg, mask, value,
1921 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001922 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001923 I915_READ(pp_stat_reg),
1924 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001925
1926 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001927}
1928
Daniel Vetter4be73782014-01-17 14:39:48 +01001929static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001930{
1931 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001932 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001933}
1934
Daniel Vetter4be73782014-01-17 14:39:48 +01001935static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001936{
Keith Packardbd943152011-09-18 23:09:52 -07001937 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001938 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001939}
Keith Packardbd943152011-09-18 23:09:52 -07001940
Daniel Vetter4be73782014-01-17 14:39:48 +01001941static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001942{
Abhay Kumard28d4732016-01-22 17:39:04 -08001943 ktime_t panel_power_on_time;
1944 s64 panel_power_off_duration;
1945
Keith Packard99ea7122011-11-01 19:57:50 -07001946 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001947
Abhay Kumard28d4732016-01-22 17:39:04 -08001948 /* take the difference of currrent time and panel power off time
1949 * and then make panel wait for t11_t12 if needed. */
1950 panel_power_on_time = ktime_get_boottime();
1951 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1952
Paulo Zanonidce56b32013-12-19 14:29:40 -02001953 /* When we disable the VDD override bit last we have to do the manual
1954 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08001955 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
1956 wait_remaining_ms_from_jiffies(jiffies,
1957 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001958
Daniel Vetter4be73782014-01-17 14:39:48 +01001959 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001960}
Keith Packardbd943152011-09-18 23:09:52 -07001961
Daniel Vetter4be73782014-01-17 14:39:48 +01001962static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001963{
1964 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1965 intel_dp->backlight_on_delay);
1966}
1967
Daniel Vetter4be73782014-01-17 14:39:48 +01001968static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001969{
1970 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
1971 intel_dp->backlight_off_delay);
1972}
Keith Packard99ea7122011-11-01 19:57:50 -07001973
Keith Packard832dd3c2011-11-01 19:34:06 -07001974/* Read the current pp_control value, unlocking the register if it
1975 * is locked
1976 */
1977
Jesse Barnes453c5422013-03-28 09:55:41 -07001978static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07001979{
Jesse Barnes453c5422013-03-28 09:55:41 -07001980 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001981 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07001982 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07001983
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001984 lockdep_assert_held(&dev_priv->pps_mutex);
1985
Jani Nikulabf13e812013-09-06 07:40:05 +03001986 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03001987 if (WARN_ON(!HAS_DDI(dev_priv) &&
1988 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05301989 control &= ~PANEL_UNLOCK_MASK;
1990 control |= PANEL_UNLOCK_REGS;
1991 }
Keith Packard832dd3c2011-11-01 19:34:06 -07001992 return control;
Keith Packardbd943152011-09-18 23:09:52 -07001993}
1994
Ville Syrjälä951468f2014-09-04 14:55:31 +03001995/*
1996 * Must be paired with edp_panel_vdd_off().
1997 * Must hold pps_mutex around the whole on/off sequence.
1998 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
1999 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03002000static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002001{
Paulo Zanoni30add222012-10-26 19:05:45 -02002002 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002003 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002004 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes5d613502011-01-24 17:10:54 -08002005 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002006 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002007 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08002008
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002009 lockdep_assert_held(&dev_priv->pps_mutex);
2010
Keith Packard97af61f572011-09-28 16:23:51 -07002011 if (!is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002012 return false;
Keith Packardbd943152011-09-18 23:09:52 -07002013
Egbert Eich2c623c12014-11-25 12:54:57 +01002014 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002015 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07002016
Daniel Vetter4be73782014-01-17 14:39:48 +01002017 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002018 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002019
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002020 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002021
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002022 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
2023 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07002024
Daniel Vetter4be73782014-01-17 14:39:48 +01002025 if (!edp_have_panel_power(intel_dp))
2026 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07002027
Jesse Barnes453c5422013-03-28 09:55:41 -07002028 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002029 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07002030
Jani Nikulabf13e812013-09-06 07:40:05 +03002031 pp_stat_reg = _pp_stat_reg(intel_dp);
2032 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002033
2034 I915_WRITE(pp_ctrl_reg, pp);
2035 POSTING_READ(pp_ctrl_reg);
2036 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2037 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07002038 /*
2039 * If the panel wasn't on, delay before accessing aux channel
2040 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002041 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002042 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
2043 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07002044 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07002045 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002046
2047 return need_to_disable;
2048}
2049
Ville Syrjälä951468f2014-09-04 14:55:31 +03002050/*
2051 * Must be paired with intel_edp_panel_vdd_off() or
2052 * intel_edp_panel_off().
2053 * Nested calls to these functions are not allowed since
2054 * we drop the lock. Caller must use some higher level
2055 * locking to prevent nested calls from other threads.
2056 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01002057void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002058{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002059 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002060
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002061 if (!is_edp(intel_dp))
2062 return;
2063
Ville Syrjälä773538e82014-09-04 14:54:56 +03002064 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002065 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002066 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002067
Rob Clarke2c719b2014-12-15 13:56:32 -05002068 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002069 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08002070}
2071
Daniel Vetter4be73782014-01-17 14:39:48 +01002072static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002073{
Paulo Zanoni30add222012-10-26 19:05:45 -02002074 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002075 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002076 struct intel_digital_port *intel_dig_port =
2077 dp_to_dig_port(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002078 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002079 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002080
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002081 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002082
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002083 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002084
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002085 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002086 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002087
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002088 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2089 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002090
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002091 pp = ironlake_get_pp_control(intel_dp);
2092 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002093
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002094 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2095 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002096
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002097 I915_WRITE(pp_ctrl_reg, pp);
2098 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002099
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002100 /* Make sure sequencer is idle before allowing subsequent activity */
2101 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2102 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002103
Imre Deak5a162e22016-08-10 14:07:30 +03002104 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002105 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002106
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002107 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002108}
2109
Daniel Vetter4be73782014-01-17 14:39:48 +01002110static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002111{
2112 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2113 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002114
Ville Syrjälä773538e82014-09-04 14:54:56 +03002115 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002116 if (!intel_dp->want_panel_vdd)
2117 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002118 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002119}
2120
Imre Deakaba86892014-07-30 15:57:31 +03002121static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2122{
2123 unsigned long delay;
2124
2125 /*
2126 * Queue the timer to fire a long time from now (relative to the power
2127 * down delay) to keep the panel power up across a sequence of
2128 * operations.
2129 */
2130 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2131 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2132}
2133
Ville Syrjälä951468f2014-09-04 14:55:31 +03002134/*
2135 * Must be paired with edp_panel_vdd_on().
2136 * Must hold pps_mutex around the whole on/off sequence.
2137 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2138 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002139static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002140{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002141 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002142
2143 lockdep_assert_held(&dev_priv->pps_mutex);
2144
Keith Packard97af61f572011-09-28 16:23:51 -07002145 if (!is_edp(intel_dp))
2146 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002147
Rob Clarke2c719b2014-12-15 13:56:32 -05002148 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002149 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002150
Keith Packardbd943152011-09-18 23:09:52 -07002151 intel_dp->want_panel_vdd = false;
2152
Imre Deakaba86892014-07-30 15:57:31 +03002153 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002154 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002155 else
2156 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002157}
2158
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002159static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002160{
Paulo Zanoni30add222012-10-26 19:05:45 -02002161 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002162 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002163 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002164 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002165
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002166 lockdep_assert_held(&dev_priv->pps_mutex);
2167
Keith Packard97af61f572011-09-28 16:23:51 -07002168 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002169 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002170
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002171 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2172 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002173
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002174 if (WARN(edp_have_panel_power(intel_dp),
2175 "eDP port %c panel power already on\n",
2176 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002177 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002178
Daniel Vetter4be73782014-01-17 14:39:48 +01002179 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002180
Jani Nikulabf13e812013-09-06 07:40:05 +03002181 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002182 pp = ironlake_get_pp_control(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002183 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002184 /* ILK workaround: disable reset around power sequence */
2185 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002186 I915_WRITE(pp_ctrl_reg, pp);
2187 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002188 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002189
Imre Deak5a162e22016-08-10 14:07:30 +03002190 pp |= PANEL_POWER_ON;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002191 if (!IS_GEN5(dev_priv))
Keith Packard99ea7122011-11-01 19:57:50 -07002192 pp |= PANEL_POWER_RESET;
2193
Jesse Barnes453c5422013-03-28 09:55:41 -07002194 I915_WRITE(pp_ctrl_reg, pp);
2195 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002196
Daniel Vetter4be73782014-01-17 14:39:48 +01002197 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002198 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002199
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002200 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002201 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002202 I915_WRITE(pp_ctrl_reg, pp);
2203 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002204 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002205}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002206
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002207void intel_edp_panel_on(struct intel_dp *intel_dp)
2208{
2209 if (!is_edp(intel_dp))
2210 return;
2211
2212 pps_lock(intel_dp);
2213 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002214 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002215}
2216
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002217
2218static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002219{
Paulo Zanoni30add222012-10-26 19:05:45 -02002220 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002221 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002222 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002223 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002224
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002225 lockdep_assert_held(&dev_priv->pps_mutex);
2226
Keith Packard97af61f572011-09-28 16:23:51 -07002227 if (!is_edp(intel_dp))
2228 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002229
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002230 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2231 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002232
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002233 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2234 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002235
Jesse Barnes453c5422013-03-28 09:55:41 -07002236 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002237 /* We need to switch off panel power _and_ force vdd, for otherwise some
2238 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002239 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002240 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002241
Jani Nikulabf13e812013-09-06 07:40:05 +03002242 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002243
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002244 intel_dp->want_panel_vdd = false;
2245
Jesse Barnes453c5422013-03-28 09:55:41 -07002246 I915_WRITE(pp_ctrl_reg, pp);
2247 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002248
Abhay Kumard28d4732016-01-22 17:39:04 -08002249 intel_dp->panel_power_off_time = ktime_get_boottime();
Daniel Vetter4be73782014-01-17 14:39:48 +01002250 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002251
2252 /* We got a reference when we enabled the VDD. */
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02002253 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002254}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002255
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002256void intel_edp_panel_off(struct intel_dp *intel_dp)
2257{
2258 if (!is_edp(intel_dp))
2259 return;
2260
2261 pps_lock(intel_dp);
2262 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002263 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002264}
2265
Jani Nikula1250d102014-08-12 17:11:39 +03002266/* Enable backlight in the panel power control. */
2267static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002268{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002269 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2270 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002271 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002272 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002273 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002274
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002275 /*
2276 * If we enable the backlight right away following a panel power
2277 * on, we may see slight flicker as the panel syncs with the eDP
2278 * link. So delay a bit to make sure the image is solid before
2279 * allowing it to appear.
2280 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002281 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002282
Ville Syrjälä773538e82014-09-04 14:54:56 +03002283 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002284
Jesse Barnes453c5422013-03-28 09:55:41 -07002285 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002286 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002287
Jani Nikulabf13e812013-09-06 07:40:05 +03002288 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002289
2290 I915_WRITE(pp_ctrl_reg, pp);
2291 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002292
Ville Syrjälä773538e82014-09-04 14:54:56 +03002293 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002294}
2295
Jani Nikula1250d102014-08-12 17:11:39 +03002296/* Enable backlight PWM and backlight PP control. */
2297void intel_edp_backlight_on(struct intel_dp *intel_dp)
2298{
2299 if (!is_edp(intel_dp))
2300 return;
2301
2302 DRM_DEBUG_KMS("\n");
2303
2304 intel_panel_enable_backlight(intel_dp->attached_connector);
2305 _intel_edp_backlight_on(intel_dp);
2306}
2307
2308/* Disable backlight in the panel power control. */
2309static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002310{
Paulo Zanoni30add222012-10-26 19:05:45 -02002311 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002312 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002313 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002314 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002315
Keith Packardf01eca22011-09-28 16:48:10 -07002316 if (!is_edp(intel_dp))
2317 return;
2318
Ville Syrjälä773538e82014-09-04 14:54:56 +03002319 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002320
Jesse Barnes453c5422013-03-28 09:55:41 -07002321 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002322 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002323
Jani Nikulabf13e812013-09-06 07:40:05 +03002324 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002325
2326 I915_WRITE(pp_ctrl_reg, pp);
2327 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002328
Ville Syrjälä773538e82014-09-04 14:54:56 +03002329 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002330
Paulo Zanonidce56b32013-12-19 14:29:40 -02002331 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002332 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002333}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002334
Jani Nikula1250d102014-08-12 17:11:39 +03002335/* Disable backlight PP control and backlight PWM. */
2336void intel_edp_backlight_off(struct intel_dp *intel_dp)
2337{
2338 if (!is_edp(intel_dp))
2339 return;
2340
2341 DRM_DEBUG_KMS("\n");
2342
2343 _intel_edp_backlight_off(intel_dp);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002344 intel_panel_disable_backlight(intel_dp->attached_connector);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002345}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002346
Jani Nikula73580fb72014-08-12 17:11:41 +03002347/*
2348 * Hook for controlling the panel power control backlight through the bl_power
2349 * sysfs attribute. Take care to handle multiple calls.
2350 */
2351static void intel_edp_backlight_power(struct intel_connector *connector,
2352 bool enable)
2353{
2354 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002355 bool is_enabled;
2356
Ville Syrjälä773538e82014-09-04 14:54:56 +03002357 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002358 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002359 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002360
2361 if (is_enabled == enable)
2362 return;
2363
Jani Nikula23ba9372014-08-27 14:08:43 +03002364 DRM_DEBUG_KMS("panel power control backlight %s\n",
2365 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002366
2367 if (enable)
2368 _intel_edp_backlight_on(intel_dp);
2369 else
2370 _intel_edp_backlight_off(intel_dp);
2371}
2372
Ville Syrjälä64e10772015-10-29 21:26:01 +02002373static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2374{
2375 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2376 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2377 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2378
2379 I915_STATE_WARN(cur_state != state,
2380 "DP port %c state assertion failure (expected %s, current %s)\n",
2381 port_name(dig_port->port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002382 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002383}
2384#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2385
2386static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2387{
2388 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2389
2390 I915_STATE_WARN(cur_state != state,
2391 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002392 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002393}
2394#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2395#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2396
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002397static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2398 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002399{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002400 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002401 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002402
Ville Syrjälä64e10772015-10-29 21:26:01 +02002403 assert_pipe_disabled(dev_priv, crtc->pipe);
2404 assert_dp_port_disabled(intel_dp);
2405 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002406
Ville Syrjäläabfce942015-10-29 21:26:03 +02002407 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002408 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002409
2410 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2411
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002412 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002413 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2414 else
2415 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2416
2417 I915_WRITE(DP_A, intel_dp->DP);
2418 POSTING_READ(DP_A);
2419 udelay(500);
2420
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002421 /*
2422 * [DevILK] Work around required when enabling DP PLL
2423 * while a pipe is enabled going to FDI:
2424 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2425 * 2. Program DP PLL enable
2426 */
2427 if (IS_GEN5(dev_priv))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02002428 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002429
Daniel Vetter07679352012-09-06 22:15:42 +02002430 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002431
Daniel Vetter07679352012-09-06 22:15:42 +02002432 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002433 POSTING_READ(DP_A);
2434 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002435}
2436
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002437static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002438{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002439 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002440 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2441 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002442
Ville Syrjälä64e10772015-10-29 21:26:01 +02002443 assert_pipe_disabled(dev_priv, crtc->pipe);
2444 assert_dp_port_disabled(intel_dp);
2445 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002446
Ville Syrjäläabfce942015-10-29 21:26:03 +02002447 DRM_DEBUG_KMS("disabling eDP PLL\n");
2448
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002449 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002450
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002451 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002452 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002453 udelay(200);
2454}
2455
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002456/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002457void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002458{
2459 int ret, i;
2460
2461 /* Should have a valid DPCD by this point */
2462 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2463 return;
2464
2465 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002466 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2467 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002468 } else {
Imre Deak357c0ae2016-11-21 21:15:06 +02002469 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
2470
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002471 /*
2472 * When turning on, we need to retry for 1ms to give the sink
2473 * time to wake up.
2474 */
2475 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002476 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2477 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002478 if (ret == 1)
2479 break;
2480 msleep(1);
2481 }
Imre Deak357c0ae2016-11-21 21:15:06 +02002482
2483 if (ret == 1 && lspcon->active)
2484 lspcon_wait_pcon_mode(lspcon);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002485 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002486
2487 if (ret != 1)
2488 DRM_DEBUG_KMS("failed to %s sink power state\n",
2489 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002490}
2491
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002492static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2493 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002494{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002495 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002496 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002497 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002498 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002499 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002500 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002501
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002502 if (!intel_display_power_get_if_enabled(dev_priv,
2503 encoder->power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002504 return false;
2505
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002506 ret = false;
2507
Imre Deak6d129be2014-03-05 16:20:54 +02002508 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002509
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002510 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002511 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002512
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002513 if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002514 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002515 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002516 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002517
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002518 for_each_pipe(dev_priv, p) {
2519 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2520 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2521 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002522 ret = true;
2523
2524 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002525 }
2526 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002527
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002528 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002529 i915_mmio_reg_offset(intel_dp->output_reg));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002530 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002531 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2532 } else {
2533 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002534 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002535
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002536 ret = true;
2537
2538out:
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002539 intel_display_power_put(dev_priv, encoder->power_domain);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002540
2541 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002542}
2543
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002544static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002545 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002546{
2547 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002548 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002549 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002550 struct drm_i915_private *dev_priv = to_i915(dev);
Xiong Zhang63000ef2013-06-28 12:59:06 +08002551 enum port port = dp_to_dig_port(intel_dp)->port;
2552 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002553
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002554 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002555
2556 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002557
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002558 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002559 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2560
2561 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002562 flags |= DRM_MODE_FLAG_PHSYNC;
2563 else
2564 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002565
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002566 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002567 flags |= DRM_MODE_FLAG_PVSYNC;
2568 else
2569 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002570 } else {
2571 if (tmp & DP_SYNC_HS_HIGH)
2572 flags |= DRM_MODE_FLAG_PHSYNC;
2573 else
2574 flags |= DRM_MODE_FLAG_NHSYNC;
2575
2576 if (tmp & DP_SYNC_VS_HIGH)
2577 flags |= DRM_MODE_FLAG_PVSYNC;
2578 else
2579 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002580 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002581
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002582 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002583
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02002584 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002585 pipe_config->limited_color_range = true;
2586
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002587 pipe_config->lane_count =
2588 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2589
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002590 intel_dp_get_m_n(crtc, pipe_config);
2591
Ville Syrjälä18442d02013-09-13 16:00:08 +03002592 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002593 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002594 pipe_config->port_clock = 162000;
2595 else
2596 pipe_config->port_clock = 270000;
2597 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002598
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002599 pipe_config->base.adjusted_mode.crtc_clock =
2600 intel_dotclock_calculate(pipe_config->port_clock,
2601 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002602
Jani Nikula6aa23e62016-03-24 17:50:20 +02002603 if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
2604 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002605 /*
2606 * This is a big fat ugly hack.
2607 *
2608 * Some machines in UEFI boot mode provide us a VBT that has 18
2609 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2610 * unknown we fail to light up. Yet the same BIOS boots up with
2611 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2612 * max, not what it tells us to use.
2613 *
2614 * Note: This will still be broken if the eDP panel is not lit
2615 * up by the BIOS, and thus we can't get the mode at module
2616 * load.
2617 */
2618 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002619 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2620 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002621 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002622}
2623
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002624static void intel_disable_dp(struct intel_encoder *encoder,
2625 struct intel_crtc_state *old_crtc_state,
2626 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002627{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002628 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002629 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002630
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002631 if (old_crtc_state->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002632 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002633
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002634 if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv))
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002635 intel_psr_disable(intel_dp);
2636
Daniel Vetter6cb49832012-05-20 17:14:50 +02002637 /* Make sure the panel is off before trying to change the mode. But also
2638 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002639 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01002640 intel_edp_backlight_off(intel_dp);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002641 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002642 intel_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02002643
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002644 /* disable the port before the pipe on g4x */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002645 if (INTEL_GEN(dev_priv) < 5)
Daniel Vetter37398502012-09-06 22:15:44 +02002646 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07002647}
2648
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002649static void ilk_post_disable_dp(struct intel_encoder *encoder,
2650 struct intel_crtc_state *old_crtc_state,
2651 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002652{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002653 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002654 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002655
Ville Syrjälä49277c32014-03-31 18:21:26 +03002656 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002657
2658 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002659 if (port == PORT_A)
2660 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002661}
2662
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002663static void vlv_post_disable_dp(struct intel_encoder *encoder,
2664 struct intel_crtc_state *old_crtc_state,
2665 struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002666{
2667 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2668
2669 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002670}
2671
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002672static void chv_post_disable_dp(struct intel_encoder *encoder,
2673 struct intel_crtc_state *old_crtc_state,
2674 struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002675{
2676 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002677 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002678 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002679
2680 intel_dp_link_down(intel_dp);
2681
Ville Syrjäläa5805162015-05-26 20:42:30 +03002682 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002683
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002684 /* Assert data lane reset */
2685 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002686
Ville Syrjäläa5805162015-05-26 20:42:30 +03002687 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002688}
2689
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002690static void
2691_intel_dp_set_link_train(struct intel_dp *intel_dp,
2692 uint32_t *DP,
2693 uint8_t dp_train_pat)
2694{
2695 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2696 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002697 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002698 enum port port = intel_dig_port->port;
2699
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002700 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2701 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2702 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2703
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002704 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002705 uint32_t temp = I915_READ(DP_TP_CTL(port));
2706
2707 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2708 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2709 else
2710 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2711
2712 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2713 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2714 case DP_TRAINING_PATTERN_DISABLE:
2715 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2716
2717 break;
2718 case DP_TRAINING_PATTERN_1:
2719 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2720 break;
2721 case DP_TRAINING_PATTERN_2:
2722 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2723 break;
2724 case DP_TRAINING_PATTERN_3:
2725 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2726 break;
2727 }
2728 I915_WRITE(DP_TP_CTL(port), temp);
2729
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002730 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002731 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002732 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2733
2734 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2735 case DP_TRAINING_PATTERN_DISABLE:
2736 *DP |= DP_LINK_TRAIN_OFF_CPT;
2737 break;
2738 case DP_TRAINING_PATTERN_1:
2739 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2740 break;
2741 case DP_TRAINING_PATTERN_2:
2742 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2743 break;
2744 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002745 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002746 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2747 break;
2748 }
2749
2750 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002751 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002752 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2753 else
2754 *DP &= ~DP_LINK_TRAIN_MASK;
2755
2756 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2757 case DP_TRAINING_PATTERN_DISABLE:
2758 *DP |= DP_LINK_TRAIN_OFF;
2759 break;
2760 case DP_TRAINING_PATTERN_1:
2761 *DP |= DP_LINK_TRAIN_PAT_1;
2762 break;
2763 case DP_TRAINING_PATTERN_2:
2764 *DP |= DP_LINK_TRAIN_PAT_2;
2765 break;
2766 case DP_TRAINING_PATTERN_3:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002767 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002768 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2769 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002770 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002771 *DP |= DP_LINK_TRAIN_PAT_2;
2772 }
2773 break;
2774 }
2775 }
2776}
2777
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002778static void intel_dp_enable_port(struct intel_dp *intel_dp,
2779 struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002780{
2781 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002782 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002783
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002784 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002785
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002786 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002787
2788 /*
2789 * Magic for VLV/CHV. We _must_ first set up the register
2790 * without actually enabling the port, and then do another
2791 * write to enable the port. Otherwise link training will
2792 * fail when the power sequencer is freshly used for this port.
2793 */
2794 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002795 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002796 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002797
2798 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2799 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002800}
2801
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002802static void intel_enable_dp(struct intel_encoder *encoder,
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002803 struct intel_crtc_state *pipe_config,
2804 struct drm_connector_state *conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002805{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002806 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2807 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002808 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulac1dec792014-10-27 16:26:56 +02002809 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002810 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002811 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002812
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002813 if (WARN_ON(dp_reg & DP_PORT_EN))
2814 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002815
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002816 pps_lock(intel_dp);
2817
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002818 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002819 vlv_init_panel_power_sequencer(intel_dp);
2820
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002821 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002822
2823 edp_panel_vdd_on(intel_dp);
2824 edp_panel_on(intel_dp);
2825 edp_panel_vdd_off(intel_dp, true);
2826
2827 pps_unlock(intel_dp);
2828
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002829 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002830 unsigned int lane_mask = 0x0;
2831
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002832 if (IS_CHERRYVIEW(dev_priv))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002833 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002834
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002835 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2836 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002837 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002838
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002839 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2840 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002841 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002842
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002843 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002844 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002845 pipe_name(pipe));
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002846 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Jani Nikulac1dec792014-10-27 16:26:56 +02002847 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002848}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002849
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002850static void g4x_enable_dp(struct intel_encoder *encoder,
2851 struct intel_crtc_state *pipe_config,
2852 struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03002853{
Jani Nikula828f5c62013-09-05 16:44:45 +03002854 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2855
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002856 intel_enable_dp(encoder, pipe_config, conn_state);
Daniel Vetter4be73782014-01-17 14:39:48 +01002857 intel_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002858}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002859
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002860static void vlv_enable_dp(struct intel_encoder *encoder,
2861 struct intel_crtc_state *pipe_config,
2862 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002863{
Jani Nikula828f5c62013-09-05 16:44:45 +03002864 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2865
Daniel Vetter4be73782014-01-17 14:39:48 +01002866 intel_edp_backlight_on(intel_dp);
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002867 intel_psr_enable(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002868}
2869
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002870static void g4x_pre_enable_dp(struct intel_encoder *encoder,
2871 struct intel_crtc_state *pipe_config,
2872 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002873{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002874 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002875 enum port port = dp_to_dig_port(intel_dp)->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002876
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002877 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002878
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002879 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002880 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002881 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002882}
2883
Ville Syrjälä83b84592014-10-16 21:29:51 +03002884static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2885{
2886 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002887 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002888 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03002889 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002890
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002891 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
2892
Ville Syrjäläd1586942017-02-08 19:52:54 +02002893 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2894 return;
2895
Ville Syrjälä83b84592014-10-16 21:29:51 +03002896 edp_panel_vdd_off_sync(intel_dp);
2897
2898 /*
2899 * VLV seems to get confused when multiple power seqeuencers
2900 * have the same port selected (even if only one has power/vdd
2901 * enabled). The failure manifests as vlv_wait_port_ready() failing
2902 * CHV on the other hand doesn't seem to mind having the same port
2903 * selected in multiple power seqeuencers, but let's clear the
2904 * port select always when logically disconnecting a power sequencer
2905 * from a port.
2906 */
2907 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2908 pipe_name(pipe), port_name(intel_dig_port->port));
2909 I915_WRITE(pp_on_reg, 0);
2910 POSTING_READ(pp_on_reg);
2911
2912 intel_dp->pps_pipe = INVALID_PIPE;
2913}
2914
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002915static void vlv_steal_power_sequencer(struct drm_device *dev,
2916 enum pipe pipe)
2917{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002918 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002919 struct intel_encoder *encoder;
2920
2921 lockdep_assert_held(&dev_priv->pps_mutex);
2922
Jani Nikula19c80542015-12-16 12:48:16 +02002923 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002924 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002925 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002926
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002927 if (encoder->type != INTEL_OUTPUT_DP &&
2928 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002929 continue;
2930
2931 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002932 port = dp_to_dig_port(intel_dp)->port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002933
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002934 WARN(intel_dp->active_pipe == pipe,
2935 "stealing pipe %c power sequencer from active (e)DP port %c\n",
2936 pipe_name(pipe), port_name(port));
2937
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002938 if (intel_dp->pps_pipe != pipe)
2939 continue;
2940
2941 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03002942 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002943
2944 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002945 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002946 }
2947}
2948
2949static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
2950{
2951 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2952 struct intel_encoder *encoder = &intel_dig_port->base;
2953 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002954 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002955 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002956
2957 lockdep_assert_held(&dev_priv->pps_mutex);
2958
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002959 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002960
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002961 if (intel_dp->pps_pipe != INVALID_PIPE &&
2962 intel_dp->pps_pipe != crtc->pipe) {
2963 /*
2964 * If another power sequencer was being used on this
2965 * port previously make sure to turn off vdd there while
2966 * we still have control of it.
2967 */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002968 vlv_detach_power_sequencer(intel_dp);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002969 }
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002970
2971 /*
2972 * We may be stealing the power
2973 * sequencer from another port.
2974 */
2975 vlv_steal_power_sequencer(dev, crtc->pipe);
2976
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002977 intel_dp->active_pipe = crtc->pipe;
2978
2979 if (!is_edp(intel_dp))
2980 return;
2981
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002982 /* now it's all ours */
2983 intel_dp->pps_pipe = crtc->pipe;
2984
2985 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
2986 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
2987
2988 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03002989 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02002990 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002991}
2992
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002993static void vlv_pre_enable_dp(struct intel_encoder *encoder,
2994 struct intel_crtc_state *pipe_config,
2995 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002996{
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03002997 vlv_phy_pre_encoder_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002998
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002999 intel_enable_dp(encoder, pipe_config, conn_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003000}
3001
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003002static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
3003 struct intel_crtc_state *pipe_config,
3004 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07003005{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003006 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02003007
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03003008 vlv_phy_pre_pll_enable(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003009}
3010
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003011static void chv_pre_enable_dp(struct intel_encoder *encoder,
3012 struct intel_crtc_state *pipe_config,
3013 struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003014{
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003015 chv_phy_pre_encoder_enable(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003016
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003017 intel_enable_dp(encoder, pipe_config, conn_state);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03003018
3019 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003020 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003021}
3022
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003023static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
3024 struct intel_crtc_state *pipe_config,
3025 struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03003026{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003027 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03003028
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03003029 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03003030}
3031
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003032static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
3033 struct intel_crtc_state *pipe_config,
3034 struct drm_connector_state *conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003035{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03003036 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003037}
3038
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003039/*
3040 * Fetch AUX CH registers 0x202 - 0x207 which contain
3041 * link status information
3042 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003043bool
Keith Packard93f62da2011-11-01 19:45:03 -07003044intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003045{
Lyude9f085eb2016-04-13 10:58:33 -04003046 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
3047 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003048}
3049
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303050static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp)
3051{
3052 uint8_t psr_caps = 0;
3053
3054 drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps);
3055 return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED;
3056}
3057
3058static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp)
3059{
3060 uint8_t dprx = 0;
3061
3062 drm_dp_dpcd_readb(&intel_dp->aux,
3063 DP_DPRX_FEATURE_ENUMERATION_LIST,
3064 &dprx);
3065 return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED;
3066}
3067
Chris Wilsona76f73d2017-01-14 10:51:13 +00003068static bool intel_dp_get_alpm_status(struct intel_dp *intel_dp)
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303069{
3070 uint8_t alpm_caps = 0;
3071
3072 drm_dp_dpcd_readb(&intel_dp->aux, DP_RECEIVER_ALPM_CAP, &alpm_caps);
3073 return alpm_caps & DP_ALPM_CAP;
3074}
3075
Paulo Zanoni11002442014-06-13 18:45:41 -03003076/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003077uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003078intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003079{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003080 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003081 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003082
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003083 if (IS_GEN9_LP(dev_priv))
Vandana Kannan93147262014-11-18 15:45:29 +05303084 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003085 else if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjäläffe51112017-02-23 19:49:01 +02003086 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3087 return intel_ddi_dp_voltage_max(encoder);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003088 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Sonika Jindalbd600182014-08-08 16:23:41 +05303089 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003090 else if (IS_GEN7(dev_priv) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303091 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003092 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303093 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08003094 else
Sonika Jindalbd600182014-08-08 16:23:41 +05303095 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08003096}
3097
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003098uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003099intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3100{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003101 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003102 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003103
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003104 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003105 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3106 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3107 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3108 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3109 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3110 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3111 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303112 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3113 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003114 default:
3115 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3116 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003117 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003118 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303119 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3120 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3121 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3122 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3123 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3124 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3125 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003126 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303127 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003128 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003129 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003130 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303131 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3132 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3133 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3134 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3135 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3136 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3137 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003138 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303139 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003140 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003141 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003142 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303143 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3144 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3145 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3146 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3147 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003148 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303149 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003150 }
3151 } else {
3152 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303153 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3154 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3155 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3156 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3157 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3158 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3159 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003160 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303161 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003162 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003163 }
3164}
3165
Daniel Vetter5829975c2015-04-16 11:36:52 +02003166static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003167{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003168 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003169 unsigned long demph_reg_value, preemph_reg_value,
3170 uniqtranscale_reg_value;
3171 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003172
3173 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303174 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003175 preemph_reg_value = 0x0004000;
3176 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303177 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003178 demph_reg_value = 0x2B405555;
3179 uniqtranscale_reg_value = 0x552AB83A;
3180 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303181 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003182 demph_reg_value = 0x2B404040;
3183 uniqtranscale_reg_value = 0x5548B83A;
3184 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303185 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003186 demph_reg_value = 0x2B245555;
3187 uniqtranscale_reg_value = 0x5560B83A;
3188 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303189 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003190 demph_reg_value = 0x2B405555;
3191 uniqtranscale_reg_value = 0x5598DA3A;
3192 break;
3193 default:
3194 return 0;
3195 }
3196 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303197 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003198 preemph_reg_value = 0x0002000;
3199 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303200 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003201 demph_reg_value = 0x2B404040;
3202 uniqtranscale_reg_value = 0x5552B83A;
3203 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303204 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003205 demph_reg_value = 0x2B404848;
3206 uniqtranscale_reg_value = 0x5580B83A;
3207 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303208 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003209 demph_reg_value = 0x2B404040;
3210 uniqtranscale_reg_value = 0x55ADDA3A;
3211 break;
3212 default:
3213 return 0;
3214 }
3215 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303216 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003217 preemph_reg_value = 0x0000000;
3218 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303219 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003220 demph_reg_value = 0x2B305555;
3221 uniqtranscale_reg_value = 0x5570B83A;
3222 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303223 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003224 demph_reg_value = 0x2B2B4040;
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_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003232 preemph_reg_value = 0x0006000;
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 = 0x1B405555;
3236 uniqtranscale_reg_value = 0x55ADDA3A;
3237 break;
3238 default:
3239 return 0;
3240 }
3241 break;
3242 default:
3243 return 0;
3244 }
3245
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003246 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3247 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003248
3249 return 0;
3250}
3251
Daniel Vetter5829975c2015-04-16 11:36:52 +02003252static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003253{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003254 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3255 u32 deemph_reg_value, margin_reg_value;
3256 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003257 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003258
3259 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303260 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003261 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303262 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003263 deemph_reg_value = 128;
3264 margin_reg_value = 52;
3265 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303266 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003267 deemph_reg_value = 128;
3268 margin_reg_value = 77;
3269 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303270 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003271 deemph_reg_value = 128;
3272 margin_reg_value = 102;
3273 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303274 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003275 deemph_reg_value = 128;
3276 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003277 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003278 break;
3279 default:
3280 return 0;
3281 }
3282 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303283 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003284 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303285 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003286 deemph_reg_value = 85;
3287 margin_reg_value = 78;
3288 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303289 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003290 deemph_reg_value = 85;
3291 margin_reg_value = 116;
3292 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303293 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003294 deemph_reg_value = 85;
3295 margin_reg_value = 154;
3296 break;
3297 default:
3298 return 0;
3299 }
3300 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303301 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003302 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303303 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003304 deemph_reg_value = 64;
3305 margin_reg_value = 104;
3306 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303307 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003308 deemph_reg_value = 64;
3309 margin_reg_value = 154;
3310 break;
3311 default:
3312 return 0;
3313 }
3314 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303315 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003316 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303317 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003318 deemph_reg_value = 43;
3319 margin_reg_value = 154;
3320 break;
3321 default:
3322 return 0;
3323 }
3324 break;
3325 default:
3326 return 0;
3327 }
3328
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003329 chv_set_phy_signal_level(encoder, deemph_reg_value,
3330 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003331
3332 return 0;
3333}
3334
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003335static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003336gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003337{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003338 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003339
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003340 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303341 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003342 default:
3343 signal_levels |= DP_VOLTAGE_0_4;
3344 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303345 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003346 signal_levels |= DP_VOLTAGE_0_6;
3347 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303348 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003349 signal_levels |= DP_VOLTAGE_0_8;
3350 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303351 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003352 signal_levels |= DP_VOLTAGE_1_2;
3353 break;
3354 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003355 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303356 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003357 default:
3358 signal_levels |= DP_PRE_EMPHASIS_0;
3359 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303360 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003361 signal_levels |= DP_PRE_EMPHASIS_3_5;
3362 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303363 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003364 signal_levels |= DP_PRE_EMPHASIS_6;
3365 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303366 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003367 signal_levels |= DP_PRE_EMPHASIS_9_5;
3368 break;
3369 }
3370 return signal_levels;
3371}
3372
Zhenyu Wange3421a12010-04-08 09:43:27 +08003373/* Gen6's DP voltage swing and pre-emphasis control */
3374static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003375gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003376{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003377 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3378 DP_TRAIN_PRE_EMPHASIS_MASK);
3379 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303380 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3381 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003382 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303383 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003384 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303385 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3386 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003387 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303388 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3389 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003390 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303391 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3392 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003393 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003394 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003395 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3396 "0x%x\n", signal_levels);
3397 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003398 }
3399}
3400
Keith Packard1a2eb462011-11-16 16:26:07 -08003401/* Gen7's DP voltage swing and pre-emphasis control */
3402static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003403gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003404{
3405 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3406 DP_TRAIN_PRE_EMPHASIS_MASK);
3407 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303408 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003409 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303410 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003411 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303412 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003413 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3414
Sonika Jindalbd600182014-08-08 16:23:41 +05303415 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003416 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303417 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003418 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3419
Sonika Jindalbd600182014-08-08 16:23:41 +05303420 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003421 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303422 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003423 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3424
3425 default:
3426 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3427 "0x%x\n", signal_levels);
3428 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3429 }
3430}
3431
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003432void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003433intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003434{
3435 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003436 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003437 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003438 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003439 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003440 uint8_t train_set = intel_dp->train_set[0];
3441
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003442 if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003443 signal_levels = ddi_signal_levels(intel_dp);
3444
Michel Thierry254e0932017-01-09 16:51:35 +02003445 if (IS_GEN9_LP(dev_priv))
David Weinehallf8896f52015-06-25 11:11:03 +03003446 signal_levels = 0;
3447 else
3448 mask = DDI_BUF_EMP_MASK;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003449 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003450 signal_levels = chv_signal_levels(intel_dp);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003451 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003452 signal_levels = vlv_signal_levels(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003453 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003454 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003455 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003456 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003457 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003458 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3459 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003460 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003461 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3462 }
3463
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303464 if (mask)
3465 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3466
3467 DRM_DEBUG_KMS("Using vswing level %d\n",
3468 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3469 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3470 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3471 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003472
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003473 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003474
3475 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3476 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003477}
3478
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003479void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003480intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3481 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003482{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003483 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003484 struct drm_i915_private *dev_priv =
3485 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003486
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003487 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003488
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003489 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003490 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003491}
3492
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003493void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003494{
3495 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3496 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003497 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak3ab9c632013-05-03 12:57:41 +03003498 enum port port = intel_dig_port->port;
3499 uint32_t val;
3500
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003501 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003502 return;
3503
3504 val = I915_READ(DP_TP_CTL(port));
3505 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3506 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3507 I915_WRITE(DP_TP_CTL(port), val);
3508
3509 /*
3510 * On PORT_A we can have only eDP in SST mode. There the only reason
3511 * we need to set idle transmission mode is to work around a HW issue
3512 * where we enable the pipe while not in idle link-training mode.
3513 * In this case there is requirement to wait for a minimum number of
3514 * idle patterns to be sent.
3515 */
3516 if (port == PORT_A)
3517 return;
3518
Chris Wilsona7670172016-06-30 15:33:10 +01003519 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3520 DP_TP_STATUS_IDLE_DONE,
3521 DP_TP_STATUS_IDLE_DONE,
3522 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003523 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3524}
3525
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003526static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003527intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003528{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003529 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003530 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003531 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003532 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003533 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003534 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003535
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003536 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003537 return;
3538
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003539 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003540 return;
3541
Zhao Yakui28c97732009-10-09 11:39:41 +08003542 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003543
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003544 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003545 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003546 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003547 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003548 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003549 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003550 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3551 else
3552 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003553 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003554 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003555 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003556 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003557
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003558 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3559 I915_WRITE(intel_dp->output_reg, DP);
3560 POSTING_READ(intel_dp->output_reg);
3561
3562 /*
3563 * HW workaround for IBX, we need to move the port
3564 * to transcoder A after disabling it to allow the
3565 * matching HDMI port to be enabled on transcoder A.
3566 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003567 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003568 /*
3569 * We get CPU/PCH FIFO underruns on the other pipe when
3570 * doing the workaround. Sweep them under the rug.
3571 */
3572 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3573 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3574
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003575 /* always enable with pattern 1 (as per spec) */
3576 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3577 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3578 I915_WRITE(intel_dp->output_reg, DP);
3579 POSTING_READ(intel_dp->output_reg);
3580
3581 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003582 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003583 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003584
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003585 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003586 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3587 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003588 }
3589
Keith Packardf01eca22011-09-28 16:48:10 -07003590 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003591
3592 intel_dp->DP = DP;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003593
3594 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3595 pps_lock(intel_dp);
3596 intel_dp->active_pipe = INVALID_PIPE;
3597 pps_unlock(intel_dp);
3598 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003599}
3600
Imre Deak24e807e2016-10-24 19:33:28 +03003601bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003602intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003603{
Lyude9f085eb2016-04-13 10:58:33 -04003604 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3605 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003606 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003607
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003608 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003609
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003610 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3611}
3612
3613static bool
3614intel_edp_init_dpcd(struct intel_dp *intel_dp)
3615{
3616 struct drm_i915_private *dev_priv =
3617 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3618
3619 /* this function is meant to be called only once */
3620 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3621
3622 if (!intel_dp_read_dpcd(intel_dp))
3623 return false;
3624
Imre Deak12a47a422016-10-24 19:33:29 +03003625 intel_dp_read_desc(intel_dp);
3626
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003627 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3628 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3629 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3630
3631 /* Check if the panel supports PSR */
3632 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3633 intel_dp->psr_dpcd,
3634 sizeof(intel_dp->psr_dpcd));
3635 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3636 dev_priv->psr.sink_support = true;
3637 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3638 }
3639
3640 if (INTEL_GEN(dev_priv) >= 9 &&
3641 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3642 uint8_t frame_sync_cap;
3643
3644 dev_priv->psr.sink_support = true;
3645 drm_dp_dpcd_read(&intel_dp->aux,
3646 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3647 &frame_sync_cap, 1);
3648 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3649 /* PSR2 needs frame sync as well */
3650 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3651 DRM_DEBUG_KMS("PSR2 %s on sink",
3652 dev_priv->psr.psr2_support ? "supported" : "not supported");
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303653
3654 if (dev_priv->psr.psr2_support) {
3655 dev_priv->psr.y_cord_support =
3656 intel_dp_get_y_cord_status(intel_dp);
3657 dev_priv->psr.colorimetry_support =
3658 intel_dp_get_colorimetry_status(intel_dp);
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303659 dev_priv->psr.alpm =
3660 intel_dp_get_alpm_status(intel_dp);
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303661 }
3662
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003663 }
3664
3665 /* Read the eDP Display control capabilities registers */
3666 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
3667 drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003668 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3669 sizeof(intel_dp->edp_dpcd))
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003670 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3671 intel_dp->edp_dpcd);
3672
3673 /* Intermediate frequency support */
3674 if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */
3675 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3676 int i;
3677
3678 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3679 sink_rates, sizeof(sink_rates));
3680
3681 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3682 int val = le16_to_cpu(sink_rates[i]);
3683
3684 if (val == 0)
3685 break;
3686
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -08003687 /* Value read multiplied by 200kHz gives the per-lane
3688 * link rate in kHz. The source rates are, however,
3689 * stored in terms of LS_Clk kHz. The full conversion
3690 * back to symbols is
3691 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
3692 */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003693 intel_dp->sink_rates[i] = (val * 200) / 10;
3694 }
3695 intel_dp->num_sink_rates = i;
3696 }
3697
3698 return true;
3699}
3700
3701
3702static bool
3703intel_dp_get_dpcd(struct intel_dp *intel_dp)
3704{
3705 if (!intel_dp_read_dpcd(intel_dp))
3706 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003707
Lyude9f085eb2016-04-13 10:58:33 -04003708 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT,
3709 &intel_dp->sink_count, 1) < 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303710 return false;
3711
3712 /*
3713 * Sink count can change between short pulse hpd hence
3714 * a member variable in intel_dp will track any changes
3715 * between short pulse interrupts.
3716 */
3717 intel_dp->sink_count = DP_GET_SINK_COUNT(intel_dp->sink_count);
3718
3719 /*
3720 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3721 * a dongle is present but no display. Unless we require to know
3722 * if a dongle is present or not, we don't need to update
3723 * downstream port information. So, an early return here saves
3724 * time from performing other operations which are not required.
3725 */
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05303726 if (!is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303727 return false;
3728
Imre Deakc726ad02016-10-24 19:33:24 +03003729 if (!drm_dp_is_branch(intel_dp->dpcd))
Adam Jacksonedb39242012-09-18 10:58:49 -04003730 return true; /* native DP sink */
3731
3732 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3733 return true; /* no per-port downstream info */
3734
Lyude9f085eb2016-04-13 10:58:33 -04003735 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3736 intel_dp->downstream_ports,
3737 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003738 return false; /* downstream port status fetch failed */
3739
3740 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003741}
3742
Dave Airlie0e32b392014-05-02 14:02:48 +10003743static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003744intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003745{
3746 u8 buf[1];
3747
Nathan Schulte7cc96132016-03-15 10:14:05 -05003748 if (!i915.enable_dp_mst)
3749 return false;
3750
Dave Airlie0e32b392014-05-02 14:02:48 +10003751 if (!intel_dp->can_mst)
3752 return false;
3753
3754 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3755 return false;
3756
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003757 if (drm_dp_dpcd_read(&intel_dp->aux, DP_MSTM_CAP, buf, 1) != 1)
3758 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003759
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003760 return buf[0] & DP_MST_CAP;
3761}
3762
3763static void
3764intel_dp_configure_mst(struct intel_dp *intel_dp)
3765{
3766 if (!i915.enable_dp_mst)
3767 return;
3768
3769 if (!intel_dp->can_mst)
3770 return;
3771
3772 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3773
3774 if (intel_dp->is_mst)
3775 DRM_DEBUG_KMS("Sink is MST capable\n");
3776 else
3777 DRM_DEBUG_KMS("Sink is not MST capable\n");
3778
3779 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3780 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003781}
3782
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003783static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003784{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003785 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003786 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003787 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003788 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003789 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003790 int count = 0;
3791 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003792
3793 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003794 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003795 ret = -EIO;
3796 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003797 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003798
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003799 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003800 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003801 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003802 ret = -EIO;
3803 goto out;
3804 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003805
Rodrigo Vivic6297842015-11-05 10:50:20 -08003806 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003807 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivic6297842015-11-05 10:50:20 -08003808
3809 if (drm_dp_dpcd_readb(&intel_dp->aux,
3810 DP_TEST_SINK_MISC, &buf) < 0) {
3811 ret = -EIO;
3812 goto out;
3813 }
3814 count = buf & DP_TEST_COUNT_MASK;
3815 } while (--attempts && count);
3816
3817 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003818 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003819 ret = -ETIMEDOUT;
3820 }
3821
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003822 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003823 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003824 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003825}
3826
3827static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3828{
3829 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003830 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003831 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3832 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003833 int ret;
3834
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003835 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3836 return -EIO;
3837
3838 if (!(buf & DP_TEST_CRC_SUPPORTED))
3839 return -ENOTTY;
3840
3841 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3842 return -EIO;
3843
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003844 if (buf & DP_TEST_SINK_START) {
3845 ret = intel_dp_sink_crc_stop(intel_dp);
3846 if (ret)
3847 return ret;
3848 }
3849
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003850 hsw_disable_ips(intel_crtc);
3851
3852 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3853 buf | DP_TEST_SINK_START) < 0) {
3854 hsw_enable_ips(intel_crtc);
3855 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003856 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003857
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003858 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003859 return 0;
3860}
3861
3862int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3863{
3864 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003865 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003866 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3867 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003868 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003869 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003870
3871 ret = intel_dp_sink_crc_start(intel_dp);
3872 if (ret)
3873 return ret;
3874
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003875 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003876 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003877
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003878 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003879 DP_TEST_SINK_MISC, &buf) < 0) {
3880 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003881 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003882 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003883 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07003884
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003885 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003886
3887 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003888 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
3889 ret = -ETIMEDOUT;
3890 goto stop;
3891 }
3892
3893 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
3894 ret = -EIO;
3895 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003896 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003897
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003898stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003899 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003900 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003901}
3902
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003903static bool
3904intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3905{
Lyude9f085eb2016-04-13 10:58:33 -04003906 return drm_dp_dpcd_read(&intel_dp->aux,
Jani Nikula9d1a1032014-03-14 16:51:15 +02003907 DP_DEVICE_SERVICE_IRQ_VECTOR,
3908 sink_irq_vector, 1) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003909}
3910
Dave Airlie0e32b392014-05-02 14:02:48 +10003911static bool
3912intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3913{
3914 int ret;
3915
Lyude9f085eb2016-04-13 10:58:33 -04003916 ret = drm_dp_dpcd_read(&intel_dp->aux,
Dave Airlie0e32b392014-05-02 14:02:48 +10003917 DP_SINK_COUNT_ESI,
3918 sink_irq_vector, 14);
3919 if (ret != 14)
3920 return false;
3921
3922 return true;
3923}
3924
Todd Previtec5d5ab72015-04-15 08:38:38 -07003925static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003926{
Manasi Navareda15f7c2017-01-24 08:16:34 -08003927 int status = 0;
3928 int min_lane_count = 1;
3929 int common_rates[DP_MAX_SUPPORTED_RATES] = {};
3930 int link_rate_index, test_link_rate;
3931 uint8_t test_lane_count, test_link_bw;
3932 /* (DP CTS 1.2)
3933 * 4.3.1.11
3934 */
3935 /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */
3936 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT,
3937 &test_lane_count);
3938
3939 if (status <= 0) {
3940 DRM_DEBUG_KMS("Lane count read failed\n");
3941 return DP_TEST_NAK;
3942 }
3943 test_lane_count &= DP_MAX_LANE_COUNT_MASK;
3944 /* Validate the requested lane count */
3945 if (test_lane_count < min_lane_count ||
3946 test_lane_count > intel_dp->max_sink_lane_count)
3947 return DP_TEST_NAK;
3948
3949 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE,
3950 &test_link_bw);
3951 if (status <= 0) {
3952 DRM_DEBUG_KMS("Link Rate read failed\n");
3953 return DP_TEST_NAK;
3954 }
3955 /* Validate the requested link rate */
3956 test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw);
3957 link_rate_index = intel_dp_link_rate_index(intel_dp,
3958 common_rates,
3959 test_link_rate);
3960 if (link_rate_index < 0)
3961 return DP_TEST_NAK;
3962
3963 intel_dp->compliance.test_lane_count = test_lane_count;
3964 intel_dp->compliance.test_link_rate = test_link_rate;
3965
3966 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07003967}
3968
3969static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
3970{
Manasi Navare611032b2017-01-24 08:21:49 -08003971 uint8_t test_pattern;
3972 uint16_t test_misc;
3973 __be16 h_width, v_height;
3974 int status = 0;
3975
3976 /* Read the TEST_PATTERN (DP CTS 3.1.5) */
3977 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_PATTERN,
3978 &test_pattern, 1);
3979 if (status <= 0) {
3980 DRM_DEBUG_KMS("Test pattern read failed\n");
3981 return DP_TEST_NAK;
3982 }
3983 if (test_pattern != DP_COLOR_RAMP)
3984 return DP_TEST_NAK;
3985
3986 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI,
3987 &h_width, 2);
3988 if (status <= 0) {
3989 DRM_DEBUG_KMS("H Width read failed\n");
3990 return DP_TEST_NAK;
3991 }
3992
3993 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI,
3994 &v_height, 2);
3995 if (status <= 0) {
3996 DRM_DEBUG_KMS("V Height read failed\n");
3997 return DP_TEST_NAK;
3998 }
3999
4000 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_MISC0,
4001 &test_misc, 1);
4002 if (status <= 0) {
4003 DRM_DEBUG_KMS("TEST MISC read failed\n");
4004 return DP_TEST_NAK;
4005 }
4006 if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB)
4007 return DP_TEST_NAK;
4008 if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA)
4009 return DP_TEST_NAK;
4010 switch (test_misc & DP_TEST_BIT_DEPTH_MASK) {
4011 case DP_TEST_BIT_DEPTH_6:
4012 intel_dp->compliance.test_data.bpc = 6;
4013 break;
4014 case DP_TEST_BIT_DEPTH_8:
4015 intel_dp->compliance.test_data.bpc = 8;
4016 break;
4017 default:
4018 return DP_TEST_NAK;
4019 }
4020
4021 intel_dp->compliance.test_data.video_pattern = test_pattern;
4022 intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width);
4023 intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height);
4024 /* Set test active flag here so userspace doesn't interrupt things */
4025 intel_dp->compliance.test_active = 1;
4026
4027 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004028}
4029
4030static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
4031{
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004032 uint8_t test_result = DP_TEST_ACK;
Todd Previte559be302015-05-04 07:48:20 -07004033 struct intel_connector *intel_connector = intel_dp->attached_connector;
4034 struct drm_connector *connector = &intel_connector->base;
4035
4036 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02004037 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07004038 intel_dp->aux.i2c_defer_count > 6) {
4039 /* Check EDID read for NACKs, DEFERs and corruption
4040 * (DP CTS 1.2 Core r1.1)
4041 * 4.2.2.4 : Failed EDID read, I2C_NAK
4042 * 4.2.2.5 : Failed EDID read, I2C_DEFER
4043 * 4.2.2.6 : EDID corruption detected
4044 * Use failsafe mode for all cases
4045 */
4046 if (intel_dp->aux.i2c_nack_count > 0 ||
4047 intel_dp->aux.i2c_defer_count > 0)
4048 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
4049 intel_dp->aux.i2c_nack_count,
4050 intel_dp->aux.i2c_defer_count);
Manasi Navarec1617ab2016-12-09 16:22:50 -08004051 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
Todd Previte559be302015-05-04 07:48:20 -07004052 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05304053 struct edid *block = intel_connector->detect_edid;
4054
4055 /* We have to write the checksum
4056 * of the last block read
4057 */
4058 block += intel_connector->detect_edid->extensions;
4059
Todd Previte559be302015-05-04 07:48:20 -07004060 if (!drm_dp_dpcd_write(&intel_dp->aux,
4061 DP_TEST_EDID_CHECKSUM,
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05304062 &block->checksum,
Dan Carpenter5a1cc652015-05-12 21:07:37 +03004063 1))
Todd Previte559be302015-05-04 07:48:20 -07004064 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
4065
4066 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004067 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED;
Todd Previte559be302015-05-04 07:48:20 -07004068 }
4069
4070 /* Set test active flag here so userspace doesn't interrupt things */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004071 intel_dp->compliance.test_active = 1;
Todd Previte559be302015-05-04 07:48:20 -07004072
Todd Previtec5d5ab72015-04-15 08:38:38 -07004073 return test_result;
4074}
4075
4076static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
4077{
4078 uint8_t test_result = DP_TEST_NAK;
4079 return test_result;
4080}
4081
4082static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
4083{
4084 uint8_t response = DP_TEST_NAK;
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004085 uint8_t request = 0;
4086 int status;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004087
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004088 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004089 if (status <= 0) {
4090 DRM_DEBUG_KMS("Could not read test request from sink\n");
4091 goto update_status;
4092 }
4093
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004094 switch (request) {
Todd Previtec5d5ab72015-04-15 08:38:38 -07004095 case DP_TEST_LINK_TRAINING:
4096 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004097 response = intel_dp_autotest_link_training(intel_dp);
4098 break;
4099 case DP_TEST_LINK_VIDEO_PATTERN:
4100 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004101 response = intel_dp_autotest_video_pattern(intel_dp);
4102 break;
4103 case DP_TEST_LINK_EDID_READ:
4104 DRM_DEBUG_KMS("EDID test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004105 response = intel_dp_autotest_edid(intel_dp);
4106 break;
4107 case DP_TEST_LINK_PHY_TEST_PATTERN:
4108 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004109 response = intel_dp_autotest_phy_pattern(intel_dp);
4110 break;
4111 default:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004112 DRM_DEBUG_KMS("Invalid test request '%02x'\n", request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004113 break;
4114 }
4115
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004116 if (response & DP_TEST_ACK)
4117 intel_dp->compliance.test_type = request;
4118
Todd Previtec5d5ab72015-04-15 08:38:38 -07004119update_status:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004120 status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004121 if (status <= 0)
4122 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004123}
4124
Dave Airlie0e32b392014-05-02 14:02:48 +10004125static int
4126intel_dp_check_mst_status(struct intel_dp *intel_dp)
4127{
4128 bool bret;
4129
4130 if (intel_dp->is_mst) {
4131 u8 esi[16] = { 0 };
4132 int ret = 0;
4133 int retry;
4134 bool handled;
4135 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4136go_again:
4137 if (bret == true) {
4138
4139 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03004140 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03004141 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10004142 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4143 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004144 intel_dp_stop_link_train(intel_dp);
4145 }
4146
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004147 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004148 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4149
4150 if (handled) {
4151 for (retry = 0; retry < 3; retry++) {
4152 int wret;
4153 wret = drm_dp_dpcd_write(&intel_dp->aux,
4154 DP_SINK_COUNT_ESI+1,
4155 &esi[1], 3);
4156 if (wret == 3) {
4157 break;
4158 }
4159 }
4160
4161 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4162 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004163 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004164 goto go_again;
4165 }
4166 } else
4167 ret = 0;
4168
4169 return ret;
4170 } else {
4171 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4172 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4173 intel_dp->is_mst = false;
4174 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4175 /* send a hotplug event */
4176 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4177 }
4178 }
4179 return -EINVAL;
4180}
4181
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304182static void
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004183intel_dp_retrain_link(struct intel_dp *intel_dp)
4184{
4185 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4186 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4187 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
4188
4189 /* Suppress underruns caused by re-training */
4190 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4191 if (crtc->config->has_pch_encoder)
4192 intel_set_pch_fifo_underrun_reporting(dev_priv,
4193 intel_crtc_pch_transcoder(crtc), false);
4194
4195 intel_dp_start_link_train(intel_dp);
4196 intel_dp_stop_link_train(intel_dp);
4197
4198 /* Keep underrun reporting disabled until things are stable */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02004199 intel_wait_for_vblank(dev_priv, crtc->pipe);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004200
4201 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4202 if (crtc->config->has_pch_encoder)
4203 intel_set_pch_fifo_underrun_reporting(dev_priv,
4204 intel_crtc_pch_transcoder(crtc), true);
4205}
4206
4207static void
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304208intel_dp_check_link_status(struct intel_dp *intel_dp)
4209{
4210 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4211 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4212 u8 link_status[DP_LINK_STATUS_SIZE];
4213
4214 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
4215
4216 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4217 DRM_ERROR("Failed to get link status\n");
4218 return;
4219 }
4220
4221 if (!intel_encoder->base.crtc)
4222 return;
4223
4224 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4225 return;
4226
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004227 /* FIXME: we need to synchronize this sort of stuff with hardware
Daniel Vetter2dd85ae2016-12-13 20:54:14 +01004228 * readout. Currently fast link training doesn't work on boot-up. */
4229 if (!intel_dp->lane_count)
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004230 return;
4231
Manasi Navareda15f7c2017-01-24 08:16:34 -08004232 /* Retrain if Channel EQ or CR not ok */
4233 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304234 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4235 intel_encoder->base.name);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004236
4237 intel_dp_retrain_link(intel_dp);
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304238 }
4239}
4240
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004241/*
4242 * According to DP spec
4243 * 5.1.2:
4244 * 1. Read DPCD
4245 * 2. Configure link according to Receiver Capabilities
4246 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4247 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304248 *
4249 * intel_dp_short_pulse - handles short pulse interrupts
4250 * when full detection is not required.
4251 * Returns %true if short pulse is handled and full detection
4252 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004253 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304254static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304255intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004256{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004257 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004258 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004259 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304260 u8 old_sink_count = intel_dp->sink_count;
4261 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004262
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304263 /*
4264 * Clearing compliance test variables to allow capturing
4265 * of values for next automated test request.
4266 */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004267 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304268
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304269 /*
4270 * Now read the DPCD to see if it's actually running
4271 * If the current value of sink count doesn't match with
4272 * the value that was stored earlier or dpcd read failed
4273 * we need to do full detection
4274 */
4275 ret = intel_dp_get_dpcd(intel_dp);
4276
4277 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4278 /* No need to proceed if we are going to do full detect */
4279 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004280 }
4281
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004282 /* Try to read the source of the interrupt */
4283 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004284 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4285 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004286 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004287 drm_dp_dpcd_writeb(&intel_dp->aux,
4288 DP_DEVICE_SERVICE_IRQ_VECTOR,
4289 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004290
4291 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Manasi Navareda15f7c2017-01-24 08:16:34 -08004292 intel_dp_handle_test_request(intel_dp);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004293 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4294 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4295 }
4296
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304297 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4298 intel_dp_check_link_status(intel_dp);
4299 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004300 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
4301 DRM_DEBUG_KMS("Link Training Compliance Test requested\n");
4302 /* Send a Hotplug Uevent to userspace to start modeset */
4303 drm_kms_helper_hotplug_event(intel_encoder->base.dev);
4304 }
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304305
4306 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004307}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004308
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004309/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004310static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004311intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004312{
Imre Deake393d0d2017-02-22 17:10:52 +02004313 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004314 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004315 uint8_t type;
4316
Imre Deake393d0d2017-02-22 17:10:52 +02004317 if (lspcon->active)
4318 lspcon_resume(lspcon);
4319
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004320 if (!intel_dp_get_dpcd(intel_dp))
4321 return connector_status_disconnected;
4322
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304323 if (is_edp(intel_dp))
4324 return connector_status_connected;
4325
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004326 /* if there's no downstream port, we're done */
Imre Deakc726ad02016-10-24 19:33:24 +03004327 if (!drm_dp_is_branch(dpcd))
Keith Packard26d61aa2011-07-25 20:01:09 -07004328 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004329
4330 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004331 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4332 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004333
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304334 return intel_dp->sink_count ?
4335 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004336 }
4337
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004338 if (intel_dp_can_mst(intel_dp))
4339 return connector_status_connected;
4340
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004341 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004342 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004343 return connector_status_connected;
4344
4345 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004346 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4347 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4348 if (type == DP_DS_PORT_TYPE_VGA ||
4349 type == DP_DS_PORT_TYPE_NON_EDID)
4350 return connector_status_unknown;
4351 } else {
4352 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4353 DP_DWN_STRM_PORT_TYPE_MASK;
4354 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4355 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4356 return connector_status_unknown;
4357 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004358
4359 /* Anything else is out of spec, warn and ignore */
4360 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004361 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004362}
4363
4364static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004365edp_detect(struct intel_dp *intel_dp)
4366{
4367 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Mika Kahola1650be72016-12-13 10:02:47 +02004368 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsond410b562014-09-02 20:03:59 +01004369 enum drm_connector_status status;
4370
Mika Kahola1650be72016-12-13 10:02:47 +02004371 status = intel_panel_detect(dev_priv);
Chris Wilsond410b562014-09-02 20:03:59 +01004372 if (status == connector_status_unknown)
4373 status = connector_status_connected;
4374
4375 return status;
4376}
4377
Jani Nikulab93433c2015-08-20 10:47:36 +03004378static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4379 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004380{
Jani Nikulab93433c2015-08-20 10:47:36 +03004381 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004382
Jani Nikula0df53b72015-08-20 10:47:40 +03004383 switch (port->port) {
4384 case PORT_A:
4385 return true;
4386 case PORT_B:
4387 bit = SDE_PORTB_HOTPLUG;
4388 break;
4389 case PORT_C:
4390 bit = SDE_PORTC_HOTPLUG;
4391 break;
4392 case PORT_D:
4393 bit = SDE_PORTD_HOTPLUG;
4394 break;
4395 default:
4396 MISSING_CASE(port->port);
4397 return false;
4398 }
4399
4400 return I915_READ(SDEISR) & bit;
4401}
4402
4403static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4404 struct intel_digital_port *port)
4405{
4406 u32 bit;
4407
4408 switch (port->port) {
4409 case PORT_A:
4410 return true;
4411 case PORT_B:
4412 bit = SDE_PORTB_HOTPLUG_CPT;
4413 break;
4414 case PORT_C:
4415 bit = SDE_PORTC_HOTPLUG_CPT;
4416 break;
4417 case PORT_D:
4418 bit = SDE_PORTD_HOTPLUG_CPT;
4419 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004420 case PORT_E:
4421 bit = SDE_PORTE_HOTPLUG_SPT;
4422 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004423 default:
4424 MISSING_CASE(port->port);
4425 return false;
Jani Nikulab93433c2015-08-20 10:47:36 +03004426 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004427
Jani Nikulab93433c2015-08-20 10:47:36 +03004428 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004429}
4430
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004431static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004432 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004433{
Jani Nikula9642c812015-08-20 10:47:41 +03004434 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004435
Jani Nikula9642c812015-08-20 10:47:41 +03004436 switch (port->port) {
4437 case PORT_B:
4438 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4439 break;
4440 case PORT_C:
4441 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4442 break;
4443 case PORT_D:
4444 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4445 break;
4446 default:
4447 MISSING_CASE(port->port);
4448 return false;
4449 }
4450
4451 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4452}
4453
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004454static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4455 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004456{
4457 u32 bit;
4458
4459 switch (port->port) {
4460 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004461 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004462 break;
4463 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004464 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004465 break;
4466 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004467 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004468 break;
4469 default:
4470 MISSING_CASE(port->port);
4471 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004472 }
4473
Jani Nikula1d245982015-08-20 10:47:37 +03004474 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004475}
4476
Jani Nikulae464bfd2015-08-20 10:47:42 +03004477static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304478 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004479{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304480 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4481 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004482 u32 bit;
4483
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304484 intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port);
4485 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004486 case PORT_A:
4487 bit = BXT_DE_PORT_HP_DDIA;
4488 break;
4489 case PORT_B:
4490 bit = BXT_DE_PORT_HP_DDIB;
4491 break;
4492 case PORT_C:
4493 bit = BXT_DE_PORT_HP_DDIC;
4494 break;
4495 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304496 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004497 return false;
4498 }
4499
4500 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4501}
4502
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004503/*
4504 * intel_digital_port_connected - is the specified port connected?
4505 * @dev_priv: i915 private structure
4506 * @port: the port to test
4507 *
4508 * Return %true if @port is connected, %false otherwise.
4509 */
Imre Deak390b4e02017-01-27 11:39:19 +02004510bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
4511 struct intel_digital_port *port)
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004512{
Jani Nikula0df53b72015-08-20 10:47:40 +03004513 if (HAS_PCH_IBX(dev_priv))
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004514 return ibx_digital_port_connected(dev_priv, port);
Ville Syrjälä22824fa2016-02-11 16:44:28 +02004515 else if (HAS_PCH_SPLIT(dev_priv))
Jani Nikula0df53b72015-08-20 10:47:40 +03004516 return cpt_digital_port_connected(dev_priv, port);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004517 else if (IS_GEN9_LP(dev_priv))
Jani Nikulae464bfd2015-08-20 10:47:42 +03004518 return bxt_digital_port_connected(dev_priv, port);
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004519 else if (IS_GM45(dev_priv))
4520 return gm45_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004521 else
4522 return g4x_digital_port_connected(dev_priv, port);
4523}
4524
Keith Packard8c241fe2011-09-28 16:38:44 -07004525static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004526intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004527{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004528 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004529
Jani Nikula9cd300e2012-10-19 14:51:52 +03004530 /* use cached edid if we have one */
4531 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004532 /* invalid edid */
4533 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004534 return NULL;
4535
Jani Nikula55e9ede2013-10-01 10:38:54 +03004536 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004537 } else
4538 return drm_get_edid(&intel_connector->base,
4539 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004540}
4541
Chris Wilsonbeb60602014-09-02 20:04:00 +01004542static void
4543intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004544{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004545 struct intel_connector *intel_connector = intel_dp->attached_connector;
4546 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004547
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304548 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004549 edid = intel_dp_get_edid(intel_dp);
4550 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004551
Chris Wilsonbeb60602014-09-02 20:04:00 +01004552 if (intel_dp->force_audio != HDMI_AUDIO_AUTO)
4553 intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON;
4554 else
4555 intel_dp->has_audio = drm_detect_monitor_audio(edid);
4556}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004557
Chris Wilsonbeb60602014-09-02 20:04:00 +01004558static void
4559intel_dp_unset_edid(struct intel_dp *intel_dp)
4560{
4561 struct intel_connector *intel_connector = intel_dp->attached_connector;
4562
4563 kfree(intel_connector->detect_edid);
4564 intel_connector->detect_edid = NULL;
4565
4566 intel_dp->has_audio = false;
4567}
4568
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004569static int
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304570intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004571{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304572 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004573 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004574 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4575 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004576 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004577 enum drm_connector_status status;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004578 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004579
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004580 WARN_ON(!drm_modeset_is_locked(&connector->dev->mode_config.connection_mutex));
4581
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004582 intel_display_power_get(to_i915(dev), intel_dp->aux_power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004583
Chris Wilsond410b562014-09-02 20:03:59 +01004584 /* Can't disconnect eDP, but you can close the lid... */
4585 if (is_edp(intel_dp))
4586 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004587 else if (intel_digital_port_connected(to_i915(dev),
4588 dp_to_dig_port(intel_dp)))
4589 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004590 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004591 status = connector_status_disconnected;
4592
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004593 if (status == connector_status_disconnected) {
Manasi Navarec1617ab2016-12-09 16:22:50 -08004594 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304595
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004596 if (intel_dp->is_mst) {
4597 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4598 intel_dp->is_mst,
4599 intel_dp->mst_mgr.mst_state);
4600 intel_dp->is_mst = false;
4601 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4602 intel_dp->is_mst);
4603 }
4604
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004605 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304606 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004607
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304608 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004609 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304610
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004611 DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
4612 yesno(intel_dp_source_supports_hbr2(intel_dp)),
4613 yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
4614
Manasi Navared7e8ef02017-02-07 16:54:11 -08004615 if (intel_dp->reset_link_params) {
4616 /* Set the max lane count for sink */
4617 intel_dp->max_sink_lane_count = drm_dp_max_lane_count(intel_dp->dpcd);
Manasi Navaref4829842016-12-05 16:27:36 -08004618
Manasi Navared7e8ef02017-02-07 16:54:11 -08004619 /* Set the max link BW for sink */
4620 intel_dp->max_sink_link_bw = intel_dp_max_link_bw(intel_dp);
4621
4622 intel_dp->reset_link_params = false;
4623 }
Manasi Navaref4829842016-12-05 16:27:36 -08004624
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004625 intel_dp_print_rates(intel_dp);
4626
Imre Deak7b3fc172016-10-25 16:12:39 +03004627 intel_dp_read_desc(intel_dp);
Mika Kahola0e390a32016-09-09 14:10:53 +03004628
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004629 intel_dp_configure_mst(intel_dp);
4630
4631 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304632 /*
4633 * If we are in MST mode then this connector
4634 * won't appear connected or have anything
4635 * with EDID on it
4636 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004637 status = connector_status_disconnected;
4638 goto out;
Ville Syrjälädea65592017-04-12 22:30:17 +03004639 } else {
4640 /*
4641 * If display is now connected check links status,
4642 * there has been known issues of link loss triggerring
4643 * long pulse.
4644 *
4645 * Some sinks (eg. ASUS PB287Q) seem to perform some
4646 * weird HPD ping pong during modesets. So we can apparently
4647 * end up with HPD going low during a modeset, and then
4648 * going back up soon after. And once that happens we must
4649 * retrain the link to get a picture. That's in case no
4650 * userspace component reacted to intermittent HPD dip.
4651 */
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304652 intel_dp_check_link_status(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004653 }
4654
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304655 /*
4656 * Clearing NACK and defer counts to get their exact values
4657 * while reading EDID which are required by Compliance tests
4658 * 4.2.2.4 and 4.2.2.5
4659 */
4660 intel_dp->aux.i2c_nack_count = 0;
4661 intel_dp->aux.i2c_defer_count = 0;
4662
Chris Wilsonbeb60602014-09-02 20:04:00 +01004663 intel_dp_set_edid(intel_dp);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004664 if (is_edp(intel_dp) || intel_connector->detect_edid)
4665 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304666 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004667
Todd Previte09b1eb12015-04-20 15:27:34 -07004668 /* Try to read the source of the interrupt */
4669 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004670 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4671 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004672 /* Clear interrupt source */
4673 drm_dp_dpcd_writeb(&intel_dp->aux,
4674 DP_DEVICE_SERVICE_IRQ_VECTOR,
4675 sink_irq_vector);
4676
4677 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4678 intel_dp_handle_test_request(intel_dp);
4679 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4680 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4681 }
4682
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004683out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004684 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304685 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304686
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004687 intel_display_power_put(to_i915(dev), intel_dp->aux_power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004688 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304689}
4690
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004691static int
4692intel_dp_detect(struct drm_connector *connector,
4693 struct drm_modeset_acquire_ctx *ctx,
4694 bool force)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304695{
4696 struct intel_dp *intel_dp = intel_attached_dp(connector);
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02004697 int status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304698
4699 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4700 connector->base.id, connector->name);
4701
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304702 /* If full detect is not performed yet, do a full detect */
4703 if (!intel_dp->detect_done)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004704 status = intel_dp_long_pulse(intel_dp->attached_connector);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304705
4706 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304707
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004708 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004709}
4710
Chris Wilsonbeb60602014-09-02 20:04:00 +01004711static void
4712intel_dp_force(struct drm_connector *connector)
4713{
4714 struct intel_dp *intel_dp = intel_attached_dp(connector);
4715 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004716 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004717
4718 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4719 connector->base.id, connector->name);
4720 intel_dp_unset_edid(intel_dp);
4721
4722 if (connector->status != connector_status_connected)
4723 return;
4724
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004725 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004726
4727 intel_dp_set_edid(intel_dp);
4728
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004729 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004730
4731 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004732 intel_encoder->type = INTEL_OUTPUT_DP;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004733}
4734
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004735static int intel_dp_get_modes(struct drm_connector *connector)
4736{
Jani Nikuladd06f902012-10-19 14:51:50 +03004737 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004738 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004739
Chris Wilsonbeb60602014-09-02 20:04:00 +01004740 edid = intel_connector->detect_edid;
4741 if (edid) {
4742 int ret = intel_connector_update_modes(connector, edid);
4743 if (ret)
4744 return ret;
4745 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004746
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004747 /* if eDP has no EDID, fall back to fixed mode */
Chris Wilsonbeb60602014-09-02 20:04:00 +01004748 if (is_edp(intel_attached_dp(connector)) &&
4749 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004750 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004751
4752 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004753 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004754 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004755 drm_mode_probed_add(connector, mode);
4756 return 1;
4757 }
4758 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004759
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004760 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004761}
4762
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004763static bool
4764intel_dp_detect_audio(struct drm_connector *connector)
4765{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004766 bool has_audio = false;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004767 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004768
Chris Wilsonbeb60602014-09-02 20:04:00 +01004769 edid = to_intel_connector(connector)->detect_edid;
4770 if (edid)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004771 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02004772
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004773 return has_audio;
4774}
4775
Chris Wilsonf6849602010-09-19 09:29:33 +01004776static int
4777intel_dp_set_property(struct drm_connector *connector,
4778 struct drm_property *property,
4779 uint64_t val)
4780{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004781 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Yuly Novikov53b41832012-10-26 12:04:00 +03004782 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004783 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
4784 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01004785 int ret;
4786
Rob Clark662595d2012-10-11 20:36:04 -05004787 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01004788 if (ret)
4789 return ret;
4790
Chris Wilson3f43c482011-05-12 22:17:24 +01004791 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004792 int i = val;
4793 bool has_audio;
4794
4795 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004796 return 0;
4797
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004798 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01004799
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004800 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004801 has_audio = intel_dp_detect_audio(connector);
4802 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004803 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004804
4805 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004806 return 0;
4807
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004808 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01004809 goto done;
4810 }
4811
Chris Wilsone953fd72011-02-21 22:23:52 +00004812 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02004813 bool old_auto = intel_dp->color_range_auto;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004814 bool old_range = intel_dp->limited_color_range;
Daniel Vetterae4edb82013-04-22 17:07:23 +02004815
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004816 switch (val) {
4817 case INTEL_BROADCAST_RGB_AUTO:
4818 intel_dp->color_range_auto = true;
4819 break;
4820 case INTEL_BROADCAST_RGB_FULL:
4821 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004822 intel_dp->limited_color_range = false;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004823 break;
4824 case INTEL_BROADCAST_RGB_LIMITED:
4825 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004826 intel_dp->limited_color_range = true;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004827 break;
4828 default:
4829 return -EINVAL;
4830 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02004831
4832 if (old_auto == intel_dp->color_range_auto &&
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004833 old_range == intel_dp->limited_color_range)
Daniel Vetterae4edb82013-04-22 17:07:23 +02004834 return 0;
4835
Chris Wilsone953fd72011-02-21 22:23:52 +00004836 goto done;
4837 }
4838
Yuly Novikov53b41832012-10-26 12:04:00 +03004839 if (is_edp(intel_dp) &&
4840 property == connector->dev->mode_config.scaling_mode_property) {
4841 if (val == DRM_MODE_SCALE_NONE) {
4842 DRM_DEBUG_KMS("no scaling not supported\n");
4843 return -EINVAL;
4844 }
Ville Syrjälä234126c2016-04-12 22:14:38 +03004845 if (HAS_GMCH_DISPLAY(dev_priv) &&
4846 val == DRM_MODE_SCALE_CENTER) {
4847 DRM_DEBUG_KMS("centering not supported\n");
4848 return -EINVAL;
4849 }
Yuly Novikov53b41832012-10-26 12:04:00 +03004850
4851 if (intel_connector->panel.fitting_mode == val) {
4852 /* the eDP scaling property is not changed */
4853 return 0;
4854 }
4855 intel_connector->panel.fitting_mode = val;
4856
4857 goto done;
4858 }
4859
Chris Wilsonf6849602010-09-19 09:29:33 +01004860 return -EINVAL;
4861
4862done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00004863 if (intel_encoder->base.crtc)
4864 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01004865
4866 return 0;
4867}
4868
Chris Wilson7a418e32016-06-24 14:00:14 +01004869static int
4870intel_dp_connector_register(struct drm_connector *connector)
4871{
4872 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004873 int ret;
4874
4875 ret = intel_connector_register(connector);
4876 if (ret)
4877 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004878
4879 i915_debugfs_connector_add(connector);
4880
4881 DRM_DEBUG_KMS("registering %s bus for %s\n",
4882 intel_dp->aux.name, connector->kdev->kobj.name);
4883
4884 intel_dp->aux.dev = connector->kdev;
4885 return drm_dp_aux_register(&intel_dp->aux);
4886}
4887
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004888static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004889intel_dp_connector_unregister(struct drm_connector *connector)
4890{
4891 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4892 intel_connector_unregister(connector);
4893}
4894
4895static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004896intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004897{
Jani Nikula1d508702012-10-19 14:51:49 +03004898 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004899
Chris Wilson10e972d2014-09-04 21:43:45 +01004900 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004901
Jani Nikula9cd300e2012-10-19 14:51:52 +03004902 if (!IS_ERR_OR_NULL(intel_connector->edid))
4903 kfree(intel_connector->edid);
4904
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004905 /* Can't call is_edp() since the encoder may have been destroyed
4906 * already. */
4907 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004908 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004909
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004910 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004911 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004912}
4913
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004914void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004915{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004916 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4917 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004918
Dave Airlie0e32b392014-05-02 14:02:48 +10004919 intel_dp_mst_encoder_cleanup(intel_dig_port);
Keith Packardbd943152011-09-18 23:09:52 -07004920 if (is_edp(intel_dp)) {
4921 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004922 /*
4923 * vdd might still be enabled do to the delayed vdd off.
4924 * Make sure vdd is actually turned off here.
4925 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004926 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004927 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004928 pps_unlock(intel_dp);
4929
Clint Taylor01527b32014-07-07 13:01:46 -07004930 if (intel_dp->edp_notifier.notifier_call) {
4931 unregister_reboot_notifier(&intel_dp->edp_notifier);
4932 intel_dp->edp_notifier.notifier_call = NULL;
4933 }
Keith Packardbd943152011-09-18 23:09:52 -07004934 }
Chris Wilson99681882016-06-20 09:29:17 +01004935
4936 intel_dp_aux_fini(intel_dp);
4937
Imre Deakc8bd0e42014-12-12 17:57:38 +02004938 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004939 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004940}
4941
Imre Deakbf93ba62016-04-18 10:04:21 +03004942void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004943{
4944 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4945
4946 if (!is_edp(intel_dp))
4947 return;
4948
Ville Syrjälä951468f2014-09-04 14:55:31 +03004949 /*
4950 * vdd might still be enabled do to the delayed vdd off.
4951 * Make sure vdd is actually turned off here.
4952 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004953 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004954 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004955 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004956 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004957}
4958
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004959static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4960{
4961 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4962 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004963 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004964
4965 lockdep_assert_held(&dev_priv->pps_mutex);
4966
4967 if (!edp_have_panel_vdd(intel_dp))
4968 return;
4969
4970 /*
4971 * The VDD bit needs a power domain reference, so if the bit is
4972 * already enabled when we boot or resume, grab this reference and
4973 * schedule a vdd off, so we don't hold on to the reference
4974 * indefinitely.
4975 */
4976 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02004977 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004978
4979 edp_panel_vdd_schedule_off(intel_dp);
4980}
4981
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02004982static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
4983{
4984 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
4985
4986 if ((intel_dp->DP & DP_PORT_EN) == 0)
4987 return INVALID_PIPE;
4988
4989 if (IS_CHERRYVIEW(dev_priv))
4990 return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
4991 else
4992 return PORT_TO_PIPE(intel_dp->DP);
4993}
4994
Imre Deakbf93ba62016-04-18 10:04:21 +03004995void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03004996{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03004997 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Imre Deakdd75f6d2016-11-21 21:15:05 +02004998 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
4999 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005000
5001 if (!HAS_DDI(dev_priv))
5002 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005003
Imre Deakdd75f6d2016-11-21 21:15:05 +02005004 if (lspcon->active)
Shashank Sharma910530c2016-10-14 19:56:52 +05305005 lspcon_resume(lspcon);
5006
Manasi Navared7e8ef02017-02-07 16:54:11 -08005007 intel_dp->reset_link_params = true;
5008
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005009 pps_lock(intel_dp);
5010
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005011 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5012 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5013
5014 if (is_edp(intel_dp)) {
5015 /* Reinit the power sequencer, in case BIOS did something with it. */
5016 intel_dp_pps_init(encoder->dev, intel_dp);
5017 intel_edp_panel_vdd_sanitize(intel_dp);
5018 }
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005019
5020 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03005021}
5022
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005023static const struct drm_connector_funcs intel_dp_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02005024 .dpms = drm_atomic_helper_connector_dpms,
Chris Wilsonbeb60602014-09-02 20:04:00 +01005025 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005026 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01005027 .set_property = intel_dp_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -08005028 .atomic_get_property = intel_connector_atomic_get_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01005029 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01005030 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03005031 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08005032 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02005033 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005034};
5035
5036static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +02005037 .detect_ctx = intel_dp_detect,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005038 .get_modes = intel_dp_get_modes,
5039 .mode_valid = intel_dp_mode_valid,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005040};
5041
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005042static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03005043 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02005044 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005045};
5046
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005047enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10005048intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
5049{
5050 struct intel_dp *intel_dp = &intel_dig_port->dp;
Dave Airlie0e32b392014-05-02 14:02:48 +10005051 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005052 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005053 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03005054
Takashi Iwai25400582015-11-19 12:09:56 +01005055 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
5056 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Ville Syrjäläcca05022016-06-22 21:57:06 +03005057 intel_dig_port->base.type = INTEL_OUTPUT_DP;
Dave Airlie13cf5502014-06-18 11:29:35 +10005058
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005059 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
5060 /*
5061 * vdd off can generate a long pulse on eDP which
5062 * would require vdd on to handle it, and thus we
5063 * would end up in an endless cycle of
5064 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
5065 */
5066 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
5067 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d522015-02-10 14:11:46 +02005068 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005069 }
5070
Ville Syrjälä26fbb772014-08-11 18:37:37 +03005071 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
5072 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10005073 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10005074
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005075 if (long_hpd) {
Manasi Navared7e8ef02017-02-07 16:54:11 -08005076 intel_dp->reset_link_params = true;
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005077 intel_dp->detect_done = false;
5078 return IRQ_NONE;
5079 }
5080
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005081 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005082
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005083 if (intel_dp->is_mst) {
5084 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
5085 /*
5086 * If we were in MST mode, and device is not
5087 * there, get out of MST mode
5088 */
5089 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
5090 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
5091 intel_dp->is_mst = false;
5092 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
5093 intel_dp->is_mst);
5094 intel_dp->detect_done = false;
5095 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10005096 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005097 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005098
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005099 if (!intel_dp->is_mst) {
5100 if (!intel_dp_short_pulse(intel_dp)) {
5101 intel_dp->detect_done = false;
5102 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05305103 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005104 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005105
5106 ret = IRQ_HANDLED;
5107
Imre Deak1c767b32014-08-18 14:42:42 +03005108put_power:
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005109 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
Imre Deak1c767b32014-08-18 14:42:42 +03005110
5111 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10005112}
5113
Rodrigo Vivi477ec322015-08-06 15:51:39 +08005114/* check the VBT to see whether the eDP is on another port */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005115bool intel_dp_is_edp(struct drm_i915_private *dev_priv, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08005116{
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005117 /*
5118 * eDP not supported on g4x. so bail out early just
5119 * for a bit extra safety in case the VBT is bonkers.
5120 */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005121 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005122 return false;
5123
Imre Deaka98d9c12016-12-21 12:17:24 +02005124 if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005125 return true;
5126
Jani Nikula951d9ef2016-03-16 12:43:31 +02005127 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08005128}
5129
Dave Airlie0e32b392014-05-02 14:02:48 +10005130void
Chris Wilsonf6849602010-09-19 09:29:33 +01005131intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
5132{
Yuly Novikov53b41832012-10-26 12:04:00 +03005133 struct intel_connector *intel_connector = to_intel_connector(connector);
5134
Chris Wilson3f43c482011-05-12 22:17:24 +01005135 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00005136 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02005137 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03005138
5139 if (is_edp(intel_dp)) {
5140 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05005141 drm_object_attach_property(
5142 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03005143 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03005144 DRM_MODE_SCALE_ASPECT);
5145 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03005146 }
Chris Wilsonf6849602010-09-19 09:29:33 +01005147}
5148
Imre Deakdada1a92014-01-29 13:25:41 +02005149static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
5150{
Abhay Kumard28d4732016-01-22 17:39:04 -08005151 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02005152 intel_dp->last_power_on = jiffies;
5153 intel_dp->last_backlight_off = jiffies;
5154}
5155
Daniel Vetter67a54562012-10-20 20:57:45 +02005156static void
Imre Deak54648612016-06-16 16:37:22 +03005157intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
5158 struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02005159{
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305160 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03005161 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07005162
Imre Deak8e8232d2016-06-16 16:37:21 +03005163 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02005164
5165 /* Workaround: Need to write PP_CONTROL with the unlock key as
5166 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305167 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02005168
Imre Deak8e8232d2016-06-16 16:37:21 +03005169 pp_on = I915_READ(regs.pp_on);
5170 pp_off = I915_READ(regs.pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005171 if (!IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005172 I915_WRITE(regs.pp_ctrl, pp_ctl);
5173 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305174 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005175
5176 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03005177 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
5178 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005179
Imre Deak54648612016-06-16 16:37:22 +03005180 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
5181 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005182
Imre Deak54648612016-06-16 16:37:22 +03005183 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
5184 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005185
Imre Deak54648612016-06-16 16:37:22 +03005186 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
5187 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005188
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005189 if (IS_GEN9_LP(dev_priv)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305190 u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
5191 BXT_POWER_CYCLE_DELAY_SHIFT;
5192 if (tmp > 0)
Imre Deak54648612016-06-16 16:37:22 +03005193 seq->t11_t12 = (tmp - 1) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305194 else
Imre Deak54648612016-06-16 16:37:22 +03005195 seq->t11_t12 = 0;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305196 } else {
Imre Deak54648612016-06-16 16:37:22 +03005197 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02005198 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305199 }
Imre Deak54648612016-06-16 16:37:22 +03005200}
5201
5202static void
Imre Deakde9c1b62016-06-16 20:01:46 +03005203intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
5204{
5205 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5206 state_name,
5207 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
5208}
5209
5210static void
5211intel_pps_verify_state(struct drm_i915_private *dev_priv,
5212 struct intel_dp *intel_dp)
5213{
5214 struct edp_power_seq hw;
5215 struct edp_power_seq *sw = &intel_dp->pps_delays;
5216
5217 intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
5218
5219 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
5220 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
5221 DRM_ERROR("PPS state mismatch\n");
5222 intel_pps_dump_state("sw", sw);
5223 intel_pps_dump_state("hw", &hw);
5224 }
5225}
5226
5227static void
Imre Deak54648612016-06-16 16:37:22 +03005228intel_dp_init_panel_power_sequencer(struct drm_device *dev,
5229 struct intel_dp *intel_dp)
5230{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005231 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak54648612016-06-16 16:37:22 +03005232 struct edp_power_seq cur, vbt, spec,
5233 *final = &intel_dp->pps_delays;
5234
5235 lockdep_assert_held(&dev_priv->pps_mutex);
5236
5237 /* already initialized? */
5238 if (final->t11_t12 != 0)
5239 return;
5240
5241 intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005242
Imre Deakde9c1b62016-06-16 20:01:46 +03005243 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005244
Jani Nikula6aa23e62016-03-24 17:50:20 +02005245 vbt = dev_priv->vbt.edp.pps;
Daniel Vetter67a54562012-10-20 20:57:45 +02005246
5247 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5248 * our hw here, which are all in 100usec. */
5249 spec.t1_t3 = 210 * 10;
5250 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5251 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5252 spec.t10 = 500 * 10;
5253 /* This one is special and actually in units of 100ms, but zero
5254 * based in the hw (so we need to add 100 ms). But the sw vbt
5255 * table multiplies it with 1000 to make it in units of 100usec,
5256 * too. */
5257 spec.t11_t12 = (510 + 100) * 10;
5258
Imre Deakde9c1b62016-06-16 20:01:46 +03005259 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005260
5261 /* Use the max of the register settings and vbt. If both are
5262 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005263#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005264 spec.field : \
5265 max(cur.field, vbt.field))
5266 assign_final(t1_t3);
5267 assign_final(t8);
5268 assign_final(t9);
5269 assign_final(t10);
5270 assign_final(t11_t12);
5271#undef assign_final
5272
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005273#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005274 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5275 intel_dp->backlight_on_delay = get_delay(t8);
5276 intel_dp->backlight_off_delay = get_delay(t9);
5277 intel_dp->panel_power_down_delay = get_delay(t10);
5278 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5279#undef get_delay
5280
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005281 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5282 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5283 intel_dp->panel_power_cycle_delay);
5284
5285 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5286 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005287
5288 /*
5289 * We override the HW backlight delays to 1 because we do manual waits
5290 * on them. For T8, even BSpec recommends doing it. For T9, if we
5291 * don't do this, we'll end up waiting for the backlight off delay
5292 * twice: once when we do the manual sleep, and once when we disable
5293 * the panel and wait for the PP_STATUS bit to become zero.
5294 */
5295 final->t8 = 1;
5296 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005297}
5298
5299static void
5300intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005301 struct intel_dp *intel_dp,
5302 bool force_disable_vdd)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005303{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005304 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07005305 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005306 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005307 struct pps_registers regs;
Ville Syrjäläad933b52014-08-18 22:15:56 +03005308 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005309 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005310
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005311 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005312
Imre Deak8e8232d2016-06-16 16:37:21 +03005313 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005314
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005315 /*
5316 * On some VLV machines the BIOS can leave the VDD
5317 * enabled even on power seqeuencers which aren't
5318 * hooked up to any port. This would mess up the
5319 * power domain tracking the first time we pick
5320 * one of these power sequencers for use since
5321 * edp_panel_vdd_on() would notice that the VDD was
5322 * already on and therefore wouldn't grab the power
5323 * domain reference. Disable VDD first to avoid this.
5324 * This also avoids spuriously turning the VDD on as
5325 * soon as the new power seqeuencer gets initialized.
5326 */
5327 if (force_disable_vdd) {
5328 u32 pp = ironlake_get_pp_control(intel_dp);
5329
5330 WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
5331
5332 if (pp & EDP_FORCE_VDD)
5333 DRM_DEBUG_KMS("VDD already on, disabling first\n");
5334
5335 pp &= ~EDP_FORCE_VDD;
5336
5337 I915_WRITE(regs.pp_ctrl, pp);
5338 }
5339
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005340 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005341 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5342 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005343 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005344 /* Compute the divisor for the pp clock, simply match the Bspec
5345 * formula. */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005346 if (IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005347 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305348 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
5349 pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
5350 << BXT_POWER_CYCLE_DELAY_SHIFT);
5351 } else {
5352 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5353 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5354 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5355 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005356
5357 /* Haswell doesn't have any port selection bits for the panel
5358 * power sequencer any more. */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005359 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005360 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005361 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005362 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005363 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005364 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005365 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005366 }
5367
Jesse Barnes453c5422013-03-28 09:55:41 -07005368 pp_on |= port_sel;
5369
Imre Deak8e8232d2016-06-16 16:37:21 +03005370 I915_WRITE(regs.pp_on, pp_on);
5371 I915_WRITE(regs.pp_off, pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005372 if (IS_GEN9_LP(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005373 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305374 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005375 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005376
Daniel Vetter67a54562012-10-20 20:57:45 +02005377 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 +03005378 I915_READ(regs.pp_on),
5379 I915_READ(regs.pp_off),
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005380 IS_GEN9_LP(dev_priv) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005381 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5382 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005383}
5384
Imre Deak335f7522016-08-10 14:07:32 +03005385static void intel_dp_pps_init(struct drm_device *dev,
5386 struct intel_dp *intel_dp)
5387{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005388 struct drm_i915_private *dev_priv = to_i915(dev);
5389
5390 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Imre Deak335f7522016-08-10 14:07:32 +03005391 vlv_initial_power_sequencer_setup(intel_dp);
5392 } else {
5393 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005394 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak335f7522016-08-10 14:07:32 +03005395 }
5396}
5397
Vandana Kannanb33a2812015-02-13 15:33:03 +05305398/**
5399 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005400 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005401 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305402 * @refresh_rate: RR to be programmed
5403 *
5404 * This function gets called when refresh rate (RR) has to be changed from
5405 * one frequency to another. Switches can be between high and low RR
5406 * supported by the panel or to any other RR based on media playback (in
5407 * this case, RR value needs to be passed from user space).
5408 *
5409 * The caller of this function needs to take a lock on dev_priv->drrs.
5410 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005411static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
5412 struct intel_crtc_state *crtc_state,
5413 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305414{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305415 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305416 struct intel_digital_port *dig_port = NULL;
5417 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005418 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305419 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305420
5421 if (refresh_rate <= 0) {
5422 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5423 return;
5424 }
5425
Vandana Kannan96178ee2015-01-10 02:25:56 +05305426 if (intel_dp == NULL) {
5427 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305428 return;
5429 }
5430
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005431 /*
Rodrigo Vivie4d59f62014-11-20 02:22:08 -08005432 * FIXME: This needs proper synchronization with psr state for some
5433 * platforms that cannot have PSR and DRRS enabled at the same time.
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005434 */
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305435
Vandana Kannan96178ee2015-01-10 02:25:56 +05305436 dig_port = dp_to_dig_port(intel_dp);
5437 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02005438 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305439
5440 if (!intel_crtc) {
5441 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5442 return;
5443 }
5444
Vandana Kannan96178ee2015-01-10 02:25:56 +05305445 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305446 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5447 return;
5448 }
5449
Vandana Kannan96178ee2015-01-10 02:25:56 +05305450 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5451 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305452 index = DRRS_LOW_RR;
5453
Vandana Kannan96178ee2015-01-10 02:25:56 +05305454 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305455 DRM_DEBUG_KMS(
5456 "DRRS requested for previously set RR...ignoring\n");
5457 return;
5458 }
5459
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005460 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305461 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5462 return;
5463 }
5464
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005465 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305466 switch (index) {
5467 case DRRS_HIGH_RR:
5468 intel_dp_set_m_n(intel_crtc, M1_N1);
5469 break;
5470 case DRRS_LOW_RR:
5471 intel_dp_set_m_n(intel_crtc, M2_N2);
5472 break;
5473 case DRRS_MAX_RR:
5474 default:
5475 DRM_ERROR("Unsupported refreshrate type\n");
5476 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005477 } else if (INTEL_GEN(dev_priv) > 6) {
5478 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005479 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305480
Ville Syrjälä649636e2015-09-22 19:50:01 +03005481 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305482 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005483 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305484 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5485 else
5486 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305487 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005488 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305489 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5490 else
5491 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305492 }
5493 I915_WRITE(reg, val);
5494 }
5495
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305496 dev_priv->drrs.refresh_rate_type = index;
5497
5498 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5499}
5500
Vandana Kannanb33a2812015-02-13 15:33:03 +05305501/**
5502 * intel_edp_drrs_enable - init drrs struct if supported
5503 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005504 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305505 *
5506 * Initializes frontbuffer_bits and drrs.dp
5507 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005508void intel_edp_drrs_enable(struct intel_dp *intel_dp,
5509 struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305510{
5511 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005512 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305513
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005514 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305515 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5516 return;
5517 }
5518
5519 mutex_lock(&dev_priv->drrs.mutex);
5520 if (WARN_ON(dev_priv->drrs.dp)) {
5521 DRM_ERROR("DRRS already enabled\n");
5522 goto unlock;
5523 }
5524
5525 dev_priv->drrs.busy_frontbuffer_bits = 0;
5526
5527 dev_priv->drrs.dp = intel_dp;
5528
5529unlock:
5530 mutex_unlock(&dev_priv->drrs.mutex);
5531}
5532
Vandana Kannanb33a2812015-02-13 15:33:03 +05305533/**
5534 * intel_edp_drrs_disable - Disable DRRS
5535 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005536 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305537 *
5538 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005539void intel_edp_drrs_disable(struct intel_dp *intel_dp,
5540 struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305541{
5542 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005543 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305544
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005545 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305546 return;
5547
5548 mutex_lock(&dev_priv->drrs.mutex);
5549 if (!dev_priv->drrs.dp) {
5550 mutex_unlock(&dev_priv->drrs.mutex);
5551 return;
5552 }
5553
5554 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005555 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5556 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305557
5558 dev_priv->drrs.dp = NULL;
5559 mutex_unlock(&dev_priv->drrs.mutex);
5560
5561 cancel_delayed_work_sync(&dev_priv->drrs.work);
5562}
5563
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305564static void intel_edp_drrs_downclock_work(struct work_struct *work)
5565{
5566 struct drm_i915_private *dev_priv =
5567 container_of(work, typeof(*dev_priv), drrs.work.work);
5568 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305569
Vandana Kannan96178ee2015-01-10 02:25:56 +05305570 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305571
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305572 intel_dp = dev_priv->drrs.dp;
5573
5574 if (!intel_dp)
5575 goto unlock;
5576
5577 /*
5578 * The delayed work can race with an invalidate hence we need to
5579 * recheck.
5580 */
5581
5582 if (dev_priv->drrs.busy_frontbuffer_bits)
5583 goto unlock;
5584
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005585 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5586 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5587
5588 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5589 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5590 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305591
5592unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305593 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305594}
5595
Vandana Kannanb33a2812015-02-13 15:33:03 +05305596/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305597 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005598 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305599 * @frontbuffer_bits: frontbuffer plane tracking bits
5600 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305601 * This function gets called everytime rendering on the given planes start.
5602 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305603 *
5604 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5605 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005606void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5607 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305608{
Vandana Kannana93fad02015-01-10 02:25:59 +05305609 struct drm_crtc *crtc;
5610 enum pipe pipe;
5611
Daniel Vetter9da7d692015-04-09 16:44:15 +02005612 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305613 return;
5614
Daniel Vetter88f933a2015-04-09 16:44:16 +02005615 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305616
Vandana Kannana93fad02015-01-10 02:25:59 +05305617 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005618 if (!dev_priv->drrs.dp) {
5619 mutex_unlock(&dev_priv->drrs.mutex);
5620 return;
5621 }
5622
Vandana Kannana93fad02015-01-10 02:25:59 +05305623 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5624 pipe = to_intel_crtc(crtc)->pipe;
5625
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005626 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5627 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5628
Ramalingam C0ddfd202015-06-15 20:50:05 +05305629 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005630 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005631 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5632 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305633
Vandana Kannana93fad02015-01-10 02:25:59 +05305634 mutex_unlock(&dev_priv->drrs.mutex);
5635}
5636
Vandana Kannanb33a2812015-02-13 15:33:03 +05305637/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305638 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005639 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305640 * @frontbuffer_bits: frontbuffer plane tracking bits
5641 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305642 * This function gets called every time rendering on the given planes has
5643 * completed or flip on a crtc is completed. So DRRS should be upclocked
5644 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5645 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305646 *
5647 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5648 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005649void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5650 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305651{
Vandana Kannana93fad02015-01-10 02:25:59 +05305652 struct drm_crtc *crtc;
5653 enum pipe pipe;
5654
Daniel Vetter9da7d692015-04-09 16:44:15 +02005655 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305656 return;
5657
Daniel Vetter88f933a2015-04-09 16:44:16 +02005658 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305659
Vandana Kannana93fad02015-01-10 02:25:59 +05305660 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005661 if (!dev_priv->drrs.dp) {
5662 mutex_unlock(&dev_priv->drrs.mutex);
5663 return;
5664 }
5665
Vandana Kannana93fad02015-01-10 02:25:59 +05305666 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5667 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005668
5669 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305670 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5671
Ramalingam C0ddfd202015-06-15 20:50:05 +05305672 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005673 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005674 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5675 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305676
5677 /*
5678 * flush also means no more activity hence schedule downclock, if all
5679 * other fbs are quiescent too
5680 */
5681 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305682 schedule_delayed_work(&dev_priv->drrs.work,
5683 msecs_to_jiffies(1000));
5684 mutex_unlock(&dev_priv->drrs.mutex);
5685}
5686
Vandana Kannanb33a2812015-02-13 15:33:03 +05305687/**
5688 * DOC: Display Refresh Rate Switching (DRRS)
5689 *
5690 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5691 * which enables swtching between low and high refresh rates,
5692 * dynamically, based on the usage scenario. This feature is applicable
5693 * for internal panels.
5694 *
5695 * Indication that the panel supports DRRS is given by the panel EDID, which
5696 * would list multiple refresh rates for one resolution.
5697 *
5698 * DRRS is of 2 types - static and seamless.
5699 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5700 * (may appear as a blink on screen) and is used in dock-undock scenario.
5701 * Seamless DRRS involves changing RR without any visual effect to the user
5702 * and can be used during normal system usage. This is done by programming
5703 * certain registers.
5704 *
5705 * Support for static/seamless DRRS may be indicated in the VBT based on
5706 * inputs from the panel spec.
5707 *
5708 * DRRS saves power by switching to low RR based on usage scenarios.
5709 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005710 * The implementation is based on frontbuffer tracking implementation. When
5711 * there is a disturbance on the screen triggered by user activity or a periodic
5712 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5713 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5714 * made.
5715 *
5716 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5717 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305718 *
5719 * DRRS can be further extended to support other internal panels and also
5720 * the scenario of video playback wherein RR is set based on the rate
5721 * requested by userspace.
5722 */
5723
5724/**
5725 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5726 * @intel_connector: eDP connector
5727 * @fixed_mode: preferred mode of panel
5728 *
5729 * This function is called only once at driver load to initialize basic
5730 * DRRS stuff.
5731 *
5732 * Returns:
5733 * Downclock mode if panel supports it, else return NULL.
5734 * DRRS support is determined by the presence of downclock mode (apart
5735 * from VBT setting).
5736 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305737static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305738intel_dp_drrs_init(struct intel_connector *intel_connector,
5739 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305740{
5741 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305742 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005743 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305744 struct drm_display_mode *downclock_mode = NULL;
5745
Daniel Vetter9da7d692015-04-09 16:44:15 +02005746 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5747 mutex_init(&dev_priv->drrs.mutex);
5748
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005749 if (INTEL_GEN(dev_priv) <= 6) {
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305750 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5751 return NULL;
5752 }
5753
5754 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005755 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305756 return NULL;
5757 }
5758
5759 downclock_mode = intel_find_panel_downclock
Mika Kaholaa318b4c2016-12-13 10:02:48 +02005760 (dev_priv, fixed_mode, connector);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305761
5762 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305763 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305764 return NULL;
5765 }
5766
Vandana Kannan96178ee2015-01-10 02:25:56 +05305767 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305768
Vandana Kannan96178ee2015-01-10 02:25:56 +05305769 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005770 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305771 return downclock_mode;
5772}
5773
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005774static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005775 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005776{
5777 struct drm_connector *connector = &intel_connector->base;
5778 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005779 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5780 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005781 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005782 struct drm_display_mode *fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305783 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005784 bool has_dpcd;
5785 struct drm_display_mode *scan;
5786 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005787 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005788
5789 if (!is_edp(intel_dp))
5790 return true;
5791
Imre Deak97a824e12016-06-21 11:51:47 +03005792 /*
5793 * On IBX/CPT we may get here with LVDS already registered. Since the
5794 * driver uses the only internal power sequencer available for both
5795 * eDP and LVDS bail out early in this case to prevent interfering
5796 * with an already powered-on LVDS power sequencer.
5797 */
5798 if (intel_get_lvds_encoder(dev)) {
5799 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5800 DRM_INFO("LVDS was detected, not registering eDP\n");
5801
5802 return false;
5803 }
5804
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005805 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005806
5807 intel_dp_init_panel_power_timestamps(intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +03005808 intel_dp_pps_init(dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005809 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005810
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005811 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005812
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005813 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005814 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005815
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005816 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005817 /* if this fails, presume the device is a ghost */
5818 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005819 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005820 }
5821
Daniel Vetter060c8772014-03-21 23:22:35 +01005822 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005823 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005824 if (edid) {
5825 if (drm_add_edid_modes(connector, edid)) {
5826 drm_mode_connector_update_edid_property(connector,
5827 edid);
5828 drm_edid_to_eld(connector, edid);
5829 } else {
5830 kfree(edid);
5831 edid = ERR_PTR(-EINVAL);
5832 }
5833 } else {
5834 edid = ERR_PTR(-ENOENT);
5835 }
5836 intel_connector->edid = edid;
5837
5838 /* prefer fixed mode from EDID if available */
5839 list_for_each_entry(scan, &connector->probed_modes, head) {
5840 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5841 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305842 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305843 intel_connector, fixed_mode);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005844 break;
5845 }
5846 }
5847
5848 /* fallback to VBT if available for eDP */
5849 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5850 fixed_mode = drm_mode_duplicate(dev,
5851 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005852 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005853 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005854 connector->display_info.width_mm = fixed_mode->width_mm;
5855 connector->display_info.height_mm = fixed_mode->height_mm;
5856 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005857 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005858 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005859
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005860 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005861 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5862 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005863
5864 /*
5865 * Figure out the current pipe for the initial backlight setup.
5866 * If the current pipe isn't valid, try the PPS pipe, and if that
5867 * fails just assume pipe A.
5868 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005869 pipe = vlv_active_pipe(intel_dp);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005870
5871 if (pipe != PIPE_A && pipe != PIPE_B)
5872 pipe = intel_dp->pps_pipe;
5873
5874 if (pipe != PIPE_A && pipe != PIPE_B)
5875 pipe = PIPE_A;
5876
5877 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5878 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005879 }
5880
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305881 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005882 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005883 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005884
5885 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005886
5887out_vdd_off:
5888 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5889 /*
5890 * vdd might still be enabled do to the delayed vdd off.
5891 * Make sure vdd is actually turned off here.
5892 */
5893 pps_lock(intel_dp);
5894 edp_panel_vdd_off_sync(intel_dp);
5895 pps_unlock(intel_dp);
5896
5897 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005898}
5899
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005900/* Set up the hotplug pin and aux power domain. */
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005901static void
5902intel_dp_init_connector_port_info(struct intel_digital_port *intel_dig_port)
5903{
5904 struct intel_encoder *encoder = &intel_dig_port->base;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005905 struct intel_dp *intel_dp = &intel_dig_port->dp;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005906
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005907 switch (intel_dig_port->port) {
5908 case PORT_A:
5909 encoder->hpd_pin = HPD_PORT_A;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005910 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_A;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005911 break;
5912 case PORT_B:
5913 encoder->hpd_pin = HPD_PORT_B;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005914 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_B;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005915 break;
5916 case PORT_C:
5917 encoder->hpd_pin = HPD_PORT_C;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005918 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_C;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005919 break;
5920 case PORT_D:
5921 encoder->hpd_pin = HPD_PORT_D;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005922 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005923 break;
5924 case PORT_E:
5925 encoder->hpd_pin = HPD_PORT_E;
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02005926
5927 /* FIXME: Check VBT for actual wiring of PORT E */
5928 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
Ander Conselvan de Oliveirab71953a2017-02-03 16:03:14 +02005929 break;
5930 default:
5931 MISSING_CASE(intel_dig_port->port);
5932 }
5933}
5934
Paulo Zanoni16c25532013-06-12 17:27:25 -03005935bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005936intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5937 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005938{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005939 struct drm_connector *connector = &intel_connector->base;
5940 struct intel_dp *intel_dp = &intel_dig_port->dp;
5941 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5942 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005943 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02005944 enum port port = intel_dig_port->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01005945 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005946
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005947 if (WARN(intel_dig_port->max_lanes < 1,
5948 "Not enough lanes (%d) for DP on port %c\n",
5949 intel_dig_port->max_lanes, port_name(port)))
5950 return false;
5951
Manasi Navared7e8ef02017-02-07 16:54:11 -08005952 intel_dp->reset_link_params = true;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005953 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005954 intel_dp->active_pipe = INVALID_PIPE;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005955
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005956 /* intel_dp vfuncs */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005957 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub6b5e382014-01-20 16:00:59 +00005958 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005959 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005960 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005961 else if (HAS_PCH_SPLIT(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005962 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
5963 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005964 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005965
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005966 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00005967 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
5968 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005969 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00005970
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005971 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03005972 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
5973
Daniel Vetter07679352012-09-06 22:15:42 +02005974 /* Preserve the current hw state. */
5975 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03005976 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00005977
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005978 if (intel_dp_is_edp(dev_priv, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05305979 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005980 else
5981 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04005982
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005983 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5984 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5985
Imre Deakf7d24902013-05-08 13:14:05 +03005986 /*
5987 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
5988 * for DP the encoder type can be set by the caller to
5989 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
5990 */
5991 if (type == DRM_MODE_CONNECTOR_eDP)
5992 intel_encoder->type = INTEL_OUTPUT_EDP;
5993
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005994 /* eDP only on port B and/or C on vlv/chv */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005995 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08005996 is_edp(intel_dp) && port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005997 return false;
5998
Imre Deake7281ea2013-05-08 13:14:08 +03005999 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
6000 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
6001 port_name(port));
6002
Adam Jacksonb3295302010-07-16 14:46:28 -04006003 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006004 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
6005
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006006 connector->interlace_allowed = true;
6007 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08006008
Ander Conselvan de Oliveira5432fca2017-02-22 08:34:26 +02006009 intel_dp_init_connector_port_info(intel_dig_port);
6010
Mika Kaholab6339582016-09-09 14:10:52 +03006011 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01006012
Daniel Vetter66a92782012-07-12 20:08:18 +02006013 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01006014 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08006015
Chris Wilsondf0e9242010-09-09 16:20:55 +01006016 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006017
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006018 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02006019 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
6020 else
6021 intel_connector->get_hw_state = intel_connector_get_hw_state;
6022
Dave Airlie0e32b392014-05-02 14:02:48 +10006023 /* init MST on ports that can support it */
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00006024 if (HAS_DP_MST(dev_priv) && !is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03006025 (port == PORT_B || port == PORT_C || port == PORT_D))
6026 intel_dp_mst_encoder_init(intel_dig_port,
6027 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10006028
Ville Syrjälä36b5f422014-10-16 21:27:30 +03006029 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006030 intel_dp_aux_fini(intel_dp);
6031 intel_dp_mst_encoder_cleanup(intel_dig_port);
6032 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03006033 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08006034
Chris Wilsonf6849602010-09-19 09:29:33 +01006035 intel_dp_add_properties(intel_dp, connector);
6036
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006037 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
6038 * 0xd. Failure to do so will result in spurious interrupts being
6039 * generated on the port when a cable is not attached.
6040 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01006041 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006042 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
6043 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
6044 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03006045
6046 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006047
6048fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006049 drm_connector_cleanup(connector);
6050
6051 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006052}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006053
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006054bool intel_dp_init(struct drm_i915_private *dev_priv,
Chris Wilson457c52d2016-06-01 08:27:50 +01006055 i915_reg_t output_reg,
6056 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006057{
6058 struct intel_digital_port *intel_dig_port;
6059 struct intel_encoder *intel_encoder;
6060 struct drm_encoder *encoder;
6061 struct intel_connector *intel_connector;
6062
Daniel Vetterb14c5672013-09-19 12:18:32 +02006063 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006064 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01006065 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006066
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03006067 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306068 if (!intel_connector)
6069 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006070
6071 intel_encoder = &intel_dig_port->base;
6072 encoder = &intel_encoder->base;
6073
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006074 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
6075 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
6076 "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306077 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006078
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01006079 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006080 intel_encoder->disable = intel_disable_dp;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006081 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07006082 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03006083 intel_encoder->suspend = intel_dp_encoder_suspend;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006084 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03006085 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03006086 intel_encoder->pre_enable = chv_pre_enable_dp;
6087 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03006088 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03006089 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01006090 } else if (IS_VALLEYVIEW(dev_priv)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006091 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006092 intel_encoder->pre_enable = vlv_pre_enable_dp;
6093 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03006094 intel_encoder->post_disable = vlv_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006095 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006096 intel_encoder->pre_enable = g4x_pre_enable_dp;
6097 intel_encoder->enable = g4x_enable_dp;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006098 if (INTEL_GEN(dev_priv) >= 5)
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03006099 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006100 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006101
Paulo Zanoni174edf12012-10-26 19:05:50 -02006102 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006103 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02006104 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006105
Ville Syrjäläcca05022016-06-22 21:57:06 +03006106 intel_encoder->type = INTEL_OUTPUT_DP;
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02006107 intel_encoder->power_domain = intel_port_to_power_domain(port);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006108 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03006109 if (port == PORT_D)
6110 intel_encoder->crtc_mask = 1 << 2;
6111 else
6112 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
6113 } else {
6114 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
6115 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02006116 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07006117 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006118
Dave Airlie13cf5502014-06-18 11:29:35 +10006119 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03006120 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10006121
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306122 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
6123 goto err_init_connector;
6124
Chris Wilson457c52d2016-06-01 08:27:50 +01006125 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306126
6127err_init_connector:
6128 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306129err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306130 kfree(intel_connector);
6131err_connector_alloc:
6132 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01006133 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006134}
Dave Airlie0e32b392014-05-02 14:02:48 +10006135
6136void intel_dp_mst_suspend(struct drm_device *dev)
6137{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006138 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006139 int i;
6140
6141 /* disable MST */
6142 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006143 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006144
6145 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006146 continue;
6147
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006148 if (intel_dig_port->dp.is_mst)
6149 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10006150 }
6151}
6152
6153void intel_dp_mst_resume(struct drm_device *dev)
6154{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006155 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006156 int i;
6157
6158 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006159 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006160 int ret;
6161
6162 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006163 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10006164
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006165 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
6166 if (ret)
6167 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10006168 }
6169}