blob: 21924cf4c8ad203812fa0f9033a902aef53429e4 [file] [log] [blame]
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Keith Packard <keithp@keithp.com>
25 *
26 */
27
28#include <linux/i2c.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040030#include <linux/export.h>
Manasi Navare611032b2017-01-24 08:21:49 -080031#include <linux/types.h>
Clint Taylor01527b32014-07-07 13:01:46 -070032#include <linux/notifier.h>
33#include <linux/reboot.h>
Manasi Navare611032b2017-01-24 08:21:49 -080034#include <asm/byteorder.h>
David Howells760285e2012-10-02 18:01:07 +010035#include <drm/drmP.h>
Matt Roperc6f95f22015-01-22 16:50:32 -080036#include <drm/drm_atomic_helper.h>
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/drm_crtc.h>
38#include <drm/drm_crtc_helper.h>
39#include <drm/drm_edid.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070040#include "intel_drv.h"
David Howells760285e2012-10-02 18:01:07 +010041#include <drm/i915_drm.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070042#include "i915_drv.h"
Keith Packarda4fc5ed2009-04-07 16:16:42 -070043
Keith Packarda4fc5ed2009-04-07 16:16:42 -070044#define DP_LINK_CHECK_TIMEOUT (10 * 1000)
45
Todd Previte559be302015-05-04 07:48:20 -070046/* Compliance test status bits */
47#define INTEL_DP_RESOLUTION_SHIFT_MASK 0
48#define INTEL_DP_RESOLUTION_PREFERRED (1 << INTEL_DP_RESOLUTION_SHIFT_MASK)
49#define INTEL_DP_RESOLUTION_STANDARD (2 << INTEL_DP_RESOLUTION_SHIFT_MASK)
50#define INTEL_DP_RESOLUTION_FAILSAFE (3 << INTEL_DP_RESOLUTION_SHIFT_MASK)
51
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080052struct dp_link_dpll {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030053 int clock;
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080054 struct dpll dpll;
55};
56
57static const struct dp_link_dpll gen4_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030058 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080059 { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030060 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080061 { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
62};
63
64static const struct dp_link_dpll pch_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030065 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080066 { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030067 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080068 { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
69};
70
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080071static const struct dp_link_dpll vlv_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030072 { 162000,
Chon Ming Lee58f6e632013-09-25 15:47:51 +080073 { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030074 { 270000,
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080075 { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } }
76};
77
Chon Ming Leeef9348c2014-04-09 13:28:18 +030078/*
79 * CHV supports eDP 1.4 that have more link rates.
80 * Below only provides the fixed rate but exclude variable rate.
81 */
82static const struct dp_link_dpll chv_dpll[] = {
83 /*
84 * CHV requires to program fractional division for m2.
85 * m2 is stored in fixed point format using formula below
86 * (m2_int << 22) | m2_fraction
87 */
Ville Syrjälä840b32b2015-08-11 20:21:46 +030088 { 162000, /* m2_int = 32, m2_fraction = 1677722 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030089 { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030090 { 270000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030091 { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030092 { 540000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030093 { .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }
94};
Sonika Jindal637a9c62015-05-07 09:52:08 +053095
Sonika Jindal64987fc2015-05-26 17:50:13 +053096static const int bxt_rates[] = { 162000, 216000, 243000, 270000,
97 324000, 432000, 540000 };
Sonika Jindal637a9c62015-05-07 09:52:08 +053098static const int skl_rates[] = { 162000, 216000, 270000,
Ville Syrjäläf4896f12015-03-12 17:10:27 +020099 324000, 432000, 540000 };
100static const int default_rates[] = { 162000, 270000, 540000 };
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300101
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700102/**
103 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
104 * @intel_dp: DP struct
105 *
106 * If a CPU or PCH DP output is attached to an eDP panel, this function
107 * will return true, and false otherwise.
108 */
109static bool is_edp(struct intel_dp *intel_dp)
110{
Paulo Zanonida63a9f2012-10-26 19:05:46 -0200111 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
112
113 return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700114}
115
Imre Deak68b4d822013-05-08 13:14:06 +0300116static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp)
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700117{
Imre Deak68b4d822013-05-08 13:14:06 +0300118 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
119
120 return intel_dig_port->base.base.dev;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700121}
122
Chris Wilsondf0e9242010-09-09 16:20:55 +0100123static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
124{
Paulo Zanonifa90ece2012-10-26 19:05:44 -0200125 return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
Chris Wilsondf0e9242010-09-09 16:20:55 +0100126}
127
Chris Wilsonea5b2132010-08-04 13:50:23 +0100128static void intel_dp_link_down(struct intel_dp *intel_dp);
Ville Syrjälä1e0560e2014-08-19 13:24:25 +0300129static bool edp_panel_vdd_on(struct intel_dp *intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +0100130static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
Ville Syrjälä093e3f12014-10-16 21:27:33 +0300131static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300132static void vlv_steal_power_sequencer(struct drm_device *dev,
133 enum pipe pipe);
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +0530134static void intel_dp_unset_edid(struct intel_dp *intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700135
Ville Syrjäläed4e9c12015-03-12 17:10:36 +0200136static int
137intel_dp_max_link_bw(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700138{
Jesse Barnes7183dc22011-07-07 11:10:58 -0700139 int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700140
141 switch (max_link_bw) {
142 case DP_LINK_BW_1_62:
143 case DP_LINK_BW_2_7:
Ville Syrjälä1db10e22015-03-12 17:10:32 +0200144 case DP_LINK_BW_5_4:
Imre Deakd4eead52013-07-09 17:05:26 +0300145 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700146 default:
Imre Deakd4eead52013-07-09 17:05:26 +0300147 WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
148 max_link_bw);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700149 max_link_bw = DP_LINK_BW_1_62;
150 break;
151 }
152 return max_link_bw;
153}
154
Paulo Zanonieeb63242014-05-06 14:56:50 +0300155static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
156{
157 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300158 u8 source_max, sink_max;
159
Ville Syrjäläccb1a832015-12-08 19:59:38 +0200160 source_max = intel_dig_port->max_lanes;
Manasi Navaref4829842016-12-05 16:27:36 -0800161 sink_max = intel_dp->max_sink_lane_count;
Paulo Zanonieeb63242014-05-06 14:56:50 +0300162
163 return min(source_max, sink_max);
164}
165
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800166int
Keith Packardc8982612012-01-25 08:16:25 -0800167intel_dp_link_required(int pixel_clock, int bpp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700168{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800169 /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
170 return DIV_ROUND_UP(pixel_clock * bpp, 8);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700171}
172
Dhinakaran Pandiyan22a2c8e2016-11-15 12:59:06 -0800173int
Dave Airliefe27d532010-06-30 11:46:17 +1000174intel_dp_max_data_rate(int max_link_clock, int max_lanes)
175{
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -0800176 /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
177 * link rate that is generally expressed in Gbps. Since, 8 bits of data
178 * is transmitted every LS_Clk per lane, there is no need to account for
179 * the channel encoding that is done in the PHY layer here.
180 */
181
182 return max_link_clock * max_lanes;
Dave Airliefe27d532010-06-30 11:46:17 +1000183}
184
Mika Kahola70ec0642016-09-09 14:10:55 +0300185static int
186intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp)
187{
188 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
189 struct intel_encoder *encoder = &intel_dig_port->base;
190 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
191 int max_dotclk = dev_priv->max_dotclk_freq;
192 int ds_max_dotclk;
193
194 int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
195
196 if (type != DP_DS_PORT_TYPE_VGA)
197 return max_dotclk;
198
199 ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd,
200 intel_dp->downstream_ports);
201
202 if (ds_max_dotclk != 0)
203 max_dotclk = min(max_dotclk, ds_max_dotclk);
204
205 return max_dotclk;
206}
207
Navare, Manasi D40dba342016-10-26 16:25:55 -0700208static int
209intel_dp_sink_rates(struct intel_dp *intel_dp, const int **sink_rates)
210{
211 if (intel_dp->num_sink_rates) {
212 *sink_rates = intel_dp->sink_rates;
213 return intel_dp->num_sink_rates;
214 }
215
216 *sink_rates = default_rates;
217
Manasi Navaref4829842016-12-05 16:27:36 -0800218 return (intel_dp->max_sink_link_bw >> 3) + 1;
Navare, Manasi D40dba342016-10-26 16:25:55 -0700219}
220
221static int
222intel_dp_source_rates(struct intel_dp *intel_dp, const int **source_rates)
223{
224 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
225 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
226 int size;
227
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200228 if (IS_GEN9_LP(dev_priv)) {
Navare, Manasi D40dba342016-10-26 16:25:55 -0700229 *source_rates = bxt_rates;
230 size = ARRAY_SIZE(bxt_rates);
Rodrigo Vivib976dc52017-01-23 10:32:37 -0800231 } else if (IS_GEN9_BC(dev_priv)) {
Navare, Manasi D40dba342016-10-26 16:25:55 -0700232 *source_rates = skl_rates;
233 size = ARRAY_SIZE(skl_rates);
234 } else {
235 *source_rates = default_rates;
236 size = ARRAY_SIZE(default_rates);
237 }
238
239 /* This depends on the fact that 5.4 is last value in the array */
240 if (!intel_dp_source_supports_hbr2(intel_dp))
241 size--;
242
243 return size;
244}
245
246static int intersect_rates(const int *source_rates, int source_len,
247 const int *sink_rates, int sink_len,
248 int *common_rates)
249{
250 int i = 0, j = 0, k = 0;
251
252 while (i < source_len && j < sink_len) {
253 if (source_rates[i] == sink_rates[j]) {
254 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
255 return k;
256 common_rates[k] = source_rates[i];
257 ++k;
258 ++i;
259 ++j;
260 } else if (source_rates[i] < sink_rates[j]) {
261 ++i;
262 } else {
263 ++j;
264 }
265 }
266 return k;
267}
268
269static int intel_dp_common_rates(struct intel_dp *intel_dp,
270 int *common_rates)
271{
272 const int *source_rates, *sink_rates;
273 int source_len, sink_len;
274
275 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
276 source_len = intel_dp_source_rates(intel_dp, &source_rates);
277
278 return intersect_rates(source_rates, source_len,
279 sink_rates, sink_len,
280 common_rates);
281}
282
Manasi Navarefdb14d32016-12-08 19:05:12 -0800283static int intel_dp_link_rate_index(struct intel_dp *intel_dp,
284 int *common_rates, int link_rate)
285{
286 int common_len;
287 int index;
288
289 common_len = intel_dp_common_rates(intel_dp, common_rates);
290 for (index = 0; index < common_len; index++) {
291 if (link_rate == common_rates[common_len - index - 1])
292 return common_len - index - 1;
293 }
294
295 return -1;
296}
297
298int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
299 int link_rate, uint8_t lane_count)
300{
301 int common_rates[DP_MAX_SUPPORTED_RATES];
302 int link_rate_index;
303
304 link_rate_index = intel_dp_link_rate_index(intel_dp,
305 common_rates,
306 link_rate);
307 if (link_rate_index > 0) {
308 intel_dp->max_sink_link_bw = drm_dp_link_rate_to_bw_code(common_rates[link_rate_index - 1]);
309 intel_dp->max_sink_lane_count = lane_count;
310 } else if (lane_count > 1) {
311 intel_dp->max_sink_link_bw = intel_dp_max_link_bw(intel_dp);
312 intel_dp->max_sink_lane_count = lane_count >> 1;
313 } else {
314 DRM_ERROR("Link Training Unsuccessful\n");
315 return -1;
316 }
317
318 return 0;
319}
320
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000321static enum drm_mode_status
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700322intel_dp_mode_valid(struct drm_connector *connector,
323 struct drm_display_mode *mode)
324{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100325 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300326 struct intel_connector *intel_connector = to_intel_connector(connector);
327 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Daniel Vetter36008362013-03-27 00:44:59 +0100328 int target_clock = mode->clock;
329 int max_rate, mode_rate, max_lanes, max_link_clock;
Mika Kahola70ec0642016-09-09 14:10:55 +0300330 int max_dotclk;
331
332 max_dotclk = intel_dp_downstream_max_dotclock(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700333
Jani Nikuladd06f902012-10-19 14:51:50 +0300334 if (is_edp(intel_dp) && fixed_mode) {
335 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100336 return MODE_PANEL;
337
Jani Nikuladd06f902012-10-19 14:51:50 +0300338 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100339 return MODE_PANEL;
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200340
341 target_clock = fixed_mode->clock;
Zhao Yakui7de56f42010-07-19 09:43:14 +0100342 }
343
Ville Syrjälä50fec212015-03-12 17:10:34 +0200344 max_link_clock = intel_dp_max_link_rate(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300345 max_lanes = intel_dp_max_lane_count(intel_dp);
Daniel Vetter36008362013-03-27 00:44:59 +0100346
347 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
348 mode_rate = intel_dp_link_required(target_clock, 18);
349
Mika Kahola799487f2016-02-02 15:16:38 +0200350 if (mode_rate > max_rate || target_clock > max_dotclk)
Daniel Vetterc4867932012-04-10 10:42:36 +0200351 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700352
353 if (mode->clock < 10000)
354 return MODE_CLOCK_LOW;
355
Daniel Vetter0af78a22012-05-23 11:30:55 +0200356 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
357 return MODE_H_ILLEGAL;
358
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700359 return MODE_OK;
360}
361
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800362uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700363{
364 int i;
365 uint32_t v = 0;
366
367 if (src_bytes > 4)
368 src_bytes = 4;
369 for (i = 0; i < src_bytes; i++)
370 v |= ((uint32_t) src[i]) << ((3-i) * 8);
371 return v;
372}
373
Damien Lespiauc2af70e2015-02-10 19:32:23 +0000374static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700375{
376 int i;
377 if (dst_bytes > 4)
378 dst_bytes = 4;
379 for (i = 0; i < dst_bytes; i++)
380 dst[i] = src >> ((3-i) * 8);
381}
382
Jani Nikulabf13e812013-09-06 07:40:05 +0300383static void
384intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300385 struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300386static void
387intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200388 struct intel_dp *intel_dp,
389 bool force_disable_vdd);
Imre Deak335f7522016-08-10 14:07:32 +0300390static void
391intel_dp_pps_init(struct drm_device *dev, struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300392
Ville Syrjälä773538e82014-09-04 14:54:56 +0300393static void pps_lock(struct intel_dp *intel_dp)
394{
395 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
396 struct intel_encoder *encoder = &intel_dig_port->base;
397 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100398 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300399 enum intel_display_power_domain power_domain;
400
401 /*
402 * See vlv_power_sequencer_reset() why we need
403 * a power domain reference here.
404 */
Ville Syrjälä25f78f52015-11-16 15:01:04 +0100405 power_domain = intel_display_port_aux_power_domain(encoder);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300406 intel_display_power_get(dev_priv, power_domain);
407
408 mutex_lock(&dev_priv->pps_mutex);
409}
410
411static void pps_unlock(struct intel_dp *intel_dp)
412{
413 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
414 struct intel_encoder *encoder = &intel_dig_port->base;
415 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100416 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300417 enum intel_display_power_domain power_domain;
418
419 mutex_unlock(&dev_priv->pps_mutex);
420
Ville Syrjälä25f78f52015-11-16 15:01:04 +0100421 power_domain = intel_display_port_aux_power_domain(encoder);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300422 intel_display_power_put(dev_priv, power_domain);
423}
424
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300425static void
426vlv_power_sequencer_kick(struct intel_dp *intel_dp)
427{
428 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200429 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300430 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300431 bool pll_enabled, release_cl_override = false;
432 enum dpio_phy phy = DPIO_PHY(pipe);
433 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300434 uint32_t DP;
435
436 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
437 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
438 pipe_name(pipe), port_name(intel_dig_port->port)))
439 return;
440
441 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
442 pipe_name(pipe), port_name(intel_dig_port->port));
443
444 /* Preserve the BIOS-computed detected bit. This is
445 * supposed to be read-only.
446 */
447 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
448 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
449 DP |= DP_PORT_WIDTH(1);
450 DP |= DP_LINK_TRAIN_PAT_1;
451
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100452 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300453 DP |= DP_PIPE_SELECT_CHV(pipe);
454 else if (pipe == PIPE_B)
455 DP |= DP_PIPEB_SELECT;
456
Ville Syrjäläd288f652014-10-28 13:20:22 +0200457 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
458
459 /*
460 * The DPLL for the pipe must be enabled for this to work.
461 * So enable temporarily it if it's not already enabled.
462 */
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300463 if (!pll_enabled) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100464 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300465 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
466
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200467 if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ?
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000468 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
469 DRM_ERROR("Failed to force on pll for pipe %c!\n",
470 pipe_name(pipe));
471 return;
472 }
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300473 }
Ville Syrjäläd288f652014-10-28 13:20:22 +0200474
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300475 /*
476 * Similar magic as in intel_dp_enable_port().
477 * We _must_ do this port enable + disable trick
478 * to make this power seqeuencer lock onto the port.
479 * Otherwise even VDD force bit won't work.
480 */
481 I915_WRITE(intel_dp->output_reg, DP);
482 POSTING_READ(intel_dp->output_reg);
483
484 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
485 POSTING_READ(intel_dp->output_reg);
486
487 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
488 POSTING_READ(intel_dp->output_reg);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200489
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300490 if (!pll_enabled) {
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200491 vlv_force_pll_off(dev_priv, pipe);
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300492
493 if (release_cl_override)
494 chv_phy_powergate_ch(dev_priv, phy, ch, false);
495 }
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300496}
497
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200498static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv)
499{
500 struct intel_encoder *encoder;
501 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
502
503 /*
504 * We don't have power sequencer currently.
505 * Pick one that's not used by other ports.
506 */
507 for_each_intel_encoder(&dev_priv->drm, encoder) {
508 struct intel_dp *intel_dp;
509
510 if (encoder->type != INTEL_OUTPUT_DP &&
511 encoder->type != INTEL_OUTPUT_EDP)
512 continue;
513
514 intel_dp = enc_to_intel_dp(&encoder->base);
515
516 if (encoder->type == INTEL_OUTPUT_EDP) {
517 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
518 intel_dp->active_pipe != intel_dp->pps_pipe);
519
520 if (intel_dp->pps_pipe != INVALID_PIPE)
521 pipes &= ~(1 << intel_dp->pps_pipe);
522 } else {
523 WARN_ON(intel_dp->pps_pipe != INVALID_PIPE);
524
525 if (intel_dp->active_pipe != INVALID_PIPE)
526 pipes &= ~(1 << intel_dp->active_pipe);
527 }
528 }
529
530 if (pipes == 0)
531 return INVALID_PIPE;
532
533 return ffs(pipes) - 1;
534}
535
Jani Nikulabf13e812013-09-06 07:40:05 +0300536static enum pipe
537vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
538{
539 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300540 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100541 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300542 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300543
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300544 lockdep_assert_held(&dev_priv->pps_mutex);
545
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300546 /* We should never land here with regular DP ports */
547 WARN_ON(!is_edp(intel_dp));
548
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200549 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
550 intel_dp->active_pipe != intel_dp->pps_pipe);
551
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300552 if (intel_dp->pps_pipe != INVALID_PIPE)
553 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300554
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200555 pipe = vlv_find_free_pps(dev_priv);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300556
557 /*
558 * Didn't find one. This should not happen since there
559 * are two power sequencers and up to two eDP ports.
560 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200561 if (WARN_ON(pipe == INVALID_PIPE))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300562 pipe = PIPE_A;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300563
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300564 vlv_steal_power_sequencer(dev, pipe);
565 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300566
567 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
568 pipe_name(intel_dp->pps_pipe),
569 port_name(intel_dig_port->port));
570
571 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300572 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200573 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300574
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300575 /*
576 * Even vdd force doesn't work until we've made
577 * the power sequencer lock in on the port.
578 */
579 vlv_power_sequencer_kick(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300580
581 return intel_dp->pps_pipe;
582}
583
Imre Deak78597992016-06-16 16:37:20 +0300584static int
585bxt_power_sequencer_idx(struct intel_dp *intel_dp)
586{
587 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
588 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100589 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak78597992016-06-16 16:37:20 +0300590
591 lockdep_assert_held(&dev_priv->pps_mutex);
592
593 /* We should never land here with regular DP ports */
594 WARN_ON(!is_edp(intel_dp));
595
596 /*
597 * TODO: BXT has 2 PPS instances. The correct port->PPS instance
598 * mapping needs to be retrieved from VBT, for now just hard-code to
599 * use instance #0 always.
600 */
601 if (!intel_dp->pps_reset)
602 return 0;
603
604 intel_dp->pps_reset = false;
605
606 /*
607 * Only the HW needs to be reprogrammed, the SW state is fixed and
608 * has been setup during connector init.
609 */
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200610 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak78597992016-06-16 16:37:20 +0300611
612 return 0;
613}
614
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300615typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
616 enum pipe pipe);
617
618static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
619 enum pipe pipe)
620{
Imre Deak44cb7342016-08-10 14:07:29 +0300621 return I915_READ(PP_STATUS(pipe)) & PP_ON;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300622}
623
624static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
625 enum pipe pipe)
626{
Imre Deak44cb7342016-08-10 14:07:29 +0300627 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300628}
629
630static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
631 enum pipe pipe)
632{
633 return true;
634}
635
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300636static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300637vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
638 enum port port,
639 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300640{
Jani Nikulabf13e812013-09-06 07:40:05 +0300641 enum pipe pipe;
642
Jani Nikulabf13e812013-09-06 07:40:05 +0300643 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
Imre Deak44cb7342016-08-10 14:07:29 +0300644 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
Jani Nikulabf13e812013-09-06 07:40:05 +0300645 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300646
647 if (port_sel != PANEL_PORT_SELECT_VLV(port))
648 continue;
649
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300650 if (!pipe_check(dev_priv, pipe))
651 continue;
652
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300653 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300654 }
655
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300656 return INVALID_PIPE;
657}
658
659static void
660vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
661{
662 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
663 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100664 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300665 enum port port = intel_dig_port->port;
666
667 lockdep_assert_held(&dev_priv->pps_mutex);
668
669 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300670 /* first pick one where the panel is on */
671 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
672 vlv_pipe_has_pp_on);
673 /* didn't find one? pick one where vdd is on */
674 if (intel_dp->pps_pipe == INVALID_PIPE)
675 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
676 vlv_pipe_has_vdd_on);
677 /* didn't find one? pick one with just the correct port */
678 if (intel_dp->pps_pipe == INVALID_PIPE)
679 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
680 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300681
682 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
683 if (intel_dp->pps_pipe == INVALID_PIPE) {
684 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
685 port_name(port));
686 return;
687 }
688
689 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
690 port_name(port), pipe_name(intel_dp->pps_pipe));
691
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300692 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +0200693 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Jani Nikulabf13e812013-09-06 07:40:05 +0300694}
695
Imre Deak78597992016-06-16 16:37:20 +0300696void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300697{
Chris Wilson91c8a322016-07-05 10:40:23 +0100698 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300699 struct intel_encoder *encoder;
700
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100701 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200702 !IS_GEN9_LP(dev_priv)))
Ville Syrjälä773538e82014-09-04 14:54:56 +0300703 return;
704
705 /*
706 * We can't grab pps_mutex here due to deadlock with power_domain
707 * mutex when power_domain functions are called while holding pps_mutex.
708 * That also means that in order to use pps_pipe the code needs to
709 * hold both a power domain reference and pps_mutex, and the power domain
710 * reference get/put must be done while _not_ holding pps_mutex.
711 * pps_{lock,unlock}() do these steps in the correct order, so one
712 * should use them always.
713 */
714
Jani Nikula19c80542015-12-16 12:48:16 +0200715 for_each_intel_encoder(dev, encoder) {
Ville Syrjälä773538e82014-09-04 14:54:56 +0300716 struct intel_dp *intel_dp;
717
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200718 if (encoder->type != INTEL_OUTPUT_DP &&
719 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300720 continue;
721
722 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +0200723
724 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
725
726 if (encoder->type != INTEL_OUTPUT_EDP)
727 continue;
728
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200729 if (IS_GEN9_LP(dev_priv))
Imre Deak78597992016-06-16 16:37:20 +0300730 intel_dp->pps_reset = true;
731 else
732 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300733 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300734}
735
Imre Deak8e8232d2016-06-16 16:37:21 +0300736struct pps_registers {
737 i915_reg_t pp_ctrl;
738 i915_reg_t pp_stat;
739 i915_reg_t pp_on;
740 i915_reg_t pp_off;
741 i915_reg_t pp_div;
742};
743
744static void intel_pps_get_registers(struct drm_i915_private *dev_priv,
745 struct intel_dp *intel_dp,
746 struct pps_registers *regs)
747{
Imre Deak44cb7342016-08-10 14:07:29 +0300748 int pps_idx = 0;
749
Imre Deak8e8232d2016-06-16 16:37:21 +0300750 memset(regs, 0, sizeof(*regs));
751
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200752 if (IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300753 pps_idx = bxt_power_sequencer_idx(intel_dp);
754 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
755 pps_idx = vlv_power_sequencer_pipe(intel_dp);
Imre Deak8e8232d2016-06-16 16:37:21 +0300756
Imre Deak44cb7342016-08-10 14:07:29 +0300757 regs->pp_ctrl = PP_CONTROL(pps_idx);
758 regs->pp_stat = PP_STATUS(pps_idx);
759 regs->pp_on = PP_ON_DELAYS(pps_idx);
760 regs->pp_off = PP_OFF_DELAYS(pps_idx);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200761 if (!IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +0300762 regs->pp_div = PP_DIVISOR(pps_idx);
Imre Deak8e8232d2016-06-16 16:37:21 +0300763}
764
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200765static i915_reg_t
766_pp_ctrl_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300767{
Imre Deak8e8232d2016-06-16 16:37:21 +0300768 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300769
Imre Deak8e8232d2016-06-16 16:37:21 +0300770 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
771 &regs);
772
773 return regs.pp_ctrl;
Jani Nikulabf13e812013-09-06 07:40:05 +0300774}
775
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200776static i915_reg_t
777_pp_stat_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300778{
Imre Deak8e8232d2016-06-16 16:37:21 +0300779 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300780
Imre Deak8e8232d2016-06-16 16:37:21 +0300781 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
782 &regs);
783
784 return regs.pp_stat;
Jani Nikulabf13e812013-09-06 07:40:05 +0300785}
786
Clint Taylor01527b32014-07-07 13:01:46 -0700787/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
788 This function only applicable when panel PM state is not to be tracked */
789static int edp_notify_handler(struct notifier_block *this, unsigned long code,
790 void *unused)
791{
792 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
793 edp_notifier);
794 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100795 struct drm_i915_private *dev_priv = to_i915(dev);
Clint Taylor01527b32014-07-07 13:01:46 -0700796
797 if (!is_edp(intel_dp) || code != SYS_RESTART)
798 return 0;
799
Ville Syrjälä773538e82014-09-04 14:54:56 +0300800 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300801
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100802 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300803 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200804 i915_reg_t pp_ctrl_reg, pp_div_reg;
Ville Syrjälä649636e2015-09-22 19:50:01 +0300805 u32 pp_div;
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300806
Imre Deak44cb7342016-08-10 14:07:29 +0300807 pp_ctrl_reg = PP_CONTROL(pipe);
808 pp_div_reg = PP_DIVISOR(pipe);
Clint Taylor01527b32014-07-07 13:01:46 -0700809 pp_div = I915_READ(pp_div_reg);
810 pp_div &= PP_REFERENCE_DIVIDER_MASK;
811
812 /* 0x1F write to PP_DIV_REG sets max cycle delay */
813 I915_WRITE(pp_div_reg, pp_div | 0x1F);
814 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
815 msleep(intel_dp->panel_power_cycle_delay);
816 }
817
Ville Syrjälä773538e82014-09-04 14:54:56 +0300818 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300819
Clint Taylor01527b32014-07-07 13:01:46 -0700820 return 0;
821}
822
Daniel Vetter4be73782014-01-17 14:39:48 +0100823static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700824{
Paulo Zanoni30add222012-10-26 19:05:45 -0200825 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100826 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700827
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300828 lockdep_assert_held(&dev_priv->pps_mutex);
829
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100830 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300831 intel_dp->pps_pipe == INVALID_PIPE)
832 return false;
833
Jani Nikulabf13e812013-09-06 07:40:05 +0300834 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700835}
836
Daniel Vetter4be73782014-01-17 14:39:48 +0100837static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700838{
Paulo Zanoni30add222012-10-26 19:05:45 -0200839 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100840 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700841
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300842 lockdep_assert_held(&dev_priv->pps_mutex);
843
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100844 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300845 intel_dp->pps_pipe == INVALID_PIPE)
846 return false;
847
Ville Syrjälä773538e82014-09-04 14:54:56 +0300848 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700849}
850
Keith Packard9b984da2011-09-19 13:54:47 -0700851static void
852intel_dp_check_edp(struct intel_dp *intel_dp)
853{
Paulo Zanoni30add222012-10-26 19:05:45 -0200854 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100855 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700856
Keith Packard9b984da2011-09-19 13:54:47 -0700857 if (!is_edp(intel_dp))
858 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700859
Daniel Vetter4be73782014-01-17 14:39:48 +0100860 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700861 WARN(1, "eDP powered off while attempting aux channel communication.\n");
862 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300863 I915_READ(_pp_stat_reg(intel_dp)),
864 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700865 }
866}
867
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100868static uint32_t
869intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
870{
871 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
872 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100873 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200874 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100875 uint32_t status;
876 bool done;
877
Daniel Vetteref04f002012-12-01 21:03:59 +0100878#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100879 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300880 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300881 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100882 else
Imre Deak713a6b662016-06-28 13:37:33 +0300883 done = wait_for(C, 10) == 0;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100884 if (!done)
885 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
886 has_aux_irq);
887#undef C
888
889 return status;
890}
891
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200892static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000893{
894 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200895 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000896
Ville Syrjäläa457f542016-03-02 17:22:17 +0200897 if (index)
898 return 0;
899
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000900 /*
901 * The clock divider is based off the hrawclk, and would like to run at
Ville Syrjäläa457f542016-03-02 17:22:17 +0200902 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000903 */
Ville Syrjäläa457f542016-03-02 17:22:17 +0200904 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000905}
906
907static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
908{
909 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200910 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000911
912 if (index)
913 return 0;
914
Ville Syrjäläa457f542016-03-02 17:22:17 +0200915 /*
916 * The clock divider is based off the cdclk or PCH rawclk, and would
917 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
918 * divide by 2000 and use that
919 */
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200920 if (intel_dig_port->port == PORT_A)
Ville Syrjäläfce18c42015-11-30 16:23:46 +0200921 return DIV_ROUND_CLOSEST(dev_priv->cdclk_freq, 2000);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200922 else
923 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000924}
925
926static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300927{
928 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200929 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300930
Ville Syrjäläa457f542016-03-02 17:22:17 +0200931 if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300932 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100933 switch (index) {
934 case 0: return 63;
935 case 1: return 72;
936 default: return 0;
937 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300938 }
Ville Syrjäläa457f542016-03-02 17:22:17 +0200939
940 return ilk_get_aux_clock_divider(intel_dp, index);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300941}
942
Damien Lespiaub6b5e382014-01-20 16:00:59 +0000943static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
944{
945 /*
946 * SKL doesn't need us to program the AUX clock divider (Hardware will
947 * derive the clock from CDCLK automatically). We still implement the
948 * get_aux_clock_divider vfunc to plug-in into the existing code.
949 */
950 return index ? 0 : 1;
951}
952
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200953static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
954 bool has_aux_irq,
955 int send_bytes,
956 uint32_t aux_clock_divider)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000957{
958 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100959 struct drm_i915_private *dev_priv =
960 to_i915(intel_dig_port->base.base.dev);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000961 uint32_t precharge, timeout;
962
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100963 if (IS_GEN6(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000964 precharge = 3;
965 else
966 precharge = 5;
967
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100968 if (IS_BROADWELL(dev_priv) && intel_dig_port->port == PORT_A)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000969 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
970 else
971 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
972
973 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +0000974 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000975 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000976 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000977 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +0000978 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000979 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
980 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000981 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000982}
983
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000984static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
985 bool has_aux_irq,
986 int send_bytes,
987 uint32_t unused)
988{
989 return DP_AUX_CH_CTL_SEND_BUSY |
990 DP_AUX_CH_CTL_DONE |
991 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
992 DP_AUX_CH_CTL_TIME_OUT_ERROR |
993 DP_AUX_CH_CTL_TIME_OUT_1600us |
994 DP_AUX_CH_CTL_RECEIVE_ERROR |
995 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Daniel Vetterd4dcbdc2016-05-18 18:47:15 +0200996 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000997 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
998}
999
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001000static int
Chris Wilsonea5b2132010-08-04 13:50:23 +01001001intel_dp_aux_ch(struct intel_dp *intel_dp,
Daniel Vetterbd9f74a2014-10-02 09:45:35 +02001002 const uint8_t *send, int send_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001003 uint8_t *recv, int recv_size)
1004{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001005 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001006 struct drm_i915_private *dev_priv =
1007 to_i915(intel_dig_port->base.base.dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001008 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Chris Wilsonbc866252013-07-21 16:00:03 +01001009 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001010 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001011 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001012 int try, clock = 0;
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +00001013 bool has_aux_irq = HAS_AUX_IRQ(dev_priv);
Jani Nikula884f19e2014-03-14 16:51:14 +02001014 bool vdd;
1015
Ville Syrjälä773538e82014-09-04 14:54:56 +03001016 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001017
Ville Syrjälä72c35002014-08-18 22:16:00 +03001018 /*
1019 * We will be called with VDD already enabled for dpcd/edid/oui reads.
1020 * In such cases we want to leave VDD enabled and it's up to upper layers
1021 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
1022 * ourselves.
1023 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001024 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001025
1026 /* dp aux is extremely sensitive to irq latency, hence request the
1027 * lowest possible wakeup latency and so prevent the cpu from going into
1028 * deep sleep states.
1029 */
1030 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001031
Keith Packard9b984da2011-09-19 13:54:47 -07001032 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08001033
Jesse Barnes11bee432011-08-01 15:02:20 -07001034 /* Try to wait for any previous AUX channel activity */
1035 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +01001036 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -07001037 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
1038 break;
1039 msleep(1);
1040 }
1041
1042 if (try == 3) {
Mika Kuoppala02196c72015-08-06 16:48:58 +03001043 static u32 last_status = -1;
1044 const u32 status = I915_READ(ch_ctl);
1045
1046 if (status != last_status) {
1047 WARN(1, "dp_aux_ch not started status 0x%08x\n",
1048 status);
1049 last_status = status;
1050 }
1051
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001052 ret = -EBUSY;
1053 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001054 }
1055
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001056 /* Only 5 data registers! */
1057 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
1058 ret = -E2BIG;
1059 goto out;
1060 }
1061
Damien Lespiauec5b01d2014-01-21 13:35:39 +00001062 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +00001063 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
1064 has_aux_irq,
1065 send_bytes,
1066 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001067
Chris Wilsonbc866252013-07-21 16:00:03 +01001068 /* Must try at least 3 times according to DP spec */
1069 for (try = 0; try < 5; try++) {
1070 /* Load the send data into the aux channel data registers */
1071 for (i = 0; i < send_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001072 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001073 intel_dp_pack_aux(send + i,
1074 send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -04001075
Chris Wilsonbc866252013-07-21 16:00:03 +01001076 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001077 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001078
Chris Wilsonbc866252013-07-21 16:00:03 +01001079 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -04001080
Chris Wilsonbc866252013-07-21 16:00:03 +01001081 /* Clear done status and any errors */
1082 I915_WRITE(ch_ctl,
1083 status |
1084 DP_AUX_CH_CTL_DONE |
1085 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1086 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -04001087
Todd Previte74ebf292015-04-15 08:38:41 -07001088 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
Chris Wilsonbc866252013-07-21 16:00:03 +01001089 continue;
Todd Previte74ebf292015-04-15 08:38:41 -07001090
1091 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
1092 * 400us delay required for errors and timeouts
1093 * Timeout errors from the HW already meet this
1094 * requirement so skip to next iteration
1095 */
1096 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1097 usleep_range(400, 500);
1098 continue;
1099 }
Chris Wilsonbc866252013-07-21 16:00:03 +01001100 if (status & DP_AUX_CH_CTL_DONE)
Jim Bridee058c942015-05-27 10:21:48 -07001101 goto done;
Chris Wilsonbc866252013-07-21 16:00:03 +01001102 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001103 }
1104
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001105 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001106 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001107 ret = -EBUSY;
1108 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001109 }
1110
Jim Bridee058c942015-05-27 10:21:48 -07001111done:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001112 /* Check for timeout or receive error.
1113 * Timeouts occur when the sink is not connected
1114 */
Keith Packarda5b3da52009-06-11 22:30:32 -07001115 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001116 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001117 ret = -EIO;
1118 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -07001119 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001120
1121 /* Timeouts occur when the device isn't connected, so they're
1122 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -07001123 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Zhao Yakui28c97732009-10-09 11:39:41 +08001124 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001125 ret = -ETIMEDOUT;
1126 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001127 }
1128
1129 /* Unload any bytes sent back from the other side */
1130 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
1131 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Rodrigo Vivi14e01882015-12-10 11:12:27 -08001132
1133 /*
1134 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1135 * We have no idea of what happened so we return -EBUSY so
1136 * drm layer takes care for the necessary retries.
1137 */
1138 if (recv_bytes == 0 || recv_bytes > 20) {
1139 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1140 recv_bytes);
1141 /*
1142 * FIXME: This patch was created on top of a series that
1143 * organize the retries at drm level. There EBUSY should
1144 * also take care for 1ms wait before retrying.
1145 * That aux retries re-org is still needed and after that is
1146 * merged we remove this sleep from here.
1147 */
1148 usleep_range(1000, 1500);
1149 ret = -EBUSY;
1150 goto out;
1151 }
1152
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001153 if (recv_bytes > recv_size)
1154 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -04001155
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001156 for (i = 0; i < recv_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001157 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001158 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001159
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001160 ret = recv_bytes;
1161out:
1162 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1163
Jani Nikula884f19e2014-03-14 16:51:14 +02001164 if (vdd)
1165 edp_panel_vdd_off(intel_dp, false);
1166
Ville Syrjälä773538e82014-09-04 14:54:56 +03001167 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001168
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001169 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001170}
1171
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001172#define BARE_ADDRESS_SIZE 3
1173#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +02001174static ssize_t
1175intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001176{
Jani Nikula9d1a1032014-03-14 16:51:15 +02001177 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1178 uint8_t txbuf[20], rxbuf[20];
1179 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001180 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001181
Ville Syrjäläd2d9cbb2015-03-19 11:44:06 +02001182 txbuf[0] = (msg->request << 4) |
1183 ((msg->address >> 16) & 0xf);
1184 txbuf[1] = (msg->address >> 8) & 0xff;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001185 txbuf[2] = msg->address & 0xff;
1186 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001187
Jani Nikula9d1a1032014-03-14 16:51:15 +02001188 switch (msg->request & ~DP_AUX_I2C_MOT) {
1189 case DP_AUX_NATIVE_WRITE:
1190 case DP_AUX_I2C_WRITE:
Ville Syrjäläc1e741222015-08-27 17:23:27 +03001191 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001192 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001193 rxsize = 2; /* 0 or 1 data bytes */
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001194
Jani Nikula9d1a1032014-03-14 16:51:15 +02001195 if (WARN_ON(txsize > 20))
1196 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001197
Ville Syrjälädd788092016-07-28 17:55:04 +03001198 WARN_ON(!msg->buffer != !msg->size);
1199
Imre Deakd81a67c2016-01-29 14:52:26 +02001200 if (msg->buffer)
1201 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001202
Jani Nikula9d1a1032014-03-14 16:51:15 +02001203 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1204 if (ret > 0) {
1205 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001206
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001207 if (ret > 1) {
1208 /* Number of bytes written in a short write. */
1209 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1210 } else {
1211 /* Return payload size. */
1212 ret = msg->size;
1213 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001214 }
Jani Nikula9d1a1032014-03-14 16:51:15 +02001215 break;
1216
1217 case DP_AUX_NATIVE_READ:
1218 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001219 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001220 rxsize = msg->size + 1;
1221
1222 if (WARN_ON(rxsize > 20))
1223 return -E2BIG;
1224
1225 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1226 if (ret > 0) {
1227 msg->reply = rxbuf[0] >> 4;
1228 /*
1229 * Assume happy day, and copy the data. The caller is
1230 * expected to check msg->reply before touching it.
1231 *
1232 * Return payload size.
1233 */
1234 ret--;
1235 memcpy(msg->buffer, rxbuf + 1, ret);
1236 }
1237 break;
1238
1239 default:
1240 ret = -EINVAL;
1241 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001242 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001243
Jani Nikula9d1a1032014-03-14 16:51:15 +02001244 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001245}
1246
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001247static enum port intel_aux_port(struct drm_i915_private *dev_priv,
1248 enum port port)
1249{
1250 const struct ddi_vbt_port_info *info =
1251 &dev_priv->vbt.ddi_port_info[port];
1252 enum port aux_port;
1253
1254 if (!info->alternate_aux_channel) {
1255 DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
1256 port_name(port), port_name(port));
1257 return port;
1258 }
1259
1260 switch (info->alternate_aux_channel) {
1261 case DP_AUX_A:
1262 aux_port = PORT_A;
1263 break;
1264 case DP_AUX_B:
1265 aux_port = PORT_B;
1266 break;
1267 case DP_AUX_C:
1268 aux_port = PORT_C;
1269 break;
1270 case DP_AUX_D:
1271 aux_port = PORT_D;
1272 break;
1273 default:
1274 MISSING_CASE(info->alternate_aux_channel);
1275 aux_port = PORT_A;
1276 break;
1277 }
1278
1279 DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
1280 port_name(aux_port), port_name(port));
1281
1282 return aux_port;
1283}
1284
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001285static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001286 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001287{
1288 switch (port) {
1289 case PORT_B:
1290 case PORT_C:
1291 case PORT_D:
1292 return DP_AUX_CH_CTL(port);
1293 default:
1294 MISSING_CASE(port);
1295 return DP_AUX_CH_CTL(PORT_B);
1296 }
1297}
1298
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001299static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001300 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001301{
1302 switch (port) {
1303 case PORT_B:
1304 case PORT_C:
1305 case PORT_D:
1306 return DP_AUX_CH_DATA(port, index);
1307 default:
1308 MISSING_CASE(port);
1309 return DP_AUX_CH_DATA(PORT_B, index);
1310 }
1311}
1312
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001313static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001314 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001315{
1316 switch (port) {
1317 case PORT_A:
1318 return DP_AUX_CH_CTL(port);
1319 case PORT_B:
1320 case PORT_C:
1321 case PORT_D:
1322 return PCH_DP_AUX_CH_CTL(port);
1323 default:
1324 MISSING_CASE(port);
1325 return DP_AUX_CH_CTL(PORT_A);
1326 }
1327}
1328
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001329static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001330 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001331{
1332 switch (port) {
1333 case PORT_A:
1334 return DP_AUX_CH_DATA(port, index);
1335 case PORT_B:
1336 case PORT_C:
1337 case PORT_D:
1338 return PCH_DP_AUX_CH_DATA(port, index);
1339 default:
1340 MISSING_CASE(port);
1341 return DP_AUX_CH_DATA(PORT_A, index);
1342 }
1343}
1344
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001345static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001346 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001347{
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001348 switch (port) {
1349 case PORT_A:
1350 case PORT_B:
1351 case PORT_C:
1352 case PORT_D:
1353 return DP_AUX_CH_CTL(port);
1354 default:
1355 MISSING_CASE(port);
1356 return DP_AUX_CH_CTL(PORT_A);
1357 }
1358}
1359
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001360static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001361 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001362{
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001363 switch (port) {
1364 case PORT_A:
1365 case PORT_B:
1366 case PORT_C:
1367 case PORT_D:
1368 return DP_AUX_CH_DATA(port, index);
1369 default:
1370 MISSING_CASE(port);
1371 return DP_AUX_CH_DATA(PORT_A, index);
1372 }
1373}
1374
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001375static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001376 enum port port)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001377{
1378 if (INTEL_INFO(dev_priv)->gen >= 9)
1379 return skl_aux_ctl_reg(dev_priv, port);
1380 else if (HAS_PCH_SPLIT(dev_priv))
1381 return ilk_aux_ctl_reg(dev_priv, port);
1382 else
1383 return g4x_aux_ctl_reg(dev_priv, port);
1384}
1385
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001386static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001387 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001388{
1389 if (INTEL_INFO(dev_priv)->gen >= 9)
1390 return skl_aux_data_reg(dev_priv, port, index);
1391 else if (HAS_PCH_SPLIT(dev_priv))
1392 return ilk_aux_data_reg(dev_priv, port, index);
1393 else
1394 return g4x_aux_data_reg(dev_priv, port, index);
1395}
1396
1397static void intel_aux_reg_init(struct intel_dp *intel_dp)
1398{
1399 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001400 enum port port = intel_aux_port(dev_priv,
1401 dp_to_dig_port(intel_dp)->port);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001402 int i;
1403
1404 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1405 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1406 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1407}
1408
Jani Nikula9d1a1032014-03-14 16:51:15 +02001409static void
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001410intel_dp_aux_fini(struct intel_dp *intel_dp)
1411{
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001412 kfree(intel_dp->aux.name);
1413}
1414
Chris Wilson7a418e32016-06-24 14:00:14 +01001415static void
Mika Kaholab6339582016-09-09 14:10:52 +03001416intel_dp_aux_init(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001417{
Jani Nikula33ad6622014-03-14 16:51:16 +02001418 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1419 enum port port = intel_dig_port->port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001420
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001421 intel_aux_reg_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01001422 drm_dp_aux_init(&intel_dp->aux);
David Flynn8316f332010-12-08 16:10:21 +00001423
Chris Wilson7a418e32016-06-24 14:00:14 +01001424 /* Failure to allocate our preferred name is not critical */
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001425 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
Jani Nikula9d1a1032014-03-14 16:51:15 +02001426 intel_dp->aux.transfer = intel_dp_aux_transfer;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001427}
1428
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001429bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301430{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001431 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Navare, Manasi D577c5432016-09-27 16:36:53 -07001432 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001433
Navare, Manasi D577c5432016-09-27 16:36:53 -07001434 if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
1435 IS_BROADWELL(dev_priv) || (INTEL_GEN(dev_priv) >= 9))
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301436 return true;
1437 else
1438 return false;
1439}
1440
Daniel Vetter0e503382014-07-04 11:26:04 -03001441static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001442intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001443 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001444{
1445 struct drm_device *dev = encoder->base.dev;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001446 struct drm_i915_private *dev_priv = to_i915(dev);
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001447 const struct dp_link_dpll *divisor = NULL;
1448 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001449
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001450 if (IS_G4X(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001451 divisor = gen4_dpll;
1452 count = ARRAY_SIZE(gen4_dpll);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001453 } else if (HAS_PCH_SPLIT(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001454 divisor = pch_dpll;
1455 count = ARRAY_SIZE(pch_dpll);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001456 } else if (IS_CHERRYVIEW(dev_priv)) {
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001457 divisor = chv_dpll;
1458 count = ARRAY_SIZE(chv_dpll);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001459 } else if (IS_VALLEYVIEW(dev_priv)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001460 divisor = vlv_dpll;
1461 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001462 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001463
1464 if (divisor && count) {
1465 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001466 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001467 pipe_config->dpll = divisor[i].dpll;
1468 pipe_config->clock_set = true;
1469 break;
1470 }
1471 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001472 }
1473}
1474
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001475static void snprintf_int_array(char *str, size_t len,
1476 const int *array, int nelem)
1477{
1478 int i;
1479
1480 str[0] = '\0';
1481
1482 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001483 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001484 if (r >= len)
1485 return;
1486 str += r;
1487 len -= r;
1488 }
1489}
1490
1491static void intel_dp_print_rates(struct intel_dp *intel_dp)
1492{
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001493 const int *source_rates, *sink_rates;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001494 int source_len, sink_len, common_len;
1495 int common_rates[DP_MAX_SUPPORTED_RATES];
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001496 char str[128]; /* FIXME: too big for stack? */
1497
1498 if ((drm_debug & DRM_UT_KMS) == 0)
1499 return;
1500
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001501 source_len = intel_dp_source_rates(intel_dp, &source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001502 snprintf_int_array(str, sizeof(str), source_rates, source_len);
1503 DRM_DEBUG_KMS("source rates: %s\n", str);
1504
1505 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
1506 snprintf_int_array(str, sizeof(str), sink_rates, sink_len);
1507 DRM_DEBUG_KMS("sink rates: %s\n", str);
1508
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001509 common_len = intel_dp_common_rates(intel_dp, common_rates);
1510 snprintf_int_array(str, sizeof(str), common_rates, common_len);
1511 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001512}
1513
Imre Deak489375c2016-10-24 19:33:31 +03001514bool
Imre Deak7b3fc172016-10-25 16:12:39 +03001515__intel_dp_read_desc(struct intel_dp *intel_dp, struct intel_dp_desc *desc)
Mika Kahola0e390a32016-09-09 14:10:53 +03001516{
Imre Deak7b3fc172016-10-25 16:12:39 +03001517 u32 base = drm_dp_is_branch(intel_dp->dpcd) ? DP_BRANCH_OUI :
1518 DP_SINK_OUI;
Mika Kahola0e390a32016-09-09 14:10:53 +03001519
Imre Deak7b3fc172016-10-25 16:12:39 +03001520 return drm_dp_dpcd_read(&intel_dp->aux, base, desc, sizeof(*desc)) ==
1521 sizeof(*desc);
Mika Kahola0e390a32016-09-09 14:10:53 +03001522}
1523
Imre Deak12a47a422016-10-24 19:33:29 +03001524bool intel_dp_read_desc(struct intel_dp *intel_dp)
Mika Kahola1a2724f2016-09-09 14:10:54 +03001525{
Imre Deak7b3fc172016-10-25 16:12:39 +03001526 struct intel_dp_desc *desc = &intel_dp->desc;
1527 bool oui_sup = intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] &
1528 DP_OUI_SUPPORT;
1529 int dev_id_len;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001530
Imre Deak7b3fc172016-10-25 16:12:39 +03001531 if (!__intel_dp_read_desc(intel_dp, desc))
1532 return false;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001533
Imre Deak7b3fc172016-10-25 16:12:39 +03001534 dev_id_len = strnlen(desc->device_id, sizeof(desc->device_id));
1535 DRM_DEBUG_KMS("DP %s: OUI %*phD%s dev-ID %*pE HW-rev %d.%d SW-rev %d.%d\n",
1536 drm_dp_is_branch(intel_dp->dpcd) ? "branch" : "sink",
1537 (int)sizeof(desc->oui), desc->oui, oui_sup ? "" : "(NS)",
1538 dev_id_len, desc->device_id,
1539 desc->hw_rev >> 4, desc->hw_rev & 0xf,
1540 desc->sw_major_rev, desc->sw_minor_rev);
Mika Kahola1a2724f2016-09-09 14:10:54 +03001541
Imre Deak7b3fc172016-10-25 16:12:39 +03001542 return true;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001543}
1544
Ville Syrjäläf4896f12015-03-12 17:10:27 +02001545static int rate_to_index(int find, const int *rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301546{
1547 int i = 0;
1548
1549 for (i = 0; i < DP_MAX_SUPPORTED_RATES; ++i)
1550 if (find == rates[i])
1551 break;
1552
1553 return i;
1554}
1555
Ville Syrjälä50fec212015-03-12 17:10:34 +02001556int
1557intel_dp_max_link_rate(struct intel_dp *intel_dp)
1558{
1559 int rates[DP_MAX_SUPPORTED_RATES] = {};
1560 int len;
1561
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001562 len = intel_dp_common_rates(intel_dp, rates);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001563 if (WARN_ON(len <= 0))
1564 return 162000;
1565
Ville Syrjälä1354f732016-07-28 17:50:45 +03001566 return rates[len - 1];
Ville Syrjälä50fec212015-03-12 17:10:34 +02001567}
1568
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001569int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1570{
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001571 return rate_to_index(rate, intel_dp->sink_rates);
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001572}
1573
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001574void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1575 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001576{
1577 if (intel_dp->num_sink_rates) {
1578 *link_bw = 0;
1579 *rate_select =
1580 intel_dp_rate_select(intel_dp, port_clock);
1581 } else {
1582 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1583 *rate_select = 0;
1584 }
1585}
1586
Jani Nikulaf580bea2016-09-15 16:28:52 +03001587static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1588 struct intel_crtc_state *pipe_config)
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001589{
1590 int bpp, bpc;
1591
1592 bpp = pipe_config->pipe_bpp;
1593 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1594
1595 if (bpc > 0)
1596 bpp = min(bpp, 3*bpc);
1597
Manasi Navare611032b2017-01-24 08:21:49 -08001598 /* For DP Compliance we override the computed bpp for the pipe */
1599 if (intel_dp->compliance.test_data.bpc != 0) {
1600 pipe_config->pipe_bpp = 3*intel_dp->compliance.test_data.bpc;
1601 pipe_config->dither_force_disable = pipe_config->pipe_bpp == 6*3;
1602 DRM_DEBUG_KMS("Setting pipe_bpp to %d\n",
1603 pipe_config->pipe_bpp);
1604 }
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001605 return bpp;
1606}
1607
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001608bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001609intel_dp_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001610 struct intel_crtc_state *pipe_config,
1611 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001612{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001613 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001614 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001615 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001616 enum port port = dp_to_dig_port(intel_dp)->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001617 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001618 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001619 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001620 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001621 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001622 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001623 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301624 int max_clock;
Manasi Navareda15f7c2017-01-24 08:16:34 -08001625 int link_rate_index;
Daniel Vetter083f9562012-04-20 20:23:49 +02001626 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001627 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001628 int common_rates[DP_MAX_SUPPORTED_RATES] = {};
1629 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001630 uint8_t link_bw, rate_select;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301631
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001632 common_len = intel_dp_common_rates(intel_dp, common_rates);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301633
1634 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001635 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301636
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001637 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001638
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001639 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001640 pipe_config->has_pch_encoder = true;
1641
Vandana Kannanf769cd22014-08-05 07:51:22 -07001642 pipe_config->has_drrs = false;
Jani Nikula9fcb1702015-05-05 16:32:12 +03001643 pipe_config->has_audio = intel_dp->has_audio && port != PORT_A;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001644
Jani Nikuladd06f902012-10-19 14:51:50 +03001645 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1646 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
1647 adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001648
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00001649 if (INTEL_GEN(dev_priv) >= 9) {
Chandra Kondurua1b22782015-04-07 15:28:45 -07001650 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001651 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001652 if (ret)
1653 return ret;
1654 }
1655
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001656 if (HAS_GMCH_DISPLAY(dev_priv))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001657 intel_gmch_panel_fitting(intel_crtc, pipe_config,
1658 intel_connector->panel.fitting_mode);
1659 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001660 intel_pch_panel_fitting(intel_crtc, pipe_config,
1661 intel_connector->panel.fitting_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001662 }
1663
Daniel Vettercb1793c2012-06-04 18:39:21 +02001664 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001665 return false;
1666
Manasi Navareda15f7c2017-01-24 08:16:34 -08001667 /* Use values requested by Compliance Test Request */
1668 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
1669 link_rate_index = intel_dp_link_rate_index(intel_dp,
1670 common_rates,
1671 intel_dp->compliance.test_link_rate);
1672 if (link_rate_index >= 0)
1673 min_clock = max_clock = link_rate_index;
1674 min_lane_count = max_lane_count = intel_dp->compliance.test_lane_count;
1675 }
Daniel Vetter083f9562012-04-20 20:23:49 +02001676 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301677 "max bw %d pixel clock %iKHz\n",
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001678 max_lane_count, common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001679 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001680
Daniel Vetter36008362013-03-27 00:44:59 +01001681 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1682 * bpc in between. */
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001683 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
Jani Nikula56071a22014-05-06 14:56:52 +03001684 if (is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301685
1686 /* Get bpp from vbt only for panels that dont have bpp in edid */
1687 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001688 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001689 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001690 dev_priv->vbt.edp.bpp);
1691 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001692 }
1693
Jani Nikula344c5bb2014-09-09 11:25:13 +03001694 /*
1695 * Use the maximum clock and number of lanes the eDP panel
1696 * advertizes being capable of. The panels are generally
1697 * designed to support only a single clock and lane
1698 * configuration, and typically these values correspond to the
1699 * native resolution of the panel.
1700 */
1701 min_lane_count = max_lane_count;
1702 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001703 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001704
Daniel Vetter36008362013-03-27 00:44:59 +01001705 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001706 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1707 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001708
Dave Airliec6930992014-07-14 11:04:39 +10001709 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301710 for (lane_count = min_lane_count;
1711 lane_count <= max_lane_count;
1712 lane_count <<= 1) {
1713
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001714 link_clock = common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001715 link_avail = intel_dp_max_data_rate(link_clock,
1716 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001717
Daniel Vetter36008362013-03-27 00:44:59 +01001718 if (mode_rate <= link_avail) {
1719 goto found;
1720 }
1721 }
1722 }
1723 }
1724
1725 return false;
1726
1727found:
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001728 if (intel_dp->color_range_auto) {
1729 /*
1730 * See:
1731 * CEA-861-E - 5.1 Default Encoding Parameters
1732 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1733 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001734 pipe_config->limited_color_range =
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02001735 bpp != 18 &&
1736 drm_default_rgb_quant_range(adjusted_mode) ==
1737 HDMI_QUANTIZATION_RANGE_LIMITED;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001738 } else {
1739 pipe_config->limited_color_range =
1740 intel_dp->limited_color_range;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001741 }
1742
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001743 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301744
Daniel Vetter657445f2013-05-04 10:09:18 +02001745 pipe_config->pipe_bpp = bpp;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001746 pipe_config->port_clock = common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001747
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001748 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1749 &link_bw, &rate_select);
1750
1751 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1752 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001753 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001754 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1755 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001756
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001757 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001758 adjusted_mode->crtc_clock,
1759 pipe_config->port_clock,
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001760 &pipe_config->dp_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001761
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301762 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301763 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001764 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301765 intel_link_compute_m_n(bpp, lane_count,
1766 intel_connector->panel.downclock_mode->clock,
1767 pipe_config->port_clock,
1768 &pipe_config->dp_m2_n2);
1769 }
1770
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001771 /*
1772 * DPLL0 VCO may need to be adjusted to get the correct
1773 * clock for eDP. This will affect cdclk as well.
1774 */
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001775 if (is_edp(intel_dp) && IS_GEN9_BC(dev_priv)) {
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001776 int vco;
1777
1778 switch (pipe_config->port_clock / 2) {
1779 case 108000:
1780 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001781 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001782 break;
1783 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001784 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001785 break;
1786 }
1787
1788 to_intel_atomic_state(pipe_config->base.state)->cdclk_pll_vco = vco;
1789 }
1790
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001791 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001792 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001793
Daniel Vetter36008362013-03-27 00:44:59 +01001794 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001795}
1796
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001797void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001798 int link_rate, uint8_t lane_count,
1799 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001800{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001801 intel_dp->link_rate = link_rate;
1802 intel_dp->lane_count = lane_count;
1803 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001804}
1805
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001806static void intel_dp_prepare(struct intel_encoder *encoder,
1807 struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001808{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001809 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001810 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001811 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001812 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001813 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001814 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001815
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001816 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1817 pipe_config->lane_count,
1818 intel_crtc_has_type(pipe_config,
1819 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001820
Keith Packard417e8222011-11-01 19:54:11 -07001821 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001822 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001823 *
1824 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001825 * SNB CPU
1826 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001827 * CPT PCH
1828 *
1829 * IBX PCH and CPU are the same for almost everything,
1830 * except that the CPU DP PLL is configured in this
1831 * register
1832 *
1833 * CPT PCH is quite different, having many bits moved
1834 * to the TRANS_DP_CTL register instead. That
1835 * configuration happens (oddly) in ironlake_pch_enable
1836 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001837
Keith Packard417e8222011-11-01 19:54:11 -07001838 /* Preserve the BIOS-computed detected bit. This is
1839 * supposed to be read-only.
1840 */
1841 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001842
Keith Packard417e8222011-11-01 19:54:11 -07001843 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001844 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001845 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001846
Keith Packard417e8222011-11-01 19:54:11 -07001847 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001848
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001849 if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001850 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1851 intel_dp->DP |= DP_SYNC_HS_HIGH;
1852 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1853 intel_dp->DP |= DP_SYNC_VS_HIGH;
1854 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1855
Jani Nikula6aba5b62013-10-04 15:08:10 +03001856 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001857 intel_dp->DP |= DP_ENHANCED_FRAMING;
1858
Daniel Vetter7c62a162013-06-01 17:16:20 +02001859 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001860 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001861 u32 trans_dp;
1862
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001863 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001864
1865 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1866 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1867 trans_dp |= TRANS_DP_ENH_FRAMING;
1868 else
1869 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1870 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001871 } else {
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02001872 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001873 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001874
1875 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1876 intel_dp->DP |= DP_SYNC_HS_HIGH;
1877 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1878 intel_dp->DP |= DP_SYNC_VS_HIGH;
1879 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1880
Jani Nikula6aba5b62013-10-04 15:08:10 +03001881 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001882 intel_dp->DP |= DP_ENHANCED_FRAMING;
1883
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001884 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001885 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001886 else if (crtc->pipe == PIPE_B)
1887 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001888 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001889}
1890
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001891#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1892#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001893
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001894#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1895#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001896
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001897#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1898#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001899
Imre Deakde9c1b62016-06-16 20:01:46 +03001900static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
1901 struct intel_dp *intel_dp);
1902
Daniel Vetter4be73782014-01-17 14:39:48 +01001903static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001904 u32 mask,
1905 u32 value)
1906{
Paulo Zanoni30add222012-10-26 19:05:45 -02001907 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001908 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001909 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001910
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001911 lockdep_assert_held(&dev_priv->pps_mutex);
1912
Imre Deakde9c1b62016-06-16 20:01:46 +03001913 intel_pps_verify_state(dev_priv, intel_dp);
1914
Jani Nikulabf13e812013-09-06 07:40:05 +03001915 pp_stat_reg = _pp_stat_reg(intel_dp);
1916 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001917
1918 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001919 mask, value,
1920 I915_READ(pp_stat_reg),
1921 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001922
Chris Wilson9036ff02016-06-30 15:33:09 +01001923 if (intel_wait_for_register(dev_priv,
1924 pp_stat_reg, mask, value,
1925 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001926 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001927 I915_READ(pp_stat_reg),
1928 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001929
1930 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001931}
1932
Daniel Vetter4be73782014-01-17 14:39:48 +01001933static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001934{
1935 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001936 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001937}
1938
Daniel Vetter4be73782014-01-17 14:39:48 +01001939static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001940{
Keith Packardbd943152011-09-18 23:09:52 -07001941 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001942 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001943}
Keith Packardbd943152011-09-18 23:09:52 -07001944
Daniel Vetter4be73782014-01-17 14:39:48 +01001945static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001946{
Abhay Kumard28d4732016-01-22 17:39:04 -08001947 ktime_t panel_power_on_time;
1948 s64 panel_power_off_duration;
1949
Keith Packard99ea7122011-11-01 19:57:50 -07001950 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001951
Abhay Kumard28d4732016-01-22 17:39:04 -08001952 /* take the difference of currrent time and panel power off time
1953 * and then make panel wait for t11_t12 if needed. */
1954 panel_power_on_time = ktime_get_boottime();
1955 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1956
Paulo Zanonidce56b32013-12-19 14:29:40 -02001957 /* When we disable the VDD override bit last we have to do the manual
1958 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08001959 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
1960 wait_remaining_ms_from_jiffies(jiffies,
1961 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001962
Daniel Vetter4be73782014-01-17 14:39:48 +01001963 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001964}
Keith Packardbd943152011-09-18 23:09:52 -07001965
Daniel Vetter4be73782014-01-17 14:39:48 +01001966static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001967{
1968 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1969 intel_dp->backlight_on_delay);
1970}
1971
Daniel Vetter4be73782014-01-17 14:39:48 +01001972static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001973{
1974 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
1975 intel_dp->backlight_off_delay);
1976}
Keith Packard99ea7122011-11-01 19:57:50 -07001977
Keith Packard832dd3c2011-11-01 19:34:06 -07001978/* Read the current pp_control value, unlocking the register if it
1979 * is locked
1980 */
1981
Jesse Barnes453c5422013-03-28 09:55:41 -07001982static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07001983{
Jesse Barnes453c5422013-03-28 09:55:41 -07001984 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001985 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07001986 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07001987
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001988 lockdep_assert_held(&dev_priv->pps_mutex);
1989
Jani Nikulabf13e812013-09-06 07:40:05 +03001990 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03001991 if (WARN_ON(!HAS_DDI(dev_priv) &&
1992 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05301993 control &= ~PANEL_UNLOCK_MASK;
1994 control |= PANEL_UNLOCK_REGS;
1995 }
Keith Packard832dd3c2011-11-01 19:34:06 -07001996 return control;
Keith Packardbd943152011-09-18 23:09:52 -07001997}
1998
Ville Syrjälä951468f2014-09-04 14:55:31 +03001999/*
2000 * Must be paired with edp_panel_vdd_off().
2001 * Must hold pps_mutex around the whole on/off sequence.
2002 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2003 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03002004static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002005{
Paulo Zanoni30add222012-10-26 19:05:45 -02002006 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002007 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2008 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002009 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002010 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08002011 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002012 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002013 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08002014
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002015 lockdep_assert_held(&dev_priv->pps_mutex);
2016
Keith Packard97af61f572011-09-28 16:23:51 -07002017 if (!is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002018 return false;
Keith Packardbd943152011-09-18 23:09:52 -07002019
Egbert Eich2c623c12014-11-25 12:54:57 +01002020 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002021 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07002022
Daniel Vetter4be73782014-01-17 14:39:48 +01002023 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002024 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002025
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002026 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002027 intel_display_power_get(dev_priv, power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002028
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002029 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
2030 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07002031
Daniel Vetter4be73782014-01-17 14:39:48 +01002032 if (!edp_have_panel_power(intel_dp))
2033 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07002034
Jesse Barnes453c5422013-03-28 09:55:41 -07002035 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002036 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07002037
Jani Nikulabf13e812013-09-06 07:40:05 +03002038 pp_stat_reg = _pp_stat_reg(intel_dp);
2039 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002040
2041 I915_WRITE(pp_ctrl_reg, pp);
2042 POSTING_READ(pp_ctrl_reg);
2043 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2044 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07002045 /*
2046 * If the panel wasn't on, delay before accessing aux channel
2047 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002048 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002049 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
2050 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07002051 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07002052 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002053
2054 return need_to_disable;
2055}
2056
Ville Syrjälä951468f2014-09-04 14:55:31 +03002057/*
2058 * Must be paired with intel_edp_panel_vdd_off() or
2059 * intel_edp_panel_off().
2060 * Nested calls to these functions are not allowed since
2061 * we drop the lock. Caller must use some higher level
2062 * locking to prevent nested calls from other threads.
2063 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01002064void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002065{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002066 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02002067
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002068 if (!is_edp(intel_dp))
2069 return;
2070
Ville Syrjälä773538e82014-09-04 14:54:56 +03002071 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002072 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002073 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03002074
Rob Clarke2c719b2014-12-15 13:56:32 -05002075 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002076 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08002077}
2078
Daniel Vetter4be73782014-01-17 14:39:48 +01002079static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002080{
Paulo Zanoni30add222012-10-26 19:05:45 -02002081 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002082 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002083 struct intel_digital_port *intel_dig_port =
2084 dp_to_dig_port(intel_dp);
2085 struct intel_encoder *intel_encoder = &intel_dig_port->base;
2086 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08002087 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002088 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002089
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002090 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002091
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002092 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002093
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002094 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002095 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002096
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002097 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2098 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002099
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002100 pp = ironlake_get_pp_control(intel_dp);
2101 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002102
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002103 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2104 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002105
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002106 I915_WRITE(pp_ctrl_reg, pp);
2107 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002108
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002109 /* Make sure sequencer is idle before allowing subsequent activity */
2110 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2111 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002112
Imre Deak5a162e22016-08-10 14:07:30 +03002113 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002114 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002115
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002116 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002117 intel_display_power_put(dev_priv, power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002118}
2119
Daniel Vetter4be73782014-01-17 14:39:48 +01002120static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002121{
2122 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2123 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002124
Ville Syrjälä773538e82014-09-04 14:54:56 +03002125 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002126 if (!intel_dp->want_panel_vdd)
2127 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002128 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002129}
2130
Imre Deakaba86892014-07-30 15:57:31 +03002131static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2132{
2133 unsigned long delay;
2134
2135 /*
2136 * Queue the timer to fire a long time from now (relative to the power
2137 * down delay) to keep the panel power up across a sequence of
2138 * operations.
2139 */
2140 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2141 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2142}
2143
Ville Syrjälä951468f2014-09-04 14:55:31 +03002144/*
2145 * Must be paired with edp_panel_vdd_on().
2146 * Must hold pps_mutex around the whole on/off sequence.
2147 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2148 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002149static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002150{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002151 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002152
2153 lockdep_assert_held(&dev_priv->pps_mutex);
2154
Keith Packard97af61f572011-09-28 16:23:51 -07002155 if (!is_edp(intel_dp))
2156 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002157
Rob Clarke2c719b2014-12-15 13:56:32 -05002158 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002159 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002160
Keith Packardbd943152011-09-18 23:09:52 -07002161 intel_dp->want_panel_vdd = false;
2162
Imre Deakaba86892014-07-30 15:57:31 +03002163 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002164 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002165 else
2166 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002167}
2168
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002169static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002170{
Paulo Zanoni30add222012-10-26 19:05:45 -02002171 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002172 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002173 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002174 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002175
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002176 lockdep_assert_held(&dev_priv->pps_mutex);
2177
Keith Packard97af61f572011-09-28 16:23:51 -07002178 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002179 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002180
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002181 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2182 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002183
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002184 if (WARN(edp_have_panel_power(intel_dp),
2185 "eDP port %c panel power already on\n",
2186 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002187 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002188
Daniel Vetter4be73782014-01-17 14:39:48 +01002189 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002190
Jani Nikulabf13e812013-09-06 07:40:05 +03002191 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002192 pp = ironlake_get_pp_control(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002193 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002194 /* ILK workaround: disable reset around power sequence */
2195 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002196 I915_WRITE(pp_ctrl_reg, pp);
2197 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002198 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002199
Imre Deak5a162e22016-08-10 14:07:30 +03002200 pp |= PANEL_POWER_ON;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002201 if (!IS_GEN5(dev_priv))
Keith Packard99ea7122011-11-01 19:57:50 -07002202 pp |= PANEL_POWER_RESET;
2203
Jesse Barnes453c5422013-03-28 09:55:41 -07002204 I915_WRITE(pp_ctrl_reg, pp);
2205 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002206
Daniel Vetter4be73782014-01-17 14:39:48 +01002207 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002208 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002209
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002210 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002211 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002212 I915_WRITE(pp_ctrl_reg, pp);
2213 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002214 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002215}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002216
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002217void intel_edp_panel_on(struct intel_dp *intel_dp)
2218{
2219 if (!is_edp(intel_dp))
2220 return;
2221
2222 pps_lock(intel_dp);
2223 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002224 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002225}
2226
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002227
2228static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002229{
Imre Deak4e6e1a52014-03-27 17:45:11 +02002230 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2231 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanoni30add222012-10-26 19:05:45 -02002232 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002233 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002234 enum intel_display_power_domain power_domain;
Keith Packard99ea7122011-11-01 19:57:50 -07002235 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002236 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002237
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002238 lockdep_assert_held(&dev_priv->pps_mutex);
2239
Keith Packard97af61f572011-09-28 16:23:51 -07002240 if (!is_edp(intel_dp))
2241 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002242
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002243 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2244 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002245
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002246 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2247 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002248
Jesse Barnes453c5422013-03-28 09:55:41 -07002249 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002250 /* We need to switch off panel power _and_ force vdd, for otherwise some
2251 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002252 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002253 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002254
Jani Nikulabf13e812013-09-06 07:40:05 +03002255 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002256
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002257 intel_dp->want_panel_vdd = false;
2258
Jesse Barnes453c5422013-03-28 09:55:41 -07002259 I915_WRITE(pp_ctrl_reg, pp);
2260 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002261
Abhay Kumard28d4732016-01-22 17:39:04 -08002262 intel_dp->panel_power_off_time = ktime_get_boottime();
Daniel Vetter4be73782014-01-17 14:39:48 +01002263 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002264
2265 /* We got a reference when we enabled the VDD. */
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002266 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002267 intel_display_power_put(dev_priv, power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002268}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002269
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002270void intel_edp_panel_off(struct intel_dp *intel_dp)
2271{
2272 if (!is_edp(intel_dp))
2273 return;
2274
2275 pps_lock(intel_dp);
2276 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002277 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002278}
2279
Jani Nikula1250d102014-08-12 17:11:39 +03002280/* Enable backlight in the panel power control. */
2281static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002282{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002283 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2284 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002285 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002286 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002287 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002288
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002289 /*
2290 * If we enable the backlight right away following a panel power
2291 * on, we may see slight flicker as the panel syncs with the eDP
2292 * link. So delay a bit to make sure the image is solid before
2293 * allowing it to appear.
2294 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002295 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002296
Ville Syrjälä773538e82014-09-04 14:54:56 +03002297 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002298
Jesse Barnes453c5422013-03-28 09:55:41 -07002299 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002300 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002301
Jani Nikulabf13e812013-09-06 07:40:05 +03002302 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002303
2304 I915_WRITE(pp_ctrl_reg, pp);
2305 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002306
Ville Syrjälä773538e82014-09-04 14:54:56 +03002307 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002308}
2309
Jani Nikula1250d102014-08-12 17:11:39 +03002310/* Enable backlight PWM and backlight PP control. */
2311void intel_edp_backlight_on(struct intel_dp *intel_dp)
2312{
2313 if (!is_edp(intel_dp))
2314 return;
2315
2316 DRM_DEBUG_KMS("\n");
2317
2318 intel_panel_enable_backlight(intel_dp->attached_connector);
2319 _intel_edp_backlight_on(intel_dp);
2320}
2321
2322/* Disable backlight in the panel power control. */
2323static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002324{
Paulo Zanoni30add222012-10-26 19:05:45 -02002325 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002326 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002327 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002328 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002329
Keith Packardf01eca22011-09-28 16:48:10 -07002330 if (!is_edp(intel_dp))
2331 return;
2332
Ville Syrjälä773538e82014-09-04 14:54:56 +03002333 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002334
Jesse Barnes453c5422013-03-28 09:55:41 -07002335 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002336 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002337
Jani Nikulabf13e812013-09-06 07:40:05 +03002338 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002339
2340 I915_WRITE(pp_ctrl_reg, pp);
2341 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002342
Ville Syrjälä773538e82014-09-04 14:54:56 +03002343 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002344
Paulo Zanonidce56b32013-12-19 14:29:40 -02002345 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002346 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002347}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002348
Jani Nikula1250d102014-08-12 17:11:39 +03002349/* Disable backlight PP control and backlight PWM. */
2350void intel_edp_backlight_off(struct intel_dp *intel_dp)
2351{
2352 if (!is_edp(intel_dp))
2353 return;
2354
2355 DRM_DEBUG_KMS("\n");
2356
2357 _intel_edp_backlight_off(intel_dp);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002358 intel_panel_disable_backlight(intel_dp->attached_connector);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002359}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002360
Jani Nikula73580fb72014-08-12 17:11:41 +03002361/*
2362 * Hook for controlling the panel power control backlight through the bl_power
2363 * sysfs attribute. Take care to handle multiple calls.
2364 */
2365static void intel_edp_backlight_power(struct intel_connector *connector,
2366 bool enable)
2367{
2368 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002369 bool is_enabled;
2370
Ville Syrjälä773538e82014-09-04 14:54:56 +03002371 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002372 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002373 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002374
2375 if (is_enabled == enable)
2376 return;
2377
Jani Nikula23ba9372014-08-27 14:08:43 +03002378 DRM_DEBUG_KMS("panel power control backlight %s\n",
2379 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002380
2381 if (enable)
2382 _intel_edp_backlight_on(intel_dp);
2383 else
2384 _intel_edp_backlight_off(intel_dp);
2385}
2386
Ville Syrjälä64e10772015-10-29 21:26:01 +02002387static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2388{
2389 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2390 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2391 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2392
2393 I915_STATE_WARN(cur_state != state,
2394 "DP port %c state assertion failure (expected %s, current %s)\n",
2395 port_name(dig_port->port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002396 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002397}
2398#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2399
2400static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2401{
2402 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2403
2404 I915_STATE_WARN(cur_state != state,
2405 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002406 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002407}
2408#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2409#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2410
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002411static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2412 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002413{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002414 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002415 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002416
Ville Syrjälä64e10772015-10-29 21:26:01 +02002417 assert_pipe_disabled(dev_priv, crtc->pipe);
2418 assert_dp_port_disabled(intel_dp);
2419 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002420
Ville Syrjäläabfce942015-10-29 21:26:03 +02002421 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002422 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002423
2424 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2425
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002426 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002427 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2428 else
2429 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2430
2431 I915_WRITE(DP_A, intel_dp->DP);
2432 POSTING_READ(DP_A);
2433 udelay(500);
2434
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002435 /*
2436 * [DevILK] Work around required when enabling DP PLL
2437 * while a pipe is enabled going to FDI:
2438 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2439 * 2. Program DP PLL enable
2440 */
2441 if (IS_GEN5(dev_priv))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02002442 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002443
Daniel Vetter07679352012-09-06 22:15:42 +02002444 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002445
Daniel Vetter07679352012-09-06 22:15:42 +02002446 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002447 POSTING_READ(DP_A);
2448 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002449}
2450
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002451static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002452{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002453 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002454 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2455 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002456
Ville Syrjälä64e10772015-10-29 21:26:01 +02002457 assert_pipe_disabled(dev_priv, crtc->pipe);
2458 assert_dp_port_disabled(intel_dp);
2459 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002460
Ville Syrjäläabfce942015-10-29 21:26:03 +02002461 DRM_DEBUG_KMS("disabling eDP PLL\n");
2462
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002463 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002464
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002465 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002466 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002467 udelay(200);
2468}
2469
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002470/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002471void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002472{
2473 int ret, i;
2474
2475 /* Should have a valid DPCD by this point */
2476 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2477 return;
2478
2479 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002480 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2481 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002482 } else {
Imre Deak357c0ae2016-11-21 21:15:06 +02002483 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
2484
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002485 /*
2486 * When turning on, we need to retry for 1ms to give the sink
2487 * time to wake up.
2488 */
2489 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002490 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2491 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002492 if (ret == 1)
2493 break;
2494 msleep(1);
2495 }
Imre Deak357c0ae2016-11-21 21:15:06 +02002496
2497 if (ret == 1 && lspcon->active)
2498 lspcon_wait_pcon_mode(lspcon);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002499 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002500
2501 if (ret != 1)
2502 DRM_DEBUG_KMS("failed to %s sink power state\n",
2503 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002504}
2505
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002506static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2507 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002508{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002509 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002510 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002511 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002512 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002513 enum intel_display_power_domain power_domain;
2514 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002515 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002516
2517 power_domain = intel_display_port_power_domain(encoder);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002518 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002519 return false;
2520
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002521 ret = false;
2522
Imre Deak6d129be2014-03-05 16:20:54 +02002523 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002524
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002525 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002526 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002527
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002528 if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002529 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002530 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002531 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002532
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002533 for_each_pipe(dev_priv, p) {
2534 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2535 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2536 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002537 ret = true;
2538
2539 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002540 }
2541 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002542
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002543 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002544 i915_mmio_reg_offset(intel_dp->output_reg));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002545 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002546 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2547 } else {
2548 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002549 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002550
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002551 ret = true;
2552
2553out:
2554 intel_display_power_put(dev_priv, power_domain);
2555
2556 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002557}
2558
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002559static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002560 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002561{
2562 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002563 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002564 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002565 struct drm_i915_private *dev_priv = to_i915(dev);
Xiong Zhang63000ef2013-06-28 12:59:06 +08002566 enum port port = dp_to_dig_port(intel_dp)->port;
2567 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002568
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002569 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002570
2571 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002572
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002573 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002574 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2575
2576 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002577 flags |= DRM_MODE_FLAG_PHSYNC;
2578 else
2579 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002580
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002581 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002582 flags |= DRM_MODE_FLAG_PVSYNC;
2583 else
2584 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002585 } else {
2586 if (tmp & DP_SYNC_HS_HIGH)
2587 flags |= DRM_MODE_FLAG_PHSYNC;
2588 else
2589 flags |= DRM_MODE_FLAG_NHSYNC;
2590
2591 if (tmp & DP_SYNC_VS_HIGH)
2592 flags |= DRM_MODE_FLAG_PVSYNC;
2593 else
2594 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002595 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002596
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002597 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002598
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02002599 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002600 pipe_config->limited_color_range = true;
2601
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002602 pipe_config->lane_count =
2603 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2604
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002605 intel_dp_get_m_n(crtc, pipe_config);
2606
Ville Syrjälä18442d02013-09-13 16:00:08 +03002607 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002608 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002609 pipe_config->port_clock = 162000;
2610 else
2611 pipe_config->port_clock = 270000;
2612 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002613
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002614 pipe_config->base.adjusted_mode.crtc_clock =
2615 intel_dotclock_calculate(pipe_config->port_clock,
2616 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002617
Jani Nikula6aa23e62016-03-24 17:50:20 +02002618 if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
2619 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002620 /*
2621 * This is a big fat ugly hack.
2622 *
2623 * Some machines in UEFI boot mode provide us a VBT that has 18
2624 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2625 * unknown we fail to light up. Yet the same BIOS boots up with
2626 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2627 * max, not what it tells us to use.
2628 *
2629 * Note: This will still be broken if the eDP panel is not lit
2630 * up by the BIOS, and thus we can't get the mode at module
2631 * load.
2632 */
2633 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002634 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2635 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002636 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002637}
2638
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002639static void intel_disable_dp(struct intel_encoder *encoder,
2640 struct intel_crtc_state *old_crtc_state,
2641 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002642{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002643 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002644 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002645
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002646 if (old_crtc_state->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002647 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002648
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002649 if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv))
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002650 intel_psr_disable(intel_dp);
2651
Daniel Vetter6cb49832012-05-20 17:14:50 +02002652 /* Make sure the panel is off before trying to change the mode. But also
2653 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002654 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01002655 intel_edp_backlight_off(intel_dp);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002656 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002657 intel_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02002658
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002659 /* disable the port before the pipe on g4x */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002660 if (INTEL_GEN(dev_priv) < 5)
Daniel Vetter37398502012-09-06 22:15:44 +02002661 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07002662}
2663
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002664static void ilk_post_disable_dp(struct intel_encoder *encoder,
2665 struct intel_crtc_state *old_crtc_state,
2666 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002667{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002668 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002669 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002670
Ville Syrjälä49277c32014-03-31 18:21:26 +03002671 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002672
2673 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002674 if (port == PORT_A)
2675 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002676}
2677
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002678static void vlv_post_disable_dp(struct intel_encoder *encoder,
2679 struct intel_crtc_state *old_crtc_state,
2680 struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002681{
2682 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2683
2684 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002685}
2686
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002687static void chv_post_disable_dp(struct intel_encoder *encoder,
2688 struct intel_crtc_state *old_crtc_state,
2689 struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002690{
2691 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002692 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002693 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002694
2695 intel_dp_link_down(intel_dp);
2696
Ville Syrjäläa5805162015-05-26 20:42:30 +03002697 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002698
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002699 /* Assert data lane reset */
2700 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002701
Ville Syrjäläa5805162015-05-26 20:42:30 +03002702 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002703}
2704
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002705static void
2706_intel_dp_set_link_train(struct intel_dp *intel_dp,
2707 uint32_t *DP,
2708 uint8_t dp_train_pat)
2709{
2710 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2711 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002712 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002713 enum port port = intel_dig_port->port;
2714
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002715 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2716 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2717 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2718
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002719 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002720 uint32_t temp = I915_READ(DP_TP_CTL(port));
2721
2722 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2723 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2724 else
2725 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2726
2727 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2728 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2729 case DP_TRAINING_PATTERN_DISABLE:
2730 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2731
2732 break;
2733 case DP_TRAINING_PATTERN_1:
2734 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2735 break;
2736 case DP_TRAINING_PATTERN_2:
2737 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2738 break;
2739 case DP_TRAINING_PATTERN_3:
2740 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2741 break;
2742 }
2743 I915_WRITE(DP_TP_CTL(port), temp);
2744
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002745 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002746 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002747 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2748
2749 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2750 case DP_TRAINING_PATTERN_DISABLE:
2751 *DP |= DP_LINK_TRAIN_OFF_CPT;
2752 break;
2753 case DP_TRAINING_PATTERN_1:
2754 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2755 break;
2756 case DP_TRAINING_PATTERN_2:
2757 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2758 break;
2759 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002760 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002761 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2762 break;
2763 }
2764
2765 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002766 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002767 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2768 else
2769 *DP &= ~DP_LINK_TRAIN_MASK;
2770
2771 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2772 case DP_TRAINING_PATTERN_DISABLE:
2773 *DP |= DP_LINK_TRAIN_OFF;
2774 break;
2775 case DP_TRAINING_PATTERN_1:
2776 *DP |= DP_LINK_TRAIN_PAT_1;
2777 break;
2778 case DP_TRAINING_PATTERN_2:
2779 *DP |= DP_LINK_TRAIN_PAT_2;
2780 break;
2781 case DP_TRAINING_PATTERN_3:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002782 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002783 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2784 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002785 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002786 *DP |= DP_LINK_TRAIN_PAT_2;
2787 }
2788 break;
2789 }
2790 }
2791}
2792
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002793static void intel_dp_enable_port(struct intel_dp *intel_dp,
2794 struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002795{
2796 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002797 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002798
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002799 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002800
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002801 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002802
2803 /*
2804 * Magic for VLV/CHV. We _must_ first set up the register
2805 * without actually enabling the port, and then do another
2806 * write to enable the port. Otherwise link training will
2807 * fail when the power sequencer is freshly used for this port.
2808 */
2809 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002810 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002811 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002812
2813 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2814 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002815}
2816
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002817static void intel_enable_dp(struct intel_encoder *encoder,
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002818 struct intel_crtc_state *pipe_config,
2819 struct drm_connector_state *conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002820{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002821 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2822 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002823 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulac1dec792014-10-27 16:26:56 +02002824 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002825 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002826 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002827
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002828 if (WARN_ON(dp_reg & DP_PORT_EN))
2829 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002830
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002831 pps_lock(intel_dp);
2832
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002833 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002834 vlv_init_panel_power_sequencer(intel_dp);
2835
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002836 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002837
2838 edp_panel_vdd_on(intel_dp);
2839 edp_panel_on(intel_dp);
2840 edp_panel_vdd_off(intel_dp, true);
2841
2842 pps_unlock(intel_dp);
2843
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002844 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002845 unsigned int lane_mask = 0x0;
2846
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002847 if (IS_CHERRYVIEW(dev_priv))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002848 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002849
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002850 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2851 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002852 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002853
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002854 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2855 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002856 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002857
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002858 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002859 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002860 pipe_name(pipe));
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002861 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Jani Nikulac1dec792014-10-27 16:26:56 +02002862 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002863}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002864
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002865static void g4x_enable_dp(struct intel_encoder *encoder,
2866 struct intel_crtc_state *pipe_config,
2867 struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03002868{
Jani Nikula828f5c62013-09-05 16:44:45 +03002869 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2870
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002871 intel_enable_dp(encoder, pipe_config, conn_state);
Daniel Vetter4be73782014-01-17 14:39:48 +01002872 intel_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002873}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002874
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002875static void vlv_enable_dp(struct intel_encoder *encoder,
2876 struct intel_crtc_state *pipe_config,
2877 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002878{
Jani Nikula828f5c62013-09-05 16:44:45 +03002879 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2880
Daniel Vetter4be73782014-01-17 14:39:48 +01002881 intel_edp_backlight_on(intel_dp);
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002882 intel_psr_enable(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002883}
2884
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002885static void g4x_pre_enable_dp(struct intel_encoder *encoder,
2886 struct intel_crtc_state *pipe_config,
2887 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002888{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002889 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002890 enum port port = dp_to_dig_port(intel_dp)->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002891
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002892 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002893
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002894 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002895 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002896 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002897}
2898
Ville Syrjälä83b84592014-10-16 21:29:51 +03002899static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2900{
2901 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002902 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002903 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03002904 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002905
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002906 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
2907
Ville Syrjälä83b84592014-10-16 21:29:51 +03002908 edp_panel_vdd_off_sync(intel_dp);
2909
2910 /*
2911 * VLV seems to get confused when multiple power seqeuencers
2912 * have the same port selected (even if only one has power/vdd
2913 * enabled). The failure manifests as vlv_wait_port_ready() failing
2914 * CHV on the other hand doesn't seem to mind having the same port
2915 * selected in multiple power seqeuencers, but let's clear the
2916 * port select always when logically disconnecting a power sequencer
2917 * from a port.
2918 */
2919 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2920 pipe_name(pipe), port_name(intel_dig_port->port));
2921 I915_WRITE(pp_on_reg, 0);
2922 POSTING_READ(pp_on_reg);
2923
2924 intel_dp->pps_pipe = INVALID_PIPE;
2925}
2926
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002927static void vlv_steal_power_sequencer(struct drm_device *dev,
2928 enum pipe pipe)
2929{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002930 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002931 struct intel_encoder *encoder;
2932
2933 lockdep_assert_held(&dev_priv->pps_mutex);
2934
Ville Syrjäläac3c12e2014-10-16 21:29:56 +03002935 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2936 return;
2937
Jani Nikula19c80542015-12-16 12:48:16 +02002938 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002939 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002940 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002941
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002942 if (encoder->type != INTEL_OUTPUT_DP &&
2943 encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002944 continue;
2945
2946 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002947 port = dp_to_dig_port(intel_dp)->port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002948
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002949 WARN(intel_dp->active_pipe == pipe,
2950 "stealing pipe %c power sequencer from active (e)DP port %c\n",
2951 pipe_name(pipe), port_name(port));
2952
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002953 if (intel_dp->pps_pipe != pipe)
2954 continue;
2955
2956 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03002957 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002958
2959 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002960 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002961 }
2962}
2963
2964static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
2965{
2966 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2967 struct intel_encoder *encoder = &intel_dig_port->base;
2968 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002969 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002970 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002971
2972 lockdep_assert_held(&dev_priv->pps_mutex);
2973
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002974 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002975
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002976 if (intel_dp->pps_pipe != INVALID_PIPE &&
2977 intel_dp->pps_pipe != crtc->pipe) {
2978 /*
2979 * If another power sequencer was being used on this
2980 * port previously make sure to turn off vdd there while
2981 * we still have control of it.
2982 */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002983 vlv_detach_power_sequencer(intel_dp);
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002984 }
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002985
2986 /*
2987 * We may be stealing the power
2988 * sequencer from another port.
2989 */
2990 vlv_steal_power_sequencer(dev, crtc->pipe);
2991
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02002992 intel_dp->active_pipe = crtc->pipe;
2993
2994 if (!is_edp(intel_dp))
2995 return;
2996
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002997 /* now it's all ours */
2998 intel_dp->pps_pipe = crtc->pipe;
2999
3000 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
3001 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
3002
3003 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03003004 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02003005 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03003006}
3007
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003008static void vlv_pre_enable_dp(struct intel_encoder *encoder,
3009 struct intel_crtc_state *pipe_config,
3010 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03003011{
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03003012 vlv_phy_pre_encoder_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003013
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003014 intel_enable_dp(encoder, pipe_config, conn_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07003015}
3016
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003017static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
3018 struct intel_crtc_state *pipe_config,
3019 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07003020{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003021 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02003022
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03003023 vlv_phy_pre_pll_enable(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003024}
3025
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003026static void chv_pre_enable_dp(struct intel_encoder *encoder,
3027 struct intel_crtc_state *pipe_config,
3028 struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003029{
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003030 chv_phy_pre_encoder_enable(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003031
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01003032 intel_enable_dp(encoder, pipe_config, conn_state);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03003033
3034 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03003035 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003036}
3037
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003038static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
3039 struct intel_crtc_state *pipe_config,
3040 struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03003041{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02003042 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03003043
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03003044 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03003045}
3046
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02003047static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
3048 struct intel_crtc_state *pipe_config,
3049 struct drm_connector_state *conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003050{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03003051 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03003052}
3053
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003054/*
3055 * Fetch AUX CH registers 0x202 - 0x207 which contain
3056 * link status information
3057 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003058bool
Keith Packard93f62da2011-11-01 19:45:03 -07003059intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003060{
Lyude9f085eb2016-04-13 10:58:33 -04003061 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
3062 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003063}
3064
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303065static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp)
3066{
3067 uint8_t psr_caps = 0;
3068
3069 drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps);
3070 return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED;
3071}
3072
3073static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp)
3074{
3075 uint8_t dprx = 0;
3076
3077 drm_dp_dpcd_readb(&intel_dp->aux,
3078 DP_DPRX_FEATURE_ENUMERATION_LIST,
3079 &dprx);
3080 return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED;
3081}
3082
Chris Wilsona76f73d2017-01-14 10:51:13 +00003083static bool intel_dp_get_alpm_status(struct intel_dp *intel_dp)
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303084{
3085 uint8_t alpm_caps = 0;
3086
3087 drm_dp_dpcd_readb(&intel_dp->aux, DP_RECEIVER_ALPM_CAP, &alpm_caps);
3088 return alpm_caps & DP_ALPM_CAP;
3089}
3090
Paulo Zanoni11002442014-06-13 18:45:41 -03003091/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003092uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003093intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003094{
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003095 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003096 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003097
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003098 if (IS_GEN9_LP(dev_priv))
Vandana Kannan93147262014-11-18 15:45:29 +05303099 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00003100 else if (INTEL_GEN(dev_priv) >= 9) {
Jani Nikula06411f02016-03-24 17:50:21 +02003101 if (dev_priv->vbt.edp.low_vswing && port == PORT_A)
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303102 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003103 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003104 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Sonika Jindalbd600182014-08-08 16:23:41 +05303105 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003106 else if (IS_GEN7(dev_priv) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303107 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003108 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05303109 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08003110 else
Sonika Jindalbd600182014-08-08 16:23:41 +05303111 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08003112}
3113
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003114uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003115intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3116{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003117 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003118 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003119
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003120 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003121 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3122 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3123 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3124 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3125 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3126 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3127 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303128 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3129 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003130 default:
3131 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3132 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003133 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003134 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303135 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3136 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3137 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3138 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3139 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3140 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3141 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003142 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303143 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003144 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003145 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003146 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303147 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3148 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3149 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3150 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3151 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3152 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3153 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003154 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303155 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003156 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003157 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003158 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303159 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3160 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3161 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3162 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3163 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003164 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303165 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003166 }
3167 } else {
3168 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303169 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3170 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3171 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3172 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3173 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3174 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3175 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003176 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303177 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003178 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003179 }
3180}
3181
Daniel Vetter5829975c2015-04-16 11:36:52 +02003182static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003183{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003184 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003185 unsigned long demph_reg_value, preemph_reg_value,
3186 uniqtranscale_reg_value;
3187 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003188
3189 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303190 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003191 preemph_reg_value = 0x0004000;
3192 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303193 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003194 demph_reg_value = 0x2B405555;
3195 uniqtranscale_reg_value = 0x552AB83A;
3196 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303197 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003198 demph_reg_value = 0x2B404040;
3199 uniqtranscale_reg_value = 0x5548B83A;
3200 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303201 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003202 demph_reg_value = 0x2B245555;
3203 uniqtranscale_reg_value = 0x5560B83A;
3204 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303205 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003206 demph_reg_value = 0x2B405555;
3207 uniqtranscale_reg_value = 0x5598DA3A;
3208 break;
3209 default:
3210 return 0;
3211 }
3212 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303213 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003214 preemph_reg_value = 0x0002000;
3215 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303216 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003217 demph_reg_value = 0x2B404040;
3218 uniqtranscale_reg_value = 0x5552B83A;
3219 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303220 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003221 demph_reg_value = 0x2B404848;
3222 uniqtranscale_reg_value = 0x5580B83A;
3223 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303224 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003225 demph_reg_value = 0x2B404040;
3226 uniqtranscale_reg_value = 0x55ADDA3A;
3227 break;
3228 default:
3229 return 0;
3230 }
3231 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303232 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003233 preemph_reg_value = 0x0000000;
3234 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303235 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003236 demph_reg_value = 0x2B305555;
3237 uniqtranscale_reg_value = 0x5570B83A;
3238 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303239 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003240 demph_reg_value = 0x2B2B4040;
3241 uniqtranscale_reg_value = 0x55ADDA3A;
3242 break;
3243 default:
3244 return 0;
3245 }
3246 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303247 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003248 preemph_reg_value = 0x0006000;
3249 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303250 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003251 demph_reg_value = 0x1B405555;
3252 uniqtranscale_reg_value = 0x55ADDA3A;
3253 break;
3254 default:
3255 return 0;
3256 }
3257 break;
3258 default:
3259 return 0;
3260 }
3261
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003262 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3263 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003264
3265 return 0;
3266}
3267
Daniel Vetter5829975c2015-04-16 11:36:52 +02003268static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003269{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003270 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3271 u32 deemph_reg_value, margin_reg_value;
3272 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003273 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003274
3275 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303276 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003277 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303278 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003279 deemph_reg_value = 128;
3280 margin_reg_value = 52;
3281 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303282 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003283 deemph_reg_value = 128;
3284 margin_reg_value = 77;
3285 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303286 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003287 deemph_reg_value = 128;
3288 margin_reg_value = 102;
3289 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303290 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003291 deemph_reg_value = 128;
3292 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003293 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003294 break;
3295 default:
3296 return 0;
3297 }
3298 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303299 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003300 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303301 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003302 deemph_reg_value = 85;
3303 margin_reg_value = 78;
3304 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303305 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003306 deemph_reg_value = 85;
3307 margin_reg_value = 116;
3308 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303309 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003310 deemph_reg_value = 85;
3311 margin_reg_value = 154;
3312 break;
3313 default:
3314 return 0;
3315 }
3316 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303317 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003318 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303319 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003320 deemph_reg_value = 64;
3321 margin_reg_value = 104;
3322 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303323 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003324 deemph_reg_value = 64;
3325 margin_reg_value = 154;
3326 break;
3327 default:
3328 return 0;
3329 }
3330 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303331 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003332 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303333 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003334 deemph_reg_value = 43;
3335 margin_reg_value = 154;
3336 break;
3337 default:
3338 return 0;
3339 }
3340 break;
3341 default:
3342 return 0;
3343 }
3344
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003345 chv_set_phy_signal_level(encoder, deemph_reg_value,
3346 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003347
3348 return 0;
3349}
3350
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003351static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003352gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003353{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003354 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003355
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003356 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303357 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003358 default:
3359 signal_levels |= DP_VOLTAGE_0_4;
3360 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303361 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003362 signal_levels |= DP_VOLTAGE_0_6;
3363 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303364 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003365 signal_levels |= DP_VOLTAGE_0_8;
3366 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303367 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003368 signal_levels |= DP_VOLTAGE_1_2;
3369 break;
3370 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003371 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303372 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003373 default:
3374 signal_levels |= DP_PRE_EMPHASIS_0;
3375 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303376 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003377 signal_levels |= DP_PRE_EMPHASIS_3_5;
3378 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303379 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003380 signal_levels |= DP_PRE_EMPHASIS_6;
3381 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303382 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003383 signal_levels |= DP_PRE_EMPHASIS_9_5;
3384 break;
3385 }
3386 return signal_levels;
3387}
3388
Zhenyu Wange3421a12010-04-08 09:43:27 +08003389/* Gen6's DP voltage swing and pre-emphasis control */
3390static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003391gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003392{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003393 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3394 DP_TRAIN_PRE_EMPHASIS_MASK);
3395 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303396 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3397 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003398 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303399 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003400 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303401 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3402 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003403 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303404 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3405 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003406 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303407 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3408 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003409 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003410 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003411 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3412 "0x%x\n", signal_levels);
3413 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003414 }
3415}
3416
Keith Packard1a2eb462011-11-16 16:26:07 -08003417/* Gen7's DP voltage swing and pre-emphasis control */
3418static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003419gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003420{
3421 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3422 DP_TRAIN_PRE_EMPHASIS_MASK);
3423 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303424 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003425 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303426 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003427 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303428 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003429 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3430
Sonika Jindalbd600182014-08-08 16:23:41 +05303431 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003432 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303433 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003434 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3435
Sonika Jindalbd600182014-08-08 16:23:41 +05303436 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003437 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303438 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003439 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3440
3441 default:
3442 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3443 "0x%x\n", signal_levels);
3444 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3445 }
3446}
3447
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003448void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003449intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003450{
3451 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003452 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003453 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003454 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003455 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003456 uint8_t train_set = intel_dp->train_set[0];
3457
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003458 if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003459 signal_levels = ddi_signal_levels(intel_dp);
3460
Michel Thierry254e0932017-01-09 16:51:35 +02003461 if (IS_GEN9_LP(dev_priv))
David Weinehallf8896f52015-06-25 11:11:03 +03003462 signal_levels = 0;
3463 else
3464 mask = DDI_BUF_EMP_MASK;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003465 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003466 signal_levels = chv_signal_levels(intel_dp);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003467 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003468 signal_levels = vlv_signal_levels(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003469 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003470 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003471 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003472 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003473 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003474 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3475 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003476 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003477 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3478 }
3479
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303480 if (mask)
3481 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3482
3483 DRM_DEBUG_KMS("Using vswing level %d\n",
3484 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3485 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3486 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3487 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003488
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003489 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003490
3491 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3492 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003493}
3494
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003495void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003496intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3497 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003498{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003499 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003500 struct drm_i915_private *dev_priv =
3501 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003502
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003503 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003504
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003505 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003506 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003507}
3508
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003509void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003510{
3511 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3512 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003513 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak3ab9c632013-05-03 12:57:41 +03003514 enum port port = intel_dig_port->port;
3515 uint32_t val;
3516
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003517 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003518 return;
3519
3520 val = I915_READ(DP_TP_CTL(port));
3521 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3522 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3523 I915_WRITE(DP_TP_CTL(port), val);
3524
3525 /*
3526 * On PORT_A we can have only eDP in SST mode. There the only reason
3527 * we need to set idle transmission mode is to work around a HW issue
3528 * where we enable the pipe while not in idle link-training mode.
3529 * In this case there is requirement to wait for a minimum number of
3530 * idle patterns to be sent.
3531 */
3532 if (port == PORT_A)
3533 return;
3534
Chris Wilsona7670172016-06-30 15:33:10 +01003535 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3536 DP_TP_STATUS_IDLE_DONE,
3537 DP_TP_STATUS_IDLE_DONE,
3538 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003539 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3540}
3541
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003542static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003543intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003544{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003545 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003546 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003547 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003548 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003549 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003550 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003551
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003552 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003553 return;
3554
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003555 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003556 return;
3557
Zhao Yakui28c97732009-10-09 11:39:41 +08003558 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003559
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003560 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003561 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003562 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003563 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003564 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003565 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003566 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3567 else
3568 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003569 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003570 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003571 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003572 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003573
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003574 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3575 I915_WRITE(intel_dp->output_reg, DP);
3576 POSTING_READ(intel_dp->output_reg);
3577
3578 /*
3579 * HW workaround for IBX, we need to move the port
3580 * to transcoder A after disabling it to allow the
3581 * matching HDMI port to be enabled on transcoder A.
3582 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003583 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003584 /*
3585 * We get CPU/PCH FIFO underruns on the other pipe when
3586 * doing the workaround. Sweep them under the rug.
3587 */
3588 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3589 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3590
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003591 /* always enable with pattern 1 (as per spec) */
3592 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3593 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3594 I915_WRITE(intel_dp->output_reg, DP);
3595 POSTING_READ(intel_dp->output_reg);
3596
3597 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003598 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003599 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003600
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003601 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003602 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3603 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003604 }
3605
Keith Packardf01eca22011-09-28 16:48:10 -07003606 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003607
3608 intel_dp->DP = DP;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02003609
3610 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3611 pps_lock(intel_dp);
3612 intel_dp->active_pipe = INVALID_PIPE;
3613 pps_unlock(intel_dp);
3614 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003615}
3616
Imre Deak24e807e2016-10-24 19:33:28 +03003617bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003618intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003619{
Lyude9f085eb2016-04-13 10:58:33 -04003620 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3621 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003622 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003623
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003624 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003625
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003626 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3627}
3628
3629static bool
3630intel_edp_init_dpcd(struct intel_dp *intel_dp)
3631{
3632 struct drm_i915_private *dev_priv =
3633 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3634
3635 /* this function is meant to be called only once */
3636 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3637
3638 if (!intel_dp_read_dpcd(intel_dp))
3639 return false;
3640
Imre Deak12a47a422016-10-24 19:33:29 +03003641 intel_dp_read_desc(intel_dp);
3642
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003643 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3644 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3645 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3646
3647 /* Check if the panel supports PSR */
3648 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3649 intel_dp->psr_dpcd,
3650 sizeof(intel_dp->psr_dpcd));
3651 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3652 dev_priv->psr.sink_support = true;
3653 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3654 }
3655
3656 if (INTEL_GEN(dev_priv) >= 9 &&
3657 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3658 uint8_t frame_sync_cap;
3659
3660 dev_priv->psr.sink_support = true;
3661 drm_dp_dpcd_read(&intel_dp->aux,
3662 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3663 &frame_sync_cap, 1);
3664 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3665 /* PSR2 needs frame sync as well */
3666 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3667 DRM_DEBUG_KMS("PSR2 %s on sink",
3668 dev_priv->psr.psr2_support ? "supported" : "not supported");
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303669
3670 if (dev_priv->psr.psr2_support) {
3671 dev_priv->psr.y_cord_support =
3672 intel_dp_get_y_cord_status(intel_dp);
3673 dev_priv->psr.colorimetry_support =
3674 intel_dp_get_colorimetry_status(intel_dp);
Nagaraju, Vathsala340c93c2017-01-02 17:00:58 +05303675 dev_priv->psr.alpm =
3676 intel_dp_get_alpm_status(intel_dp);
Nagaraju, Vathsala97da2ef2017-01-02 17:00:55 +05303677 }
3678
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003679 }
3680
3681 /* Read the eDP Display control capabilities registers */
3682 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
3683 drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003684 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3685 sizeof(intel_dp->edp_dpcd))
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003686 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3687 intel_dp->edp_dpcd);
3688
3689 /* Intermediate frequency support */
3690 if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */
3691 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3692 int i;
3693
3694 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3695 sink_rates, sizeof(sink_rates));
3696
3697 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3698 int val = le16_to_cpu(sink_rates[i]);
3699
3700 if (val == 0)
3701 break;
3702
Dhinakaran Pandiyanfd81c442016-11-14 13:50:20 -08003703 /* Value read multiplied by 200kHz gives the per-lane
3704 * link rate in kHz. The source rates are, however,
3705 * stored in terms of LS_Clk kHz. The full conversion
3706 * back to symbols is
3707 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
3708 */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003709 intel_dp->sink_rates[i] = (val * 200) / 10;
3710 }
3711 intel_dp->num_sink_rates = i;
3712 }
3713
3714 return true;
3715}
3716
3717
3718static bool
3719intel_dp_get_dpcd(struct intel_dp *intel_dp)
3720{
3721 if (!intel_dp_read_dpcd(intel_dp))
3722 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003723
Lyude9f085eb2016-04-13 10:58:33 -04003724 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT,
3725 &intel_dp->sink_count, 1) < 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303726 return false;
3727
3728 /*
3729 * Sink count can change between short pulse hpd hence
3730 * a member variable in intel_dp will track any changes
3731 * between short pulse interrupts.
3732 */
3733 intel_dp->sink_count = DP_GET_SINK_COUNT(intel_dp->sink_count);
3734
3735 /*
3736 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3737 * a dongle is present but no display. Unless we require to know
3738 * if a dongle is present or not, we don't need to update
3739 * downstream port information. So, an early return here saves
3740 * time from performing other operations which are not required.
3741 */
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05303742 if (!is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303743 return false;
3744
Imre Deakc726ad02016-10-24 19:33:24 +03003745 if (!drm_dp_is_branch(intel_dp->dpcd))
Adam Jacksonedb39242012-09-18 10:58:49 -04003746 return true; /* native DP sink */
3747
3748 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3749 return true; /* no per-port downstream info */
3750
Lyude9f085eb2016-04-13 10:58:33 -04003751 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3752 intel_dp->downstream_ports,
3753 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003754 return false; /* downstream port status fetch failed */
3755
3756 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003757}
3758
Dave Airlie0e32b392014-05-02 14:02:48 +10003759static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003760intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003761{
3762 u8 buf[1];
3763
Nathan Schulte7cc96132016-03-15 10:14:05 -05003764 if (!i915.enable_dp_mst)
3765 return false;
3766
Dave Airlie0e32b392014-05-02 14:02:48 +10003767 if (!intel_dp->can_mst)
3768 return false;
3769
3770 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3771 return false;
3772
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003773 if (drm_dp_dpcd_read(&intel_dp->aux, DP_MSTM_CAP, buf, 1) != 1)
3774 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003775
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003776 return buf[0] & DP_MST_CAP;
3777}
3778
3779static void
3780intel_dp_configure_mst(struct intel_dp *intel_dp)
3781{
3782 if (!i915.enable_dp_mst)
3783 return;
3784
3785 if (!intel_dp->can_mst)
3786 return;
3787
3788 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3789
3790 if (intel_dp->is_mst)
3791 DRM_DEBUG_KMS("Sink is MST capable\n");
3792 else
3793 DRM_DEBUG_KMS("Sink is not MST capable\n");
3794
3795 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3796 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003797}
3798
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003799static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003800{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003801 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003802 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003803 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003804 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003805 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003806 int count = 0;
3807 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003808
3809 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003810 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003811 ret = -EIO;
3812 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003813 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003814
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003815 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003816 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003817 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003818 ret = -EIO;
3819 goto out;
3820 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003821
Rodrigo Vivic6297842015-11-05 10:50:20 -08003822 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003823 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivic6297842015-11-05 10:50:20 -08003824
3825 if (drm_dp_dpcd_readb(&intel_dp->aux,
3826 DP_TEST_SINK_MISC, &buf) < 0) {
3827 ret = -EIO;
3828 goto out;
3829 }
3830 count = buf & DP_TEST_COUNT_MASK;
3831 } while (--attempts && count);
3832
3833 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003834 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003835 ret = -ETIMEDOUT;
3836 }
3837
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003838 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003839 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003840 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003841}
3842
3843static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3844{
3845 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003846 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003847 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3848 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003849 int ret;
3850
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003851 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3852 return -EIO;
3853
3854 if (!(buf & DP_TEST_CRC_SUPPORTED))
3855 return -ENOTTY;
3856
3857 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3858 return -EIO;
3859
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003860 if (buf & DP_TEST_SINK_START) {
3861 ret = intel_dp_sink_crc_stop(intel_dp);
3862 if (ret)
3863 return ret;
3864 }
3865
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003866 hsw_disable_ips(intel_crtc);
3867
3868 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3869 buf | DP_TEST_SINK_START) < 0) {
3870 hsw_enable_ips(intel_crtc);
3871 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003872 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003873
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003874 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003875 return 0;
3876}
3877
3878int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3879{
3880 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003881 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003882 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3883 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003884 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003885 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003886
3887 ret = intel_dp_sink_crc_start(intel_dp);
3888 if (ret)
3889 return ret;
3890
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003891 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003892 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003893
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003894 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003895 DP_TEST_SINK_MISC, &buf) < 0) {
3896 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003897 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003898 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003899 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07003900
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003901 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003902
3903 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003904 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
3905 ret = -ETIMEDOUT;
3906 goto stop;
3907 }
3908
3909 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
3910 ret = -EIO;
3911 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003912 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003913
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003914stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003915 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003916 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003917}
3918
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003919static bool
3920intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3921{
Lyude9f085eb2016-04-13 10:58:33 -04003922 return drm_dp_dpcd_read(&intel_dp->aux,
Jani Nikula9d1a1032014-03-14 16:51:15 +02003923 DP_DEVICE_SERVICE_IRQ_VECTOR,
3924 sink_irq_vector, 1) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003925}
3926
Dave Airlie0e32b392014-05-02 14:02:48 +10003927static bool
3928intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3929{
3930 int ret;
3931
Lyude9f085eb2016-04-13 10:58:33 -04003932 ret = drm_dp_dpcd_read(&intel_dp->aux,
Dave Airlie0e32b392014-05-02 14:02:48 +10003933 DP_SINK_COUNT_ESI,
3934 sink_irq_vector, 14);
3935 if (ret != 14)
3936 return false;
3937
3938 return true;
3939}
3940
Todd Previtec5d5ab72015-04-15 08:38:38 -07003941static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003942{
Manasi Navareda15f7c2017-01-24 08:16:34 -08003943 int status = 0;
3944 int min_lane_count = 1;
3945 int common_rates[DP_MAX_SUPPORTED_RATES] = {};
3946 int link_rate_index, test_link_rate;
3947 uint8_t test_lane_count, test_link_bw;
3948 /* (DP CTS 1.2)
3949 * 4.3.1.11
3950 */
3951 /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */
3952 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT,
3953 &test_lane_count);
3954
3955 if (status <= 0) {
3956 DRM_DEBUG_KMS("Lane count read failed\n");
3957 return DP_TEST_NAK;
3958 }
3959 test_lane_count &= DP_MAX_LANE_COUNT_MASK;
3960 /* Validate the requested lane count */
3961 if (test_lane_count < min_lane_count ||
3962 test_lane_count > intel_dp->max_sink_lane_count)
3963 return DP_TEST_NAK;
3964
3965 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE,
3966 &test_link_bw);
3967 if (status <= 0) {
3968 DRM_DEBUG_KMS("Link Rate read failed\n");
3969 return DP_TEST_NAK;
3970 }
3971 /* Validate the requested link rate */
3972 test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw);
3973 link_rate_index = intel_dp_link_rate_index(intel_dp,
3974 common_rates,
3975 test_link_rate);
3976 if (link_rate_index < 0)
3977 return DP_TEST_NAK;
3978
3979 intel_dp->compliance.test_lane_count = test_lane_count;
3980 intel_dp->compliance.test_link_rate = test_link_rate;
3981
3982 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07003983}
3984
3985static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
3986{
Manasi Navare611032b2017-01-24 08:21:49 -08003987 uint8_t test_pattern;
3988 uint16_t test_misc;
3989 __be16 h_width, v_height;
3990 int status = 0;
3991
3992 /* Read the TEST_PATTERN (DP CTS 3.1.5) */
3993 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_PATTERN,
3994 &test_pattern, 1);
3995 if (status <= 0) {
3996 DRM_DEBUG_KMS("Test pattern read failed\n");
3997 return DP_TEST_NAK;
3998 }
3999 if (test_pattern != DP_COLOR_RAMP)
4000 return DP_TEST_NAK;
4001
4002 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI,
4003 &h_width, 2);
4004 if (status <= 0) {
4005 DRM_DEBUG_KMS("H Width read failed\n");
4006 return DP_TEST_NAK;
4007 }
4008
4009 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI,
4010 &v_height, 2);
4011 if (status <= 0) {
4012 DRM_DEBUG_KMS("V Height read failed\n");
4013 return DP_TEST_NAK;
4014 }
4015
4016 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_MISC0,
4017 &test_misc, 1);
4018 if (status <= 0) {
4019 DRM_DEBUG_KMS("TEST MISC read failed\n");
4020 return DP_TEST_NAK;
4021 }
4022 if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB)
4023 return DP_TEST_NAK;
4024 if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA)
4025 return DP_TEST_NAK;
4026 switch (test_misc & DP_TEST_BIT_DEPTH_MASK) {
4027 case DP_TEST_BIT_DEPTH_6:
4028 intel_dp->compliance.test_data.bpc = 6;
4029 break;
4030 case DP_TEST_BIT_DEPTH_8:
4031 intel_dp->compliance.test_data.bpc = 8;
4032 break;
4033 default:
4034 return DP_TEST_NAK;
4035 }
4036
4037 intel_dp->compliance.test_data.video_pattern = test_pattern;
4038 intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width);
4039 intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height);
4040 /* Set test active flag here so userspace doesn't interrupt things */
4041 intel_dp->compliance.test_active = 1;
4042
4043 return DP_TEST_ACK;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004044}
4045
4046static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
4047{
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004048 uint8_t test_result = DP_TEST_ACK;
Todd Previte559be302015-05-04 07:48:20 -07004049 struct intel_connector *intel_connector = intel_dp->attached_connector;
4050 struct drm_connector *connector = &intel_connector->base;
4051
4052 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02004053 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07004054 intel_dp->aux.i2c_defer_count > 6) {
4055 /* Check EDID read for NACKs, DEFERs and corruption
4056 * (DP CTS 1.2 Core r1.1)
4057 * 4.2.2.4 : Failed EDID read, I2C_NAK
4058 * 4.2.2.5 : Failed EDID read, I2C_DEFER
4059 * 4.2.2.6 : EDID corruption detected
4060 * Use failsafe mode for all cases
4061 */
4062 if (intel_dp->aux.i2c_nack_count > 0 ||
4063 intel_dp->aux.i2c_defer_count > 0)
4064 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
4065 intel_dp->aux.i2c_nack_count,
4066 intel_dp->aux.i2c_defer_count);
Manasi Navarec1617ab2016-12-09 16:22:50 -08004067 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
Todd Previte559be302015-05-04 07:48:20 -07004068 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05304069 struct edid *block = intel_connector->detect_edid;
4070
4071 /* We have to write the checksum
4072 * of the last block read
4073 */
4074 block += intel_connector->detect_edid->extensions;
4075
Todd Previte559be302015-05-04 07:48:20 -07004076 if (!drm_dp_dpcd_write(&intel_dp->aux,
4077 DP_TEST_EDID_CHECKSUM,
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05304078 &block->checksum,
Dan Carpenter5a1cc652015-05-12 21:07:37 +03004079 1))
Todd Previte559be302015-05-04 07:48:20 -07004080 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
4081
4082 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
Manasi Navareb48a5ba2017-01-20 19:09:28 -08004083 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED;
Todd Previte559be302015-05-04 07:48:20 -07004084 }
4085
4086 /* Set test active flag here so userspace doesn't interrupt things */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004087 intel_dp->compliance.test_active = 1;
Todd Previte559be302015-05-04 07:48:20 -07004088
Todd Previtec5d5ab72015-04-15 08:38:38 -07004089 return test_result;
4090}
4091
4092static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
4093{
4094 uint8_t test_result = DP_TEST_NAK;
4095 return test_result;
4096}
4097
4098static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
4099{
4100 uint8_t response = DP_TEST_NAK;
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004101 uint8_t request = 0;
4102 int status;
Todd Previtec5d5ab72015-04-15 08:38:38 -07004103
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004104 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004105 if (status <= 0) {
4106 DRM_DEBUG_KMS("Could not read test request from sink\n");
4107 goto update_status;
4108 }
4109
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004110 switch (request) {
Todd Previtec5d5ab72015-04-15 08:38:38 -07004111 case DP_TEST_LINK_TRAINING:
4112 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004113 response = intel_dp_autotest_link_training(intel_dp);
4114 break;
4115 case DP_TEST_LINK_VIDEO_PATTERN:
4116 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004117 response = intel_dp_autotest_video_pattern(intel_dp);
4118 break;
4119 case DP_TEST_LINK_EDID_READ:
4120 DRM_DEBUG_KMS("EDID test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004121 response = intel_dp_autotest_edid(intel_dp);
4122 break;
4123 case DP_TEST_LINK_PHY_TEST_PATTERN:
4124 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
Todd Previtec5d5ab72015-04-15 08:38:38 -07004125 response = intel_dp_autotest_phy_pattern(intel_dp);
4126 break;
4127 default:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004128 DRM_DEBUG_KMS("Invalid test request '%02x'\n", request);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004129 break;
4130 }
4131
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004132 if (response & DP_TEST_ACK)
4133 intel_dp->compliance.test_type = request;
4134
Todd Previtec5d5ab72015-04-15 08:38:38 -07004135update_status:
Jani Nikula5ec63bb2017-01-20 19:04:06 +02004136 status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response);
Todd Previtec5d5ab72015-04-15 08:38:38 -07004137 if (status <= 0)
4138 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004139}
4140
Dave Airlie0e32b392014-05-02 14:02:48 +10004141static int
4142intel_dp_check_mst_status(struct intel_dp *intel_dp)
4143{
4144 bool bret;
4145
4146 if (intel_dp->is_mst) {
4147 u8 esi[16] = { 0 };
4148 int ret = 0;
4149 int retry;
4150 bool handled;
4151 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4152go_again:
4153 if (bret == true) {
4154
4155 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03004156 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03004157 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10004158 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4159 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10004160 intel_dp_stop_link_train(intel_dp);
4161 }
4162
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004163 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004164 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4165
4166 if (handled) {
4167 for (retry = 0; retry < 3; retry++) {
4168 int wret;
4169 wret = drm_dp_dpcd_write(&intel_dp->aux,
4170 DP_SINK_COUNT_ESI+1,
4171 &esi[1], 3);
4172 if (wret == 3) {
4173 break;
4174 }
4175 }
4176
4177 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4178 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02004179 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10004180 goto go_again;
4181 }
4182 } else
4183 ret = 0;
4184
4185 return ret;
4186 } else {
4187 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4188 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4189 intel_dp->is_mst = false;
4190 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4191 /* send a hotplug event */
4192 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4193 }
4194 }
4195 return -EINVAL;
4196}
4197
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304198static void
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004199intel_dp_retrain_link(struct intel_dp *intel_dp)
4200{
4201 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4202 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4203 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
4204
4205 /* Suppress underruns caused by re-training */
4206 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4207 if (crtc->config->has_pch_encoder)
4208 intel_set_pch_fifo_underrun_reporting(dev_priv,
4209 intel_crtc_pch_transcoder(crtc), false);
4210
4211 intel_dp_start_link_train(intel_dp);
4212 intel_dp_stop_link_train(intel_dp);
4213
4214 /* Keep underrun reporting disabled until things are stable */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02004215 intel_wait_for_vblank(dev_priv, crtc->pipe);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004216
4217 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4218 if (crtc->config->has_pch_encoder)
4219 intel_set_pch_fifo_underrun_reporting(dev_priv,
4220 intel_crtc_pch_transcoder(crtc), true);
4221}
4222
4223static void
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304224intel_dp_check_link_status(struct intel_dp *intel_dp)
4225{
4226 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4227 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4228 u8 link_status[DP_LINK_STATUS_SIZE];
4229
4230 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
4231
4232 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4233 DRM_ERROR("Failed to get link status\n");
4234 return;
4235 }
4236
4237 if (!intel_encoder->base.crtc)
4238 return;
4239
4240 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4241 return;
4242
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004243 /* FIXME: we need to synchronize this sort of stuff with hardware
Daniel Vetter2dd85ae2016-12-13 20:54:14 +01004244 * readout. Currently fast link training doesn't work on boot-up. */
4245 if (!intel_dp->lane_count)
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004246 return;
4247
Manasi Navareda15f7c2017-01-24 08:16:34 -08004248 /* Retrain if Channel EQ or CR not ok */
4249 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304250 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4251 intel_encoder->base.name);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004252
4253 intel_dp_retrain_link(intel_dp);
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304254 }
4255}
4256
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004257/*
4258 * According to DP spec
4259 * 5.1.2:
4260 * 1. Read DPCD
4261 * 2. Configure link according to Receiver Capabilities
4262 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4263 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304264 *
4265 * intel_dp_short_pulse - handles short pulse interrupts
4266 * when full detection is not required.
4267 * Returns %true if short pulse is handled and full detection
4268 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004269 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304270static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304271intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004272{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004273 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004274 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004275 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304276 u8 old_sink_count = intel_dp->sink_count;
4277 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004278
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304279 /*
4280 * Clearing compliance test variables to allow capturing
4281 * of values for next automated test request.
4282 */
Manasi Navarec1617ab2016-12-09 16:22:50 -08004283 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304284
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304285 /*
4286 * Now read the DPCD to see if it's actually running
4287 * If the current value of sink count doesn't match with
4288 * the value that was stored earlier or dpcd read failed
4289 * we need to do full detection
4290 */
4291 ret = intel_dp_get_dpcd(intel_dp);
4292
4293 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4294 /* No need to proceed if we are going to do full detect */
4295 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004296 }
4297
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004298 /* Try to read the source of the interrupt */
4299 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004300 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4301 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004302 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004303 drm_dp_dpcd_writeb(&intel_dp->aux,
4304 DP_DEVICE_SERVICE_IRQ_VECTOR,
4305 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004306
4307 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Manasi Navareda15f7c2017-01-24 08:16:34 -08004308 intel_dp_handle_test_request(intel_dp);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004309 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4310 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4311 }
4312
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304313 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4314 intel_dp_check_link_status(intel_dp);
4315 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Manasi Navareda15f7c2017-01-24 08:16:34 -08004316 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
4317 DRM_DEBUG_KMS("Link Training Compliance Test requested\n");
4318 /* Send a Hotplug Uevent to userspace to start modeset */
4319 drm_kms_helper_hotplug_event(intel_encoder->base.dev);
4320 }
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304321
4322 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004323}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004324
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004325/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004326static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004327intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004328{
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004329 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004330 uint8_t type;
4331
4332 if (!intel_dp_get_dpcd(intel_dp))
4333 return connector_status_disconnected;
4334
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304335 if (is_edp(intel_dp))
4336 return connector_status_connected;
4337
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004338 /* if there's no downstream port, we're done */
Imre Deakc726ad02016-10-24 19:33:24 +03004339 if (!drm_dp_is_branch(dpcd))
Keith Packard26d61aa2011-07-25 20:01:09 -07004340 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004341
4342 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004343 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4344 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004345
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304346 return intel_dp->sink_count ?
4347 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004348 }
4349
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004350 if (intel_dp_can_mst(intel_dp))
4351 return connector_status_connected;
4352
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004353 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004354 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004355 return connector_status_connected;
4356
4357 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004358 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4359 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4360 if (type == DP_DS_PORT_TYPE_VGA ||
4361 type == DP_DS_PORT_TYPE_NON_EDID)
4362 return connector_status_unknown;
4363 } else {
4364 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4365 DP_DWN_STRM_PORT_TYPE_MASK;
4366 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4367 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4368 return connector_status_unknown;
4369 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004370
4371 /* Anything else is out of spec, warn and ignore */
4372 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004373 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004374}
4375
4376static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004377edp_detect(struct intel_dp *intel_dp)
4378{
4379 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Mika Kahola1650be72016-12-13 10:02:47 +02004380 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsond410b562014-09-02 20:03:59 +01004381 enum drm_connector_status status;
4382
Mika Kahola1650be72016-12-13 10:02:47 +02004383 status = intel_panel_detect(dev_priv);
Chris Wilsond410b562014-09-02 20:03:59 +01004384 if (status == connector_status_unknown)
4385 status = connector_status_connected;
4386
4387 return status;
4388}
4389
Jani Nikulab93433c2015-08-20 10:47:36 +03004390static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4391 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004392{
Jani Nikulab93433c2015-08-20 10:47:36 +03004393 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004394
Jani Nikula0df53b72015-08-20 10:47:40 +03004395 switch (port->port) {
4396 case PORT_A:
4397 return true;
4398 case PORT_B:
4399 bit = SDE_PORTB_HOTPLUG;
4400 break;
4401 case PORT_C:
4402 bit = SDE_PORTC_HOTPLUG;
4403 break;
4404 case PORT_D:
4405 bit = SDE_PORTD_HOTPLUG;
4406 break;
4407 default:
4408 MISSING_CASE(port->port);
4409 return false;
4410 }
4411
4412 return I915_READ(SDEISR) & bit;
4413}
4414
4415static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4416 struct intel_digital_port *port)
4417{
4418 u32 bit;
4419
4420 switch (port->port) {
4421 case PORT_A:
4422 return true;
4423 case PORT_B:
4424 bit = SDE_PORTB_HOTPLUG_CPT;
4425 break;
4426 case PORT_C:
4427 bit = SDE_PORTC_HOTPLUG_CPT;
4428 break;
4429 case PORT_D:
4430 bit = SDE_PORTD_HOTPLUG_CPT;
4431 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004432 case PORT_E:
4433 bit = SDE_PORTE_HOTPLUG_SPT;
4434 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004435 default:
4436 MISSING_CASE(port->port);
4437 return false;
Jani Nikulab93433c2015-08-20 10:47:36 +03004438 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004439
Jani Nikulab93433c2015-08-20 10:47:36 +03004440 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004441}
4442
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004443static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004444 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004445{
Jani Nikula9642c812015-08-20 10:47:41 +03004446 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004447
Jani Nikula9642c812015-08-20 10:47:41 +03004448 switch (port->port) {
4449 case PORT_B:
4450 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4451 break;
4452 case PORT_C:
4453 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4454 break;
4455 case PORT_D:
4456 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4457 break;
4458 default:
4459 MISSING_CASE(port->port);
4460 return false;
4461 }
4462
4463 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4464}
4465
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004466static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4467 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004468{
4469 u32 bit;
4470
4471 switch (port->port) {
4472 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004473 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004474 break;
4475 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004476 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004477 break;
4478 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004479 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004480 break;
4481 default:
4482 MISSING_CASE(port->port);
4483 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004484 }
4485
Jani Nikula1d245982015-08-20 10:47:37 +03004486 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004487}
4488
Jani Nikulae464bfd2015-08-20 10:47:42 +03004489static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304490 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004491{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304492 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4493 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004494 u32 bit;
4495
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304496 intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port);
4497 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004498 case PORT_A:
4499 bit = BXT_DE_PORT_HP_DDIA;
4500 break;
4501 case PORT_B:
4502 bit = BXT_DE_PORT_HP_DDIB;
4503 break;
4504 case PORT_C:
4505 bit = BXT_DE_PORT_HP_DDIC;
4506 break;
4507 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304508 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004509 return false;
4510 }
4511
4512 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4513}
4514
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004515/*
4516 * intel_digital_port_connected - is the specified port connected?
4517 * @dev_priv: i915 private structure
4518 * @port: the port to test
4519 *
4520 * Return %true if @port is connected, %false otherwise.
4521 */
Imre Deak390b4e02017-01-27 11:39:19 +02004522bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
4523 struct intel_digital_port *port)
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004524{
Jani Nikula0df53b72015-08-20 10:47:40 +03004525 if (HAS_PCH_IBX(dev_priv))
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004526 return ibx_digital_port_connected(dev_priv, port);
Ville Syrjälä22824fa2016-02-11 16:44:28 +02004527 else if (HAS_PCH_SPLIT(dev_priv))
Jani Nikula0df53b72015-08-20 10:47:40 +03004528 return cpt_digital_port_connected(dev_priv, port);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004529 else if (IS_GEN9_LP(dev_priv))
Jani Nikulae464bfd2015-08-20 10:47:42 +03004530 return bxt_digital_port_connected(dev_priv, port);
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004531 else if (IS_GM45(dev_priv))
4532 return gm45_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004533 else
4534 return g4x_digital_port_connected(dev_priv, port);
4535}
4536
Keith Packard8c241fe2011-09-28 16:38:44 -07004537static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004538intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004539{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004540 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004541
Jani Nikula9cd300e2012-10-19 14:51:52 +03004542 /* use cached edid if we have one */
4543 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004544 /* invalid edid */
4545 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004546 return NULL;
4547
Jani Nikula55e9ede2013-10-01 10:38:54 +03004548 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004549 } else
4550 return drm_get_edid(&intel_connector->base,
4551 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004552}
4553
Chris Wilsonbeb60602014-09-02 20:04:00 +01004554static void
4555intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004556{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004557 struct intel_connector *intel_connector = intel_dp->attached_connector;
4558 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004559
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304560 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004561 edid = intel_dp_get_edid(intel_dp);
4562 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004563
Chris Wilsonbeb60602014-09-02 20:04:00 +01004564 if (intel_dp->force_audio != HDMI_AUDIO_AUTO)
4565 intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON;
4566 else
4567 intel_dp->has_audio = drm_detect_monitor_audio(edid);
4568}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004569
Chris Wilsonbeb60602014-09-02 20:04:00 +01004570static void
4571intel_dp_unset_edid(struct intel_dp *intel_dp)
4572{
4573 struct intel_connector *intel_connector = intel_dp->attached_connector;
4574
4575 kfree(intel_connector->detect_edid);
4576 intel_connector->detect_edid = NULL;
4577
4578 intel_dp->has_audio = false;
4579}
4580
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004581static enum drm_connector_status
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304582intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004583{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304584 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004585 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004586 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4587 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004588 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004589 enum drm_connector_status status;
Imre Deak671dedd2014-03-05 16:20:53 +02004590 enum intel_display_power_domain power_domain;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004591 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004592
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004593 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4594 intel_display_power_get(to_i915(dev), power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004595
Chris Wilsond410b562014-09-02 20:03:59 +01004596 /* Can't disconnect eDP, but you can close the lid... */
4597 if (is_edp(intel_dp))
4598 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004599 else if (intel_digital_port_connected(to_i915(dev),
4600 dp_to_dig_port(intel_dp)))
4601 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004602 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004603 status = connector_status_disconnected;
4604
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004605 if (status == connector_status_disconnected) {
Manasi Navarec1617ab2016-12-09 16:22:50 -08004606 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304607
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004608 if (intel_dp->is_mst) {
4609 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4610 intel_dp->is_mst,
4611 intel_dp->mst_mgr.mst_state);
4612 intel_dp->is_mst = false;
4613 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4614 intel_dp->is_mst);
4615 }
4616
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004617 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304618 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004619
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304620 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004621 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304622
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004623 DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
4624 yesno(intel_dp_source_supports_hbr2(intel_dp)),
4625 yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
4626
Manasi Navaref4829842016-12-05 16:27:36 -08004627 /* Set the max lane count for sink */
4628 intel_dp->max_sink_lane_count = drm_dp_max_lane_count(intel_dp->dpcd);
4629
4630 /* Set the max link BW for sink */
4631 intel_dp->max_sink_link_bw = intel_dp_max_link_bw(intel_dp);
4632
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004633 intel_dp_print_rates(intel_dp);
4634
Imre Deak7b3fc172016-10-25 16:12:39 +03004635 intel_dp_read_desc(intel_dp);
Mika Kahola0e390a32016-09-09 14:10:53 +03004636
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004637 intel_dp_configure_mst(intel_dp);
4638
4639 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304640 /*
4641 * If we are in MST mode then this connector
4642 * won't appear connected or have anything
4643 * with EDID on it
4644 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004645 status = connector_status_disconnected;
4646 goto out;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304647 } else if (connector->status == connector_status_connected) {
4648 /*
4649 * If display was connected already and is still connected
4650 * check links status, there has been known issues of
4651 * link loss triggerring long pulse!!!!
4652 */
4653 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4654 intel_dp_check_link_status(intel_dp);
4655 drm_modeset_unlock(&dev->mode_config.connection_mutex);
4656 goto out;
Dave Airlie0e32b392014-05-02 14:02:48 +10004657 }
4658
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304659 /*
4660 * Clearing NACK and defer counts to get their exact values
4661 * while reading EDID which are required by Compliance tests
4662 * 4.2.2.4 and 4.2.2.5
4663 */
4664 intel_dp->aux.i2c_nack_count = 0;
4665 intel_dp->aux.i2c_defer_count = 0;
4666
Chris Wilsonbeb60602014-09-02 20:04:00 +01004667 intel_dp_set_edid(intel_dp);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004668 if (is_edp(intel_dp) || intel_connector->detect_edid)
4669 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304670 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004671
Todd Previte09b1eb12015-04-20 15:27:34 -07004672 /* Try to read the source of the interrupt */
4673 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004674 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4675 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004676 /* Clear interrupt source */
4677 drm_dp_dpcd_writeb(&intel_dp->aux,
4678 DP_DEVICE_SERVICE_IRQ_VECTOR,
4679 sink_irq_vector);
4680
4681 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4682 intel_dp_handle_test_request(intel_dp);
4683 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4684 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4685 }
4686
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004687out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004688 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304689 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304690
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004691 intel_display_power_put(to_i915(dev), power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004692 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304693}
4694
4695static enum drm_connector_status
4696intel_dp_detect(struct drm_connector *connector, bool force)
4697{
4698 struct intel_dp *intel_dp = intel_attached_dp(connector);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004699 enum drm_connector_status status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304700
4701 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4702 connector->base.id, connector->name);
4703
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304704 /* If full detect is not performed yet, do a full detect */
4705 if (!intel_dp->detect_done)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004706 status = intel_dp_long_pulse(intel_dp->attached_connector);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304707
4708 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304709
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004710 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004711}
4712
Chris Wilsonbeb60602014-09-02 20:04:00 +01004713static void
4714intel_dp_force(struct drm_connector *connector)
4715{
4716 struct intel_dp *intel_dp = intel_attached_dp(connector);
4717 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004718 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004719 enum intel_display_power_domain power_domain;
4720
4721 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4722 connector->base.id, connector->name);
4723 intel_dp_unset_edid(intel_dp);
4724
4725 if (connector->status != connector_status_connected)
4726 return;
4727
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004728 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4729 intel_display_power_get(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004730
4731 intel_dp_set_edid(intel_dp);
4732
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004733 intel_display_power_put(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004734
4735 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004736 intel_encoder->type = INTEL_OUTPUT_DP;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004737}
4738
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004739static int intel_dp_get_modes(struct drm_connector *connector)
4740{
Jani Nikuladd06f902012-10-19 14:51:50 +03004741 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004742 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004743
Chris Wilsonbeb60602014-09-02 20:04:00 +01004744 edid = intel_connector->detect_edid;
4745 if (edid) {
4746 int ret = intel_connector_update_modes(connector, edid);
4747 if (ret)
4748 return ret;
4749 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004750
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004751 /* if eDP has no EDID, fall back to fixed mode */
Chris Wilsonbeb60602014-09-02 20:04:00 +01004752 if (is_edp(intel_attached_dp(connector)) &&
4753 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004754 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004755
4756 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004757 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004758 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004759 drm_mode_probed_add(connector, mode);
4760 return 1;
4761 }
4762 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004763
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004764 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004765}
4766
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004767static bool
4768intel_dp_detect_audio(struct drm_connector *connector)
4769{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004770 bool has_audio = false;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004771 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004772
Chris Wilsonbeb60602014-09-02 20:04:00 +01004773 edid = to_intel_connector(connector)->detect_edid;
4774 if (edid)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004775 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02004776
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004777 return has_audio;
4778}
4779
Chris Wilsonf6849602010-09-19 09:29:33 +01004780static int
4781intel_dp_set_property(struct drm_connector *connector,
4782 struct drm_property *property,
4783 uint64_t val)
4784{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004785 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Yuly Novikov53b41832012-10-26 12:04:00 +03004786 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004787 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
4788 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01004789 int ret;
4790
Rob Clark662595d2012-10-11 20:36:04 -05004791 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01004792 if (ret)
4793 return ret;
4794
Chris Wilson3f43c482011-05-12 22:17:24 +01004795 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004796 int i = val;
4797 bool has_audio;
4798
4799 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004800 return 0;
4801
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004802 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01004803
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004804 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004805 has_audio = intel_dp_detect_audio(connector);
4806 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004807 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004808
4809 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004810 return 0;
4811
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004812 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01004813 goto done;
4814 }
4815
Chris Wilsone953fd72011-02-21 22:23:52 +00004816 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02004817 bool old_auto = intel_dp->color_range_auto;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004818 bool old_range = intel_dp->limited_color_range;
Daniel Vetterae4edb82013-04-22 17:07:23 +02004819
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004820 switch (val) {
4821 case INTEL_BROADCAST_RGB_AUTO:
4822 intel_dp->color_range_auto = true;
4823 break;
4824 case INTEL_BROADCAST_RGB_FULL:
4825 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004826 intel_dp->limited_color_range = false;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004827 break;
4828 case INTEL_BROADCAST_RGB_LIMITED:
4829 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004830 intel_dp->limited_color_range = true;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004831 break;
4832 default:
4833 return -EINVAL;
4834 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02004835
4836 if (old_auto == intel_dp->color_range_auto &&
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004837 old_range == intel_dp->limited_color_range)
Daniel Vetterae4edb82013-04-22 17:07:23 +02004838 return 0;
4839
Chris Wilsone953fd72011-02-21 22:23:52 +00004840 goto done;
4841 }
4842
Yuly Novikov53b41832012-10-26 12:04:00 +03004843 if (is_edp(intel_dp) &&
4844 property == connector->dev->mode_config.scaling_mode_property) {
4845 if (val == DRM_MODE_SCALE_NONE) {
4846 DRM_DEBUG_KMS("no scaling not supported\n");
4847 return -EINVAL;
4848 }
Ville Syrjälä234126c2016-04-12 22:14:38 +03004849 if (HAS_GMCH_DISPLAY(dev_priv) &&
4850 val == DRM_MODE_SCALE_CENTER) {
4851 DRM_DEBUG_KMS("centering not supported\n");
4852 return -EINVAL;
4853 }
Yuly Novikov53b41832012-10-26 12:04:00 +03004854
4855 if (intel_connector->panel.fitting_mode == val) {
4856 /* the eDP scaling property is not changed */
4857 return 0;
4858 }
4859 intel_connector->panel.fitting_mode = val;
4860
4861 goto done;
4862 }
4863
Chris Wilsonf6849602010-09-19 09:29:33 +01004864 return -EINVAL;
4865
4866done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00004867 if (intel_encoder->base.crtc)
4868 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01004869
4870 return 0;
4871}
4872
Chris Wilson7a418e32016-06-24 14:00:14 +01004873static int
4874intel_dp_connector_register(struct drm_connector *connector)
4875{
4876 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004877 int ret;
4878
4879 ret = intel_connector_register(connector);
4880 if (ret)
4881 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004882
4883 i915_debugfs_connector_add(connector);
4884
4885 DRM_DEBUG_KMS("registering %s bus for %s\n",
4886 intel_dp->aux.name, connector->kdev->kobj.name);
4887
4888 intel_dp->aux.dev = connector->kdev;
4889 return drm_dp_aux_register(&intel_dp->aux);
4890}
4891
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004892static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004893intel_dp_connector_unregister(struct drm_connector *connector)
4894{
4895 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4896 intel_connector_unregister(connector);
4897}
4898
4899static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004900intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004901{
Jani Nikula1d508702012-10-19 14:51:49 +03004902 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004903
Chris Wilson10e972d2014-09-04 21:43:45 +01004904 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004905
Jani Nikula9cd300e2012-10-19 14:51:52 +03004906 if (!IS_ERR_OR_NULL(intel_connector->edid))
4907 kfree(intel_connector->edid);
4908
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004909 /* Can't call is_edp() since the encoder may have been destroyed
4910 * already. */
4911 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004912 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004913
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004914 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004915 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004916}
4917
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004918void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004919{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004920 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4921 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004922
Dave Airlie0e32b392014-05-02 14:02:48 +10004923 intel_dp_mst_encoder_cleanup(intel_dig_port);
Keith Packardbd943152011-09-18 23:09:52 -07004924 if (is_edp(intel_dp)) {
4925 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004926 /*
4927 * vdd might still be enabled do to the delayed vdd off.
4928 * Make sure vdd is actually turned off here.
4929 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004930 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004931 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004932 pps_unlock(intel_dp);
4933
Clint Taylor01527b32014-07-07 13:01:46 -07004934 if (intel_dp->edp_notifier.notifier_call) {
4935 unregister_reboot_notifier(&intel_dp->edp_notifier);
4936 intel_dp->edp_notifier.notifier_call = NULL;
4937 }
Keith Packardbd943152011-09-18 23:09:52 -07004938 }
Chris Wilson99681882016-06-20 09:29:17 +01004939
4940 intel_dp_aux_fini(intel_dp);
4941
Imre Deakc8bd0e42014-12-12 17:57:38 +02004942 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004943 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004944}
4945
Imre Deakbf93ba62016-04-18 10:04:21 +03004946void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004947{
4948 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4949
4950 if (!is_edp(intel_dp))
4951 return;
4952
Ville Syrjälä951468f2014-09-04 14:55:31 +03004953 /*
4954 * vdd might still be enabled do to the delayed vdd off.
4955 * Make sure vdd is actually turned off here.
4956 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004957 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004958 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004959 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004960 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004961}
4962
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004963static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4964{
4965 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4966 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004967 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004968 enum intel_display_power_domain power_domain;
4969
4970 lockdep_assert_held(&dev_priv->pps_mutex);
4971
4972 if (!edp_have_panel_vdd(intel_dp))
4973 return;
4974
4975 /*
4976 * The VDD bit needs a power domain reference, so if the bit is
4977 * already enabled when we boot or resume, grab this reference and
4978 * schedule a vdd off, so we don't hold on to the reference
4979 * indefinitely.
4980 */
4981 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004982 power_domain = intel_display_port_aux_power_domain(&intel_dig_port->base);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004983 intel_display_power_get(dev_priv, power_domain);
4984
4985 edp_panel_vdd_schedule_off(intel_dp);
4986}
4987
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02004988static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
4989{
4990 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
4991
4992 if ((intel_dp->DP & DP_PORT_EN) == 0)
4993 return INVALID_PIPE;
4994
4995 if (IS_CHERRYVIEW(dev_priv))
4996 return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
4997 else
4998 return PORT_TO_PIPE(intel_dp->DP);
4999}
5000
Imre Deakbf93ba62016-04-18 10:04:21 +03005001void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03005002{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005003 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Imre Deakdd75f6d2016-11-21 21:15:05 +02005004 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
5005 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
Ville Syrjälä64989ca42016-05-13 20:53:56 +03005006
5007 if (!HAS_DDI(dev_priv))
5008 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005009
Imre Deakdd75f6d2016-11-21 21:15:05 +02005010 if (lspcon->active)
Shashank Sharma910530c2016-10-14 19:56:52 +05305011 lspcon_resume(lspcon);
5012
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005013 pps_lock(intel_dp);
5014
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005015 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5016 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5017
5018 if (is_edp(intel_dp)) {
5019 /* Reinit the power sequencer, in case BIOS did something with it. */
5020 intel_dp_pps_init(encoder->dev, intel_dp);
5021 intel_edp_panel_vdd_sanitize(intel_dp);
5022 }
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005023
5024 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03005025}
5026
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005027static const struct drm_connector_funcs intel_dp_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02005028 .dpms = drm_atomic_helper_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005029 .detect = intel_dp_detect,
Chris Wilsonbeb60602014-09-02 20:04:00 +01005030 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005031 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01005032 .set_property = intel_dp_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -08005033 .atomic_get_property = intel_connector_atomic_get_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01005034 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01005035 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03005036 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08005037 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02005038 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005039};
5040
5041static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
5042 .get_modes = intel_dp_get_modes,
5043 .mode_valid = intel_dp_mode_valid,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005044};
5045
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005046static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03005047 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02005048 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005049};
5050
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005051enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10005052intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
5053{
5054 struct intel_dp *intel_dp = &intel_dig_port->dp;
Imre Deak1c767b32014-08-18 14:42:42 +03005055 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Dave Airlie0e32b392014-05-02 14:02:48 +10005056 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005057 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak1c767b32014-08-18 14:42:42 +03005058 enum intel_display_power_domain power_domain;
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005059 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03005060
Takashi Iwai25400582015-11-19 12:09:56 +01005061 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
5062 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Ville Syrjäläcca05022016-06-22 21:57:06 +03005063 intel_dig_port->base.type = INTEL_OUTPUT_DP;
Dave Airlie13cf5502014-06-18 11:29:35 +10005064
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005065 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
5066 /*
5067 * vdd off can generate a long pulse on eDP which
5068 * would require vdd on to handle it, and thus we
5069 * would end up in an endless cycle of
5070 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
5071 */
5072 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
5073 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d52f82015-02-10 14:11:46 +02005074 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03005075 }
5076
Ville Syrjälä26fbb772014-08-11 18:37:37 +03005077 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
5078 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10005079 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10005080
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005081 if (long_hpd) {
5082 intel_dp->detect_done = false;
5083 return IRQ_NONE;
5084 }
5085
Ville Syrjälä25f78f52015-11-16 15:01:04 +01005086 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak1c767b32014-08-18 14:42:42 +03005087 intel_display_power_get(dev_priv, power_domain);
5088
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005089 if (intel_dp->is_mst) {
5090 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
5091 /*
5092 * If we were in MST mode, and device is not
5093 * there, get out of MST mode
5094 */
5095 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
5096 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
5097 intel_dp->is_mst = false;
5098 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
5099 intel_dp->is_mst);
5100 intel_dp->detect_done = false;
5101 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10005102 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005103 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005104
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03005105 if (!intel_dp->is_mst) {
5106 if (!intel_dp_short_pulse(intel_dp)) {
5107 intel_dp->detect_done = false;
5108 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05305109 }
Dave Airlie0e32b392014-05-02 14:02:48 +10005110 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01005111
5112 ret = IRQ_HANDLED;
5113
Imre Deak1c767b32014-08-18 14:42:42 +03005114put_power:
5115 intel_display_power_put(dev_priv, power_domain);
5116
5117 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10005118}
5119
Rodrigo Vivi477ec322015-08-06 15:51:39 +08005120/* check the VBT to see whether the eDP is on another port */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005121bool intel_dp_is_edp(struct drm_i915_private *dev_priv, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08005122{
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005123 /*
5124 * eDP not supported on g4x. so bail out early just
5125 * for a bit extra safety in case the VBT is bonkers.
5126 */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005127 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03005128 return false;
5129
Imre Deaka98d9c12016-12-21 12:17:24 +02005130 if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005131 return true;
5132
Jani Nikula951d9ef2016-03-16 12:43:31 +02005133 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08005134}
5135
Dave Airlie0e32b392014-05-02 14:02:48 +10005136void
Chris Wilsonf6849602010-09-19 09:29:33 +01005137intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
5138{
Yuly Novikov53b41832012-10-26 12:04:00 +03005139 struct intel_connector *intel_connector = to_intel_connector(connector);
5140
Chris Wilson3f43c482011-05-12 22:17:24 +01005141 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00005142 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02005143 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03005144
5145 if (is_edp(intel_dp)) {
5146 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05005147 drm_object_attach_property(
5148 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03005149 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03005150 DRM_MODE_SCALE_ASPECT);
5151 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03005152 }
Chris Wilsonf6849602010-09-19 09:29:33 +01005153}
5154
Imre Deakdada1a92014-01-29 13:25:41 +02005155static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
5156{
Abhay Kumard28d4732016-01-22 17:39:04 -08005157 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02005158 intel_dp->last_power_on = jiffies;
5159 intel_dp->last_backlight_off = jiffies;
5160}
5161
Daniel Vetter67a54562012-10-20 20:57:45 +02005162static void
Imre Deak54648612016-06-16 16:37:22 +03005163intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
5164 struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02005165{
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305166 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03005167 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07005168
Imre Deak8e8232d2016-06-16 16:37:21 +03005169 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02005170
5171 /* Workaround: Need to write PP_CONTROL with the unlock key as
5172 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305173 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02005174
Imre Deak8e8232d2016-06-16 16:37:21 +03005175 pp_on = I915_READ(regs.pp_on);
5176 pp_off = I915_READ(regs.pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005177 if (!IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005178 I915_WRITE(regs.pp_ctrl, pp_ctl);
5179 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305180 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005181
5182 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03005183 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
5184 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005185
Imre Deak54648612016-06-16 16:37:22 +03005186 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
5187 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005188
Imre Deak54648612016-06-16 16:37:22 +03005189 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
5190 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005191
Imre Deak54648612016-06-16 16:37:22 +03005192 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
5193 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02005194
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005195 if (IS_GEN9_LP(dev_priv)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305196 u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
5197 BXT_POWER_CYCLE_DELAY_SHIFT;
5198 if (tmp > 0)
Imre Deak54648612016-06-16 16:37:22 +03005199 seq->t11_t12 = (tmp - 1) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305200 else
Imre Deak54648612016-06-16 16:37:22 +03005201 seq->t11_t12 = 0;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305202 } else {
Imre Deak54648612016-06-16 16:37:22 +03005203 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02005204 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305205 }
Imre Deak54648612016-06-16 16:37:22 +03005206}
5207
5208static void
Imre Deakde9c1b62016-06-16 20:01:46 +03005209intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
5210{
5211 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5212 state_name,
5213 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
5214}
5215
5216static void
5217intel_pps_verify_state(struct drm_i915_private *dev_priv,
5218 struct intel_dp *intel_dp)
5219{
5220 struct edp_power_seq hw;
5221 struct edp_power_seq *sw = &intel_dp->pps_delays;
5222
5223 intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
5224
5225 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
5226 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
5227 DRM_ERROR("PPS state mismatch\n");
5228 intel_pps_dump_state("sw", sw);
5229 intel_pps_dump_state("hw", &hw);
5230 }
5231}
5232
5233static void
Imre Deak54648612016-06-16 16:37:22 +03005234intel_dp_init_panel_power_sequencer(struct drm_device *dev,
5235 struct intel_dp *intel_dp)
5236{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005237 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak54648612016-06-16 16:37:22 +03005238 struct edp_power_seq cur, vbt, spec,
5239 *final = &intel_dp->pps_delays;
5240
5241 lockdep_assert_held(&dev_priv->pps_mutex);
5242
5243 /* already initialized? */
5244 if (final->t11_t12 != 0)
5245 return;
5246
5247 intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005248
Imre Deakde9c1b62016-06-16 20:01:46 +03005249 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005250
Jani Nikula6aa23e62016-03-24 17:50:20 +02005251 vbt = dev_priv->vbt.edp.pps;
Daniel Vetter67a54562012-10-20 20:57:45 +02005252
5253 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5254 * our hw here, which are all in 100usec. */
5255 spec.t1_t3 = 210 * 10;
5256 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5257 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5258 spec.t10 = 500 * 10;
5259 /* This one is special and actually in units of 100ms, but zero
5260 * based in the hw (so we need to add 100 ms). But the sw vbt
5261 * table multiplies it with 1000 to make it in units of 100usec,
5262 * too. */
5263 spec.t11_t12 = (510 + 100) * 10;
5264
Imre Deakde9c1b62016-06-16 20:01:46 +03005265 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005266
5267 /* Use the max of the register settings and vbt. If both are
5268 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005269#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005270 spec.field : \
5271 max(cur.field, vbt.field))
5272 assign_final(t1_t3);
5273 assign_final(t8);
5274 assign_final(t9);
5275 assign_final(t10);
5276 assign_final(t11_t12);
5277#undef assign_final
5278
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005279#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005280 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5281 intel_dp->backlight_on_delay = get_delay(t8);
5282 intel_dp->backlight_off_delay = get_delay(t9);
5283 intel_dp->panel_power_down_delay = get_delay(t10);
5284 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5285#undef get_delay
5286
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005287 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5288 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5289 intel_dp->panel_power_cycle_delay);
5290
5291 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5292 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005293
5294 /*
5295 * We override the HW backlight delays to 1 because we do manual waits
5296 * on them. For T8, even BSpec recommends doing it. For T9, if we
5297 * don't do this, we'll end up waiting for the backlight off delay
5298 * twice: once when we do the manual sleep, and once when we disable
5299 * the panel and wait for the PP_STATUS bit to become zero.
5300 */
5301 final->t8 = 1;
5302 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005303}
5304
5305static void
5306intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005307 struct intel_dp *intel_dp,
5308 bool force_disable_vdd)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005309{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005310 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07005311 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005312 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005313 struct pps_registers regs;
Ville Syrjäläad933b52014-08-18 22:15:56 +03005314 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005315 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005316
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005317 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005318
Imre Deak8e8232d2016-06-16 16:37:21 +03005319 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005320
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005321 /*
5322 * On some VLV machines the BIOS can leave the VDD
5323 * enabled even on power seqeuencers which aren't
5324 * hooked up to any port. This would mess up the
5325 * power domain tracking the first time we pick
5326 * one of these power sequencers for use since
5327 * edp_panel_vdd_on() would notice that the VDD was
5328 * already on and therefore wouldn't grab the power
5329 * domain reference. Disable VDD first to avoid this.
5330 * This also avoids spuriously turning the VDD on as
5331 * soon as the new power seqeuencer gets initialized.
5332 */
5333 if (force_disable_vdd) {
5334 u32 pp = ironlake_get_pp_control(intel_dp);
5335
5336 WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
5337
5338 if (pp & EDP_FORCE_VDD)
5339 DRM_DEBUG_KMS("VDD already on, disabling first\n");
5340
5341 pp &= ~EDP_FORCE_VDD;
5342
5343 I915_WRITE(regs.pp_ctrl, pp);
5344 }
5345
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005346 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005347 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5348 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005349 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005350 /* Compute the divisor for the pp clock, simply match the Bspec
5351 * formula. */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005352 if (IS_GEN9_LP(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005353 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305354 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
5355 pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
5356 << BXT_POWER_CYCLE_DELAY_SHIFT);
5357 } else {
5358 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5359 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5360 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5361 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005362
5363 /* Haswell doesn't have any port selection bits for the panel
5364 * power sequencer any more. */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005365 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005366 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005367 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005368 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005369 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005370 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005371 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005372 }
5373
Jesse Barnes453c5422013-03-28 09:55:41 -07005374 pp_on |= port_sel;
5375
Imre Deak8e8232d2016-06-16 16:37:21 +03005376 I915_WRITE(regs.pp_on, pp_on);
5377 I915_WRITE(regs.pp_off, pp_off);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005378 if (IS_GEN9_LP(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005379 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305380 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005381 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005382
Daniel Vetter67a54562012-10-20 20:57:45 +02005383 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 +03005384 I915_READ(regs.pp_on),
5385 I915_READ(regs.pp_off),
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02005386 IS_GEN9_LP(dev_priv) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005387 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5388 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005389}
5390
Imre Deak335f7522016-08-10 14:07:32 +03005391static void intel_dp_pps_init(struct drm_device *dev,
5392 struct intel_dp *intel_dp)
5393{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005394 struct drm_i915_private *dev_priv = to_i915(dev);
5395
5396 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Imre Deak335f7522016-08-10 14:07:32 +03005397 vlv_initial_power_sequencer_setup(intel_dp);
5398 } else {
5399 intel_dp_init_panel_power_sequencer(dev, intel_dp);
Ville Syrjälä5d5ab2d2016-12-20 18:51:17 +02005400 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
Imre Deak335f7522016-08-10 14:07:32 +03005401 }
5402}
5403
Vandana Kannanb33a2812015-02-13 15:33:03 +05305404/**
5405 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005406 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005407 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305408 * @refresh_rate: RR to be programmed
5409 *
5410 * This function gets called when refresh rate (RR) has to be changed from
5411 * one frequency to another. Switches can be between high and low RR
5412 * supported by the panel or to any other RR based on media playback (in
5413 * this case, RR value needs to be passed from user space).
5414 *
5415 * The caller of this function needs to take a lock on dev_priv->drrs.
5416 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005417static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
5418 struct intel_crtc_state *crtc_state,
5419 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305420{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305421 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305422 struct intel_digital_port *dig_port = NULL;
5423 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005424 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305425 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305426
5427 if (refresh_rate <= 0) {
5428 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5429 return;
5430 }
5431
Vandana Kannan96178ee2015-01-10 02:25:56 +05305432 if (intel_dp == NULL) {
5433 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305434 return;
5435 }
5436
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005437 /*
Rodrigo Vivie4d59f62014-11-20 02:22:08 -08005438 * FIXME: This needs proper synchronization with psr state for some
5439 * platforms that cannot have PSR and DRRS enabled at the same time.
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005440 */
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305441
Vandana Kannan96178ee2015-01-10 02:25:56 +05305442 dig_port = dp_to_dig_port(intel_dp);
5443 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02005444 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305445
5446 if (!intel_crtc) {
5447 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5448 return;
5449 }
5450
Vandana Kannan96178ee2015-01-10 02:25:56 +05305451 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305452 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5453 return;
5454 }
5455
Vandana Kannan96178ee2015-01-10 02:25:56 +05305456 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5457 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305458 index = DRRS_LOW_RR;
5459
Vandana Kannan96178ee2015-01-10 02:25:56 +05305460 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305461 DRM_DEBUG_KMS(
5462 "DRRS requested for previously set RR...ignoring\n");
5463 return;
5464 }
5465
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005466 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305467 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5468 return;
5469 }
5470
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005471 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305472 switch (index) {
5473 case DRRS_HIGH_RR:
5474 intel_dp_set_m_n(intel_crtc, M1_N1);
5475 break;
5476 case DRRS_LOW_RR:
5477 intel_dp_set_m_n(intel_crtc, M2_N2);
5478 break;
5479 case DRRS_MAX_RR:
5480 default:
5481 DRM_ERROR("Unsupported refreshrate type\n");
5482 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005483 } else if (INTEL_GEN(dev_priv) > 6) {
5484 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005485 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305486
Ville Syrjälä649636e2015-09-22 19:50:01 +03005487 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305488 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005489 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305490 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5491 else
5492 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305493 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005494 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305495 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5496 else
5497 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305498 }
5499 I915_WRITE(reg, val);
5500 }
5501
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305502 dev_priv->drrs.refresh_rate_type = index;
5503
5504 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5505}
5506
Vandana Kannanb33a2812015-02-13 15:33:03 +05305507/**
5508 * intel_edp_drrs_enable - init drrs struct if supported
5509 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005510 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305511 *
5512 * Initializes frontbuffer_bits and drrs.dp
5513 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005514void intel_edp_drrs_enable(struct intel_dp *intel_dp,
5515 struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305516{
5517 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005518 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305519
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005520 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305521 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5522 return;
5523 }
5524
5525 mutex_lock(&dev_priv->drrs.mutex);
5526 if (WARN_ON(dev_priv->drrs.dp)) {
5527 DRM_ERROR("DRRS already enabled\n");
5528 goto unlock;
5529 }
5530
5531 dev_priv->drrs.busy_frontbuffer_bits = 0;
5532
5533 dev_priv->drrs.dp = intel_dp;
5534
5535unlock:
5536 mutex_unlock(&dev_priv->drrs.mutex);
5537}
5538
Vandana Kannanb33a2812015-02-13 15:33:03 +05305539/**
5540 * intel_edp_drrs_disable - Disable DRRS
5541 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005542 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305543 *
5544 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005545void intel_edp_drrs_disable(struct intel_dp *intel_dp,
5546 struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305547{
5548 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005549 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305550
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005551 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305552 return;
5553
5554 mutex_lock(&dev_priv->drrs.mutex);
5555 if (!dev_priv->drrs.dp) {
5556 mutex_unlock(&dev_priv->drrs.mutex);
5557 return;
5558 }
5559
5560 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005561 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5562 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305563
5564 dev_priv->drrs.dp = NULL;
5565 mutex_unlock(&dev_priv->drrs.mutex);
5566
5567 cancel_delayed_work_sync(&dev_priv->drrs.work);
5568}
5569
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305570static void intel_edp_drrs_downclock_work(struct work_struct *work)
5571{
5572 struct drm_i915_private *dev_priv =
5573 container_of(work, typeof(*dev_priv), drrs.work.work);
5574 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305575
Vandana Kannan96178ee2015-01-10 02:25:56 +05305576 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305577
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305578 intel_dp = dev_priv->drrs.dp;
5579
5580 if (!intel_dp)
5581 goto unlock;
5582
5583 /*
5584 * The delayed work can race with an invalidate hence we need to
5585 * recheck.
5586 */
5587
5588 if (dev_priv->drrs.busy_frontbuffer_bits)
5589 goto unlock;
5590
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005591 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5592 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5593
5594 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5595 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5596 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305597
5598unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305599 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305600}
5601
Vandana Kannanb33a2812015-02-13 15:33:03 +05305602/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305603 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005604 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305605 * @frontbuffer_bits: frontbuffer plane tracking bits
5606 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305607 * This function gets called everytime rendering on the given planes start.
5608 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305609 *
5610 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5611 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005612void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5613 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305614{
Vandana Kannana93fad02015-01-10 02:25:59 +05305615 struct drm_crtc *crtc;
5616 enum pipe pipe;
5617
Daniel Vetter9da7d692015-04-09 16:44:15 +02005618 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305619 return;
5620
Daniel Vetter88f933a2015-04-09 16:44:16 +02005621 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305622
Vandana Kannana93fad02015-01-10 02:25:59 +05305623 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005624 if (!dev_priv->drrs.dp) {
5625 mutex_unlock(&dev_priv->drrs.mutex);
5626 return;
5627 }
5628
Vandana Kannana93fad02015-01-10 02:25:59 +05305629 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5630 pipe = to_intel_crtc(crtc)->pipe;
5631
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005632 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5633 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5634
Ramalingam C0ddfd202015-06-15 20:50:05 +05305635 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005636 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005637 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5638 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305639
Vandana Kannana93fad02015-01-10 02:25:59 +05305640 mutex_unlock(&dev_priv->drrs.mutex);
5641}
5642
Vandana Kannanb33a2812015-02-13 15:33:03 +05305643/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305644 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005645 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305646 * @frontbuffer_bits: frontbuffer plane tracking bits
5647 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305648 * This function gets called every time rendering on the given planes has
5649 * completed or flip on a crtc is completed. So DRRS should be upclocked
5650 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5651 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305652 *
5653 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5654 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005655void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5656 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305657{
Vandana Kannana93fad02015-01-10 02:25:59 +05305658 struct drm_crtc *crtc;
5659 enum pipe pipe;
5660
Daniel Vetter9da7d692015-04-09 16:44:15 +02005661 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305662 return;
5663
Daniel Vetter88f933a2015-04-09 16:44:16 +02005664 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305665
Vandana Kannana93fad02015-01-10 02:25:59 +05305666 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005667 if (!dev_priv->drrs.dp) {
5668 mutex_unlock(&dev_priv->drrs.mutex);
5669 return;
5670 }
5671
Vandana Kannana93fad02015-01-10 02:25:59 +05305672 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5673 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005674
5675 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305676 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5677
Ramalingam C0ddfd202015-06-15 20:50:05 +05305678 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005679 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005680 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5681 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305682
5683 /*
5684 * flush also means no more activity hence schedule downclock, if all
5685 * other fbs are quiescent too
5686 */
5687 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305688 schedule_delayed_work(&dev_priv->drrs.work,
5689 msecs_to_jiffies(1000));
5690 mutex_unlock(&dev_priv->drrs.mutex);
5691}
5692
Vandana Kannanb33a2812015-02-13 15:33:03 +05305693/**
5694 * DOC: Display Refresh Rate Switching (DRRS)
5695 *
5696 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5697 * which enables swtching between low and high refresh rates,
5698 * dynamically, based on the usage scenario. This feature is applicable
5699 * for internal panels.
5700 *
5701 * Indication that the panel supports DRRS is given by the panel EDID, which
5702 * would list multiple refresh rates for one resolution.
5703 *
5704 * DRRS is of 2 types - static and seamless.
5705 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5706 * (may appear as a blink on screen) and is used in dock-undock scenario.
5707 * Seamless DRRS involves changing RR without any visual effect to the user
5708 * and can be used during normal system usage. This is done by programming
5709 * certain registers.
5710 *
5711 * Support for static/seamless DRRS may be indicated in the VBT based on
5712 * inputs from the panel spec.
5713 *
5714 * DRRS saves power by switching to low RR based on usage scenarios.
5715 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005716 * The implementation is based on frontbuffer tracking implementation. When
5717 * there is a disturbance on the screen triggered by user activity or a periodic
5718 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5719 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5720 * made.
5721 *
5722 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5723 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305724 *
5725 * DRRS can be further extended to support other internal panels and also
5726 * the scenario of video playback wherein RR is set based on the rate
5727 * requested by userspace.
5728 */
5729
5730/**
5731 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5732 * @intel_connector: eDP connector
5733 * @fixed_mode: preferred mode of panel
5734 *
5735 * This function is called only once at driver load to initialize basic
5736 * DRRS stuff.
5737 *
5738 * Returns:
5739 * Downclock mode if panel supports it, else return NULL.
5740 * DRRS support is determined by the presence of downclock mode (apart
5741 * from VBT setting).
5742 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305743static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305744intel_dp_drrs_init(struct intel_connector *intel_connector,
5745 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305746{
5747 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305748 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005749 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305750 struct drm_display_mode *downclock_mode = NULL;
5751
Daniel Vetter9da7d692015-04-09 16:44:15 +02005752 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5753 mutex_init(&dev_priv->drrs.mutex);
5754
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005755 if (INTEL_GEN(dev_priv) <= 6) {
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305756 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5757 return NULL;
5758 }
5759
5760 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005761 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305762 return NULL;
5763 }
5764
5765 downclock_mode = intel_find_panel_downclock
Mika Kaholaa318b4c2016-12-13 10:02:48 +02005766 (dev_priv, fixed_mode, connector);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305767
5768 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305769 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305770 return NULL;
5771 }
5772
Vandana Kannan96178ee2015-01-10 02:25:56 +05305773 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305774
Vandana Kannan96178ee2015-01-10 02:25:56 +05305775 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005776 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305777 return downclock_mode;
5778}
5779
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005780static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005781 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005782{
5783 struct drm_connector *connector = &intel_connector->base;
5784 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005785 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5786 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005787 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005788 struct drm_display_mode *fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305789 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005790 bool has_dpcd;
5791 struct drm_display_mode *scan;
5792 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005793 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005794
5795 if (!is_edp(intel_dp))
5796 return true;
5797
Imre Deak97a824e12016-06-21 11:51:47 +03005798 /*
5799 * On IBX/CPT we may get here with LVDS already registered. Since the
5800 * driver uses the only internal power sequencer available for both
5801 * eDP and LVDS bail out early in this case to prevent interfering
5802 * with an already powered-on LVDS power sequencer.
5803 */
5804 if (intel_get_lvds_encoder(dev)) {
5805 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5806 DRM_INFO("LVDS was detected, not registering eDP\n");
5807
5808 return false;
5809 }
5810
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005811 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005812
5813 intel_dp_init_panel_power_timestamps(intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +03005814 intel_dp_pps_init(dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005815 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005816
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005817 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005818
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005819 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005820 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005821
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005822 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005823 /* if this fails, presume the device is a ghost */
5824 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005825 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005826 }
5827
Daniel Vetter060c8772014-03-21 23:22:35 +01005828 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005829 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005830 if (edid) {
5831 if (drm_add_edid_modes(connector, edid)) {
5832 drm_mode_connector_update_edid_property(connector,
5833 edid);
5834 drm_edid_to_eld(connector, edid);
5835 } else {
5836 kfree(edid);
5837 edid = ERR_PTR(-EINVAL);
5838 }
5839 } else {
5840 edid = ERR_PTR(-ENOENT);
5841 }
5842 intel_connector->edid = edid;
5843
5844 /* prefer fixed mode from EDID if available */
5845 list_for_each_entry(scan, &connector->probed_modes, head) {
5846 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5847 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305848 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305849 intel_connector, fixed_mode);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005850 break;
5851 }
5852 }
5853
5854 /* fallback to VBT if available for eDP */
5855 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5856 fixed_mode = drm_mode_duplicate(dev,
5857 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005858 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005859 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005860 connector->display_info.width_mm = fixed_mode->width_mm;
5861 connector->display_info.height_mm = fixed_mode->height_mm;
5862 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005863 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005864 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005865
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005866 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005867 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5868 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005869
5870 /*
5871 * Figure out the current pipe for the initial backlight setup.
5872 * If the current pipe isn't valid, try the PPS pipe, and if that
5873 * fails just assume pipe A.
5874 */
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005875 pipe = vlv_active_pipe(intel_dp);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005876
5877 if (pipe != PIPE_A && pipe != PIPE_B)
5878 pipe = intel_dp->pps_pipe;
5879
5880 if (pipe != PIPE_A && pipe != PIPE_B)
5881 pipe = PIPE_A;
5882
5883 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5884 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005885 }
5886
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305887 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005888 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005889 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005890
5891 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005892
5893out_vdd_off:
5894 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5895 /*
5896 * vdd might still be enabled do to the delayed vdd off.
5897 * Make sure vdd is actually turned off here.
5898 */
5899 pps_lock(intel_dp);
5900 edp_panel_vdd_off_sync(intel_dp);
5901 pps_unlock(intel_dp);
5902
5903 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005904}
5905
Paulo Zanoni16c25532013-06-12 17:27:25 -03005906bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005907intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5908 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005909{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005910 struct drm_connector *connector = &intel_connector->base;
5911 struct intel_dp *intel_dp = &intel_dig_port->dp;
5912 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5913 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005914 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02005915 enum port port = intel_dig_port->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01005916 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005917
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005918 if (WARN(intel_dig_port->max_lanes < 1,
5919 "Not enough lanes (%d) for DP on port %c\n",
5920 intel_dig_port->max_lanes, port_name(port)))
5921 return false;
5922
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005923 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005924 intel_dp->active_pipe = INVALID_PIPE;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005925
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005926 /* intel_dp vfuncs */
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005927 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub6b5e382014-01-20 16:00:59 +00005928 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005929 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005930 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005931 else if (HAS_PCH_SPLIT(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005932 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
5933 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005934 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005935
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005936 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00005937 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
5938 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005939 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00005940
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005941 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03005942 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
5943
Daniel Vetter07679352012-09-06 22:15:42 +02005944 /* Preserve the current hw state. */
5945 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03005946 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00005947
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00005948 if (intel_dp_is_edp(dev_priv, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05305949 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005950 else
5951 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04005952
Ville Syrjälä9f2bdb02016-12-14 20:00:23 +02005953 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5954 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5955
Imre Deakf7d24902013-05-08 13:14:05 +03005956 /*
5957 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
5958 * for DP the encoder type can be set by the caller to
5959 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
5960 */
5961 if (type == DRM_MODE_CONNECTOR_eDP)
5962 intel_encoder->type = INTEL_OUTPUT_EDP;
5963
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005964 /* eDP only on port B and/or C on vlv/chv */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005965 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08005966 is_edp(intel_dp) && port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005967 return false;
5968
Imre Deake7281ea2013-05-08 13:14:08 +03005969 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
5970 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
5971 port_name(port));
5972
Adam Jacksonb3295302010-07-16 14:46:28 -04005973 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005974 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
5975
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005976 connector->interlace_allowed = true;
5977 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08005978
Mika Kaholab6339582016-09-09 14:10:52 +03005979 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01005980
Daniel Vetter66a92782012-07-12 20:08:18 +02005981 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01005982 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08005983
Chris Wilsondf0e9242010-09-09 16:20:55 +01005984 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005985
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005986 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02005987 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
5988 else
5989 intel_connector->get_hw_state = intel_connector_get_hw_state;
5990
Jani Nikula0b998362014-03-14 16:51:17 +02005991 /* Set up the hotplug pin. */
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005992 switch (port) {
5993 case PORT_A:
Egbert Eich1d843f92013-02-25 12:06:49 -05005994 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005995 break;
5996 case PORT_B:
Egbert Eich1d843f92013-02-25 12:06:49 -05005997 intel_encoder->hpd_pin = HPD_PORT_B;
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01005998 if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1))
Sonika Jindalcf1d5882015-08-10 10:35:36 +05305999 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03006000 break;
6001 case PORT_C:
Egbert Eich1d843f92013-02-25 12:06:49 -05006002 intel_encoder->hpd_pin = HPD_PORT_C;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03006003 break;
6004 case PORT_D:
Egbert Eich1d843f92013-02-25 12:06:49 -05006005 intel_encoder->hpd_pin = HPD_PORT_D;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03006006 break;
Xiong Zhang26951ca2015-08-17 15:55:50 +08006007 case PORT_E:
6008 intel_encoder->hpd_pin = HPD_PORT_E;
6009 break;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03006010 default:
Damien Lespiauad1c0b12013-03-07 15:30:28 +00006011 BUG();
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08006012 }
6013
Dave Airlie0e32b392014-05-02 14:02:48 +10006014 /* init MST on ports that can support it */
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00006015 if (HAS_DP_MST(dev_priv) && !is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03006016 (port == PORT_B || port == PORT_C || port == PORT_D))
6017 intel_dp_mst_encoder_init(intel_dig_port,
6018 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10006019
Ville Syrjälä36b5f422014-10-16 21:27:30 +03006020 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006021 intel_dp_aux_fini(intel_dp);
6022 intel_dp_mst_encoder_cleanup(intel_dig_port);
6023 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03006024 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08006025
Chris Wilsonf6849602010-09-19 09:29:33 +01006026 intel_dp_add_properties(intel_dp, connector);
6027
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006028 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
6029 * 0xd. Failure to do so will result in spurious interrupts being
6030 * generated on the port when a cable is not attached.
6031 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01006032 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006033 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
6034 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
6035 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03006036
6037 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006038
6039fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02006040 drm_connector_cleanup(connector);
6041
6042 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07006043}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006044
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006045bool intel_dp_init(struct drm_i915_private *dev_priv,
Chris Wilson457c52d2016-06-01 08:27:50 +01006046 i915_reg_t output_reg,
6047 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006048{
6049 struct intel_digital_port *intel_dig_port;
6050 struct intel_encoder *intel_encoder;
6051 struct drm_encoder *encoder;
6052 struct intel_connector *intel_connector;
6053
Daniel Vetterb14c5672013-09-19 12:18:32 +02006054 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006055 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01006056 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006057
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03006058 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306059 if (!intel_connector)
6060 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006061
6062 intel_encoder = &intel_dig_port->base;
6063 encoder = &intel_encoder->base;
6064
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02006065 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
6066 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
6067 "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306068 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006069
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01006070 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006071 intel_encoder->disable = intel_disable_dp;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02006072 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07006073 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03006074 intel_encoder->suspend = intel_dp_encoder_suspend;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006075 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03006076 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03006077 intel_encoder->pre_enable = chv_pre_enable_dp;
6078 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03006079 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03006080 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01006081 } else if (IS_VALLEYVIEW(dev_priv)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006082 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006083 intel_encoder->pre_enable = vlv_pre_enable_dp;
6084 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03006085 intel_encoder->post_disable = vlv_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006086 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03006087 intel_encoder->pre_enable = g4x_pre_enable_dp;
6088 intel_encoder->enable = g4x_enable_dp;
Tvrtko Ursulindd11bc12016-11-16 08:55:41 +00006089 if (INTEL_GEN(dev_priv) >= 5)
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03006090 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03006091 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006092
Paulo Zanoni174edf12012-10-26 19:05:50 -02006093 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006094 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02006095 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006096
Ville Syrjäläcca05022016-06-22 21:57:06 +03006097 intel_encoder->type = INTEL_OUTPUT_DP;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006098 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03006099 if (port == PORT_D)
6100 intel_encoder->crtc_mask = 1 << 2;
6101 else
6102 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
6103 } else {
6104 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
6105 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02006106 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07006107 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006108
Dave Airlie13cf5502014-06-18 11:29:35 +10006109 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03006110 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10006111
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306112 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
6113 goto err_init_connector;
6114
Chris Wilson457c52d2016-06-01 08:27:50 +01006115 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306116
6117err_init_connector:
6118 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05306119err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05306120 kfree(intel_connector);
6121err_connector_alloc:
6122 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01006123 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02006124}
Dave Airlie0e32b392014-05-02 14:02:48 +10006125
6126void intel_dp_mst_suspend(struct drm_device *dev)
6127{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006128 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006129 int i;
6130
6131 /* disable MST */
6132 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006133 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006134
6135 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006136 continue;
6137
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006138 if (intel_dig_port->dp.is_mst)
6139 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10006140 }
6141}
6142
6143void intel_dp_mst_resume(struct drm_device *dev)
6144{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006145 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10006146 int i;
6147
6148 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03006149 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006150 int ret;
6151
6152 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10006153 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10006154
Ville Syrjälä5aa56962016-06-22 21:57:00 +03006155 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
6156 if (ret)
6157 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10006158 }
6159}