blob: a1b0181f42c4bee807dd981b2c226628323e0a58 [file] [log] [blame]
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Keith Packard <keithp@keithp.com>
25 *
26 */
27
28#include <linux/i2c.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040030#include <linux/export.h>
Clint Taylor01527b32014-07-07 13:01:46 -070031#include <linux/notifier.h>
32#include <linux/reboot.h>
David Howells760285e2012-10-02 18:01:07 +010033#include <drm/drmP.h>
Matt Roperc6f95f22015-01-22 16:50:32 -080034#include <drm/drm_atomic_helper.h>
David Howells760285e2012-10-02 18:01:07 +010035#include <drm/drm_crtc.h>
36#include <drm/drm_crtc_helper.h>
37#include <drm/drm_edid.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070038#include "intel_drv.h"
David Howells760285e2012-10-02 18:01:07 +010039#include <drm/i915_drm.h>
Keith Packarda4fc5ed2009-04-07 16:16:42 -070040#include "i915_drv.h"
Keith Packarda4fc5ed2009-04-07 16:16:42 -070041
Keith Packarda4fc5ed2009-04-07 16:16:42 -070042#define DP_LINK_CHECK_TIMEOUT (10 * 1000)
43
Todd Previte559be302015-05-04 07:48:20 -070044/* Compliance test status bits */
45#define INTEL_DP_RESOLUTION_SHIFT_MASK 0
46#define INTEL_DP_RESOLUTION_PREFERRED (1 << INTEL_DP_RESOLUTION_SHIFT_MASK)
47#define INTEL_DP_RESOLUTION_STANDARD (2 << INTEL_DP_RESOLUTION_SHIFT_MASK)
48#define INTEL_DP_RESOLUTION_FAILSAFE (3 << INTEL_DP_RESOLUTION_SHIFT_MASK)
49
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080050struct dp_link_dpll {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030051 int clock;
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080052 struct dpll dpll;
53};
54
55static const struct dp_link_dpll gen4_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030056 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080057 { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030058 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080059 { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
60};
61
62static const struct dp_link_dpll pch_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030063 { 162000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080064 { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030065 { 270000,
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +080066 { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
67};
68
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080069static const struct dp_link_dpll vlv_dpll[] = {
Ville Syrjälä840b32b2015-08-11 20:21:46 +030070 { 162000,
Chon Ming Lee58f6e632013-09-25 15:47:51 +080071 { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030072 { 270000,
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +080073 { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } }
74};
75
Chon Ming Leeef9348c2014-04-09 13:28:18 +030076/*
77 * CHV supports eDP 1.4 that have more link rates.
78 * Below only provides the fixed rate but exclude variable rate.
79 */
80static const struct dp_link_dpll chv_dpll[] = {
81 /*
82 * CHV requires to program fractional division for m2.
83 * m2 is stored in fixed point format using formula below
84 * (m2_int << 22) | m2_fraction
85 */
Ville Syrjälä840b32b2015-08-11 20:21:46 +030086 { 162000, /* m2_int = 32, m2_fraction = 1677722 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030087 { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030088 { 270000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030089 { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } },
Ville Syrjälä840b32b2015-08-11 20:21:46 +030090 { 540000, /* m2_int = 27, m2_fraction = 0 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +030091 { .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }
92};
Sonika Jindal637a9c62015-05-07 09:52:08 +053093
Sonika Jindal64987fc2015-05-26 17:50:13 +053094static const int bxt_rates[] = { 162000, 216000, 243000, 270000,
95 324000, 432000, 540000 };
Sonika Jindal637a9c62015-05-07 09:52:08 +053096static const int skl_rates[] = { 162000, 216000, 270000,
Ville Syrjäläf4896f12015-03-12 17:10:27 +020097 324000, 432000, 540000 };
98static const int default_rates[] = { 162000, 270000, 540000 };
Chon Ming Leeef9348c2014-04-09 13:28:18 +030099
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700100/**
101 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
102 * @intel_dp: DP struct
103 *
104 * If a CPU or PCH DP output is attached to an eDP panel, this function
105 * will return true, and false otherwise.
106 */
107static bool is_edp(struct intel_dp *intel_dp)
108{
Paulo Zanonida63a9f2012-10-26 19:05:46 -0200109 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
110
111 return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700112}
113
Imre Deak68b4d822013-05-08 13:14:06 +0300114static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp)
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700115{
Imre Deak68b4d822013-05-08 13:14:06 +0300116 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
117
118 return intel_dig_port->base.base.dev;
Jesse Barnescfcb0fc2010-10-07 16:01:06 -0700119}
120
Chris Wilsondf0e9242010-09-09 16:20:55 +0100121static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
122{
Paulo Zanonifa90ece2012-10-26 19:05:44 -0200123 return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
Chris Wilsondf0e9242010-09-09 16:20:55 +0100124}
125
Chris Wilsonea5b2132010-08-04 13:50:23 +0100126static void intel_dp_link_down(struct intel_dp *intel_dp);
Ville Syrjälä1e0560e2014-08-19 13:24:25 +0300127static bool edp_panel_vdd_on(struct intel_dp *intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +0100128static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
Ville Syrjälä093e3f12014-10-16 21:27:33 +0300129static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300130static void vlv_steal_power_sequencer(struct drm_device *dev,
131 enum pipe pipe);
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +0530132static void intel_dp_unset_edid(struct intel_dp *intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700133
Ville Syrjäläed4e9c12015-03-12 17:10:36 +0200134static int
135intel_dp_max_link_bw(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700136{
Jesse Barnes7183dc22011-07-07 11:10:58 -0700137 int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700138
139 switch (max_link_bw) {
140 case DP_LINK_BW_1_62:
141 case DP_LINK_BW_2_7:
Ville Syrjälä1db10e22015-03-12 17:10:32 +0200142 case DP_LINK_BW_5_4:
Imre Deakd4eead52013-07-09 17:05:26 +0300143 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700144 default:
Imre Deakd4eead52013-07-09 17:05:26 +0300145 WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
146 max_link_bw);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700147 max_link_bw = DP_LINK_BW_1_62;
148 break;
149 }
150 return max_link_bw;
151}
152
Paulo Zanonieeb63242014-05-06 14:56:50 +0300153static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
154{
155 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300156 u8 source_max, sink_max;
157
Ville Syrjäläccb1a832015-12-08 19:59:38 +0200158 source_max = intel_dig_port->max_lanes;
Paulo Zanonieeb63242014-05-06 14:56:50 +0300159 sink_max = drm_dp_max_lane_count(intel_dp->dpcd);
160
161 return min(source_max, sink_max);
162}
163
Adam Jacksoncd9dde42011-10-14 12:43:49 -0400164/*
165 * The units on the numbers in the next two are... bizarre. Examples will
166 * make it clearer; this one parallels an example in the eDP spec.
167 *
168 * intel_dp_max_data_rate for one lane of 2.7GHz evaluates as:
169 *
170 * 270000 * 1 * 8 / 10 == 216000
171 *
172 * The actual data capacity of that configuration is 2.16Gbit/s, so the
173 * units are decakilobits. ->clock in a drm_display_mode is in kilohertz -
174 * or equivalently, kilopixels per second - so for 1680x1050R it'd be
175 * 119000. At 18bpp that's 2142000 kilobits per second.
176 *
177 * Thus the strange-looking division by 10 in intel_dp_link_required, to
178 * get the result in decakilobits instead of kilobits.
179 */
180
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700181static int
Keith Packardc8982612012-01-25 08:16:25 -0800182intel_dp_link_required(int pixel_clock, int bpp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700183{
Adam Jacksoncd9dde42011-10-14 12:43:49 -0400184 return (pixel_clock * bpp + 9) / 10;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700185}
186
187static int
Dave Airliefe27d532010-06-30 11:46:17 +1000188intel_dp_max_data_rate(int max_link_clock, int max_lanes)
189{
190 return (max_link_clock * max_lanes * 8) / 10;
191}
192
Mika Kahola70ec0642016-09-09 14:10:55 +0300193static int
194intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp)
195{
196 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
197 struct intel_encoder *encoder = &intel_dig_port->base;
198 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
199 int max_dotclk = dev_priv->max_dotclk_freq;
200 int ds_max_dotclk;
201
202 int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
203
204 if (type != DP_DS_PORT_TYPE_VGA)
205 return max_dotclk;
206
207 ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd,
208 intel_dp->downstream_ports);
209
210 if (ds_max_dotclk != 0)
211 max_dotclk = min(max_dotclk, ds_max_dotclk);
212
213 return max_dotclk;
214}
215
Navare, Manasi D40dba342016-10-26 16:25:55 -0700216static int
217intel_dp_sink_rates(struct intel_dp *intel_dp, const int **sink_rates)
218{
219 if (intel_dp->num_sink_rates) {
220 *sink_rates = intel_dp->sink_rates;
221 return intel_dp->num_sink_rates;
222 }
223
224 *sink_rates = default_rates;
225
226 return (intel_dp_max_link_bw(intel_dp) >> 3) + 1;
227}
228
229static int
230intel_dp_source_rates(struct intel_dp *intel_dp, const int **source_rates)
231{
232 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
233 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
234 int size;
235
236 if (IS_BROXTON(dev_priv)) {
237 *source_rates = bxt_rates;
238 size = ARRAY_SIZE(bxt_rates);
239 } else if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
240 *source_rates = skl_rates;
241 size = ARRAY_SIZE(skl_rates);
242 } else {
243 *source_rates = default_rates;
244 size = ARRAY_SIZE(default_rates);
245 }
246
247 /* This depends on the fact that 5.4 is last value in the array */
248 if (!intel_dp_source_supports_hbr2(intel_dp))
249 size--;
250
251 return size;
252}
253
254static int intersect_rates(const int *source_rates, int source_len,
255 const int *sink_rates, int sink_len,
256 int *common_rates)
257{
258 int i = 0, j = 0, k = 0;
259
260 while (i < source_len && j < sink_len) {
261 if (source_rates[i] == sink_rates[j]) {
262 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
263 return k;
264 common_rates[k] = source_rates[i];
265 ++k;
266 ++i;
267 ++j;
268 } else if (source_rates[i] < sink_rates[j]) {
269 ++i;
270 } else {
271 ++j;
272 }
273 }
274 return k;
275}
276
277static int intel_dp_common_rates(struct intel_dp *intel_dp,
278 int *common_rates)
279{
280 const int *source_rates, *sink_rates;
281 int source_len, sink_len;
282
283 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
284 source_len = intel_dp_source_rates(intel_dp, &source_rates);
285
286 return intersect_rates(source_rates, source_len,
287 sink_rates, sink_len,
288 common_rates);
289}
290
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000291static enum drm_mode_status
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700292intel_dp_mode_valid(struct drm_connector *connector,
293 struct drm_display_mode *mode)
294{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100295 struct intel_dp *intel_dp = intel_attached_dp(connector);
Jani Nikuladd06f902012-10-19 14:51:50 +0300296 struct intel_connector *intel_connector = to_intel_connector(connector);
297 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Daniel Vetter36008362013-03-27 00:44:59 +0100298 int target_clock = mode->clock;
299 int max_rate, mode_rate, max_lanes, max_link_clock;
Mika Kahola70ec0642016-09-09 14:10:55 +0300300 int max_dotclk;
301
302 max_dotclk = intel_dp_downstream_max_dotclock(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700303
Jani Nikuladd06f902012-10-19 14:51:50 +0300304 if (is_edp(intel_dp) && fixed_mode) {
305 if (mode->hdisplay > fixed_mode->hdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100306 return MODE_PANEL;
307
Jani Nikuladd06f902012-10-19 14:51:50 +0300308 if (mode->vdisplay > fixed_mode->vdisplay)
Zhao Yakui7de56f42010-07-19 09:43:14 +0100309 return MODE_PANEL;
Daniel Vetter03afc4a2013-04-02 23:42:31 +0200310
311 target_clock = fixed_mode->clock;
Zhao Yakui7de56f42010-07-19 09:43:14 +0100312 }
313
Ville Syrjälä50fec212015-03-12 17:10:34 +0200314 max_link_clock = intel_dp_max_link_rate(intel_dp);
Paulo Zanonieeb63242014-05-06 14:56:50 +0300315 max_lanes = intel_dp_max_lane_count(intel_dp);
Daniel Vetter36008362013-03-27 00:44:59 +0100316
317 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
318 mode_rate = intel_dp_link_required(target_clock, 18);
319
Mika Kahola799487f2016-02-02 15:16:38 +0200320 if (mode_rate > max_rate || target_clock > max_dotclk)
Daniel Vetterc4867932012-04-10 10:42:36 +0200321 return MODE_CLOCK_HIGH;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700322
323 if (mode->clock < 10000)
324 return MODE_CLOCK_LOW;
325
Daniel Vetter0af78a22012-05-23 11:30:55 +0200326 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
327 return MODE_H_ILLEGAL;
328
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700329 return MODE_OK;
330}
331
Rodrigo Vivia4f12892014-11-14 08:52:27 -0800332uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700333{
334 int i;
335 uint32_t v = 0;
336
337 if (src_bytes > 4)
338 src_bytes = 4;
339 for (i = 0; i < src_bytes; i++)
340 v |= ((uint32_t) src[i]) << ((3-i) * 8);
341 return v;
342}
343
Damien Lespiauc2af70e2015-02-10 19:32:23 +0000344static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700345{
346 int i;
347 if (dst_bytes > 4)
348 dst_bytes = 4;
349 for (i = 0; i < dst_bytes; i++)
350 dst[i] = src >> ((3-i) * 8);
351}
352
Jani Nikulabf13e812013-09-06 07:40:05 +0300353static void
354intel_dp_init_panel_power_sequencer(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300355 struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300356static void
357intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300358 struct intel_dp *intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +0300359static void
360intel_dp_pps_init(struct drm_device *dev, struct intel_dp *intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300361
Ville Syrjälä773538e82014-09-04 14:54:56 +0300362static void pps_lock(struct intel_dp *intel_dp)
363{
364 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
365 struct intel_encoder *encoder = &intel_dig_port->base;
366 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100367 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300368 enum intel_display_power_domain power_domain;
369
370 /*
371 * See vlv_power_sequencer_reset() why we need
372 * a power domain reference here.
373 */
Ville Syrjälä25f78f52015-11-16 15:01:04 +0100374 power_domain = intel_display_port_aux_power_domain(encoder);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300375 intel_display_power_get(dev_priv, power_domain);
376
377 mutex_lock(&dev_priv->pps_mutex);
378}
379
380static void pps_unlock(struct intel_dp *intel_dp)
381{
382 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
383 struct intel_encoder *encoder = &intel_dig_port->base;
384 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100385 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300386 enum intel_display_power_domain power_domain;
387
388 mutex_unlock(&dev_priv->pps_mutex);
389
Ville Syrjälä25f78f52015-11-16 15:01:04 +0100390 power_domain = intel_display_port_aux_power_domain(encoder);
Ville Syrjälä773538e82014-09-04 14:54:56 +0300391 intel_display_power_put(dev_priv, power_domain);
392}
393
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300394static void
395vlv_power_sequencer_kick(struct intel_dp *intel_dp)
396{
397 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200398 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300399 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300400 bool pll_enabled, release_cl_override = false;
401 enum dpio_phy phy = DPIO_PHY(pipe);
402 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300403 uint32_t DP;
404
405 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
406 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
407 pipe_name(pipe), port_name(intel_dig_port->port)))
408 return;
409
410 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
411 pipe_name(pipe), port_name(intel_dig_port->port));
412
413 /* Preserve the BIOS-computed detected bit. This is
414 * supposed to be read-only.
415 */
416 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
417 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
418 DP |= DP_PORT_WIDTH(1);
419 DP |= DP_LINK_TRAIN_PAT_1;
420
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100421 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300422 DP |= DP_PIPE_SELECT_CHV(pipe);
423 else if (pipe == PIPE_B)
424 DP |= DP_PIPEB_SELECT;
425
Ville Syrjäläd288f652014-10-28 13:20:22 +0200426 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
427
428 /*
429 * The DPLL for the pipe must be enabled for this to work.
430 * So enable temporarily it if it's not already enabled.
431 */
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300432 if (!pll_enabled) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100433 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300434 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
435
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200436 if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ?
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000437 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
438 DRM_ERROR("Failed to force on pll for pipe %c!\n",
439 pipe_name(pipe));
440 return;
441 }
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300442 }
Ville Syrjäläd288f652014-10-28 13:20:22 +0200443
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300444 /*
445 * Similar magic as in intel_dp_enable_port().
446 * We _must_ do this port enable + disable trick
447 * to make this power seqeuencer lock onto the port.
448 * Otherwise even VDD force bit won't work.
449 */
450 I915_WRITE(intel_dp->output_reg, DP);
451 POSTING_READ(intel_dp->output_reg);
452
453 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
454 POSTING_READ(intel_dp->output_reg);
455
456 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
457 POSTING_READ(intel_dp->output_reg);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200458
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300459 if (!pll_enabled) {
Ville Syrjälä30ad9812016-10-31 22:37:07 +0200460 vlv_force_pll_off(dev_priv, pipe);
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300461
462 if (release_cl_override)
463 chv_phy_powergate_ch(dev_priv, phy, ch, false);
464 }
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300465}
466
Jani Nikulabf13e812013-09-06 07:40:05 +0300467static enum pipe
468vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
469{
470 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300471 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100472 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300473 struct intel_encoder *encoder;
474 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300475 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300476
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300477 lockdep_assert_held(&dev_priv->pps_mutex);
478
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300479 /* We should never land here with regular DP ports */
480 WARN_ON(!is_edp(intel_dp));
481
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300482 if (intel_dp->pps_pipe != INVALID_PIPE)
483 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300484
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300485 /*
486 * We don't have power sequencer currently.
487 * Pick one that's not used by other ports.
488 */
Jani Nikula19c80542015-12-16 12:48:16 +0200489 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300490 struct intel_dp *tmp;
491
492 if (encoder->type != INTEL_OUTPUT_EDP)
493 continue;
494
495 tmp = enc_to_intel_dp(&encoder->base);
496
497 if (tmp->pps_pipe != INVALID_PIPE)
498 pipes &= ~(1 << tmp->pps_pipe);
499 }
500
501 /*
502 * Didn't find one. This should not happen since there
503 * are two power sequencers and up to two eDP ports.
504 */
505 if (WARN_ON(pipes == 0))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300506 pipe = PIPE_A;
507 else
508 pipe = ffs(pipes) - 1;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300509
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300510 vlv_steal_power_sequencer(dev, pipe);
511 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300512
513 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
514 pipe_name(intel_dp->pps_pipe),
515 port_name(intel_dig_port->port));
516
517 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300518 intel_dp_init_panel_power_sequencer(dev, intel_dp);
519 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300520
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300521 /*
522 * Even vdd force doesn't work until we've made
523 * the power sequencer lock in on the port.
524 */
525 vlv_power_sequencer_kick(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300526
527 return intel_dp->pps_pipe;
528}
529
Imre Deak78597992016-06-16 16:37:20 +0300530static int
531bxt_power_sequencer_idx(struct intel_dp *intel_dp)
532{
533 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
534 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100535 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak78597992016-06-16 16:37:20 +0300536
537 lockdep_assert_held(&dev_priv->pps_mutex);
538
539 /* We should never land here with regular DP ports */
540 WARN_ON(!is_edp(intel_dp));
541
542 /*
543 * TODO: BXT has 2 PPS instances. The correct port->PPS instance
544 * mapping needs to be retrieved from VBT, for now just hard-code to
545 * use instance #0 always.
546 */
547 if (!intel_dp->pps_reset)
548 return 0;
549
550 intel_dp->pps_reset = false;
551
552 /*
553 * Only the HW needs to be reprogrammed, the SW state is fixed and
554 * has been setup during connector init.
555 */
556 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
557
558 return 0;
559}
560
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300561typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
562 enum pipe pipe);
563
564static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
565 enum pipe pipe)
566{
Imre Deak44cb7342016-08-10 14:07:29 +0300567 return I915_READ(PP_STATUS(pipe)) & PP_ON;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300568}
569
570static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
571 enum pipe pipe)
572{
Imre Deak44cb7342016-08-10 14:07:29 +0300573 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300574}
575
576static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
577 enum pipe pipe)
578{
579 return true;
580}
581
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300582static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300583vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
584 enum port port,
585 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300586{
Jani Nikulabf13e812013-09-06 07:40:05 +0300587 enum pipe pipe;
588
Jani Nikulabf13e812013-09-06 07:40:05 +0300589 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
Imre Deak44cb7342016-08-10 14:07:29 +0300590 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
Jani Nikulabf13e812013-09-06 07:40:05 +0300591 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300592
593 if (port_sel != PANEL_PORT_SELECT_VLV(port))
594 continue;
595
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300596 if (!pipe_check(dev_priv, pipe))
597 continue;
598
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300599 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300600 }
601
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300602 return INVALID_PIPE;
603}
604
605static void
606vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
607{
608 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
609 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100610 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300611 enum port port = intel_dig_port->port;
612
613 lockdep_assert_held(&dev_priv->pps_mutex);
614
615 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300616 /* first pick one where the panel is on */
617 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
618 vlv_pipe_has_pp_on);
619 /* didn't find one? pick one where vdd is on */
620 if (intel_dp->pps_pipe == INVALID_PIPE)
621 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
622 vlv_pipe_has_vdd_on);
623 /* didn't find one? pick one with just the correct port */
624 if (intel_dp->pps_pipe == INVALID_PIPE)
625 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
626 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300627
628 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
629 if (intel_dp->pps_pipe == INVALID_PIPE) {
630 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
631 port_name(port));
632 return;
633 }
634
635 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
636 port_name(port), pipe_name(intel_dp->pps_pipe));
637
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300638 intel_dp_init_panel_power_sequencer(dev, intel_dp);
639 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300640}
641
Imre Deak78597992016-06-16 16:37:20 +0300642void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300643{
Chris Wilson91c8a322016-07-05 10:40:23 +0100644 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300645 struct intel_encoder *encoder;
646
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100647 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100648 !IS_BROXTON(dev_priv)))
Ville Syrjälä773538e82014-09-04 14:54:56 +0300649 return;
650
651 /*
652 * We can't grab pps_mutex here due to deadlock with power_domain
653 * mutex when power_domain functions are called while holding pps_mutex.
654 * That also means that in order to use pps_pipe the code needs to
655 * hold both a power domain reference and pps_mutex, and the power domain
656 * reference get/put must be done while _not_ holding pps_mutex.
657 * pps_{lock,unlock}() do these steps in the correct order, so one
658 * should use them always.
659 */
660
Jani Nikula19c80542015-12-16 12:48:16 +0200661 for_each_intel_encoder(dev, encoder) {
Ville Syrjälä773538e82014-09-04 14:54:56 +0300662 struct intel_dp *intel_dp;
663
664 if (encoder->type != INTEL_OUTPUT_EDP)
665 continue;
666
667 intel_dp = enc_to_intel_dp(&encoder->base);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100668 if (IS_BROXTON(dev_priv))
Imre Deak78597992016-06-16 16:37:20 +0300669 intel_dp->pps_reset = true;
670 else
671 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300672 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300673}
674
Imre Deak8e8232d2016-06-16 16:37:21 +0300675struct pps_registers {
676 i915_reg_t pp_ctrl;
677 i915_reg_t pp_stat;
678 i915_reg_t pp_on;
679 i915_reg_t pp_off;
680 i915_reg_t pp_div;
681};
682
683static void intel_pps_get_registers(struct drm_i915_private *dev_priv,
684 struct intel_dp *intel_dp,
685 struct pps_registers *regs)
686{
Imre Deak44cb7342016-08-10 14:07:29 +0300687 int pps_idx = 0;
688
Imre Deak8e8232d2016-06-16 16:37:21 +0300689 memset(regs, 0, sizeof(*regs));
690
Imre Deak44cb7342016-08-10 14:07:29 +0300691 if (IS_BROXTON(dev_priv))
692 pps_idx = bxt_power_sequencer_idx(intel_dp);
693 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
694 pps_idx = vlv_power_sequencer_pipe(intel_dp);
Imre Deak8e8232d2016-06-16 16:37:21 +0300695
Imre Deak44cb7342016-08-10 14:07:29 +0300696 regs->pp_ctrl = PP_CONTROL(pps_idx);
697 regs->pp_stat = PP_STATUS(pps_idx);
698 regs->pp_on = PP_ON_DELAYS(pps_idx);
699 regs->pp_off = PP_OFF_DELAYS(pps_idx);
700 if (!IS_BROXTON(dev_priv))
701 regs->pp_div = PP_DIVISOR(pps_idx);
Imre Deak8e8232d2016-06-16 16:37:21 +0300702}
703
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200704static i915_reg_t
705_pp_ctrl_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300706{
Imre Deak8e8232d2016-06-16 16:37:21 +0300707 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300708
Imre Deak8e8232d2016-06-16 16:37:21 +0300709 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
710 &regs);
711
712 return regs.pp_ctrl;
Jani Nikulabf13e812013-09-06 07:40:05 +0300713}
714
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200715static i915_reg_t
716_pp_stat_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300717{
Imre Deak8e8232d2016-06-16 16:37:21 +0300718 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300719
Imre Deak8e8232d2016-06-16 16:37:21 +0300720 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
721 &regs);
722
723 return regs.pp_stat;
Jani Nikulabf13e812013-09-06 07:40:05 +0300724}
725
Clint Taylor01527b32014-07-07 13:01:46 -0700726/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
727 This function only applicable when panel PM state is not to be tracked */
728static int edp_notify_handler(struct notifier_block *this, unsigned long code,
729 void *unused)
730{
731 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
732 edp_notifier);
733 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100734 struct drm_i915_private *dev_priv = to_i915(dev);
Clint Taylor01527b32014-07-07 13:01:46 -0700735
736 if (!is_edp(intel_dp) || code != SYS_RESTART)
737 return 0;
738
Ville Syrjälä773538e82014-09-04 14:54:56 +0300739 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300740
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100741 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300742 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200743 i915_reg_t pp_ctrl_reg, pp_div_reg;
Ville Syrjälä649636e2015-09-22 19:50:01 +0300744 u32 pp_div;
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300745
Imre Deak44cb7342016-08-10 14:07:29 +0300746 pp_ctrl_reg = PP_CONTROL(pipe);
747 pp_div_reg = PP_DIVISOR(pipe);
Clint Taylor01527b32014-07-07 13:01:46 -0700748 pp_div = I915_READ(pp_div_reg);
749 pp_div &= PP_REFERENCE_DIVIDER_MASK;
750
751 /* 0x1F write to PP_DIV_REG sets max cycle delay */
752 I915_WRITE(pp_div_reg, pp_div | 0x1F);
753 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
754 msleep(intel_dp->panel_power_cycle_delay);
755 }
756
Ville Syrjälä773538e82014-09-04 14:54:56 +0300757 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300758
Clint Taylor01527b32014-07-07 13:01:46 -0700759 return 0;
760}
761
Daniel Vetter4be73782014-01-17 14:39:48 +0100762static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700763{
Paulo Zanoni30add222012-10-26 19:05:45 -0200764 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100765 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700766
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300767 lockdep_assert_held(&dev_priv->pps_mutex);
768
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100769 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300770 intel_dp->pps_pipe == INVALID_PIPE)
771 return false;
772
Jani Nikulabf13e812013-09-06 07:40:05 +0300773 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700774}
775
Daniel Vetter4be73782014-01-17 14:39:48 +0100776static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700777{
Paulo Zanoni30add222012-10-26 19:05:45 -0200778 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100779 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700780
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300781 lockdep_assert_held(&dev_priv->pps_mutex);
782
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100783 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300784 intel_dp->pps_pipe == INVALID_PIPE)
785 return false;
786
Ville Syrjälä773538e82014-09-04 14:54:56 +0300787 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700788}
789
Keith Packard9b984da2011-09-19 13:54:47 -0700790static void
791intel_dp_check_edp(struct intel_dp *intel_dp)
792{
Paulo Zanoni30add222012-10-26 19:05:45 -0200793 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100794 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700795
Keith Packard9b984da2011-09-19 13:54:47 -0700796 if (!is_edp(intel_dp))
797 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700798
Daniel Vetter4be73782014-01-17 14:39:48 +0100799 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700800 WARN(1, "eDP powered off while attempting aux channel communication.\n");
801 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300802 I915_READ(_pp_stat_reg(intel_dp)),
803 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700804 }
805}
806
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100807static uint32_t
808intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
809{
810 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
811 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100812 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200813 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100814 uint32_t status;
815 bool done;
816
Daniel Vetteref04f002012-12-01 21:03:59 +0100817#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100818 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300819 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300820 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100821 else
Imre Deak713a6b662016-06-28 13:37:33 +0300822 done = wait_for(C, 10) == 0;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100823 if (!done)
824 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
825 has_aux_irq);
826#undef C
827
828 return status;
829}
830
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200831static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000832{
833 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200834 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000835
Ville Syrjäläa457f542016-03-02 17:22:17 +0200836 if (index)
837 return 0;
838
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000839 /*
840 * The clock divider is based off the hrawclk, and would like to run at
Ville Syrjäläa457f542016-03-02 17:22:17 +0200841 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000842 */
Ville Syrjäläa457f542016-03-02 17:22:17 +0200843 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000844}
845
846static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
847{
848 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200849 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000850
851 if (index)
852 return 0;
853
Ville Syrjäläa457f542016-03-02 17:22:17 +0200854 /*
855 * The clock divider is based off the cdclk or PCH rawclk, and would
856 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
857 * divide by 2000 and use that
858 */
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200859 if (intel_dig_port->port == PORT_A)
Ville Syrjäläfce18c42015-11-30 16:23:46 +0200860 return DIV_ROUND_CLOSEST(dev_priv->cdclk_freq, 2000);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200861 else
862 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000863}
864
865static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300866{
867 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200868 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300869
Ville Syrjäläa457f542016-03-02 17:22:17 +0200870 if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300871 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100872 switch (index) {
873 case 0: return 63;
874 case 1: return 72;
875 default: return 0;
876 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300877 }
Ville Syrjäläa457f542016-03-02 17:22:17 +0200878
879 return ilk_get_aux_clock_divider(intel_dp, index);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300880}
881
Damien Lespiaub6b5e382014-01-20 16:00:59 +0000882static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
883{
884 /*
885 * SKL doesn't need us to program the AUX clock divider (Hardware will
886 * derive the clock from CDCLK automatically). We still implement the
887 * get_aux_clock_divider vfunc to plug-in into the existing code.
888 */
889 return index ? 0 : 1;
890}
891
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200892static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
893 bool has_aux_irq,
894 int send_bytes,
895 uint32_t aux_clock_divider)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000896{
897 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100898 struct drm_i915_private *dev_priv =
899 to_i915(intel_dig_port->base.base.dev);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000900 uint32_t precharge, timeout;
901
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100902 if (IS_GEN6(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000903 precharge = 3;
904 else
905 precharge = 5;
906
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100907 if (IS_BROADWELL(dev_priv) && intel_dig_port->port == PORT_A)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000908 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
909 else
910 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
911
912 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +0000913 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000914 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000915 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000916 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +0000917 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000918 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
919 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000920 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000921}
922
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000923static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
924 bool has_aux_irq,
925 int send_bytes,
926 uint32_t unused)
927{
928 return DP_AUX_CH_CTL_SEND_BUSY |
929 DP_AUX_CH_CTL_DONE |
930 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
931 DP_AUX_CH_CTL_TIME_OUT_ERROR |
932 DP_AUX_CH_CTL_TIME_OUT_1600us |
933 DP_AUX_CH_CTL_RECEIVE_ERROR |
934 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Daniel Vetterd4dcbdc2016-05-18 18:47:15 +0200935 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000936 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
937}
938
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700939static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100940intel_dp_aux_ch(struct intel_dp *intel_dp,
Daniel Vetterbd9f74a2014-10-02 09:45:35 +0200941 const uint8_t *send, int send_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700942 uint8_t *recv, int recv_size)
943{
Paulo Zanoni174edf12012-10-26 19:05:50 -0200944 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +0000945 struct drm_i915_private *dev_priv =
946 to_i915(intel_dig_port->base.base.dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200947 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Chris Wilsonbc866252013-07-21 16:00:03 +0100948 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100949 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700950 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000951 int try, clock = 0;
Tvrtko Ursulin0031fb92016-11-04 14:42:44 +0000952 bool has_aux_irq = HAS_AUX_IRQ(dev_priv);
Jani Nikula884f19e2014-03-14 16:51:14 +0200953 bool vdd;
954
Ville Syrjälä773538e82014-09-04 14:54:56 +0300955 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300956
Ville Syrjälä72c35002014-08-18 22:16:00 +0300957 /*
958 * We will be called with VDD already enabled for dpcd/edid/oui reads.
959 * In such cases we want to leave VDD enabled and it's up to upper layers
960 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
961 * ourselves.
962 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +0300963 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100964
965 /* dp aux is extremely sensitive to irq latency, hence request the
966 * lowest possible wakeup latency and so prevent the cpu from going into
967 * deep sleep states.
968 */
969 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700970
Keith Packard9b984da2011-09-19 13:54:47 -0700971 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +0800972
Jesse Barnes11bee432011-08-01 15:02:20 -0700973 /* Try to wait for any previous AUX channel activity */
974 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +0100975 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -0700976 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
977 break;
978 msleep(1);
979 }
980
981 if (try == 3) {
Mika Kuoppala02196c72015-08-06 16:48:58 +0300982 static u32 last_status = -1;
983 const u32 status = I915_READ(ch_ctl);
984
985 if (status != last_status) {
986 WARN(1, "dp_aux_ch not started status 0x%08x\n",
987 status);
988 last_status = status;
989 }
990
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100991 ret = -EBUSY;
992 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100993 }
994
Paulo Zanoni46a5ae92013-09-17 11:14:10 -0300995 /* Only 5 data registers! */
996 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
997 ret = -E2BIG;
998 goto out;
999 }
1000
Damien Lespiauec5b01d2014-01-21 13:35:39 +00001001 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +00001002 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
1003 has_aux_irq,
1004 send_bytes,
1005 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001006
Chris Wilsonbc866252013-07-21 16:00:03 +01001007 /* Must try at least 3 times according to DP spec */
1008 for (try = 0; try < 5; try++) {
1009 /* Load the send data into the aux channel data registers */
1010 for (i = 0; i < send_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001011 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001012 intel_dp_pack_aux(send + i,
1013 send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -04001014
Chris Wilsonbc866252013-07-21 16:00:03 +01001015 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001016 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001017
Chris Wilsonbc866252013-07-21 16:00:03 +01001018 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -04001019
Chris Wilsonbc866252013-07-21 16:00:03 +01001020 /* Clear done status and any errors */
1021 I915_WRITE(ch_ctl,
1022 status |
1023 DP_AUX_CH_CTL_DONE |
1024 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1025 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -04001026
Todd Previte74ebf292015-04-15 08:38:41 -07001027 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
Chris Wilsonbc866252013-07-21 16:00:03 +01001028 continue;
Todd Previte74ebf292015-04-15 08:38:41 -07001029
1030 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
1031 * 400us delay required for errors and timeouts
1032 * Timeout errors from the HW already meet this
1033 * requirement so skip to next iteration
1034 */
1035 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1036 usleep_range(400, 500);
1037 continue;
1038 }
Chris Wilsonbc866252013-07-21 16:00:03 +01001039 if (status & DP_AUX_CH_CTL_DONE)
Jim Bridee058c942015-05-27 10:21:48 -07001040 goto done;
Chris Wilsonbc866252013-07-21 16:00:03 +01001041 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001042 }
1043
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001044 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001045 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001046 ret = -EBUSY;
1047 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001048 }
1049
Jim Bridee058c942015-05-27 10:21:48 -07001050done:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001051 /* Check for timeout or receive error.
1052 * Timeouts occur when the sink is not connected
1053 */
Keith Packarda5b3da52009-06-11 22:30:32 -07001054 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001055 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001056 ret = -EIO;
1057 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -07001058 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001059
1060 /* Timeouts occur when the device isn't connected, so they're
1061 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -07001062 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Zhao Yakui28c97732009-10-09 11:39:41 +08001063 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001064 ret = -ETIMEDOUT;
1065 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001066 }
1067
1068 /* Unload any bytes sent back from the other side */
1069 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
1070 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Rodrigo Vivi14e01882015-12-10 11:12:27 -08001071
1072 /*
1073 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1074 * We have no idea of what happened so we return -EBUSY so
1075 * drm layer takes care for the necessary retries.
1076 */
1077 if (recv_bytes == 0 || recv_bytes > 20) {
1078 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1079 recv_bytes);
1080 /*
1081 * FIXME: This patch was created on top of a series that
1082 * organize the retries at drm level. There EBUSY should
1083 * also take care for 1ms wait before retrying.
1084 * That aux retries re-org is still needed and after that is
1085 * merged we remove this sleep from here.
1086 */
1087 usleep_range(1000, 1500);
1088 ret = -EBUSY;
1089 goto out;
1090 }
1091
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001092 if (recv_bytes > recv_size)
1093 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -04001094
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001095 for (i = 0; i < recv_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001096 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001097 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001098
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001099 ret = recv_bytes;
1100out:
1101 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1102
Jani Nikula884f19e2014-03-14 16:51:14 +02001103 if (vdd)
1104 edp_panel_vdd_off(intel_dp, false);
1105
Ville Syrjälä773538e82014-09-04 14:54:56 +03001106 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001107
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001108 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001109}
1110
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001111#define BARE_ADDRESS_SIZE 3
1112#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +02001113static ssize_t
1114intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001115{
Jani Nikula9d1a1032014-03-14 16:51:15 +02001116 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1117 uint8_t txbuf[20], rxbuf[20];
1118 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001119 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001120
Ville Syrjäläd2d9cbb2015-03-19 11:44:06 +02001121 txbuf[0] = (msg->request << 4) |
1122 ((msg->address >> 16) & 0xf);
1123 txbuf[1] = (msg->address >> 8) & 0xff;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001124 txbuf[2] = msg->address & 0xff;
1125 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001126
Jani Nikula9d1a1032014-03-14 16:51:15 +02001127 switch (msg->request & ~DP_AUX_I2C_MOT) {
1128 case DP_AUX_NATIVE_WRITE:
1129 case DP_AUX_I2C_WRITE:
Ville Syrjäläc1e741222015-08-27 17:23:27 +03001130 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001131 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001132 rxsize = 2; /* 0 or 1 data bytes */
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001133
Jani Nikula9d1a1032014-03-14 16:51:15 +02001134 if (WARN_ON(txsize > 20))
1135 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001136
Ville Syrjälädd788092016-07-28 17:55:04 +03001137 WARN_ON(!msg->buffer != !msg->size);
1138
Imre Deakd81a67c2016-01-29 14:52:26 +02001139 if (msg->buffer)
1140 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001141
Jani Nikula9d1a1032014-03-14 16:51:15 +02001142 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1143 if (ret > 0) {
1144 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001145
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001146 if (ret > 1) {
1147 /* Number of bytes written in a short write. */
1148 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1149 } else {
1150 /* Return payload size. */
1151 ret = msg->size;
1152 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001153 }
Jani Nikula9d1a1032014-03-14 16:51:15 +02001154 break;
1155
1156 case DP_AUX_NATIVE_READ:
1157 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001158 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001159 rxsize = msg->size + 1;
1160
1161 if (WARN_ON(rxsize > 20))
1162 return -E2BIG;
1163
1164 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1165 if (ret > 0) {
1166 msg->reply = rxbuf[0] >> 4;
1167 /*
1168 * Assume happy day, and copy the data. The caller is
1169 * expected to check msg->reply before touching it.
1170 *
1171 * Return payload size.
1172 */
1173 ret--;
1174 memcpy(msg->buffer, rxbuf + 1, ret);
1175 }
1176 break;
1177
1178 default:
1179 ret = -EINVAL;
1180 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001181 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001182
Jani Nikula9d1a1032014-03-14 16:51:15 +02001183 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001184}
1185
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001186static enum port intel_aux_port(struct drm_i915_private *dev_priv,
1187 enum port port)
1188{
1189 const struct ddi_vbt_port_info *info =
1190 &dev_priv->vbt.ddi_port_info[port];
1191 enum port aux_port;
1192
1193 if (!info->alternate_aux_channel) {
1194 DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
1195 port_name(port), port_name(port));
1196 return port;
1197 }
1198
1199 switch (info->alternate_aux_channel) {
1200 case DP_AUX_A:
1201 aux_port = PORT_A;
1202 break;
1203 case DP_AUX_B:
1204 aux_port = PORT_B;
1205 break;
1206 case DP_AUX_C:
1207 aux_port = PORT_C;
1208 break;
1209 case DP_AUX_D:
1210 aux_port = PORT_D;
1211 break;
1212 default:
1213 MISSING_CASE(info->alternate_aux_channel);
1214 aux_port = PORT_A;
1215 break;
1216 }
1217
1218 DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
1219 port_name(aux_port), port_name(port));
1220
1221 return aux_port;
1222}
1223
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001224static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001225 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001226{
1227 switch (port) {
1228 case PORT_B:
1229 case PORT_C:
1230 case PORT_D:
1231 return DP_AUX_CH_CTL(port);
1232 default:
1233 MISSING_CASE(port);
1234 return DP_AUX_CH_CTL(PORT_B);
1235 }
1236}
1237
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001238static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001239 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001240{
1241 switch (port) {
1242 case PORT_B:
1243 case PORT_C:
1244 case PORT_D:
1245 return DP_AUX_CH_DATA(port, index);
1246 default:
1247 MISSING_CASE(port);
1248 return DP_AUX_CH_DATA(PORT_B, index);
1249 }
1250}
1251
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001252static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001253 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001254{
1255 switch (port) {
1256 case PORT_A:
1257 return DP_AUX_CH_CTL(port);
1258 case PORT_B:
1259 case PORT_C:
1260 case PORT_D:
1261 return PCH_DP_AUX_CH_CTL(port);
1262 default:
1263 MISSING_CASE(port);
1264 return DP_AUX_CH_CTL(PORT_A);
1265 }
1266}
1267
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001268static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001269 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001270{
1271 switch (port) {
1272 case PORT_A:
1273 return DP_AUX_CH_DATA(port, index);
1274 case PORT_B:
1275 case PORT_C:
1276 case PORT_D:
1277 return PCH_DP_AUX_CH_DATA(port, index);
1278 default:
1279 MISSING_CASE(port);
1280 return DP_AUX_CH_DATA(PORT_A, index);
1281 }
1282}
1283
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001284static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001285 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001286{
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001287 switch (port) {
1288 case PORT_A:
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_A);
1296 }
1297}
1298
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001299static i915_reg_t skl_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{
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001302 switch (port) {
1303 case PORT_A:
1304 case PORT_B:
1305 case PORT_C:
1306 case PORT_D:
1307 return DP_AUX_CH_DATA(port, index);
1308 default:
1309 MISSING_CASE(port);
1310 return DP_AUX_CH_DATA(PORT_A, index);
1311 }
1312}
1313
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001314static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001315 enum port port)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001316{
1317 if (INTEL_INFO(dev_priv)->gen >= 9)
1318 return skl_aux_ctl_reg(dev_priv, port);
1319 else if (HAS_PCH_SPLIT(dev_priv))
1320 return ilk_aux_ctl_reg(dev_priv, port);
1321 else
1322 return g4x_aux_ctl_reg(dev_priv, port);
1323}
1324
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001325static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001326 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001327{
1328 if (INTEL_INFO(dev_priv)->gen >= 9)
1329 return skl_aux_data_reg(dev_priv, port, index);
1330 else if (HAS_PCH_SPLIT(dev_priv))
1331 return ilk_aux_data_reg(dev_priv, port, index);
1332 else
1333 return g4x_aux_data_reg(dev_priv, port, index);
1334}
1335
1336static void intel_aux_reg_init(struct intel_dp *intel_dp)
1337{
1338 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001339 enum port port = intel_aux_port(dev_priv,
1340 dp_to_dig_port(intel_dp)->port);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001341 int i;
1342
1343 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1344 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1345 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1346}
1347
Jani Nikula9d1a1032014-03-14 16:51:15 +02001348static void
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001349intel_dp_aux_fini(struct intel_dp *intel_dp)
1350{
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001351 kfree(intel_dp->aux.name);
1352}
1353
Chris Wilson7a418e32016-06-24 14:00:14 +01001354static void
Mika Kaholab6339582016-09-09 14:10:52 +03001355intel_dp_aux_init(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001356{
Jani Nikula33ad6622014-03-14 16:51:16 +02001357 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1358 enum port port = intel_dig_port->port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001359
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001360 intel_aux_reg_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01001361 drm_dp_aux_init(&intel_dp->aux);
David Flynn8316f332010-12-08 16:10:21 +00001362
Chris Wilson7a418e32016-06-24 14:00:14 +01001363 /* Failure to allocate our preferred name is not critical */
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001364 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
Jani Nikula9d1a1032014-03-14 16:51:15 +02001365 intel_dp->aux.transfer = intel_dp_aux_transfer;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001366}
1367
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001368bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301369{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001370 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Navare, Manasi D577c5432016-09-27 16:36:53 -07001371 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001372
Navare, Manasi D577c5432016-09-27 16:36:53 -07001373 if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
1374 IS_BROADWELL(dev_priv) || (INTEL_GEN(dev_priv) >= 9))
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301375 return true;
1376 else
1377 return false;
1378}
1379
Daniel Vetter0e503382014-07-04 11:26:04 -03001380static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001381intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001382 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001383{
1384 struct drm_device *dev = encoder->base.dev;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001385 struct drm_i915_private *dev_priv = to_i915(dev);
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001386 const struct dp_link_dpll *divisor = NULL;
1387 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001388
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001389 if (IS_G4X(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001390 divisor = gen4_dpll;
1391 count = ARRAY_SIZE(gen4_dpll);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001392 } else if (HAS_PCH_SPLIT(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001393 divisor = pch_dpll;
1394 count = ARRAY_SIZE(pch_dpll);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001395 } else if (IS_CHERRYVIEW(dev_priv)) {
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001396 divisor = chv_dpll;
1397 count = ARRAY_SIZE(chv_dpll);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001398 } else if (IS_VALLEYVIEW(dev_priv)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001399 divisor = vlv_dpll;
1400 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001401 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001402
1403 if (divisor && count) {
1404 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001405 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001406 pipe_config->dpll = divisor[i].dpll;
1407 pipe_config->clock_set = true;
1408 break;
1409 }
1410 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001411 }
1412}
1413
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001414static void snprintf_int_array(char *str, size_t len,
1415 const int *array, int nelem)
1416{
1417 int i;
1418
1419 str[0] = '\0';
1420
1421 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001422 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001423 if (r >= len)
1424 return;
1425 str += r;
1426 len -= r;
1427 }
1428}
1429
1430static void intel_dp_print_rates(struct intel_dp *intel_dp)
1431{
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001432 const int *source_rates, *sink_rates;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001433 int source_len, sink_len, common_len;
1434 int common_rates[DP_MAX_SUPPORTED_RATES];
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001435 char str[128]; /* FIXME: too big for stack? */
1436
1437 if ((drm_debug & DRM_UT_KMS) == 0)
1438 return;
1439
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001440 source_len = intel_dp_source_rates(intel_dp, &source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001441 snprintf_int_array(str, sizeof(str), source_rates, source_len);
1442 DRM_DEBUG_KMS("source rates: %s\n", str);
1443
1444 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
1445 snprintf_int_array(str, sizeof(str), sink_rates, sink_len);
1446 DRM_DEBUG_KMS("sink rates: %s\n", str);
1447
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001448 common_len = intel_dp_common_rates(intel_dp, common_rates);
1449 snprintf_int_array(str, sizeof(str), common_rates, common_len);
1450 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001451}
1452
Imre Deak489375c2016-10-24 19:33:31 +03001453bool
Imre Deak7b3fc172016-10-25 16:12:39 +03001454__intel_dp_read_desc(struct intel_dp *intel_dp, struct intel_dp_desc *desc)
Mika Kahola0e390a32016-09-09 14:10:53 +03001455{
Imre Deak7b3fc172016-10-25 16:12:39 +03001456 u32 base = drm_dp_is_branch(intel_dp->dpcd) ? DP_BRANCH_OUI :
1457 DP_SINK_OUI;
Mika Kahola0e390a32016-09-09 14:10:53 +03001458
Imre Deak7b3fc172016-10-25 16:12:39 +03001459 return drm_dp_dpcd_read(&intel_dp->aux, base, desc, sizeof(*desc)) ==
1460 sizeof(*desc);
Mika Kahola0e390a32016-09-09 14:10:53 +03001461}
1462
Imre Deak12a47a422016-10-24 19:33:29 +03001463bool intel_dp_read_desc(struct intel_dp *intel_dp)
Mika Kahola1a2724f2016-09-09 14:10:54 +03001464{
Imre Deak7b3fc172016-10-25 16:12:39 +03001465 struct intel_dp_desc *desc = &intel_dp->desc;
1466 bool oui_sup = intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] &
1467 DP_OUI_SUPPORT;
1468 int dev_id_len;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001469
Imre Deak7b3fc172016-10-25 16:12:39 +03001470 if (!__intel_dp_read_desc(intel_dp, desc))
1471 return false;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001472
Imre Deak7b3fc172016-10-25 16:12:39 +03001473 dev_id_len = strnlen(desc->device_id, sizeof(desc->device_id));
1474 DRM_DEBUG_KMS("DP %s: OUI %*phD%s dev-ID %*pE HW-rev %d.%d SW-rev %d.%d\n",
1475 drm_dp_is_branch(intel_dp->dpcd) ? "branch" : "sink",
1476 (int)sizeof(desc->oui), desc->oui, oui_sup ? "" : "(NS)",
1477 dev_id_len, desc->device_id,
1478 desc->hw_rev >> 4, desc->hw_rev & 0xf,
1479 desc->sw_major_rev, desc->sw_minor_rev);
Mika Kahola1a2724f2016-09-09 14:10:54 +03001480
Imre Deak7b3fc172016-10-25 16:12:39 +03001481 return true;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001482}
1483
Ville Syrjäläf4896f12015-03-12 17:10:27 +02001484static int rate_to_index(int find, const int *rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301485{
1486 int i = 0;
1487
1488 for (i = 0; i < DP_MAX_SUPPORTED_RATES; ++i)
1489 if (find == rates[i])
1490 break;
1491
1492 return i;
1493}
1494
Ville Syrjälä50fec212015-03-12 17:10:34 +02001495int
1496intel_dp_max_link_rate(struct intel_dp *intel_dp)
1497{
1498 int rates[DP_MAX_SUPPORTED_RATES] = {};
1499 int len;
1500
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001501 len = intel_dp_common_rates(intel_dp, rates);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001502 if (WARN_ON(len <= 0))
1503 return 162000;
1504
Ville Syrjälä1354f732016-07-28 17:50:45 +03001505 return rates[len - 1];
Ville Syrjälä50fec212015-03-12 17:10:34 +02001506}
1507
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001508int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1509{
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001510 return rate_to_index(rate, intel_dp->sink_rates);
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001511}
1512
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001513void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1514 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001515{
1516 if (intel_dp->num_sink_rates) {
1517 *link_bw = 0;
1518 *rate_select =
1519 intel_dp_rate_select(intel_dp, port_clock);
1520 } else {
1521 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1522 *rate_select = 0;
1523 }
1524}
1525
Jani Nikulaf580bea2016-09-15 16:28:52 +03001526static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1527 struct intel_crtc_state *pipe_config)
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001528{
1529 int bpp, bpc;
1530
1531 bpp = pipe_config->pipe_bpp;
1532 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1533
1534 if (bpc > 0)
1535 bpp = min(bpp, 3*bpc);
1536
1537 return bpp;
1538}
1539
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001540bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001541intel_dp_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001542 struct intel_crtc_state *pipe_config,
1543 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001544{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001545 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001546 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001547 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001548 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001549 enum port port = dp_to_dig_port(intel_dp)->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001550 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001551 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001552 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001553 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001554 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001555 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001556 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301557 int max_clock;
Daniel Vetter083f9562012-04-20 20:23:49 +02001558 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001559 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001560 int common_rates[DP_MAX_SUPPORTED_RATES] = {};
1561 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001562 uint8_t link_bw, rate_select;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301563
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001564 common_len = intel_dp_common_rates(intel_dp, common_rates);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301565
1566 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001567 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301568
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001569 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001570
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001571 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001572 pipe_config->has_pch_encoder = true;
1573
Vandana Kannanf769cd22014-08-05 07:51:22 -07001574 pipe_config->has_drrs = false;
Jani Nikula9fcb1702015-05-05 16:32:12 +03001575 pipe_config->has_audio = intel_dp->has_audio && port != PORT_A;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001576
Jani Nikuladd06f902012-10-19 14:51:50 +03001577 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1578 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
1579 adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001580
1581 if (INTEL_INFO(dev)->gen >= 9) {
1582 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001583 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001584 if (ret)
1585 return ret;
1586 }
1587
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001588 if (HAS_GMCH_DISPLAY(dev_priv))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001589 intel_gmch_panel_fitting(intel_crtc, pipe_config,
1590 intel_connector->panel.fitting_mode);
1591 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001592 intel_pch_panel_fitting(intel_crtc, pipe_config,
1593 intel_connector->panel.fitting_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001594 }
1595
Daniel Vettercb1793c2012-06-04 18:39:21 +02001596 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001597 return false;
1598
Daniel Vetter083f9562012-04-20 20:23:49 +02001599 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301600 "max bw %d pixel clock %iKHz\n",
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001601 max_lane_count, common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001602 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001603
Daniel Vetter36008362013-03-27 00:44:59 +01001604 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1605 * bpc in between. */
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001606 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
Jani Nikula56071a22014-05-06 14:56:52 +03001607 if (is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301608
1609 /* Get bpp from vbt only for panels that dont have bpp in edid */
1610 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001611 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001612 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001613 dev_priv->vbt.edp.bpp);
1614 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001615 }
1616
Jani Nikula344c5bb2014-09-09 11:25:13 +03001617 /*
1618 * Use the maximum clock and number of lanes the eDP panel
1619 * advertizes being capable of. The panels are generally
1620 * designed to support only a single clock and lane
1621 * configuration, and typically these values correspond to the
1622 * native resolution of the panel.
1623 */
1624 min_lane_count = max_lane_count;
1625 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001626 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001627
Daniel Vetter36008362013-03-27 00:44:59 +01001628 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001629 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1630 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001631
Dave Airliec6930992014-07-14 11:04:39 +10001632 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301633 for (lane_count = min_lane_count;
1634 lane_count <= max_lane_count;
1635 lane_count <<= 1) {
1636
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001637 link_clock = common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001638 link_avail = intel_dp_max_data_rate(link_clock,
1639 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001640
Daniel Vetter36008362013-03-27 00:44:59 +01001641 if (mode_rate <= link_avail) {
1642 goto found;
1643 }
1644 }
1645 }
1646 }
1647
1648 return false;
1649
1650found:
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001651 if (intel_dp->color_range_auto) {
1652 /*
1653 * See:
1654 * CEA-861-E - 5.1 Default Encoding Parameters
1655 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1656 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001657 pipe_config->limited_color_range =
1658 bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1;
1659 } else {
1660 pipe_config->limited_color_range =
1661 intel_dp->limited_color_range;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001662 }
1663
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001664 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301665
Daniel Vetter657445f2013-05-04 10:09:18 +02001666 pipe_config->pipe_bpp = bpp;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001667 pipe_config->port_clock = common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001668
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001669 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1670 &link_bw, &rate_select);
1671
1672 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1673 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001674 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001675 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1676 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001677
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001678 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001679 adjusted_mode->crtc_clock,
1680 pipe_config->port_clock,
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001681 &pipe_config->dp_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001682
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301683 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301684 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001685 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301686 intel_link_compute_m_n(bpp, lane_count,
1687 intel_connector->panel.downclock_mode->clock,
1688 pipe_config->port_clock,
1689 &pipe_config->dp_m2_n2);
1690 }
1691
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001692 /*
1693 * DPLL0 VCO may need to be adjusted to get the correct
1694 * clock for eDP. This will affect cdclk as well.
1695 */
1696 if (is_edp(intel_dp) &&
1697 (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))) {
1698 int vco;
1699
1700 switch (pipe_config->port_clock / 2) {
1701 case 108000:
1702 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001703 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001704 break;
1705 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001706 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001707 break;
1708 }
1709
1710 to_intel_atomic_state(pipe_config->base.state)->cdclk_pll_vco = vco;
1711 }
1712
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001713 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001714 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001715
Daniel Vetter36008362013-03-27 00:44:59 +01001716 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001717}
1718
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001719void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001720 int link_rate, uint8_t lane_count,
1721 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001722{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001723 intel_dp->link_rate = link_rate;
1724 intel_dp->lane_count = lane_count;
1725 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001726}
1727
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001728static void intel_dp_prepare(struct intel_encoder *encoder,
1729 struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001730{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001731 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001732 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001733 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001734 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001735 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001736 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001737
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001738 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1739 pipe_config->lane_count,
1740 intel_crtc_has_type(pipe_config,
1741 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001742
Keith Packard417e8222011-11-01 19:54:11 -07001743 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001744 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001745 *
1746 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001747 * SNB CPU
1748 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001749 * CPT PCH
1750 *
1751 * IBX PCH and CPU are the same for almost everything,
1752 * except that the CPU DP PLL is configured in this
1753 * register
1754 *
1755 * CPT PCH is quite different, having many bits moved
1756 * to the TRANS_DP_CTL register instead. That
1757 * configuration happens (oddly) in ironlake_pch_enable
1758 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001759
Keith Packard417e8222011-11-01 19:54:11 -07001760 /* Preserve the BIOS-computed detected bit. This is
1761 * supposed to be read-only.
1762 */
1763 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001764
Keith Packard417e8222011-11-01 19:54:11 -07001765 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001766 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001767 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001768
Keith Packard417e8222011-11-01 19:54:11 -07001769 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001770
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001771 if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001772 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1773 intel_dp->DP |= DP_SYNC_HS_HIGH;
1774 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1775 intel_dp->DP |= DP_SYNC_VS_HIGH;
1776 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1777
Jani Nikula6aba5b62013-10-04 15:08:10 +03001778 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001779 intel_dp->DP |= DP_ENHANCED_FRAMING;
1780
Daniel Vetter7c62a162013-06-01 17:16:20 +02001781 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001782 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001783 u32 trans_dp;
1784
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001785 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001786
1787 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1788 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1789 trans_dp |= TRANS_DP_ENH_FRAMING;
1790 else
1791 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1792 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001793 } else {
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02001794 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001795 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001796
1797 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1798 intel_dp->DP |= DP_SYNC_HS_HIGH;
1799 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1800 intel_dp->DP |= DP_SYNC_VS_HIGH;
1801 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1802
Jani Nikula6aba5b62013-10-04 15:08:10 +03001803 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001804 intel_dp->DP |= DP_ENHANCED_FRAMING;
1805
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001806 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001807 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001808 else if (crtc->pipe == PIPE_B)
1809 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001810 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001811}
1812
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001813#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1814#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001815
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001816#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1817#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001818
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001819#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1820#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001821
Imre Deakde9c1b62016-06-16 20:01:46 +03001822static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
1823 struct intel_dp *intel_dp);
1824
Daniel Vetter4be73782014-01-17 14:39:48 +01001825static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001826 u32 mask,
1827 u32 value)
1828{
Paulo Zanoni30add222012-10-26 19:05:45 -02001829 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001830 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001831 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001832
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001833 lockdep_assert_held(&dev_priv->pps_mutex);
1834
Imre Deakde9c1b62016-06-16 20:01:46 +03001835 intel_pps_verify_state(dev_priv, intel_dp);
1836
Jani Nikulabf13e812013-09-06 07:40:05 +03001837 pp_stat_reg = _pp_stat_reg(intel_dp);
1838 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001839
1840 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001841 mask, value,
1842 I915_READ(pp_stat_reg),
1843 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001844
Chris Wilson9036ff02016-06-30 15:33:09 +01001845 if (intel_wait_for_register(dev_priv,
1846 pp_stat_reg, mask, value,
1847 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001848 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001849 I915_READ(pp_stat_reg),
1850 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001851
1852 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001853}
1854
Daniel Vetter4be73782014-01-17 14:39:48 +01001855static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001856{
1857 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001858 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001859}
1860
Daniel Vetter4be73782014-01-17 14:39:48 +01001861static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001862{
Keith Packardbd943152011-09-18 23:09:52 -07001863 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001864 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001865}
Keith Packardbd943152011-09-18 23:09:52 -07001866
Daniel Vetter4be73782014-01-17 14:39:48 +01001867static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001868{
Abhay Kumard28d4732016-01-22 17:39:04 -08001869 ktime_t panel_power_on_time;
1870 s64 panel_power_off_duration;
1871
Keith Packard99ea7122011-11-01 19:57:50 -07001872 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001873
Abhay Kumard28d4732016-01-22 17:39:04 -08001874 /* take the difference of currrent time and panel power off time
1875 * and then make panel wait for t11_t12 if needed. */
1876 panel_power_on_time = ktime_get_boottime();
1877 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1878
Paulo Zanonidce56b32013-12-19 14:29:40 -02001879 /* When we disable the VDD override bit last we have to do the manual
1880 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08001881 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
1882 wait_remaining_ms_from_jiffies(jiffies,
1883 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001884
Daniel Vetter4be73782014-01-17 14:39:48 +01001885 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001886}
Keith Packardbd943152011-09-18 23:09:52 -07001887
Daniel Vetter4be73782014-01-17 14:39:48 +01001888static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001889{
1890 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1891 intel_dp->backlight_on_delay);
1892}
1893
Daniel Vetter4be73782014-01-17 14:39:48 +01001894static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001895{
1896 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
1897 intel_dp->backlight_off_delay);
1898}
Keith Packard99ea7122011-11-01 19:57:50 -07001899
Keith Packard832dd3c2011-11-01 19:34:06 -07001900/* Read the current pp_control value, unlocking the register if it
1901 * is locked
1902 */
1903
Jesse Barnes453c5422013-03-28 09:55:41 -07001904static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07001905{
Jesse Barnes453c5422013-03-28 09:55:41 -07001906 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001907 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07001908 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07001909
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001910 lockdep_assert_held(&dev_priv->pps_mutex);
1911
Jani Nikulabf13e812013-09-06 07:40:05 +03001912 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03001913 if (WARN_ON(!HAS_DDI(dev_priv) &&
1914 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05301915 control &= ~PANEL_UNLOCK_MASK;
1916 control |= PANEL_UNLOCK_REGS;
1917 }
Keith Packard832dd3c2011-11-01 19:34:06 -07001918 return control;
Keith Packardbd943152011-09-18 23:09:52 -07001919}
1920
Ville Syrjälä951468f2014-09-04 14:55:31 +03001921/*
1922 * Must be paired with edp_panel_vdd_off().
1923 * Must hold pps_mutex around the whole on/off sequence.
1924 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
1925 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001926static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001927{
Paulo Zanoni30add222012-10-26 19:05:45 -02001928 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001929 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1930 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001931 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001932 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08001933 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001934 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001935 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08001936
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001937 lockdep_assert_held(&dev_priv->pps_mutex);
1938
Keith Packard97af61f572011-09-28 16:23:51 -07001939 if (!is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001940 return false;
Keith Packardbd943152011-09-18 23:09:52 -07001941
Egbert Eich2c623c12014-11-25 12:54:57 +01001942 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07001943 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07001944
Daniel Vetter4be73782014-01-17 14:39:48 +01001945 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001946 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02001947
Ville Syrjälä25f78f52015-11-16 15:01:04 +01001948 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001949 intel_display_power_get(dev_priv, power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02001950
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001951 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
1952 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07001953
Daniel Vetter4be73782014-01-17 14:39:48 +01001954 if (!edp_have_panel_power(intel_dp))
1955 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001956
Jesse Barnes453c5422013-03-28 09:55:41 -07001957 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001958 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07001959
Jani Nikulabf13e812013-09-06 07:40:05 +03001960 pp_stat_reg = _pp_stat_reg(intel_dp);
1961 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001962
1963 I915_WRITE(pp_ctrl_reg, pp);
1964 POSTING_READ(pp_ctrl_reg);
1965 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1966 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07001967 /*
1968 * If the panel wasn't on, delay before accessing aux channel
1969 */
Daniel Vetter4be73782014-01-17 14:39:48 +01001970 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001971 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
1972 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07001973 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07001974 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001975
1976 return need_to_disable;
1977}
1978
Ville Syrjälä951468f2014-09-04 14:55:31 +03001979/*
1980 * Must be paired with intel_edp_panel_vdd_off() or
1981 * intel_edp_panel_off().
1982 * Nested calls to these functions are not allowed since
1983 * we drop the lock. Caller must use some higher level
1984 * locking to prevent nested calls from other threads.
1985 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01001986void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001987{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001988 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001989
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001990 if (!is_edp(intel_dp))
1991 return;
1992
Ville Syrjälä773538e82014-09-04 14:54:56 +03001993 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001994 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03001995 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001996
Rob Clarke2c719b2014-12-15 13:56:32 -05001997 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001998 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08001999}
2000
Daniel Vetter4be73782014-01-17 14:39:48 +01002001static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002002{
Paulo Zanoni30add222012-10-26 19:05:45 -02002003 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002004 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002005 struct intel_digital_port *intel_dig_port =
2006 dp_to_dig_port(intel_dp);
2007 struct intel_encoder *intel_encoder = &intel_dig_port->base;
2008 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08002009 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002010 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002011
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002012 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002013
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002014 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002015
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002016 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002017 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002018
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002019 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2020 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002021
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002022 pp = ironlake_get_pp_control(intel_dp);
2023 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002024
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002025 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2026 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002027
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002028 I915_WRITE(pp_ctrl_reg, pp);
2029 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002030
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002031 /* Make sure sequencer is idle before allowing subsequent activity */
2032 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2033 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002034
Imre Deak5a162e22016-08-10 14:07:30 +03002035 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002036 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002037
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002038 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002039 intel_display_power_put(dev_priv, power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002040}
2041
Daniel Vetter4be73782014-01-17 14:39:48 +01002042static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002043{
2044 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2045 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002046
Ville Syrjälä773538e82014-09-04 14:54:56 +03002047 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002048 if (!intel_dp->want_panel_vdd)
2049 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002050 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002051}
2052
Imre Deakaba86892014-07-30 15:57:31 +03002053static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2054{
2055 unsigned long delay;
2056
2057 /*
2058 * Queue the timer to fire a long time from now (relative to the power
2059 * down delay) to keep the panel power up across a sequence of
2060 * operations.
2061 */
2062 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2063 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2064}
2065
Ville Syrjälä951468f2014-09-04 14:55:31 +03002066/*
2067 * Must be paired with edp_panel_vdd_on().
2068 * Must hold pps_mutex around the whole on/off sequence.
2069 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2070 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002071static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002072{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002073 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002074
2075 lockdep_assert_held(&dev_priv->pps_mutex);
2076
Keith Packard97af61f572011-09-28 16:23:51 -07002077 if (!is_edp(intel_dp))
2078 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002079
Rob Clarke2c719b2014-12-15 13:56:32 -05002080 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002081 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002082
Keith Packardbd943152011-09-18 23:09:52 -07002083 intel_dp->want_panel_vdd = false;
2084
Imre Deakaba86892014-07-30 15:57:31 +03002085 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002086 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002087 else
2088 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002089}
2090
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002091static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002092{
Paulo Zanoni30add222012-10-26 19:05:45 -02002093 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002094 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002095 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002096 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002097
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002098 lockdep_assert_held(&dev_priv->pps_mutex);
2099
Keith Packard97af61f572011-09-28 16:23:51 -07002100 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002101 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002102
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002103 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2104 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002105
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002106 if (WARN(edp_have_panel_power(intel_dp),
2107 "eDP port %c panel power already on\n",
2108 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002109 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002110
Daniel Vetter4be73782014-01-17 14:39:48 +01002111 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002112
Jani Nikulabf13e812013-09-06 07:40:05 +03002113 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002114 pp = ironlake_get_pp_control(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002115 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002116 /* ILK workaround: disable reset around power sequence */
2117 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002118 I915_WRITE(pp_ctrl_reg, pp);
2119 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002120 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002121
Imre Deak5a162e22016-08-10 14:07:30 +03002122 pp |= PANEL_POWER_ON;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002123 if (!IS_GEN5(dev_priv))
Keith Packard99ea7122011-11-01 19:57:50 -07002124 pp |= PANEL_POWER_RESET;
2125
Jesse Barnes453c5422013-03-28 09:55:41 -07002126 I915_WRITE(pp_ctrl_reg, pp);
2127 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002128
Daniel Vetter4be73782014-01-17 14:39:48 +01002129 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002130 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002131
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002132 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002133 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002134 I915_WRITE(pp_ctrl_reg, pp);
2135 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002136 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002137}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002138
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002139void intel_edp_panel_on(struct intel_dp *intel_dp)
2140{
2141 if (!is_edp(intel_dp))
2142 return;
2143
2144 pps_lock(intel_dp);
2145 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002146 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002147}
2148
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002149
2150static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002151{
Imre Deak4e6e1a52014-03-27 17:45:11 +02002152 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2153 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanoni30add222012-10-26 19:05:45 -02002154 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002155 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002156 enum intel_display_power_domain power_domain;
Keith Packard99ea7122011-11-01 19:57:50 -07002157 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002158 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002159
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002160 lockdep_assert_held(&dev_priv->pps_mutex);
2161
Keith Packard97af61f572011-09-28 16:23:51 -07002162 if (!is_edp(intel_dp))
2163 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002164
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002165 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2166 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002167
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002168 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2169 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002170
Jesse Barnes453c5422013-03-28 09:55:41 -07002171 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002172 /* We need to switch off panel power _and_ force vdd, for otherwise some
2173 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002174 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002175 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002176
Jani Nikulabf13e812013-09-06 07:40:05 +03002177 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002178
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002179 intel_dp->want_panel_vdd = false;
2180
Jesse Barnes453c5422013-03-28 09:55:41 -07002181 I915_WRITE(pp_ctrl_reg, pp);
2182 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002183
Abhay Kumard28d4732016-01-22 17:39:04 -08002184 intel_dp->panel_power_off_time = ktime_get_boottime();
Daniel Vetter4be73782014-01-17 14:39:48 +01002185 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002186
2187 /* We got a reference when we enabled the VDD. */
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002188 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002189 intel_display_power_put(dev_priv, power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002190}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002191
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002192void intel_edp_panel_off(struct intel_dp *intel_dp)
2193{
2194 if (!is_edp(intel_dp))
2195 return;
2196
2197 pps_lock(intel_dp);
2198 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002199 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002200}
2201
Jani Nikula1250d102014-08-12 17:11:39 +03002202/* Enable backlight in the panel power control. */
2203static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002204{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002205 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2206 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002207 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002208 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002209 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002210
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002211 /*
2212 * If we enable the backlight right away following a panel power
2213 * on, we may see slight flicker as the panel syncs with the eDP
2214 * link. So delay a bit to make sure the image is solid before
2215 * allowing it to appear.
2216 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002217 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002218
Ville Syrjälä773538e82014-09-04 14:54:56 +03002219 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002220
Jesse Barnes453c5422013-03-28 09:55:41 -07002221 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002222 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002223
Jani Nikulabf13e812013-09-06 07:40:05 +03002224 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002225
2226 I915_WRITE(pp_ctrl_reg, pp);
2227 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002228
Ville Syrjälä773538e82014-09-04 14:54:56 +03002229 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002230}
2231
Jani Nikula1250d102014-08-12 17:11:39 +03002232/* Enable backlight PWM and backlight PP control. */
2233void intel_edp_backlight_on(struct intel_dp *intel_dp)
2234{
2235 if (!is_edp(intel_dp))
2236 return;
2237
2238 DRM_DEBUG_KMS("\n");
2239
2240 intel_panel_enable_backlight(intel_dp->attached_connector);
2241 _intel_edp_backlight_on(intel_dp);
2242}
2243
2244/* Disable backlight in the panel power control. */
2245static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002246{
Paulo Zanoni30add222012-10-26 19:05:45 -02002247 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002248 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002249 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002250 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002251
Keith Packardf01eca22011-09-28 16:48:10 -07002252 if (!is_edp(intel_dp))
2253 return;
2254
Ville Syrjälä773538e82014-09-04 14:54:56 +03002255 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002256
Jesse Barnes453c5422013-03-28 09:55:41 -07002257 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002258 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002259
Jani Nikulabf13e812013-09-06 07:40:05 +03002260 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002261
2262 I915_WRITE(pp_ctrl_reg, pp);
2263 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002264
Ville Syrjälä773538e82014-09-04 14:54:56 +03002265 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002266
Paulo Zanonidce56b32013-12-19 14:29:40 -02002267 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002268 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002269}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002270
Jani Nikula1250d102014-08-12 17:11:39 +03002271/* Disable backlight PP control and backlight PWM. */
2272void intel_edp_backlight_off(struct intel_dp *intel_dp)
2273{
2274 if (!is_edp(intel_dp))
2275 return;
2276
2277 DRM_DEBUG_KMS("\n");
2278
2279 _intel_edp_backlight_off(intel_dp);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002280 intel_panel_disable_backlight(intel_dp->attached_connector);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002281}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002282
Jani Nikula73580fb72014-08-12 17:11:41 +03002283/*
2284 * Hook for controlling the panel power control backlight through the bl_power
2285 * sysfs attribute. Take care to handle multiple calls.
2286 */
2287static void intel_edp_backlight_power(struct intel_connector *connector,
2288 bool enable)
2289{
2290 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002291 bool is_enabled;
2292
Ville Syrjälä773538e82014-09-04 14:54:56 +03002293 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002294 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002295 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002296
2297 if (is_enabled == enable)
2298 return;
2299
Jani Nikula23ba9372014-08-27 14:08:43 +03002300 DRM_DEBUG_KMS("panel power control backlight %s\n",
2301 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002302
2303 if (enable)
2304 _intel_edp_backlight_on(intel_dp);
2305 else
2306 _intel_edp_backlight_off(intel_dp);
2307}
2308
Ville Syrjälä64e10772015-10-29 21:26:01 +02002309static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2310{
2311 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2312 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2313 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2314
2315 I915_STATE_WARN(cur_state != state,
2316 "DP port %c state assertion failure (expected %s, current %s)\n",
2317 port_name(dig_port->port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002318 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002319}
2320#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2321
2322static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2323{
2324 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2325
2326 I915_STATE_WARN(cur_state != state,
2327 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002328 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002329}
2330#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2331#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2332
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002333static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2334 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002335{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002336 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002337 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002338
Ville Syrjälä64e10772015-10-29 21:26:01 +02002339 assert_pipe_disabled(dev_priv, crtc->pipe);
2340 assert_dp_port_disabled(intel_dp);
2341 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002342
Ville Syrjäläabfce942015-10-29 21:26:03 +02002343 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002344 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002345
2346 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2347
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002348 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002349 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2350 else
2351 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2352
2353 I915_WRITE(DP_A, intel_dp->DP);
2354 POSTING_READ(DP_A);
2355 udelay(500);
2356
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002357 /*
2358 * [DevILK] Work around required when enabling DP PLL
2359 * while a pipe is enabled going to FDI:
2360 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2361 * 2. Program DP PLL enable
2362 */
2363 if (IS_GEN5(dev_priv))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02002364 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002365
Daniel Vetter07679352012-09-06 22:15:42 +02002366 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002367
Daniel Vetter07679352012-09-06 22:15:42 +02002368 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002369 POSTING_READ(DP_A);
2370 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002371}
2372
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002373static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002374{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002375 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002376 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2377 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002378
Ville Syrjälä64e10772015-10-29 21:26:01 +02002379 assert_pipe_disabled(dev_priv, crtc->pipe);
2380 assert_dp_port_disabled(intel_dp);
2381 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002382
Ville Syrjäläabfce942015-10-29 21:26:03 +02002383 DRM_DEBUG_KMS("disabling eDP PLL\n");
2384
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002385 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002386
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002387 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002388 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002389 udelay(200);
2390}
2391
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002392/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002393void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002394{
2395 int ret, i;
2396
2397 /* Should have a valid DPCD by this point */
2398 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2399 return;
2400
2401 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002402 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2403 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002404 } else {
2405 /*
2406 * When turning on, we need to retry for 1ms to give the sink
2407 * time to wake up.
2408 */
2409 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002410 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2411 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002412 if (ret == 1)
2413 break;
2414 msleep(1);
2415 }
2416 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002417
2418 if (ret != 1)
2419 DRM_DEBUG_KMS("failed to %s sink power state\n",
2420 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002421}
2422
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002423static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2424 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002425{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002426 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002427 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002428 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002429 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002430 enum intel_display_power_domain power_domain;
2431 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002432 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002433
2434 power_domain = intel_display_port_power_domain(encoder);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002435 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002436 return false;
2437
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002438 ret = false;
2439
Imre Deak6d129be2014-03-05 16:20:54 +02002440 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002441
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002442 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002443 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002444
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002445 if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002446 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002447 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002448 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002449
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002450 for_each_pipe(dev_priv, p) {
2451 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2452 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2453 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002454 ret = true;
2455
2456 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002457 }
2458 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002459
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002460 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002461 i915_mmio_reg_offset(intel_dp->output_reg));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002462 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002463 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2464 } else {
2465 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002466 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002467
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002468 ret = true;
2469
2470out:
2471 intel_display_power_put(dev_priv, power_domain);
2472
2473 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002474}
2475
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002476static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002477 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002478{
2479 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002480 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002481 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002482 struct drm_i915_private *dev_priv = to_i915(dev);
Xiong Zhang63000ef2013-06-28 12:59:06 +08002483 enum port port = dp_to_dig_port(intel_dp)->port;
2484 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002485
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002486 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002487
2488 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002489
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002490 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002491 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2492
2493 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002494 flags |= DRM_MODE_FLAG_PHSYNC;
2495 else
2496 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002497
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002498 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002499 flags |= DRM_MODE_FLAG_PVSYNC;
2500 else
2501 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002502 } else {
2503 if (tmp & DP_SYNC_HS_HIGH)
2504 flags |= DRM_MODE_FLAG_PHSYNC;
2505 else
2506 flags |= DRM_MODE_FLAG_NHSYNC;
2507
2508 if (tmp & DP_SYNC_VS_HIGH)
2509 flags |= DRM_MODE_FLAG_PVSYNC;
2510 else
2511 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002512 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002513
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002514 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002515
Ville Syrjäläc99f53f2016-11-14 19:44:07 +02002516 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002517 pipe_config->limited_color_range = true;
2518
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002519 pipe_config->lane_count =
2520 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2521
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002522 intel_dp_get_m_n(crtc, pipe_config);
2523
Ville Syrjälä18442d02013-09-13 16:00:08 +03002524 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002525 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002526 pipe_config->port_clock = 162000;
2527 else
2528 pipe_config->port_clock = 270000;
2529 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002530
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002531 pipe_config->base.adjusted_mode.crtc_clock =
2532 intel_dotclock_calculate(pipe_config->port_clock,
2533 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002534
Jani Nikula6aa23e62016-03-24 17:50:20 +02002535 if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
2536 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002537 /*
2538 * This is a big fat ugly hack.
2539 *
2540 * Some machines in UEFI boot mode provide us a VBT that has 18
2541 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2542 * unknown we fail to light up. Yet the same BIOS boots up with
2543 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2544 * max, not what it tells us to use.
2545 *
2546 * Note: This will still be broken if the eDP panel is not lit
2547 * up by the BIOS, and thus we can't get the mode at module
2548 * load.
2549 */
2550 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002551 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2552 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002553 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002554}
2555
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002556static void intel_disable_dp(struct intel_encoder *encoder,
2557 struct intel_crtc_state *old_crtc_state,
2558 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002559{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002560 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002561 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002562
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002563 if (old_crtc_state->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002564 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002565
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002566 if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv))
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002567 intel_psr_disable(intel_dp);
2568
Daniel Vetter6cb49832012-05-20 17:14:50 +02002569 /* Make sure the panel is off before trying to change the mode. But also
2570 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002571 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01002572 intel_edp_backlight_off(intel_dp);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002573 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002574 intel_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02002575
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002576 /* disable the port before the pipe on g4x */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002577 if (INTEL_GEN(dev_priv) < 5)
Daniel Vetter37398502012-09-06 22:15:44 +02002578 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07002579}
2580
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002581static void ilk_post_disable_dp(struct intel_encoder *encoder,
2582 struct intel_crtc_state *old_crtc_state,
2583 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002584{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002585 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002586 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002587
Ville Syrjälä49277c32014-03-31 18:21:26 +03002588 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002589
2590 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002591 if (port == PORT_A)
2592 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002593}
2594
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002595static void vlv_post_disable_dp(struct intel_encoder *encoder,
2596 struct intel_crtc_state *old_crtc_state,
2597 struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002598{
2599 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2600
2601 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002602}
2603
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002604static void chv_post_disable_dp(struct intel_encoder *encoder,
2605 struct intel_crtc_state *old_crtc_state,
2606 struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002607{
2608 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002609 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002610 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002611
2612 intel_dp_link_down(intel_dp);
2613
Ville Syrjäläa5805162015-05-26 20:42:30 +03002614 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002615
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002616 /* Assert data lane reset */
2617 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002618
Ville Syrjäläa5805162015-05-26 20:42:30 +03002619 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002620}
2621
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002622static void
2623_intel_dp_set_link_train(struct intel_dp *intel_dp,
2624 uint32_t *DP,
2625 uint8_t dp_train_pat)
2626{
2627 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2628 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002629 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002630 enum port port = intel_dig_port->port;
2631
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002632 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2633 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2634 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2635
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002636 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002637 uint32_t temp = I915_READ(DP_TP_CTL(port));
2638
2639 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2640 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2641 else
2642 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2643
2644 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2645 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2646 case DP_TRAINING_PATTERN_DISABLE:
2647 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2648
2649 break;
2650 case DP_TRAINING_PATTERN_1:
2651 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2652 break;
2653 case DP_TRAINING_PATTERN_2:
2654 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2655 break;
2656 case DP_TRAINING_PATTERN_3:
2657 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2658 break;
2659 }
2660 I915_WRITE(DP_TP_CTL(port), temp);
2661
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002662 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002663 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002664 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2665
2666 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2667 case DP_TRAINING_PATTERN_DISABLE:
2668 *DP |= DP_LINK_TRAIN_OFF_CPT;
2669 break;
2670 case DP_TRAINING_PATTERN_1:
2671 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2672 break;
2673 case DP_TRAINING_PATTERN_2:
2674 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2675 break;
2676 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002677 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002678 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2679 break;
2680 }
2681
2682 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002683 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002684 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2685 else
2686 *DP &= ~DP_LINK_TRAIN_MASK;
2687
2688 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2689 case DP_TRAINING_PATTERN_DISABLE:
2690 *DP |= DP_LINK_TRAIN_OFF;
2691 break;
2692 case DP_TRAINING_PATTERN_1:
2693 *DP |= DP_LINK_TRAIN_PAT_1;
2694 break;
2695 case DP_TRAINING_PATTERN_2:
2696 *DP |= DP_LINK_TRAIN_PAT_2;
2697 break;
2698 case DP_TRAINING_PATTERN_3:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002699 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002700 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2701 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002702 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002703 *DP |= DP_LINK_TRAIN_PAT_2;
2704 }
2705 break;
2706 }
2707 }
2708}
2709
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002710static void intel_dp_enable_port(struct intel_dp *intel_dp,
2711 struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002712{
2713 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002714 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002715
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002716 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002717
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002718 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002719
2720 /*
2721 * Magic for VLV/CHV. We _must_ first set up the register
2722 * without actually enabling the port, and then do another
2723 * write to enable the port. Otherwise link training will
2724 * fail when the power sequencer is freshly used for this port.
2725 */
2726 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002727 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002728 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002729
2730 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2731 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002732}
2733
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002734static void intel_enable_dp(struct intel_encoder *encoder,
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002735 struct intel_crtc_state *pipe_config,
2736 struct drm_connector_state *conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002737{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002738 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2739 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002740 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulac1dec792014-10-27 16:26:56 +02002741 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002742 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002743 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002744
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002745 if (WARN_ON(dp_reg & DP_PORT_EN))
2746 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002747
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002748 pps_lock(intel_dp);
2749
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002750 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002751 vlv_init_panel_power_sequencer(intel_dp);
2752
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002753 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002754
2755 edp_panel_vdd_on(intel_dp);
2756 edp_panel_on(intel_dp);
2757 edp_panel_vdd_off(intel_dp, true);
2758
2759 pps_unlock(intel_dp);
2760
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002761 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002762 unsigned int lane_mask = 0x0;
2763
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002764 if (IS_CHERRYVIEW(dev_priv))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002765 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002766
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002767 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2768 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002769 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002770
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002771 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2772 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002773 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002774
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002775 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002776 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002777 pipe_name(pipe));
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002778 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Jani Nikulac1dec792014-10-27 16:26:56 +02002779 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002780}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002781
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002782static void g4x_enable_dp(struct intel_encoder *encoder,
2783 struct intel_crtc_state *pipe_config,
2784 struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03002785{
Jani Nikula828f5c62013-09-05 16:44:45 +03002786 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2787
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002788 intel_enable_dp(encoder, pipe_config, conn_state);
Daniel Vetter4be73782014-01-17 14:39:48 +01002789 intel_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002790}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002791
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002792static void vlv_enable_dp(struct intel_encoder *encoder,
2793 struct intel_crtc_state *pipe_config,
2794 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002795{
Jani Nikula828f5c62013-09-05 16:44:45 +03002796 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2797
Daniel Vetter4be73782014-01-17 14:39:48 +01002798 intel_edp_backlight_on(intel_dp);
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002799 intel_psr_enable(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002800}
2801
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002802static void g4x_pre_enable_dp(struct intel_encoder *encoder,
2803 struct intel_crtc_state *pipe_config,
2804 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002805{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002806 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002807 enum port port = dp_to_dig_port(intel_dp)->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002808
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002809 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002810
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002811 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002812 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002813 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002814}
2815
Ville Syrjälä83b84592014-10-16 21:29:51 +03002816static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2817{
2818 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002819 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002820 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03002821 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002822
2823 edp_panel_vdd_off_sync(intel_dp);
2824
2825 /*
2826 * VLV seems to get confused when multiple power seqeuencers
2827 * have the same port selected (even if only one has power/vdd
2828 * enabled). The failure manifests as vlv_wait_port_ready() failing
2829 * CHV on the other hand doesn't seem to mind having the same port
2830 * selected in multiple power seqeuencers, but let's clear the
2831 * port select always when logically disconnecting a power sequencer
2832 * from a port.
2833 */
2834 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2835 pipe_name(pipe), port_name(intel_dig_port->port));
2836 I915_WRITE(pp_on_reg, 0);
2837 POSTING_READ(pp_on_reg);
2838
2839 intel_dp->pps_pipe = INVALID_PIPE;
2840}
2841
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002842static void vlv_steal_power_sequencer(struct drm_device *dev,
2843 enum pipe pipe)
2844{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002845 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002846 struct intel_encoder *encoder;
2847
2848 lockdep_assert_held(&dev_priv->pps_mutex);
2849
Ville Syrjäläac3c12e2014-10-16 21:29:56 +03002850 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2851 return;
2852
Jani Nikula19c80542015-12-16 12:48:16 +02002853 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002854 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002855 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002856
2857 if (encoder->type != INTEL_OUTPUT_EDP)
2858 continue;
2859
2860 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002861 port = dp_to_dig_port(intel_dp)->port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002862
2863 if (intel_dp->pps_pipe != pipe)
2864 continue;
2865
2866 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03002867 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002868
Maarten Lankhorste02f9a02015-08-05 12:37:08 +02002869 WARN(encoder->base.crtc,
Ville Syrjälä034e43c2014-10-16 21:27:28 +03002870 "stealing pipe %c power sequencer from active eDP port %c\n",
2871 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002872
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002873 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002874 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002875 }
2876}
2877
2878static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
2879{
2880 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2881 struct intel_encoder *encoder = &intel_dig_port->base;
2882 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002883 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002884 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002885
2886 lockdep_assert_held(&dev_priv->pps_mutex);
2887
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002888 if (!is_edp(intel_dp))
2889 return;
2890
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002891 if (intel_dp->pps_pipe == crtc->pipe)
2892 return;
2893
2894 /*
2895 * If another power sequencer was being used on this
2896 * port previously make sure to turn off vdd there while
2897 * we still have control of it.
2898 */
2899 if (intel_dp->pps_pipe != INVALID_PIPE)
Ville Syrjälä83b84592014-10-16 21:29:51 +03002900 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002901
2902 /*
2903 * We may be stealing the power
2904 * sequencer from another port.
2905 */
2906 vlv_steal_power_sequencer(dev, crtc->pipe);
2907
2908 /* now it's all ours */
2909 intel_dp->pps_pipe = crtc->pipe;
2910
2911 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
2912 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
2913
2914 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03002915 intel_dp_init_panel_power_sequencer(dev, intel_dp);
2916 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002917}
2918
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002919static void vlv_pre_enable_dp(struct intel_encoder *encoder,
2920 struct intel_crtc_state *pipe_config,
2921 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002922{
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03002923 vlv_phy_pre_encoder_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002924
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002925 intel_enable_dp(encoder, pipe_config, conn_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002926}
2927
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002928static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
2929 struct intel_crtc_state *pipe_config,
2930 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07002931{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002932 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002933
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03002934 vlv_phy_pre_pll_enable(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002935}
2936
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002937static void chv_pre_enable_dp(struct intel_encoder *encoder,
2938 struct intel_crtc_state *pipe_config,
2939 struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002940{
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03002941 chv_phy_pre_encoder_enable(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002942
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002943 intel_enable_dp(encoder, pipe_config, conn_state);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03002944
2945 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03002946 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002947}
2948
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002949static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
2950 struct intel_crtc_state *pipe_config,
2951 struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03002952{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002953 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03002954
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03002955 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03002956}
2957
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002958static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
2959 struct intel_crtc_state *pipe_config,
2960 struct drm_connector_state *conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03002961{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03002962 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03002963}
2964
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002965/*
2966 * Fetch AUX CH registers 0x202 - 0x207 which contain
2967 * link status information
2968 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03002969bool
Keith Packard93f62da2011-11-01 19:45:03 -07002970intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002971{
Lyude9f085eb2016-04-13 10:58:33 -04002972 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
2973 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002974}
2975
Paulo Zanoni11002442014-06-13 18:45:41 -03002976/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03002977uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08002978intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002979{
Paulo Zanoni30add222012-10-26 19:05:45 -02002980 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002981 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002982 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08002983
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01002984 if (IS_BROXTON(dev_priv))
Vandana Kannan93147262014-11-18 15:45:29 +05302985 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
2986 else if (INTEL_INFO(dev)->gen >= 9) {
Jani Nikula06411f02016-03-24 17:50:21 +02002987 if (dev_priv->vbt.edp.low_vswing && port == PORT_A)
Sonika Jindal7ad14a22015-02-25 10:29:12 +05302988 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00002989 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002990 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Sonika Jindalbd600182014-08-08 16:23:41 +05302991 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002992 else if (IS_GEN7(dev_priv) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05302993 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002994 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05302995 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08002996 else
Sonika Jindalbd600182014-08-08 16:23:41 +05302997 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08002998}
2999
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003000uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003001intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3002{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003003 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003004 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003005
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003006 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003007 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3008 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3009 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3010 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3011 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3012 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3013 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303014 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3015 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003016 default:
3017 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3018 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003019 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003020 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303021 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3022 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3023 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3024 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3025 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3026 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3027 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003028 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303029 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003030 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003031 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003032 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303033 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3034 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3035 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3036 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3037 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3038 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3039 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003040 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303041 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003042 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003043 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003044 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303045 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3046 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3047 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3048 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3049 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003050 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303051 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003052 }
3053 } else {
3054 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303055 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3056 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3057 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3058 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3059 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3060 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3061 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003062 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303063 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003064 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003065 }
3066}
3067
Daniel Vetter5829975c2015-04-16 11:36:52 +02003068static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003069{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003070 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003071 unsigned long demph_reg_value, preemph_reg_value,
3072 uniqtranscale_reg_value;
3073 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003074
3075 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303076 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003077 preemph_reg_value = 0x0004000;
3078 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303079 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003080 demph_reg_value = 0x2B405555;
3081 uniqtranscale_reg_value = 0x552AB83A;
3082 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303083 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003084 demph_reg_value = 0x2B404040;
3085 uniqtranscale_reg_value = 0x5548B83A;
3086 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303087 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003088 demph_reg_value = 0x2B245555;
3089 uniqtranscale_reg_value = 0x5560B83A;
3090 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303091 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003092 demph_reg_value = 0x2B405555;
3093 uniqtranscale_reg_value = 0x5598DA3A;
3094 break;
3095 default:
3096 return 0;
3097 }
3098 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303099 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003100 preemph_reg_value = 0x0002000;
3101 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303102 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003103 demph_reg_value = 0x2B404040;
3104 uniqtranscale_reg_value = 0x5552B83A;
3105 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303106 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003107 demph_reg_value = 0x2B404848;
3108 uniqtranscale_reg_value = 0x5580B83A;
3109 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303110 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003111 demph_reg_value = 0x2B404040;
3112 uniqtranscale_reg_value = 0x55ADDA3A;
3113 break;
3114 default:
3115 return 0;
3116 }
3117 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303118 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003119 preemph_reg_value = 0x0000000;
3120 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303121 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003122 demph_reg_value = 0x2B305555;
3123 uniqtranscale_reg_value = 0x5570B83A;
3124 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303125 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003126 demph_reg_value = 0x2B2B4040;
3127 uniqtranscale_reg_value = 0x55ADDA3A;
3128 break;
3129 default:
3130 return 0;
3131 }
3132 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303133 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003134 preemph_reg_value = 0x0006000;
3135 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303136 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003137 demph_reg_value = 0x1B405555;
3138 uniqtranscale_reg_value = 0x55ADDA3A;
3139 break;
3140 default:
3141 return 0;
3142 }
3143 break;
3144 default:
3145 return 0;
3146 }
3147
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003148 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3149 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003150
3151 return 0;
3152}
3153
Daniel Vetter5829975c2015-04-16 11:36:52 +02003154static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003155{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003156 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3157 u32 deemph_reg_value, margin_reg_value;
3158 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003159 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003160
3161 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303162 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003163 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303164 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003165 deemph_reg_value = 128;
3166 margin_reg_value = 52;
3167 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303168 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003169 deemph_reg_value = 128;
3170 margin_reg_value = 77;
3171 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303172 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003173 deemph_reg_value = 128;
3174 margin_reg_value = 102;
3175 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303176 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003177 deemph_reg_value = 128;
3178 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003179 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003180 break;
3181 default:
3182 return 0;
3183 }
3184 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303185 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003186 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303187 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003188 deemph_reg_value = 85;
3189 margin_reg_value = 78;
3190 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303191 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003192 deemph_reg_value = 85;
3193 margin_reg_value = 116;
3194 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303195 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003196 deemph_reg_value = 85;
3197 margin_reg_value = 154;
3198 break;
3199 default:
3200 return 0;
3201 }
3202 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303203 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003204 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303205 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003206 deemph_reg_value = 64;
3207 margin_reg_value = 104;
3208 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303209 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003210 deemph_reg_value = 64;
3211 margin_reg_value = 154;
3212 break;
3213 default:
3214 return 0;
3215 }
3216 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303217 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003218 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303219 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003220 deemph_reg_value = 43;
3221 margin_reg_value = 154;
3222 break;
3223 default:
3224 return 0;
3225 }
3226 break;
3227 default:
3228 return 0;
3229 }
3230
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003231 chv_set_phy_signal_level(encoder, deemph_reg_value,
3232 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003233
3234 return 0;
3235}
3236
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003237static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003238gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003239{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003240 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003241
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003242 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303243 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003244 default:
3245 signal_levels |= DP_VOLTAGE_0_4;
3246 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303247 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003248 signal_levels |= DP_VOLTAGE_0_6;
3249 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303250 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003251 signal_levels |= DP_VOLTAGE_0_8;
3252 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303253 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003254 signal_levels |= DP_VOLTAGE_1_2;
3255 break;
3256 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003257 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303258 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003259 default:
3260 signal_levels |= DP_PRE_EMPHASIS_0;
3261 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303262 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003263 signal_levels |= DP_PRE_EMPHASIS_3_5;
3264 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303265 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003266 signal_levels |= DP_PRE_EMPHASIS_6;
3267 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303268 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003269 signal_levels |= DP_PRE_EMPHASIS_9_5;
3270 break;
3271 }
3272 return signal_levels;
3273}
3274
Zhenyu Wange3421a12010-04-08 09:43:27 +08003275/* Gen6's DP voltage swing and pre-emphasis control */
3276static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003277gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003278{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003279 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3280 DP_TRAIN_PRE_EMPHASIS_MASK);
3281 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303282 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3283 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003284 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303285 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003286 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303287 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3288 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003289 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303290 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3291 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003292 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303293 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3294 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003295 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003296 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003297 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3298 "0x%x\n", signal_levels);
3299 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003300 }
3301}
3302
Keith Packard1a2eb462011-11-16 16:26:07 -08003303/* Gen7's DP voltage swing and pre-emphasis control */
3304static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003305gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003306{
3307 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3308 DP_TRAIN_PRE_EMPHASIS_MASK);
3309 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303310 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003311 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303312 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003313 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303314 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003315 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3316
Sonika Jindalbd600182014-08-08 16:23:41 +05303317 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003318 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303319 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003320 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3321
Sonika Jindalbd600182014-08-08 16:23:41 +05303322 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003323 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303324 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003325 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3326
3327 default:
3328 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3329 "0x%x\n", signal_levels);
3330 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3331 }
3332}
3333
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003334void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003335intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003336{
3337 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003338 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003339 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003340 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003341 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003342 uint8_t train_set = intel_dp->train_set[0];
3343
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003344 if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003345 signal_levels = ddi_signal_levels(intel_dp);
3346
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01003347 if (IS_BROXTON(dev_priv))
David Weinehallf8896f52015-06-25 11:11:03 +03003348 signal_levels = 0;
3349 else
3350 mask = DDI_BUF_EMP_MASK;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003351 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003352 signal_levels = chv_signal_levels(intel_dp);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003353 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003354 signal_levels = vlv_signal_levels(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003355 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003356 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003357 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003358 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003359 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003360 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3361 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003362 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003363 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3364 }
3365
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303366 if (mask)
3367 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3368
3369 DRM_DEBUG_KMS("Using vswing level %d\n",
3370 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3371 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3372 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3373 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003374
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003375 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003376
3377 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3378 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003379}
3380
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003381void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003382intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3383 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003384{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003385 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003386 struct drm_i915_private *dev_priv =
3387 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003388
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003389 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003390
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003391 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003392 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003393}
3394
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003395void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003396{
3397 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3398 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003399 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak3ab9c632013-05-03 12:57:41 +03003400 enum port port = intel_dig_port->port;
3401 uint32_t val;
3402
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003403 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003404 return;
3405
3406 val = I915_READ(DP_TP_CTL(port));
3407 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3408 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3409 I915_WRITE(DP_TP_CTL(port), val);
3410
3411 /*
3412 * On PORT_A we can have only eDP in SST mode. There the only reason
3413 * we need to set idle transmission mode is to work around a HW issue
3414 * where we enable the pipe while not in idle link-training mode.
3415 * In this case there is requirement to wait for a minimum number of
3416 * idle patterns to be sent.
3417 */
3418 if (port == PORT_A)
3419 return;
3420
Chris Wilsona7670172016-06-30 15:33:10 +01003421 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3422 DP_TP_STATUS_IDLE_DONE,
3423 DP_TP_STATUS_IDLE_DONE,
3424 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003425 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3426}
3427
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003428static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003429intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003430{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003431 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003432 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003433 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003434 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003435 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003436 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003437
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003438 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003439 return;
3440
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003441 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003442 return;
3443
Zhao Yakui28c97732009-10-09 11:39:41 +08003444 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003445
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003446 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003447 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003448 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003449 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003450 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003451 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003452 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3453 else
3454 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003455 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003456 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003457 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003458 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003459
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003460 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3461 I915_WRITE(intel_dp->output_reg, DP);
3462 POSTING_READ(intel_dp->output_reg);
3463
3464 /*
3465 * HW workaround for IBX, we need to move the port
3466 * to transcoder A after disabling it to allow the
3467 * matching HDMI port to be enabled on transcoder A.
3468 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003469 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003470 /*
3471 * We get CPU/PCH FIFO underruns on the other pipe when
3472 * doing the workaround. Sweep them under the rug.
3473 */
3474 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3475 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3476
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003477 /* always enable with pattern 1 (as per spec) */
3478 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3479 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3480 I915_WRITE(intel_dp->output_reg, DP);
3481 POSTING_READ(intel_dp->output_reg);
3482
3483 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003484 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003485 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003486
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003487 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003488 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3489 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003490 }
3491
Keith Packardf01eca22011-09-28 16:48:10 -07003492 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003493
3494 intel_dp->DP = DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003495}
3496
Imre Deak24e807e2016-10-24 19:33:28 +03003497bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003498intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003499{
Lyude9f085eb2016-04-13 10:58:33 -04003500 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3501 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003502 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003503
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003504 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003505
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003506 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3507}
3508
3509static bool
3510intel_edp_init_dpcd(struct intel_dp *intel_dp)
3511{
3512 struct drm_i915_private *dev_priv =
3513 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3514
3515 /* this function is meant to be called only once */
3516 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3517
3518 if (!intel_dp_read_dpcd(intel_dp))
3519 return false;
3520
Imre Deak12a47a422016-10-24 19:33:29 +03003521 intel_dp_read_desc(intel_dp);
3522
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003523 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3524 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3525 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3526
3527 /* Check if the panel supports PSR */
3528 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3529 intel_dp->psr_dpcd,
3530 sizeof(intel_dp->psr_dpcd));
3531 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3532 dev_priv->psr.sink_support = true;
3533 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3534 }
3535
3536 if (INTEL_GEN(dev_priv) >= 9 &&
3537 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3538 uint8_t frame_sync_cap;
3539
3540 dev_priv->psr.sink_support = true;
3541 drm_dp_dpcd_read(&intel_dp->aux,
3542 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3543 &frame_sync_cap, 1);
3544 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3545 /* PSR2 needs frame sync as well */
3546 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3547 DRM_DEBUG_KMS("PSR2 %s on sink",
3548 dev_priv->psr.psr2_support ? "supported" : "not supported");
3549 }
3550
3551 /* Read the eDP Display control capabilities registers */
3552 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
3553 drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003554 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3555 sizeof(intel_dp->edp_dpcd))
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003556 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3557 intel_dp->edp_dpcd);
3558
3559 /* Intermediate frequency support */
3560 if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */
3561 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3562 int i;
3563
3564 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3565 sink_rates, sizeof(sink_rates));
3566
3567 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3568 int val = le16_to_cpu(sink_rates[i]);
3569
3570 if (val == 0)
3571 break;
3572
3573 /* Value read is in kHz while drm clock is saved in deca-kHz */
3574 intel_dp->sink_rates[i] = (val * 200) / 10;
3575 }
3576 intel_dp->num_sink_rates = i;
3577 }
3578
3579 return true;
3580}
3581
3582
3583static bool
3584intel_dp_get_dpcd(struct intel_dp *intel_dp)
3585{
3586 if (!intel_dp_read_dpcd(intel_dp))
3587 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003588
Lyude9f085eb2016-04-13 10:58:33 -04003589 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT,
3590 &intel_dp->sink_count, 1) < 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303591 return false;
3592
3593 /*
3594 * Sink count can change between short pulse hpd hence
3595 * a member variable in intel_dp will track any changes
3596 * between short pulse interrupts.
3597 */
3598 intel_dp->sink_count = DP_GET_SINK_COUNT(intel_dp->sink_count);
3599
3600 /*
3601 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3602 * a dongle is present but no display. Unless we require to know
3603 * if a dongle is present or not, we don't need to update
3604 * downstream port information. So, an early return here saves
3605 * time from performing other operations which are not required.
3606 */
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05303607 if (!is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303608 return false;
3609
Imre Deakc726ad02016-10-24 19:33:24 +03003610 if (!drm_dp_is_branch(intel_dp->dpcd))
Adam Jacksonedb39242012-09-18 10:58:49 -04003611 return true; /* native DP sink */
3612
3613 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3614 return true; /* no per-port downstream info */
3615
Lyude9f085eb2016-04-13 10:58:33 -04003616 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3617 intel_dp->downstream_ports,
3618 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003619 return false; /* downstream port status fetch failed */
3620
3621 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003622}
3623
Dave Airlie0e32b392014-05-02 14:02:48 +10003624static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003625intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003626{
3627 u8 buf[1];
3628
Nathan Schulte7cc96132016-03-15 10:14:05 -05003629 if (!i915.enable_dp_mst)
3630 return false;
3631
Dave Airlie0e32b392014-05-02 14:02:48 +10003632 if (!intel_dp->can_mst)
3633 return false;
3634
3635 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3636 return false;
3637
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003638 if (drm_dp_dpcd_read(&intel_dp->aux, DP_MSTM_CAP, buf, 1) != 1)
3639 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003640
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003641 return buf[0] & DP_MST_CAP;
3642}
3643
3644static void
3645intel_dp_configure_mst(struct intel_dp *intel_dp)
3646{
3647 if (!i915.enable_dp_mst)
3648 return;
3649
3650 if (!intel_dp->can_mst)
3651 return;
3652
3653 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3654
3655 if (intel_dp->is_mst)
3656 DRM_DEBUG_KMS("Sink is MST capable\n");
3657 else
3658 DRM_DEBUG_KMS("Sink is not MST capable\n");
3659
3660 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3661 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003662}
3663
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003664static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003665{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003666 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003667 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003668 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003669 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003670 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003671 int count = 0;
3672 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003673
3674 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003675 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003676 ret = -EIO;
3677 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003678 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003679
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003680 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003681 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003682 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003683 ret = -EIO;
3684 goto out;
3685 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003686
Rodrigo Vivic6297842015-11-05 10:50:20 -08003687 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003688 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivic6297842015-11-05 10:50:20 -08003689
3690 if (drm_dp_dpcd_readb(&intel_dp->aux,
3691 DP_TEST_SINK_MISC, &buf) < 0) {
3692 ret = -EIO;
3693 goto out;
3694 }
3695 count = buf & DP_TEST_COUNT_MASK;
3696 } while (--attempts && count);
3697
3698 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003699 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003700 ret = -ETIMEDOUT;
3701 }
3702
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003703 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003704 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003705 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003706}
3707
3708static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3709{
3710 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003711 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003712 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3713 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003714 int ret;
3715
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003716 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3717 return -EIO;
3718
3719 if (!(buf & DP_TEST_CRC_SUPPORTED))
3720 return -ENOTTY;
3721
3722 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3723 return -EIO;
3724
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003725 if (buf & DP_TEST_SINK_START) {
3726 ret = intel_dp_sink_crc_stop(intel_dp);
3727 if (ret)
3728 return ret;
3729 }
3730
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003731 hsw_disable_ips(intel_crtc);
3732
3733 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3734 buf | DP_TEST_SINK_START) < 0) {
3735 hsw_enable_ips(intel_crtc);
3736 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003737 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003738
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003739 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003740 return 0;
3741}
3742
3743int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3744{
3745 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003746 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003747 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3748 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003749 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003750 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003751
3752 ret = intel_dp_sink_crc_start(intel_dp);
3753 if (ret)
3754 return ret;
3755
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003756 do {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003757 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003758
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003759 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003760 DP_TEST_SINK_MISC, &buf) < 0) {
3761 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003762 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003763 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003764 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07003765
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003766 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003767
3768 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003769 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
3770 ret = -ETIMEDOUT;
3771 goto stop;
3772 }
3773
3774 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
3775 ret = -EIO;
3776 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003777 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003778
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003779stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003780 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003781 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003782}
3783
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003784static bool
3785intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3786{
Lyude9f085eb2016-04-13 10:58:33 -04003787 return drm_dp_dpcd_read(&intel_dp->aux,
Jani Nikula9d1a1032014-03-14 16:51:15 +02003788 DP_DEVICE_SERVICE_IRQ_VECTOR,
3789 sink_irq_vector, 1) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003790}
3791
Dave Airlie0e32b392014-05-02 14:02:48 +10003792static bool
3793intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3794{
3795 int ret;
3796
Lyude9f085eb2016-04-13 10:58:33 -04003797 ret = drm_dp_dpcd_read(&intel_dp->aux,
Dave Airlie0e32b392014-05-02 14:02:48 +10003798 DP_SINK_COUNT_ESI,
3799 sink_irq_vector, 14);
3800 if (ret != 14)
3801 return false;
3802
3803 return true;
3804}
3805
Todd Previtec5d5ab72015-04-15 08:38:38 -07003806static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003807{
Todd Previtec5d5ab72015-04-15 08:38:38 -07003808 uint8_t test_result = DP_TEST_ACK;
3809 return test_result;
3810}
3811
3812static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
3813{
3814 uint8_t test_result = DP_TEST_NAK;
3815 return test_result;
3816}
3817
3818static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
3819{
3820 uint8_t test_result = DP_TEST_NAK;
Todd Previte559be302015-05-04 07:48:20 -07003821 struct intel_connector *intel_connector = intel_dp->attached_connector;
3822 struct drm_connector *connector = &intel_connector->base;
3823
3824 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02003825 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07003826 intel_dp->aux.i2c_defer_count > 6) {
3827 /* Check EDID read for NACKs, DEFERs and corruption
3828 * (DP CTS 1.2 Core r1.1)
3829 * 4.2.2.4 : Failed EDID read, I2C_NAK
3830 * 4.2.2.5 : Failed EDID read, I2C_DEFER
3831 * 4.2.2.6 : EDID corruption detected
3832 * Use failsafe mode for all cases
3833 */
3834 if (intel_dp->aux.i2c_nack_count > 0 ||
3835 intel_dp->aux.i2c_defer_count > 0)
3836 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
3837 intel_dp->aux.i2c_nack_count,
3838 intel_dp->aux.i2c_defer_count);
3839 intel_dp->compliance_test_data = INTEL_DP_RESOLUTION_FAILSAFE;
3840 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05303841 struct edid *block = intel_connector->detect_edid;
3842
3843 /* We have to write the checksum
3844 * of the last block read
3845 */
3846 block += intel_connector->detect_edid->extensions;
3847
Todd Previte559be302015-05-04 07:48:20 -07003848 if (!drm_dp_dpcd_write(&intel_dp->aux,
3849 DP_TEST_EDID_CHECKSUM,
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05303850 &block->checksum,
Dan Carpenter5a1cc652015-05-12 21:07:37 +03003851 1))
Todd Previte559be302015-05-04 07:48:20 -07003852 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
3853
3854 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
3855 intel_dp->compliance_test_data = INTEL_DP_RESOLUTION_STANDARD;
3856 }
3857
3858 /* Set test active flag here so userspace doesn't interrupt things */
3859 intel_dp->compliance_test_active = 1;
3860
Todd Previtec5d5ab72015-04-15 08:38:38 -07003861 return test_result;
3862}
3863
3864static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
3865{
3866 uint8_t test_result = DP_TEST_NAK;
3867 return test_result;
3868}
3869
3870static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
3871{
3872 uint8_t response = DP_TEST_NAK;
3873 uint8_t rxdata = 0;
3874 int status = 0;
3875
Todd Previtec5d5ab72015-04-15 08:38:38 -07003876 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_REQUEST, &rxdata, 1);
3877 if (status <= 0) {
3878 DRM_DEBUG_KMS("Could not read test request from sink\n");
3879 goto update_status;
3880 }
3881
3882 switch (rxdata) {
3883 case DP_TEST_LINK_TRAINING:
3884 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
3885 intel_dp->compliance_test_type = DP_TEST_LINK_TRAINING;
3886 response = intel_dp_autotest_link_training(intel_dp);
3887 break;
3888 case DP_TEST_LINK_VIDEO_PATTERN:
3889 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
3890 intel_dp->compliance_test_type = DP_TEST_LINK_VIDEO_PATTERN;
3891 response = intel_dp_autotest_video_pattern(intel_dp);
3892 break;
3893 case DP_TEST_LINK_EDID_READ:
3894 DRM_DEBUG_KMS("EDID test requested\n");
3895 intel_dp->compliance_test_type = DP_TEST_LINK_EDID_READ;
3896 response = intel_dp_autotest_edid(intel_dp);
3897 break;
3898 case DP_TEST_LINK_PHY_TEST_PATTERN:
3899 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
3900 intel_dp->compliance_test_type = DP_TEST_LINK_PHY_TEST_PATTERN;
3901 response = intel_dp_autotest_phy_pattern(intel_dp);
3902 break;
3903 default:
3904 DRM_DEBUG_KMS("Invalid test request '%02x'\n", rxdata);
3905 break;
3906 }
3907
3908update_status:
3909 status = drm_dp_dpcd_write(&intel_dp->aux,
3910 DP_TEST_RESPONSE,
3911 &response, 1);
3912 if (status <= 0)
3913 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003914}
3915
Dave Airlie0e32b392014-05-02 14:02:48 +10003916static int
3917intel_dp_check_mst_status(struct intel_dp *intel_dp)
3918{
3919 bool bret;
3920
3921 if (intel_dp->is_mst) {
3922 u8 esi[16] = { 0 };
3923 int ret = 0;
3924 int retry;
3925 bool handled;
3926 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
3927go_again:
3928 if (bret == true) {
3929
3930 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03003931 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03003932 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10003933 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
3934 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10003935 intel_dp_stop_link_train(intel_dp);
3936 }
3937
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02003938 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10003939 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
3940
3941 if (handled) {
3942 for (retry = 0; retry < 3; retry++) {
3943 int wret;
3944 wret = drm_dp_dpcd_write(&intel_dp->aux,
3945 DP_SINK_COUNT_ESI+1,
3946 &esi[1], 3);
3947 if (wret == 3) {
3948 break;
3949 }
3950 }
3951
3952 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
3953 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02003954 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10003955 goto go_again;
3956 }
3957 } else
3958 ret = 0;
3959
3960 return ret;
3961 } else {
3962 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3963 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
3964 intel_dp->is_mst = false;
3965 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
3966 /* send a hotplug event */
3967 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
3968 }
3969 }
3970 return -EINVAL;
3971}
3972
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05303973static void
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03003974intel_dp_retrain_link(struct intel_dp *intel_dp)
3975{
3976 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3977 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3978 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
3979
3980 /* Suppress underruns caused by re-training */
3981 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
3982 if (crtc->config->has_pch_encoder)
3983 intel_set_pch_fifo_underrun_reporting(dev_priv,
3984 intel_crtc_pch_transcoder(crtc), false);
3985
3986 intel_dp_start_link_train(intel_dp);
3987 intel_dp_stop_link_train(intel_dp);
3988
3989 /* Keep underrun reporting disabled until things are stable */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02003990 intel_wait_for_vblank(dev_priv, crtc->pipe);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03003991
3992 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
3993 if (crtc->config->has_pch_encoder)
3994 intel_set_pch_fifo_underrun_reporting(dev_priv,
3995 intel_crtc_pch_transcoder(crtc), true);
3996}
3997
3998static void
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05303999intel_dp_check_link_status(struct intel_dp *intel_dp)
4000{
4001 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4002 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4003 u8 link_status[DP_LINK_STATUS_SIZE];
4004
4005 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
4006
4007 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4008 DRM_ERROR("Failed to get link status\n");
4009 return;
4010 }
4011
4012 if (!intel_encoder->base.crtc)
4013 return;
4014
4015 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4016 return;
4017
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004018 /* FIXME: we need to synchronize this sort of stuff with hardware
4019 * readout */
4020 if (WARN_ON_ONCE(!intel_dp->lane_count))
4021 return;
4022
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304023 /* if link training is requested we should perform it always */
4024 if ((intel_dp->compliance_test_type == DP_TEST_LINK_TRAINING) ||
4025 (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count))) {
4026 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4027 intel_encoder->base.name);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004028
4029 intel_dp_retrain_link(intel_dp);
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304030 }
4031}
4032
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004033/*
4034 * According to DP spec
4035 * 5.1.2:
4036 * 1. Read DPCD
4037 * 2. Configure link according to Receiver Capabilities
4038 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4039 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304040 *
4041 * intel_dp_short_pulse - handles short pulse interrupts
4042 * when full detection is not required.
4043 * Returns %true if short pulse is handled and full detection
4044 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004045 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304046static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304047intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004048{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004049 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004050 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304051 u8 old_sink_count = intel_dp->sink_count;
4052 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004053
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304054 /*
4055 * Clearing compliance test variables to allow capturing
4056 * of values for next automated test request.
4057 */
4058 intel_dp->compliance_test_active = 0;
4059 intel_dp->compliance_test_type = 0;
4060 intel_dp->compliance_test_data = 0;
4061
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304062 /*
4063 * Now read the DPCD to see if it's actually running
4064 * If the current value of sink count doesn't match with
4065 * the value that was stored earlier or dpcd read failed
4066 * we need to do full detection
4067 */
4068 ret = intel_dp_get_dpcd(intel_dp);
4069
4070 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4071 /* No need to proceed if we are going to do full detect */
4072 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004073 }
4074
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004075 /* Try to read the source of the interrupt */
4076 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004077 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4078 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004079 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004080 drm_dp_dpcd_writeb(&intel_dp->aux,
4081 DP_DEVICE_SERVICE_IRQ_VECTOR,
4082 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004083
4084 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Todd Previte09b1eb12015-04-20 15:27:34 -07004085 DRM_DEBUG_DRIVER("Test request in short pulse not handled\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004086 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4087 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4088 }
4089
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304090 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4091 intel_dp_check_link_status(intel_dp);
4092 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304093
4094 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004095}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004096
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004097/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004098static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004099intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004100{
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004101 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004102 uint8_t type;
4103
4104 if (!intel_dp_get_dpcd(intel_dp))
4105 return connector_status_disconnected;
4106
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304107 if (is_edp(intel_dp))
4108 return connector_status_connected;
4109
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004110 /* if there's no downstream port, we're done */
Imre Deakc726ad02016-10-24 19:33:24 +03004111 if (!drm_dp_is_branch(dpcd))
Keith Packard26d61aa2011-07-25 20:01:09 -07004112 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004113
4114 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004115 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4116 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004117
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304118 return intel_dp->sink_count ?
4119 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004120 }
4121
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004122 if (intel_dp_can_mst(intel_dp))
4123 return connector_status_connected;
4124
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004125 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004126 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004127 return connector_status_connected;
4128
4129 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004130 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4131 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4132 if (type == DP_DS_PORT_TYPE_VGA ||
4133 type == DP_DS_PORT_TYPE_NON_EDID)
4134 return connector_status_unknown;
4135 } else {
4136 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4137 DP_DWN_STRM_PORT_TYPE_MASK;
4138 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4139 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4140 return connector_status_unknown;
4141 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004142
4143 /* Anything else is out of spec, warn and ignore */
4144 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004145 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004146}
4147
4148static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004149edp_detect(struct intel_dp *intel_dp)
4150{
4151 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4152 enum drm_connector_status status;
4153
4154 status = intel_panel_detect(dev);
4155 if (status == connector_status_unknown)
4156 status = connector_status_connected;
4157
4158 return status;
4159}
4160
Jani Nikulab93433c2015-08-20 10:47:36 +03004161static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4162 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004163{
Jani Nikulab93433c2015-08-20 10:47:36 +03004164 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004165
Jani Nikula0df53b72015-08-20 10:47:40 +03004166 switch (port->port) {
4167 case PORT_A:
4168 return true;
4169 case PORT_B:
4170 bit = SDE_PORTB_HOTPLUG;
4171 break;
4172 case PORT_C:
4173 bit = SDE_PORTC_HOTPLUG;
4174 break;
4175 case PORT_D:
4176 bit = SDE_PORTD_HOTPLUG;
4177 break;
4178 default:
4179 MISSING_CASE(port->port);
4180 return false;
4181 }
4182
4183 return I915_READ(SDEISR) & bit;
4184}
4185
4186static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4187 struct intel_digital_port *port)
4188{
4189 u32 bit;
4190
4191 switch (port->port) {
4192 case PORT_A:
4193 return true;
4194 case PORT_B:
4195 bit = SDE_PORTB_HOTPLUG_CPT;
4196 break;
4197 case PORT_C:
4198 bit = SDE_PORTC_HOTPLUG_CPT;
4199 break;
4200 case PORT_D:
4201 bit = SDE_PORTD_HOTPLUG_CPT;
4202 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004203 case PORT_E:
4204 bit = SDE_PORTE_HOTPLUG_SPT;
4205 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004206 default:
4207 MISSING_CASE(port->port);
4208 return false;
Jani Nikulab93433c2015-08-20 10:47:36 +03004209 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004210
Jani Nikulab93433c2015-08-20 10:47:36 +03004211 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004212}
4213
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004214static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004215 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004216{
Jani Nikula9642c812015-08-20 10:47:41 +03004217 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004218
Jani Nikula9642c812015-08-20 10:47:41 +03004219 switch (port->port) {
4220 case PORT_B:
4221 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4222 break;
4223 case PORT_C:
4224 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4225 break;
4226 case PORT_D:
4227 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4228 break;
4229 default:
4230 MISSING_CASE(port->port);
4231 return false;
4232 }
4233
4234 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4235}
4236
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004237static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4238 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004239{
4240 u32 bit;
4241
4242 switch (port->port) {
4243 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004244 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004245 break;
4246 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004247 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004248 break;
4249 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004250 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004251 break;
4252 default:
4253 MISSING_CASE(port->port);
4254 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004255 }
4256
Jani Nikula1d245982015-08-20 10:47:37 +03004257 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004258}
4259
Jani Nikulae464bfd2015-08-20 10:47:42 +03004260static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304261 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004262{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304263 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4264 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004265 u32 bit;
4266
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304267 intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port);
4268 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004269 case PORT_A:
4270 bit = BXT_DE_PORT_HP_DDIA;
4271 break;
4272 case PORT_B:
4273 bit = BXT_DE_PORT_HP_DDIB;
4274 break;
4275 case PORT_C:
4276 bit = BXT_DE_PORT_HP_DDIC;
4277 break;
4278 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304279 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004280 return false;
4281 }
4282
4283 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4284}
4285
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004286/*
4287 * intel_digital_port_connected - is the specified port connected?
4288 * @dev_priv: i915 private structure
4289 * @port: the port to test
4290 *
4291 * Return %true if @port is connected, %false otherwise.
4292 */
David Weinehall23f889b2016-08-17 15:47:48 +03004293static bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004294 struct intel_digital_port *port)
4295{
Jani Nikula0df53b72015-08-20 10:47:40 +03004296 if (HAS_PCH_IBX(dev_priv))
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004297 return ibx_digital_port_connected(dev_priv, port);
Ville Syrjälä22824fa2016-02-11 16:44:28 +02004298 else if (HAS_PCH_SPLIT(dev_priv))
Jani Nikula0df53b72015-08-20 10:47:40 +03004299 return cpt_digital_port_connected(dev_priv, port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004300 else if (IS_BROXTON(dev_priv))
4301 return bxt_digital_port_connected(dev_priv, port);
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004302 else if (IS_GM45(dev_priv))
4303 return gm45_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004304 else
4305 return g4x_digital_port_connected(dev_priv, port);
4306}
4307
Keith Packard8c241fe2011-09-28 16:38:44 -07004308static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004309intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004310{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004311 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004312
Jani Nikula9cd300e2012-10-19 14:51:52 +03004313 /* use cached edid if we have one */
4314 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004315 /* invalid edid */
4316 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004317 return NULL;
4318
Jani Nikula55e9ede2013-10-01 10:38:54 +03004319 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004320 } else
4321 return drm_get_edid(&intel_connector->base,
4322 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004323}
4324
Chris Wilsonbeb60602014-09-02 20:04:00 +01004325static void
4326intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004327{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004328 struct intel_connector *intel_connector = intel_dp->attached_connector;
4329 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004330
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304331 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004332 edid = intel_dp_get_edid(intel_dp);
4333 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004334
Chris Wilsonbeb60602014-09-02 20:04:00 +01004335 if (intel_dp->force_audio != HDMI_AUDIO_AUTO)
4336 intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON;
4337 else
4338 intel_dp->has_audio = drm_detect_monitor_audio(edid);
4339}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004340
Chris Wilsonbeb60602014-09-02 20:04:00 +01004341static void
4342intel_dp_unset_edid(struct intel_dp *intel_dp)
4343{
4344 struct intel_connector *intel_connector = intel_dp->attached_connector;
4345
4346 kfree(intel_connector->detect_edid);
4347 intel_connector->detect_edid = NULL;
4348
4349 intel_dp->has_audio = false;
4350}
4351
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004352static enum drm_connector_status
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304353intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004354{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304355 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004356 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004357 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4358 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004359 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004360 enum drm_connector_status status;
Imre Deak671dedd2014-03-05 16:20:53 +02004361 enum intel_display_power_domain power_domain;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004362 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004363
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004364 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4365 intel_display_power_get(to_i915(dev), power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004366
Chris Wilsond410b562014-09-02 20:03:59 +01004367 /* Can't disconnect eDP, but you can close the lid... */
4368 if (is_edp(intel_dp))
4369 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004370 else if (intel_digital_port_connected(to_i915(dev),
4371 dp_to_dig_port(intel_dp)))
4372 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004373 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004374 status = connector_status_disconnected;
4375
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004376 if (status == connector_status_disconnected) {
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304377 intel_dp->compliance_test_active = 0;
4378 intel_dp->compliance_test_type = 0;
4379 intel_dp->compliance_test_data = 0;
4380
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004381 if (intel_dp->is_mst) {
4382 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4383 intel_dp->is_mst,
4384 intel_dp->mst_mgr.mst_state);
4385 intel_dp->is_mst = false;
4386 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4387 intel_dp->is_mst);
4388 }
4389
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004390 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304391 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004392
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304393 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004394 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304395
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004396 DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
4397 yesno(intel_dp_source_supports_hbr2(intel_dp)),
4398 yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
4399
4400 intel_dp_print_rates(intel_dp);
4401
Imre Deak7b3fc172016-10-25 16:12:39 +03004402 intel_dp_read_desc(intel_dp);
Mika Kahola0e390a32016-09-09 14:10:53 +03004403
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004404 intel_dp_configure_mst(intel_dp);
4405
4406 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304407 /*
4408 * If we are in MST mode then this connector
4409 * won't appear connected or have anything
4410 * with EDID on it
4411 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004412 status = connector_status_disconnected;
4413 goto out;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304414 } else if (connector->status == connector_status_connected) {
4415 /*
4416 * If display was connected already and is still connected
4417 * check links status, there has been known issues of
4418 * link loss triggerring long pulse!!!!
4419 */
4420 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4421 intel_dp_check_link_status(intel_dp);
4422 drm_modeset_unlock(&dev->mode_config.connection_mutex);
4423 goto out;
Dave Airlie0e32b392014-05-02 14:02:48 +10004424 }
4425
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304426 /*
4427 * Clearing NACK and defer counts to get their exact values
4428 * while reading EDID which are required by Compliance tests
4429 * 4.2.2.4 and 4.2.2.5
4430 */
4431 intel_dp->aux.i2c_nack_count = 0;
4432 intel_dp->aux.i2c_defer_count = 0;
4433
Chris Wilsonbeb60602014-09-02 20:04:00 +01004434 intel_dp_set_edid(intel_dp);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004435 if (is_edp(intel_dp) || intel_connector->detect_edid)
4436 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304437 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004438
Todd Previte09b1eb12015-04-20 15:27:34 -07004439 /* Try to read the source of the interrupt */
4440 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004441 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4442 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004443 /* Clear interrupt source */
4444 drm_dp_dpcd_writeb(&intel_dp->aux,
4445 DP_DEVICE_SERVICE_IRQ_VECTOR,
4446 sink_irq_vector);
4447
4448 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4449 intel_dp_handle_test_request(intel_dp);
4450 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4451 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4452 }
4453
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004454out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004455 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304456 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304457
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004458 intel_display_power_put(to_i915(dev), power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004459 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304460}
4461
4462static enum drm_connector_status
4463intel_dp_detect(struct drm_connector *connector, bool force)
4464{
4465 struct intel_dp *intel_dp = intel_attached_dp(connector);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004466 enum drm_connector_status status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304467
4468 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4469 connector->base.id, connector->name);
4470
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304471 /* If full detect is not performed yet, do a full detect */
4472 if (!intel_dp->detect_done)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004473 status = intel_dp_long_pulse(intel_dp->attached_connector);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304474
4475 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304476
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004477 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004478}
4479
Chris Wilsonbeb60602014-09-02 20:04:00 +01004480static void
4481intel_dp_force(struct drm_connector *connector)
4482{
4483 struct intel_dp *intel_dp = intel_attached_dp(connector);
4484 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004485 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004486 enum intel_display_power_domain power_domain;
4487
4488 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4489 connector->base.id, connector->name);
4490 intel_dp_unset_edid(intel_dp);
4491
4492 if (connector->status != connector_status_connected)
4493 return;
4494
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004495 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4496 intel_display_power_get(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004497
4498 intel_dp_set_edid(intel_dp);
4499
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004500 intel_display_power_put(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004501
4502 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004503 intel_encoder->type = INTEL_OUTPUT_DP;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004504}
4505
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004506static int intel_dp_get_modes(struct drm_connector *connector)
4507{
Jani Nikuladd06f902012-10-19 14:51:50 +03004508 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004509 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004510
Chris Wilsonbeb60602014-09-02 20:04:00 +01004511 edid = intel_connector->detect_edid;
4512 if (edid) {
4513 int ret = intel_connector_update_modes(connector, edid);
4514 if (ret)
4515 return ret;
4516 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004517
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004518 /* if eDP has no EDID, fall back to fixed mode */
Chris Wilsonbeb60602014-09-02 20:04:00 +01004519 if (is_edp(intel_attached_dp(connector)) &&
4520 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004521 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004522
4523 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004524 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004525 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004526 drm_mode_probed_add(connector, mode);
4527 return 1;
4528 }
4529 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004530
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004531 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004532}
4533
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004534static bool
4535intel_dp_detect_audio(struct drm_connector *connector)
4536{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004537 bool has_audio = false;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004538 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004539
Chris Wilsonbeb60602014-09-02 20:04:00 +01004540 edid = to_intel_connector(connector)->detect_edid;
4541 if (edid)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004542 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02004543
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004544 return has_audio;
4545}
4546
Chris Wilsonf6849602010-09-19 09:29:33 +01004547static int
4548intel_dp_set_property(struct drm_connector *connector,
4549 struct drm_property *property,
4550 uint64_t val)
4551{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004552 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Yuly Novikov53b41832012-10-26 12:04:00 +03004553 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004554 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
4555 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01004556 int ret;
4557
Rob Clark662595d2012-10-11 20:36:04 -05004558 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01004559 if (ret)
4560 return ret;
4561
Chris Wilson3f43c482011-05-12 22:17:24 +01004562 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004563 int i = val;
4564 bool has_audio;
4565
4566 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004567 return 0;
4568
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004569 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01004570
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004571 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004572 has_audio = intel_dp_detect_audio(connector);
4573 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004574 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004575
4576 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004577 return 0;
4578
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004579 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01004580 goto done;
4581 }
4582
Chris Wilsone953fd72011-02-21 22:23:52 +00004583 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02004584 bool old_auto = intel_dp->color_range_auto;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004585 bool old_range = intel_dp->limited_color_range;
Daniel Vetterae4edb82013-04-22 17:07:23 +02004586
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004587 switch (val) {
4588 case INTEL_BROADCAST_RGB_AUTO:
4589 intel_dp->color_range_auto = true;
4590 break;
4591 case INTEL_BROADCAST_RGB_FULL:
4592 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004593 intel_dp->limited_color_range = false;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004594 break;
4595 case INTEL_BROADCAST_RGB_LIMITED:
4596 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004597 intel_dp->limited_color_range = true;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004598 break;
4599 default:
4600 return -EINVAL;
4601 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02004602
4603 if (old_auto == intel_dp->color_range_auto &&
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004604 old_range == intel_dp->limited_color_range)
Daniel Vetterae4edb82013-04-22 17:07:23 +02004605 return 0;
4606
Chris Wilsone953fd72011-02-21 22:23:52 +00004607 goto done;
4608 }
4609
Yuly Novikov53b41832012-10-26 12:04:00 +03004610 if (is_edp(intel_dp) &&
4611 property == connector->dev->mode_config.scaling_mode_property) {
4612 if (val == DRM_MODE_SCALE_NONE) {
4613 DRM_DEBUG_KMS("no scaling not supported\n");
4614 return -EINVAL;
4615 }
Ville Syrjälä234126c2016-04-12 22:14:38 +03004616 if (HAS_GMCH_DISPLAY(dev_priv) &&
4617 val == DRM_MODE_SCALE_CENTER) {
4618 DRM_DEBUG_KMS("centering not supported\n");
4619 return -EINVAL;
4620 }
Yuly Novikov53b41832012-10-26 12:04:00 +03004621
4622 if (intel_connector->panel.fitting_mode == val) {
4623 /* the eDP scaling property is not changed */
4624 return 0;
4625 }
4626 intel_connector->panel.fitting_mode = val;
4627
4628 goto done;
4629 }
4630
Chris Wilsonf6849602010-09-19 09:29:33 +01004631 return -EINVAL;
4632
4633done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00004634 if (intel_encoder->base.crtc)
4635 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01004636
4637 return 0;
4638}
4639
Chris Wilson7a418e32016-06-24 14:00:14 +01004640static int
4641intel_dp_connector_register(struct drm_connector *connector)
4642{
4643 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004644 int ret;
4645
4646 ret = intel_connector_register(connector);
4647 if (ret)
4648 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004649
4650 i915_debugfs_connector_add(connector);
4651
4652 DRM_DEBUG_KMS("registering %s bus for %s\n",
4653 intel_dp->aux.name, connector->kdev->kobj.name);
4654
4655 intel_dp->aux.dev = connector->kdev;
4656 return drm_dp_aux_register(&intel_dp->aux);
4657}
4658
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004659static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004660intel_dp_connector_unregister(struct drm_connector *connector)
4661{
4662 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4663 intel_connector_unregister(connector);
4664}
4665
4666static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004667intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004668{
Jani Nikula1d508702012-10-19 14:51:49 +03004669 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004670
Chris Wilson10e972d2014-09-04 21:43:45 +01004671 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004672
Jani Nikula9cd300e2012-10-19 14:51:52 +03004673 if (!IS_ERR_OR_NULL(intel_connector->edid))
4674 kfree(intel_connector->edid);
4675
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004676 /* Can't call is_edp() since the encoder may have been destroyed
4677 * already. */
4678 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004679 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004680
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004681 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004682 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004683}
4684
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004685void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004686{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004687 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4688 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004689
Dave Airlie0e32b392014-05-02 14:02:48 +10004690 intel_dp_mst_encoder_cleanup(intel_dig_port);
Keith Packardbd943152011-09-18 23:09:52 -07004691 if (is_edp(intel_dp)) {
4692 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004693 /*
4694 * vdd might still be enabled do to the delayed vdd off.
4695 * Make sure vdd is actually turned off here.
4696 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004697 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004698 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004699 pps_unlock(intel_dp);
4700
Clint Taylor01527b32014-07-07 13:01:46 -07004701 if (intel_dp->edp_notifier.notifier_call) {
4702 unregister_reboot_notifier(&intel_dp->edp_notifier);
4703 intel_dp->edp_notifier.notifier_call = NULL;
4704 }
Keith Packardbd943152011-09-18 23:09:52 -07004705 }
Chris Wilson99681882016-06-20 09:29:17 +01004706
4707 intel_dp_aux_fini(intel_dp);
4708
Imre Deakc8bd0e42014-12-12 17:57:38 +02004709 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004710 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004711}
4712
Imre Deakbf93ba62016-04-18 10:04:21 +03004713void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004714{
4715 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4716
4717 if (!is_edp(intel_dp))
4718 return;
4719
Ville Syrjälä951468f2014-09-04 14:55:31 +03004720 /*
4721 * vdd might still be enabled do to the delayed vdd off.
4722 * Make sure vdd is actually turned off here.
4723 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004724 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004725 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004726 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004727 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004728}
4729
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004730static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4731{
4732 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4733 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004734 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004735 enum intel_display_power_domain power_domain;
4736
4737 lockdep_assert_held(&dev_priv->pps_mutex);
4738
4739 if (!edp_have_panel_vdd(intel_dp))
4740 return;
4741
4742 /*
4743 * The VDD bit needs a power domain reference, so if the bit is
4744 * already enabled when we boot or resume, grab this reference and
4745 * schedule a vdd off, so we don't hold on to the reference
4746 * indefinitely.
4747 */
4748 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004749 power_domain = intel_display_port_aux_power_domain(&intel_dig_port->base);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004750 intel_display_power_get(dev_priv, power_domain);
4751
4752 edp_panel_vdd_schedule_off(intel_dp);
4753}
4754
Imre Deakbf93ba62016-04-18 10:04:21 +03004755void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03004756{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03004757 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Shashank Sharma910530c2016-10-14 19:56:52 +05304758 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4759 struct intel_lspcon *lspcon = &intel_dig_port->lspcon;
4760 struct intel_dp *intel_dp = &intel_dig_port->dp;
Ville Syrjälä64989ca42016-05-13 20:53:56 +03004761
4762 if (!HAS_DDI(dev_priv))
4763 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004764
Shashank Sharma910530c2016-10-14 19:56:52 +05304765 if (IS_GEN9(dev_priv) && lspcon->active)
4766 lspcon_resume(lspcon);
4767
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004768 if (to_intel_encoder(encoder)->type != INTEL_OUTPUT_EDP)
4769 return;
4770
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004771 pps_lock(intel_dp);
4772
Imre Deak335f7522016-08-10 14:07:32 +03004773 /* Reinit the power sequencer, in case BIOS did something with it. */
4774 intel_dp_pps_init(encoder->dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004775 intel_edp_panel_vdd_sanitize(intel_dp);
4776
4777 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03004778}
4779
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004780static const struct drm_connector_funcs intel_dp_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02004781 .dpms = drm_atomic_helper_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004782 .detect = intel_dp_detect,
Chris Wilsonbeb60602014-09-02 20:04:00 +01004783 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004784 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01004785 .set_property = intel_dp_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -08004786 .atomic_get_property = intel_connector_atomic_get_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01004787 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01004788 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004789 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08004790 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02004791 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004792};
4793
4794static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
4795 .get_modes = intel_dp_get_modes,
4796 .mode_valid = intel_dp_mode_valid,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004797};
4798
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004799static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03004800 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02004801 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004802};
4803
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004804enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10004805intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
4806{
4807 struct intel_dp *intel_dp = &intel_dig_port->dp;
Imre Deak1c767b32014-08-18 14:42:42 +03004808 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Dave Airlie0e32b392014-05-02 14:02:48 +10004809 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004810 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak1c767b32014-08-18 14:42:42 +03004811 enum intel_display_power_domain power_domain;
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004812 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03004813
Takashi Iwai25400582015-11-19 12:09:56 +01004814 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
4815 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004816 intel_dig_port->base.type = INTEL_OUTPUT_DP;
Dave Airlie13cf5502014-06-18 11:29:35 +10004817
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03004818 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
4819 /*
4820 * vdd off can generate a long pulse on eDP which
4821 * would require vdd on to handle it, and thus we
4822 * would end up in an endless cycle of
4823 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
4824 */
4825 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
4826 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d522015-02-10 14:11:46 +02004827 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03004828 }
4829
Ville Syrjälä26fbb772014-08-11 18:37:37 +03004830 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
4831 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10004832 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10004833
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004834 if (long_hpd) {
4835 intel_dp->detect_done = false;
4836 return IRQ_NONE;
4837 }
4838
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004839 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak1c767b32014-08-18 14:42:42 +03004840 intel_display_power_get(dev_priv, power_domain);
4841
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004842 if (intel_dp->is_mst) {
4843 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
4844 /*
4845 * If we were in MST mode, and device is not
4846 * there, get out of MST mode
4847 */
4848 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4849 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
4850 intel_dp->is_mst = false;
4851 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4852 intel_dp->is_mst);
4853 intel_dp->detect_done = false;
4854 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10004855 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004856 }
Dave Airlie0e32b392014-05-02 14:02:48 +10004857
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004858 if (!intel_dp->is_mst) {
4859 if (!intel_dp_short_pulse(intel_dp)) {
4860 intel_dp->detect_done = false;
4861 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304862 }
Dave Airlie0e32b392014-05-02 14:02:48 +10004863 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004864
4865 ret = IRQ_HANDLED;
4866
Imre Deak1c767b32014-08-18 14:42:42 +03004867put_power:
4868 intel_display_power_put(dev_priv, power_domain);
4869
4870 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10004871}
4872
Rodrigo Vivi477ec322015-08-06 15:51:39 +08004873/* check the VBT to see whether the eDP is on another port */
Ville Syrjälä5d8a7752013-11-01 18:22:39 +02004874bool intel_dp_is_edp(struct drm_device *dev, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08004875{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004876 struct drm_i915_private *dev_priv = to_i915(dev);
Zhao Yakui36e83a12010-06-12 14:32:21 +08004877
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03004878 /*
4879 * eDP not supported on g4x. so bail out early just
4880 * for a bit extra safety in case the VBT is bonkers.
4881 */
4882 if (INTEL_INFO(dev)->gen < 5)
4883 return false;
4884
Ville Syrjälä3b32a352013-11-01 18:22:41 +02004885 if (port == PORT_A)
4886 return true;
4887
Jani Nikula951d9ef2016-03-16 12:43:31 +02004888 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08004889}
4890
Dave Airlie0e32b392014-05-02 14:02:48 +10004891void
Chris Wilsonf6849602010-09-19 09:29:33 +01004892intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
4893{
Yuly Novikov53b41832012-10-26 12:04:00 +03004894 struct intel_connector *intel_connector = to_intel_connector(connector);
4895
Chris Wilson3f43c482011-05-12 22:17:24 +01004896 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00004897 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004898 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03004899
4900 if (is_edp(intel_dp)) {
4901 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05004902 drm_object_attach_property(
4903 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03004904 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03004905 DRM_MODE_SCALE_ASPECT);
4906 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03004907 }
Chris Wilsonf6849602010-09-19 09:29:33 +01004908}
4909
Imre Deakdada1a92014-01-29 13:25:41 +02004910static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
4911{
Abhay Kumard28d4732016-01-22 17:39:04 -08004912 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02004913 intel_dp->last_power_on = jiffies;
4914 intel_dp->last_backlight_off = jiffies;
4915}
4916
Daniel Vetter67a54562012-10-20 20:57:45 +02004917static void
Imre Deak54648612016-06-16 16:37:22 +03004918intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
4919 struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02004920{
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304921 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03004922 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07004923
Imre Deak8e8232d2016-06-16 16:37:21 +03004924 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02004925
4926 /* Workaround: Need to write PP_CONTROL with the unlock key as
4927 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304928 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02004929
Imre Deak8e8232d2016-06-16 16:37:21 +03004930 pp_on = I915_READ(regs.pp_on);
4931 pp_off = I915_READ(regs.pp_off);
Imre Deak54648612016-06-16 16:37:22 +03004932 if (!IS_BROXTON(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03004933 I915_WRITE(regs.pp_ctrl, pp_ctl);
4934 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304935 }
Daniel Vetter67a54562012-10-20 20:57:45 +02004936
4937 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03004938 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
4939 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004940
Imre Deak54648612016-06-16 16:37:22 +03004941 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
4942 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004943
Imre Deak54648612016-06-16 16:37:22 +03004944 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
4945 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004946
Imre Deak54648612016-06-16 16:37:22 +03004947 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
4948 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004949
Imre Deak54648612016-06-16 16:37:22 +03004950 if (IS_BROXTON(dev_priv)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304951 u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
4952 BXT_POWER_CYCLE_DELAY_SHIFT;
4953 if (tmp > 0)
Imre Deak54648612016-06-16 16:37:22 +03004954 seq->t11_t12 = (tmp - 1) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304955 else
Imre Deak54648612016-06-16 16:37:22 +03004956 seq->t11_t12 = 0;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304957 } else {
Imre Deak54648612016-06-16 16:37:22 +03004958 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02004959 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304960 }
Imre Deak54648612016-06-16 16:37:22 +03004961}
4962
4963static void
Imre Deakde9c1b62016-06-16 20:01:46 +03004964intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
4965{
4966 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
4967 state_name,
4968 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
4969}
4970
4971static void
4972intel_pps_verify_state(struct drm_i915_private *dev_priv,
4973 struct intel_dp *intel_dp)
4974{
4975 struct edp_power_seq hw;
4976 struct edp_power_seq *sw = &intel_dp->pps_delays;
4977
4978 intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
4979
4980 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
4981 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
4982 DRM_ERROR("PPS state mismatch\n");
4983 intel_pps_dump_state("sw", sw);
4984 intel_pps_dump_state("hw", &hw);
4985 }
4986}
4987
4988static void
Imre Deak54648612016-06-16 16:37:22 +03004989intel_dp_init_panel_power_sequencer(struct drm_device *dev,
4990 struct intel_dp *intel_dp)
4991{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004992 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak54648612016-06-16 16:37:22 +03004993 struct edp_power_seq cur, vbt, spec,
4994 *final = &intel_dp->pps_delays;
4995
4996 lockdep_assert_held(&dev_priv->pps_mutex);
4997
4998 /* already initialized? */
4999 if (final->t11_t12 != 0)
5000 return;
5001
5002 intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005003
Imre Deakde9c1b62016-06-16 20:01:46 +03005004 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005005
Jani Nikula6aa23e62016-03-24 17:50:20 +02005006 vbt = dev_priv->vbt.edp.pps;
Daniel Vetter67a54562012-10-20 20:57:45 +02005007
5008 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5009 * our hw here, which are all in 100usec. */
5010 spec.t1_t3 = 210 * 10;
5011 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5012 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5013 spec.t10 = 500 * 10;
5014 /* This one is special and actually in units of 100ms, but zero
5015 * based in the hw (so we need to add 100 ms). But the sw vbt
5016 * table multiplies it with 1000 to make it in units of 100usec,
5017 * too. */
5018 spec.t11_t12 = (510 + 100) * 10;
5019
Imre Deakde9c1b62016-06-16 20:01:46 +03005020 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005021
5022 /* Use the max of the register settings and vbt. If both are
5023 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005024#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005025 spec.field : \
5026 max(cur.field, vbt.field))
5027 assign_final(t1_t3);
5028 assign_final(t8);
5029 assign_final(t9);
5030 assign_final(t10);
5031 assign_final(t11_t12);
5032#undef assign_final
5033
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005034#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005035 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5036 intel_dp->backlight_on_delay = get_delay(t8);
5037 intel_dp->backlight_off_delay = get_delay(t9);
5038 intel_dp->panel_power_down_delay = get_delay(t10);
5039 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5040#undef get_delay
5041
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005042 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5043 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5044 intel_dp->panel_power_cycle_delay);
5045
5046 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5047 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005048
5049 /*
5050 * We override the HW backlight delays to 1 because we do manual waits
5051 * on them. For T8, even BSpec recommends doing it. For T9, if we
5052 * don't do this, we'll end up waiting for the backlight off delay
5053 * twice: once when we do the manual sleep, and once when we disable
5054 * the panel and wait for the PP_STATUS bit to become zero.
5055 */
5056 final->t8 = 1;
5057 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005058}
5059
5060static void
5061intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005062 struct intel_dp *intel_dp)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005063{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005064 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07005065 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005066 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005067 struct pps_registers regs;
Ville Syrjäläad933b52014-08-18 22:15:56 +03005068 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005069 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005070
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005071 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005072
Imre Deak8e8232d2016-06-16 16:37:21 +03005073 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005074
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005075 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005076 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5077 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005078 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005079 /* Compute the divisor for the pp clock, simply match the Bspec
5080 * formula. */
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01005081 if (IS_BROXTON(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005082 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305083 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
5084 pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
5085 << BXT_POWER_CYCLE_DELAY_SHIFT);
5086 } else {
5087 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5088 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5089 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5090 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005091
5092 /* Haswell doesn't have any port selection bits for the panel
5093 * power sequencer any more. */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005094 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005095 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005096 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005097 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005098 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005099 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005100 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005101 }
5102
Jesse Barnes453c5422013-03-28 09:55:41 -07005103 pp_on |= port_sel;
5104
Imre Deak8e8232d2016-06-16 16:37:21 +03005105 I915_WRITE(regs.pp_on, pp_on);
5106 I915_WRITE(regs.pp_off, pp_off);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01005107 if (IS_BROXTON(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005108 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305109 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005110 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005111
Daniel Vetter67a54562012-10-20 20:57:45 +02005112 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 +03005113 I915_READ(regs.pp_on),
5114 I915_READ(regs.pp_off),
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01005115 IS_BROXTON(dev_priv) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005116 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5117 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005118}
5119
Imre Deak335f7522016-08-10 14:07:32 +03005120static void intel_dp_pps_init(struct drm_device *dev,
5121 struct intel_dp *intel_dp)
5122{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005123 struct drm_i915_private *dev_priv = to_i915(dev);
5124
5125 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Imre Deak335f7522016-08-10 14:07:32 +03005126 vlv_initial_power_sequencer_setup(intel_dp);
5127 } else {
5128 intel_dp_init_panel_power_sequencer(dev, intel_dp);
5129 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
5130 }
5131}
5132
Vandana Kannanb33a2812015-02-13 15:33:03 +05305133/**
5134 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005135 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005136 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305137 * @refresh_rate: RR to be programmed
5138 *
5139 * This function gets called when refresh rate (RR) has to be changed from
5140 * one frequency to another. Switches can be between high and low RR
5141 * supported by the panel or to any other RR based on media playback (in
5142 * this case, RR value needs to be passed from user space).
5143 *
5144 * The caller of this function needs to take a lock on dev_priv->drrs.
5145 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005146static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
5147 struct intel_crtc_state *crtc_state,
5148 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305149{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305150 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305151 struct intel_digital_port *dig_port = NULL;
5152 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005153 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305154 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305155
5156 if (refresh_rate <= 0) {
5157 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5158 return;
5159 }
5160
Vandana Kannan96178ee2015-01-10 02:25:56 +05305161 if (intel_dp == NULL) {
5162 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305163 return;
5164 }
5165
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005166 /*
Rodrigo Vivie4d59f62014-11-20 02:22:08 -08005167 * FIXME: This needs proper synchronization with psr state for some
5168 * platforms that cannot have PSR and DRRS enabled at the same time.
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005169 */
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305170
Vandana Kannan96178ee2015-01-10 02:25:56 +05305171 dig_port = dp_to_dig_port(intel_dp);
5172 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02005173 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305174
5175 if (!intel_crtc) {
5176 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5177 return;
5178 }
5179
Vandana Kannan96178ee2015-01-10 02:25:56 +05305180 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305181 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5182 return;
5183 }
5184
Vandana Kannan96178ee2015-01-10 02:25:56 +05305185 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5186 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305187 index = DRRS_LOW_RR;
5188
Vandana Kannan96178ee2015-01-10 02:25:56 +05305189 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305190 DRM_DEBUG_KMS(
5191 "DRRS requested for previously set RR...ignoring\n");
5192 return;
5193 }
5194
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005195 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305196 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5197 return;
5198 }
5199
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005200 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305201 switch (index) {
5202 case DRRS_HIGH_RR:
5203 intel_dp_set_m_n(intel_crtc, M1_N1);
5204 break;
5205 case DRRS_LOW_RR:
5206 intel_dp_set_m_n(intel_crtc, M2_N2);
5207 break;
5208 case DRRS_MAX_RR:
5209 default:
5210 DRM_ERROR("Unsupported refreshrate type\n");
5211 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005212 } else if (INTEL_GEN(dev_priv) > 6) {
5213 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005214 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305215
Ville Syrjälä649636e2015-09-22 19:50:01 +03005216 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305217 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005218 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305219 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5220 else
5221 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305222 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005223 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305224 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5225 else
5226 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305227 }
5228 I915_WRITE(reg, val);
5229 }
5230
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305231 dev_priv->drrs.refresh_rate_type = index;
5232
5233 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5234}
5235
Vandana Kannanb33a2812015-02-13 15:33:03 +05305236/**
5237 * intel_edp_drrs_enable - init drrs struct if supported
5238 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005239 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305240 *
5241 * Initializes frontbuffer_bits and drrs.dp
5242 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005243void intel_edp_drrs_enable(struct intel_dp *intel_dp,
5244 struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305245{
5246 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005247 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305248
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005249 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305250 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5251 return;
5252 }
5253
5254 mutex_lock(&dev_priv->drrs.mutex);
5255 if (WARN_ON(dev_priv->drrs.dp)) {
5256 DRM_ERROR("DRRS already enabled\n");
5257 goto unlock;
5258 }
5259
5260 dev_priv->drrs.busy_frontbuffer_bits = 0;
5261
5262 dev_priv->drrs.dp = intel_dp;
5263
5264unlock:
5265 mutex_unlock(&dev_priv->drrs.mutex);
5266}
5267
Vandana Kannanb33a2812015-02-13 15:33:03 +05305268/**
5269 * intel_edp_drrs_disable - Disable DRRS
5270 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005271 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305272 *
5273 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005274void intel_edp_drrs_disable(struct intel_dp *intel_dp,
5275 struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305276{
5277 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005278 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305279
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005280 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305281 return;
5282
5283 mutex_lock(&dev_priv->drrs.mutex);
5284 if (!dev_priv->drrs.dp) {
5285 mutex_unlock(&dev_priv->drrs.mutex);
5286 return;
5287 }
5288
5289 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005290 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5291 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305292
5293 dev_priv->drrs.dp = NULL;
5294 mutex_unlock(&dev_priv->drrs.mutex);
5295
5296 cancel_delayed_work_sync(&dev_priv->drrs.work);
5297}
5298
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305299static void intel_edp_drrs_downclock_work(struct work_struct *work)
5300{
5301 struct drm_i915_private *dev_priv =
5302 container_of(work, typeof(*dev_priv), drrs.work.work);
5303 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305304
Vandana Kannan96178ee2015-01-10 02:25:56 +05305305 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305306
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305307 intel_dp = dev_priv->drrs.dp;
5308
5309 if (!intel_dp)
5310 goto unlock;
5311
5312 /*
5313 * The delayed work can race with an invalidate hence we need to
5314 * recheck.
5315 */
5316
5317 if (dev_priv->drrs.busy_frontbuffer_bits)
5318 goto unlock;
5319
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005320 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5321 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5322
5323 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5324 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5325 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305326
5327unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305328 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305329}
5330
Vandana Kannanb33a2812015-02-13 15:33:03 +05305331/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305332 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005333 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305334 * @frontbuffer_bits: frontbuffer plane tracking bits
5335 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305336 * This function gets called everytime rendering on the given planes start.
5337 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305338 *
5339 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5340 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005341void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5342 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305343{
Vandana Kannana93fad02015-01-10 02:25:59 +05305344 struct drm_crtc *crtc;
5345 enum pipe pipe;
5346
Daniel Vetter9da7d692015-04-09 16:44:15 +02005347 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305348 return;
5349
Daniel Vetter88f933a2015-04-09 16:44:16 +02005350 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305351
Vandana Kannana93fad02015-01-10 02:25:59 +05305352 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005353 if (!dev_priv->drrs.dp) {
5354 mutex_unlock(&dev_priv->drrs.mutex);
5355 return;
5356 }
5357
Vandana Kannana93fad02015-01-10 02:25:59 +05305358 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5359 pipe = to_intel_crtc(crtc)->pipe;
5360
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005361 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5362 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5363
Ramalingam C0ddfd202015-06-15 20:50:05 +05305364 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005365 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005366 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5367 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305368
Vandana Kannana93fad02015-01-10 02:25:59 +05305369 mutex_unlock(&dev_priv->drrs.mutex);
5370}
5371
Vandana Kannanb33a2812015-02-13 15:33:03 +05305372/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305373 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005374 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305375 * @frontbuffer_bits: frontbuffer plane tracking bits
5376 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305377 * This function gets called every time rendering on the given planes has
5378 * completed or flip on a crtc is completed. So DRRS should be upclocked
5379 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5380 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305381 *
5382 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5383 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005384void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5385 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305386{
Vandana Kannana93fad02015-01-10 02:25:59 +05305387 struct drm_crtc *crtc;
5388 enum pipe pipe;
5389
Daniel Vetter9da7d692015-04-09 16:44:15 +02005390 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305391 return;
5392
Daniel Vetter88f933a2015-04-09 16:44:16 +02005393 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305394
Vandana Kannana93fad02015-01-10 02:25:59 +05305395 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005396 if (!dev_priv->drrs.dp) {
5397 mutex_unlock(&dev_priv->drrs.mutex);
5398 return;
5399 }
5400
Vandana Kannana93fad02015-01-10 02:25:59 +05305401 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5402 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005403
5404 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305405 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5406
Ramalingam C0ddfd202015-06-15 20:50:05 +05305407 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005408 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005409 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5410 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305411
5412 /*
5413 * flush also means no more activity hence schedule downclock, if all
5414 * other fbs are quiescent too
5415 */
5416 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305417 schedule_delayed_work(&dev_priv->drrs.work,
5418 msecs_to_jiffies(1000));
5419 mutex_unlock(&dev_priv->drrs.mutex);
5420}
5421
Vandana Kannanb33a2812015-02-13 15:33:03 +05305422/**
5423 * DOC: Display Refresh Rate Switching (DRRS)
5424 *
5425 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5426 * which enables swtching between low and high refresh rates,
5427 * dynamically, based on the usage scenario. This feature is applicable
5428 * for internal panels.
5429 *
5430 * Indication that the panel supports DRRS is given by the panel EDID, which
5431 * would list multiple refresh rates for one resolution.
5432 *
5433 * DRRS is of 2 types - static and seamless.
5434 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5435 * (may appear as a blink on screen) and is used in dock-undock scenario.
5436 * Seamless DRRS involves changing RR without any visual effect to the user
5437 * and can be used during normal system usage. This is done by programming
5438 * certain registers.
5439 *
5440 * Support for static/seamless DRRS may be indicated in the VBT based on
5441 * inputs from the panel spec.
5442 *
5443 * DRRS saves power by switching to low RR based on usage scenarios.
5444 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005445 * The implementation is based on frontbuffer tracking implementation. When
5446 * there is a disturbance on the screen triggered by user activity or a periodic
5447 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5448 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5449 * made.
5450 *
5451 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5452 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305453 *
5454 * DRRS can be further extended to support other internal panels and also
5455 * the scenario of video playback wherein RR is set based on the rate
5456 * requested by userspace.
5457 */
5458
5459/**
5460 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5461 * @intel_connector: eDP connector
5462 * @fixed_mode: preferred mode of panel
5463 *
5464 * This function is called only once at driver load to initialize basic
5465 * DRRS stuff.
5466 *
5467 * Returns:
5468 * Downclock mode if panel supports it, else return NULL.
5469 * DRRS support is determined by the presence of downclock mode (apart
5470 * from VBT setting).
5471 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305472static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305473intel_dp_drrs_init(struct intel_connector *intel_connector,
5474 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305475{
5476 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305477 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005478 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305479 struct drm_display_mode *downclock_mode = NULL;
5480
Daniel Vetter9da7d692015-04-09 16:44:15 +02005481 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5482 mutex_init(&dev_priv->drrs.mutex);
5483
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305484 if (INTEL_INFO(dev)->gen <= 6) {
5485 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5486 return NULL;
5487 }
5488
5489 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005490 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305491 return NULL;
5492 }
5493
5494 downclock_mode = intel_find_panel_downclock
5495 (dev, fixed_mode, connector);
5496
5497 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305498 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305499 return NULL;
5500 }
5501
Vandana Kannan96178ee2015-01-10 02:25:56 +05305502 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305503
Vandana Kannan96178ee2015-01-10 02:25:56 +05305504 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005505 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305506 return downclock_mode;
5507}
5508
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005509static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005510 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005511{
5512 struct drm_connector *connector = &intel_connector->base;
5513 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005514 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5515 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005516 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005517 struct drm_display_mode *fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305518 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005519 bool has_dpcd;
5520 struct drm_display_mode *scan;
5521 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005522 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005523
5524 if (!is_edp(intel_dp))
5525 return true;
5526
Imre Deak97a824e12016-06-21 11:51:47 +03005527 /*
5528 * On IBX/CPT we may get here with LVDS already registered. Since the
5529 * driver uses the only internal power sequencer available for both
5530 * eDP and LVDS bail out early in this case to prevent interfering
5531 * with an already powered-on LVDS power sequencer.
5532 */
5533 if (intel_get_lvds_encoder(dev)) {
5534 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5535 DRM_INFO("LVDS was detected, not registering eDP\n");
5536
5537 return false;
5538 }
5539
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005540 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005541
5542 intel_dp_init_panel_power_timestamps(intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +03005543 intel_dp_pps_init(dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005544 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005545
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005546 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005547
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005548 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005549 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005550
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005551 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005552 /* if this fails, presume the device is a ghost */
5553 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005554 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005555 }
5556
Daniel Vetter060c8772014-03-21 23:22:35 +01005557 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005558 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005559 if (edid) {
5560 if (drm_add_edid_modes(connector, edid)) {
5561 drm_mode_connector_update_edid_property(connector,
5562 edid);
5563 drm_edid_to_eld(connector, edid);
5564 } else {
5565 kfree(edid);
5566 edid = ERR_PTR(-EINVAL);
5567 }
5568 } else {
5569 edid = ERR_PTR(-ENOENT);
5570 }
5571 intel_connector->edid = edid;
5572
5573 /* prefer fixed mode from EDID if available */
5574 list_for_each_entry(scan, &connector->probed_modes, head) {
5575 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5576 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305577 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305578 intel_connector, fixed_mode);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005579 break;
5580 }
5581 }
5582
5583 /* fallback to VBT if available for eDP */
5584 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5585 fixed_mode = drm_mode_duplicate(dev,
5586 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005587 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005588 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005589 connector->display_info.width_mm = fixed_mode->width_mm;
5590 connector->display_info.height_mm = fixed_mode->height_mm;
5591 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005592 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005593 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005594
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005595 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005596 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5597 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005598
5599 /*
5600 * Figure out the current pipe for the initial backlight setup.
5601 * If the current pipe isn't valid, try the PPS pipe, and if that
5602 * fails just assume pipe A.
5603 */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005604 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä6517d272014-11-07 11:16:02 +02005605 pipe = DP_PORT_TO_PIPE_CHV(intel_dp->DP);
5606 else
5607 pipe = PORT_TO_PIPE(intel_dp->DP);
5608
5609 if (pipe != PIPE_A && pipe != PIPE_B)
5610 pipe = intel_dp->pps_pipe;
5611
5612 if (pipe != PIPE_A && pipe != PIPE_B)
5613 pipe = PIPE_A;
5614
5615 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5616 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005617 }
5618
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305619 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005620 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005621 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005622
5623 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005624
5625out_vdd_off:
5626 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5627 /*
5628 * vdd might still be enabled do to the delayed vdd off.
5629 * Make sure vdd is actually turned off here.
5630 */
5631 pps_lock(intel_dp);
5632 edp_panel_vdd_off_sync(intel_dp);
5633 pps_unlock(intel_dp);
5634
5635 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005636}
5637
Paulo Zanoni16c25532013-06-12 17:27:25 -03005638bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005639intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5640 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005641{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005642 struct drm_connector *connector = &intel_connector->base;
5643 struct intel_dp *intel_dp = &intel_dig_port->dp;
5644 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5645 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005646 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02005647 enum port port = intel_dig_port->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01005648 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005649
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005650 if (WARN(intel_dig_port->max_lanes < 1,
5651 "Not enough lanes (%d) for DP on port %c\n",
5652 intel_dig_port->max_lanes, port_name(port)))
5653 return false;
5654
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005655 intel_dp->pps_pipe = INVALID_PIPE;
5656
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005657 /* intel_dp vfuncs */
Damien Lespiaub6b5e382014-01-20 16:00:59 +00005658 if (INTEL_INFO(dev)->gen >= 9)
5659 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005660 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005661 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005662 else if (HAS_PCH_SPLIT(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005663 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
5664 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005665 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005666
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00005667 if (INTEL_INFO(dev)->gen >= 9)
5668 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
5669 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005670 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00005671
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005672 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03005673 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
5674
Daniel Vetter07679352012-09-06 22:15:42 +02005675 /* Preserve the current hw state. */
5676 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03005677 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00005678
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005679 if (intel_dp_is_edp(dev, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05305680 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005681 else
5682 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04005683
Imre Deakf7d24902013-05-08 13:14:05 +03005684 /*
5685 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
5686 * for DP the encoder type can be set by the caller to
5687 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
5688 */
5689 if (type == DRM_MODE_CONNECTOR_eDP)
5690 intel_encoder->type = INTEL_OUTPUT_EDP;
5691
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005692 /* eDP only on port B and/or C on vlv/chv */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005693 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08005694 is_edp(intel_dp) && port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005695 return false;
5696
Imre Deake7281ea2013-05-08 13:14:08 +03005697 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
5698 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
5699 port_name(port));
5700
Adam Jacksonb3295302010-07-16 14:46:28 -04005701 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005702 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
5703
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005704 connector->interlace_allowed = true;
5705 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08005706
Mika Kaholab6339582016-09-09 14:10:52 +03005707 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01005708
Daniel Vetter66a92782012-07-12 20:08:18 +02005709 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01005710 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08005711
Chris Wilsondf0e9242010-09-09 16:20:55 +01005712 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005713
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005714 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02005715 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
5716 else
5717 intel_connector->get_hw_state = intel_connector_get_hw_state;
5718
Jani Nikula0b998362014-03-14 16:51:17 +02005719 /* Set up the hotplug pin. */
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005720 switch (port) {
5721 case PORT_A:
Egbert Eich1d843f92013-02-25 12:06:49 -05005722 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005723 break;
5724 case PORT_B:
Egbert Eich1d843f92013-02-25 12:06:49 -05005725 intel_encoder->hpd_pin = HPD_PORT_B;
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01005726 if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1))
Sonika Jindalcf1d5882015-08-10 10:35:36 +05305727 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005728 break;
5729 case PORT_C:
Egbert Eich1d843f92013-02-25 12:06:49 -05005730 intel_encoder->hpd_pin = HPD_PORT_C;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005731 break;
5732 case PORT_D:
Egbert Eich1d843f92013-02-25 12:06:49 -05005733 intel_encoder->hpd_pin = HPD_PORT_D;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005734 break;
Xiong Zhang26951ca2015-08-17 15:55:50 +08005735 case PORT_E:
5736 intel_encoder->hpd_pin = HPD_PORT_E;
5737 break;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005738 default:
Damien Lespiauad1c0b12013-03-07 15:30:28 +00005739 BUG();
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08005740 }
5741
Dave Airlie0e32b392014-05-02 14:02:48 +10005742 /* init MST on ports that can support it */
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00005743 if (HAS_DP_MST(dev_priv) && !is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03005744 (port == PORT_B || port == PORT_C || port == PORT_D))
5745 intel_dp_mst_encoder_init(intel_dig_port,
5746 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10005747
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005748 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005749 intel_dp_aux_fini(intel_dp);
5750 intel_dp_mst_encoder_cleanup(intel_dig_port);
5751 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03005752 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08005753
Chris Wilsonf6849602010-09-19 09:29:33 +01005754 intel_dp_add_properties(intel_dp, connector);
5755
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005756 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
5757 * 0xd. Failure to do so will result in spurious interrupts being
5758 * generated on the port when a cable is not attached.
5759 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01005760 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005761 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
5762 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
5763 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03005764
5765 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005766
5767fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005768 drm_connector_cleanup(connector);
5769
5770 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005771}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005772
Chris Wilson457c52d2016-06-01 08:27:50 +01005773bool intel_dp_init(struct drm_device *dev,
5774 i915_reg_t output_reg,
5775 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005776{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005777 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005778 struct intel_digital_port *intel_dig_port;
5779 struct intel_encoder *intel_encoder;
5780 struct drm_encoder *encoder;
5781 struct intel_connector *intel_connector;
5782
Daniel Vetterb14c5672013-09-19 12:18:32 +02005783 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005784 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01005785 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005786
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03005787 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305788 if (!intel_connector)
5789 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005790
5791 intel_encoder = &intel_dig_port->base;
5792 encoder = &intel_encoder->base;
5793
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305794 if (drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
Ville Syrjälä580d8ed2016-05-27 20:59:24 +03005795 DRM_MODE_ENCODER_TMDS, "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305796 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005797
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01005798 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005799 intel_encoder->disable = intel_disable_dp;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005800 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07005801 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03005802 intel_encoder->suspend = intel_dp_encoder_suspend;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005803 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03005804 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03005805 intel_encoder->pre_enable = chv_pre_enable_dp;
5806 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03005807 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03005808 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01005809 } else if (IS_VALLEYVIEW(dev_priv)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03005810 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005811 intel_encoder->pre_enable = vlv_pre_enable_dp;
5812 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03005813 intel_encoder->post_disable = vlv_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005814 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03005815 intel_encoder->pre_enable = g4x_pre_enable_dp;
5816 intel_encoder->enable = g4x_enable_dp;
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03005817 if (INTEL_INFO(dev)->gen >= 5)
5818 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005819 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005820
Paulo Zanoni174edf12012-10-26 19:05:50 -02005821 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005822 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005823 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005824
Ville Syrjäläcca05022016-06-22 21:57:06 +03005825 intel_encoder->type = INTEL_OUTPUT_DP;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005826 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03005827 if (port == PORT_D)
5828 intel_encoder->crtc_mask = 1 << 2;
5829 else
5830 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
5831 } else {
5832 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
5833 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02005834 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07005835 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005836
Dave Airlie13cf5502014-06-18 11:29:35 +10005837 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03005838 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10005839
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305840 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
5841 goto err_init_connector;
5842
Chris Wilson457c52d2016-06-01 08:27:50 +01005843 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305844
5845err_init_connector:
5846 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305847err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305848 kfree(intel_connector);
5849err_connector_alloc:
5850 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01005851 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005852}
Dave Airlie0e32b392014-05-02 14:02:48 +10005853
5854void intel_dp_mst_suspend(struct drm_device *dev)
5855{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005856 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10005857 int i;
5858
5859 /* disable MST */
5860 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03005861 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005862
5863 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10005864 continue;
5865
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005866 if (intel_dig_port->dp.is_mst)
5867 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10005868 }
5869}
5870
5871void intel_dp_mst_resume(struct drm_device *dev)
5872{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005873 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10005874 int i;
5875
5876 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03005877 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005878 int ret;
5879
5880 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10005881 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10005882
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005883 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
5884 if (ret)
5885 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10005886 }
5887}