blob: 1063afe5174d63cc43bd13e90d4bb6ee2124a616 [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);
398 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100399 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300400 enum pipe pipe = intel_dp->pps_pipe;
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300401 bool pll_enabled, release_cl_override = false;
402 enum dpio_phy phy = DPIO_PHY(pipe);
403 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300404 uint32_t DP;
405
406 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
407 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
408 pipe_name(pipe), port_name(intel_dig_port->port)))
409 return;
410
411 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
412 pipe_name(pipe), port_name(intel_dig_port->port));
413
414 /* Preserve the BIOS-computed detected bit. This is
415 * supposed to be read-only.
416 */
417 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
418 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
419 DP |= DP_PORT_WIDTH(1);
420 DP |= DP_LINK_TRAIN_PAT_1;
421
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100422 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300423 DP |= DP_PIPE_SELECT_CHV(pipe);
424 else if (pipe == PIPE_B)
425 DP |= DP_PIPEB_SELECT;
426
Ville Syrjäläd288f652014-10-28 13:20:22 +0200427 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
428
429 /*
430 * The DPLL for the pipe must be enabled for this to work.
431 * So enable temporarily it if it's not already enabled.
432 */
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300433 if (!pll_enabled) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100434 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300435 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
436
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100437 if (vlv_force_pll_on(dev, pipe, IS_CHERRYVIEW(dev_priv) ?
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +0000438 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
439 DRM_ERROR("Failed to force on pll for pipe %c!\n",
440 pipe_name(pipe));
441 return;
442 }
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300443 }
Ville Syrjäläd288f652014-10-28 13:20:22 +0200444
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300445 /*
446 * Similar magic as in intel_dp_enable_port().
447 * We _must_ do this port enable + disable trick
448 * to make this power seqeuencer lock onto the port.
449 * Otherwise even VDD force bit won't work.
450 */
451 I915_WRITE(intel_dp->output_reg, DP);
452 POSTING_READ(intel_dp->output_reg);
453
454 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
455 POSTING_READ(intel_dp->output_reg);
456
457 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
458 POSTING_READ(intel_dp->output_reg);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200459
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300460 if (!pll_enabled) {
Ville Syrjäläd288f652014-10-28 13:20:22 +0200461 vlv_force_pll_off(dev, pipe);
Ville Syrjälä0047eed2015-07-10 10:56:24 +0300462
463 if (release_cl_override)
464 chv_phy_powergate_ch(dev_priv, phy, ch, false);
465 }
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300466}
467
Jani Nikulabf13e812013-09-06 07:40:05 +0300468static enum pipe
469vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
470{
471 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300472 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100473 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300474 struct intel_encoder *encoder;
475 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300476 enum pipe pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300477
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300478 lockdep_assert_held(&dev_priv->pps_mutex);
479
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300480 /* We should never land here with regular DP ports */
481 WARN_ON(!is_edp(intel_dp));
482
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300483 if (intel_dp->pps_pipe != INVALID_PIPE)
484 return intel_dp->pps_pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300485
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300486 /*
487 * We don't have power sequencer currently.
488 * Pick one that's not used by other ports.
489 */
Jani Nikula19c80542015-12-16 12:48:16 +0200490 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300491 struct intel_dp *tmp;
492
493 if (encoder->type != INTEL_OUTPUT_EDP)
494 continue;
495
496 tmp = enc_to_intel_dp(&encoder->base);
497
498 if (tmp->pps_pipe != INVALID_PIPE)
499 pipes &= ~(1 << tmp->pps_pipe);
500 }
501
502 /*
503 * Didn't find one. This should not happen since there
504 * are two power sequencers and up to two eDP ports.
505 */
506 if (WARN_ON(pipes == 0))
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300507 pipe = PIPE_A;
508 else
509 pipe = ffs(pipes) - 1;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300510
Ville Syrjäläa8c33442014-10-16 21:29:59 +0300511 vlv_steal_power_sequencer(dev, pipe);
512 intel_dp->pps_pipe = pipe;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300513
514 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
515 pipe_name(intel_dp->pps_pipe),
516 port_name(intel_dig_port->port));
517
518 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300519 intel_dp_init_panel_power_sequencer(dev, intel_dp);
520 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300521
Ville Syrjälä961a0db2014-10-16 21:29:42 +0300522 /*
523 * Even vdd force doesn't work until we've made
524 * the power sequencer lock in on the port.
525 */
526 vlv_power_sequencer_kick(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300527
528 return intel_dp->pps_pipe;
529}
530
Imre Deak78597992016-06-16 16:37:20 +0300531static int
532bxt_power_sequencer_idx(struct intel_dp *intel_dp)
533{
534 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
535 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100536 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak78597992016-06-16 16:37:20 +0300537
538 lockdep_assert_held(&dev_priv->pps_mutex);
539
540 /* We should never land here with regular DP ports */
541 WARN_ON(!is_edp(intel_dp));
542
543 /*
544 * TODO: BXT has 2 PPS instances. The correct port->PPS instance
545 * mapping needs to be retrieved from VBT, for now just hard-code to
546 * use instance #0 always.
547 */
548 if (!intel_dp->pps_reset)
549 return 0;
550
551 intel_dp->pps_reset = false;
552
553 /*
554 * Only the HW needs to be reprogrammed, the SW state is fixed and
555 * has been setup during connector init.
556 */
557 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
558
559 return 0;
560}
561
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300562typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
563 enum pipe pipe);
564
565static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
566 enum pipe pipe)
567{
Imre Deak44cb7342016-08-10 14:07:29 +0300568 return I915_READ(PP_STATUS(pipe)) & PP_ON;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300569}
570
571static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
572 enum pipe pipe)
573{
Imre Deak44cb7342016-08-10 14:07:29 +0300574 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300575}
576
577static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
578 enum pipe pipe)
579{
580 return true;
581}
582
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300583static enum pipe
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300584vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
585 enum port port,
586 vlv_pipe_check pipe_check)
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300587{
Jani Nikulabf13e812013-09-06 07:40:05 +0300588 enum pipe pipe;
589
Jani Nikulabf13e812013-09-06 07:40:05 +0300590 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
Imre Deak44cb7342016-08-10 14:07:29 +0300591 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
Jani Nikulabf13e812013-09-06 07:40:05 +0300592 PANEL_PORT_SELECT_MASK;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300593
594 if (port_sel != PANEL_PORT_SELECT_VLV(port))
595 continue;
596
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300597 if (!pipe_check(dev_priv, pipe))
598 continue;
599
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300600 return pipe;
Jani Nikulabf13e812013-09-06 07:40:05 +0300601 }
602
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300603 return INVALID_PIPE;
604}
605
606static void
607vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
608{
609 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
610 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100611 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300612 enum port port = intel_dig_port->port;
613
614 lockdep_assert_held(&dev_priv->pps_mutex);
615
616 /* try to find a pipe with this port selected */
Ville Syrjälä6491ab22014-08-18 22:16:06 +0300617 /* first pick one where the panel is on */
618 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
619 vlv_pipe_has_pp_on);
620 /* didn't find one? pick one where vdd is on */
621 if (intel_dp->pps_pipe == INVALID_PIPE)
622 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
623 vlv_pipe_has_vdd_on);
624 /* didn't find one? pick one with just the correct port */
625 if (intel_dp->pps_pipe == INVALID_PIPE)
626 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
627 vlv_pipe_any);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +0300628
629 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
630 if (intel_dp->pps_pipe == INVALID_PIPE) {
631 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
632 port_name(port));
633 return;
634 }
635
636 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
637 port_name(port), pipe_name(intel_dp->pps_pipe));
638
Ville Syrjälä36b5f422014-10-16 21:27:30 +0300639 intel_dp_init_panel_power_sequencer(dev, intel_dp);
640 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Jani Nikulabf13e812013-09-06 07:40:05 +0300641}
642
Imre Deak78597992016-06-16 16:37:20 +0300643void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä773538e82014-09-04 14:54:56 +0300644{
Chris Wilson91c8a322016-07-05 10:40:23 +0100645 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300646 struct intel_encoder *encoder;
647
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100648 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100649 !IS_BROXTON(dev_priv)))
Ville Syrjälä773538e82014-09-04 14:54:56 +0300650 return;
651
652 /*
653 * We can't grab pps_mutex here due to deadlock with power_domain
654 * mutex when power_domain functions are called while holding pps_mutex.
655 * That also means that in order to use pps_pipe the code needs to
656 * hold both a power domain reference and pps_mutex, and the power domain
657 * reference get/put must be done while _not_ holding pps_mutex.
658 * pps_{lock,unlock}() do these steps in the correct order, so one
659 * should use them always.
660 */
661
Jani Nikula19c80542015-12-16 12:48:16 +0200662 for_each_intel_encoder(dev, encoder) {
Ville Syrjälä773538e82014-09-04 14:54:56 +0300663 struct intel_dp *intel_dp;
664
665 if (encoder->type != INTEL_OUTPUT_EDP)
666 continue;
667
668 intel_dp = enc_to_intel_dp(&encoder->base);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100669 if (IS_BROXTON(dev_priv))
Imre Deak78597992016-06-16 16:37:20 +0300670 intel_dp->pps_reset = true;
671 else
672 intel_dp->pps_pipe = INVALID_PIPE;
Ville Syrjälä773538e82014-09-04 14:54:56 +0300673 }
Jani Nikulabf13e812013-09-06 07:40:05 +0300674}
675
Imre Deak8e8232d2016-06-16 16:37:21 +0300676struct pps_registers {
677 i915_reg_t pp_ctrl;
678 i915_reg_t pp_stat;
679 i915_reg_t pp_on;
680 i915_reg_t pp_off;
681 i915_reg_t pp_div;
682};
683
684static void intel_pps_get_registers(struct drm_i915_private *dev_priv,
685 struct intel_dp *intel_dp,
686 struct pps_registers *regs)
687{
Imre Deak44cb7342016-08-10 14:07:29 +0300688 int pps_idx = 0;
689
Imre Deak8e8232d2016-06-16 16:37:21 +0300690 memset(regs, 0, sizeof(*regs));
691
Imre Deak44cb7342016-08-10 14:07:29 +0300692 if (IS_BROXTON(dev_priv))
693 pps_idx = bxt_power_sequencer_idx(intel_dp);
694 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
695 pps_idx = vlv_power_sequencer_pipe(intel_dp);
Imre Deak8e8232d2016-06-16 16:37:21 +0300696
Imre Deak44cb7342016-08-10 14:07:29 +0300697 regs->pp_ctrl = PP_CONTROL(pps_idx);
698 regs->pp_stat = PP_STATUS(pps_idx);
699 regs->pp_on = PP_ON_DELAYS(pps_idx);
700 regs->pp_off = PP_OFF_DELAYS(pps_idx);
701 if (!IS_BROXTON(dev_priv))
702 regs->pp_div = PP_DIVISOR(pps_idx);
Imre Deak8e8232d2016-06-16 16:37:21 +0300703}
704
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200705static i915_reg_t
706_pp_ctrl_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300707{
Imre Deak8e8232d2016-06-16 16:37:21 +0300708 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300709
Imre Deak8e8232d2016-06-16 16:37:21 +0300710 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
711 &regs);
712
713 return regs.pp_ctrl;
Jani Nikulabf13e812013-09-06 07:40:05 +0300714}
715
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200716static i915_reg_t
717_pp_stat_reg(struct intel_dp *intel_dp)
Jani Nikulabf13e812013-09-06 07:40:05 +0300718{
Imre Deak8e8232d2016-06-16 16:37:21 +0300719 struct pps_registers regs;
Jani Nikulabf13e812013-09-06 07:40:05 +0300720
Imre Deak8e8232d2016-06-16 16:37:21 +0300721 intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
722 &regs);
723
724 return regs.pp_stat;
Jani Nikulabf13e812013-09-06 07:40:05 +0300725}
726
Clint Taylor01527b32014-07-07 13:01:46 -0700727/* Reboot notifier handler to shutdown panel power to guarantee T12 timing
728 This function only applicable when panel PM state is not to be tracked */
729static int edp_notify_handler(struct notifier_block *this, unsigned long code,
730 void *unused)
731{
732 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
733 edp_notifier);
734 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100735 struct drm_i915_private *dev_priv = to_i915(dev);
Clint Taylor01527b32014-07-07 13:01:46 -0700736
737 if (!is_edp(intel_dp) || code != SYS_RESTART)
738 return 0;
739
Ville Syrjälä773538e82014-09-04 14:54:56 +0300740 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300741
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100742 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300743 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200744 i915_reg_t pp_ctrl_reg, pp_div_reg;
Ville Syrjälä649636e2015-09-22 19:50:01 +0300745 u32 pp_div;
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300746
Imre Deak44cb7342016-08-10 14:07:29 +0300747 pp_ctrl_reg = PP_CONTROL(pipe);
748 pp_div_reg = PP_DIVISOR(pipe);
Clint Taylor01527b32014-07-07 13:01:46 -0700749 pp_div = I915_READ(pp_div_reg);
750 pp_div &= PP_REFERENCE_DIVIDER_MASK;
751
752 /* 0x1F write to PP_DIV_REG sets max cycle delay */
753 I915_WRITE(pp_div_reg, pp_div | 0x1F);
754 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
755 msleep(intel_dp->panel_power_cycle_delay);
756 }
757
Ville Syrjälä773538e82014-09-04 14:54:56 +0300758 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300759
Clint Taylor01527b32014-07-07 13:01:46 -0700760 return 0;
761}
762
Daniel Vetter4be73782014-01-17 14:39:48 +0100763static bool edp_have_panel_power(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700764{
Paulo Zanoni30add222012-10-26 19:05:45 -0200765 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100766 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700767
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300768 lockdep_assert_held(&dev_priv->pps_mutex);
769
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100770 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300771 intel_dp->pps_pipe == INVALID_PIPE)
772 return false;
773
Jani Nikulabf13e812013-09-06 07:40:05 +0300774 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
Keith Packardebf33b12011-09-29 15:53:27 -0700775}
776
Daniel Vetter4be73782014-01-17 14:39:48 +0100777static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
Keith Packardebf33b12011-09-29 15:53:27 -0700778{
Paulo Zanoni30add222012-10-26 19:05:45 -0200779 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100780 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700781
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300782 lockdep_assert_held(&dev_priv->pps_mutex);
783
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100784 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä9a423562014-10-16 21:29:48 +0300785 intel_dp->pps_pipe == INVALID_PIPE)
786 return false;
787
Ville Syrjälä773538e82014-09-04 14:54:56 +0300788 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -0700789}
790
Keith Packard9b984da2011-09-19 13:54:47 -0700791static void
792intel_dp_check_edp(struct intel_dp *intel_dp)
793{
Paulo Zanoni30add222012-10-26 19:05:45 -0200794 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +0100795 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packardebf33b12011-09-29 15:53:27 -0700796
Keith Packard9b984da2011-09-19 13:54:47 -0700797 if (!is_edp(intel_dp))
798 return;
Jesse Barnes453c5422013-03-28 09:55:41 -0700799
Daniel Vetter4be73782014-01-17 14:39:48 +0100800 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
Keith Packard9b984da2011-09-19 13:54:47 -0700801 WARN(1, "eDP powered off while attempting aux channel communication.\n");
802 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
Jani Nikulabf13e812013-09-06 07:40:05 +0300803 I915_READ(_pp_stat_reg(intel_dp)),
804 I915_READ(_pp_ctrl_reg(intel_dp)));
Keith Packard9b984da2011-09-19 13:54:47 -0700805 }
806}
807
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100808static uint32_t
809intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
810{
811 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
812 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100813 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200814 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100815 uint32_t status;
816 bool done;
817
Daniel Vetteref04f002012-12-01 21:03:59 +0100818#define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100819 if (has_aux_irq)
Paulo Zanonib18ac462013-02-18 19:00:24 -0300820 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
Imre Deak35987062013-05-21 20:03:20 +0300821 msecs_to_jiffies_timeout(10));
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100822 else
Imre Deak713a6b662016-06-28 13:37:33 +0300823 done = wait_for(C, 10) == 0;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100824 if (!done)
825 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
826 has_aux_irq);
827#undef C
828
829 return status;
830}
831
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200832static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000833{
834 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200835 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000836
Ville Syrjäläa457f542016-03-02 17:22:17 +0200837 if (index)
838 return 0;
839
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000840 /*
841 * The clock divider is based off the hrawclk, and would like to run at
Ville Syrjäläa457f542016-03-02 17:22:17 +0200842 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000843 */
Ville Syrjäläa457f542016-03-02 17:22:17 +0200844 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000845}
846
847static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
848{
849 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200850 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000851
852 if (index)
853 return 0;
854
Ville Syrjäläa457f542016-03-02 17:22:17 +0200855 /*
856 * The clock divider is based off the cdclk or PCH rawclk, and would
857 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
858 * divide by 2000 and use that
859 */
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200860 if (intel_dig_port->port == PORT_A)
Ville Syrjäläfce18c42015-11-30 16:23:46 +0200861 return DIV_ROUND_CLOSEST(dev_priv->cdclk_freq, 2000);
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +0200862 else
863 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
Damien Lespiauec5b01d2014-01-21 13:35:39 +0000864}
865
866static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300867{
868 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjäläa457f542016-03-02 17:22:17 +0200869 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300870
Ville Syrjäläa457f542016-03-02 17:22:17 +0200871 if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300872 /* Workaround for non-ULT HSW */
Chris Wilsonbc866252013-07-21 16:00:03 +0100873 switch (index) {
874 case 0: return 63;
875 case 1: return 72;
876 default: return 0;
877 }
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300878 }
Ville Syrjäläa457f542016-03-02 17:22:17 +0200879
880 return ilk_get_aux_clock_divider(intel_dp, index);
Rodrigo Vivib84a1cf2013-07-11 18:44:57 -0300881}
882
Damien Lespiaub6b5e382014-01-20 16:00:59 +0000883static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
884{
885 /*
886 * SKL doesn't need us to program the AUX clock divider (Hardware will
887 * derive the clock from CDCLK automatically). We still implement the
888 * get_aux_clock_divider vfunc to plug-in into the existing code.
889 */
890 return index ? 0 : 1;
891}
892
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +0200893static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
894 bool has_aux_irq,
895 int send_bytes,
896 uint32_t aux_clock_divider)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000897{
898 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100899 struct drm_i915_private *dev_priv =
900 to_i915(intel_dig_port->base.base.dev);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000901 uint32_t precharge, timeout;
902
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100903 if (IS_GEN6(dev_priv))
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000904 precharge = 3;
905 else
906 precharge = 5;
907
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100908 if (IS_BROADWELL(dev_priv) && intel_dig_port->port == PORT_A)
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000909 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
910 else
911 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
912
913 return DP_AUX_CH_CTL_SEND_BUSY |
Damien Lespiau788d4432014-01-20 15:52:31 +0000914 DP_AUX_CH_CTL_DONE |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000915 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000916 DP_AUX_CH_CTL_TIME_OUT_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000917 timeout |
Damien Lespiau788d4432014-01-20 15:52:31 +0000918 DP_AUX_CH_CTL_RECEIVE_ERROR |
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000919 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
920 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
Damien Lespiau788d4432014-01-20 15:52:31 +0000921 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000922}
923
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000924static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
925 bool has_aux_irq,
926 int send_bytes,
927 uint32_t unused)
928{
929 return DP_AUX_CH_CTL_SEND_BUSY |
930 DP_AUX_CH_CTL_DONE |
931 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
932 DP_AUX_CH_CTL_TIME_OUT_ERROR |
933 DP_AUX_CH_CTL_TIME_OUT_1600us |
934 DP_AUX_CH_CTL_RECEIVE_ERROR |
935 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
Daniel Vetterd4dcbdc2016-05-18 18:47:15 +0200936 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +0000937 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
938}
939
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700940static int
Chris Wilsonea5b2132010-08-04 13:50:23 +0100941intel_dp_aux_ch(struct intel_dp *intel_dp,
Daniel Vetterbd9f74a2014-10-02 09:45:35 +0200942 const uint8_t *send, int send_bytes,
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700943 uint8_t *recv, int recv_size)
944{
Paulo Zanoni174edf12012-10-26 19:05:50 -0200945 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
946 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100947 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200948 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
Chris Wilsonbc866252013-07-21 16:00:03 +0100949 uint32_t aux_clock_divider;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100950 int i, ret, recv_bytes;
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700951 uint32_t status;
Damien Lespiau5ed12a12014-01-20 15:52:30 +0000952 int try, clock = 0;
Daniel Vetter4e6b7882014-02-07 16:33:20 +0100953 bool has_aux_irq = HAS_AUX_IRQ(dev);
Jani Nikula884f19e2014-03-14 16:51:14 +0200954 bool vdd;
955
Ville Syrjälä773538e82014-09-04 14:54:56 +0300956 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +0300957
Ville Syrjälä72c35002014-08-18 22:16:00 +0300958 /*
959 * We will be called with VDD already enabled for dpcd/edid/oui reads.
960 * In such cases we want to leave VDD enabled and it's up to upper layers
961 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
962 * ourselves.
963 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +0300964 vdd = edp_panel_vdd_on(intel_dp);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100965
966 /* dp aux is extremely sensitive to irq latency, hence request the
967 * lowest possible wakeup latency and so prevent the cpu from going into
968 * deep sleep states.
969 */
970 pm_qos_update_request(&dev_priv->pm_qos, 0);
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700971
Keith Packard9b984da2011-09-19 13:54:47 -0700972 intel_dp_check_edp(intel_dp);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +0800973
Jesse Barnes11bee432011-08-01 15:02:20 -0700974 /* Try to wait for any previous AUX channel activity */
975 for (try = 0; try < 3; try++) {
Daniel Vetteref04f002012-12-01 21:03:59 +0100976 status = I915_READ_NOTRACE(ch_ctl);
Jesse Barnes11bee432011-08-01 15:02:20 -0700977 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
978 break;
979 msleep(1);
980 }
981
982 if (try == 3) {
Mika Kuoppala02196c72015-08-06 16:48:58 +0300983 static u32 last_status = -1;
984 const u32 status = I915_READ(ch_ctl);
985
986 if (status != last_status) {
987 WARN(1, "dp_aux_ch not started status 0x%08x\n",
988 status);
989 last_status = status;
990 }
991
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100992 ret = -EBUSY;
993 goto out;
Chris Wilson4f7f7b72010-08-18 18:12:56 +0100994 }
995
Paulo Zanoni46a5ae92013-09-17 11:14:10 -0300996 /* Only 5 data registers! */
997 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
998 ret = -E2BIG;
999 goto out;
1000 }
1001
Damien Lespiauec5b01d2014-01-21 13:35:39 +00001002 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
Damien Lespiau153b1102014-01-21 13:37:15 +00001003 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
1004 has_aux_irq,
1005 send_bytes,
1006 aux_clock_divider);
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001007
Chris Wilsonbc866252013-07-21 16:00:03 +01001008 /* Must try at least 3 times according to DP spec */
1009 for (try = 0; try < 5; try++) {
1010 /* Load the send data into the aux channel data registers */
1011 for (i = 0; i < send_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001012 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001013 intel_dp_pack_aux(send + i,
1014 send_bytes - i));
Akshay Joshi0206e352011-08-16 15:34:10 -04001015
Chris Wilsonbc866252013-07-21 16:00:03 +01001016 /* Send the command and wait for it to complete */
Damien Lespiau5ed12a12014-01-20 15:52:30 +00001017 I915_WRITE(ch_ctl, send_ctl);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001018
Chris Wilsonbc866252013-07-21 16:00:03 +01001019 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
Akshay Joshi0206e352011-08-16 15:34:10 -04001020
Chris Wilsonbc866252013-07-21 16:00:03 +01001021 /* Clear done status and any errors */
1022 I915_WRITE(ch_ctl,
1023 status |
1024 DP_AUX_CH_CTL_DONE |
1025 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1026 DP_AUX_CH_CTL_RECEIVE_ERROR);
Adam Jacksond7e96fe2011-07-26 15:39:46 -04001027
Todd Previte74ebf292015-04-15 08:38:41 -07001028 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
Chris Wilsonbc866252013-07-21 16:00:03 +01001029 continue;
Todd Previte74ebf292015-04-15 08:38:41 -07001030
1031 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
1032 * 400us delay required for errors and timeouts
1033 * Timeout errors from the HW already meet this
1034 * requirement so skip to next iteration
1035 */
1036 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1037 usleep_range(400, 500);
1038 continue;
1039 }
Chris Wilsonbc866252013-07-21 16:00:03 +01001040 if (status & DP_AUX_CH_CTL_DONE)
Jim Bridee058c942015-05-27 10:21:48 -07001041 goto done;
Chris Wilsonbc866252013-07-21 16:00:03 +01001042 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001043 }
1044
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001045 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001046 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001047 ret = -EBUSY;
1048 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001049 }
1050
Jim Bridee058c942015-05-27 10:21:48 -07001051done:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001052 /* Check for timeout or receive error.
1053 * Timeouts occur when the sink is not connected
1054 */
Keith Packarda5b3da52009-06-11 22:30:32 -07001055 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001056 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001057 ret = -EIO;
1058 goto out;
Keith Packarda5b3da52009-06-11 22:30:32 -07001059 }
Keith Packard1ae8c0a2009-06-28 15:42:17 -07001060
1061 /* Timeouts occur when the device isn't connected, so they're
1062 * "normal" -- don't fill the kernel log with these */
Keith Packarda5b3da52009-06-11 22:30:32 -07001063 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
Zhao Yakui28c97732009-10-09 11:39:41 +08001064 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001065 ret = -ETIMEDOUT;
1066 goto out;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001067 }
1068
1069 /* Unload any bytes sent back from the other side */
1070 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
1071 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
Rodrigo Vivi14e01882015-12-10 11:12:27 -08001072
1073 /*
1074 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1075 * We have no idea of what happened so we return -EBUSY so
1076 * drm layer takes care for the necessary retries.
1077 */
1078 if (recv_bytes == 0 || recv_bytes > 20) {
1079 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1080 recv_bytes);
1081 /*
1082 * FIXME: This patch was created on top of a series that
1083 * organize the retries at drm level. There EBUSY should
1084 * also take care for 1ms wait before retrying.
1085 * That aux retries re-org is still needed and after that is
1086 * merged we remove this sleep from here.
1087 */
1088 usleep_range(1000, 1500);
1089 ret = -EBUSY;
1090 goto out;
1091 }
1092
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001093 if (recv_bytes > recv_size)
1094 recv_bytes = recv_size;
Akshay Joshi0206e352011-08-16 15:34:10 -04001095
Chris Wilson4f7f7b72010-08-18 18:12:56 +01001096 for (i = 0; i < recv_bytes; i += 4)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001097 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
Rodrigo Vivia4f12892014-11-14 08:52:27 -08001098 recv + i, recv_bytes - i);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001099
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001100 ret = recv_bytes;
1101out:
1102 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1103
Jani Nikula884f19e2014-03-14 16:51:14 +02001104 if (vdd)
1105 edp_panel_vdd_off(intel_dp, false);
1106
Ville Syrjälä773538e82014-09-04 14:54:56 +03001107 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001108
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001109 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001110}
1111
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001112#define BARE_ADDRESS_SIZE 3
1113#define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
Jani Nikula9d1a1032014-03-14 16:51:15 +02001114static ssize_t
1115intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001116{
Jani Nikula9d1a1032014-03-14 16:51:15 +02001117 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1118 uint8_t txbuf[20], rxbuf[20];
1119 size_t txsize, rxsize;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001120 int ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001121
Ville Syrjäläd2d9cbb2015-03-19 11:44:06 +02001122 txbuf[0] = (msg->request << 4) |
1123 ((msg->address >> 16) & 0xf);
1124 txbuf[1] = (msg->address >> 8) & 0xff;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001125 txbuf[2] = msg->address & 0xff;
1126 txbuf[3] = msg->size - 1;
Paulo Zanoni46a5ae92013-09-17 11:14:10 -03001127
Jani Nikula9d1a1032014-03-14 16:51:15 +02001128 switch (msg->request & ~DP_AUX_I2C_MOT) {
1129 case DP_AUX_NATIVE_WRITE:
1130 case DP_AUX_I2C_WRITE:
Ville Syrjäläc1e741222015-08-27 17:23:27 +03001131 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001132 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001133 rxsize = 2; /* 0 or 1 data bytes */
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001134
Jani Nikula9d1a1032014-03-14 16:51:15 +02001135 if (WARN_ON(txsize > 20))
1136 return -E2BIG;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001137
Ville Syrjälädd788092016-07-28 17:55:04 +03001138 WARN_ON(!msg->buffer != !msg->size);
1139
Imre Deakd81a67c2016-01-29 14:52:26 +02001140 if (msg->buffer)
1141 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001142
Jani Nikula9d1a1032014-03-14 16:51:15 +02001143 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1144 if (ret > 0) {
1145 msg->reply = rxbuf[0] >> 4;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001146
Jani Nikulaa1ddefd2015-03-17 17:18:54 +02001147 if (ret > 1) {
1148 /* Number of bytes written in a short write. */
1149 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1150 } else {
1151 /* Return payload size. */
1152 ret = msg->size;
1153 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001154 }
Jani Nikula9d1a1032014-03-14 16:51:15 +02001155 break;
1156
1157 case DP_AUX_NATIVE_READ:
1158 case DP_AUX_I2C_READ:
Jani Nikulaa6c8aff02014-04-07 12:37:25 +03001159 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
Jani Nikula9d1a1032014-03-14 16:51:15 +02001160 rxsize = msg->size + 1;
1161
1162 if (WARN_ON(rxsize > 20))
1163 return -E2BIG;
1164
1165 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1166 if (ret > 0) {
1167 msg->reply = rxbuf[0] >> 4;
1168 /*
1169 * Assume happy day, and copy the data. The caller is
1170 * expected to check msg->reply before touching it.
1171 *
1172 * Return payload size.
1173 */
1174 ret--;
1175 memcpy(msg->buffer, rxbuf + 1, ret);
1176 }
1177 break;
1178
1179 default:
1180 ret = -EINVAL;
1181 break;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001182 }
Jani Nikulaf51a44b2014-02-11 11:52:05 +02001183
Jani Nikula9d1a1032014-03-14 16:51:15 +02001184 return ret;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001185}
1186
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001187static enum port intel_aux_port(struct drm_i915_private *dev_priv,
1188 enum port port)
1189{
1190 const struct ddi_vbt_port_info *info =
1191 &dev_priv->vbt.ddi_port_info[port];
1192 enum port aux_port;
1193
1194 if (!info->alternate_aux_channel) {
1195 DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
1196 port_name(port), port_name(port));
1197 return port;
1198 }
1199
1200 switch (info->alternate_aux_channel) {
1201 case DP_AUX_A:
1202 aux_port = PORT_A;
1203 break;
1204 case DP_AUX_B:
1205 aux_port = PORT_B;
1206 break;
1207 case DP_AUX_C:
1208 aux_port = PORT_C;
1209 break;
1210 case DP_AUX_D:
1211 aux_port = PORT_D;
1212 break;
1213 default:
1214 MISSING_CASE(info->alternate_aux_channel);
1215 aux_port = PORT_A;
1216 break;
1217 }
1218
1219 DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
1220 port_name(aux_port), port_name(port));
1221
1222 return aux_port;
1223}
1224
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001225static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001226 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001227{
1228 switch (port) {
1229 case PORT_B:
1230 case PORT_C:
1231 case PORT_D:
1232 return DP_AUX_CH_CTL(port);
1233 default:
1234 MISSING_CASE(port);
1235 return DP_AUX_CH_CTL(PORT_B);
1236 }
1237}
1238
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001239static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001240 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001241{
1242 switch (port) {
1243 case PORT_B:
1244 case PORT_C:
1245 case PORT_D:
1246 return DP_AUX_CH_DATA(port, index);
1247 default:
1248 MISSING_CASE(port);
1249 return DP_AUX_CH_DATA(PORT_B, index);
1250 }
1251}
1252
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001253static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001254 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001255{
1256 switch (port) {
1257 case PORT_A:
1258 return DP_AUX_CH_CTL(port);
1259 case PORT_B:
1260 case PORT_C:
1261 case PORT_D:
1262 return PCH_DP_AUX_CH_CTL(port);
1263 default:
1264 MISSING_CASE(port);
1265 return DP_AUX_CH_CTL(PORT_A);
1266 }
1267}
1268
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001269static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001270 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001271{
1272 switch (port) {
1273 case PORT_A:
1274 return DP_AUX_CH_DATA(port, index);
1275 case PORT_B:
1276 case PORT_C:
1277 case PORT_D:
1278 return PCH_DP_AUX_CH_DATA(port, index);
1279 default:
1280 MISSING_CASE(port);
1281 return DP_AUX_CH_DATA(PORT_A, index);
1282 }
1283}
1284
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001285static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001286 enum port port)
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001287{
Ville Syrjäläda00bdc2015-11-11 20:34:13 +02001288 switch (port) {
1289 case PORT_A:
1290 case PORT_B:
1291 case PORT_C:
1292 case PORT_D:
1293 return DP_AUX_CH_CTL(port);
1294 default:
1295 MISSING_CASE(port);
1296 return DP_AUX_CH_CTL(PORT_A);
1297 }
1298}
1299
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001300static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001301 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001302{
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001303 switch (port) {
1304 case PORT_A:
1305 case PORT_B:
1306 case PORT_C:
1307 case PORT_D:
1308 return DP_AUX_CH_DATA(port, index);
1309 default:
1310 MISSING_CASE(port);
1311 return DP_AUX_CH_DATA(PORT_A, index);
1312 }
1313}
1314
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001315static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001316 enum port port)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001317{
1318 if (INTEL_INFO(dev_priv)->gen >= 9)
1319 return skl_aux_ctl_reg(dev_priv, port);
1320 else if (HAS_PCH_SPLIT(dev_priv))
1321 return ilk_aux_ctl_reg(dev_priv, port);
1322 else
1323 return g4x_aux_ctl_reg(dev_priv, port);
1324}
1325
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001326static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
Ville Syrjäläc8a89b02016-10-11 20:52:48 +03001327 enum port port, int index)
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001328{
1329 if (INTEL_INFO(dev_priv)->gen >= 9)
1330 return skl_aux_data_reg(dev_priv, port, index);
1331 else if (HAS_PCH_SPLIT(dev_priv))
1332 return ilk_aux_data_reg(dev_priv, port, index);
1333 else
1334 return g4x_aux_data_reg(dev_priv, port, index);
1335}
1336
1337static void intel_aux_reg_init(struct intel_dp *intel_dp)
1338{
1339 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjälä8f7ce032016-10-11 20:52:45 +03001340 enum port port = intel_aux_port(dev_priv,
1341 dp_to_dig_port(intel_dp)->port);
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001342 int i;
1343
1344 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1345 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1346 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1347}
1348
Jani Nikula9d1a1032014-03-14 16:51:15 +02001349static void
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001350intel_dp_aux_fini(struct intel_dp *intel_dp)
1351{
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001352 kfree(intel_dp->aux.name);
1353}
1354
Chris Wilson7a418e32016-06-24 14:00:14 +01001355static void
Mika Kaholab6339582016-09-09 14:10:52 +03001356intel_dp_aux_init(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001357{
Jani Nikula33ad6622014-03-14 16:51:16 +02001358 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1359 enum port port = intel_dig_port->port;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001360
Ville Syrjälä330e20e2015-11-11 20:34:14 +02001361 intel_aux_reg_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01001362 drm_dp_aux_init(&intel_dp->aux);
David Flynn8316f332010-12-08 16:10:21 +00001363
Chris Wilson7a418e32016-06-24 14:00:14 +01001364 /* Failure to allocate our preferred name is not critical */
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02001365 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
Jani Nikula9d1a1032014-03-14 16:51:15 +02001366 intel_dp->aux.transfer = intel_dp_aux_transfer;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001367}
1368
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001369bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301370{
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001371 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Navare, Manasi D577c5432016-09-27 16:36:53 -07001372 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001373
Navare, Manasi D577c5432016-09-27 16:36:53 -07001374 if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
1375 IS_BROADWELL(dev_priv) || (INTEL_GEN(dev_priv) >= 9))
Thulasimani,Sivakumared63baa2015-08-18 15:30:37 +05301376 return true;
1377 else
1378 return false;
1379}
1380
Daniel Vetter0e503382014-07-04 11:26:04 -03001381static void
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001382intel_dp_set_clock(struct intel_encoder *encoder,
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001383 struct intel_crtc_state *pipe_config)
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001384{
1385 struct drm_device *dev = encoder->base.dev;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001386 struct drm_i915_private *dev_priv = to_i915(dev);
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001387 const struct dp_link_dpll *divisor = NULL;
1388 int i, count = 0;
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001389
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001390 if (IS_G4X(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001391 divisor = gen4_dpll;
1392 count = ARRAY_SIZE(gen4_dpll);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001393 } else if (HAS_PCH_SPLIT(dev_priv)) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001394 divisor = pch_dpll;
1395 count = ARRAY_SIZE(pch_dpll);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001396 } else if (IS_CHERRYVIEW(dev_priv)) {
Chon Ming Leeef9348c2014-04-09 13:28:18 +03001397 divisor = chv_dpll;
1398 count = ARRAY_SIZE(chv_dpll);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001399 } else if (IS_VALLEYVIEW(dev_priv)) {
Chon Ming Lee65ce4bf2013-09-04 01:30:38 +08001400 divisor = vlv_dpll;
1401 count = ARRAY_SIZE(vlv_dpll);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001402 }
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001403
1404 if (divisor && count) {
1405 for (i = 0; i < count; i++) {
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001406 if (pipe_config->port_clock == divisor[i].clock) {
Chon Ming Lee9dd4ffd2013-09-04 01:30:37 +08001407 pipe_config->dpll = divisor[i].dpll;
1408 pipe_config->clock_set = true;
1409 break;
1410 }
1411 }
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001412 }
1413}
1414
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001415static void snprintf_int_array(char *str, size_t len,
1416 const int *array, int nelem)
1417{
1418 int i;
1419
1420 str[0] = '\0';
1421
1422 for (i = 0; i < nelem; i++) {
Jani Nikulab2f505b2015-05-18 16:01:45 +03001423 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001424 if (r >= len)
1425 return;
1426 str += r;
1427 len -= r;
1428 }
1429}
1430
1431static void intel_dp_print_rates(struct intel_dp *intel_dp)
1432{
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001433 const int *source_rates, *sink_rates;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001434 int source_len, sink_len, common_len;
1435 int common_rates[DP_MAX_SUPPORTED_RATES];
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001436 char str[128]; /* FIXME: too big for stack? */
1437
1438 if ((drm_debug & DRM_UT_KMS) == 0)
1439 return;
1440
Ander Conselvan de Oliveirae588fa12015-10-23 13:01:50 +03001441 source_len = intel_dp_source_rates(intel_dp, &source_rates);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001442 snprintf_int_array(str, sizeof(str), source_rates, source_len);
1443 DRM_DEBUG_KMS("source rates: %s\n", str);
1444
1445 sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
1446 snprintf_int_array(str, sizeof(str), sink_rates, sink_len);
1447 DRM_DEBUG_KMS("sink rates: %s\n", str);
1448
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001449 common_len = intel_dp_common_rates(intel_dp, common_rates);
1450 snprintf_int_array(str, sizeof(str), common_rates, common_len);
1451 DRM_DEBUG_KMS("common rates: %s\n", str);
Ville Syrjälä0336400e2015-03-12 17:10:39 +02001452}
1453
Imre Deak489375c2016-10-24 19:33:31 +03001454bool
Imre Deak7b3fc172016-10-25 16:12:39 +03001455__intel_dp_read_desc(struct intel_dp *intel_dp, struct intel_dp_desc *desc)
Mika Kahola0e390a32016-09-09 14:10:53 +03001456{
Imre Deak7b3fc172016-10-25 16:12:39 +03001457 u32 base = drm_dp_is_branch(intel_dp->dpcd) ? DP_BRANCH_OUI :
1458 DP_SINK_OUI;
Mika Kahola0e390a32016-09-09 14:10:53 +03001459
Imre Deak7b3fc172016-10-25 16:12:39 +03001460 return drm_dp_dpcd_read(&intel_dp->aux, base, desc, sizeof(*desc)) ==
1461 sizeof(*desc);
Mika Kahola0e390a32016-09-09 14:10:53 +03001462}
1463
Imre Deak12a47a422016-10-24 19:33:29 +03001464bool intel_dp_read_desc(struct intel_dp *intel_dp)
Mika Kahola1a2724f2016-09-09 14:10:54 +03001465{
Imre Deak7b3fc172016-10-25 16:12:39 +03001466 struct intel_dp_desc *desc = &intel_dp->desc;
1467 bool oui_sup = intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] &
1468 DP_OUI_SUPPORT;
1469 int dev_id_len;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001470
Imre Deak7b3fc172016-10-25 16:12:39 +03001471 if (!__intel_dp_read_desc(intel_dp, desc))
1472 return false;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001473
Imre Deak7b3fc172016-10-25 16:12:39 +03001474 dev_id_len = strnlen(desc->device_id, sizeof(desc->device_id));
1475 DRM_DEBUG_KMS("DP %s: OUI %*phD%s dev-ID %*pE HW-rev %d.%d SW-rev %d.%d\n",
1476 drm_dp_is_branch(intel_dp->dpcd) ? "branch" : "sink",
1477 (int)sizeof(desc->oui), desc->oui, oui_sup ? "" : "(NS)",
1478 dev_id_len, desc->device_id,
1479 desc->hw_rev >> 4, desc->hw_rev & 0xf,
1480 desc->sw_major_rev, desc->sw_minor_rev);
Mika Kahola1a2724f2016-09-09 14:10:54 +03001481
Imre Deak7b3fc172016-10-25 16:12:39 +03001482 return true;
Mika Kahola1a2724f2016-09-09 14:10:54 +03001483}
1484
Ville Syrjäläf4896f12015-03-12 17:10:27 +02001485static int rate_to_index(int find, const int *rates)
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301486{
1487 int i = 0;
1488
1489 for (i = 0; i < DP_MAX_SUPPORTED_RATES; ++i)
1490 if (find == rates[i])
1491 break;
1492
1493 return i;
1494}
1495
Ville Syrjälä50fec212015-03-12 17:10:34 +02001496int
1497intel_dp_max_link_rate(struct intel_dp *intel_dp)
1498{
1499 int rates[DP_MAX_SUPPORTED_RATES] = {};
1500 int len;
1501
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001502 len = intel_dp_common_rates(intel_dp, rates);
Ville Syrjälä50fec212015-03-12 17:10:34 +02001503 if (WARN_ON(len <= 0))
1504 return 162000;
1505
Ville Syrjälä1354f732016-07-28 17:50:45 +03001506 return rates[len - 1];
Ville Syrjälä50fec212015-03-12 17:10:34 +02001507}
1508
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001509int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1510{
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001511 return rate_to_index(rate, intel_dp->sink_rates);
Ville Syrjäläed4e9c12015-03-12 17:10:36 +02001512}
1513
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03001514void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1515 uint8_t *link_bw, uint8_t *rate_select)
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001516{
1517 if (intel_dp->num_sink_rates) {
1518 *link_bw = 0;
1519 *rate_select =
1520 intel_dp_rate_select(intel_dp, port_clock);
1521 } else {
1522 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1523 *rate_select = 0;
1524 }
1525}
1526
Jani Nikulaf580bea2016-09-15 16:28:52 +03001527static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1528 struct intel_crtc_state *pipe_config)
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001529{
1530 int bpp, bpc;
1531
1532 bpp = pipe_config->pipe_bpp;
1533 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1534
1535 if (bpc > 0)
1536 bpp = min(bpp, 3*bpc);
1537
1538 return bpp;
1539}
1540
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001541bool
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001542intel_dp_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001543 struct intel_crtc_state *pipe_config,
1544 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001545{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001546 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001547 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001548 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001549 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001550 enum port port = dp_to_dig_port(intel_dp)->port;
Ander Conselvan de Oliveira84556d52015-03-20 16:18:10 +02001551 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
Jani Nikuladd06f902012-10-19 14:51:50 +03001552 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001553 int lane_count, clock;
Jani Nikula56071a22014-05-06 14:56:52 +03001554 int min_lane_count = 1;
Paulo Zanonieeb63242014-05-06 14:56:50 +03001555 int max_lane_count = intel_dp_max_lane_count(intel_dp);
Todd Previte06ea66b2014-01-20 10:19:39 -07001556 /* Conveniently, the link BW constants become indices with a shift...*/
Jani Nikula56071a22014-05-06 14:56:52 +03001557 int min_clock = 0;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301558 int max_clock;
Daniel Vetter083f9562012-04-20 20:23:49 +02001559 int bpp, mode_rate;
Daniel Vetterff9a6752013-06-01 17:16:21 +02001560 int link_avail, link_clock;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001561 int common_rates[DP_MAX_SUPPORTED_RATES] = {};
1562 int common_len;
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001563 uint8_t link_bw, rate_select;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301564
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001565 common_len = intel_dp_common_rates(intel_dp, common_rates);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301566
1567 /* No common link rates between source and sink */
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001568 WARN_ON(common_len <= 0);
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301569
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001570 max_clock = common_len - 1;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001571
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001572 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001573 pipe_config->has_pch_encoder = true;
1574
Vandana Kannanf769cd22014-08-05 07:51:22 -07001575 pipe_config->has_drrs = false;
Jani Nikula9fcb1702015-05-05 16:32:12 +03001576 pipe_config->has_audio = intel_dp->has_audio && port != PORT_A;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001577
Jani Nikuladd06f902012-10-19 14:51:50 +03001578 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1579 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
1580 adjusted_mode);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001581
1582 if (INTEL_INFO(dev)->gen >= 9) {
1583 int ret;
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02001584 ret = skl_update_scaler_crtc(pipe_config);
Chandra Kondurua1b22782015-04-07 15:28:45 -07001585 if (ret)
1586 return ret;
1587 }
1588
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001589 if (HAS_GMCH_DISPLAY(dev_priv))
Jesse Barnes2dd24552013-04-25 12:55:01 -07001590 intel_gmch_panel_fitting(intel_crtc, pipe_config,
1591 intel_connector->panel.fitting_mode);
1592 else
Jesse Barnesb074cec2013-04-25 12:55:02 -07001593 intel_pch_panel_fitting(intel_crtc, pipe_config,
1594 intel_connector->panel.fitting_mode);
Zhao Yakui0d3a1be2010-07-19 09:43:13 +01001595 }
1596
Daniel Vettercb1793c2012-06-04 18:39:21 +02001597 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Daniel Vetter0af78a22012-05-23 11:30:55 +02001598 return false;
1599
Daniel Vetter083f9562012-04-20 20:23:49 +02001600 DRM_DEBUG_KMS("DP link computation with max lane count %i "
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301601 "max bw %d pixel clock %iKHz\n",
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001602 max_lane_count, common_rates[max_clock],
Damien Lespiau241bfc32013-09-25 16:45:37 +01001603 adjusted_mode->crtc_clock);
Daniel Vetter083f9562012-04-20 20:23:49 +02001604
Daniel Vetter36008362013-03-27 00:44:59 +01001605 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1606 * bpc in between. */
Mika Kaholaf9bb7052016-09-09 14:10:56 +03001607 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
Jani Nikula56071a22014-05-06 14:56:52 +03001608 if (is_edp(intel_dp)) {
Thulasimani,Sivakumar22ce5622015-07-31 11:05:27 +05301609
1610 /* Get bpp from vbt only for panels that dont have bpp in edid */
1611 if (intel_connector->base.display_info.bpc == 0 &&
Jani Nikula6aa23e62016-03-24 17:50:20 +02001612 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
Jani Nikula56071a22014-05-06 14:56:52 +03001613 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02001614 dev_priv->vbt.edp.bpp);
1615 bpp = dev_priv->vbt.edp.bpp;
Jani Nikula56071a22014-05-06 14:56:52 +03001616 }
1617
Jani Nikula344c5bb2014-09-09 11:25:13 +03001618 /*
1619 * Use the maximum clock and number of lanes the eDP panel
1620 * advertizes being capable of. The panels are generally
1621 * designed to support only a single clock and lane
1622 * configuration, and typically these values correspond to the
1623 * native resolution of the panel.
1624 */
1625 min_lane_count = max_lane_count;
1626 min_clock = max_clock;
Imre Deak79842112013-07-18 17:44:13 +03001627 }
Daniel Vetter657445f2013-05-04 10:09:18 +02001628
Daniel Vetter36008362013-03-27 00:44:59 +01001629 for (; bpp >= 6*3; bpp -= 2*3) {
Damien Lespiau241bfc32013-09-25 16:45:37 +01001630 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1631 bpp);
Daniel Vetterc4867932012-04-10 10:42:36 +02001632
Dave Airliec6930992014-07-14 11:04:39 +10001633 for (clock = min_clock; clock <= max_clock; clock++) {
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301634 for (lane_count = min_lane_count;
1635 lane_count <= max_lane_count;
1636 lane_count <<= 1) {
1637
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001638 link_clock = common_rates[clock];
Daniel Vetter36008362013-03-27 00:44:59 +01001639 link_avail = intel_dp_max_data_rate(link_clock,
1640 lane_count);
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001641
Daniel Vetter36008362013-03-27 00:44:59 +01001642 if (mode_rate <= link_avail) {
1643 goto found;
1644 }
1645 }
1646 }
1647 }
1648
1649 return false;
1650
1651found:
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001652 if (intel_dp->color_range_auto) {
1653 /*
1654 * See:
1655 * CEA-861-E - 5.1 Default Encoding Parameters
1656 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1657 */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001658 pipe_config->limited_color_range =
1659 bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1;
1660 } else {
1661 pipe_config->limited_color_range =
1662 intel_dp->limited_color_range;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001663 }
1664
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001665 pipe_config->lane_count = lane_count;
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301666
Daniel Vetter657445f2013-05-04 10:09:18 +02001667 pipe_config->pipe_bpp = bpp;
Ville Syrjälä94ca7192015-03-13 19:40:31 +02001668 pipe_config->port_clock = common_rates[clock];
Daniel Vetterc4867932012-04-10 10:42:36 +02001669
Ville Syrjälä04a60f92015-07-06 15:10:06 +03001670 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1671 &link_bw, &rate_select);
1672
1673 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1674 link_bw, rate_select, pipe_config->lane_count,
Daniel Vetterff9a6752013-06-01 17:16:21 +02001675 pipe_config->port_clock, bpp);
Daniel Vetter36008362013-03-27 00:44:59 +01001676 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1677 mode_rate, link_avail);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001678
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001679 intel_link_compute_m_n(bpp, lane_count,
Damien Lespiau241bfc32013-09-25 16:45:37 +01001680 adjusted_mode->crtc_clock,
1681 pipe_config->port_clock,
Daniel Vetter03afc4a2013-04-02 23:42:31 +02001682 &pipe_config->dp_m_n);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001683
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301684 if (intel_connector->panel.downclock_mode != NULL &&
Vandana Kannan96178ee2015-01-10 02:25:56 +05301685 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07001686 pipe_config->has_drrs = true;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05301687 intel_link_compute_m_n(bpp, lane_count,
1688 intel_connector->panel.downclock_mode->clock,
1689 pipe_config->port_clock,
1690 &pipe_config->dp_m2_n2);
1691 }
1692
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001693 /*
1694 * DPLL0 VCO may need to be adjusted to get the correct
1695 * clock for eDP. This will affect cdclk as well.
1696 */
1697 if (is_edp(intel_dp) &&
1698 (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))) {
1699 int vco;
1700
1701 switch (pipe_config->port_clock / 2) {
1702 case 108000:
1703 case 216000:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001704 vco = 8640000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001705 break;
1706 default:
Ville Syrjälä63911d72016-05-13 23:41:32 +03001707 vco = 8100000;
Ville Syrjälä14d41b32016-05-13 23:41:22 +03001708 break;
1709 }
1710
1711 to_intel_atomic_state(pipe_config->base.state)->cdclk_pll_vco = vco;
1712 }
1713
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001714 if (!HAS_DDI(dev_priv))
Ville Syrjälä840b32b2015-08-11 20:21:46 +03001715 intel_dp_set_clock(encoder, pipe_config);
Daniel Vetterc6bb3532013-04-19 11:14:33 +02001716
Daniel Vetter36008362013-03-27 00:44:59 +01001717 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001718}
1719
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001720void intel_dp_set_link_params(struct intel_dp *intel_dp,
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001721 int link_rate, uint8_t lane_count,
1722 bool link_mst)
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001723{
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001724 intel_dp->link_rate = link_rate;
1725 intel_dp->lane_count = lane_count;
1726 intel_dp->link_mst = link_mst;
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001727}
1728
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001729static void intel_dp_prepare(struct intel_encoder *encoder,
1730 struct intel_crtc_state *pipe_config)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001731{
Daniel Vetterb934223d2013-07-21 21:37:05 +02001732 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001733 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterb934223d2013-07-21 21:37:05 +02001734 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03001735 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetterb934223d2013-07-21 21:37:05 +02001736 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001737 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001738
Ander Conselvan de Oliveiradfa10482016-09-01 15:08:06 -07001739 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1740 pipe_config->lane_count,
1741 intel_crtc_has_type(pipe_config,
1742 INTEL_OUTPUT_DP_MST));
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001743
Keith Packard417e8222011-11-01 19:54:11 -07001744 /*
Keith Packard1a2eb462011-11-16 16:26:07 -08001745 * There are four kinds of DP registers:
Keith Packard417e8222011-11-01 19:54:11 -07001746 *
1747 * IBX PCH
Keith Packard1a2eb462011-11-16 16:26:07 -08001748 * SNB CPU
1749 * IVB CPU
Keith Packard417e8222011-11-01 19:54:11 -07001750 * CPT PCH
1751 *
1752 * IBX PCH and CPU are the same for almost everything,
1753 * except that the CPU DP PLL is configured in this
1754 * register
1755 *
1756 * CPT PCH is quite different, having many bits moved
1757 * to the TRANS_DP_CTL register instead. That
1758 * configuration happens (oddly) in ironlake_pch_enable
1759 */
Adam Jackson9c9e7922010-04-05 17:57:59 -04001760
Keith Packard417e8222011-11-01 19:54:11 -07001761 /* Preserve the BIOS-computed detected bit. This is
1762 * supposed to be read-only.
1763 */
1764 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001765
Keith Packard417e8222011-11-01 19:54:11 -07001766 /* Handle DP bits in common between all three register formats */
Keith Packard417e8222011-11-01 19:54:11 -07001767 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001768 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001769
Keith Packard417e8222011-11-01 19:54:11 -07001770 /* Split out the IBX/CPU vs CPT settings */
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001771
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001772 if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08001773 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1774 intel_dp->DP |= DP_SYNC_HS_HIGH;
1775 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1776 intel_dp->DP |= DP_SYNC_VS_HIGH;
1777 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1778
Jani Nikula6aba5b62013-10-04 15:08:10 +03001779 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard1a2eb462011-11-16 16:26:07 -08001780 intel_dp->DP |= DP_ENHANCED_FRAMING;
1781
Daniel Vetter7c62a162013-06-01 17:16:20 +02001782 intel_dp->DP |= crtc->pipe << 29;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001783 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001784 u32 trans_dp;
1785
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001786 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03001787
1788 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1789 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1790 trans_dp |= TRANS_DP_ENH_FRAMING;
1791 else
1792 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1793 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001794 } else {
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001795 if (!HAS_PCH_SPLIT(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001796 !IS_CHERRYVIEW(dev_priv) &&
1797 pipe_config->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001798 intel_dp->DP |= DP_COLOR_RANGE_16_235;
Keith Packard417e8222011-11-01 19:54:11 -07001799
1800 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1801 intel_dp->DP |= DP_SYNC_HS_HIGH;
1802 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1803 intel_dp->DP |= DP_SYNC_VS_HIGH;
1804 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1805
Jani Nikula6aba5b62013-10-04 15:08:10 +03001806 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Keith Packard417e8222011-11-01 19:54:11 -07001807 intel_dp->DP |= DP_ENHANCED_FRAMING;
1808
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001809 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +03001810 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03001811 else if (crtc->pipe == PIPE_B)
1812 intel_dp->DP |= DP_PIPEB_SELECT;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001813 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07001814}
1815
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001816#define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1817#define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001818
Paulo Zanoni1a5ef5b2013-12-19 14:29:43 -02001819#define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1820#define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
Keith Packard99ea7122011-11-01 19:57:50 -07001821
Paulo Zanoniffd6749d2013-12-19 14:29:42 -02001822#define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1823#define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
Keith Packard99ea7122011-11-01 19:57:50 -07001824
Imre Deakde9c1b62016-06-16 20:01:46 +03001825static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
1826 struct intel_dp *intel_dp);
1827
Daniel Vetter4be73782014-01-17 14:39:48 +01001828static void wait_panel_status(struct intel_dp *intel_dp,
Keith Packard99ea7122011-11-01 19:57:50 -07001829 u32 mask,
1830 u32 value)
1831{
Paulo Zanoni30add222012-10-26 19:05:45 -02001832 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001833 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001834 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes453c5422013-03-28 09:55:41 -07001835
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001836 lockdep_assert_held(&dev_priv->pps_mutex);
1837
Imre Deakde9c1b62016-06-16 20:01:46 +03001838 intel_pps_verify_state(dev_priv, intel_dp);
1839
Jani Nikulabf13e812013-09-06 07:40:05 +03001840 pp_stat_reg = _pp_stat_reg(intel_dp);
1841 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001842
1843 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001844 mask, value,
1845 I915_READ(pp_stat_reg),
1846 I915_READ(pp_ctrl_reg));
Keith Packard99ea7122011-11-01 19:57:50 -07001847
Chris Wilson9036ff02016-06-30 15:33:09 +01001848 if (intel_wait_for_register(dev_priv,
1849 pp_stat_reg, mask, value,
1850 5000))
Keith Packard99ea7122011-11-01 19:57:50 -07001851 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
Jesse Barnes453c5422013-03-28 09:55:41 -07001852 I915_READ(pp_stat_reg),
1853 I915_READ(pp_ctrl_reg));
Chris Wilson54c136d2013-12-02 09:57:16 +00001854
1855 DRM_DEBUG_KMS("Wait complete\n");
Keith Packard99ea7122011-11-01 19:57:50 -07001856}
1857
Daniel Vetter4be73782014-01-17 14:39:48 +01001858static void wait_panel_on(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001859{
1860 DRM_DEBUG_KMS("Wait for panel power on\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001861 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001862}
1863
Daniel Vetter4be73782014-01-17 14:39:48 +01001864static void wait_panel_off(struct intel_dp *intel_dp)
Keith Packardbd943152011-09-18 23:09:52 -07001865{
Keith Packardbd943152011-09-18 23:09:52 -07001866 DRM_DEBUG_KMS("Wait for panel power off time\n");
Daniel Vetter4be73782014-01-17 14:39:48 +01001867 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
Keith Packardbd943152011-09-18 23:09:52 -07001868}
Keith Packardbd943152011-09-18 23:09:52 -07001869
Daniel Vetter4be73782014-01-17 14:39:48 +01001870static void wait_panel_power_cycle(struct intel_dp *intel_dp)
Keith Packard99ea7122011-11-01 19:57:50 -07001871{
Abhay Kumard28d4732016-01-22 17:39:04 -08001872 ktime_t panel_power_on_time;
1873 s64 panel_power_off_duration;
1874
Keith Packard99ea7122011-11-01 19:57:50 -07001875 DRM_DEBUG_KMS("Wait for panel power cycle\n");
Paulo Zanonidce56b32013-12-19 14:29:40 -02001876
Abhay Kumard28d4732016-01-22 17:39:04 -08001877 /* take the difference of currrent time and panel power off time
1878 * and then make panel wait for t11_t12 if needed. */
1879 panel_power_on_time = ktime_get_boottime();
1880 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1881
Paulo Zanonidce56b32013-12-19 14:29:40 -02001882 /* When we disable the VDD override bit last we have to do the manual
1883 * wait. */
Abhay Kumard28d4732016-01-22 17:39:04 -08001884 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
1885 wait_remaining_ms_from_jiffies(jiffies,
1886 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
Paulo Zanonidce56b32013-12-19 14:29:40 -02001887
Daniel Vetter4be73782014-01-17 14:39:48 +01001888 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
Keith Packard99ea7122011-11-01 19:57:50 -07001889}
Keith Packardbd943152011-09-18 23:09:52 -07001890
Daniel Vetter4be73782014-01-17 14:39:48 +01001891static void wait_backlight_on(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001892{
1893 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1894 intel_dp->backlight_on_delay);
1895}
1896
Daniel Vetter4be73782014-01-17 14:39:48 +01001897static void edp_wait_backlight_off(struct intel_dp *intel_dp)
Paulo Zanonidce56b32013-12-19 14:29:40 -02001898{
1899 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
1900 intel_dp->backlight_off_delay);
1901}
Keith Packard99ea7122011-11-01 19:57:50 -07001902
Keith Packard832dd3c2011-11-01 19:34:06 -07001903/* Read the current pp_control value, unlocking the register if it
1904 * is locked
1905 */
1906
Jesse Barnes453c5422013-03-28 09:55:41 -07001907static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
Keith Packard832dd3c2011-11-01 19:34:06 -07001908{
Jesse Barnes453c5422013-03-28 09:55:41 -07001909 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001910 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07001911 u32 control;
Jesse Barnes453c5422013-03-28 09:55:41 -07001912
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001913 lockdep_assert_held(&dev_priv->pps_mutex);
1914
Jani Nikulabf13e812013-09-06 07:40:05 +03001915 control = I915_READ(_pp_ctrl_reg(intel_dp));
Imre Deak8090ba82016-08-10 14:07:33 +03001916 if (WARN_ON(!HAS_DDI(dev_priv) &&
1917 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05301918 control &= ~PANEL_UNLOCK_MASK;
1919 control |= PANEL_UNLOCK_REGS;
1920 }
Keith Packard832dd3c2011-11-01 19:34:06 -07001921 return control;
Keith Packardbd943152011-09-18 23:09:52 -07001922}
1923
Ville Syrjälä951468f2014-09-04 14:55:31 +03001924/*
1925 * Must be paired with edp_panel_vdd_off().
1926 * Must hold pps_mutex around the whole on/off sequence.
1927 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
1928 */
Ville Syrjälä1e0560e2014-08-19 13:24:25 +03001929static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08001930{
Paulo Zanoni30add222012-10-26 19:05:45 -02001931 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001932 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1933 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001934 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001935 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08001936 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001937 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001938 bool need_to_disable = !intel_dp->want_panel_vdd;
Jesse Barnes5d613502011-01-24 17:10:54 -08001939
Ville Syrjäläe39b9992014-09-04 14:53:14 +03001940 lockdep_assert_held(&dev_priv->pps_mutex);
1941
Keith Packard97af61f572011-09-28 16:23:51 -07001942 if (!is_edp(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001943 return false;
Keith Packardbd943152011-09-18 23:09:52 -07001944
Egbert Eich2c623c12014-11-25 12:54:57 +01001945 cancel_delayed_work(&intel_dp->panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07001946 intel_dp->want_panel_vdd = true;
Keith Packard99ea7122011-11-01 19:57:50 -07001947
Daniel Vetter4be73782014-01-17 14:39:48 +01001948 if (edp_have_panel_vdd(intel_dp))
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001949 return need_to_disable;
Paulo Zanonib0665d52013-10-30 19:50:27 -02001950
Ville Syrjälä25f78f52015-11-16 15:01:04 +01001951 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02001952 intel_display_power_get(dev_priv, power_domain);
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02001953
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001954 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
1955 port_name(intel_dig_port->port));
Keith Packardbd943152011-09-18 23:09:52 -07001956
Daniel Vetter4be73782014-01-17 14:39:48 +01001957 if (!edp_have_panel_power(intel_dp))
1958 wait_panel_power_cycle(intel_dp);
Keith Packard99ea7122011-11-01 19:57:50 -07001959
Jesse Barnes453c5422013-03-28 09:55:41 -07001960 pp = ironlake_get_pp_control(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08001961 pp |= EDP_FORCE_VDD;
Keith Packardebf33b12011-09-29 15:53:27 -07001962
Jani Nikulabf13e812013-09-06 07:40:05 +03001963 pp_stat_reg = _pp_stat_reg(intel_dp);
1964 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07001965
1966 I915_WRITE(pp_ctrl_reg, pp);
1967 POSTING_READ(pp_ctrl_reg);
1968 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
1969 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Keith Packardebf33b12011-09-29 15:53:27 -07001970 /*
1971 * If the panel wasn't on, delay before accessing aux channel
1972 */
Daniel Vetter4be73782014-01-17 14:39:48 +01001973 if (!edp_have_panel_power(intel_dp)) {
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03001974 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
1975 port_name(intel_dig_port->port));
Keith Packardf01eca22011-09-28 16:48:10 -07001976 msleep(intel_dp->panel_power_up_delay);
Keith Packardf01eca22011-09-28 16:48:10 -07001977 }
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001978
1979 return need_to_disable;
1980}
1981
Ville Syrjälä951468f2014-09-04 14:55:31 +03001982/*
1983 * Must be paired with intel_edp_panel_vdd_off() or
1984 * intel_edp_panel_off().
1985 * Nested calls to these functions are not allowed since
1986 * we drop the lock. Caller must use some higher level
1987 * locking to prevent nested calls from other threads.
1988 */
Daniel Vetterb80d6c72014-03-19 15:54:37 +01001989void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001990{
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001991 bool vdd;
Jani Nikulaadddaaf2014-03-14 16:51:13 +02001992
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001993 if (!is_edp(intel_dp))
1994 return;
1995
Ville Syrjälä773538e82014-09-04 14:54:56 +03001996 pps_lock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001997 vdd = edp_panel_vdd_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03001998 pps_unlock(intel_dp);
Ville Syrjäläc695b6b2014-08-18 22:16:03 +03001999
Rob Clarke2c719b2014-12-15 13:56:32 -05002000 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002001 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes5d613502011-01-24 17:10:54 -08002002}
2003
Daniel Vetter4be73782014-01-17 14:39:48 +01002004static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
Jesse Barnes5d613502011-01-24 17:10:54 -08002005{
Paulo Zanoni30add222012-10-26 19:05:45 -02002006 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002007 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002008 struct intel_digital_port *intel_dig_port =
2009 dp_to_dig_port(intel_dp);
2010 struct intel_encoder *intel_encoder = &intel_dig_port->base;
2011 enum intel_display_power_domain power_domain;
Jesse Barnes5d613502011-01-24 17:10:54 -08002012 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002013 i915_reg_t pp_stat_reg, pp_ctrl_reg;
Jesse Barnes5d613502011-01-24 17:10:54 -08002014
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002015 lockdep_assert_held(&dev_priv->pps_mutex);
Daniel Vettera0e99e62012-12-02 01:05:46 +01002016
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002017 WARN_ON(intel_dp->want_panel_vdd);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002018
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002019 if (!edp_have_panel_vdd(intel_dp))
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002020 return;
Paulo Zanonib0665d52013-10-30 19:50:27 -02002021
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002022 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2023 port_name(intel_dig_port->port));
Jesse Barnes453c5422013-03-28 09:55:41 -07002024
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002025 pp = ironlake_get_pp_control(intel_dp);
2026 pp &= ~EDP_FORCE_VDD;
Jesse Barnes453c5422013-03-28 09:55:41 -07002027
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002028 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2029 pp_stat_reg = _pp_stat_reg(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002030
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002031 I915_WRITE(pp_ctrl_reg, pp);
2032 POSTING_READ(pp_ctrl_reg);
Paulo Zanoni90791a52013-12-06 17:32:42 -02002033
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002034 /* Make sure sequencer is idle before allowing subsequent activity */
2035 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2036 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002037
Imre Deak5a162e22016-08-10 14:07:30 +03002038 if ((pp & PANEL_POWER_ON) == 0)
Abhay Kumard28d4732016-01-22 17:39:04 -08002039 intel_dp->panel_power_off_time = ktime_get_boottime();
Paulo Zanonie9cb81a2013-11-21 13:47:23 -02002040
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002041 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Ville Syrjäläbe2c9192014-08-18 22:16:01 +03002042 intel_display_power_put(dev_priv, power_domain);
Keith Packardbd943152011-09-18 23:09:52 -07002043}
2044
Daniel Vetter4be73782014-01-17 14:39:48 +01002045static void edp_panel_vdd_work(struct work_struct *__work)
Keith Packardbd943152011-09-18 23:09:52 -07002046{
2047 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2048 struct intel_dp, panel_vdd_work);
Keith Packardbd943152011-09-18 23:09:52 -07002049
Ville Syrjälä773538e82014-09-04 14:54:56 +03002050 pps_lock(intel_dp);
Ville Syrjälä15e899a2014-08-18 22:16:02 +03002051 if (!intel_dp->want_panel_vdd)
2052 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002053 pps_unlock(intel_dp);
Keith Packardbd943152011-09-18 23:09:52 -07002054}
2055
Imre Deakaba86892014-07-30 15:57:31 +03002056static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2057{
2058 unsigned long delay;
2059
2060 /*
2061 * Queue the timer to fire a long time from now (relative to the power
2062 * down delay) to keep the panel power up across a sequence of
2063 * operations.
2064 */
2065 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2066 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2067}
2068
Ville Syrjälä951468f2014-09-04 14:55:31 +03002069/*
2070 * Must be paired with edp_panel_vdd_on().
2071 * Must hold pps_mutex around the whole on/off sequence.
2072 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2073 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002074static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
Keith Packardbd943152011-09-18 23:09:52 -07002075{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002076 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002077
2078 lockdep_assert_held(&dev_priv->pps_mutex);
2079
Keith Packard97af61f572011-09-28 16:23:51 -07002080 if (!is_edp(intel_dp))
2081 return;
Jesse Barnes5d613502011-01-24 17:10:54 -08002082
Rob Clarke2c719b2014-12-15 13:56:32 -05002083 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002084 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packardf2e8b182011-11-01 20:01:35 -07002085
Keith Packardbd943152011-09-18 23:09:52 -07002086 intel_dp->want_panel_vdd = false;
2087
Imre Deakaba86892014-07-30 15:57:31 +03002088 if (sync)
Daniel Vetter4be73782014-01-17 14:39:48 +01002089 edp_panel_vdd_off_sync(intel_dp);
Imre Deakaba86892014-07-30 15:57:31 +03002090 else
2091 edp_panel_vdd_schedule_off(intel_dp);
Jesse Barnes5d613502011-01-24 17:10:54 -08002092}
2093
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002094static void edp_panel_on(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002095{
Paulo Zanoni30add222012-10-26 19:05:45 -02002096 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002097 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packard99ea7122011-11-01 19:57:50 -07002098 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002099 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002100
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002101 lockdep_assert_held(&dev_priv->pps_mutex);
2102
Keith Packard97af61f572011-09-28 16:23:51 -07002103 if (!is_edp(intel_dp))
Keith Packardbd943152011-09-18 23:09:52 -07002104 return;
Keith Packard99ea7122011-11-01 19:57:50 -07002105
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002106 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2107 port_name(dp_to_dig_port(intel_dp)->port));
Keith Packard99ea7122011-11-01 19:57:50 -07002108
Ville Syrjäläe7a89ac2014-10-16 21:30:07 +03002109 if (WARN(edp_have_panel_power(intel_dp),
2110 "eDP port %c panel power already on\n",
2111 port_name(dp_to_dig_port(intel_dp)->port)))
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002112 return;
Jesse Barnes9934c132010-07-22 13:18:19 -07002113
Daniel Vetter4be73782014-01-17 14:39:48 +01002114 wait_panel_power_cycle(intel_dp);
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002115
Jani Nikulabf13e812013-09-06 07:40:05 +03002116 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002117 pp = ironlake_get_pp_control(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002118 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002119 /* ILK workaround: disable reset around power sequence */
2120 pp &= ~PANEL_POWER_RESET;
Jani Nikulabf13e812013-09-06 07:40:05 +03002121 I915_WRITE(pp_ctrl_reg, pp);
2122 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002123 }
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002124
Imre Deak5a162e22016-08-10 14:07:30 +03002125 pp |= PANEL_POWER_ON;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002126 if (!IS_GEN5(dev_priv))
Keith Packard99ea7122011-11-01 19:57:50 -07002127 pp |= PANEL_POWER_RESET;
2128
Jesse Barnes453c5422013-03-28 09:55:41 -07002129 I915_WRITE(pp_ctrl_reg, pp);
2130 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002131
Daniel Vetter4be73782014-01-17 14:39:48 +01002132 wait_panel_on(intel_dp);
Paulo Zanonidce56b32013-12-19 14:29:40 -02002133 intel_dp->last_power_on = jiffies;
Jesse Barnes9934c132010-07-22 13:18:19 -07002134
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002135 if (IS_GEN5(dev_priv)) {
Keith Packard05ce1a42011-09-29 16:33:01 -07002136 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
Jani Nikulabf13e812013-09-06 07:40:05 +03002137 I915_WRITE(pp_ctrl_reg, pp);
2138 POSTING_READ(pp_ctrl_reg);
Keith Packard05ce1a42011-09-29 16:33:01 -07002139 }
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002140}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002141
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002142void intel_edp_panel_on(struct intel_dp *intel_dp)
2143{
2144 if (!is_edp(intel_dp))
2145 return;
2146
2147 pps_lock(intel_dp);
2148 edp_panel_on(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002149 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002150}
2151
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002152
2153static void edp_panel_off(struct intel_dp *intel_dp)
Jesse Barnes9934c132010-07-22 13:18:19 -07002154{
Imre Deak4e6e1a52014-03-27 17:45:11 +02002155 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2156 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanoni30add222012-10-26 19:05:45 -02002157 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002158 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002159 enum intel_display_power_domain power_domain;
Keith Packard99ea7122011-11-01 19:57:50 -07002160 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002161 i915_reg_t pp_ctrl_reg;
Jesse Barnes9934c132010-07-22 13:18:19 -07002162
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002163 lockdep_assert_held(&dev_priv->pps_mutex);
2164
Keith Packard97af61f572011-09-28 16:23:51 -07002165 if (!is_edp(intel_dp))
2166 return;
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002167
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002168 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2169 port_name(dp_to_dig_port(intel_dp)->port));
Jesse Barnes37c6c9b2010-08-11 10:04:43 -07002170
Ville Syrjälä3936fcf2014-10-16 21:30:02 +03002171 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2172 port_name(dp_to_dig_port(intel_dp)->port));
Jani Nikula24f3e092014-03-17 16:43:36 +02002173
Jesse Barnes453c5422013-03-28 09:55:41 -07002174 pp = ironlake_get_pp_control(intel_dp);
Daniel Vetter35a38552012-08-12 22:17:14 +02002175 /* We need to switch off panel power _and_ force vdd, for otherwise some
2176 * panels get very unhappy and cease to work. */
Imre Deak5a162e22016-08-10 14:07:30 +03002177 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
Patrik Jakobssonb3064152014-03-04 00:42:44 +01002178 EDP_BLC_ENABLE);
Jesse Barnes453c5422013-03-28 09:55:41 -07002179
Jani Nikulabf13e812013-09-06 07:40:05 +03002180 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002181
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002182 intel_dp->want_panel_vdd = false;
2183
Jesse Barnes453c5422013-03-28 09:55:41 -07002184 I915_WRITE(pp_ctrl_reg, pp);
2185 POSTING_READ(pp_ctrl_reg);
Jesse Barnes9934c132010-07-22 13:18:19 -07002186
Abhay Kumard28d4732016-01-22 17:39:04 -08002187 intel_dp->panel_power_off_time = ktime_get_boottime();
Daniel Vetter4be73782014-01-17 14:39:48 +01002188 wait_panel_off(intel_dp);
Paulo Zanoni849e39f2014-03-07 20:05:20 -03002189
2190 /* We got a reference when we enabled the VDD. */
Ville Syrjälä25f78f52015-11-16 15:01:04 +01002191 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak4e6e1a52014-03-27 17:45:11 +02002192 intel_display_power_put(dev_priv, power_domain);
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002193}
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002194
Ville Syrjälä9f0fb5b2014-10-16 21:27:32 +03002195void intel_edp_panel_off(struct intel_dp *intel_dp)
2196{
2197 if (!is_edp(intel_dp))
2198 return;
2199
2200 pps_lock(intel_dp);
2201 edp_panel_off(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002202 pps_unlock(intel_dp);
Jesse Barnes9934c132010-07-22 13:18:19 -07002203}
2204
Jani Nikula1250d102014-08-12 17:11:39 +03002205/* Enable backlight in the panel power control. */
2206static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002207{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002208 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2209 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002210 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002211 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002212 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002213
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07002214 /*
2215 * If we enable the backlight right away following a panel power
2216 * on, we may see slight flicker as the panel syncs with the eDP
2217 * link. So delay a bit to make sure the image is solid before
2218 * allowing it to appear.
2219 */
Daniel Vetter4be73782014-01-17 14:39:48 +01002220 wait_backlight_on(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002221
Ville Syrjälä773538e82014-09-04 14:54:56 +03002222 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002223
Jesse Barnes453c5422013-03-28 09:55:41 -07002224 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002225 pp |= EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002226
Jani Nikulabf13e812013-09-06 07:40:05 +03002227 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002228
2229 I915_WRITE(pp_ctrl_reg, pp);
2230 POSTING_READ(pp_ctrl_reg);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002231
Ville Syrjälä773538e82014-09-04 14:54:56 +03002232 pps_unlock(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002233}
2234
Jani Nikula1250d102014-08-12 17:11:39 +03002235/* Enable backlight PWM and backlight PP control. */
2236void intel_edp_backlight_on(struct intel_dp *intel_dp)
2237{
2238 if (!is_edp(intel_dp))
2239 return;
2240
2241 DRM_DEBUG_KMS("\n");
2242
2243 intel_panel_enable_backlight(intel_dp->attached_connector);
2244 _intel_edp_backlight_on(intel_dp);
2245}
2246
2247/* Disable backlight in the panel power control. */
2248static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002249{
Paulo Zanoni30add222012-10-26 19:05:45 -02002250 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002251 struct drm_i915_private *dev_priv = to_i915(dev);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002252 u32 pp;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002253 i915_reg_t pp_ctrl_reg;
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002254
Keith Packardf01eca22011-09-28 16:48:10 -07002255 if (!is_edp(intel_dp))
2256 return;
2257
Ville Syrjälä773538e82014-09-04 14:54:56 +03002258 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002259
Jesse Barnes453c5422013-03-28 09:55:41 -07002260 pp = ironlake_get_pp_control(intel_dp);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002261 pp &= ~EDP_BLC_ENABLE;
Jesse Barnes453c5422013-03-28 09:55:41 -07002262
Jani Nikulabf13e812013-09-06 07:40:05 +03002263 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
Jesse Barnes453c5422013-03-28 09:55:41 -07002264
2265 I915_WRITE(pp_ctrl_reg, pp);
2266 POSTING_READ(pp_ctrl_reg);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002267
Ville Syrjälä773538e82014-09-04 14:54:56 +03002268 pps_unlock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002269
Paulo Zanonidce56b32013-12-19 14:29:40 -02002270 intel_dp->last_backlight_off = jiffies;
Jesse Barnesf7d23232014-03-31 11:13:56 -07002271 edp_wait_backlight_off(intel_dp);
Jani Nikula1250d102014-08-12 17:11:39 +03002272}
Jesse Barnesf7d23232014-03-31 11:13:56 -07002273
Jani Nikula1250d102014-08-12 17:11:39 +03002274/* Disable backlight PP control and backlight PWM. */
2275void intel_edp_backlight_off(struct intel_dp *intel_dp)
2276{
2277 if (!is_edp(intel_dp))
2278 return;
2279
2280 DRM_DEBUG_KMS("\n");
2281
2282 _intel_edp_backlight_off(intel_dp);
Jesse Barnesf7d23232014-03-31 11:13:56 -07002283 intel_panel_disable_backlight(intel_dp->attached_connector);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08002284}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002285
Jani Nikula73580fb72014-08-12 17:11:41 +03002286/*
2287 * Hook for controlling the panel power control backlight through the bl_power
2288 * sysfs attribute. Take care to handle multiple calls.
2289 */
2290static void intel_edp_backlight_power(struct intel_connector *connector,
2291 bool enable)
2292{
2293 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002294 bool is_enabled;
2295
Ville Syrjälä773538e82014-09-04 14:54:56 +03002296 pps_lock(intel_dp);
Ville Syrjäläe39b9992014-09-04 14:53:14 +03002297 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002298 pps_unlock(intel_dp);
Jani Nikula73580fb72014-08-12 17:11:41 +03002299
2300 if (is_enabled == enable)
2301 return;
2302
Jani Nikula23ba9372014-08-27 14:08:43 +03002303 DRM_DEBUG_KMS("panel power control backlight %s\n",
2304 enable ? "enable" : "disable");
Jani Nikula73580fb72014-08-12 17:11:41 +03002305
2306 if (enable)
2307 _intel_edp_backlight_on(intel_dp);
2308 else
2309 _intel_edp_backlight_off(intel_dp);
2310}
2311
Ville Syrjälä64e10772015-10-29 21:26:01 +02002312static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2313{
2314 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2315 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2316 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2317
2318 I915_STATE_WARN(cur_state != state,
2319 "DP port %c state assertion failure (expected %s, current %s)\n",
2320 port_name(dig_port->port),
Jani Nikula87ad3212016-01-14 12:53:34 +02002321 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002322}
2323#define assert_dp_port_disabled(d) assert_dp_port((d), false)
2324
2325static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2326{
2327 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2328
2329 I915_STATE_WARN(cur_state != state,
2330 "eDP PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02002331 onoff(state), onoff(cur_state));
Ville Syrjälä64e10772015-10-29 21:26:01 +02002332}
2333#define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2334#define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2335
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002336static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2337 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002338{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002339 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002340 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002341
Ville Syrjälä64e10772015-10-29 21:26:01 +02002342 assert_pipe_disabled(dev_priv, crtc->pipe);
2343 assert_dp_port_disabled(intel_dp);
2344 assert_edp_pll_disabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002345
Ville Syrjäläabfce942015-10-29 21:26:03 +02002346 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002347 pipe_config->port_clock);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002348
2349 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2350
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002351 if (pipe_config->port_clock == 162000)
Ville Syrjäläabfce942015-10-29 21:26:03 +02002352 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2353 else
2354 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2355
2356 I915_WRITE(DP_A, intel_dp->DP);
2357 POSTING_READ(DP_A);
2358 udelay(500);
2359
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002360 /*
2361 * [DevILK] Work around required when enabling DP PLL
2362 * while a pipe is enabled going to FDI:
2363 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2364 * 2. Program DP PLL enable
2365 */
2366 if (IS_GEN5(dev_priv))
Chris Wilson91c8a322016-07-05 10:40:23 +01002367 intel_wait_for_vblank_if_active(&dev_priv->drm, !crtc->pipe);
Ville Syrjälä6b23f3e2016-04-01 21:53:19 +03002368
Daniel Vetter07679352012-09-06 22:15:42 +02002369 intel_dp->DP |= DP_PLL_ENABLE;
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002370
Daniel Vetter07679352012-09-06 22:15:42 +02002371 I915_WRITE(DP_A, intel_dp->DP);
Jesse Barnes298b0b32010-10-07 16:01:24 -07002372 POSTING_READ(DP_A);
2373 udelay(200);
Jesse Barnesd240f202010-08-13 15:43:26 -07002374}
2375
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002376static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
Jesse Barnesd240f202010-08-13 15:43:26 -07002377{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02002378 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä64e10772015-10-29 21:26:01 +02002379 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
2380 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesd240f202010-08-13 15:43:26 -07002381
Ville Syrjälä64e10772015-10-29 21:26:01 +02002382 assert_pipe_disabled(dev_priv, crtc->pipe);
2383 assert_dp_port_disabled(intel_dp);
2384 assert_edp_pll_enabled(dev_priv);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002385
Ville Syrjäläabfce942015-10-29 21:26:03 +02002386 DRM_DEBUG_KMS("disabling eDP PLL\n");
2387
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002388 intel_dp->DP &= ~DP_PLL_ENABLE;
Daniel Vetter07679352012-09-06 22:15:42 +02002389
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002390 I915_WRITE(DP_A, intel_dp->DP);
Chris Wilson1af5fa12010-09-08 21:07:28 +01002391 POSTING_READ(DP_A);
Jesse Barnesd240f202010-08-13 15:43:26 -07002392 udelay(200);
2393}
2394
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002395/* If the sink supports it, try to set the power state appropriately */
Paulo Zanonic19b0662012-10-15 15:51:41 -03002396void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002397{
2398 int ret, i;
2399
2400 /* Should have a valid DPCD by this point */
2401 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2402 return;
2403
2404 if (mode != DRM_MODE_DPMS_ON) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002405 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2406 DP_SET_POWER_D3);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002407 } else {
2408 /*
2409 * When turning on, we need to retry for 1ms to give the sink
2410 * time to wake up.
2411 */
2412 for (i = 0; i < 3; i++) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02002413 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2414 DP_SET_POWER_D0);
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002415 if (ret == 1)
2416 break;
2417 msleep(1);
2418 }
2419 }
Jani Nikulaf9cac722014-09-02 16:33:52 +03002420
2421 if (ret != 1)
2422 DRM_DEBUG_KMS("failed to %s sink power state\n",
2423 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
Jesse Barnesc7ad3812011-07-07 11:11:03 -07002424}
2425
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002426static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2427 enum pipe *pipe)
Jesse Barnesd240f202010-08-13 15:43:26 -07002428{
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002429 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002430 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002431 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002432 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak6d129be2014-03-05 16:20:54 +02002433 enum intel_display_power_domain power_domain;
2434 u32 tmp;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002435 bool ret;
Imre Deak6d129be2014-03-05 16:20:54 +02002436
2437 power_domain = intel_display_port_power_domain(encoder);
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002438 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02002439 return false;
2440
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002441 ret = false;
2442
Imre Deak6d129be2014-03-05 16:20:54 +02002443 tmp = I915_READ(intel_dp->output_reg);
Jesse Barnesd240f202010-08-13 15:43:26 -07002444
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002445 if (!(tmp & DP_PORT_EN))
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002446 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002447
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002448 if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002449 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002450 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002451 enum pipe p;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002452
Ville Syrjäläadc289d2015-05-05 17:17:30 +03002453 for_each_pipe(dev_priv, p) {
2454 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2455 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2456 *pipe = p;
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002457 ret = true;
2458
2459 goto out;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002460 }
2461 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002462
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002463 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002464 i915_mmio_reg_offset(intel_dp->output_reg));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002465 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002466 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2467 } else {
2468 *pipe = PORT_TO_PIPE(tmp);
Daniel Vetter4a0833e2012-10-26 10:58:11 +02002469 }
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002470
Imre Deak6fa9a5e2016-02-12 18:55:18 +02002471 ret = true;
2472
2473out:
2474 intel_display_power_put(dev_priv, power_domain);
2475
2476 return ret;
Daniel Vetter19d8fe12012-07-02 13:26:27 +02002477}
2478
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002479static void intel_dp_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002480 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002481{
2482 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002483 u32 tmp, flags = 0;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002484 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002485 struct drm_i915_private *dev_priv = to_i915(dev);
Xiong Zhang63000ef2013-06-28 12:59:06 +08002486 enum port port = dp_to_dig_port(intel_dp)->port;
2487 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002488
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002489 tmp = I915_READ(intel_dp->output_reg);
Jani Nikula9fcb1702015-05-05 16:32:12 +03002490
2491 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002492
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002493 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002494 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2495
2496 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002497 flags |= DRM_MODE_FLAG_PHSYNC;
2498 else
2499 flags |= DRM_MODE_FLAG_NHSYNC;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002500
Ville Syrjäläb81e34c2015-07-06 15:10:03 +03002501 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
Xiong Zhang63000ef2013-06-28 12:59:06 +08002502 flags |= DRM_MODE_FLAG_PVSYNC;
2503 else
2504 flags |= DRM_MODE_FLAG_NVSYNC;
Ville Syrjälä39e5fa82015-05-05 17:17:29 +03002505 } else {
2506 if (tmp & DP_SYNC_HS_HIGH)
2507 flags |= DRM_MODE_FLAG_PHSYNC;
2508 else
2509 flags |= DRM_MODE_FLAG_NHSYNC;
2510
2511 if (tmp & DP_SYNC_VS_HIGH)
2512 flags |= DRM_MODE_FLAG_PVSYNC;
2513 else
2514 flags |= DRM_MODE_FLAG_NVSYNC;
Xiong Zhang63000ef2013-06-28 12:59:06 +08002515 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002516
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002517 pipe_config->base.adjusted_mode.flags |= flags;
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002518
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002519 if (!HAS_PCH_SPLIT(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
2520 !IS_CHERRYVIEW(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
Ville Syrjälä8c875fc2014-09-12 15:46:29 +03002521 pipe_config->limited_color_range = true;
2522
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002523 pipe_config->lane_count =
2524 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2525
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002526 intel_dp_get_m_n(crtc, pipe_config);
2527
Ville Syrjälä18442d02013-09-13 16:00:08 +03002528 if (port == PORT_A) {
Ville Syrjäläb377e0d2015-10-29 21:25:59 +02002529 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
Jesse Barnesf1f644d2013-06-27 00:39:25 +03002530 pipe_config->port_clock = 162000;
2531 else
2532 pipe_config->port_clock = 270000;
2533 }
Ville Syrjälä18442d02013-09-13 16:00:08 +03002534
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02002535 pipe_config->base.adjusted_mode.crtc_clock =
2536 intel_dotclock_calculate(pipe_config->port_clock,
2537 &pipe_config->dp_m_n);
Daniel Vetter7f16e5c2013-11-04 16:28:47 +01002538
Jani Nikula6aa23e62016-03-24 17:50:20 +02002539 if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
2540 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002541 /*
2542 * This is a big fat ugly hack.
2543 *
2544 * Some machines in UEFI boot mode provide us a VBT that has 18
2545 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2546 * unknown we fail to light up. Yet the same BIOS boots up with
2547 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2548 * max, not what it tells us to use.
2549 *
2550 * Note: This will still be broken if the eDP panel is not lit
2551 * up by the BIOS, and thus we can't get the mode at module
2552 * load.
2553 */
2554 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002555 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2556 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Jani Nikulac6cd2ee2013-10-21 10:52:07 +03002557 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002558}
2559
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002560static void intel_disable_dp(struct intel_encoder *encoder,
2561 struct intel_crtc_state *old_crtc_state,
2562 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002563{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002564 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002565 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jani Nikula495a5bb2014-10-27 16:26:55 +02002566
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002567 if (old_crtc_state->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +02002568 intel_audio_codec_disable(encoder);
Daniel Vetter6cb49832012-05-20 17:14:50 +02002569
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002570 if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv))
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002571 intel_psr_disable(intel_dp);
2572
Daniel Vetter6cb49832012-05-20 17:14:50 +02002573 /* Make sure the panel is off before trying to change the mode. But also
2574 * ensure that we have vdd while we switch off the panel. */
Jani Nikula24f3e092014-03-17 16:43:36 +02002575 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01002576 intel_edp_backlight_off(intel_dp);
Jani Nikulafdbc3b12013-11-12 17:10:13 +02002577 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01002578 intel_edp_panel_off(intel_dp);
Daniel Vetter37398502012-09-06 22:15:44 +02002579
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002580 /* disable the port before the pipe on g4x */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002581 if (INTEL_GEN(dev_priv) < 5)
Daniel Vetter37398502012-09-06 22:15:44 +02002582 intel_dp_link_down(intel_dp);
Jesse Barnesd240f202010-08-13 15:43:26 -07002583}
2584
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002585static void ilk_post_disable_dp(struct intel_encoder *encoder,
2586 struct intel_crtc_state *old_crtc_state,
2587 struct drm_connector_state *old_conn_state)
Jesse Barnesd240f202010-08-13 15:43:26 -07002588{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002589 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Imre Deak982a3862013-05-23 19:39:40 +03002590 enum port port = dp_to_dig_port(intel_dp)->port;
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002591
Ville Syrjälä49277c32014-03-31 18:21:26 +03002592 intel_dp_link_down(intel_dp);
Ville Syrjäläabfce942015-10-29 21:26:03 +02002593
2594 /* Only ilk+ has port A */
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03002595 if (port == PORT_A)
2596 ironlake_edp_pll_off(intel_dp);
Ville Syrjälä49277c32014-03-31 18:21:26 +03002597}
2598
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002599static void vlv_post_disable_dp(struct intel_encoder *encoder,
2600 struct intel_crtc_state *old_crtc_state,
2601 struct drm_connector_state *old_conn_state)
Ville Syrjälä49277c32014-03-31 18:21:26 +03002602{
2603 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2604
2605 intel_dp_link_down(intel_dp);
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002606}
2607
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002608static void chv_post_disable_dp(struct intel_encoder *encoder,
2609 struct intel_crtc_state *old_crtc_state,
2610 struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03002611{
2612 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002613 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002614 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002615
2616 intel_dp_link_down(intel_dp);
2617
Ville Syrjäläa5805162015-05-26 20:42:30 +03002618 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002619
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03002620 /* Assert data lane reset */
2621 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002622
Ville Syrjäläa5805162015-05-26 20:42:30 +03002623 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03002624}
2625
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002626static void
2627_intel_dp_set_link_train(struct intel_dp *intel_dp,
2628 uint32_t *DP,
2629 uint8_t dp_train_pat)
2630{
2631 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2632 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002633 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002634 enum port port = intel_dig_port->port;
2635
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002636 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2637 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2638 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2639
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01002640 if (HAS_DDI(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002641 uint32_t temp = I915_READ(DP_TP_CTL(port));
2642
2643 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2644 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2645 else
2646 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2647
2648 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2649 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2650 case DP_TRAINING_PATTERN_DISABLE:
2651 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2652
2653 break;
2654 case DP_TRAINING_PATTERN_1:
2655 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2656 break;
2657 case DP_TRAINING_PATTERN_2:
2658 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2659 break;
2660 case DP_TRAINING_PATTERN_3:
2661 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2662 break;
2663 }
2664 I915_WRITE(DP_TP_CTL(port), temp);
2665
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002666 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002667 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002668 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2669
2670 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2671 case DP_TRAINING_PATTERN_DISABLE:
2672 *DP |= DP_LINK_TRAIN_OFF_CPT;
2673 break;
2674 case DP_TRAINING_PATTERN_1:
2675 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2676 break;
2677 case DP_TRAINING_PATTERN_2:
2678 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2679 break;
2680 case DP_TRAINING_PATTERN_3:
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002681 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002682 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2683 break;
2684 }
2685
2686 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002687 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002688 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2689 else
2690 *DP &= ~DP_LINK_TRAIN_MASK;
2691
2692 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2693 case DP_TRAINING_PATTERN_DISABLE:
2694 *DP |= DP_LINK_TRAIN_OFF;
2695 break;
2696 case DP_TRAINING_PATTERN_1:
2697 *DP |= DP_LINK_TRAIN_PAT_1;
2698 break;
2699 case DP_TRAINING_PATTERN_2:
2700 *DP |= DP_LINK_TRAIN_PAT_2;
2701 break;
2702 case DP_TRAINING_PATTERN_3:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002703 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002704 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2705 } else {
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002706 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002707 *DP |= DP_LINK_TRAIN_PAT_2;
2708 }
2709 break;
2710 }
2711 }
2712}
2713
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002714static void intel_dp_enable_port(struct intel_dp *intel_dp,
2715 struct intel_crtc_state *old_crtc_state)
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002716{
2717 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002718 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002719
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002720 /* enable with pattern 1 (as per spec) */
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002721
Pandiyan, Dhinakaran8b0878a2016-08-04 13:48:35 -07002722 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002723
2724 /*
2725 * Magic for VLV/CHV. We _must_ first set up the register
2726 * without actually enabling the port, and then do another
2727 * write to enable the port. Otherwise link training will
2728 * fail when the power sequencer is freshly used for this port.
2729 */
2730 intel_dp->DP |= DP_PORT_EN;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002731 if (old_crtc_state->has_audio)
Ville Syrjälä6fec7662015-11-10 16:16:17 +02002732 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
Ville Syrjälä7b713f52014-10-16 21:27:35 +03002733
2734 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2735 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä7b13b582014-08-18 22:16:08 +03002736}
2737
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002738static void intel_enable_dp(struct intel_encoder *encoder,
2739 struct intel_crtc_state *pipe_config)
Jesse Barnesd240f202010-08-13 15:43:26 -07002740{
Daniel Vettere8cb4552012-07-01 13:05:48 +02002741 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2742 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002743 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulac1dec792014-10-27 16:26:56 +02002744 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +01002745 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002746 enum pipe pipe = crtc->pipe;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002747
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02002748 if (WARN_ON(dp_reg & DP_PORT_EN))
2749 return;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002750
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002751 pps_lock(intel_dp);
2752
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002753 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002754 vlv_init_panel_power_sequencer(intel_dp);
2755
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002756 intel_dp_enable_port(intel_dp, pipe_config);
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002757
2758 edp_panel_vdd_on(intel_dp);
2759 edp_panel_on(intel_dp);
2760 edp_panel_vdd_off(intel_dp, true);
2761
2762 pps_unlock(intel_dp);
2763
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002764 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002765 unsigned int lane_mask = 0x0;
2766
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002767 if (IS_CHERRYVIEW(dev_priv))
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002768 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002769
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03002770 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2771 lane_mask);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002772 }
Ville Syrjälä61234fa2014-10-16 21:27:34 +03002773
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002774 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2775 intel_dp_start_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03002776 intel_dp_stop_link_train(intel_dp);
Jani Nikulac1dec792014-10-27 16:26:56 +02002777
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002778 if (pipe_config->has_audio) {
Jani Nikulac1dec792014-10-27 16:26:56 +02002779 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002780 pipe_name(pipe));
Jani Nikulac1dec792014-10-27 16:26:56 +02002781 intel_audio_codec_enable(encoder);
2782 }
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002783}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002784
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002785static void g4x_enable_dp(struct intel_encoder *encoder,
2786 struct intel_crtc_state *pipe_config,
2787 struct drm_connector_state *conn_state)
Jani Nikulaecff4f32013-09-06 07:38:29 +03002788{
Jani Nikula828f5c62013-09-05 16:44:45 +03002789 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2790
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002791 intel_enable_dp(encoder, pipe_config);
Daniel Vetter4be73782014-01-17 14:39:48 +01002792 intel_edp_backlight_on(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002793}
Jesse Barnes89b667f2013-04-18 14:51:36 -07002794
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002795static void vlv_enable_dp(struct intel_encoder *encoder,
2796 struct intel_crtc_state *pipe_config,
2797 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002798{
Jani Nikula828f5c62013-09-05 16:44:45 +03002799 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2800
Daniel Vetter4be73782014-01-17 14:39:48 +01002801 intel_edp_backlight_on(intel_dp);
Rodrigo Vivib32c6f42014-11-20 03:44:37 -08002802 intel_psr_enable(intel_dp);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002803}
2804
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002805static void g4x_pre_enable_dp(struct intel_encoder *encoder,
2806 struct intel_crtc_state *pipe_config,
2807 struct drm_connector_state *conn_state)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002808{
Daniel Vetter2bd2ad62012-09-06 22:15:41 +02002809 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjäläd6fbdd12015-10-29 21:25:58 +02002810 enum port port = dp_to_dig_port(intel_dp)->port;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002811
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002812 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002813
Daniel Vetterd41f1ef2014-04-24 23:54:53 +02002814 /* Only ilk+ has port A */
Ville Syrjäläabfce942015-10-29 21:26:03 +02002815 if (port == PORT_A)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002816 ironlake_edp_pll_on(intel_dp, pipe_config);
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002817}
2818
Ville Syrjälä83b84592014-10-16 21:29:51 +03002819static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2820{
2821 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002822 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002823 enum pipe pipe = intel_dp->pps_pipe;
Imre Deak44cb7342016-08-10 14:07:29 +03002824 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
Ville Syrjälä83b84592014-10-16 21:29:51 +03002825
2826 edp_panel_vdd_off_sync(intel_dp);
2827
2828 /*
2829 * VLV seems to get confused when multiple power seqeuencers
2830 * have the same port selected (even if only one has power/vdd
2831 * enabled). The failure manifests as vlv_wait_port_ready() failing
2832 * CHV on the other hand doesn't seem to mind having the same port
2833 * selected in multiple power seqeuencers, but let's clear the
2834 * port select always when logically disconnecting a power sequencer
2835 * from a port.
2836 */
2837 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2838 pipe_name(pipe), port_name(intel_dig_port->port));
2839 I915_WRITE(pp_on_reg, 0);
2840 POSTING_READ(pp_on_reg);
2841
2842 intel_dp->pps_pipe = INVALID_PIPE;
2843}
2844
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002845static void vlv_steal_power_sequencer(struct drm_device *dev,
2846 enum pipe pipe)
2847{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002848 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002849 struct intel_encoder *encoder;
2850
2851 lockdep_assert_held(&dev_priv->pps_mutex);
2852
Ville Syrjäläac3c12e2014-10-16 21:29:56 +03002853 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2854 return;
2855
Jani Nikula19c80542015-12-16 12:48:16 +02002856 for_each_intel_encoder(dev, encoder) {
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002857 struct intel_dp *intel_dp;
Ville Syrjälä773538e82014-09-04 14:54:56 +03002858 enum port port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002859
2860 if (encoder->type != INTEL_OUTPUT_EDP)
2861 continue;
2862
2863 intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä773538e82014-09-04 14:54:56 +03002864 port = dp_to_dig_port(intel_dp)->port;
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002865
2866 if (intel_dp->pps_pipe != pipe)
2867 continue;
2868
2869 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Ville Syrjälä773538e82014-09-04 14:54:56 +03002870 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002871
Maarten Lankhorste02f9a02015-08-05 12:37:08 +02002872 WARN(encoder->base.crtc,
Ville Syrjälä034e43c2014-10-16 21:27:28 +03002873 "stealing pipe %c power sequencer from active eDP port %c\n",
2874 pipe_name(pipe), port_name(port));
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002875
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002876 /* make sure vdd is off before we steal it */
Ville Syrjälä83b84592014-10-16 21:29:51 +03002877 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002878 }
2879}
2880
2881static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
2882{
2883 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2884 struct intel_encoder *encoder = &intel_dig_port->base;
2885 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002886 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002887 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002888
2889 lockdep_assert_held(&dev_priv->pps_mutex);
2890
Ville Syrjälä093e3f12014-10-16 21:27:33 +03002891 if (!is_edp(intel_dp))
2892 return;
2893
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002894 if (intel_dp->pps_pipe == crtc->pipe)
2895 return;
2896
2897 /*
2898 * If another power sequencer was being used on this
2899 * port previously make sure to turn off vdd there while
2900 * we still have control of it.
2901 */
2902 if (intel_dp->pps_pipe != INVALID_PIPE)
Ville Syrjälä83b84592014-10-16 21:29:51 +03002903 vlv_detach_power_sequencer(intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002904
2905 /*
2906 * We may be stealing the power
2907 * sequencer from another port.
2908 */
2909 vlv_steal_power_sequencer(dev, crtc->pipe);
2910
2911 /* now it's all ours */
2912 intel_dp->pps_pipe = crtc->pipe;
2913
2914 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
2915 pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
2916
2917 /* init power sequencer on this pipe and port */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03002918 intel_dp_init_panel_power_sequencer(dev, intel_dp);
2919 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03002920}
2921
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002922static void vlv_pre_enable_dp(struct intel_encoder *encoder,
2923 struct intel_crtc_state *pipe_config,
2924 struct drm_connector_state *conn_state)
Jani Nikulaab1f90f2013-07-30 12:20:30 +03002925{
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03002926 vlv_phy_pre_encoder_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002927
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002928 intel_enable_dp(encoder, pipe_config);
Jesse Barnes89b667f2013-04-18 14:51:36 -07002929}
2930
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002931static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
2932 struct intel_crtc_state *pipe_config,
2933 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07002934{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002935 intel_dp_prepare(encoder, pipe_config);
Daniel Vetter8ac33ed2014-04-24 23:54:54 +02002936
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03002937 vlv_phy_pre_pll_enable(encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002938}
2939
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002940static void chv_pre_enable_dp(struct intel_encoder *encoder,
2941 struct intel_crtc_state *pipe_config,
2942 struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002943{
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03002944 chv_phy_pre_encoder_enable(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002945
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002946 intel_enable_dp(encoder, pipe_config);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03002947
2948 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03002949 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002950}
2951
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002952static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
2953 struct intel_crtc_state *pipe_config,
2954 struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03002955{
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002956 intel_dp_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03002957
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03002958 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03002959}
2960
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002961static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
2962 struct intel_crtc_state *pipe_config,
2963 struct drm_connector_state *conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03002964{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03002965 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03002966}
2967
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002968/*
2969 * Fetch AUX CH registers 0x202 - 0x207 which contain
2970 * link status information
2971 */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03002972bool
Keith Packard93f62da2011-11-01 19:45:03 -07002973intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002974{
Lyude9f085eb2016-04-13 10:58:33 -04002975 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
2976 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002977}
2978
Paulo Zanoni11002442014-06-13 18:45:41 -03002979/* These are source-specific values. */
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03002980uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08002981intel_dp_voltage_max(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07002982{
Paulo Zanoni30add222012-10-26 19:05:45 -02002983 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01002984 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deakbc7d38a2013-05-16 14:40:36 +03002985 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08002986
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01002987 if (IS_BROXTON(dev_priv))
Vandana Kannan93147262014-11-18 15:45:29 +05302988 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
2989 else if (INTEL_INFO(dev)->gen >= 9) {
Jani Nikula06411f02016-03-24 17:50:21 +02002990 if (dev_priv->vbt.edp.low_vswing && port == PORT_A)
Sonika Jindal7ad14a22015-02-25 10:29:12 +05302991 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00002992 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002993 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Sonika Jindalbd600182014-08-08 16:23:41 +05302994 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002995 else if (IS_GEN7(dev_priv) && port == PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05302996 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002997 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
Sonika Jindalbd600182014-08-08 16:23:41 +05302998 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Keith Packard1a2eb462011-11-16 16:26:07 -08002999 else
Sonika Jindalbd600182014-08-08 16:23:41 +05303000 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Keith Packard1a2eb462011-11-16 16:26:07 -08003001}
3002
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003003uint8_t
Keith Packard1a2eb462011-11-16 16:26:07 -08003004intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3005{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003006 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
Imre Deakbc7d38a2013-05-16 14:40:36 +03003007 enum port port = dp_to_dig_port(intel_dp)->port;
Keith Packard1a2eb462011-11-16 16:26:07 -08003008
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003009 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003010 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3011 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3012 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3013 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3014 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3015 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3016 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Sonika Jindal7ad14a22015-02-25 10:29:12 +05303017 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3018 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Damien Lespiau5a9d1f12013-12-03 13:56:26 +00003019 default:
3020 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3021 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003022 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003023 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303024 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3025 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3026 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3027 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3028 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3029 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3030 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003031 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303032 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Paulo Zanonid6c0d722012-10-15 15:51:34 -03003033 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003034 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003035 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303036 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3037 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3038 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3039 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3040 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3041 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3042 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003043 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303044 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003045 }
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003046 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Keith Packard1a2eb462011-11-16 16:26:07 -08003047 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303048 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3049 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3050 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3051 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3052 return DP_TRAIN_PRE_EMPH_LEVEL_1;
Keith Packard1a2eb462011-11-16 16:26:07 -08003053 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303054 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003055 }
3056 } else {
3057 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303058 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3059 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3060 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3061 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3062 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3063 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3064 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packard1a2eb462011-11-16 16:26:07 -08003065 default:
Sonika Jindalbd600182014-08-08 16:23:41 +05303066 return DP_TRAIN_PRE_EMPH_LEVEL_0;
Keith Packard1a2eb462011-11-16 16:26:07 -08003067 }
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003068 }
3069}
3070
Daniel Vetter5829975c2015-04-16 11:36:52 +02003071static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003072{
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003073 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003074 unsigned long demph_reg_value, preemph_reg_value,
3075 uniqtranscale_reg_value;
3076 uint8_t train_set = intel_dp->train_set[0];
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003077
3078 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303079 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003080 preemph_reg_value = 0x0004000;
3081 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303082 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003083 demph_reg_value = 0x2B405555;
3084 uniqtranscale_reg_value = 0x552AB83A;
3085 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303086 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003087 demph_reg_value = 0x2B404040;
3088 uniqtranscale_reg_value = 0x5548B83A;
3089 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303090 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003091 demph_reg_value = 0x2B245555;
3092 uniqtranscale_reg_value = 0x5560B83A;
3093 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303094 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003095 demph_reg_value = 0x2B405555;
3096 uniqtranscale_reg_value = 0x5598DA3A;
3097 break;
3098 default:
3099 return 0;
3100 }
3101 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303102 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003103 preemph_reg_value = 0x0002000;
3104 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303105 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003106 demph_reg_value = 0x2B404040;
3107 uniqtranscale_reg_value = 0x5552B83A;
3108 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303109 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003110 demph_reg_value = 0x2B404848;
3111 uniqtranscale_reg_value = 0x5580B83A;
3112 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303113 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003114 demph_reg_value = 0x2B404040;
3115 uniqtranscale_reg_value = 0x55ADDA3A;
3116 break;
3117 default:
3118 return 0;
3119 }
3120 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303121 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003122 preemph_reg_value = 0x0000000;
3123 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303124 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003125 demph_reg_value = 0x2B305555;
3126 uniqtranscale_reg_value = 0x5570B83A;
3127 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303128 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003129 demph_reg_value = 0x2B2B4040;
3130 uniqtranscale_reg_value = 0x55ADDA3A;
3131 break;
3132 default:
3133 return 0;
3134 }
3135 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303136 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003137 preemph_reg_value = 0x0006000;
3138 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303139 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003140 demph_reg_value = 0x1B405555;
3141 uniqtranscale_reg_value = 0x55ADDA3A;
3142 break;
3143 default:
3144 return 0;
3145 }
3146 break;
3147 default:
3148 return 0;
3149 }
3150
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03003151 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3152 uniqtranscale_reg_value, 0);
Pallavi Ge2fa6fb2013-04-18 14:44:28 -07003153
3154 return 0;
3155}
3156
Daniel Vetter5829975c2015-04-16 11:36:52 +02003157static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003158{
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003159 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3160 u32 deemph_reg_value, margin_reg_value;
3161 bool uniq_trans_scale = false;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003162 uint8_t train_set = intel_dp->train_set[0];
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003163
3164 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303165 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003166 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303167 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003168 deemph_reg_value = 128;
3169 margin_reg_value = 52;
3170 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303171 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003172 deemph_reg_value = 128;
3173 margin_reg_value = 77;
3174 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303175 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003176 deemph_reg_value = 128;
3177 margin_reg_value = 102;
3178 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303179 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003180 deemph_reg_value = 128;
3181 margin_reg_value = 154;
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003182 uniq_trans_scale = true;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003183 break;
3184 default:
3185 return 0;
3186 }
3187 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303188 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003189 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303190 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003191 deemph_reg_value = 85;
3192 margin_reg_value = 78;
3193 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303194 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003195 deemph_reg_value = 85;
3196 margin_reg_value = 116;
3197 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303198 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003199 deemph_reg_value = 85;
3200 margin_reg_value = 154;
3201 break;
3202 default:
3203 return 0;
3204 }
3205 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303206 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003207 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303208 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003209 deemph_reg_value = 64;
3210 margin_reg_value = 104;
3211 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303212 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003213 deemph_reg_value = 64;
3214 margin_reg_value = 154;
3215 break;
3216 default:
3217 return 0;
3218 }
3219 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303220 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003221 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303222 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003223 deemph_reg_value = 43;
3224 margin_reg_value = 154;
3225 break;
3226 default:
3227 return 0;
3228 }
3229 break;
3230 default:
3231 return 0;
3232 }
3233
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03003234 chv_set_phy_signal_level(encoder, deemph_reg_value,
3235 margin_reg_value, uniq_trans_scale);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03003236
3237 return 0;
3238}
3239
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003240static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003241gen4_signal_levels(uint8_t train_set)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003242{
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003243 uint32_t signal_levels = 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003244
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003245 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303246 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003247 default:
3248 signal_levels |= DP_VOLTAGE_0_4;
3249 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303250 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003251 signal_levels |= DP_VOLTAGE_0_6;
3252 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303253 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003254 signal_levels |= DP_VOLTAGE_0_8;
3255 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303256 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003257 signal_levels |= DP_VOLTAGE_1_2;
3258 break;
3259 }
Chris Wilson3cf2efb2010-11-29 10:09:55 +00003260 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303261 case DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003262 default:
3263 signal_levels |= DP_PRE_EMPHASIS_0;
3264 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303265 case DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003266 signal_levels |= DP_PRE_EMPHASIS_3_5;
3267 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303268 case DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003269 signal_levels |= DP_PRE_EMPHASIS_6;
3270 break;
Sonika Jindalbd600182014-08-08 16:23:41 +05303271 case DP_TRAIN_PRE_EMPH_LEVEL_3:
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003272 signal_levels |= DP_PRE_EMPHASIS_9_5;
3273 break;
3274 }
3275 return signal_levels;
3276}
3277
Zhenyu Wange3421a12010-04-08 09:43:27 +08003278/* Gen6's DP voltage swing and pre-emphasis control */
3279static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003280gen6_edp_signal_levels(uint8_t train_set)
Zhenyu Wange3421a12010-04-08 09:43:27 +08003281{
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003282 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3283 DP_TRAIN_PRE_EMPHASIS_MASK);
3284 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303285 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3286 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003287 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303288 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003289 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303290 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3291 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003292 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303293 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3294 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003295 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
Sonika Jindalbd600182014-08-08 16:23:41 +05303296 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3297 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003298 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003299 default:
Yuanhan Liu3c5a62b2011-01-06 18:26:08 +08003300 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3301 "0x%x\n", signal_levels);
3302 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003303 }
3304}
3305
Keith Packard1a2eb462011-11-16 16:26:07 -08003306/* Gen7's DP voltage swing and pre-emphasis control */
3307static uint32_t
Daniel Vetter5829975c2015-04-16 11:36:52 +02003308gen7_edp_signal_levels(uint8_t train_set)
Keith Packard1a2eb462011-11-16 16:26:07 -08003309{
3310 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3311 DP_TRAIN_PRE_EMPHASIS_MASK);
3312 switch (signal_levels) {
Sonika Jindalbd600182014-08-08 16:23:41 +05303313 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003314 return EDP_LINK_TRAIN_400MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303315 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003316 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303317 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
Keith Packard1a2eb462011-11-16 16:26:07 -08003318 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3319
Sonika Jindalbd600182014-08-08 16:23:41 +05303320 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003321 return EDP_LINK_TRAIN_600MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303322 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003323 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3324
Sonika Jindalbd600182014-08-08 16:23:41 +05303325 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
Keith Packard1a2eb462011-11-16 16:26:07 -08003326 return EDP_LINK_TRAIN_800MV_0DB_IVB;
Sonika Jindalbd600182014-08-08 16:23:41 +05303327 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
Keith Packard1a2eb462011-11-16 16:26:07 -08003328 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3329
3330 default:
3331 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3332 "0x%x\n", signal_levels);
3333 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3334 }
3335}
3336
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003337void
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003338intel_dp_set_signal_levels(struct intel_dp *intel_dp)
Paulo Zanonif0a34242012-12-06 16:51:50 -02003339{
3340 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003341 enum port port = intel_dig_port->port;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003342 struct drm_device *dev = intel_dig_port->base.base.dev;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003343 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehallf8896f52015-06-25 11:11:03 +03003344 uint32_t signal_levels, mask = 0;
Paulo Zanonif0a34242012-12-06 16:51:50 -02003345 uint8_t train_set = intel_dp->train_set[0];
3346
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003347 if (HAS_DDI(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +03003348 signal_levels = ddi_signal_levels(intel_dp);
3349
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01003350 if (IS_BROXTON(dev_priv))
David Weinehallf8896f52015-06-25 11:11:03 +03003351 signal_levels = 0;
3352 else
3353 mask = DDI_BUF_EMP_MASK;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003354 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003355 signal_levels = chv_signal_levels(intel_dp);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003356 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003357 signal_levels = vlv_signal_levels(intel_dp);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003358 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003359 signal_levels = gen7_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003360 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003361 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003362 signal_levels = gen6_edp_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003363 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3364 } else {
Daniel Vetter5829975c2015-04-16 11:36:52 +02003365 signal_levels = gen4_signal_levels(train_set);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003366 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3367 }
3368
Vandana Kannan96fb9f92014-11-18 15:45:27 +05303369 if (mask)
3370 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3371
3372 DRM_DEBUG_KMS("Using vswing level %d\n",
3373 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3374 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3375 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3376 DP_TRAIN_PRE_EMPHASIS_SHIFT);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003377
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003378 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
Ander Conselvan de Oliveirab905a912015-10-23 13:01:47 +03003379
3380 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3381 POSTING_READ(intel_dp->output_reg);
Paulo Zanonif0a34242012-12-06 16:51:50 -02003382}
3383
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003384void
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003385intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3386 uint8_t dp_train_pat)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003387{
Paulo Zanoni174edf12012-10-26 19:05:50 -02003388 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03003389 struct drm_i915_private *dev_priv =
3390 to_i915(intel_dig_port->base.base.dev);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003391
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003392 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
Paulo Zanoni47ea7542012-07-17 16:55:16 -03003393
Ander Conselvan de Oliveiraf4eb6922015-10-23 13:01:44 +03003394 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003395 POSTING_READ(intel_dp->output_reg);
Ander Conselvan de Oliveirae9c176d2015-10-23 13:01:45 +03003396}
3397
Ander Conselvan de Oliveira94223d02015-10-23 13:01:48 +03003398void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
Imre Deak3ab9c632013-05-03 12:57:41 +03003399{
3400 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3401 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003402 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak3ab9c632013-05-03 12:57:41 +03003403 enum port port = intel_dig_port->port;
3404 uint32_t val;
3405
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003406 if (!HAS_DDI(dev_priv))
Imre Deak3ab9c632013-05-03 12:57:41 +03003407 return;
3408
3409 val = I915_READ(DP_TP_CTL(port));
3410 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3411 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3412 I915_WRITE(DP_TP_CTL(port), val);
3413
3414 /*
3415 * On PORT_A we can have only eDP in SST mode. There the only reason
3416 * we need to set idle transmission mode is to work around a HW issue
3417 * where we enable the pipe while not in idle link-training mode.
3418 * In this case there is requirement to wait for a minimum number of
3419 * idle patterns to be sent.
3420 */
3421 if (port == PORT_A)
3422 return;
3423
Chris Wilsona7670172016-06-30 15:33:10 +01003424 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3425 DP_TP_STATUS_IDLE_DONE,
3426 DP_TP_STATUS_IDLE_DONE,
3427 1))
Imre Deak3ab9c632013-05-03 12:57:41 +03003428 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3429}
3430
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003431static void
Chris Wilsonea5b2132010-08-04 13:50:23 +01003432intel_dp_link_down(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003433{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003434 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003435 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
Imre Deakbc7d38a2013-05-16 14:40:36 +03003436 enum port port = intel_dig_port->port;
Paulo Zanonida63a9f2012-10-26 19:05:46 -02003437 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003438 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonea5b2132010-08-04 13:50:23 +01003439 uint32_t DP = intel_dp->DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003440
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01003441 if (WARN_ON(HAS_DDI(dev_priv)))
Paulo Zanonic19b0662012-10-15 15:51:41 -03003442 return;
3443
Daniel Vetter0c33d8d2012-09-06 22:15:43 +02003444 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
Chris Wilson1b39d6f2010-12-06 11:20:45 +00003445 return;
3446
Zhao Yakui28c97732009-10-09 11:39:41 +08003447 DRM_DEBUG_KMS("\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +08003448
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003449 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003450 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
Zhenyu Wange3421a12010-04-08 09:43:27 +08003451 DP &= ~DP_LINK_TRAIN_MASK_CPT;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003452 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003453 } else {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003454 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläaad3d142014-06-28 02:04:25 +03003455 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3456 else
3457 DP &= ~DP_LINK_TRAIN_MASK;
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003458 DP |= DP_LINK_TRAIN_PAT_IDLE;
Zhenyu Wange3421a12010-04-08 09:43:27 +08003459 }
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003460 I915_WRITE(intel_dp->output_reg, DP);
Chris Wilsonfe255d02010-09-11 21:37:48 +01003461 POSTING_READ(intel_dp->output_reg);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08003462
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003463 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3464 I915_WRITE(intel_dp->output_reg, DP);
3465 POSTING_READ(intel_dp->output_reg);
3466
3467 /*
3468 * HW workaround for IBX, we need to move the port
3469 * to transcoder A after disabling it to allow the
3470 * matching HDMI port to be enabled on transcoder A.
3471 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003472 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003473 /*
3474 * We get CPU/PCH FIFO underruns on the other pipe when
3475 * doing the workaround. Sweep them under the rug.
3476 */
3477 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3478 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3479
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03003480 /* always enable with pattern 1 (as per spec) */
3481 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3482 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3483 I915_WRITE(intel_dp->output_reg, DP);
3484 POSTING_READ(intel_dp->output_reg);
3485
3486 DP &= ~DP_PORT_EN;
Eric Anholt5bddd172010-11-18 09:32:59 +08003487 I915_WRITE(intel_dp->output_reg, DP);
Daniel Vetter0ca09682014-11-24 16:54:11 +01003488 POSTING_READ(intel_dp->output_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003489
Chris Wilson91c8a322016-07-05 10:40:23 +01003490 intel_wait_for_vblank_if_active(&dev_priv->drm, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02003491 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3492 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Eric Anholt5bddd172010-11-18 09:32:59 +08003493 }
3494
Keith Packardf01eca22011-09-28 16:48:10 -07003495 msleep(intel_dp->panel_power_down_delay);
Ville Syrjälä6fec7662015-11-10 16:16:17 +02003496
3497 intel_dp->DP = DP;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07003498}
3499
Imre Deak24e807e2016-10-24 19:33:28 +03003500bool
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003501intel_dp_read_dpcd(struct intel_dp *intel_dp)
Keith Packard92fd8fd2011-07-25 19:50:10 -07003502{
Lyude9f085eb2016-04-13 10:58:33 -04003503 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3504 sizeof(intel_dp->dpcd)) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003505 return false; /* aux transfer failed */
Keith Packard92fd8fd2011-07-25 19:50:10 -07003506
Andy Shevchenkoa8e98152014-09-01 14:12:01 +03003507 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
Damien Lespiau577c7a52012-12-13 16:09:02 +00003508
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003509 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3510}
3511
3512static bool
3513intel_edp_init_dpcd(struct intel_dp *intel_dp)
3514{
3515 struct drm_i915_private *dev_priv =
3516 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3517
3518 /* this function is meant to be called only once */
3519 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3520
3521 if (!intel_dp_read_dpcd(intel_dp))
3522 return false;
3523
Imre Deak12a47a422016-10-24 19:33:29 +03003524 intel_dp_read_desc(intel_dp);
3525
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003526 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3527 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3528 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3529
3530 /* Check if the panel supports PSR */
3531 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3532 intel_dp->psr_dpcd,
3533 sizeof(intel_dp->psr_dpcd));
3534 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3535 dev_priv->psr.sink_support = true;
3536 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3537 }
3538
3539 if (INTEL_GEN(dev_priv) >= 9 &&
3540 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3541 uint8_t frame_sync_cap;
3542
3543 dev_priv->psr.sink_support = true;
3544 drm_dp_dpcd_read(&intel_dp->aux,
3545 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3546 &frame_sync_cap, 1);
3547 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3548 /* PSR2 needs frame sync as well */
3549 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3550 DRM_DEBUG_KMS("PSR2 %s on sink",
3551 dev_priv->psr.psr2_support ? "supported" : "not supported");
3552 }
3553
3554 /* Read the eDP Display control capabilities registers */
3555 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
3556 drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
Dan Carpenterf7170e22016-10-13 11:55:08 +03003557 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3558 sizeof(intel_dp->edp_dpcd))
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03003559 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3560 intel_dp->edp_dpcd);
3561
3562 /* Intermediate frequency support */
3563 if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */
3564 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3565 int i;
3566
3567 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3568 sink_rates, sizeof(sink_rates));
3569
3570 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3571 int val = le16_to_cpu(sink_rates[i]);
3572
3573 if (val == 0)
3574 break;
3575
3576 /* Value read is in kHz while drm clock is saved in deca-kHz */
3577 intel_dp->sink_rates[i] = (val * 200) / 10;
3578 }
3579 intel_dp->num_sink_rates = i;
3580 }
3581
3582 return true;
3583}
3584
3585
3586static bool
3587intel_dp_get_dpcd(struct intel_dp *intel_dp)
3588{
3589 if (!intel_dp_read_dpcd(intel_dp))
3590 return false;
Adam Jacksonedb39242012-09-18 10:58:49 -04003591
Lyude9f085eb2016-04-13 10:58:33 -04003592 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT,
3593 &intel_dp->sink_count, 1) < 0)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303594 return false;
3595
3596 /*
3597 * Sink count can change between short pulse hpd hence
3598 * a member variable in intel_dp will track any changes
3599 * between short pulse interrupts.
3600 */
3601 intel_dp->sink_count = DP_GET_SINK_COUNT(intel_dp->sink_count);
3602
3603 /*
3604 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3605 * a dongle is present but no display. Unless we require to know
3606 * if a dongle is present or not, we don't need to update
3607 * downstream port information. So, an early return here saves
3608 * time from performing other operations which are not required.
3609 */
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05303610 if (!is_edp(intel_dp) && !intel_dp->sink_count)
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05303611 return false;
3612
Imre Deakc726ad02016-10-24 19:33:24 +03003613 if (!drm_dp_is_branch(intel_dp->dpcd))
Adam Jacksonedb39242012-09-18 10:58:49 -04003614 return true; /* native DP sink */
3615
3616 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3617 return true; /* no per-port downstream info */
3618
Lyude9f085eb2016-04-13 10:58:33 -04003619 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3620 intel_dp->downstream_ports,
3621 DP_MAX_DOWNSTREAM_PORTS) < 0)
Adam Jacksonedb39242012-09-18 10:58:49 -04003622 return false; /* downstream port status fetch failed */
3623
3624 return true;
Keith Packard92fd8fd2011-07-25 19:50:10 -07003625}
3626
Dave Airlie0e32b392014-05-02 14:02:48 +10003627static bool
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003628intel_dp_can_mst(struct intel_dp *intel_dp)
Dave Airlie0e32b392014-05-02 14:02:48 +10003629{
3630 u8 buf[1];
3631
Nathan Schulte7cc96132016-03-15 10:14:05 -05003632 if (!i915.enable_dp_mst)
3633 return false;
3634
Dave Airlie0e32b392014-05-02 14:02:48 +10003635 if (!intel_dp->can_mst)
3636 return false;
3637
3638 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3639 return false;
3640
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003641 if (drm_dp_dpcd_read(&intel_dp->aux, DP_MSTM_CAP, buf, 1) != 1)
3642 return false;
Dave Airlie0e32b392014-05-02 14:02:48 +10003643
Ville Syrjäläc4e31702016-07-29 16:51:16 +03003644 return buf[0] & DP_MST_CAP;
3645}
3646
3647static void
3648intel_dp_configure_mst(struct intel_dp *intel_dp)
3649{
3650 if (!i915.enable_dp_mst)
3651 return;
3652
3653 if (!intel_dp->can_mst)
3654 return;
3655
3656 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3657
3658 if (intel_dp->is_mst)
3659 DRM_DEBUG_KMS("Sink is MST capable\n");
3660 else
3661 DRM_DEBUG_KMS("Sink is not MST capable\n");
3662
3663 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3664 intel_dp->is_mst);
Dave Airlie0e32b392014-05-02 14:02:48 +10003665}
3666
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003667static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003668{
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003669 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Rodrigo Vivid72f9d92015-11-05 10:50:19 -08003670 struct drm_device *dev = dig_port->base.base.dev;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003671 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003672 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003673 int ret = 0;
Rodrigo Vivic6297842015-11-05 10:50:20 -08003674 int count = 0;
3675 int attempts = 10;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003676
3677 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003678 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003679 ret = -EIO;
3680 goto out;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003681 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003682
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003683 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003684 buf & ~DP_TEST_SINK_START) < 0) {
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003685 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003686 ret = -EIO;
3687 goto out;
3688 }
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003689
Rodrigo Vivic6297842015-11-05 10:50:20 -08003690 do {
3691 intel_wait_for_vblank(dev, intel_crtc->pipe);
3692
3693 if (drm_dp_dpcd_readb(&intel_dp->aux,
3694 DP_TEST_SINK_MISC, &buf) < 0) {
3695 ret = -EIO;
3696 goto out;
3697 }
3698 count = buf & DP_TEST_COUNT_MASK;
3699 } while (--attempts && count);
3700
3701 if (attempts == 0) {
Rodrigo Vividc5a9032016-01-29 14:44:59 -08003702 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
Rodrigo Vivic6297842015-11-05 10:50:20 -08003703 ret = -ETIMEDOUT;
3704 }
3705
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003706 out:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003707 hsw_enable_ips(intel_crtc);
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003708 return ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003709}
3710
3711static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
3712{
3713 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
Rodrigo Vivid72f9d92015-11-05 10:50:19 -08003714 struct drm_device *dev = dig_port->base.base.dev;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003715 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3716 u8 buf;
Rodrigo Vivie5a1cab2015-07-23 16:35:48 -07003717 int ret;
3718
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003719 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3720 return -EIO;
3721
3722 if (!(buf & DP_TEST_CRC_SUPPORTED))
3723 return -ENOTTY;
3724
3725 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3726 return -EIO;
3727
Rodrigo Vivi6d8175d2015-11-05 10:50:22 -08003728 if (buf & DP_TEST_SINK_START) {
3729 ret = intel_dp_sink_crc_stop(intel_dp);
3730 if (ret)
3731 return ret;
3732 }
3733
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003734 hsw_disable_ips(intel_crtc);
3735
3736 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3737 buf | DP_TEST_SINK_START) < 0) {
3738 hsw_enable_ips(intel_crtc);
3739 return -EIO;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003740 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003741
Rodrigo Vivid72f9d92015-11-05 10:50:19 -08003742 intel_wait_for_vblank(dev, intel_crtc->pipe);
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003743 return 0;
3744}
3745
3746int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
3747{
3748 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
3749 struct drm_device *dev = dig_port->base.base.dev;
3750 struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
3751 u8 buf;
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003752 int count, ret;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003753 int attempts = 6;
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003754
3755 ret = intel_dp_sink_crc_start(intel_dp);
3756 if (ret)
3757 return ret;
3758
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003759 do {
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003760 intel_wait_for_vblank(dev, intel_crtc->pipe);
3761
Rodrigo Vivi1dda5f92014-10-01 07:32:37 -07003762 if (drm_dp_dpcd_readb(&intel_dp->aux,
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003763 DP_TEST_SINK_MISC, &buf) < 0) {
3764 ret = -EIO;
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003765 goto stop;
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003766 }
Rodrigo Vivi621d4c72015-07-23 16:35:49 -07003767 count = buf & DP_TEST_COUNT_MASK;
Rodrigo Viviaabc95d2015-07-23 16:35:50 -07003768
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003769 } while (--attempts && count == 0);
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003770
3771 if (attempts == 0) {
Rodrigo Vivi7e38eef2015-11-05 10:50:21 -08003772 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
3773 ret = -ETIMEDOUT;
3774 goto stop;
3775 }
3776
3777 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
3778 ret = -EIO;
3779 goto stop;
Rodrigo Viviad9dc912014-09-16 19:18:12 -04003780 }
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003781
Rodrigo Viviafe0d672015-07-23 16:35:45 -07003782stop:
Rodrigo Vivi082dcc72015-07-30 16:26:39 -07003783 intel_dp_sink_crc_stop(intel_dp);
Paulo Zanoni4373f0f2015-05-25 18:52:29 -03003784 return ret;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003785}
3786
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003787static bool
3788intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3789{
Lyude9f085eb2016-04-13 10:58:33 -04003790 return drm_dp_dpcd_read(&intel_dp->aux,
Jani Nikula9d1a1032014-03-14 16:51:15 +02003791 DP_DEVICE_SERVICE_IRQ_VECTOR,
3792 sink_irq_vector, 1) == 1;
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003793}
3794
Dave Airlie0e32b392014-05-02 14:02:48 +10003795static bool
3796intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3797{
3798 int ret;
3799
Lyude9f085eb2016-04-13 10:58:33 -04003800 ret = drm_dp_dpcd_read(&intel_dp->aux,
Dave Airlie0e32b392014-05-02 14:02:48 +10003801 DP_SINK_COUNT_ESI,
3802 sink_irq_vector, 14);
3803 if (ret != 14)
3804 return false;
3805
3806 return true;
3807}
3808
Todd Previtec5d5ab72015-04-15 08:38:38 -07003809static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003810{
Todd Previtec5d5ab72015-04-15 08:38:38 -07003811 uint8_t test_result = DP_TEST_ACK;
3812 return test_result;
3813}
3814
3815static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
3816{
3817 uint8_t test_result = DP_TEST_NAK;
3818 return test_result;
3819}
3820
3821static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
3822{
3823 uint8_t test_result = DP_TEST_NAK;
Todd Previte559be302015-05-04 07:48:20 -07003824 struct intel_connector *intel_connector = intel_dp->attached_connector;
3825 struct drm_connector *connector = &intel_connector->base;
3826
3827 if (intel_connector->detect_edid == NULL ||
Daniel Vetterac6f2e22015-05-08 16:15:41 +02003828 connector->edid_corrupt ||
Todd Previte559be302015-05-04 07:48:20 -07003829 intel_dp->aux.i2c_defer_count > 6) {
3830 /* Check EDID read for NACKs, DEFERs and corruption
3831 * (DP CTS 1.2 Core r1.1)
3832 * 4.2.2.4 : Failed EDID read, I2C_NAK
3833 * 4.2.2.5 : Failed EDID read, I2C_DEFER
3834 * 4.2.2.6 : EDID corruption detected
3835 * Use failsafe mode for all cases
3836 */
3837 if (intel_dp->aux.i2c_nack_count > 0 ||
3838 intel_dp->aux.i2c_defer_count > 0)
3839 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
3840 intel_dp->aux.i2c_nack_count,
3841 intel_dp->aux.i2c_defer_count);
3842 intel_dp->compliance_test_data = INTEL_DP_RESOLUTION_FAILSAFE;
3843 } else {
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05303844 struct edid *block = intel_connector->detect_edid;
3845
3846 /* We have to write the checksum
3847 * of the last block read
3848 */
3849 block += intel_connector->detect_edid->extensions;
3850
Todd Previte559be302015-05-04 07:48:20 -07003851 if (!drm_dp_dpcd_write(&intel_dp->aux,
3852 DP_TEST_EDID_CHECKSUM,
Thulasimani,Sivakumarf79b468e2015-08-07 15:14:30 +05303853 &block->checksum,
Dan Carpenter5a1cc652015-05-12 21:07:37 +03003854 1))
Todd Previte559be302015-05-04 07:48:20 -07003855 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
3856
3857 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
3858 intel_dp->compliance_test_data = INTEL_DP_RESOLUTION_STANDARD;
3859 }
3860
3861 /* Set test active flag here so userspace doesn't interrupt things */
3862 intel_dp->compliance_test_active = 1;
3863
Todd Previtec5d5ab72015-04-15 08:38:38 -07003864 return test_result;
3865}
3866
3867static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
3868{
3869 uint8_t test_result = DP_TEST_NAK;
3870 return test_result;
3871}
3872
3873static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
3874{
3875 uint8_t response = DP_TEST_NAK;
3876 uint8_t rxdata = 0;
3877 int status = 0;
3878
Todd Previtec5d5ab72015-04-15 08:38:38 -07003879 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_REQUEST, &rxdata, 1);
3880 if (status <= 0) {
3881 DRM_DEBUG_KMS("Could not read test request from sink\n");
3882 goto update_status;
3883 }
3884
3885 switch (rxdata) {
3886 case DP_TEST_LINK_TRAINING:
3887 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
3888 intel_dp->compliance_test_type = DP_TEST_LINK_TRAINING;
3889 response = intel_dp_autotest_link_training(intel_dp);
3890 break;
3891 case DP_TEST_LINK_VIDEO_PATTERN:
3892 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
3893 intel_dp->compliance_test_type = DP_TEST_LINK_VIDEO_PATTERN;
3894 response = intel_dp_autotest_video_pattern(intel_dp);
3895 break;
3896 case DP_TEST_LINK_EDID_READ:
3897 DRM_DEBUG_KMS("EDID test requested\n");
3898 intel_dp->compliance_test_type = DP_TEST_LINK_EDID_READ;
3899 response = intel_dp_autotest_edid(intel_dp);
3900 break;
3901 case DP_TEST_LINK_PHY_TEST_PATTERN:
3902 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
3903 intel_dp->compliance_test_type = DP_TEST_LINK_PHY_TEST_PATTERN;
3904 response = intel_dp_autotest_phy_pattern(intel_dp);
3905 break;
3906 default:
3907 DRM_DEBUG_KMS("Invalid test request '%02x'\n", rxdata);
3908 break;
3909 }
3910
3911update_status:
3912 status = drm_dp_dpcd_write(&intel_dp->aux,
3913 DP_TEST_RESPONSE,
3914 &response, 1);
3915 if (status <= 0)
3916 DRM_DEBUG_KMS("Could not write test response to sink\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07003917}
3918
Dave Airlie0e32b392014-05-02 14:02:48 +10003919static int
3920intel_dp_check_mst_status(struct intel_dp *intel_dp)
3921{
3922 bool bret;
3923
3924 if (intel_dp->is_mst) {
3925 u8 esi[16] = { 0 };
3926 int ret = 0;
3927 int retry;
3928 bool handled;
3929 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
3930go_again:
3931 if (bret == true) {
3932
3933 /* check link status - esi[10] = 0x200c */
Ville Syrjälä19e0b4c2016-08-05 19:05:42 +03003934 if (intel_dp->active_mst_links &&
Ville Syrjälä901c2da2015-08-17 18:05:12 +03003935 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10003936 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
3937 intel_dp_start_link_train(intel_dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10003938 intel_dp_stop_link_train(intel_dp);
3939 }
3940
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02003941 DRM_DEBUG_KMS("got esi %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10003942 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
3943
3944 if (handled) {
3945 for (retry = 0; retry < 3; retry++) {
3946 int wret;
3947 wret = drm_dp_dpcd_write(&intel_dp->aux,
3948 DP_SINK_COUNT_ESI+1,
3949 &esi[1], 3);
3950 if (wret == 3) {
3951 break;
3952 }
3953 }
3954
3955 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
3956 if (bret == true) {
Andy Shevchenko6f34cc32015-01-15 13:45:09 +02003957 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
Dave Airlie0e32b392014-05-02 14:02:48 +10003958 goto go_again;
3959 }
3960 } else
3961 ret = 0;
3962
3963 return ret;
3964 } else {
3965 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3966 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
3967 intel_dp->is_mst = false;
3968 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
3969 /* send a hotplug event */
3970 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
3971 }
3972 }
3973 return -EINVAL;
3974}
3975
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05303976static void
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03003977intel_dp_retrain_link(struct intel_dp *intel_dp)
3978{
3979 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3980 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3981 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
3982
3983 /* Suppress underruns caused by re-training */
3984 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
3985 if (crtc->config->has_pch_encoder)
3986 intel_set_pch_fifo_underrun_reporting(dev_priv,
3987 intel_crtc_pch_transcoder(crtc), false);
3988
3989 intel_dp_start_link_train(intel_dp);
3990 intel_dp_stop_link_train(intel_dp);
3991
3992 /* Keep underrun reporting disabled until things are stable */
3993 intel_wait_for_vblank(&dev_priv->drm, crtc->pipe);
3994
3995 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
3996 if (crtc->config->has_pch_encoder)
3997 intel_set_pch_fifo_underrun_reporting(dev_priv,
3998 intel_crtc_pch_transcoder(crtc), true);
3999}
4000
4001static void
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304002intel_dp_check_link_status(struct intel_dp *intel_dp)
4003{
4004 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4005 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4006 u8 link_status[DP_LINK_STATUS_SIZE];
4007
4008 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
4009
4010 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4011 DRM_ERROR("Failed to get link status\n");
4012 return;
4013 }
4014
4015 if (!intel_encoder->base.crtc)
4016 return;
4017
4018 if (!to_intel_crtc(intel_encoder->base.crtc)->active)
4019 return;
4020
Matthew Auldd4cb3fd2016-10-19 22:29:53 +01004021 /* FIXME: we need to synchronize this sort of stuff with hardware
4022 * readout */
4023 if (WARN_ON_ONCE(!intel_dp->lane_count))
4024 return;
4025
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304026 /* if link training is requested we should perform it always */
4027 if ((intel_dp->compliance_test_type == DP_TEST_LINK_TRAINING) ||
4028 (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count))) {
4029 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4030 intel_encoder->base.name);
Ville Syrjäläbfd02b32016-10-14 20:02:54 +03004031
4032 intel_dp_retrain_link(intel_dp);
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304033 }
4034}
4035
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004036/*
4037 * According to DP spec
4038 * 5.1.2:
4039 * 1. Read DPCD
4040 * 2. Configure link according to Receiver Capabilities
4041 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4042 * 4. Check link status on receipt of hot-plug interrupt
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304043 *
4044 * intel_dp_short_pulse - handles short pulse interrupts
4045 * when full detection is not required.
4046 * Returns %true if short pulse is handled and full detection
4047 * is NOT required and %false otherwise.
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004048 */
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304049static bool
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304050intel_dp_short_pulse(struct intel_dp *intel_dp)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004051{
Dave Airlie5b215bc2014-08-05 10:40:20 +10004052 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004053 u8 sink_irq_vector = 0;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304054 u8 old_sink_count = intel_dp->sink_count;
4055 bool ret;
Dave Airlie5b215bc2014-08-05 10:40:20 +10004056
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304057 /*
4058 * Clearing compliance test variables to allow capturing
4059 * of values for next automated test request.
4060 */
4061 intel_dp->compliance_test_active = 0;
4062 intel_dp->compliance_test_type = 0;
4063 intel_dp->compliance_test_data = 0;
4064
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304065 /*
4066 * Now read the DPCD to see if it's actually running
4067 * If the current value of sink count doesn't match with
4068 * the value that was stored earlier or dpcd read failed
4069 * we need to do full detection
4070 */
4071 ret = intel_dp_get_dpcd(intel_dp);
4072
4073 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4074 /* No need to proceed if we are going to do full detect */
4075 return false;
Jesse Barnes59cd09e2011-07-07 11:10:59 -07004076 }
4077
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004078 /* Try to read the source of the interrupt */
4079 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004080 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4081 sink_irq_vector != 0) {
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004082 /* Clear interrupt source */
Jani Nikula9d1a1032014-03-14 16:51:15 +02004083 drm_dp_dpcd_writeb(&intel_dp->aux,
4084 DP_DEVICE_SERVICE_IRQ_VECTOR,
4085 sink_irq_vector);
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004086
4087 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
Todd Previte09b1eb12015-04-20 15:27:34 -07004088 DRM_DEBUG_DRIVER("Test request in short pulse not handled\n");
Jesse Barnesa60f0e32011-10-20 15:09:17 -07004089 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4090 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4091 }
4092
Shubhangi Shrivastava5c9114d2016-03-30 18:05:24 +05304093 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4094 intel_dp_check_link_status(intel_dp);
4095 drm_modeset_unlock(&dev->mode_config.connection_mutex);
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304096
4097 return true;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004098}
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004099
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004100/* XXX this is probably wrong for multiple downstream ports */
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004101static enum drm_connector_status
Keith Packard26d61aa2011-07-25 20:01:09 -07004102intel_dp_detect_dpcd(struct intel_dp *intel_dp)
Adam Jackson71ba90002011-07-12 17:38:04 -04004103{
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004104 uint8_t *dpcd = intel_dp->dpcd;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004105 uint8_t type;
4106
4107 if (!intel_dp_get_dpcd(intel_dp))
4108 return connector_status_disconnected;
4109
Shubhangi Shrivastava1034ce72016-04-12 12:23:54 +05304110 if (is_edp(intel_dp))
4111 return connector_status_connected;
4112
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004113 /* if there's no downstream port, we're done */
Imre Deakc726ad02016-10-24 19:33:24 +03004114 if (!drm_dp_is_branch(dpcd))
Keith Packard26d61aa2011-07-25 20:01:09 -07004115 return connector_status_connected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004116
4117 /* If we're HPD-aware, SINK_COUNT changes dynamically */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004118 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4119 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
Jani Nikula9d1a1032014-03-14 16:51:15 +02004120
Shubhangi Shrivastava30d9aa42016-03-30 18:05:25 +05304121 return intel_dp->sink_count ?
4122 connector_status_connected : connector_status_disconnected;
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004123 }
4124
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004125 if (intel_dp_can_mst(intel_dp))
4126 return connector_status_connected;
4127
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004128 /* If no HPD, poke DDC gently */
Jani Nikula0b998362014-03-14 16:51:17 +02004129 if (drm_probe_ddc(&intel_dp->aux.ddc))
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004130 return connector_status_connected;
4131
4132 /* Well we tried, say unknown for unreliable port types */
Jani Nikulac9ff1602013-09-27 14:48:42 +03004133 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4134 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4135 if (type == DP_DS_PORT_TYPE_VGA ||
4136 type == DP_DS_PORT_TYPE_NON_EDID)
4137 return connector_status_unknown;
4138 } else {
4139 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4140 DP_DWN_STRM_PORT_TYPE_MASK;
4141 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4142 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4143 return connector_status_unknown;
4144 }
Adam Jacksoncaf9ab22012-09-18 10:58:50 -04004145
4146 /* Anything else is out of spec, warn and ignore */
4147 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
Keith Packard26d61aa2011-07-25 20:01:09 -07004148 return connector_status_disconnected;
Adam Jackson71ba90002011-07-12 17:38:04 -04004149}
4150
4151static enum drm_connector_status
Chris Wilsond410b562014-09-02 20:03:59 +01004152edp_detect(struct intel_dp *intel_dp)
4153{
4154 struct drm_device *dev = intel_dp_to_dev(intel_dp);
4155 enum drm_connector_status status;
4156
4157 status = intel_panel_detect(dev);
4158 if (status == connector_status_unknown)
4159 status = connector_status_connected;
4160
4161 return status;
4162}
4163
Jani Nikulab93433c2015-08-20 10:47:36 +03004164static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4165 struct intel_digital_port *port)
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004166{
Jani Nikulab93433c2015-08-20 10:47:36 +03004167 u32 bit;
Jesse Barnes01cb9ea2010-10-07 16:01:12 -07004168
Jani Nikula0df53b72015-08-20 10:47:40 +03004169 switch (port->port) {
4170 case PORT_A:
4171 return true;
4172 case PORT_B:
4173 bit = SDE_PORTB_HOTPLUG;
4174 break;
4175 case PORT_C:
4176 bit = SDE_PORTC_HOTPLUG;
4177 break;
4178 case PORT_D:
4179 bit = SDE_PORTD_HOTPLUG;
4180 break;
4181 default:
4182 MISSING_CASE(port->port);
4183 return false;
4184 }
4185
4186 return I915_READ(SDEISR) & bit;
4187}
4188
4189static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4190 struct intel_digital_port *port)
4191{
4192 u32 bit;
4193
4194 switch (port->port) {
4195 case PORT_A:
4196 return true;
4197 case PORT_B:
4198 bit = SDE_PORTB_HOTPLUG_CPT;
4199 break;
4200 case PORT_C:
4201 bit = SDE_PORTC_HOTPLUG_CPT;
4202 break;
4203 case PORT_D:
4204 bit = SDE_PORTD_HOTPLUG_CPT;
4205 break;
Jani Nikulaa78695d2015-09-18 15:54:50 +03004206 case PORT_E:
4207 bit = SDE_PORTE_HOTPLUG_SPT;
4208 break;
Jani Nikula0df53b72015-08-20 10:47:40 +03004209 default:
4210 MISSING_CASE(port->port);
4211 return false;
Jani Nikulab93433c2015-08-20 10:47:36 +03004212 }
Damien Lespiau1b469632012-12-13 16:09:01 +00004213
Jani Nikulab93433c2015-08-20 10:47:36 +03004214 return I915_READ(SDEISR) & bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004215}
4216
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004217static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula1d245982015-08-20 10:47:37 +03004218 struct intel_digital_port *port)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004219{
Jani Nikula9642c812015-08-20 10:47:41 +03004220 u32 bit;
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08004221
Jani Nikula9642c812015-08-20 10:47:41 +03004222 switch (port->port) {
4223 case PORT_B:
4224 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4225 break;
4226 case PORT_C:
4227 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4228 break;
4229 case PORT_D:
4230 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4231 break;
4232 default:
4233 MISSING_CASE(port->port);
4234 return false;
4235 }
4236
4237 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4238}
4239
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004240static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4241 struct intel_digital_port *port)
Jani Nikula9642c812015-08-20 10:47:41 +03004242{
4243 u32 bit;
4244
4245 switch (port->port) {
4246 case PORT_B:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004247 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004248 break;
4249 case PORT_C:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004250 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004251 break;
4252 case PORT_D:
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004253 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
Jani Nikula9642c812015-08-20 10:47:41 +03004254 break;
4255 default:
4256 MISSING_CASE(port->port);
4257 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004258 }
4259
Jani Nikula1d245982015-08-20 10:47:37 +03004260 return I915_READ(PORT_HOTPLUG_STAT) & bit;
Dave Airlie2a592be2014-09-01 16:58:12 +10004261}
4262
Jani Nikulae464bfd2015-08-20 10:47:42 +03004263static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304264 struct intel_digital_port *intel_dig_port)
Jani Nikulae464bfd2015-08-20 10:47:42 +03004265{
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304266 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4267 enum port port;
Jani Nikulae464bfd2015-08-20 10:47:42 +03004268 u32 bit;
4269
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304270 intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port);
4271 switch (port) {
Jani Nikulae464bfd2015-08-20 10:47:42 +03004272 case PORT_A:
4273 bit = BXT_DE_PORT_HP_DDIA;
4274 break;
4275 case PORT_B:
4276 bit = BXT_DE_PORT_HP_DDIB;
4277 break;
4278 case PORT_C:
4279 bit = BXT_DE_PORT_HP_DDIC;
4280 break;
4281 default:
Sonika Jindale2ec35a2015-09-11 16:58:32 +05304282 MISSING_CASE(port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004283 return false;
4284 }
4285
4286 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4287}
4288
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004289/*
4290 * intel_digital_port_connected - is the specified port connected?
4291 * @dev_priv: i915 private structure
4292 * @port: the port to test
4293 *
4294 * Return %true if @port is connected, %false otherwise.
4295 */
David Weinehall23f889b2016-08-17 15:47:48 +03004296static bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004297 struct intel_digital_port *port)
4298{
Jani Nikula0df53b72015-08-20 10:47:40 +03004299 if (HAS_PCH_IBX(dev_priv))
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004300 return ibx_digital_port_connected(dev_priv, port);
Ville Syrjälä22824fa2016-02-11 16:44:28 +02004301 else if (HAS_PCH_SPLIT(dev_priv))
Jani Nikula0df53b72015-08-20 10:47:40 +03004302 return cpt_digital_port_connected(dev_priv, port);
Jani Nikulae464bfd2015-08-20 10:47:42 +03004303 else if (IS_BROXTON(dev_priv))
4304 return bxt_digital_port_connected(dev_priv, port);
Ville Syrjälä0780cd32016-02-10 19:59:05 +02004305 else if (IS_GM45(dev_priv))
4306 return gm45_digital_port_connected(dev_priv, port);
Jani Nikula7e66bcf2015-08-20 10:47:39 +03004307 else
4308 return g4x_digital_port_connected(dev_priv, port);
4309}
4310
Keith Packard8c241fe2011-09-28 16:38:44 -07004311static struct edid *
Chris Wilsonbeb60602014-09-02 20:04:00 +01004312intel_dp_get_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004313{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004314 struct intel_connector *intel_connector = intel_dp->attached_connector;
Keith Packard8c241fe2011-09-28 16:38:44 -07004315
Jani Nikula9cd300e2012-10-19 14:51:52 +03004316 /* use cached edid if we have one */
4317 if (intel_connector->edid) {
Jani Nikula9cd300e2012-10-19 14:51:52 +03004318 /* invalid edid */
4319 if (IS_ERR(intel_connector->edid))
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004320 return NULL;
4321
Jani Nikula55e9ede2013-10-01 10:38:54 +03004322 return drm_edid_duplicate(intel_connector->edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004323 } else
4324 return drm_get_edid(&intel_connector->base,
4325 &intel_dp->aux.ddc);
Keith Packard8c241fe2011-09-28 16:38:44 -07004326}
4327
Chris Wilsonbeb60602014-09-02 20:04:00 +01004328static void
4329intel_dp_set_edid(struct intel_dp *intel_dp)
Keith Packard8c241fe2011-09-28 16:38:44 -07004330{
Chris Wilsonbeb60602014-09-02 20:04:00 +01004331 struct intel_connector *intel_connector = intel_dp->attached_connector;
4332 struct edid *edid;
Keith Packard8c241fe2011-09-28 16:38:44 -07004333
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304334 intel_dp_unset_edid(intel_dp);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004335 edid = intel_dp_get_edid(intel_dp);
4336 intel_connector->detect_edid = edid;
Jani Nikula9cd300e2012-10-19 14:51:52 +03004337
Chris Wilsonbeb60602014-09-02 20:04:00 +01004338 if (intel_dp->force_audio != HDMI_AUDIO_AUTO)
4339 intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON;
4340 else
4341 intel_dp->has_audio = drm_detect_monitor_audio(edid);
4342}
Jesse Barnesd6f24d02012-06-14 15:28:33 -04004343
Chris Wilsonbeb60602014-09-02 20:04:00 +01004344static void
4345intel_dp_unset_edid(struct intel_dp *intel_dp)
4346{
4347 struct intel_connector *intel_connector = intel_dp->attached_connector;
4348
4349 kfree(intel_connector->detect_edid);
4350 intel_connector->detect_edid = NULL;
4351
4352 intel_dp->has_audio = false;
4353}
4354
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004355static enum drm_connector_status
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304356intel_dp_long_pulse(struct intel_connector *intel_connector)
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004357{
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304358 struct drm_connector *connector = &intel_connector->base;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004359 struct intel_dp *intel_dp = intel_attached_dp(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -02004360 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4361 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Paulo Zanonifa90ece2012-10-26 19:05:44 -02004362 struct drm_device *dev = connector->dev;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004363 enum drm_connector_status status;
Imre Deak671dedd2014-03-05 16:20:53 +02004364 enum intel_display_power_domain power_domain;
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004365 u8 sink_irq_vector = 0;
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004366
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004367 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4368 intel_display_power_get(to_i915(dev), power_domain);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004369
Chris Wilsond410b562014-09-02 20:03:59 +01004370 /* Can't disconnect eDP, but you can close the lid... */
4371 if (is_edp(intel_dp))
4372 status = edp_detect(intel_dp);
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004373 else if (intel_digital_port_connected(to_i915(dev),
4374 dp_to_dig_port(intel_dp)))
4375 status = intel_dp_detect_dpcd(intel_dp);
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004376 else
Ander Conselvan de Oliveirac555a812015-11-18 17:19:30 +02004377 status = connector_status_disconnected;
4378
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004379 if (status == connector_status_disconnected) {
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304380 intel_dp->compliance_test_active = 0;
4381 intel_dp->compliance_test_type = 0;
4382 intel_dp->compliance_test_data = 0;
4383
jim.bride@linux.intel.com0e505a02016-04-11 10:11:24 -07004384 if (intel_dp->is_mst) {
4385 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4386 intel_dp->is_mst,
4387 intel_dp->mst_mgr.mst_state);
4388 intel_dp->is_mst = false;
4389 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4390 intel_dp->is_mst);
4391 }
4392
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004393 goto out;
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304394 }
Zhenyu Wanga9756bb2010-09-19 13:09:06 +08004395
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304396 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004397 intel_encoder->type = INTEL_OUTPUT_DP;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304398
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03004399 DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
4400 yesno(intel_dp_source_supports_hbr2(intel_dp)),
4401 yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
4402
4403 intel_dp_print_rates(intel_dp);
4404
Imre Deak7b3fc172016-10-25 16:12:39 +03004405 intel_dp_read_desc(intel_dp);
Mika Kahola0e390a32016-09-09 14:10:53 +03004406
Ville Syrjäläc4e31702016-07-29 16:51:16 +03004407 intel_dp_configure_mst(intel_dp);
4408
4409 if (intel_dp->is_mst) {
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304410 /*
4411 * If we are in MST mode then this connector
4412 * won't appear connected or have anything
4413 * with EDID on it
4414 */
Dave Airlie0e32b392014-05-02 14:02:48 +10004415 status = connector_status_disconnected;
4416 goto out;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304417 } else if (connector->status == connector_status_connected) {
4418 /*
4419 * If display was connected already and is still connected
4420 * check links status, there has been known issues of
4421 * link loss triggerring long pulse!!!!
4422 */
4423 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4424 intel_dp_check_link_status(intel_dp);
4425 drm_modeset_unlock(&dev->mode_config.connection_mutex);
4426 goto out;
Dave Airlie0e32b392014-05-02 14:02:48 +10004427 }
4428
Shubhangi Shrivastava4df69602015-10-28 15:30:36 +05304429 /*
4430 * Clearing NACK and defer counts to get their exact values
4431 * while reading EDID which are required by Compliance tests
4432 * 4.2.2.4 and 4.2.2.5
4433 */
4434 intel_dp->aux.i2c_nack_count = 0;
4435 intel_dp->aux.i2c_defer_count = 0;
4436
Chris Wilsonbeb60602014-09-02 20:04:00 +01004437 intel_dp_set_edid(intel_dp);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004438 if (is_edp(intel_dp) || intel_connector->detect_edid)
4439 status = connector_status_connected;
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304440 intel_dp->detect_done = true;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004441
Todd Previte09b1eb12015-04-20 15:27:34 -07004442 /* Try to read the source of the interrupt */
4443 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
Ville Syrjälä65fbb4e2016-07-28 17:50:47 +03004444 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4445 sink_irq_vector != 0) {
Todd Previte09b1eb12015-04-20 15:27:34 -07004446 /* Clear interrupt source */
4447 drm_dp_dpcd_writeb(&intel_dp->aux,
4448 DP_DEVICE_SERVICE_IRQ_VECTOR,
4449 sink_irq_vector);
4450
4451 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4452 intel_dp_handle_test_request(intel_dp);
4453 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4454 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4455 }
4456
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004457out:
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004458 if (status != connector_status_connected && !intel_dp->is_mst)
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304459 intel_dp_unset_edid(intel_dp);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304460
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004461 intel_display_power_put(to_i915(dev), power_domain);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004462 return status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304463}
4464
4465static enum drm_connector_status
4466intel_dp_detect(struct drm_connector *connector, bool force)
4467{
4468 struct intel_dp *intel_dp = intel_attached_dp(connector);
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004469 enum drm_connector_status status = connector->status;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304470
4471 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4472 connector->base.id, connector->name);
4473
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304474 /* If full detect is not performed yet, do a full detect */
4475 if (!intel_dp->detect_done)
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004476 status = intel_dp_long_pulse(intel_dp->attached_connector);
Shubhangi Shrivastava7d23e3c2016-03-30 18:05:23 +05304477
4478 intel_dp->detect_done = false;
Shubhangi Shrivastavaf21a2192016-03-30 18:05:22 +05304479
Ville Syrjälä5cb651a2016-10-03 10:55:16 +03004480 return status;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004481}
4482
Chris Wilsonbeb60602014-09-02 20:04:00 +01004483static void
4484intel_dp_force(struct drm_connector *connector)
4485{
4486 struct intel_dp *intel_dp = intel_attached_dp(connector);
4487 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004488 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004489 enum intel_display_power_domain power_domain;
4490
4491 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4492 connector->base.id, connector->name);
4493 intel_dp_unset_edid(intel_dp);
4494
4495 if (connector->status != connector_status_connected)
4496 return;
4497
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004498 power_domain = intel_display_port_aux_power_domain(intel_encoder);
4499 intel_display_power_get(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004500
4501 intel_dp_set_edid(intel_dp);
4502
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004503 intel_display_power_put(dev_priv, power_domain);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004504
4505 if (intel_encoder->type != INTEL_OUTPUT_EDP)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004506 intel_encoder->type = INTEL_OUTPUT_DP;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004507}
4508
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004509static int intel_dp_get_modes(struct drm_connector *connector)
4510{
Jani Nikuladd06f902012-10-19 14:51:50 +03004511 struct intel_connector *intel_connector = to_intel_connector(connector);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004512 struct edid *edid;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004513
Chris Wilsonbeb60602014-09-02 20:04:00 +01004514 edid = intel_connector->detect_edid;
4515 if (edid) {
4516 int ret = intel_connector_update_modes(connector, edid);
4517 if (ret)
4518 return ret;
4519 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004520
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004521 /* if eDP has no EDID, fall back to fixed mode */
Chris Wilsonbeb60602014-09-02 20:04:00 +01004522 if (is_edp(intel_attached_dp(connector)) &&
4523 intel_connector->panel.fixed_mode) {
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004524 struct drm_display_mode *mode;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004525
4526 mode = drm_mode_duplicate(connector->dev,
Jani Nikuladd06f902012-10-19 14:51:50 +03004527 intel_connector->panel.fixed_mode);
Jani Nikulaf8779fd2012-10-19 14:51:48 +03004528 if (mode) {
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004529 drm_mode_probed_add(connector, mode);
4530 return 1;
4531 }
4532 }
Chris Wilsonbeb60602014-09-02 20:04:00 +01004533
Zhenyu Wang32f9d652009-07-24 01:00:32 +08004534 return 0;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004535}
4536
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004537static bool
4538intel_dp_detect_audio(struct drm_connector *connector)
4539{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004540 bool has_audio = false;
Chris Wilsonbeb60602014-09-02 20:04:00 +01004541 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004542
Chris Wilsonbeb60602014-09-02 20:04:00 +01004543 edid = to_intel_connector(connector)->detect_edid;
4544 if (edid)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004545 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02004546
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004547 return has_audio;
4548}
4549
Chris Wilsonf6849602010-09-19 09:29:33 +01004550static int
4551intel_dp_set_property(struct drm_connector *connector,
4552 struct drm_property *property,
4553 uint64_t val)
4554{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004555 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Yuly Novikov53b41832012-10-26 12:04:00 +03004556 struct intel_connector *intel_connector = to_intel_connector(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004557 struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
4558 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
Chris Wilsonf6849602010-09-19 09:29:33 +01004559 int ret;
4560
Rob Clark662595d2012-10-11 20:36:04 -05004561 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilsonf6849602010-09-19 09:29:33 +01004562 if (ret)
4563 return ret;
4564
Chris Wilson3f43c482011-05-12 22:17:24 +01004565 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004566 int i = val;
4567 bool has_audio;
4568
4569 if (i == intel_dp->force_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004570 return 0;
4571
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004572 intel_dp->force_audio = i;
Chris Wilsonf6849602010-09-19 09:29:33 +01004573
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004574 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004575 has_audio = intel_dp_detect_audio(connector);
4576 else
Daniel Vetterc3e5f672012-02-23 17:14:47 +01004577 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004578
4579 if (has_audio == intel_dp->has_audio)
Chris Wilsonf6849602010-09-19 09:29:33 +01004580 return 0;
4581
Chris Wilson1aad7ac2011-02-09 18:46:58 +00004582 intel_dp->has_audio = has_audio;
Chris Wilsonf6849602010-09-19 09:29:33 +01004583 goto done;
4584 }
4585
Chris Wilsone953fd72011-02-21 22:23:52 +00004586 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02004587 bool old_auto = intel_dp->color_range_auto;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004588 bool old_range = intel_dp->limited_color_range;
Daniel Vetterae4edb82013-04-22 17:07:23 +02004589
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004590 switch (val) {
4591 case INTEL_BROADCAST_RGB_AUTO:
4592 intel_dp->color_range_auto = true;
4593 break;
4594 case INTEL_BROADCAST_RGB_FULL:
4595 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004596 intel_dp->limited_color_range = false;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004597 break;
4598 case INTEL_BROADCAST_RGB_LIMITED:
4599 intel_dp->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004600 intel_dp->limited_color_range = true;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004601 break;
4602 default:
4603 return -EINVAL;
4604 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02004605
4606 if (old_auto == intel_dp->color_range_auto &&
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03004607 old_range == intel_dp->limited_color_range)
Daniel Vetterae4edb82013-04-22 17:07:23 +02004608 return 0;
4609
Chris Wilsone953fd72011-02-21 22:23:52 +00004610 goto done;
4611 }
4612
Yuly Novikov53b41832012-10-26 12:04:00 +03004613 if (is_edp(intel_dp) &&
4614 property == connector->dev->mode_config.scaling_mode_property) {
4615 if (val == DRM_MODE_SCALE_NONE) {
4616 DRM_DEBUG_KMS("no scaling not supported\n");
4617 return -EINVAL;
4618 }
Ville Syrjälä234126c2016-04-12 22:14:38 +03004619 if (HAS_GMCH_DISPLAY(dev_priv) &&
4620 val == DRM_MODE_SCALE_CENTER) {
4621 DRM_DEBUG_KMS("centering not supported\n");
4622 return -EINVAL;
4623 }
Yuly Novikov53b41832012-10-26 12:04:00 +03004624
4625 if (intel_connector->panel.fitting_mode == val) {
4626 /* the eDP scaling property is not changed */
4627 return 0;
4628 }
4629 intel_connector->panel.fitting_mode = val;
4630
4631 goto done;
4632 }
4633
Chris Wilsonf6849602010-09-19 09:29:33 +01004634 return -EINVAL;
4635
4636done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00004637 if (intel_encoder->base.crtc)
4638 intel_crtc_restore_mode(intel_encoder->base.crtc);
Chris Wilsonf6849602010-09-19 09:29:33 +01004639
4640 return 0;
4641}
4642
Chris Wilson7a418e32016-06-24 14:00:14 +01004643static int
4644intel_dp_connector_register(struct drm_connector *connector)
4645{
4646 struct intel_dp *intel_dp = intel_attached_dp(connector);
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01004647 int ret;
4648
4649 ret = intel_connector_register(connector);
4650 if (ret)
4651 return ret;
Chris Wilson7a418e32016-06-24 14:00:14 +01004652
4653 i915_debugfs_connector_add(connector);
4654
4655 DRM_DEBUG_KMS("registering %s bus for %s\n",
4656 intel_dp->aux.name, connector->kdev->kobj.name);
4657
4658 intel_dp->aux.dev = connector->kdev;
4659 return drm_dp_aux_register(&intel_dp->aux);
4660}
4661
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004662static void
Chris Wilsonc191eca2016-06-17 11:40:33 +01004663intel_dp_connector_unregister(struct drm_connector *connector)
4664{
4665 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4666 intel_connector_unregister(connector);
4667}
4668
4669static void
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004670intel_dp_connector_destroy(struct drm_connector *connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004671{
Jani Nikula1d508702012-10-19 14:51:49 +03004672 struct intel_connector *intel_connector = to_intel_connector(connector);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004673
Chris Wilson10e972d2014-09-04 21:43:45 +01004674 kfree(intel_connector->detect_edid);
Chris Wilsonbeb60602014-09-02 20:04:00 +01004675
Jani Nikula9cd300e2012-10-19 14:51:52 +03004676 if (!IS_ERR_OR_NULL(intel_connector->edid))
4677 kfree(intel_connector->edid);
4678
Paulo Zanoniacd8db102013-06-12 17:27:23 -03004679 /* Can't call is_edp() since the encoder may have been destroyed
4680 * already. */
4681 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
Jani Nikula1d508702012-10-19 14:51:49 +03004682 intel_panel_fini(&intel_connector->panel);
Matthew Garrettaaa6fd22011-08-12 12:11:33 +02004683
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004684 drm_connector_cleanup(connector);
Zhenyu Wang55f78c42010-03-29 16:13:57 +08004685 kfree(connector);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004686}
4687
Paulo Zanoni00c09d72012-10-26 19:05:52 -02004688void intel_dp_encoder_destroy(struct drm_encoder *encoder)
Daniel Vetter24d05922010-08-20 18:08:28 +02004689{
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004690 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4691 struct intel_dp *intel_dp = &intel_dig_port->dp;
Daniel Vetter24d05922010-08-20 18:08:28 +02004692
Dave Airlie0e32b392014-05-02 14:02:48 +10004693 intel_dp_mst_encoder_cleanup(intel_dig_port);
Keith Packardbd943152011-09-18 23:09:52 -07004694 if (is_edp(intel_dp)) {
4695 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä951468f2014-09-04 14:55:31 +03004696 /*
4697 * vdd might still be enabled do to the delayed vdd off.
4698 * Make sure vdd is actually turned off here.
4699 */
Ville Syrjälä773538e82014-09-04 14:54:56 +03004700 pps_lock(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01004701 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004702 pps_unlock(intel_dp);
4703
Clint Taylor01527b32014-07-07 13:01:46 -07004704 if (intel_dp->edp_notifier.notifier_call) {
4705 unregister_reboot_notifier(&intel_dp->edp_notifier);
4706 intel_dp->edp_notifier.notifier_call = NULL;
4707 }
Keith Packardbd943152011-09-18 23:09:52 -07004708 }
Chris Wilson99681882016-06-20 09:29:17 +01004709
4710 intel_dp_aux_fini(intel_dp);
4711
Imre Deakc8bd0e42014-12-12 17:57:38 +02004712 drm_encoder_cleanup(encoder);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02004713 kfree(intel_dig_port);
Daniel Vetter24d05922010-08-20 18:08:28 +02004714}
4715
Imre Deakbf93ba62016-04-18 10:04:21 +03004716void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
Imre Deak07f9cd02014-08-18 14:42:45 +03004717{
4718 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4719
4720 if (!is_edp(intel_dp))
4721 return;
4722
Ville Syrjälä951468f2014-09-04 14:55:31 +03004723 /*
4724 * vdd might still be enabled do to the delayed vdd off.
4725 * Make sure vdd is actually turned off here.
4726 */
Ville Syrjäläafa4e532014-11-25 15:43:48 +02004727 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004728 pps_lock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004729 edp_panel_vdd_off_sync(intel_dp);
Ville Syrjälä773538e82014-09-04 14:54:56 +03004730 pps_unlock(intel_dp);
Imre Deak07f9cd02014-08-18 14:42:45 +03004731}
4732
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004733static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4734{
4735 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4736 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004737 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004738 enum intel_display_power_domain power_domain;
4739
4740 lockdep_assert_held(&dev_priv->pps_mutex);
4741
4742 if (!edp_have_panel_vdd(intel_dp))
4743 return;
4744
4745 /*
4746 * The VDD bit needs a power domain reference, so if the bit is
4747 * already enabled when we boot or resume, grab this reference and
4748 * schedule a vdd off, so we don't hold on to the reference
4749 * indefinitely.
4750 */
4751 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004752 power_domain = intel_display_port_aux_power_domain(&intel_dig_port->base);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004753 intel_display_power_get(dev_priv, power_domain);
4754
4755 edp_panel_vdd_schedule_off(intel_dp);
4756}
4757
Imre Deakbf93ba62016-04-18 10:04:21 +03004758void intel_dp_encoder_reset(struct drm_encoder *encoder)
Imre Deak6d93c0c2014-07-31 14:03:36 +03004759{
Ville Syrjälä64989ca42016-05-13 20:53:56 +03004760 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Shashank Sharma910530c2016-10-14 19:56:52 +05304761 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4762 struct intel_lspcon *lspcon = &intel_dig_port->lspcon;
4763 struct intel_dp *intel_dp = &intel_dig_port->dp;
Ville Syrjälä64989ca42016-05-13 20:53:56 +03004764
4765 if (!HAS_DDI(dev_priv))
4766 intel_dp->DP = I915_READ(intel_dp->output_reg);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004767
Shashank Sharma910530c2016-10-14 19:56:52 +05304768 if (IS_GEN9(dev_priv) && lspcon->active)
4769 lspcon_resume(lspcon);
4770
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004771 if (to_intel_encoder(encoder)->type != INTEL_OUTPUT_EDP)
4772 return;
4773
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004774 pps_lock(intel_dp);
4775
Imre Deak335f7522016-08-10 14:07:32 +03004776 /* Reinit the power sequencer, in case BIOS did something with it. */
4777 intel_dp_pps_init(encoder->dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02004778 intel_edp_panel_vdd_sanitize(intel_dp);
4779
4780 pps_unlock(intel_dp);
Imre Deak6d93c0c2014-07-31 14:03:36 +03004781}
4782
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004783static const struct drm_connector_funcs intel_dp_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02004784 .dpms = drm_atomic_helper_connector_dpms,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004785 .detect = intel_dp_detect,
Chris Wilsonbeb60602014-09-02 20:04:00 +01004786 .force = intel_dp_force,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004787 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilsonf6849602010-09-19 09:29:33 +01004788 .set_property = intel_dp_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -08004789 .atomic_get_property = intel_connector_atomic_get_property,
Chris Wilson7a418e32016-06-24 14:00:14 +01004790 .late_register = intel_dp_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01004791 .early_unregister = intel_dp_connector_unregister,
Paulo Zanoni73845ad2013-06-12 17:27:30 -03004792 .destroy = intel_dp_connector_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08004793 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02004794 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004795};
4796
4797static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
4798 .get_modes = intel_dp_get_modes,
4799 .mode_valid = intel_dp_mode_valid,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004800};
4801
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004802static const struct drm_encoder_funcs intel_dp_enc_funcs = {
Imre Deak6d93c0c2014-07-31 14:03:36 +03004803 .reset = intel_dp_encoder_reset,
Daniel Vetter24d05922010-08-20 18:08:28 +02004804 .destroy = intel_dp_encoder_destroy,
Keith Packarda4fc5ed2009-04-07 16:16:42 -07004805};
4806
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004807enum irqreturn
Dave Airlie13cf5502014-06-18 11:29:35 +10004808intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
4809{
4810 struct intel_dp *intel_dp = &intel_dig_port->dp;
Imre Deak1c767b32014-08-18 14:42:42 +03004811 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Dave Airlie0e32b392014-05-02 14:02:48 +10004812 struct drm_device *dev = intel_dig_port->base.base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004813 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak1c767b32014-08-18 14:42:42 +03004814 enum intel_display_power_domain power_domain;
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004815 enum irqreturn ret = IRQ_NONE;
Imre Deak1c767b32014-08-18 14:42:42 +03004816
Takashi Iwai25400582015-11-19 12:09:56 +01004817 if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
4818 intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
Ville Syrjäläcca05022016-06-22 21:57:06 +03004819 intel_dig_port->base.type = INTEL_OUTPUT_DP;
Dave Airlie13cf5502014-06-18 11:29:35 +10004820
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03004821 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
4822 /*
4823 * vdd off can generate a long pulse on eDP which
4824 * would require vdd on to handle it, and thus we
4825 * would end up in an endless cycle of
4826 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
4827 */
4828 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
4829 port_name(intel_dig_port->port));
Ville Syrjäläa8b3d522015-02-10 14:11:46 +02004830 return IRQ_HANDLED;
Ville Syrjälä7a7f84c2014-10-16 20:46:10 +03004831 }
4832
Ville Syrjälä26fbb772014-08-11 18:37:37 +03004833 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
4834 port_name(intel_dig_port->port),
Dave Airlie0e32b392014-05-02 14:02:48 +10004835 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10004836
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004837 if (long_hpd) {
4838 intel_dp->detect_done = false;
4839 return IRQ_NONE;
4840 }
4841
Ville Syrjälä25f78f52015-11-16 15:01:04 +01004842 power_domain = intel_display_port_aux_power_domain(intel_encoder);
Imre Deak1c767b32014-08-18 14:42:42 +03004843 intel_display_power_get(dev_priv, power_domain);
4844
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004845 if (intel_dp->is_mst) {
4846 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
4847 /*
4848 * If we were in MST mode, and device is not
4849 * there, get out of MST mode
4850 */
4851 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4852 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
4853 intel_dp->is_mst = false;
4854 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4855 intel_dp->is_mst);
4856 intel_dp->detect_done = false;
4857 goto put_power;
Dave Airlie0e32b392014-05-02 14:02:48 +10004858 }
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004859 }
Dave Airlie0e32b392014-05-02 14:02:48 +10004860
Ville Syrjälä27d4efc2016-10-03 10:55:15 +03004861 if (!intel_dp->is_mst) {
4862 if (!intel_dp_short_pulse(intel_dp)) {
4863 intel_dp->detect_done = false;
4864 goto put_power;
Shubhangi Shrivastava39ff7472016-03-30 18:05:26 +05304865 }
Dave Airlie0e32b392014-05-02 14:02:48 +10004866 }
Daniel Vetterb2c5c182015-01-23 06:00:31 +01004867
4868 ret = IRQ_HANDLED;
4869
Imre Deak1c767b32014-08-18 14:42:42 +03004870put_power:
4871 intel_display_power_put(dev_priv, power_domain);
4872
4873 return ret;
Dave Airlie13cf5502014-06-18 11:29:35 +10004874}
4875
Rodrigo Vivi477ec322015-08-06 15:51:39 +08004876/* check the VBT to see whether the eDP is on another port */
Ville Syrjälä5d8a7752013-11-01 18:22:39 +02004877bool intel_dp_is_edp(struct drm_device *dev, enum port port)
Zhao Yakui36e83a12010-06-12 14:32:21 +08004878{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004879 struct drm_i915_private *dev_priv = to_i915(dev);
Zhao Yakui36e83a12010-06-12 14:32:21 +08004880
Ville Syrjälä53ce81a2015-09-11 21:04:38 +03004881 /*
4882 * eDP not supported on g4x. so bail out early just
4883 * for a bit extra safety in case the VBT is bonkers.
4884 */
4885 if (INTEL_INFO(dev)->gen < 5)
4886 return false;
4887
Ville Syrjälä3b32a352013-11-01 18:22:41 +02004888 if (port == PORT_A)
4889 return true;
4890
Jani Nikula951d9ef2016-03-16 12:43:31 +02004891 return intel_bios_is_port_edp(dev_priv, port);
Zhao Yakui36e83a12010-06-12 14:32:21 +08004892}
4893
Dave Airlie0e32b392014-05-02 14:02:48 +10004894void
Chris Wilsonf6849602010-09-19 09:29:33 +01004895intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
4896{
Yuly Novikov53b41832012-10-26 12:04:00 +03004897 struct intel_connector *intel_connector = to_intel_connector(connector);
4898
Chris Wilson3f43c482011-05-12 22:17:24 +01004899 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00004900 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02004901 intel_dp->color_range_auto = true;
Yuly Novikov53b41832012-10-26 12:04:00 +03004902
4903 if (is_edp(intel_dp)) {
4904 drm_mode_create_scaling_mode_property(connector->dev);
Rob Clark6de6d842012-10-11 20:36:04 -05004905 drm_object_attach_property(
4906 &connector->base,
Yuly Novikov53b41832012-10-26 12:04:00 +03004907 connector->dev->mode_config.scaling_mode_property,
Yuly Novikov8e740cd2012-10-26 12:04:01 +03004908 DRM_MODE_SCALE_ASPECT);
4909 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
Yuly Novikov53b41832012-10-26 12:04:00 +03004910 }
Chris Wilsonf6849602010-09-19 09:29:33 +01004911}
4912
Imre Deakdada1a92014-01-29 13:25:41 +02004913static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
4914{
Abhay Kumard28d4732016-01-22 17:39:04 -08004915 intel_dp->panel_power_off_time = ktime_get_boottime();
Imre Deakdada1a92014-01-29 13:25:41 +02004916 intel_dp->last_power_on = jiffies;
4917 intel_dp->last_backlight_off = jiffies;
4918}
4919
Daniel Vetter67a54562012-10-20 20:57:45 +02004920static void
Imre Deak54648612016-06-16 16:37:22 +03004921intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
4922 struct intel_dp *intel_dp, struct edp_power_seq *seq)
Daniel Vetter67a54562012-10-20 20:57:45 +02004923{
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304924 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
Imre Deak8e8232d2016-06-16 16:37:21 +03004925 struct pps_registers regs;
Jesse Barnes453c5422013-03-28 09:55:41 -07004926
Imre Deak8e8232d2016-06-16 16:37:21 +03004927 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Daniel Vetter67a54562012-10-20 20:57:45 +02004928
4929 /* Workaround: Need to write PP_CONTROL with the unlock key as
4930 * the very first thing. */
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304931 pp_ctl = ironlake_get_pp_control(intel_dp);
Daniel Vetter67a54562012-10-20 20:57:45 +02004932
Imre Deak8e8232d2016-06-16 16:37:21 +03004933 pp_on = I915_READ(regs.pp_on);
4934 pp_off = I915_READ(regs.pp_off);
Imre Deak54648612016-06-16 16:37:22 +03004935 if (!IS_BROXTON(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03004936 I915_WRITE(regs.pp_ctrl, pp_ctl);
4937 pp_div = I915_READ(regs.pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304938 }
Daniel Vetter67a54562012-10-20 20:57:45 +02004939
4940 /* Pull timing values out of registers */
Imre Deak54648612016-06-16 16:37:22 +03004941 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
4942 PANEL_POWER_UP_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004943
Imre Deak54648612016-06-16 16:37:22 +03004944 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
4945 PANEL_LIGHT_ON_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004946
Imre Deak54648612016-06-16 16:37:22 +03004947 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
4948 PANEL_LIGHT_OFF_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004949
Imre Deak54648612016-06-16 16:37:22 +03004950 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
4951 PANEL_POWER_DOWN_DELAY_SHIFT;
Daniel Vetter67a54562012-10-20 20:57:45 +02004952
Imre Deak54648612016-06-16 16:37:22 +03004953 if (IS_BROXTON(dev_priv)) {
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304954 u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
4955 BXT_POWER_CYCLE_DELAY_SHIFT;
4956 if (tmp > 0)
Imre Deak54648612016-06-16 16:37:22 +03004957 seq->t11_t12 = (tmp - 1) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304958 else
Imre Deak54648612016-06-16 16:37:22 +03004959 seq->t11_t12 = 0;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304960 } else {
Imre Deak54648612016-06-16 16:37:22 +03004961 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Daniel Vetter67a54562012-10-20 20:57:45 +02004962 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
Vandana Kannanb0a08be2015-06-18 11:00:55 +05304963 }
Imre Deak54648612016-06-16 16:37:22 +03004964}
4965
4966static void
Imre Deakde9c1b62016-06-16 20:01:46 +03004967intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
4968{
4969 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
4970 state_name,
4971 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
4972}
4973
4974static void
4975intel_pps_verify_state(struct drm_i915_private *dev_priv,
4976 struct intel_dp *intel_dp)
4977{
4978 struct edp_power_seq hw;
4979 struct edp_power_seq *sw = &intel_dp->pps_delays;
4980
4981 intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
4982
4983 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
4984 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
4985 DRM_ERROR("PPS state mismatch\n");
4986 intel_pps_dump_state("sw", sw);
4987 intel_pps_dump_state("hw", &hw);
4988 }
4989}
4990
4991static void
Imre Deak54648612016-06-16 16:37:22 +03004992intel_dp_init_panel_power_sequencer(struct drm_device *dev,
4993 struct intel_dp *intel_dp)
4994{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004995 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak54648612016-06-16 16:37:22 +03004996 struct edp_power_seq cur, vbt, spec,
4997 *final = &intel_dp->pps_delays;
4998
4999 lockdep_assert_held(&dev_priv->pps_mutex);
5000
5001 /* already initialized? */
5002 if (final->t11_t12 != 0)
5003 return;
5004
5005 intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005006
Imre Deakde9c1b62016-06-16 20:01:46 +03005007 intel_pps_dump_state("cur", &cur);
Daniel Vetter67a54562012-10-20 20:57:45 +02005008
Jani Nikula6aa23e62016-03-24 17:50:20 +02005009 vbt = dev_priv->vbt.edp.pps;
Daniel Vetter67a54562012-10-20 20:57:45 +02005010
5011 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5012 * our hw here, which are all in 100usec. */
5013 spec.t1_t3 = 210 * 10;
5014 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5015 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5016 spec.t10 = 500 * 10;
5017 /* This one is special and actually in units of 100ms, but zero
5018 * based in the hw (so we need to add 100 ms). But the sw vbt
5019 * table multiplies it with 1000 to make it in units of 100usec,
5020 * too. */
5021 spec.t11_t12 = (510 + 100) * 10;
5022
Imre Deakde9c1b62016-06-16 20:01:46 +03005023 intel_pps_dump_state("vbt", &vbt);
Daniel Vetter67a54562012-10-20 20:57:45 +02005024
5025 /* Use the max of the register settings and vbt. If both are
5026 * unset, fall back to the spec limits. */
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005027#define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
Daniel Vetter67a54562012-10-20 20:57:45 +02005028 spec.field : \
5029 max(cur.field, vbt.field))
5030 assign_final(t1_t3);
5031 assign_final(t8);
5032 assign_final(t9);
5033 assign_final(t10);
5034 assign_final(t11_t12);
5035#undef assign_final
5036
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005037#define get_delay(field) (DIV_ROUND_UP(final->field, 10))
Daniel Vetter67a54562012-10-20 20:57:45 +02005038 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5039 intel_dp->backlight_on_delay = get_delay(t8);
5040 intel_dp->backlight_off_delay = get_delay(t9);
5041 intel_dp->panel_power_down_delay = get_delay(t10);
5042 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5043#undef get_delay
5044
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005045 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5046 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5047 intel_dp->panel_power_cycle_delay);
5048
5049 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5050 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
Imre Deakde9c1b62016-06-16 20:01:46 +03005051
5052 /*
5053 * We override the HW backlight delays to 1 because we do manual waits
5054 * on them. For T8, even BSpec recommends doing it. For T9, if we
5055 * don't do this, we'll end up waiting for the backlight off delay
5056 * twice: once when we do the manual sleep, and once when we disable
5057 * the panel and wait for the PP_STATUS bit to become zero.
5058 */
5059 final->t8 = 1;
5060 final->t9 = 1;
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005061}
5062
5063static void
5064intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005065 struct intel_dp *intel_dp)
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005066{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005067 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes453c5422013-03-28 09:55:41 -07005068 u32 pp_on, pp_off, pp_div, port_sel = 0;
Ville Syrjäläe7dc33f2016-03-02 17:22:13 +02005069 int div = dev_priv->rawclk_freq / 1000;
Imre Deak8e8232d2016-06-16 16:37:21 +03005070 struct pps_registers regs;
Ville Syrjäläad933b52014-08-18 22:15:56 +03005071 enum port port = dp_to_dig_port(intel_dp)->port;
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005072 const struct edp_power_seq *seq = &intel_dp->pps_delays;
Jesse Barnes453c5422013-03-28 09:55:41 -07005073
Ville Syrjäläe39b9992014-09-04 14:53:14 +03005074 lockdep_assert_held(&dev_priv->pps_mutex);
Jesse Barnes453c5422013-03-28 09:55:41 -07005075
Imre Deak8e8232d2016-06-16 16:37:21 +03005076 intel_pps_get_registers(dev_priv, intel_dp, &regs);
Jesse Barnes453c5422013-03-28 09:55:41 -07005077
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005078 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
Imre Deakde9c1b62016-06-16 20:01:46 +03005079 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5080 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
Jani Nikulaf30d26e2013-01-16 10:53:40 +02005081 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
Daniel Vetter67a54562012-10-20 20:57:45 +02005082 /* Compute the divisor for the pp clock, simply match the Bspec
5083 * formula. */
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01005084 if (IS_BROXTON(dev_priv)) {
Imre Deak8e8232d2016-06-16 16:37:21 +03005085 pp_div = I915_READ(regs.pp_ctrl);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305086 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
5087 pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
5088 << BXT_POWER_CYCLE_DELAY_SHIFT);
5089 } else {
5090 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5091 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5092 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5093 }
Daniel Vetter67a54562012-10-20 20:57:45 +02005094
5095 /* Haswell doesn't have any port selection bits for the panel
5096 * power sequencer any more. */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005097 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005098 port_sel = PANEL_PORT_SELECT_VLV(port);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005099 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläad933b52014-08-18 22:15:56 +03005100 if (port == PORT_A)
Jani Nikulaa24c1442013-09-05 16:44:46 +03005101 port_sel = PANEL_PORT_SELECT_DPA;
Daniel Vetter67a54562012-10-20 20:57:45 +02005102 else
Jani Nikulaa24c1442013-09-05 16:44:46 +03005103 port_sel = PANEL_PORT_SELECT_DPD;
Daniel Vetter67a54562012-10-20 20:57:45 +02005104 }
5105
Jesse Barnes453c5422013-03-28 09:55:41 -07005106 pp_on |= port_sel;
5107
Imre Deak8e8232d2016-06-16 16:37:21 +03005108 I915_WRITE(regs.pp_on, pp_on);
5109 I915_WRITE(regs.pp_off, pp_off);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01005110 if (IS_BROXTON(dev_priv))
Imre Deak8e8232d2016-06-16 16:37:21 +03005111 I915_WRITE(regs.pp_ctrl, pp_div);
Vandana Kannanb0a08be2015-06-18 11:00:55 +05305112 else
Imre Deak8e8232d2016-06-16 16:37:21 +03005113 I915_WRITE(regs.pp_div, pp_div);
Daniel Vetter67a54562012-10-20 20:57:45 +02005114
Daniel Vetter67a54562012-10-20 20:57:45 +02005115 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 +03005116 I915_READ(regs.pp_on),
5117 I915_READ(regs.pp_off),
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01005118 IS_BROXTON(dev_priv) ?
Imre Deak8e8232d2016-06-16 16:37:21 +03005119 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5120 I915_READ(regs.pp_div));
Zhenyu Wange3421a12010-04-08 09:43:27 +08005121}
5122
Imre Deak335f7522016-08-10 14:07:32 +03005123static void intel_dp_pps_init(struct drm_device *dev,
5124 struct intel_dp *intel_dp)
5125{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005126 struct drm_i915_private *dev_priv = to_i915(dev);
5127
5128 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Imre Deak335f7522016-08-10 14:07:32 +03005129 vlv_initial_power_sequencer_setup(intel_dp);
5130 } else {
5131 intel_dp_init_panel_power_sequencer(dev, intel_dp);
5132 intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
5133 }
5134}
5135
Vandana Kannanb33a2812015-02-13 15:33:03 +05305136/**
5137 * intel_dp_set_drrs_state - program registers for RR switch to take effect
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005138 * @dev_priv: i915 device
Maarten Lankhorste8964022016-08-25 11:07:02 +02005139 * @crtc_state: a pointer to the active intel_crtc_state
Vandana Kannanb33a2812015-02-13 15:33:03 +05305140 * @refresh_rate: RR to be programmed
5141 *
5142 * This function gets called when refresh rate (RR) has to be changed from
5143 * one frequency to another. Switches can be between high and low RR
5144 * supported by the panel or to any other RR based on media playback (in
5145 * this case, RR value needs to be passed from user space).
5146 *
5147 * The caller of this function needs to take a lock on dev_priv->drrs.
5148 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005149static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
5150 struct intel_crtc_state *crtc_state,
5151 int refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305152{
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305153 struct intel_encoder *encoder;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305154 struct intel_digital_port *dig_port = NULL;
5155 struct intel_dp *intel_dp = dev_priv->drrs.dp;
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005156 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Vandana Kannan96178ee2015-01-10 02:25:56 +05305157 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305158
5159 if (refresh_rate <= 0) {
5160 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5161 return;
5162 }
5163
Vandana Kannan96178ee2015-01-10 02:25:56 +05305164 if (intel_dp == NULL) {
5165 DRM_DEBUG_KMS("DRRS not supported.\n");
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305166 return;
5167 }
5168
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005169 /*
Rodrigo Vivie4d59f62014-11-20 02:22:08 -08005170 * FIXME: This needs proper synchronization with psr state for some
5171 * platforms that cannot have PSR and DRRS enabled at the same time.
Daniel Vetter1fcc9d12014-07-11 10:30:10 -07005172 */
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305173
Vandana Kannan96178ee2015-01-10 02:25:56 +05305174 dig_port = dp_to_dig_port(intel_dp);
5175 encoder = &dig_port->base;
Ander Conselvan de Oliveira723f9aa2015-03-20 16:18:18 +02005176 intel_crtc = to_intel_crtc(encoder->base.crtc);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305177
5178 if (!intel_crtc) {
5179 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5180 return;
5181 }
5182
Vandana Kannan96178ee2015-01-10 02:25:56 +05305183 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305184 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5185 return;
5186 }
5187
Vandana Kannan96178ee2015-01-10 02:25:56 +05305188 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5189 refresh_rate)
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305190 index = DRRS_LOW_RR;
5191
Vandana Kannan96178ee2015-01-10 02:25:56 +05305192 if (index == dev_priv->drrs.refresh_rate_type) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305193 DRM_DEBUG_KMS(
5194 "DRRS requested for previously set RR...ignoring\n");
5195 return;
5196 }
5197
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005198 if (!crtc_state->base.active) {
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305199 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5200 return;
5201 }
5202
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005203 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
Vandana Kannana4c30b12015-02-13 15:33:00 +05305204 switch (index) {
5205 case DRRS_HIGH_RR:
5206 intel_dp_set_m_n(intel_crtc, M1_N1);
5207 break;
5208 case DRRS_LOW_RR:
5209 intel_dp_set_m_n(intel_crtc, M2_N2);
5210 break;
5211 case DRRS_MAX_RR:
5212 default:
5213 DRM_ERROR("Unsupported refreshrate type\n");
5214 }
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005215 } else if (INTEL_GEN(dev_priv) > 6) {
5216 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
Ville Syrjälä649636e2015-09-22 19:50:01 +03005217 u32 val;
Vandana Kannana4c30b12015-02-13 15:33:00 +05305218
Ville Syrjälä649636e2015-09-22 19:50:01 +03005219 val = I915_READ(reg);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305220 if (index > DRRS_HIGH_RR) {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005221 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305222 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5223 else
5224 val |= PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305225 } else {
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005226 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Vandana Kannan6fa7aec2015-02-13 15:33:01 +05305227 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5228 else
5229 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305230 }
5231 I915_WRITE(reg, val);
5232 }
5233
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305234 dev_priv->drrs.refresh_rate_type = index;
5235
5236 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5237}
5238
Vandana Kannanb33a2812015-02-13 15:33:03 +05305239/**
5240 * intel_edp_drrs_enable - init drrs struct if supported
5241 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005242 * @crtc_state: A pointer to the active crtc state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305243 *
5244 * Initializes frontbuffer_bits and drrs.dp
5245 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005246void intel_edp_drrs_enable(struct intel_dp *intel_dp,
5247 struct intel_crtc_state *crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305248{
5249 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005250 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305251
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005252 if (!crtc_state->has_drrs) {
Vandana Kannanc3955782015-01-22 15:17:40 +05305253 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5254 return;
5255 }
5256
5257 mutex_lock(&dev_priv->drrs.mutex);
5258 if (WARN_ON(dev_priv->drrs.dp)) {
5259 DRM_ERROR("DRRS already enabled\n");
5260 goto unlock;
5261 }
5262
5263 dev_priv->drrs.busy_frontbuffer_bits = 0;
5264
5265 dev_priv->drrs.dp = intel_dp;
5266
5267unlock:
5268 mutex_unlock(&dev_priv->drrs.mutex);
5269}
5270
Vandana Kannanb33a2812015-02-13 15:33:03 +05305271/**
5272 * intel_edp_drrs_disable - Disable DRRS
5273 * @intel_dp: DP struct
Maarten Lankhorst5423adf2016-08-31 11:01:36 +02005274 * @old_crtc_state: Pointer to old crtc_state.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305275 *
5276 */
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005277void intel_edp_drrs_disable(struct intel_dp *intel_dp,
5278 struct intel_crtc_state *old_crtc_state)
Vandana Kannanc3955782015-01-22 15:17:40 +05305279{
5280 struct drm_device *dev = intel_dp_to_dev(intel_dp);
Chris Wilsonfac5e232016-07-04 11:34:36 +01005281 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannanc3955782015-01-22 15:17:40 +05305282
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005283 if (!old_crtc_state->has_drrs)
Vandana Kannanc3955782015-01-22 15:17:40 +05305284 return;
5285
5286 mutex_lock(&dev_priv->drrs.mutex);
5287 if (!dev_priv->drrs.dp) {
5288 mutex_unlock(&dev_priv->drrs.mutex);
5289 return;
5290 }
5291
5292 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005293 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5294 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannanc3955782015-01-22 15:17:40 +05305295
5296 dev_priv->drrs.dp = NULL;
5297 mutex_unlock(&dev_priv->drrs.mutex);
5298
5299 cancel_delayed_work_sync(&dev_priv->drrs.work);
5300}
5301
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305302static void intel_edp_drrs_downclock_work(struct work_struct *work)
5303{
5304 struct drm_i915_private *dev_priv =
5305 container_of(work, typeof(*dev_priv), drrs.work.work);
5306 struct intel_dp *intel_dp;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305307
Vandana Kannan96178ee2015-01-10 02:25:56 +05305308 mutex_lock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305309
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305310 intel_dp = dev_priv->drrs.dp;
5311
5312 if (!intel_dp)
5313 goto unlock;
5314
5315 /*
5316 * The delayed work can race with an invalidate hence we need to
5317 * recheck.
5318 */
5319
5320 if (dev_priv->drrs.busy_frontbuffer_bits)
5321 goto unlock;
5322
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005323 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5324 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5325
5326 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5327 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5328 }
Vandana Kannan4e9ac942015-01-22 15:14:45 +05305329
5330unlock:
Vandana Kannan96178ee2015-01-10 02:25:56 +05305331 mutex_unlock(&dev_priv->drrs.mutex);
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305332}
5333
Vandana Kannanb33a2812015-02-13 15:33:03 +05305334/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305335 * intel_edp_drrs_invalidate - Disable Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005336 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305337 * @frontbuffer_bits: frontbuffer plane tracking bits
5338 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305339 * This function gets called everytime rendering on the given planes start.
5340 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Vandana Kannanb33a2812015-02-13 15:33:03 +05305341 *
5342 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5343 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005344void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5345 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305346{
Vandana Kannana93fad02015-01-10 02:25:59 +05305347 struct drm_crtc *crtc;
5348 enum pipe pipe;
5349
Daniel Vetter9da7d692015-04-09 16:44:15 +02005350 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305351 return;
5352
Daniel Vetter88f933a2015-04-09 16:44:16 +02005353 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305354
Vandana Kannana93fad02015-01-10 02:25:59 +05305355 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005356 if (!dev_priv->drrs.dp) {
5357 mutex_unlock(&dev_priv->drrs.mutex);
5358 return;
5359 }
5360
Vandana Kannana93fad02015-01-10 02:25:59 +05305361 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5362 pipe = to_intel_crtc(crtc)->pipe;
5363
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005364 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5365 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5366
Ramalingam C0ddfd202015-06-15 20:50:05 +05305367 /* invalidate means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005368 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005369 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5370 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Vandana Kannana93fad02015-01-10 02:25:59 +05305371
Vandana Kannana93fad02015-01-10 02:25:59 +05305372 mutex_unlock(&dev_priv->drrs.mutex);
5373}
5374
Vandana Kannanb33a2812015-02-13 15:33:03 +05305375/**
Ramalingam C0ddfd202015-06-15 20:50:05 +05305376 * intel_edp_drrs_flush - Restart Idleness DRRS
Chris Wilson5748b6a2016-08-04 16:32:38 +01005377 * @dev_priv: i915 device
Vandana Kannanb33a2812015-02-13 15:33:03 +05305378 * @frontbuffer_bits: frontbuffer plane tracking bits
5379 *
Ramalingam C0ddfd202015-06-15 20:50:05 +05305380 * This function gets called every time rendering on the given planes has
5381 * completed or flip on a crtc is completed. So DRRS should be upclocked
5382 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5383 * if no other planes are dirty.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305384 *
5385 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5386 */
Chris Wilson5748b6a2016-08-04 16:32:38 +01005387void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5388 unsigned int frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305389{
Vandana Kannana93fad02015-01-10 02:25:59 +05305390 struct drm_crtc *crtc;
5391 enum pipe pipe;
5392
Daniel Vetter9da7d692015-04-09 16:44:15 +02005393 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
Vandana Kannana93fad02015-01-10 02:25:59 +05305394 return;
5395
Daniel Vetter88f933a2015-04-09 16:44:16 +02005396 cancel_delayed_work(&dev_priv->drrs.work);
Ramalingam C3954e732015-03-03 12:11:46 +05305397
Vandana Kannana93fad02015-01-10 02:25:59 +05305398 mutex_lock(&dev_priv->drrs.mutex);
Daniel Vetter9da7d692015-04-09 16:44:15 +02005399 if (!dev_priv->drrs.dp) {
5400 mutex_unlock(&dev_priv->drrs.mutex);
5401 return;
5402 }
5403
Vandana Kannana93fad02015-01-10 02:25:59 +05305404 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5405 pipe = to_intel_crtc(crtc)->pipe;
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005406
5407 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
Vandana Kannana93fad02015-01-10 02:25:59 +05305408 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5409
Ramalingam C0ddfd202015-06-15 20:50:05 +05305410 /* flush means busy screen hence upclock */
Daniel Vetterc1d038c2015-06-18 10:30:25 +02005411 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02005412 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5413 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
Ramalingam C0ddfd202015-06-15 20:50:05 +05305414
5415 /*
5416 * flush also means no more activity hence schedule downclock, if all
5417 * other fbs are quiescent too
5418 */
5419 if (!dev_priv->drrs.busy_frontbuffer_bits)
Vandana Kannana93fad02015-01-10 02:25:59 +05305420 schedule_delayed_work(&dev_priv->drrs.work,
5421 msecs_to_jiffies(1000));
5422 mutex_unlock(&dev_priv->drrs.mutex);
5423}
5424
Vandana Kannanb33a2812015-02-13 15:33:03 +05305425/**
5426 * DOC: Display Refresh Rate Switching (DRRS)
5427 *
5428 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5429 * which enables swtching between low and high refresh rates,
5430 * dynamically, based on the usage scenario. This feature is applicable
5431 * for internal panels.
5432 *
5433 * Indication that the panel supports DRRS is given by the panel EDID, which
5434 * would list multiple refresh rates for one resolution.
5435 *
5436 * DRRS is of 2 types - static and seamless.
5437 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5438 * (may appear as a blink on screen) and is used in dock-undock scenario.
5439 * Seamless DRRS involves changing RR without any visual effect to the user
5440 * and can be used during normal system usage. This is done by programming
5441 * certain registers.
5442 *
5443 * Support for static/seamless DRRS may be indicated in the VBT based on
5444 * inputs from the panel spec.
5445 *
5446 * DRRS saves power by switching to low RR based on usage scenarios.
5447 *
Daniel Vetter2e7a5702016-06-01 23:40:36 +02005448 * The implementation is based on frontbuffer tracking implementation. When
5449 * there is a disturbance on the screen triggered by user activity or a periodic
5450 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5451 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5452 * made.
5453 *
5454 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5455 * and intel_edp_drrs_flush() are called.
Vandana Kannanb33a2812015-02-13 15:33:03 +05305456 *
5457 * DRRS can be further extended to support other internal panels and also
5458 * the scenario of video playback wherein RR is set based on the rate
5459 * requested by userspace.
5460 */
5461
5462/**
5463 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5464 * @intel_connector: eDP connector
5465 * @fixed_mode: preferred mode of panel
5466 *
5467 * This function is called only once at driver load to initialize basic
5468 * DRRS stuff.
5469 *
5470 * Returns:
5471 * Downclock mode if panel supports it, else return NULL.
5472 * DRRS support is determined by the presence of downclock mode (apart
5473 * from VBT setting).
5474 */
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305475static struct drm_display_mode *
Vandana Kannan96178ee2015-01-10 02:25:56 +05305476intel_dp_drrs_init(struct intel_connector *intel_connector,
5477 struct drm_display_mode *fixed_mode)
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305478{
5479 struct drm_connector *connector = &intel_connector->base;
Vandana Kannan96178ee2015-01-10 02:25:56 +05305480 struct drm_device *dev = connector->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005481 struct drm_i915_private *dev_priv = to_i915(dev);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305482 struct drm_display_mode *downclock_mode = NULL;
5483
Daniel Vetter9da7d692015-04-09 16:44:15 +02005484 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5485 mutex_init(&dev_priv->drrs.mutex);
5486
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305487 if (INTEL_INFO(dev)->gen <= 6) {
5488 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5489 return NULL;
5490 }
5491
5492 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005493 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305494 return NULL;
5495 }
5496
5497 downclock_mode = intel_find_panel_downclock
5498 (dev, fixed_mode, connector);
5499
5500 if (!downclock_mode) {
Ramalingam Ca1d26342015-02-23 17:38:33 +05305501 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305502 return NULL;
5503 }
5504
Vandana Kannan96178ee2015-01-10 02:25:56 +05305505 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
Pradeep Bhat439d7ac2014-04-05 12:13:28 +05305506
Vandana Kannan96178ee2015-01-10 02:25:56 +05305507 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Damien Lespiau4079b8d2014-08-05 10:39:42 +01005508 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305509 return downclock_mode;
5510}
5511
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005512static bool intel_edp_init_connector(struct intel_dp *intel_dp,
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005513 struct intel_connector *intel_connector)
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005514{
5515 struct drm_connector *connector = &intel_connector->base;
5516 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005517 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5518 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005519 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005520 struct drm_display_mode *fixed_mode = NULL;
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305521 struct drm_display_mode *downclock_mode = NULL;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005522 bool has_dpcd;
5523 struct drm_display_mode *scan;
5524 struct edid *edid;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005525 enum pipe pipe = INVALID_PIPE;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005526
5527 if (!is_edp(intel_dp))
5528 return true;
5529
Imre Deak97a824e12016-06-21 11:51:47 +03005530 /*
5531 * On IBX/CPT we may get here with LVDS already registered. Since the
5532 * driver uses the only internal power sequencer available for both
5533 * eDP and LVDS bail out early in this case to prevent interfering
5534 * with an already powered-on LVDS power sequencer.
5535 */
5536 if (intel_get_lvds_encoder(dev)) {
5537 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5538 DRM_INFO("LVDS was detected, not registering eDP\n");
5539
5540 return false;
5541 }
5542
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005543 pps_lock(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005544
5545 intel_dp_init_panel_power_timestamps(intel_dp);
Imre Deak335f7522016-08-10 14:07:32 +03005546 intel_dp_pps_init(dev, intel_dp);
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005547 intel_edp_panel_vdd_sanitize(intel_dp);
Imre Deakb4d06ed2016-06-21 11:51:49 +03005548
Ville Syrjälä49e6bc52014-10-28 16:15:52 +02005549 pps_unlock(intel_dp);
Paulo Zanoni63635212014-04-22 19:55:42 -03005550
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005551 /* Cache DPCD and EDID for edp. */
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005552 has_dpcd = intel_edp_init_dpcd(intel_dp);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005553
Ville Syrjäläfe5a66f2016-07-29 16:52:39 +03005554 if (!has_dpcd) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005555 /* if this fails, presume the device is a ghost */
5556 DRM_INFO("failed to retrieve link info, disabling eDP\n");
Imre Deakb4d06ed2016-06-21 11:51:49 +03005557 goto out_vdd_off;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005558 }
5559
Daniel Vetter060c8772014-03-21 23:22:35 +01005560 mutex_lock(&dev->mode_config.mutex);
Jani Nikula0b998362014-03-14 16:51:17 +02005561 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005562 if (edid) {
5563 if (drm_add_edid_modes(connector, edid)) {
5564 drm_mode_connector_update_edid_property(connector,
5565 edid);
5566 drm_edid_to_eld(connector, edid);
5567 } else {
5568 kfree(edid);
5569 edid = ERR_PTR(-EINVAL);
5570 }
5571 } else {
5572 edid = ERR_PTR(-ENOENT);
5573 }
5574 intel_connector->edid = edid;
5575
5576 /* prefer fixed mode from EDID if available */
5577 list_for_each_entry(scan, &connector->probed_modes, head) {
5578 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5579 fixed_mode = drm_mode_duplicate(dev, scan);
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305580 downclock_mode = intel_dp_drrs_init(
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305581 intel_connector, fixed_mode);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005582 break;
5583 }
5584 }
5585
5586 /* fallback to VBT if available for eDP */
5587 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5588 fixed_mode = drm_mode_duplicate(dev,
5589 dev_priv->vbt.lfp_lvds_vbt_mode);
Ville Syrjälädf457242016-05-31 12:08:34 +03005590 if (fixed_mode) {
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005591 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjälädf457242016-05-31 12:08:34 +03005592 connector->display_info.width_mm = fixed_mode->width_mm;
5593 connector->display_info.height_mm = fixed_mode->height_mm;
5594 }
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005595 }
Daniel Vetter060c8772014-03-21 23:22:35 +01005596 mutex_unlock(&dev->mode_config.mutex);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005597
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005598 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Clint Taylor01527b32014-07-07 13:01:46 -07005599 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5600 register_reboot_notifier(&intel_dp->edp_notifier);
Ville Syrjälä6517d272014-11-07 11:16:02 +02005601
5602 /*
5603 * Figure out the current pipe for the initial backlight setup.
5604 * If the current pipe isn't valid, try the PPS pipe, and if that
5605 * fails just assume pipe A.
5606 */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005607 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä6517d272014-11-07 11:16:02 +02005608 pipe = DP_PORT_TO_PIPE_CHV(intel_dp->DP);
5609 else
5610 pipe = PORT_TO_PIPE(intel_dp->DP);
5611
5612 if (pipe != PIPE_A && pipe != PIPE_B)
5613 pipe = intel_dp->pps_pipe;
5614
5615 if (pipe != PIPE_A && pipe != PIPE_B)
5616 pipe = PIPE_A;
5617
5618 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5619 pipe_name(pipe));
Clint Taylor01527b32014-07-07 13:01:46 -07005620 }
5621
Pradeep Bhat4f9db5b2014-04-05 12:12:31 +05305622 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
Jani Nikula5507fae2015-09-14 14:03:48 +03005623 intel_connector->panel.backlight.power = intel_edp_backlight_power;
Ville Syrjälä6517d272014-11-07 11:16:02 +02005624 intel_panel_setup_backlight(connector, pipe);
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005625
5626 return true;
Imre Deakb4d06ed2016-06-21 11:51:49 +03005627
5628out_vdd_off:
5629 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5630 /*
5631 * vdd might still be enabled do to the delayed vdd off.
5632 * Make sure vdd is actually turned off here.
5633 */
5634 pps_lock(intel_dp);
5635 edp_panel_vdd_off_sync(intel_dp);
5636 pps_unlock(intel_dp);
5637
5638 return false;
Paulo Zanonied92f0b2013-06-12 17:27:24 -03005639}
5640
Paulo Zanoni16c25532013-06-12 17:27:25 -03005641bool
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005642intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5643 struct intel_connector *intel_connector)
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005644{
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005645 struct drm_connector *connector = &intel_connector->base;
5646 struct intel_dp *intel_dp = &intel_dig_port->dp;
5647 struct intel_encoder *intel_encoder = &intel_dig_port->base;
5648 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005649 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02005650 enum port port = intel_dig_port->port;
Chris Wilson7a418e32016-06-24 14:00:14 +01005651 int type;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005652
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005653 if (WARN(intel_dig_port->max_lanes < 1,
5654 "Not enough lanes (%d) for DP on port %c\n",
5655 intel_dig_port->max_lanes, port_name(port)))
5656 return false;
5657
Ville Syrjäläa4a5d2f2014-09-04 14:54:20 +03005658 intel_dp->pps_pipe = INVALID_PIPE;
5659
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005660 /* intel_dp vfuncs */
Damien Lespiaub6b5e382014-01-20 16:00:59 +00005661 if (INTEL_INFO(dev)->gen >= 9)
5662 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005663 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005664 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005665 else if (HAS_PCH_SPLIT(dev_priv))
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005666 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
5667 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005668 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
Damien Lespiauec5b01d2014-01-21 13:35:39 +00005669
Damien Lespiaub9ca5fa2014-01-20 16:01:00 +00005670 if (INTEL_INFO(dev)->gen >= 9)
5671 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
5672 else
Ville Syrjälä6ffb1be2016-03-02 17:22:14 +02005673 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
Damien Lespiau153b1102014-01-21 13:37:15 +00005674
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005675 if (HAS_DDI(dev_priv))
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03005676 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
5677
Daniel Vetter07679352012-09-06 22:15:42 +02005678 /* Preserve the current hw state. */
5679 intel_dp->DP = I915_READ(intel_dp->output_reg);
Jani Nikuladd06f902012-10-19 14:51:50 +03005680 intel_dp->attached_connector = intel_connector;
Chris Wilson3d3dc142011-02-12 10:33:12 +00005681
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005682 if (intel_dp_is_edp(dev, port))
Gajanan Bhat19c03922012-09-27 19:13:07 +05305683 type = DRM_MODE_CONNECTOR_eDP;
Ville Syrjälä3b32a352013-11-01 18:22:41 +02005684 else
5685 type = DRM_MODE_CONNECTOR_DisplayPort;
Adam Jacksonb3295302010-07-16 14:46:28 -04005686
Imre Deakf7d24902013-05-08 13:14:05 +03005687 /*
5688 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
5689 * for DP the encoder type can be set by the caller to
5690 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
5691 */
5692 if (type == DRM_MODE_CONNECTOR_eDP)
5693 intel_encoder->type = INTEL_OUTPUT_EDP;
5694
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005695 /* eDP only on port B and/or C on vlv/chv */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005696 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08005697 is_edp(intel_dp) && port != PORT_B && port != PORT_C))
Ville Syrjäläc17ed5b2014-10-16 21:27:27 +03005698 return false;
5699
Imre Deake7281ea2013-05-08 13:14:08 +03005700 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
5701 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
5702 port_name(port));
5703
Adam Jacksonb3295302010-07-16 14:46:28 -04005704 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005705 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
5706
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005707 connector->interlace_allowed = true;
5708 connector->doublescan_allowed = 0;
Ma Lingf8aed702009-08-24 13:50:24 +08005709
Mika Kaholab6339582016-09-09 14:10:52 +03005710 intel_dp_aux_init(intel_dp);
Chris Wilson7a418e32016-06-24 14:00:14 +01005711
Daniel Vetter66a92782012-07-12 20:08:18 +02005712 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
Daniel Vetter4be73782014-01-17 14:39:48 +01005713 edp_panel_vdd_work);
Zhenyu Wang6251ec02010-01-12 05:38:32 +08005714
Chris Wilsondf0e9242010-09-09 16:20:55 +01005715 intel_connector_attach_encoder(intel_connector, intel_encoder);
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005716
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01005717 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02005718 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
5719 else
5720 intel_connector->get_hw_state = intel_connector_get_hw_state;
5721
Jani Nikula0b998362014-03-14 16:51:17 +02005722 /* Set up the hotplug pin. */
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005723 switch (port) {
5724 case PORT_A:
Egbert Eich1d843f92013-02-25 12:06:49 -05005725 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005726 break;
5727 case PORT_B:
Egbert Eich1d843f92013-02-25 12:06:49 -05005728 intel_encoder->hpd_pin = HPD_PORT_B;
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01005729 if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1))
Sonika Jindalcf1d5882015-08-10 10:35:36 +05305730 intel_encoder->hpd_pin = HPD_PORT_A;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005731 break;
5732 case PORT_C:
Egbert Eich1d843f92013-02-25 12:06:49 -05005733 intel_encoder->hpd_pin = HPD_PORT_C;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005734 break;
5735 case PORT_D:
Egbert Eich1d843f92013-02-25 12:06:49 -05005736 intel_encoder->hpd_pin = HPD_PORT_D;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005737 break;
Xiong Zhang26951ca2015-08-17 15:55:50 +08005738 case PORT_E:
5739 intel_encoder->hpd_pin = HPD_PORT_E;
5740 break;
Paulo Zanoniab9d7c32012-07-17 17:53:45 -03005741 default:
Damien Lespiauad1c0b12013-03-07 15:30:28 +00005742 BUG();
Zhenyu Wang5eb08b62009-07-24 01:00:31 +08005743 }
5744
Dave Airlie0e32b392014-05-02 14:02:48 +10005745 /* init MST on ports that can support it */
Ville Syrjäläf8e58dd2016-06-22 21:56:59 +03005746 if (HAS_DP_MST(dev) && !is_edp(intel_dp) &&
Jani Nikula0c9b3712015-05-18 17:10:01 +03005747 (port == PORT_B || port == PORT_C || port == PORT_D))
5748 intel_dp_mst_encoder_init(intel_dig_port,
5749 intel_connector->base.base.id);
Dave Airlie0e32b392014-05-02 14:02:48 +10005750
Ville Syrjälä36b5f422014-10-16 21:27:30 +03005751 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005752 intel_dp_aux_fini(intel_dp);
5753 intel_dp_mst_encoder_cleanup(intel_dig_port);
5754 goto fail;
Paulo Zanonib2f246a2013-06-12 17:27:26 -03005755 }
Zhenyu Wang32f9d652009-07-24 01:00:32 +08005756
Chris Wilsonf6849602010-09-19 09:29:33 +01005757 intel_dp_add_properties(intel_dp, connector);
5758
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005759 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
5760 * 0xd. Failure to do so will result in spurious interrupts being
5761 * generated on the port when a cable is not attached.
5762 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01005763 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005764 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
5765 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
5766 }
Paulo Zanoni16c25532013-06-12 17:27:25 -03005767
5768 return true;
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005769
5770fail:
Ville Syrjäläa121f4e2015-11-11 20:34:11 +02005771 drm_connector_cleanup(connector);
5772
5773 return false;
Keith Packarda4fc5ed2009-04-07 16:16:42 -07005774}
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005775
Chris Wilson457c52d2016-06-01 08:27:50 +01005776bool intel_dp_init(struct drm_device *dev,
5777 i915_reg_t output_reg,
5778 enum port port)
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005779{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005780 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005781 struct intel_digital_port *intel_dig_port;
5782 struct intel_encoder *intel_encoder;
5783 struct drm_encoder *encoder;
5784 struct intel_connector *intel_connector;
5785
Daniel Vetterb14c5672013-09-19 12:18:32 +02005786 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005787 if (!intel_dig_port)
Chris Wilson457c52d2016-06-01 08:27:50 +01005788 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005789
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03005790 intel_connector = intel_connector_alloc();
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305791 if (!intel_connector)
5792 goto err_connector_alloc;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005793
5794 intel_encoder = &intel_dig_port->base;
5795 encoder = &intel_encoder->base;
5796
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305797 if (drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
Ville Syrjälä580d8ed2016-05-27 20:59:24 +03005798 DRM_MODE_ENCODER_TMDS, "DP %c", port_name(port)))
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305799 goto err_encoder_init;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005800
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01005801 intel_encoder->compute_config = intel_dp_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005802 intel_encoder->disable = intel_disable_dp;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02005803 intel_encoder->get_hw_state = intel_dp_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07005804 intel_encoder->get_config = intel_dp_get_config;
Imre Deak07f9cd02014-08-18 14:42:45 +03005805 intel_encoder->suspend = intel_dp_encoder_suspend;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005806 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03005807 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03005808 intel_encoder->pre_enable = chv_pre_enable_dp;
5809 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä580d3812014-04-09 13:29:00 +03005810 intel_encoder->post_disable = chv_post_disable_dp;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03005811 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01005812 } else if (IS_VALLEYVIEW(dev_priv)) {
Jani Nikulaecff4f32013-09-06 07:38:29 +03005813 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005814 intel_encoder->pre_enable = vlv_pre_enable_dp;
5815 intel_encoder->enable = vlv_enable_dp;
Ville Syrjälä49277c32014-03-31 18:21:26 +03005816 intel_encoder->post_disable = vlv_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005817 } else {
Jani Nikulaecff4f32013-09-06 07:38:29 +03005818 intel_encoder->pre_enable = g4x_pre_enable_dp;
5819 intel_encoder->enable = g4x_enable_dp;
Ville Syrjälä08aff3f2014-08-18 22:16:09 +03005820 if (INTEL_INFO(dev)->gen >= 5)
5821 intel_encoder->post_disable = ilk_post_disable_dp;
Jani Nikulaab1f90f2013-07-30 12:20:30 +03005822 }
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005823
Paulo Zanoni174edf12012-10-26 19:05:50 -02005824 intel_dig_port->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005825 intel_dig_port->dp.output_reg = output_reg;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02005826 intel_dig_port->max_lanes = 4;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005827
Ville Syrjäläcca05022016-06-22 21:57:06 +03005828 intel_encoder->type = INTEL_OUTPUT_DP;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01005829 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03005830 if (port == PORT_D)
5831 intel_encoder->crtc_mask = 1 << 2;
5832 else
5833 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
5834 } else {
5835 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
5836 }
Ville Syrjäläbc079e82014-03-03 16:15:28 +02005837 intel_encoder->cloneable = 0;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07005838 intel_encoder->port = port;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005839
Dave Airlie13cf5502014-06-18 11:29:35 +10005840 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03005841 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Dave Airlie13cf5502014-06-18 11:29:35 +10005842
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305843 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
5844 goto err_init_connector;
5845
Chris Wilson457c52d2016-06-01 08:27:50 +01005846 return true;
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305847
5848err_init_connector:
5849 drm_encoder_cleanup(encoder);
Sudip Mukherjee893da0c2015-10-08 19:28:00 +05305850err_encoder_init:
Sudip Mukherjee11aee0f2015-10-08 19:27:59 +05305851 kfree(intel_connector);
5852err_connector_alloc:
5853 kfree(intel_dig_port);
Chris Wilson457c52d2016-06-01 08:27:50 +01005854 return false;
Paulo Zanonif0fec3f2012-10-26 19:05:48 -02005855}
Dave Airlie0e32b392014-05-02 14:02:48 +10005856
5857void intel_dp_mst_suspend(struct drm_device *dev)
5858{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005859 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10005860 int i;
5861
5862 /* disable MST */
5863 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03005864 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005865
5866 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10005867 continue;
5868
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005869 if (intel_dig_port->dp.is_mst)
5870 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
Dave Airlie0e32b392014-05-02 14:02:48 +10005871 }
5872}
5873
5874void intel_dp_mst_resume(struct drm_device *dev)
5875{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005876 struct drm_i915_private *dev_priv = to_i915(dev);
Dave Airlie0e32b392014-05-02 14:02:48 +10005877 int i;
5878
5879 for (i = 0; i < I915_MAX_PORTS; i++) {
Jani Nikula5fcece82015-05-27 15:03:42 +03005880 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005881 int ret;
5882
5883 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10005884 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +10005885
Ville Syrjälä5aa56962016-06-22 21:57:00 +03005886 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
5887 if (ret)
5888 intel_dp_check_mst_status(&intel_dig_port->dp);
Dave Airlie0e32b392014-05-02 14:02:48 +10005889 }
5890}